Skip to content

Commit d75f9dd

Browse files
committed
Revert "[IR][NFC] Update IRBuilder to use InsertPosition (#96497)"
Reverts the above commit, as it updates a common header function and did not update all callsites: https://lab.llvm.org/buildbot/#/builders/29/builds/382 This reverts commit 6481dc5.
1 parent 3b5b814 commit d75f9dd

File tree

97 files changed

+326
-252
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

97 files changed

+326
-252
lines changed

clang/lib/CodeGen/CGBlocks.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1545,7 +1545,7 @@ llvm::Function *CodeGenFunction::GenerateBlockFunction(
15451545
entry_ptr = entry_ptr->getNextNonDebugInstruction()->getIterator();
15461546
else
15471547
entry_ptr = entry->end();
1548-
Builder.SetInsertPoint(entry_ptr);
1548+
Builder.SetInsertPoint(entry, entry_ptr);
15491549

15501550
// Emit debug information for all the DeclRefExprs.
15511551
// FIXME: also for 'this'

clang/lib/CodeGen/CGGPUBuiltin.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,13 +202,13 @@ RValue CodeGenFunction::EmitAMDGPUDevicePrintfCallExpr(const CallExpr *E) {
202202
Args.push_back(Arg);
203203
}
204204

205-
llvm::IRBuilder<> IRB(Builder.GetInsertPoint());
205+
llvm::IRBuilder<> IRB(Builder.GetInsertBlock(), Builder.GetInsertPoint());
206206
IRB.SetCurrentDebugLocation(Builder.getCurrentDebugLocation());
207207

208208
bool isBuffered = (CGM.getTarget().getTargetOpts().AMDGPUPrintfKindVal ==
209209
clang::TargetOptions::AMDGPUPrintfKind::Buffered);
210210
auto Printf = llvm::emitAMDGPUPrintfCall(IRB, Args, isBuffered);
211-
Builder.SetInsertPoint(IRB.GetInsertPoint());
211+
Builder.SetInsertPoint(IRB.GetInsertBlock(), IRB.GetInsertPoint());
212212
return RValue::get(Printf);
213213
}
214214

clang/lib/CodeGen/CGHLSLRuntime.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ void CGHLSLRuntime::generateGlobalCtorDtorCalls() {
436436
for (auto &F : M.functions()) {
437437
if (!F.hasFnAttribute("hlsl.shader"))
438438
continue;
439-
IRBuilder<> B(F.getEntryBlock().begin());
439+
IRBuilder<> B(&F.getEntryBlock(), F.getEntryBlock().begin());
440440
for (auto *Fn : CtorFns)
441441
B.CreateCall(FunctionCallee(Fn));
442442

clang/lib/CodeGen/CGObjC.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2970,20 +2970,21 @@ static llvm::Value *emitARCOperationAfterCall(CodeGenFunction &CGF,
29702970
value = doFallback(CGF, value);
29712971
} else if (llvm::CallInst *call = dyn_cast<llvm::CallInst>(value)) {
29722972
// Place the retain immediately following the call.
2973-
CGF.Builder.SetInsertPoint(++llvm::BasicBlock::iterator(call));
2973+
CGF.Builder.SetInsertPoint(call->getParent(),
2974+
++llvm::BasicBlock::iterator(call));
29742975
value = doAfterCall(CGF, value);
29752976
} else if (llvm::InvokeInst *invoke = dyn_cast<llvm::InvokeInst>(value)) {
29762977
// Place the retain at the beginning of the normal destination block.
29772978
llvm::BasicBlock *BB = invoke->getNormalDest();
2978-
CGF.Builder.SetInsertPoint(BB->begin());
2979+
CGF.Builder.SetInsertPoint(BB, BB->begin());
29792980
value = doAfterCall(CGF, value);
29802981

29812982
// Bitcasts can arise because of related-result returns. Rewrite
29822983
// the operand.
29832984
} else if (llvm::BitCastInst *bitcast = dyn_cast<llvm::BitCastInst>(value)) {
29842985
// Change the insert point to avoid emitting the fall-back call after the
29852986
// bitcast.
2986-
CGF.Builder.SetInsertPoint(bitcast->getIterator());
2987+
CGF.Builder.SetInsertPoint(bitcast->getParent(), bitcast->getIterator());
29872988
llvm::Value *operand = bitcast->getOperand(0);
29882989
operand = emitARCOperationAfterCall(CGF, operand, doAfterCall, doFallback);
29892990
bitcast->setOperand(0, operand);

clang/lib/CodeGen/CGObjCMac.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4417,7 +4417,7 @@ void FragileHazards::emitHazardsInNewBlocks() {
44174417
// call. If the call throws, then this is sufficient to
44184418
// guarantee correctness as long as it doesn't also write to any
44194419
// locals.
4420-
Builder.SetInsertPoint(BI);
4420+
Builder.SetInsertPoint(&BB, BI);
44214421
emitReadHazard(Builder);
44224422
}
44234423
}

clang/lib/CodeGen/CGOpenMPRuntime.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1447,7 +1447,7 @@ llvm::Value *CGOpenMPRuntime::getThreadID(CodeGenFunction &CGF,
14471447
if (!Elem.second.ServiceInsertPt)
14481448
setLocThreadIdInsertPt(CGF);
14491449
CGBuilderTy::InsertPointGuard IPG(CGF.Builder);
1450-
CGF.Builder.SetInsertPoint(&*Elem.second.ServiceInsertPt);
1450+
CGF.Builder.SetInsertPoint(Elem.second.ServiceInsertPt);
14511451
auto DL = ApplyDebugLocation::CreateDefaultArtificial(CGF, Loc);
14521452
llvm::CallInst *Call = CGF.Builder.CreateCall(
14531453
OMPBuilder.getOrCreateRuntimeFunction(CGM.getModule(),

clang/lib/CodeGen/CGStmt.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3076,7 +3076,7 @@ void CodeGenFunction::EmitAsmStmt(const AsmStmt &S) {
30763076
if (IsGCCAsmGoto && !CBRRegResults.empty()) {
30773077
for (llvm::BasicBlock *Succ : CBR->getIndirectDests()) {
30783078
llvm::IRBuilderBase::InsertPointGuard IPG(Builder);
3079-
Builder.SetInsertPoint(--(Succ->end()));
3079+
Builder.SetInsertPoint(Succ, --(Succ->end()));
30803080
EmitAsmStores(*this, S, CBRRegResults[Succ], ResultRegTypes,
30813081
ResultTruncRegTypes, ResultRegDests, ResultRegQualTys,
30823082
ResultTypeRequiresCast, ResultRegIsFlagReg);

clang/lib/CodeGen/CodeGenABITypes.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ llvm::Value *CodeGen::getCXXDestructorImplicitParam(
123123
CGF.CurCodeDecl = D;
124124
CGF.CurFuncDecl = D;
125125
CGF.CurFn = InsertBlock->getParent();
126-
CGF.Builder.SetInsertPoint(InsertPoint);
126+
CGF.Builder.SetInsertPoint(InsertBlock, InsertPoint);
127127
return CGM.getCXXABI().getCXXDestructorImplicitParam(
128128
CGF, D, Type, ForVirtualBase, Delegating);
129129
}

clang/lib/CodeGen/CodeGenFunction.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2764,7 +2764,7 @@ void CodeGenFunction::EmitSanitizerStatReport(llvm::SanitizerStatKind SSK) {
27642764
if (!CGM.getCodeGenOpts().SanitizeStats)
27652765
return;
27662766

2767-
llvm::IRBuilder<> IRB(Builder.GetInsertPoint());
2767+
llvm::IRBuilder<> IRB(Builder.GetInsertBlock(), Builder.GetInsertPoint());
27682768
IRB.SetCurrentDebugLocation(Builder.getCurrentDebugLocation());
27692769
CGM.getSanStats().create(IRB, SSK);
27702770
}
@@ -2883,7 +2883,7 @@ void CodeGenFunction::EmitAArch64MultiVersionResolver(
28832883
}
28842884

28852885
if (!AArch64CpuInitialized) {
2886-
Builder.SetInsertPoint(CurBlock->begin());
2886+
Builder.SetInsertPoint(CurBlock, CurBlock->begin());
28872887
EmitAArch64CpuInit();
28882888
AArch64CpuInitialized = true;
28892889
Builder.SetInsertPoint(CurBlock);

llvm/include/llvm/IR/IRBuilder.h

Lines changed: 63 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -173,13 +173,37 @@ class IRBuilderBase {
173173
BasicBlock::iterator GetInsertPoint() const { return InsertPt; }
174174
LLVMContext &getContext() const { return Context; }
175175

176+
/// This specifies that created instructions should be appended to the
177+
/// end of the specified block.
178+
void SetInsertPoint(BasicBlock *TheBB) {
179+
BB = TheBB;
180+
InsertPt = BB->end();
181+
}
182+
183+
/// This specifies that created instructions should be inserted before
184+
/// the specified instruction.
185+
void SetInsertPoint(Instruction *I) {
186+
BB = I->getParent();
187+
InsertPt = I->getIterator();
188+
assert(InsertPt != BB->end() && "Can't read debug loc from end()");
189+
SetCurrentDebugLocation(I->getStableDebugLoc());
190+
}
191+
176192
/// This specifies that created instructions should be inserted at the
177-
/// specified insert position.
178-
void SetInsertPoint(InsertPosition IP) {
179-
BB = IP.getBasicBlock();
193+
/// specified point.
194+
void SetInsertPoint(BasicBlock *TheBB, BasicBlock::iterator IP) {
195+
BB = TheBB;
196+
InsertPt = IP;
197+
if (IP != TheBB->end())
198+
SetCurrentDebugLocation(IP->getStableDebugLoc());
199+
}
200+
201+
/// This specifies that created instructions should be inserted at
202+
/// the specified point, but also requires that \p IP is dereferencable.
203+
void SetInsertPoint(BasicBlock::iterator IP) {
204+
BB = IP->getParent();
180205
InsertPt = IP;
181-
if (InsertPt != BB->end())
182-
SetCurrentDebugLocation(InsertPt->getStableDebugLoc());
206+
SetCurrentDebugLocation(IP->getStableDebugLoc());
183207
}
184208

185209
/// This specifies that created instructions should inserted at the beginning
@@ -262,7 +286,7 @@ class IRBuilderBase {
262286
/// Sets the current insert point to a previously-saved location.
263287
void restoreIP(InsertPoint IP) {
264288
if (IP.isSet())
265-
SetInsertPoint(IP.getPoint());
289+
SetInsertPoint(IP.getBlock(), IP.getPoint());
266290
else
267291
ClearInsertionPoint();
268292
}
@@ -2653,22 +2677,46 @@ class IRBuilder : public IRBuilderBase {
26532677
ArrayRef<OperandBundleDef> OpBundles = std::nullopt)
26542678
: IRBuilderBase(C, this->Folder, this->Inserter, FPMathTag, OpBundles) {}
26552679

2656-
explicit IRBuilder(InsertPosition IP, MDNode *FPMathTag = nullptr,
2680+
explicit IRBuilder(BasicBlock *TheBB, FolderTy Folder,
2681+
MDNode *FPMathTag = nullptr,
26572682
ArrayRef<OperandBundleDef> OpBundles = std::nullopt)
2658-
: IRBuilderBase(IP.getBasicBlock()->getContext(), this->Folder,
2659-
this->Inserter, FPMathTag, OpBundles) {
2660-
SetInsertPoint(IP);
2683+
: IRBuilderBase(TheBB->getContext(), this->Folder, this->Inserter,
2684+
FPMathTag, OpBundles),
2685+
Folder(Folder) {
2686+
SetInsertPoint(TheBB);
26612687
}
26622688

2663-
explicit IRBuilder(InsertPosition IP, FolderTy Folder,
2664-
MDNode *FPMathTag = nullptr,
2689+
explicit IRBuilder(BasicBlock *TheBB, MDNode *FPMathTag = nullptr,
26652690
ArrayRef<OperandBundleDef> OpBundles = std::nullopt)
2666-
: IRBuilderBase(IP.getBasicBlock()->getContext(), this->Folder,
2667-
this->Inserter, FPMathTag, OpBundles),
2668-
Folder(Folder) {
2691+
: IRBuilderBase(TheBB->getContext(), this->Folder, this->Inserter,
2692+
FPMathTag, OpBundles) {
2693+
SetInsertPoint(TheBB);
2694+
}
2695+
2696+
explicit IRBuilder(Instruction *IP, MDNode *FPMathTag = nullptr,
2697+
ArrayRef<OperandBundleDef> OpBundles = std::nullopt)
2698+
: IRBuilderBase(IP->getContext(), this->Folder, this->Inserter, FPMathTag,
2699+
OpBundles) {
26692700
SetInsertPoint(IP);
26702701
}
26712702

2703+
IRBuilder(BasicBlock *TheBB, BasicBlock::iterator IP, FolderTy Folder,
2704+
MDNode *FPMathTag = nullptr,
2705+
ArrayRef<OperandBundleDef> OpBundles = std::nullopt)
2706+
: IRBuilderBase(TheBB->getContext(), this->Folder, this->Inserter,
2707+
FPMathTag, OpBundles),
2708+
Folder(Folder) {
2709+
SetInsertPoint(TheBB, IP);
2710+
}
2711+
2712+
IRBuilder(BasicBlock *TheBB, BasicBlock::iterator IP,
2713+
MDNode *FPMathTag = nullptr,
2714+
ArrayRef<OperandBundleDef> OpBundles = std::nullopt)
2715+
: IRBuilderBase(TheBB->getContext(), this->Folder, this->Inserter,
2716+
FPMathTag, OpBundles) {
2717+
SetInsertPoint(TheBB, IP);
2718+
}
2719+
26722720
/// Avoid copying the full IRBuilder. Prefer using InsertPointGuard
26732721
/// or FastMathFlagGuard instead.
26742722
IRBuilder(const IRBuilder &) = delete;

0 commit comments

Comments
 (0)