[DebugInfo] Enable deprecation of iterator-insertion methods (#102608)

This is an almost-final step in eliminating debug-intrinsics -- read more
about that here: https://llvm.org/docs/RemoveDIsDebugInfo.html . To
correctly update variable location information in the background when
inserting instructions, we need some information carried at runtime in
BasicBlock::iterator, hence deprecating pointer-insertion.
                                                                                                                                                                                                                 An immediate fix for any deprecation warnings is to call "getIterator"
on the insertion position pointer. If you intend on inserting at the start
of a block, use BB->begin() or similar methods to fetch the appropriate
iterator.
This commit is contained in:
Jeremy Morse 2024-09-20 13:56:43 +01:00 committed by GitHub
parent 1808fc13c8
commit 2f50b280dc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 43 additions and 132 deletions

View File

@ -158,7 +158,7 @@ static bool eliminateCondBranches_v1(Function &F) {
// Replace the conditional branch with an unconditional one, by creating // Replace the conditional branch with an unconditional one, by creating
// a new unconditional branch to the selected successor and removing the // a new unconditional branch to the selected successor and removing the
// conditional one. // conditional one.
BranchInst::Create(BI->getSuccessor(CI->isZero()), BI); BranchInst::Create(BI->getSuccessor(CI->isZero()), BI->getIterator());
BI->eraseFromParent(); BI->eraseFromParent();
Changed = true; Changed = true;
} }
@ -195,7 +195,7 @@ static bool eliminateCondBranches_v2(Function &F, DominatorTree &DT) {
// a new unconditional branch to the selected successor and removing the // a new unconditional branch to the selected successor and removing the
// conditional one. // conditional one.
BranchInst *NewBranch = BranchInst *NewBranch =
BranchInst::Create(BI->getSuccessor(CI->isZero()), BI); BranchInst::Create(BI->getSuccessor(CI->isZero()), BI->getIterator());
BI->eraseFromParent(); BI->eraseFromParent();
// Delete the edge between BB and RemovedSucc in the DominatorTree, iff // Delete the edge between BB and RemovedSucc in the DominatorTree, iff
@ -242,7 +242,8 @@ static bool eliminateCondBranches_v3(Function &F, DominatorTree &DT) {
// a new unconditional branch to the selected successor and removing the // a new unconditional branch to the selected successor and removing the
// conditional one. // conditional one.
BranchInst *NewBranch = BranchInst::Create(TakenSucc, BB.getTerminator()); BranchInst *NewBranch =
BranchInst::Create(TakenSucc, BB.getTerminator()->getIterator());
BB.getTerminator()->eraseFromParent(); BB.getTerminator()->eraseFromParent();
// Delete the edge between BB and RemovedSucc in the DominatorTree, iff // Delete the edge between BB and RemovedSucc in the DominatorTree, iff

View File

@ -58,17 +58,9 @@ class UnaryInstruction : public Instruction {
constexpr static IntrusiveOperandsAllocMarker AllocMarker{1}; constexpr static IntrusiveOperandsAllocMarker AllocMarker{1};
protected: protected:
UnaryInstruction(Type *Ty, unsigned iType, Value *V, BasicBlock::iterator IB)
: Instruction(Ty, iType, AllocMarker, IB) {
Op<0>() = V;
}
UnaryInstruction(Type *Ty, unsigned iType, Value *V, UnaryInstruction(Type *Ty, unsigned iType, Value *V,
Instruction *IB = nullptr) InsertPosition InsertBefore = nullptr)
: Instruction(Ty, iType, AllocMarker, IB) { : Instruction(Ty, iType, AllocMarker, InsertBefore) {
Op<0>() = V;
}
UnaryInstruction(Type *Ty, unsigned iType, Value *V, BasicBlock *IAE)
: Instruction(Ty, iType, AllocMarker, IAE) {
Op<0>() = V; Op<0>() = V;
} }
@ -130,27 +122,15 @@ public:
/// These methods just forward to Create, and are useful when you /// These methods just forward to Create, and are useful when you
/// statically know what type of instruction you're going to create. These /// statically know what type of instruction you're going to create. These
/// helpers just save some typing. /// helpers just save some typing.
#define HANDLE_UNARY_INST(N, OPC, CLASS) \ #define HANDLE_UNARY_INST(N, OPC, CLASS) \
static UnaryOperator *Create##OPC(Value *V, const Twine &Name = "") {\ static UnaryOperator *Create##OPC(Value *V, const Twine &Name = "") { \
return Create(Instruction::OPC, V, Name);\ return Create(Instruction::OPC, V, Name); \
} }
#include "llvm/IR/Instruction.def" #include "llvm/IR/Instruction.def"
#define HANDLE_UNARY_INST(N, OPC, CLASS) \ #define HANDLE_UNARY_INST(N, OPC, CLASS) \
static UnaryOperator *Create##OPC(Value *V, const Twine &Name, \ static UnaryOperator *Create##OPC(Value *V, const Twine &Name, \
BasicBlock *BB) {\ InsertPosition InsertBefore = nullptr) { \
return Create(Instruction::OPC, V, Name, BB);\ return Create(Instruction::OPC, V, Name, InsertBefore); \
}
#include "llvm/IR/Instruction.def"
#define HANDLE_UNARY_INST(N, OPC, CLASS) \
static UnaryOperator *Create##OPC(Value *V, const Twine &Name, \
Instruction *I) {\
return Create(Instruction::OPC, V, Name, I);\
}
#include "llvm/IR/Instruction.def"
#define HANDLE_UNARY_INST(N, OPC, CLASS) \
static UnaryOperator *Create##OPC(Value *V, const Twine &Name, \
BasicBlock::iterator It) {\
return Create(Instruction::OPC, V, Name, It);\
} }
#include "llvm/IR/Instruction.def" #include "llvm/IR/Instruction.def"
@ -221,28 +201,16 @@ public:
/// These methods just forward to Create, and are useful when you /// These methods just forward to Create, and are useful when you
/// statically know what type of instruction you're going to create. These /// statically know what type of instruction you're going to create. These
/// helpers just save some typing. /// helpers just save some typing.
#define HANDLE_BINARY_INST(N, OPC, CLASS) \ #define HANDLE_BINARY_INST(N, OPC, CLASS) \
static BinaryOperator *Create##OPC(Value *V1, Value *V2, \ static BinaryOperator *Create##OPC(Value *V1, Value *V2, \
const Twine &Name = "") {\ const Twine &Name = "") { \
return Create(Instruction::OPC, V1, V2, Name);\ return Create(Instruction::OPC, V1, V2, Name); \
} }
#include "llvm/IR/Instruction.def" #include "llvm/IR/Instruction.def"
#define HANDLE_BINARY_INST(N, OPC, CLASS) \ #define HANDLE_BINARY_INST(N, OPC, CLASS) \
static BinaryOperator *Create##OPC(Value *V1, Value *V2, \ static BinaryOperator *Create##OPC(Value *V1, Value *V2, const Twine &Name, \
const Twine &Name, BasicBlock *BB) {\ InsertPosition InsertBefore) { \
return Create(Instruction::OPC, V1, V2, Name, BB);\ return Create(Instruction::OPC, V1, V2, Name, InsertBefore); \
}
#include "llvm/IR/Instruction.def"
#define HANDLE_BINARY_INST(N, OPC, CLASS) \
static BinaryOperator *Create##OPC(Value *V1, Value *V2, \
const Twine &Name, Instruction *I) {\
return Create(Instruction::OPC, V1, V2, Name, I);\
}
#include "llvm/IR/Instruction.def"
#define HANDLE_BINARY_INST(N, OPC, CLASS) \
static BinaryOperator *Create##OPC(Value *V1, Value *V2, \
const Twine &Name, BasicBlock::iterator It) {\
return Create(Instruction::OPC, V1, V2, Name, It);\
} }
#include "llvm/IR/Instruction.def" #include "llvm/IR/Instruction.def"
@ -313,21 +281,11 @@ public:
BO->setHasNoSignedWrap(true); BO->setHasNoSignedWrap(true);
return BO; return BO;
} }
static BinaryOperator *CreateNSW(BinaryOps Opc, Value *V1, Value *V2, static BinaryOperator *CreateNSW(BinaryOps Opc, Value *V1, Value *V2,
const Twine &Name, BasicBlock *BB) { const Twine &Name,
BinaryOperator *BO = Create(Opc, V1, V2, Name, BB); InsertPosition InsertBefore) {
BO->setHasNoSignedWrap(true); BinaryOperator *BO = Create(Opc, V1, V2, Name, InsertBefore);
return BO;
}
static BinaryOperator *CreateNSW(BinaryOps Opc, Value *V1, Value *V2,
const Twine &Name, Instruction *I) {
BinaryOperator *BO = Create(Opc, V1, V2, Name, I);
BO->setHasNoSignedWrap(true);
return BO;
}
static BinaryOperator *CreateNSW(BinaryOps Opc, Value *V1, Value *V2,
const Twine &Name, BasicBlock::iterator It) {
BinaryOperator *BO = Create(Opc, V1, V2, Name, It);
BO->setHasNoSignedWrap(true); BO->setHasNoSignedWrap(true);
return BO; return BO;
} }
@ -338,21 +296,11 @@ public:
BO->setHasNoUnsignedWrap(true); BO->setHasNoUnsignedWrap(true);
return BO; return BO;
} }
static BinaryOperator *CreateNUW(BinaryOps Opc, Value *V1, Value *V2, static BinaryOperator *CreateNUW(BinaryOps Opc, Value *V1, Value *V2,
const Twine &Name, BasicBlock *BB) { const Twine &Name,
BinaryOperator *BO = Create(Opc, V1, V2, Name, BB); InsertPosition InsertBefore) {
BO->setHasNoUnsignedWrap(true); BinaryOperator *BO = Create(Opc, V1, V2, Name, InsertBefore);
return BO;
}
static BinaryOperator *CreateNUW(BinaryOps Opc, Value *V1, Value *V2,
const Twine &Name, Instruction *I) {
BinaryOperator *BO = Create(Opc, V1, V2, Name, I);
BO->setHasNoUnsignedWrap(true);
return BO;
}
static BinaryOperator *CreateNUW(BinaryOps Opc, Value *V1, Value *V2,
const Twine &Name, BasicBlock::iterator It) {
BinaryOperator *BO = Create(Opc, V1, V2, Name, It);
BO->setHasNoUnsignedWrap(true); BO->setHasNoUnsignedWrap(true);
return BO; return BO;
} }
@ -363,22 +311,11 @@ public:
BO->setIsExact(true); BO->setIsExact(true);
return BO; return BO;
} }
static BinaryOperator *CreateExact(BinaryOps Opc, Value *V1, Value *V2,
const Twine &Name, BasicBlock *BB) {
BinaryOperator *BO = Create(Opc, V1, V2, Name, BB);
BO->setIsExact(true);
return BO;
}
static BinaryOperator *CreateExact(BinaryOps Opc, Value *V1, Value *V2,
const Twine &Name, Instruction *I) {
BinaryOperator *BO = Create(Opc, V1, V2, Name, I);
BO->setIsExact(true);
return BO;
}
static BinaryOperator *CreateExact(BinaryOps Opc, Value *V1, Value *V2, static BinaryOperator *CreateExact(BinaryOps Opc, Value *V1, Value *V2,
const Twine &Name, const Twine &Name,
BasicBlock::iterator It) { InsertPosition InsertBefore) {
BinaryOperator *BO = Create(Opc, V1, V2, Name, It); BinaryOperator *BO = Create(Opc, V1, V2, Name, InsertBefore);
BO->setIsExact(true); BO->setIsExact(true);
return BO; return BO;
} }
@ -387,13 +324,7 @@ public:
CreateDisjoint(BinaryOps Opc, Value *V1, Value *V2, const Twine &Name = ""); CreateDisjoint(BinaryOps Opc, Value *V1, Value *V2, const Twine &Name = "");
static inline BinaryOperator *CreateDisjoint(BinaryOps Opc, Value *V1, static inline BinaryOperator *CreateDisjoint(BinaryOps Opc, Value *V1,
Value *V2, const Twine &Name, Value *V2, const Twine &Name,
BasicBlock *BB); InsertPosition InsertBefore);
static inline BinaryOperator *CreateDisjoint(BinaryOps Opc, Value *V1,
Value *V2, const Twine &Name,
Instruction *I);
static inline BinaryOperator *CreateDisjoint(BinaryOps Opc, Value *V1,
Value *V2, const Twine &Name,
BasicBlock::iterator It);
#define DEFINE_HELPERS(OPC, NUWNSWEXACT) \ #define DEFINE_HELPERS(OPC, NUWNSWEXACT) \
static BinaryOperator *Create##NUWNSWEXACT##OPC(Value *V1, Value *V2, \ static BinaryOperator *Create##NUWNSWEXACT##OPC(Value *V1, Value *V2, \
@ -401,16 +332,9 @@ public:
return Create##NUWNSWEXACT(Instruction::OPC, V1, V2, Name); \ return Create##NUWNSWEXACT(Instruction::OPC, V1, V2, Name); \
} \ } \
static BinaryOperator *Create##NUWNSWEXACT##OPC( \ static BinaryOperator *Create##NUWNSWEXACT##OPC( \
Value *V1, Value *V2, const Twine &Name, BasicBlock *BB) { \ Value *V1, Value *V2, const Twine &Name, \
return Create##NUWNSWEXACT(Instruction::OPC, V1, V2, Name, BB); \ InsertPosition InsertBefore = nullptr) { \
} \ return Create##NUWNSWEXACT(Instruction::OPC, V1, V2, Name, InsertBefore); \
static BinaryOperator *Create##NUWNSWEXACT##OPC( \
Value *V1, Value *V2, const Twine &Name, Instruction *I) { \
return Create##NUWNSWEXACT(Instruction::OPC, V1, V2, Name, I); \
} \
static BinaryOperator *Create##NUWNSWEXACT##OPC( \
Value *V1, Value *V2, const Twine &Name, BasicBlock::iterator It) { \
return Create##NUWNSWEXACT(Instruction::OPC, V1, V2, Name, It); \
} }
DEFINE_HELPERS(Add, NSW) // CreateNSWAdd DEFINE_HELPERS(Add, NSW) // CreateNSWAdd
@ -501,22 +425,8 @@ BinaryOperator *BinaryOperator::CreateDisjoint(BinaryOps Opc, Value *V1,
} }
BinaryOperator *BinaryOperator::CreateDisjoint(BinaryOps Opc, Value *V1, BinaryOperator *BinaryOperator::CreateDisjoint(BinaryOps Opc, Value *V1,
Value *V2, const Twine &Name, Value *V2, const Twine &Name,
BasicBlock *BB) { InsertPosition InsertBefore) {
BinaryOperator *BO = Create(Opc, V1, V2, Name, BB); BinaryOperator *BO = Create(Opc, V1, V2, Name, InsertBefore);
cast<PossiblyDisjointInst>(BO)->setIsDisjoint(true);
return BO;
}
BinaryOperator *BinaryOperator::CreateDisjoint(BinaryOps Opc, Value *V1,
Value *V2, const Twine &Name,
Instruction *I) {
BinaryOperator *BO = Create(Opc, V1, V2, Name, I);
cast<PossiblyDisjointInst>(BO)->setIsDisjoint(true);
return BO;
}
BinaryOperator *BinaryOperator::CreateDisjoint(BinaryOps Opc, Value *V1,
Value *V2, const Twine &Name,
BasicBlock::iterator It) {
BinaryOperator *BO = Create(Opc, V1, V2, Name, It);
cast<PossiblyDisjointInst>(BO)->setIsDisjoint(true); cast<PossiblyDisjointInst>(BO)->setIsDisjoint(true);
return BO; return BO;
} }

View File

@ -52,8 +52,8 @@ class InsertPosition {
public: public:
InsertPosition(std::nullptr_t) : InsertAt() {} InsertPosition(std::nullptr_t) : InsertAt() {}
// LLVM_DEPRECATED("Use BasicBlock::iterators for insertion instead", LLVM_DEPRECATED("Use BasicBlock::iterators for insertion instead",
// "BasicBlock::iterator") "BasicBlock::iterator")
InsertPosition(Instruction *InsertBefore); InsertPosition(Instruction *InsertBefore);
InsertPosition(BasicBlock *InsertAtEnd); InsertPosition(BasicBlock *InsertAtEnd);
InsertPosition(InstListType::iterator InsertAt) : InsertAt(InsertAt) {} InsertPosition(InstListType::iterator InsertAt) : InsertAt(InsertAt) {}

View File

@ -1362,9 +1362,9 @@ BasicBlock *PHINode::LLVMBBToBB::operator()(llvm::BasicBlock *LLVMBB) const {
PHINode *PHINode::create(Type *Ty, unsigned NumReservedValues, PHINode *PHINode::create(Type *Ty, unsigned NumReservedValues,
Instruction *InsertBefore, Context &Ctx, Instruction *InsertBefore, Context &Ctx,
const Twine &Name) { const Twine &Name) {
llvm::PHINode *NewPHI = llvm::PHINode *NewPHI = llvm::PHINode::Create(
llvm::PHINode::Create(Ty->LLVMTy, NumReservedValues, Name, Ty->LLVMTy, NumReservedValues, Name,
InsertBefore->getTopmostLLVMInstruction()); InsertBefore->getTopmostLLVMInstruction()->getIterator());
return Ctx.createPHINode(NewPHI); return Ctx.createPHINode(NewPHI);
} }