Skip to content

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

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

Merged
merged 6 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
16 changes: 16 additions & 0 deletions llvm/include/llvm/IR/InstrTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ class UnaryInstruction : public Instruction {
: Instruction(Ty, iType, &Op<0>(), 1, IB) {
Op<0>() = V;
}
LLVM_DEPRECATED("Use BasicBlock::iterators for insertion instead",
"BasicBlock::iterator")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these (and the other cases in this file where you've added LLVM_DEPRECATED) could be replaced with InsertPosition arguments - especially the HANDLE_ cases, where we have 3 different methods for each type, which all forward to the same InsertPosition fn underneath. Not sure why I missed these the first time, but (as long as it works) it should probably be done now.

UnaryInstruction(Type *Ty, unsigned iType, Value *V,
Instruction *IB = nullptr)
: Instruction(Ty, iType, &Op<0>(), 1, IB) {
Expand Down Expand Up @@ -140,6 +142,8 @@ class UnaryOperator : public UnaryInstruction {
}
#include "llvm/IR/Instruction.def"
#define HANDLE_UNARY_INST(N, OPC, CLASS) \
LLVM_DEPRECATED("Use BasicBlock::iterators for insertion instead", \
"BasicBlock::iterator") \
static UnaryOperator *Create##OPC(Value *V, const Twine &Name, \
Instruction *I) {\
return Create(Instruction::OPC, V, Name, I);\
Expand Down Expand Up @@ -230,6 +234,8 @@ class BinaryOperator : public Instruction {
}
#include "llvm/IR/Instruction.def"
#define HANDLE_BINARY_INST(N, OPC, CLASS) \
LLVM_DEPRECATED("Use BasicBlock::iterators for insertion instead", \
"BasicBlock::iterator") \
static BinaryOperator *Create##OPC(Value *V1, Value *V2, \
const Twine &Name, Instruction *I) {\
return Create(Instruction::OPC, V1, V2, Name, I);\
Expand Down Expand Up @@ -315,6 +321,8 @@ class BinaryOperator : public Instruction {
BO->setHasNoSignedWrap(true);
return BO;
}
LLVM_DEPRECATED("Use BasicBlock::iterators for insertion instead",
"BasicBlock::iterator")
static BinaryOperator *CreateNSW(BinaryOps Opc, Value *V1, Value *V2,
const Twine &Name, Instruction *I) {
BinaryOperator *BO = Create(Opc, V1, V2, Name, I);
Expand All @@ -340,6 +348,8 @@ class BinaryOperator : public Instruction {
BO->setHasNoUnsignedWrap(true);
return BO;
}
LLVM_DEPRECATED("Use BasicBlock::iterators for insertion instead",
"BasicBlock::iterator")
static BinaryOperator *CreateNUW(BinaryOps Opc, Value *V1, Value *V2,
const Twine &Name, Instruction *I) {
BinaryOperator *BO = Create(Opc, V1, V2, Name, I);
Expand All @@ -365,6 +375,8 @@ class BinaryOperator : public Instruction {
BO->setIsExact(true);
return BO;
}
LLVM_DEPRECATED("Use BasicBlock::iterators for insertion instead",
"BasicBlock::iterator")
static BinaryOperator *CreateExact(BinaryOps Opc, Value *V1, Value *V2,
const Twine &Name, Instruction *I) {
BinaryOperator *BO = Create(Opc, V1, V2, Name, I);
Expand Down Expand Up @@ -400,6 +412,8 @@ class BinaryOperator : public Instruction {
Value *V1, Value *V2, const Twine &Name, BasicBlock *BB) { \
return Create##NUWNSWEXACT(Instruction::OPC, V1, V2, Name, BB); \
} \
LLVM_DEPRECATED("Use BasicBlock::iterators for insertion instead", \
"BasicBlock::iterator") \
static BinaryOperator *Create##NUWNSWEXACT##OPC( \
Value *V1, Value *V2, const Twine &Name, Instruction *I) { \
return Create##NUWNSWEXACT(Instruction::OPC, V1, V2, Name, I); \
Expand Down Expand Up @@ -502,6 +516,8 @@ BinaryOperator *BinaryOperator::CreateDisjoint(BinaryOps Opc, Value *V1,
cast<PossiblyDisjointInst>(BO)->setIsDisjoint(true);
return BO;
}
LLVM_DEPRECATED("Use BasicBlock::iterators for insertion instead",
"BasicBlock::iterator")
BinaryOperator *BinaryOperator::CreateDisjoint(BinaryOps Opc, Value *V1,
Value *V2, const Twine &Name,
Instruction *I) {
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
3 changes: 2 additions & 1 deletion llvm/lib/SandboxIR/SandboxIR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1142,7 +1142,8 @@ PHINode *PHINode::create(Type *Ty, unsigned NumReservedValues,
Instruction *InsertBefore, Context &Ctx,
const Twine &Name) {
llvm::PHINode *NewPHI = llvm::PHINode::Create(
Ty, NumReservedValues, Name, InsertBefore->getTopmostLLVMInstruction());
Ty, NumReservedValues, Name,
InsertBefore->getTopmostLLVMInstruction()->getIterator());
return Ctx.createPHINode(NewPHI);
}

Expand Down
Loading