Skip to content

Commit fd7d788

Browse files
authored
[DebugInfo][RemoveDIs] Use iterators to insert everywhere (#102003)
These are the final few places in LLVM where we use instruction pointers to identify the position that we're inserting something. We're trying to get away from that with a view to deprecating those methods, thus use iterators in all these places. I believe they're all debug-info safe. The sketchiest part is the ExtractValueInst copy constructor, where we cast nullptr to a BasicBlock pointer, so that we take the non-default insert-into-no-block path for instruction insertion, instead of the default nullptr-instruction path for UnaryInstruction. Such a hack is necessary until we get rid of the instruction constructor entirely.
1 parent 1139dee commit fd7d788

File tree

6 files changed

+16
-13
lines changed

6 files changed

+16
-13
lines changed

llvm/lib/IR/Instructions.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2484,8 +2484,9 @@ void ExtractValueInst::init(ArrayRef<unsigned> Idxs, const Twine &Name) {
24842484
}
24852485

24862486
ExtractValueInst::ExtractValueInst(const ExtractValueInst &EVI)
2487-
: UnaryInstruction(EVI.getType(), ExtractValue, EVI.getOperand(0)),
2488-
Indices(EVI.Indices) {
2487+
: UnaryInstruction(EVI.getType(), ExtractValue, EVI.getOperand(0),
2488+
(BasicBlock *)nullptr),
2489+
Indices(EVI.Indices) {
24892490
SubclassOptionalData = EVI.SubclassOptionalData;
24902491
}
24912492

llvm/lib/Transforms/IPO/ExpandVariadics.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -809,7 +809,7 @@ bool ExpandVariadics::expandCall(Module &M, IRBuilder<> &Builder, CallBase *CB,
809809
Value *Dst = NF ? NF : CI->getCalledOperand();
810810
FunctionType *NFTy = inlinableVariadicFunctionType(M, VarargFunctionType);
811811

812-
NewCB = CallInst::Create(NFTy, Dst, Args, OpBundles, "", CI);
812+
NewCB = CallInst::Create(NFTy, Dst, Args, OpBundles, "", CI->getIterator());
813813

814814
CallInst::TailCallKind TCK = CI->getTailCallKind();
815815
assert(TCK != CallInst::TCK_MustTail);

llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -690,8 +690,8 @@ class RuntimeCallInserter {
690690
if (EHPad && EHPad->isEHPad()) {
691691
// Replace CI with a clone with an added funclet OperandBundle
692692
OperandBundleDef OB("funclet", EHPad);
693-
auto *NewCall =
694-
CallBase::addOperandBundle(CI, LLVMContext::OB_funclet, OB, CI);
693+
auto *NewCall = CallBase::addOperandBundle(CI, LLVMContext::OB_funclet,
694+
OB, CI->getIterator());
695695
NewCall->copyMetadata(*CI);
696696
CI->replaceAllUsesWith(NewCall);
697697
CI->eraseFromParent();

llvm/lib/Transforms/Scalar/LICM.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2767,8 +2767,9 @@ static bool hoistMulAddAssociation(Instruction &I, Loop &L,
27672767
unsigned OpIdx = U->getOperandNo();
27682768
auto *LHS = OpIdx == 0 ? Mul : Ins->getOperand(0);
27692769
auto *RHS = OpIdx == 1 ? Mul : Ins->getOperand(1);
2770-
auto *NewBO = BinaryOperator::Create(Ins->getOpcode(), LHS, RHS,
2771-
Ins->getName() + ".reass", Ins);
2770+
auto *NewBO =
2771+
BinaryOperator::Create(Ins->getOpcode(), LHS, RHS,
2772+
Ins->getName() + ".reass", Ins->getIterator());
27722773
NewBO->copyIRFlags(Ins);
27732774
if (VariantOp == Ins)
27742775
VariantOp = NewBO;
@@ -2822,9 +2823,9 @@ static bool hoistBOAssociation(Instruction &I, Loop &L,
28222823
assert(Preheader && "Loop is not in simplify form?");
28232824

28242825
auto *Inv = BinaryOperator::Create(Opcode, C1, C2, "invariant.op",
2825-
Preheader->getTerminator());
2826-
auto *NewBO =
2827-
BinaryOperator::Create(Opcode, LV, Inv, BO->getName() + ".reass", BO);
2826+
Preheader->getTerminator()->getIterator());
2827+
auto *NewBO = BinaryOperator::Create(
2828+
Opcode, LV, Inv, BO->getName() + ".reass", BO->getIterator());
28282829

28292830
// Copy NUW for ADDs if both instructions have it.
28302831
if (Opcode == Instruction::Add && BO->hasNoUnsignedWrap() &&

llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ static void convertMetadataToAssumes(LoadInst *LI, Value *Val,
460460
LLVMContext &Ctx = LI->getContext();
461461
new StoreInst(ConstantInt::getTrue(Ctx),
462462
PoisonValue::get(PointerType::getUnqual(Ctx)),
463-
/*isVolatile=*/false, Align(1), LI);
463+
/*isVolatile=*/false, Align(1), LI->getIterator());
464464
return;
465465
}
466466

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2632,8 +2632,9 @@ PHINode *InnerLoopVectorizer::createInductionResumeValue(
26322632
}
26332633

26342634
// Create phi nodes to merge from the backedge-taken check block.
2635-
PHINode *BCResumeVal = PHINode::Create(OrigPhi->getType(), 3, "bc.resume.val",
2636-
LoopScalarPreHeader->getFirstNonPHI());
2635+
PHINode *BCResumeVal =
2636+
PHINode::Create(OrigPhi->getType(), 3, "bc.resume.val",
2637+
LoopScalarPreHeader->getFirstNonPHIIt());
26372638
// Copy original phi DL over to the new one.
26382639
BCResumeVal->setDebugLoc(OrigPhi->getDebugLoc());
26392640

0 commit comments

Comments
 (0)