Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 6 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -1357,9 +1357,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
Loading