[RewriteStatepointsForGC] Hoist some code out of a loop
llvm-svn: 242808
This commit is contained in:
parent
3651233004
commit
94babb7030
|
@ -1164,21 +1164,22 @@ static void CreateGCRelocates(ArrayRef<llvm::Value *> LiveVariables,
|
|||
ArrayRef<llvm::Value *> BasePtrs,
|
||||
Instruction *StatepointToken,
|
||||
IRBuilder<> Builder) {
|
||||
if (LiveVariables.empty())
|
||||
return;
|
||||
|
||||
// All gc_relocate are set to i8 addrspace(1)* type. We originally generated
|
||||
// unique declarations for each pointer type, but this proved problematic
|
||||
// because the intrinsic mangling code is incomplete and fragile. Since
|
||||
// we're moving towards a single unified pointer type anyways, we can just
|
||||
// cast everything to an i8* of the right address space. A bitcast is added
|
||||
// later to convert gc_relocate to the actual value's type.
|
||||
Module *M = StatepointToken->getModule();
|
||||
auto AS = cast<PointerType>(LiveVariables[0]->getType())->getAddressSpace();
|
||||
Type *Types[] = {Type::getInt8PtrTy(M->getContext(), AS)};
|
||||
Value *GCRelocateDecl =
|
||||
Intrinsic::getDeclaration(M, Intrinsic::experimental_gc_relocate, Types);
|
||||
|
||||
for (unsigned i = 0; i < LiveVariables.size(); i++) {
|
||||
// We generate a (potentially) unique declaration for every pointer type
|
||||
// combination. This results is some blow up the function declarations in
|
||||
// the IR, but removes the need for argument bitcasts which shrinks the IR
|
||||
// greatly and makes it much more readable.
|
||||
SmallVector<Type *, 1> Types; // one per 'any' type
|
||||
// All gc_relocate are set to i8 addrspace(1)* type. This could help avoid
|
||||
// cases where the actual value's type mangling is not supported by llvm. A
|
||||
// bitcast is added later to convert gc_relocate to the actual value's type.
|
||||
Types.push_back(Type::getInt8PtrTy(M->getContext(), 1));
|
||||
Value *GCRelocateDecl = Intrinsic::getDeclaration(
|
||||
M, Intrinsic::experimental_gc_relocate, Types);
|
||||
|
||||
// Generate the gc.relocate call and save the result
|
||||
Value *BaseIdx =
|
||||
Builder.getInt32(LiveStart + find_index(LiveVariables, BasePtrs[i]));
|
||||
|
|
Loading…
Reference in New Issue