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

via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 20 05:56:47 PDT 2024


Author: Jeremy Morse
Date: 2024-09-20T13:56:43+01:00
New Revision: 2f50b280dc8e995ef67ad31a5f71adc4c270890d

URL: https://github.com/llvm/llvm-project/commit/2f50b280dc8e995ef67ad31a5f71adc4c270890d
DIFF: https://github.com/llvm/llvm-project/commit/2f50b280dc8e995ef67ad31a5f71adc4c270890d.diff

LOG: [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.

Added: 
    

Modified: 
    llvm/examples/IRTransforms/SimplifyCFG.cpp
    llvm/include/llvm/IR/InstrTypes.h
    llvm/include/llvm/IR/Instruction.h
    llvm/lib/SandboxIR/SandboxIR.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/examples/IRTransforms/SimplifyCFG.cpp b/llvm/examples/IRTransforms/SimplifyCFG.cpp
index d6364385eb1ec9..a37060cedb4a77 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 4720533bac8598..4852f64d0977fb 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<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;
 }

diff  --git a/llvm/include/llvm/IR/Instruction.h b/llvm/include/llvm/IR/Instruction.h
index 108f44e7c5ad32..4a1e66a90831c8 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 fa151aeeefa76d..fb095852d86ef3 100644
--- a/llvm/lib/SandboxIR/SandboxIR.cpp
+++ b/llvm/lib/SandboxIR/SandboxIR.cpp
@@ -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);
 }
 


        


More information about the llvm-commits mailing list