Skip to content

Commit 92aec51

Browse files
authored
[DebugInfo][RemoveDIs] Use iterator-inserters in clang (#102006)
As part of the LLVM effort to eliminate debug-info intrinsics, we're moving to a world where only iterators should be used to insert instructions. This isn't a problem in clang when instructions get generated before any debug-info is inserted, however we're planning on deprecating and removing the instruction-pointer insertion routines. Scatter some calls to getIterator in a few places, remove a deref-then-addrof on another iterator, and add an overload for the createLoadInstBefore utility. Some callers passes a null insertion point, which we need to handle explicitly now.
1 parent cdadc2e commit 92aec51

9 files changed

+43
-31
lines changed

clang/lib/CodeGen/CGCUDANV.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -505,9 +505,9 @@ static void replaceManagedVar(llvm::GlobalVariable *Var,
505505
}
506506
if (auto *I = dyn_cast<llvm::Instruction>(U)) {
507507
llvm::Value *OldV = Var;
508-
llvm::Instruction *NewV =
509-
new llvm::LoadInst(Var->getType(), ManagedVar, "ld.managed", false,
510-
llvm::Align(Var->getAlignment()), I);
508+
llvm::Instruction *NewV = new llvm::LoadInst(
509+
Var->getType(), ManagedVar, "ld.managed", false,
510+
llvm::Align(Var->getAlignment()), I->getIterator());
511511
WorkItem.pop_back();
512512
// Replace constant expressions directly or indirectly using the managed
513513
// variable with instructions.

clang/lib/CodeGen/CGCall.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5064,8 +5064,8 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
50645064
llvm::AllocaInst *AI;
50655065
if (IP) {
50665066
IP = IP->getNextNode();
5067-
AI = new llvm::AllocaInst(ArgStruct, DL.getAllocaAddrSpace(),
5068-
"argmem", IP);
5067+
AI = new llvm::AllocaInst(ArgStruct, DL.getAllocaAddrSpace(), "argmem",
5068+
IP->getIterator());
50695069
} else {
50705070
AI = CreateTempAlloca(ArgStruct, "argmem");
50715071
}

clang/lib/CodeGen/CGCleanup.cpp

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -293,20 +293,26 @@ void CodeGenFunction::initFullExprCleanupWithFlag(RawAddress ActiveFlag) {
293293
void EHScopeStack::Cleanup::anchor() {}
294294

295295
static void createStoreInstBefore(llvm::Value *value, Address addr,
296-
llvm::Instruction *beforeInst,
296+
llvm::BasicBlock::iterator beforeInst,
297297
CodeGenFunction &CGF) {
298298
auto store = new llvm::StoreInst(value, addr.emitRawPointer(CGF), beforeInst);
299299
store->setAlignment(addr.getAlignment().getAsAlign());
300300
}
301301

302302
static llvm::LoadInst *createLoadInstBefore(Address addr, const Twine &name,
303-
llvm::Instruction *beforeInst,
303+
llvm::BasicBlock::iterator beforeInst,
304304
CodeGenFunction &CGF) {
305305
return new llvm::LoadInst(addr.getElementType(), addr.emitRawPointer(CGF),
306306
name, false, addr.getAlignment().getAsAlign(),
307307
beforeInst);
308308
}
309309

310+
static llvm::LoadInst *createLoadInstBefore(Address addr, const Twine &name,
311+
CodeGenFunction &CGF) {
312+
return new llvm::LoadInst(addr.getElementType(), addr.emitRawPointer(CGF),
313+
name, false, addr.getAlignment().getAsAlign());
314+
}
315+
310316
/// All the branch fixups on the EH stack have propagated out past the
311317
/// outermost normal cleanup; resolve them all by adding cases to the
312318
/// given switch instruction.
@@ -330,8 +336,8 @@ static void ResolveAllBranchFixups(CodeGenFunction &CGF,
330336
// entry which we're currently popping.
331337
if (Fixup.OptimisticBranchBlock == nullptr) {
332338
createStoreInstBefore(CGF.Builder.getInt32(Fixup.DestinationIndex),
333-
CGF.getNormalCleanupDestSlot(), Fixup.InitialBranch,
334-
CGF);
339+
CGF.getNormalCleanupDestSlot(),
340+
Fixup.InitialBranch->getIterator(), CGF);
335341
Fixup.InitialBranch->setSuccessor(0, CleanupEntry);
336342
}
337343

@@ -358,7 +364,7 @@ static llvm::SwitchInst *TransitionToCleanupSwitch(CodeGenFunction &CGF,
358364
if (llvm::BranchInst *Br = dyn_cast<llvm::BranchInst>(Term)) {
359365
assert(Br->isUnconditional());
360366
auto Load = createLoadInstBefore(CGF.getNormalCleanupDestSlot(),
361-
"cleanup.dest", Term, CGF);
367+
"cleanup.dest", Term->getIterator(), CGF);
362368
llvm::SwitchInst *Switch =
363369
llvm::SwitchInst::Create(Load, Br->getSuccessor(0), 4, Block);
364370
Br->eraseFromParent();
@@ -612,7 +618,8 @@ static void destroyOptimisticNormalEntry(CodeGenFunction &CGF,
612618
llvm::SwitchInst *si = cast<llvm::SwitchInst>(use.getUser());
613619
if (si->getNumCases() == 1 && si->getDefaultDest() == unreachableBB) {
614620
// Replace the switch with a branch.
615-
llvm::BranchInst::Create(si->case_begin()->getCaseSuccessor(), si);
621+
llvm::BranchInst::Create(si->case_begin()->getCaseSuccessor(),
622+
si->getIterator());
616623

617624
// The switch operand is a load from the cleanup-dest alloca.
618625
llvm::LoadInst *condition = cast<llvm::LoadInst>(si->getCondition());
@@ -908,8 +915,8 @@ void CodeGenFunction::PopCleanupBlock(bool FallthroughIsBranchThrough,
908915
// pass the abnormal exit flag to Fn (SEH cleanup)
909916
cleanupFlags.setHasExitSwitch();
910917

911-
llvm::LoadInst *Load = createLoadInstBefore(
912-
getNormalCleanupDestSlot(), "cleanup.dest", nullptr, *this);
918+
llvm::LoadInst *Load = createLoadInstBefore(getNormalCleanupDestSlot(),
919+
"cleanup.dest", *this);
913920
llvm::SwitchInst *Switch =
914921
llvm::SwitchInst::Create(Load, Default, SwitchCapacity);
915922

@@ -954,11 +961,12 @@ void CodeGenFunction::PopCleanupBlock(bool FallthroughIsBranchThrough,
954961
for (unsigned I = FixupDepth, E = EHStack.getNumBranchFixups();
955962
I < E; ++I) {
956963
BranchFixup &Fixup = EHStack.getBranchFixup(I);
957-
if (!Fixup.Destination) continue;
964+
if (!Fixup.Destination)
965+
continue;
958966
if (!Fixup.OptimisticBranchBlock) {
959967
createStoreInstBefore(Builder.getInt32(Fixup.DestinationIndex),
960-
getNormalCleanupDestSlot(), Fixup.InitialBranch,
961-
*this);
968+
getNormalCleanupDestSlot(),
969+
Fixup.InitialBranch->getIterator(), *this);
962970
Fixup.InitialBranch->setSuccessor(0, NormalEntry);
963971
}
964972
Fixup.OptimisticBranchBlock = NormalExit;
@@ -1133,7 +1141,8 @@ void CodeGenFunction::EmitBranchThroughCleanup(JumpDest Dest) {
11331141

11341142
// Store the index at the start.
11351143
llvm::ConstantInt *Index = Builder.getInt32(Dest.getDestIndex());
1136-
createStoreInstBefore(Index, getNormalCleanupDestSlot(), BI, *this);
1144+
createStoreInstBefore(Index, getNormalCleanupDestSlot(), BI->getIterator(),
1145+
*this);
11371146

11381147
// Adjust BI to point to the first cleanup block.
11391148
{
@@ -1252,7 +1261,7 @@ static void SetupCleanupBlockActivation(CodeGenFunction &CGF,
12521261
if (CGF.isInConditionalBranch()) {
12531262
CGF.setBeforeOutermostConditional(value, var, CGF);
12541263
} else {
1255-
createStoreInstBefore(value, var, dominatingIP, CGF);
1264+
createStoreInstBefore(value, var, dominatingIP->getIterator(), CGF);
12561265
}
12571266
}
12581267

clang/lib/CodeGen/CGCoroutine.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -866,8 +866,9 @@ void CodeGenFunction::EmitCoroutineBody(const CoroutineBodyStmt &S) {
866866
EmitStmt(S.getPromiseDeclStmt());
867867

868868
Address PromiseAddr = GetAddrOfLocalVar(S.getPromiseDecl());
869-
auto *PromiseAddrVoidPtr = new llvm::BitCastInst(
870-
PromiseAddr.emitRawPointer(*this), VoidPtrTy, "", CoroId);
869+
auto *PromiseAddrVoidPtr =
870+
new llvm::BitCastInst(PromiseAddr.emitRawPointer(*this), VoidPtrTy, "",
871+
CoroId->getIterator());
871872
// Update CoroId to refer to the promise. We could not do it earlier because
872873
// promise local variable was not emitted yet.
873874
CoroId->setArgOperand(1, PromiseAddrVoidPtr);

clang/lib/CodeGen/CGExpr.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,9 @@ llvm::AllocaInst *CodeGenFunction::CreateTempAlloca(llvm::Type *Ty,
120120
if (ArraySize)
121121
Alloca = Builder.CreateAlloca(Ty, ArraySize, Name);
122122
else
123-
Alloca = new llvm::AllocaInst(Ty, CGM.getDataLayout().getAllocaAddrSpace(),
124-
ArraySize, Name, &*AllocaInsertPt);
123+
Alloca =
124+
new llvm::AllocaInst(Ty, CGM.getDataLayout().getAllocaAddrSpace(),
125+
ArraySize, Name, AllocaInsertPt->getIterator());
125126
if (Allocas) {
126127
Allocas->Add(Alloca);
127128
}

clang/lib/CodeGen/CGObjC.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2393,7 +2393,8 @@ static llvm::Value *emitOptimizedARCReturnCall(llvm::Value *value,
23932393
llvm::OperandBundleDef OB("clang.arc.attachedcall", bundleArgs);
23942394
auto *oldCall = cast<llvm::CallBase>(value);
23952395
llvm::CallBase *newCall = llvm::CallBase::addOperandBundle(
2396-
oldCall, llvm::LLVMContext::OB_clang_arc_attachedcall, OB, oldCall);
2396+
oldCall, llvm::LLVMContext::OB_clang_arc_attachedcall, OB,
2397+
oldCall->getIterator());
23972398
newCall->copyMetadata(*oldCall);
23982399
oldCall->replaceAllUsesWith(newCall);
23992400
oldCall->eraseFromParent();

clang/lib/CodeGen/CGStmt.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3238,7 +3238,7 @@ CodeGenFunction::addConvergenceControlToken(llvm::CallBase *Input,
32383238
llvm::Value *bundleArgs[] = {ParentToken};
32393239
llvm::OperandBundleDef OB("convergencectrl", bundleArgs);
32403240
auto Output = llvm::CallBase::addOperandBundle(
3241-
Input, llvm::LLVMContext::OB_convergencectrl, OB, Input);
3241+
Input, llvm::LLVMContext::OB_convergencectrl, OB, Input->getIterator());
32423242
Input->replaceAllUsesWith(Output);
32433243
Input->eraseFromParent();
32443244
return Output;

clang/lib/CodeGen/CodeGenFunction.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1313,8 +1313,8 @@ class CodeGenFunction : public CodeGenTypeCache {
13131313
CodeGenFunction &CGF) {
13141314
assert(isInConditionalBranch());
13151315
llvm::BasicBlock *block = OutermostConditional->getStartingBlock();
1316-
auto store =
1317-
new llvm::StoreInst(value, addr.emitRawPointer(CGF), &block->back());
1316+
auto store = new llvm::StoreInst(value, addr.emitRawPointer(CGF),
1317+
block->back().getIterator());
13181318
store->setAlignment(addr.getAlignment().getAsAlign());
13191319
}
13201320

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5911,13 +5911,13 @@ static void replaceUsesOfNonProtoConstant(llvm::Constant *old,
59115911

59125912
llvm::CallBase *newCall;
59135913
if (isa<llvm::CallInst>(callSite)) {
5914-
newCall =
5915-
llvm::CallInst::Create(newFn, newArgs, newBundles, "", callSite);
5914+
newCall = llvm::CallInst::Create(newFn, newArgs, newBundles, "",
5915+
callSite->getIterator());
59165916
} else {
59175917
auto *oldInvoke = cast<llvm::InvokeInst>(callSite);
5918-
newCall = llvm::InvokeInst::Create(newFn, oldInvoke->getNormalDest(),
5919-
oldInvoke->getUnwindDest(), newArgs,
5920-
newBundles, "", callSite);
5918+
newCall = llvm::InvokeInst::Create(
5919+
newFn, oldInvoke->getNormalDest(), oldInvoke->getUnwindDest(),
5920+
newArgs, newBundles, "", callSite->getIterator());
59215921
}
59225922
newArgs.clear(); // for the next iteration
59235923

0 commit comments

Comments
 (0)