Skip to content

Commit

Permalink
[DebugInfo] Enable deprecation of iterator-insertion methods (#102608)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jmorse authored Sep 20, 2024
1 parent 1808fc1 commit 2f50b28
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 132 deletions.
7 changes: 4 additions & 3 deletions llvm/examples/IRTransforms/SimplifyCFG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ static bool eliminateCondBranches_v1(Function &F) {
// Replace the conditional branch with an unconditional one, by creating
// a new unconditional branch to the selected successor and removing the
// conditional one.
BranchInst::Create(BI->getSuccessor(CI->isZero()), BI);
BranchInst::Create(BI->getSuccessor(CI->isZero()), BI->getIterator());
BI->eraseFromParent();
Changed = true;
}
Expand Down Expand Up @@ -195,7 +195,7 @@ static bool eliminateCondBranches_v2(Function &F, DominatorTree &DT) {
// a new unconditional branch to the selected successor and removing the
// conditional one.
BranchInst *NewBranch =
BranchInst::Create(BI->getSuccessor(CI->isZero()), BI);
BranchInst::Create(BI->getSuccessor(CI->isZero()), BI->getIterator());
BI->eraseFromParent();

// Delete the edge between BB and RemovedSucc in the DominatorTree, iff
Expand Down Expand Up @@ -242,7 +242,8 @@ static bool eliminateCondBranches_v3(Function &F, DominatorTree &DT) {
// a new unconditional branch to the selected successor and removing the
// conditional one.

BranchInst *NewBranch = BranchInst::Create(TakenSucc, BB.getTerminator());
BranchInst *NewBranch =
BranchInst::Create(TakenSucc, BB.getTerminator()->getIterator());
BB.getTerminator()->eraseFromParent();

// Delete the edge between BB and RemovedSucc in the DominatorTree, iff
Expand Down
158 changes: 34 additions & 124 deletions llvm/include/llvm/IR/InstrTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,9 @@ class UnaryInstruction : public Instruction {
constexpr static IntrusiveOperandsAllocMarker AllocMarker{1};

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,
Instruction *IB = nullptr)
: Instruction(Ty, iType, AllocMarker, IB) {
Op<0>() = V;
}
UnaryInstruction(Type *Ty, unsigned iType, Value *V, BasicBlock *IAE)
: Instruction(Ty, iType, AllocMarker, IAE) {
InsertPosition InsertBefore = nullptr)
: Instruction(Ty, iType, AllocMarker, InsertBefore) {
Op<0>() = V;
}

Expand Down Expand Up @@ -130,27 +122,15 @@ class UnaryOperator : public UnaryInstruction {
/// These methods just forward to Create, and are useful when you
/// statically know what type of instruction you're going to create. These
/// helpers just save some typing.
#define HANDLE_UNARY_INST(N, OPC, CLASS) \
static UnaryOperator *Create##OPC(Value *V, const Twine &Name = "") {\
return Create(Instruction::OPC, V, Name);\
}
#include "llvm/IR/Instruction.def"
#define HANDLE_UNARY_INST(N, OPC, CLASS) \
static UnaryOperator *Create##OPC(Value *V, const Twine &Name, \
BasicBlock *BB) {\
return Create(Instruction::OPC, V, Name, BB);\
}
#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);\
#define HANDLE_UNARY_INST(N, OPC, CLASS) \
static UnaryOperator *Create##OPC(Value *V, const Twine &Name = "") { \
return Create(Instruction::OPC, V, Name); \
}
#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);\
#define HANDLE_UNARY_INST(N, OPC, CLASS) \
static UnaryOperator *Create##OPC(Value *V, const Twine &Name, \
InsertPosition InsertBefore = nullptr) { \
return Create(Instruction::OPC, V, Name, InsertBefore); \
}
#include "llvm/IR/Instruction.def"

Expand Down Expand Up @@ -221,28 +201,16 @@ class BinaryOperator : public Instruction {
/// These methods just forward to Create, and are useful when you
/// statically know what type of instruction you're going to create. These
/// helpers just save some typing.
#define HANDLE_BINARY_INST(N, OPC, CLASS) \
static BinaryOperator *Create##OPC(Value *V1, Value *V2, \
const Twine &Name = "") {\
return Create(Instruction::OPC, V1, V2, Name);\
#define HANDLE_BINARY_INST(N, OPC, CLASS) \
static BinaryOperator *Create##OPC(Value *V1, Value *V2, \
const Twine &Name = "") { \
return Create(Instruction::OPC, V1, V2, Name); \
}
#include "llvm/IR/Instruction.def"
#define HANDLE_BINARY_INST(N, OPC, CLASS) \
static BinaryOperator *Create##OPC(Value *V1, Value *V2, \
const Twine &Name, BasicBlock *BB) {\
return Create(Instruction::OPC, V1, V2, Name, BB);\
}
#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);\
#define HANDLE_BINARY_INST(N, OPC, CLASS) \
static BinaryOperator *Create##OPC(Value *V1, Value *V2, const Twine &Name, \
InsertPosition InsertBefore) { \
return Create(Instruction::OPC, V1, V2, Name, InsertBefore); \
}
#include "llvm/IR/Instruction.def"

Expand Down Expand Up @@ -313,21 +281,11 @@ class BinaryOperator : public Instruction {
BO->setHasNoSignedWrap(true);
return BO;
}

static BinaryOperator *CreateNSW(BinaryOps Opc, Value *V1, Value *V2,
const Twine &Name, BasicBlock *BB) {
BinaryOperator *BO = Create(Opc, V1, V2, Name, BB);
BO->setHasNoSignedWrap(true);
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);
const Twine &Name,
InsertPosition InsertBefore) {
BinaryOperator *BO = Create(Opc, V1, V2, Name, InsertBefore);
BO->setHasNoSignedWrap(true);
return BO;
}
Expand All @@ -338,21 +296,11 @@ class BinaryOperator : public Instruction {
BO->setHasNoUnsignedWrap(true);
return BO;
}

static BinaryOperator *CreateNUW(BinaryOps Opc, Value *V1, Value *V2,
const Twine &Name, BasicBlock *BB) {
BinaryOperator *BO = Create(Opc, V1, V2, Name, BB);
BO->setHasNoUnsignedWrap(true);
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);
const Twine &Name,
InsertPosition InsertBefore) {
BinaryOperator *BO = Create(Opc, V1, V2, Name, InsertBefore);
BO->setHasNoUnsignedWrap(true);
return BO;
}
Expand All @@ -363,22 +311,11 @@ class BinaryOperator : public Instruction {
BO->setIsExact(true);
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,
const Twine &Name,
BasicBlock::iterator It) {
BinaryOperator *BO = Create(Opc, V1, V2, Name, It);
InsertPosition InsertBefore) {
BinaryOperator *BO = Create(Opc, V1, V2, Name, InsertBefore);
BO->setIsExact(true);
return BO;
}
Expand All @@ -387,30 +324,17 @@ class BinaryOperator : public Instruction {
CreateDisjoint(BinaryOps Opc, Value *V1, Value *V2, const Twine &Name = "");
static inline BinaryOperator *CreateDisjoint(BinaryOps Opc, Value *V1,
Value *V2, const Twine &Name,
BasicBlock *BB);
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);
InsertPosition InsertBefore);

#define DEFINE_HELPERS(OPC, NUWNSWEXACT) \
static BinaryOperator *Create##NUWNSWEXACT##OPC(Value *V1, Value *V2, \
const Twine &Name = "") { \
return Create##NUWNSWEXACT(Instruction::OPC, V1, V2, Name); \
} \
static BinaryOperator *Create##NUWNSWEXACT##OPC( \
Value *V1, Value *V2, const Twine &Name, BasicBlock *BB) { \
return Create##NUWNSWEXACT(Instruction::OPC, V1, V2, Name, BB); \
} \
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); \
Value *V1, Value *V2, const Twine &Name, \
InsertPosition InsertBefore = nullptr) { \
return Create##NUWNSWEXACT(Instruction::OPC, V1, V2, Name, InsertBefore); \
}

DEFINE_HELPERS(Add, NSW) // CreateNSWAdd
Expand Down Expand Up @@ -501,22 +425,8 @@ BinaryOperator *BinaryOperator::CreateDisjoint(BinaryOps Opc, Value *V1,
}
BinaryOperator *BinaryOperator::CreateDisjoint(BinaryOps Opc, Value *V1,
Value *V2, const Twine &Name,
BasicBlock *BB) {
BinaryOperator *BO = Create(Opc, V1, V2, Name, BB);
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);
InsertPosition InsertBefore) {
BinaryOperator *BO = Create(Opc, V1, V2, Name, InsertBefore);
cast<PossiblyDisjointInst>(BO)->setIsDisjoint(true);
return BO;
}
Expand Down
4 changes: 2 additions & 2 deletions llvm/include/llvm/IR/Instruction.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ class InsertPosition {

public:
InsertPosition(std::nullptr_t) : InsertAt() {}
// LLVM_DEPRECATED("Use BasicBlock::iterators for insertion instead",
// "BasicBlock::iterator")
LLVM_DEPRECATED("Use BasicBlock::iterators for insertion instead",
"BasicBlock::iterator")
InsertPosition(Instruction *InsertBefore);
InsertPosition(BasicBlock *InsertAtEnd);
InsertPosition(InstListType::iterator InsertAt) : InsertAt(InsertAt) {}
Expand Down
6 changes: 3 additions & 3 deletions llvm/lib/SandboxIR/SandboxIR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1362,9 +1362,9 @@ BasicBlock *PHINode::LLVMBBToBB::operator()(llvm::BasicBlock *LLVMBB) const {
PHINode *PHINode::create(Type *Ty, unsigned NumReservedValues,
Instruction *InsertBefore, Context &Ctx,
const Twine &Name) {
llvm::PHINode *NewPHI =
llvm::PHINode::Create(Ty->LLVMTy, NumReservedValues, Name,
InsertBefore->getTopmostLLVMInstruction());
llvm::PHINode *NewPHI = llvm::PHINode::Create(
Ty->LLVMTy, NumReservedValues, Name,
InsertBefore->getTopmostLLVMInstruction()->getIterator());
return Ctx.createPHINode(NewPHI);
}

Expand Down

0 comments on commit 2f50b28

Please sign in to comment.