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

Jeremy Morse via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 13 08:46:42 PDT 2024


https://github.com/jmorse updated https://github.com/llvm/llvm-project/pull/102608

>From bb3f8509ca64d5845956e28c2a0b0435d6633f0a Mon Sep 17 00:00:00 2001
From: Jeremy Morse <jeremy.morse at sony.com>
Date: Mon, 5 Aug 2024 16:25:11 +0100
Subject: [PATCH 1/5] [DebugInfo] Enable deprecation of iterator-insertion
 methods

Propagate to some other utilities that shouldn't be used, but we don't want
to delete just yet. There's some final cleanup in the LLVM Examples which
usually don't get built: otherwise everything in the monorepo seems to build
cleanly.

I've also added a cast to the default-nullptr PHINode::Create method. Its
default-form seems pretty widespread, doing this causes most uses to take
the "Being inserted in a BasicBlock that happens to be absent" path as
opposed to the "Being inserted with an instruction pointer, which is
deprecated" path. We should still get deprecation warnings if anyone passes
in an instruction pointer directly.
---
 llvm/examples/IRTransforms/SimplifyCFG.cpp |  6 +++---
 llvm/include/llvm/IR/InstrTypes.h          | 16 ++++++++++++++++
 llvm/include/llvm/IR/Instruction.h         |  4 ++--
 llvm/include/llvm/IR/Instructions.h        |  2 +-
 llvm/lib/SandboxIR/SandboxIR.cpp           |  2 +-
 5 files changed, 23 insertions(+), 7 deletions(-)

diff --git a/llvm/examples/IRTransforms/SimplifyCFG.cpp b/llvm/examples/IRTransforms/SimplifyCFG.cpp
index d6364385eb1ec9..7df646c64c7f19 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,7 @@ 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 afae564bf022d2..638ac66537e73a 100644
--- a/llvm/include/llvm/IR/InstrTypes.h
+++ b/llvm/include/llvm/IR/InstrTypes.h
@@ -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")
   UnaryInstruction(Type *Ty, unsigned iType, Value *V,
                    Instruction *IB = nullptr)
     : Instruction(Ty, iType, &Op<0>(), 1, IB) {
@@ -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);\
@@ -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);\
@@ -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);
@@ -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);
@@ -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);
@@ -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);             \
@@ -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) {
diff --git a/llvm/include/llvm/IR/Instruction.h b/llvm/include/llvm/IR/Instruction.h
index c27572300d5063..569346f037b554 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/include/llvm/IR/Instructions.h b/llvm/include/llvm/IR/Instructions.h
index 968737a843e292..c3c156e2663456 100644
--- a/llvm/include/llvm/IR/Instructions.h
+++ b/llvm/include/llvm/IR/Instructions.h
@@ -2537,7 +2537,7 @@ class PHINode : public Instruction {
   /// edges that this phi node will have (use 0 if you really have no idea).
   static PHINode *Create(Type *Ty, unsigned NumReservedValues,
                          const Twine &NameStr = "",
-                         InsertPosition InsertBefore = nullptr) {
+                         InsertPosition InsertBefore = (BasicBlock*)nullptr) {
     return new PHINode(Ty, NumReservedValues, NameStr, InsertBefore);
   }
 
diff --git a/llvm/lib/SandboxIR/SandboxIR.cpp b/llvm/lib/SandboxIR/SandboxIR.cpp
index 2cb76fc89d9b4d..e48f025ceaf820 100644
--- a/llvm/lib/SandboxIR/SandboxIR.cpp
+++ b/llvm/lib/SandboxIR/SandboxIR.cpp
@@ -1142,7 +1142,7 @@ 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);
 }
 

>From d6a2cd107022db27c8600a5ea876dd5a54183202 Mon Sep 17 00:00:00 2001
From: Jeremy Morse <jeremy.morse at sony.com>
Date: Fri, 9 Aug 2024 15:39:09 +0100
Subject: [PATCH 2/5] Squelch apparently un-necessary cast

---
 llvm/include/llvm/IR/Instructions.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/include/llvm/IR/Instructions.h b/llvm/include/llvm/IR/Instructions.h
index c3c156e2663456..968737a843e292 100644
--- a/llvm/include/llvm/IR/Instructions.h
+++ b/llvm/include/llvm/IR/Instructions.h
@@ -2537,7 +2537,7 @@ class PHINode : public Instruction {
   /// edges that this phi node will have (use 0 if you really have no idea).
   static PHINode *Create(Type *Ty, unsigned NumReservedValues,
                          const Twine &NameStr = "",
-                         InsertPosition InsertBefore = (BasicBlock*)nullptr) {
+                         InsertPosition InsertBefore = nullptr) {
     return new PHINode(Ty, NumReservedValues, NameStr, InsertBefore);
   }
 

>From d083c064b2edb1604adf39b8d7dd5d0d78d0755a Mon Sep 17 00:00:00 2001
From: Jeremy Morse <jeremy.morse at sony.com>
Date: Fri, 9 Aug 2024 15:41:24 +0100
Subject: [PATCH 3/5] Clang-format

---
 llvm/examples/IRTransforms/SimplifyCFG.cpp |  3 ++-
 llvm/include/llvm/IR/InstrTypes.h          | 12 ++++++------
 llvm/include/llvm/IR/Instruction.h         |  2 +-
 llvm/lib/SandboxIR/SandboxIR.cpp           |  3 ++-
 4 files changed, 11 insertions(+), 9 deletions(-)

diff --git a/llvm/examples/IRTransforms/SimplifyCFG.cpp b/llvm/examples/IRTransforms/SimplifyCFG.cpp
index 7df646c64c7f19..a37060cedb4a77 100644
--- a/llvm/examples/IRTransforms/SimplifyCFG.cpp
+++ b/llvm/examples/IRTransforms/SimplifyCFG.cpp
@@ -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()->getIterator());
+    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 638ac66537e73a..503bf3e95b917e 100644
--- a/llvm/include/llvm/IR/InstrTypes.h
+++ b/llvm/include/llvm/IR/InstrTypes.h
@@ -61,7 +61,7 @@ class UnaryInstruction : public Instruction {
     Op<0>() = V;
   }
   LLVM_DEPRECATED("Use BasicBlock::iterators for insertion instead",
-    "BasicBlock::iterator")
+                  "BasicBlock::iterator")
   UnaryInstruction(Type *Ty, unsigned iType, Value *V,
                    Instruction *IB = nullptr)
     : Instruction(Ty, iType, &Op<0>(), 1, IB) {
@@ -322,7 +322,7 @@ class BinaryOperator : public Instruction {
     return BO;
   }
   LLVM_DEPRECATED("Use BasicBlock::iterators for insertion instead",
-    "BasicBlock::iterator")
+                  "BasicBlock::iterator")
   static BinaryOperator *CreateNSW(BinaryOps Opc, Value *V1, Value *V2,
                                    const Twine &Name, Instruction *I) {
     BinaryOperator *BO = Create(Opc, V1, V2, Name, I);
@@ -349,7 +349,7 @@ class BinaryOperator : public Instruction {
     return BO;
   }
   LLVM_DEPRECATED("Use BasicBlock::iterators for insertion instead",
-    "BasicBlock::iterator")
+                  "BasicBlock::iterator")
   static BinaryOperator *CreateNUW(BinaryOps Opc, Value *V1, Value *V2,
                                    const Twine &Name, Instruction *I) {
     BinaryOperator *BO = Create(Opc, V1, V2, Name, I);
@@ -376,7 +376,7 @@ class BinaryOperator : public Instruction {
     return BO;
   }
   LLVM_DEPRECATED("Use BasicBlock::iterators for insertion instead",
-    "BasicBlock::iterator")
+                  "BasicBlock::iterator")
   static BinaryOperator *CreateExact(BinaryOps Opc, Value *V1, Value *V2,
                                      const Twine &Name, Instruction *I) {
     BinaryOperator *BO = Create(Opc, V1, V2, Name, I);
@@ -413,7 +413,7 @@ class BinaryOperator : public Instruction {
     return Create##NUWNSWEXACT(Instruction::OPC, V1, V2, Name, BB);            \
   }                                                                            \
   LLVM_DEPRECATED("Use BasicBlock::iterators for insertion instead",           \
-      "BasicBlock::iterator")                                                  \
+                  "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);             \
@@ -517,7 +517,7 @@ BinaryOperator *BinaryOperator::CreateDisjoint(BinaryOps Opc, Value *V1,
   return BO;
 }
 LLVM_DEPRECATED("Use BasicBlock::iterators for insertion instead",
-"BasicBlock::iterator")
+                "BasicBlock::iterator")
 BinaryOperator *BinaryOperator::CreateDisjoint(BinaryOps Opc, Value *V1,
                                                Value *V2, const Twine &Name,
                                                Instruction *I) {
diff --git a/llvm/include/llvm/IR/Instruction.h b/llvm/include/llvm/IR/Instruction.h
index 569346f037b554..f29c7dcd7f29b3 100644
--- a/llvm/include/llvm/IR/Instruction.h
+++ b/llvm/include/llvm/IR/Instruction.h
@@ -53,7 +53,7 @@ class InsertPosition {
 public:
   InsertPosition(std::nullptr_t) : InsertAt() {}
   LLVM_DEPRECATED("Use BasicBlock::iterators for insertion instead",
-    "BasicBlock::iterator")
+                  "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 e48f025ceaf820..64b16fbd80160d 100644
--- a/llvm/lib/SandboxIR/SandboxIR.cpp
+++ b/llvm/lib/SandboxIR/SandboxIR.cpp
@@ -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()->getIterator());
+      Ty, NumReservedValues, Name,
+      InsertBefore->getTopmostLLVMInstruction()->getIterator());
   return Ctx.createPHINode(NewPHI);
 }
 

>From 0d12a8e40bb45c5379d08e498756b0df077db33d Mon Sep 17 00:00:00 2001
From: Jeremy Morse <jeremy.morse at sony.com>
Date: Fri, 13 Sep 2024 15:11:47 +0100
Subject: [PATCH 4/5] Switch to InsertPosition taking inst constructors

---
 llvm/include/llvm/IR/InstrTypes.h | 169 ++++++------------------------
 1 file changed, 32 insertions(+), 137 deletions(-)

diff --git a/llvm/include/llvm/IR/InstrTypes.h b/llvm/include/llvm/IR/InstrTypes.h
index 8ed2051170b452..ffbc2ce954b2a2 100644
--- a/llvm/include/llvm/IR/InstrTypes.h
+++ b/llvm/include/llvm/IR/InstrTypes.h
@@ -58,19 +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;
-  }
-  LLVM_DEPRECATED("Use BasicBlock::iterators for insertion instead",
-                  "BasicBlock::iterator")
   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;
   }
 
@@ -137,24 +127,10 @@ class UnaryOperator : public UnaryInstruction {
     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) \
-  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);\
-  }
-#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"
 
@@ -231,24 +207,10 @@ class BinaryOperator : public Instruction {
     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) \
-  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);\
-  }
-#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"
 
@@ -319,23 +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;
-  }
-  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);
-    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;
   }
@@ -346,23 +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;
-  }
-  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);
-    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;
   }
@@ -373,39 +311,20 @@ 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;
-  }
-  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);
-    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;
   }
 
   static inline BinaryOperator *
   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);
+  static inline BinaryOperator *
+  CreateDisjoint(BinaryOps Opc, Value *V1, Value *V2, const Twine &Name,
+                 InsertPosition InsertBefore);
 
 #define DEFINE_HELPERS(OPC, NUWNSWEXACT)                                       \
   static BinaryOperator *Create##NUWNSWEXACT##OPC(Value *V1, Value *V2,        \
@@ -413,18 +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);            \
-  }                                                                            \
-  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);             \
-  }                                                                            \
-  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
@@ -513,26 +423,11 @@ BinaryOperator *BinaryOperator::CreateDisjoint(BinaryOps Opc, Value *V1,
   cast<PossiblyDisjointInst>(BO)->setIsDisjoint(true);
   return BO;
 }
-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;
-}
-LLVM_DEPRECATED("Use BasicBlock::iterators for insertion instead",
-                "BasicBlock::iterator")
-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);
+BinaryOperator *
+BinaryOperator::CreateDisjoint(BinaryOps Opc, Value *V1, Value *V2,
+                               const Twine &Name,
+                               InsertPosition InsertBefore) {
+  BinaryOperator *BO = Create(Opc, V1, V2, Name, InsertBefore);
   cast<PossiblyDisjointInst>(BO)->setIsDisjoint(true);
   return BO;
 }

>From b4335742eba9bacdf10530f85e8508dd3d1d3b5a Mon Sep 17 00:00:00 2001
From: Jeremy Morse <jeremy.morse at sony.com>
Date: Fri, 13 Sep 2024 16:46:08 +0100
Subject: [PATCH 5/5] the proverbial clang-format

---
 llvm/include/llvm/IR/InstrTypes.h | 29 ++++++++++++++---------------
 llvm/lib/SandboxIR/SandboxIR.cpp  |  6 +++---
 2 files changed, 17 insertions(+), 18 deletions(-)

diff --git a/llvm/include/llvm/IR/InstrTypes.h b/llvm/include/llvm/IR/InstrTypes.h
index ffbc2ce954b2a2..4852f64d0977fb 100644
--- a/llvm/include/llvm/IR/InstrTypes.h
+++ b/llvm/include/llvm/IR/InstrTypes.h
@@ -122,9 +122,9 @@ 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);\
+#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)                                       \
@@ -201,15 +201,15 @@ 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,  \
-                                     InsertPosition InsertBefore) {  \
+                                     InsertPosition InsertBefore) {            \
     return Create(Instruction::OPC, V1, V2, Name, InsertBefore);               \
   }
 #include "llvm/IR/Instruction.def"
@@ -322,9 +322,9 @@ class BinaryOperator : public Instruction {
 
   static inline BinaryOperator *
   CreateDisjoint(BinaryOps Opc, Value *V1, Value *V2, const Twine &Name = "");
-  static inline BinaryOperator *
-  CreateDisjoint(BinaryOps Opc, Value *V1, Value *V2, const Twine &Name,
-                 InsertPosition InsertBefore);
+  static inline BinaryOperator *CreateDisjoint(BinaryOps Opc, Value *V1,
+                                               Value *V2, const Twine &Name,
+                                               InsertPosition InsertBefore);
 
 #define DEFINE_HELPERS(OPC, NUWNSWEXACT)                                       \
   static BinaryOperator *Create##NUWNSWEXACT##OPC(Value *V1, Value *V2,        \
@@ -423,10 +423,9 @@ BinaryOperator *BinaryOperator::CreateDisjoint(BinaryOps Opc, Value *V1,
   cast<PossiblyDisjointInst>(BO)->setIsDisjoint(true);
   return BO;
 }
-BinaryOperator *
-BinaryOperator::CreateDisjoint(BinaryOps Opc, Value *V1, Value *V2,
-                               const Twine &Name,
-                               InsertPosition InsertBefore) {
+BinaryOperator *BinaryOperator::CreateDisjoint(BinaryOps Opc, Value *V1,
+                                               Value *V2, const Twine &Name,
+                                               InsertPosition InsertBefore) {
   BinaryOperator *BO = Create(Opc, V1, V2, Name, InsertBefore);
   cast<PossiblyDisjointInst>(BO)->setIsDisjoint(true);
   return BO;
diff --git a/llvm/lib/SandboxIR/SandboxIR.cpp b/llvm/lib/SandboxIR/SandboxIR.cpp
index 0aa318d315f3ee..717d63e61c6377 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()->getIterator());
+  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