Skip to content

Commit 59ec94b

Browse files
committed
IRGen: Cleanup through use of IRGenFunction
1 parent efe7bef commit 59ec94b

File tree

1 file changed

+20
-21
lines changed

1 file changed

+20
-21
lines changed

lib/IRGen/GenDecl.cpp

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2130,28 +2130,26 @@ static void emitDynamicallyReplaceableThunk(IRGenModule &IGM,
21302130
implFn->addFnAttr(llvm::Attribute::NoInline);
21312131

21322132
// Load the function and dispatch to it forwarding our arguments.
2133-
llvm::BasicBlock *entryBB =
2134-
llvm::BasicBlock::Create(IGM.getLLVMContext(), "entry", dispatchFn);
2135-
IRBuilder B(IGM.getLLVMContext(), false);
2136-
B.SetInsertPoint(entryBB);
2133+
IRGenFunction IGF(IGM, dispatchFn);
21372134
if (IGM.DebugInfo)
2138-
IGM.DebugInfo->emitArtificialFunction(B, dispatchFn);
2135+
IGM.DebugInfo->emitArtificialFunction(IGF, dispatchFn);
21392136
llvm::Constant *indices[] = {llvm::ConstantInt::get(IGM.Int32Ty, 0),
21402137
llvm::ConstantInt::get(IGM.Int32Ty, 0)};
2141-
auto *fnPtr = B.CreateLoad(
2138+
auto *fnPtr = IGF.Builder.CreateLoad(
21422139
llvm::ConstantExpr::getInBoundsGetElementPtr(nullptr, linkEntry, indices),
21432140
IGM.getPointerAlignment());
2144-
auto *typeFnPtr = B.CreateBitOrPointerCast(fnPtr, implFn->getType());
2141+
auto *typeFnPtr =
2142+
IGF.Builder.CreateBitOrPointerCast(fnPtr, implFn->getType());
21452143
SmallVector<llvm::Value *, 16> forwardedArgs;
21462144
for (auto &arg : dispatchFn->args())
21472145
forwardedArgs.push_back(&arg);
2148-
auto *Res =
2149-
B.CreateCall(FunctionPointer(typeFnPtr, signature), forwardedArgs);
2146+
auto *Res = IGF.Builder.CreateCall(FunctionPointer(typeFnPtr, signature),
2147+
forwardedArgs);
21502148
Res->setTailCall();
21512149
if (implFn->getReturnType()->isVoidTy())
2152-
B.CreateRetVoid();
2150+
IGF.Builder.CreateRetVoid();
21532151
else
2154-
B.CreateRet(Res);
2152+
IGF.Builder.CreateRet(Res);
21552153
}
21562154

21572155
void IRGenModule::emitOpaqueTypeDescriptorAccessor(OpaqueTypeDecl *opaque) {
@@ -2227,34 +2225,35 @@ void IRGenModule::emitDynamicReplacementOriginalFunctionThunk(SILFunction *f) {
22272225
f->getOptimizationMode());
22282226
implFn->addFnAttr(llvm::Attribute::NoInline);
22292227

2228+
IRGenFunction IGF(*this, implFn);
2229+
if (DebugInfo)
2230+
DebugInfo->emitArtificialFunction(IGF, implFn);
2231+
22302232
LinkEntity varEntity =
22312233
LinkEntity::forDynamicallyReplaceableFunctionVariable(f);
22322234
auto linkEntry = getChainEntryForDynamicReplacement(*this, varEntity, nullptr,
22332235
NotForDefinition);
22342236

22352237
// Load the function and dispatch to it forwarding our arguments.
2236-
llvm::BasicBlock *entryBB =
2237-
llvm::BasicBlock::Create(getLLVMContext(), "entry", implFn);
2238-
IRBuilder B(getLLVMContext(), false);
2239-
B.SetInsertPoint(entryBB);
22402238
llvm::Constant *indices[] = {llvm::ConstantInt::get(Int32Ty, 0),
22412239
llvm::ConstantInt::get(Int32Ty, 0)};
22422240

2243-
auto *fnPtr = B.CreateLoad(
2241+
auto *fnPtr = IGF.Builder.CreateLoad(
22442242
llvm::ConstantExpr::getInBoundsGetElementPtr(nullptr, linkEntry, indices),
22452243
getPointerAlignment());
2246-
auto *typeFnPtr = B.CreateBitOrPointerCast(fnPtr, implFn->getType());
2244+
auto *typeFnPtr =
2245+
IGF.Builder.CreateBitOrPointerCast(fnPtr, implFn->getType());
22472246

22482247
SmallVector<llvm::Value *, 16> forwardedArgs;
22492248
for (auto &arg : implFn->args())
22502249
forwardedArgs.push_back(&arg);
2251-
auto *Res =
2252-
B.CreateCall(FunctionPointer(typeFnPtr, signature), forwardedArgs);
2250+
auto *Res = IGF.Builder.CreateCall(FunctionPointer(typeFnPtr, signature),
2251+
forwardedArgs);
22532252

22542253
if (implFn->getReturnType()->isVoidTy())
2255-
B.CreateRetVoid();
2254+
IGF.Builder.CreateRetVoid();
22562255
else
2257-
B.CreateRet(Res);
2256+
IGF.Builder.CreateRet(Res);
22582257
}
22592258

22602259
/// Find the entry point for a SIL function.

0 commit comments

Comments
 (0)