diff --git a/llvm/examples/IRTransforms/SimplifyCFG.cpp b/llvm/examples/IRTransforms/SimplifyCFG.cpp index d6364385eb1ec..a37060cedb4a7 100644 --- a/llvm/examples/IRTransforms/SimplifyCFG.cpp +++ b/llvm/examples/IRTransforms/SimplifyCFG.cpp @@ -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; } @@ -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 @@ -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 diff --git a/llvm/include/llvm/IR/InstrTypes.h b/llvm/include/llvm/IR/InstrTypes.h index 4720533bac859..4852f64d0977f 100644 --- a/llvm/include/llvm/IR/InstrTypes.h +++ b/llvm/include/llvm/IR/InstrTypes.h @@ -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; } @@ -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" @@ -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" @@ -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; } @@ -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; } @@ -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; } @@ -387,13 +324,7 @@ 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, \ @@ -401,16 +332,9 @@ class BinaryOperator : public Instruction { 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 @@ -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(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(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(BO)->setIsDisjoint(true); return BO; } diff --git a/llvm/include/llvm/IR/Instruction.h b/llvm/include/llvm/IR/Instruction.h index a12d5d9d8fe94..be841025839cd 100644 --- a/llvm/include/llvm/IR/Instruction.h +++ b/llvm/include/llvm/IR/Instruction.h @@ -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) {} diff --git a/llvm/lib/SandboxIR/SandboxIR.cpp b/llvm/lib/SandboxIR/SandboxIR.cpp index 05d05f7ed10fb..717d63e61c637 100644 --- a/llvm/lib/SandboxIR/SandboxIR.cpp +++ b/llvm/lib/SandboxIR/SandboxIR.cpp @@ -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); }