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

[RemoveDIs] Add iterator-taking constructors and Create methods #82778

Merged
merged 1 commit into from
Feb 26, 2024

Conversation

jmorse
Copy link
Member

@jmorse jmorse commented Feb 23, 2024

Part of removing debug-intrinsics from LLVM requires using iterators whenever we insert an instruction into a block. That means we need all instruction constructors and factory functions to have an iterator taking option, which this patch adds.

The whole of this patch should be NFC: it's adding new flavours of existing constructors, and plumbing those through to the Instruction constructor that takes iterators. It's almost entirely boilerplate copy-and-paste too.

~

This PR is a candidate for the "most boring PR of the year", given that it adds prototypes and handlers for a bunch of methods with slightly different signature to do the same thing. However, I figure it's worth /some/ review of the general approach, just to confirm that I haven't missed anything obvious that's going on.

There are a large number of clang-format issues with the patch, mostly due to adjacent code with noncompliant indentation and the like. I've patched up the lines that I'm adding, I don't wish to pollute git history by clang-formatting all the surrounding code.

Part of removing debug-intrinsics from LLVM requires using iterators
whenever we insert an instruction into a block. That means we need all
instructor constructors and factory functions to have an iterator taking
option, which this patch adds.

The whole of this patch should be NFC: it's adding new flavours of existing
constructors, and plumbing those through to the Instruction constructor
that takes iterators. It's almost entirely boilerplate copy-and-paste too.
@llvmbot
Copy link
Collaborator

llvmbot commented Feb 23, 2024

@llvm/pr-subscribers-llvm-ir

Author: Jeremy Morse (jmorse)

Changes

Part of removing debug-intrinsics from LLVM requires using iterators whenever we insert an instruction into a block. That means we need all instruction constructors and factory functions to have an iterator taking option, which this patch adds.

The whole of this patch should be NFC: it's adding new flavours of existing constructors, and plumbing those through to the Instruction constructor that takes iterators. It's almost entirely boilerplate copy-and-paste too.

~

This PR is a candidate for the "most boring PR of the year", given that it adds prototypes and handlers for a bunch of methods with slightly different signature to do the same thing. However, I figure it's worth /some/ review of the general approach, just to confirm that I haven't missed anything obvious that's going on.

There are a large number of clang-format issues with the patch, mostly due to adjacent code with noncompliant indentation and the like. I've patched up the lines that I'm adding, I don't wish to pollute git history by clang-formatting all the surrounding code.


Patch is 124.44 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/82778.diff

5 Files Affected:

  • (modified) llvm/include/llvm/IR/InstrTypes.h (+219)
  • (modified) llvm/include/llvm/IR/Instruction.h (+2)
  • (modified) llvm/include/llvm/IR/Instructions.h (+621-10)
  • (modified) llvm/lib/IR/Instruction.cpp (+10)
  • (modified) llvm/lib/IR/Instructions.cpp (+498-6)
diff --git a/llvm/include/llvm/IR/InstrTypes.h b/llvm/include/llvm/IR/InstrTypes.h
index 6eba902fa04165..4ee51cd192ed7c 100644
--- a/llvm/include/llvm/IR/InstrTypes.h
+++ b/llvm/include/llvm/IR/InstrTypes.h
@@ -54,6 +54,10 @@ typedef unsigned ID;
 
 class UnaryInstruction : public Instruction {
 protected:
+  UnaryInstruction(Type *Ty, unsigned iType, Value *V, BasicBlock::iterator IB)
+      : Instruction(Ty, iType, &Op<0>(), 1, IB) {
+    Op<0>() = V;
+  }
   UnaryInstruction(Type *Ty, unsigned iType, Value *V,
                    Instruction *IB = nullptr)
     : Instruction(Ty, iType, &Op<0>(), 1, IB) {
@@ -101,6 +105,8 @@ class UnaryOperator : public UnaryInstruction {
   void AssertOK();
 
 protected:
+  UnaryOperator(UnaryOps iType, Value *S, Type *Ty,
+                const Twine &Name, BasicBlock::iterator InsertBefore);
   UnaryOperator(UnaryOps iType, Value *S, Type *Ty,
                 const Twine &Name, Instruction *InsertBefore);
   UnaryOperator(UnaryOps iType, Value *S, Type *Ty,
@@ -112,6 +118,12 @@ class UnaryOperator : public UnaryInstruction {
   UnaryOperator *cloneImpl() const;
 
 public:
+  /// Construct a unary instruction, given the opcode and an operand.
+  /// Insert the instruction into a BasicBlock right before the specified
+  /// instruction (InsertBefore must be a valid iterator).
+  ///
+  static UnaryOperator *Create(UnaryOps Op, Value *S, const Twine &Name,
+                               BasicBlock::iterator InsertBefore);
 
   /// Construct a unary instruction, given the opcode and an operand.
   /// Optionally (if InstBefore is specified) insert the instruction
@@ -150,6 +162,20 @@ class UnaryOperator : public UnaryInstruction {
     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);\
+  }
+#include "llvm/IR/Instruction.def"
+
+  static UnaryOperator *
+  CreateWithCopiedFlags(UnaryOps Opc, Value *V, Instruction *CopyO,
+                        const Twine &Name, BasicBlock::iterator InsertBefore) {
+    UnaryOperator *UO = Create(Opc, V, Name, InsertBefore);
+    UO->copyIRFlags(CopyO);
+    return UO;
+  }
 
   static UnaryOperator *
   CreateWithCopiedFlags(UnaryOps Opc, Value *V, Instruction *CopyO,
@@ -160,6 +186,13 @@ class UnaryOperator : public UnaryInstruction {
     return UO;
   }
 
+  static UnaryOperator *CreateFNegFMF(Value *Op, Instruction *FMFSource,
+                                      const Twine &Name,
+                                      BasicBlock::iterator InsertBefore) {
+    return CreateWithCopiedFlags(Instruction::FNeg, Op, FMFSource, Name,
+                                 InsertBefore);
+  }
+
   static UnaryOperator *CreateFNegFMF(Value *Op, Instruction *FMFSource,
                                       const Twine &Name = "",
                                       Instruction *InsertBefore = nullptr) {
@@ -188,6 +221,8 @@ class BinaryOperator : public Instruction {
   void AssertOK();
 
 protected:
+  BinaryOperator(BinaryOps iType, Value *S1, Value *S2, Type *Ty,
+                 const Twine &Name, BasicBlock::iterator InsertBefore);
   BinaryOperator(BinaryOps iType, Value *S1, Value *S2, Type *Ty,
                  const Twine &Name, Instruction *InsertBefore);
   BinaryOperator(BinaryOps iType, Value *S1, Value *S2, Type *Ty,
@@ -206,6 +241,14 @@ class BinaryOperator : public Instruction {
   /// Transparently provide more efficient getOperand methods.
   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
 
+  /// Construct a binary instruction, given the opcode and the two
+  /// operands. Insert the instruction into a BasicBlock right before the
+  /// specified instruction.
+  ///
+  static BinaryOperator *Create(BinaryOps Op, Value *S1, Value *S2,
+                                const Twine &Name,
+                                BasicBlock::iterator InsertBefore);
+
   /// Construct a binary instruction, given the opcode and the two
   /// operands.  Optionally (if InstBefore is specified) insert the instruction
   /// into a BasicBlock right before the specified instruction.  The specified
@@ -243,6 +286,20 @@ class BinaryOperator : public Instruction {
     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);\
+  }
+#include "llvm/IR/Instruction.def"
+
+  static BinaryOperator *
+  CreateWithCopiedFlags(BinaryOps Opc, Value *V1, Value *V2, Value *CopyO,
+                        const Twine &Name, BasicBlock::iterator InsertBefore) {
+    BinaryOperator *BO = Create(Opc, V1, V2, Name, InsertBefore);
+    BO->copyIRFlags(CopyO);
+    return BO;
+  }
 
   static BinaryOperator *
   CreateWithCopiedFlags(BinaryOps Opc, Value *V1, Value *V2, Value *CopyO,
@@ -297,6 +354,12 @@ class BinaryOperator : public Instruction {
     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);
+    BO->setHasNoSignedWrap(true);
+    return BO;
+  }
 
   static BinaryOperator *CreateNUW(BinaryOps Opc, Value *V1, Value *V2,
                                    const Twine &Name = "") {
@@ -316,6 +379,12 @@ class BinaryOperator : public Instruction {
     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);
+    BO->setHasNoUnsignedWrap(true);
+    return BO;
+  }
 
   static BinaryOperator *CreateExact(BinaryOps Opc, Value *V1, Value *V2,
                                      const Twine &Name = "") {
@@ -335,6 +404,13 @@ class BinaryOperator : public Instruction {
     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);
+    BO->setIsExact(true);
+    return BO;
+  }
 
   static inline BinaryOperator *
   CreateDisjoint(BinaryOps Opc, Value *V1, Value *V2, const Twine &Name = "");
@@ -344,6 +420,9 @@ class BinaryOperator : public Instruction {
   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);
 
 #define DEFINE_HELPERS(OPC, NUWNSWEXACT)                                       \
   static BinaryOperator *Create##NUWNSWEXACT##OPC(Value *V1, Value *V2,        \
@@ -357,6 +436,10 @@ class BinaryOperator : public Instruction {
   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);            \
   }
 
   DEFINE_HELPERS(Add, NSW) // CreateNSWAdd
@@ -382,18 +465,26 @@ class BinaryOperator : public Instruction {
   ///
   /// Create the NEG and NOT instructions out of SUB and XOR instructions.
   ///
+  static BinaryOperator *CreateNeg(Value *Op, const Twine &Name,
+                                   BasicBlock::iterator InsertBefore);
   static BinaryOperator *CreateNeg(Value *Op, const Twine &Name = "",
                                    Instruction *InsertBefore = nullptr);
   static BinaryOperator *CreateNeg(Value *Op, const Twine &Name,
                                    BasicBlock *InsertAtEnd);
+  static BinaryOperator *CreateNSWNeg(Value *Op, const Twine &Name,
+                                      BasicBlock::iterator InsertBefore);
   static BinaryOperator *CreateNSWNeg(Value *Op, const Twine &Name = "",
                                       Instruction *InsertBefore = nullptr);
   static BinaryOperator *CreateNSWNeg(Value *Op, const Twine &Name,
                                       BasicBlock *InsertAtEnd);
+  static BinaryOperator *CreateNUWNeg(Value *Op, const Twine &Name,
+                                      BasicBlock::iterator InsertBefore);
   static BinaryOperator *CreateNUWNeg(Value *Op, const Twine &Name = "",
                                       Instruction *InsertBefore = nullptr);
   static BinaryOperator *CreateNUWNeg(Value *Op, const Twine &Name,
                                       BasicBlock *InsertAtEnd);
+  static BinaryOperator *CreateNot(Value *Op, const Twine &Name,
+                                   BasicBlock::iterator InsertBefore);
   static BinaryOperator *CreateNot(Value *Op, const Twine &Name = "",
                                    Instruction *InsertBefore = nullptr);
   static BinaryOperator *CreateNot(Value *Op, const Twine &Name,
@@ -469,6 +560,13 @@ 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::iterator It) {
+  BinaryOperator *BO = Create(Opc, V1, V2, Name, It);
+  cast<PossiblyDisjointInst>(BO)->setIsDisjoint(true);
+  return BO;
+}
 
 //===----------------------------------------------------------------------===//
 //                               CastInst Class
@@ -482,6 +580,12 @@ BinaryOperator *BinaryOperator::CreateDisjoint(BinaryOps Opc, Value *V1,
 /// Base class of casting instructions.
 class CastInst : public UnaryInstruction {
 protected:
+  /// Constructor with insert-before-instruction semantics for subclasses
+  CastInst(Type *Ty, unsigned iType, Value *S, const Twine &NameStr,
+           BasicBlock::iterator InsertBefore)
+      : UnaryInstruction(Ty, iType, S, InsertBefore) {
+    setName(NameStr);
+  }
   /// Constructor with insert-before-instruction semantics for subclasses
   CastInst(Type *Ty, unsigned iType, Value *S,
            const Twine &NameStr = "", Instruction *InsertBefore = nullptr)
@@ -496,6 +600,19 @@ class CastInst : public UnaryInstruction {
   }
 
 public:
+  /// Provides a way to construct any of the CastInst subclasses using an
+  /// opcode instead of the subclass's constructor. The opcode must be in the
+  /// CastOps category (Instruction::isCast(opcode) returns true). This
+  /// constructor has insert-before-instruction semantics to automatically
+  /// insert the new CastInst before InsertBefore, which must be a valid
+  /// iterator. Construct any of the CastInst subclasses.
+  static CastInst *
+  Create(Instruction::CastOps, ///< The opcode of the cast instruction
+         Value *S,             ///< The value to be casted (operand 0)
+         Type *Ty,             ///< The type to which cast should be made
+         const Twine &Name,    ///< Name for the instruction
+         BasicBlock::iterator InsertBefore ///< Place to insert the instruction
+  );
   /// Provides a way to construct any of the CastInst subclasses using an
   /// opcode instead of the subclass's constructor. The opcode must be in the
   /// CastOps category (Instruction::isCast(opcode) returns true). This
@@ -523,6 +640,14 @@ class CastInst : public UnaryInstruction {
     BasicBlock *InsertAtEnd  ///< The block to insert the instruction into
   );
 
+  /// Create a ZExt or BitCast cast instruction
+  static CastInst *CreateZExtOrBitCast(
+    Value *S,                ///< The value to be casted (operand 0)
+    Type *Ty,          ///< The type to which cast should be made
+    const Twine &Name, ///< Name for the instruction
+    BasicBlock::iterator InsertBefore ///< Place to insert the instruction
+  );
+
   /// Create a ZExt or BitCast cast instruction
   static CastInst *CreateZExtOrBitCast(
     Value *S,                ///< The value to be casted (operand 0)
@@ -539,6 +664,14 @@ class CastInst : public UnaryInstruction {
     BasicBlock *InsertAtEnd  ///< The block to insert the instruction into
   );
 
+  /// Create a SExt or BitCast cast instruction
+  static CastInst *CreateSExtOrBitCast(
+    Value *S,                ///< The value to be casted (operand 0)
+    Type *Ty,          ///< The type to which cast should be made
+    const Twine &Name, ///< Name for the instruction
+    BasicBlock::iterator InsertBefore ///< Place to insert the instruction
+  );
+
   /// Create a SExt or BitCast cast instruction
   static CastInst *CreateSExtOrBitCast(
     Value *S,                ///< The value to be casted (operand 0)
@@ -563,6 +696,14 @@ class CastInst : public UnaryInstruction {
     BasicBlock *InsertAtEnd  ///< The block to insert the instruction into
   );
 
+  /// Create a BitCast, AddrSpaceCast or a PtrToInt cast instruction.
+  static CastInst *CreatePointerCast(
+    Value *S,                ///< The pointer value to be casted (operand 0)
+    Type *Ty,          ///< The type to which cast should be made
+    const Twine &Name, ///< Name for the instruction
+    BasicBlock::iterator InsertBefore ///< Place to insert the instruction
+  );
+
   /// Create a BitCast, AddrSpaceCast or a PtrToInt cast instruction.
   static CastInst *CreatePointerCast(
     Value *S,                ///< The pointer value to be casted (operand 0)
@@ -579,6 +720,14 @@ class CastInst : public UnaryInstruction {
     BasicBlock *InsertAtEnd  ///< The block to insert the instruction into
   );
 
+  /// Create a BitCast or an AddrSpaceCast cast instruction.
+  static CastInst *CreatePointerBitCastOrAddrSpaceCast(
+    Value *S,                ///< The pointer value to be casted (operand 0)
+    Type *Ty,          ///< The type to which cast should be made
+    const Twine &Name, ///< Name for the instruction
+    BasicBlock::iterator InsertBefore ///< Place to insert the instruction
+  );
+
   /// Create a BitCast or an AddrSpaceCast cast instruction.
   static CastInst *CreatePointerBitCastOrAddrSpaceCast(
     Value *S,                ///< The pointer value to be casted (operand 0)
@@ -587,6 +736,19 @@ class CastInst : public UnaryInstruction {
     Instruction *InsertBefore = nullptr ///< Place to insert the instruction
   );
 
+  /// Create a BitCast, a PtrToInt, or an IntToPTr cast instruction.
+  ///
+  /// If the value is a pointer type and the destination an integer type,
+  /// creates a PtrToInt cast. If the value is an integer type and the
+  /// destination a pointer type, creates an IntToPtr cast. Otherwise, creates
+  /// a bitcast.
+  static CastInst *CreateBitOrPointerCast(
+    Value *S,                ///< The pointer value to be casted (operand 0)
+    Type *Ty,          ///< The type to which cast should be made
+    const Twine &Name, ///< Name for the instruction
+    BasicBlock::iterator InsertBefore ///< Place to insert the instruction
+  );
+
   /// Create a BitCast, a PtrToInt, or an IntToPTr cast instruction.
   ///
   /// If the value is a pointer type and the destination an integer type,
@@ -600,6 +762,15 @@ class CastInst : public UnaryInstruction {
     Instruction *InsertBefore = nullptr ///< Place to insert the instruction
   );
 
+  /// Create a ZExt, BitCast, or Trunc for int -> int casts.
+  static CastInst *CreateIntegerCast(
+    Value *S,                ///< The pointer value to be casted (operand 0)
+    Type *Ty,          ///< The type to which cast should be made
+    bool isSigned,           ///< Whether to regard S as signed or not
+    const Twine &Name, ///< Name for the instruction
+    BasicBlock::iterator InsertBefore ///< Place to insert the instruction
+  );
+
   /// Create a ZExt, BitCast, or Trunc for int -> int casts.
   static CastInst *CreateIntegerCast(
     Value *S,                ///< The pointer value to be casted (operand 0)
@@ -618,6 +789,14 @@ class CastInst : public UnaryInstruction {
     BasicBlock *InsertAtEnd  ///< The block to insert the instruction into
   );
 
+  /// Create an FPExt, BitCast, or FPTrunc for fp -> fp casts
+  static CastInst *CreateFPCast(
+    Value *S,                ///< The floating point value to be casted
+    Type *Ty,          ///< The floating point type to cast to
+    const Twine &Name, ///< Name for the instruction
+    BasicBlock::iterator InsertBefore ///< Place to insert the instruction
+  );
+
   /// Create an FPExt, BitCast, or FPTrunc for fp -> fp casts
   static CastInst *CreateFPCast(
     Value *S,                ///< The floating point value to be casted
@@ -634,6 +813,14 @@ class CastInst : public UnaryInstruction {
     BasicBlock *InsertAtEnd  ///< The block to insert the instruction into
   );
 
+  /// Create a Trunc or BitCast cast instruction
+  static CastInst *CreateTruncOrBitCast(
+    Value *S,                ///< The value to be casted (operand 0)
+    Type *Ty,          ///< The type to which cast should be made
+    const Twine &Name, ///< Name for the instruction
+    BasicBlock::iterator InsertBefore ///< Place to insert the instruction
+  );
+
   /// Create a Trunc or BitCast cast instruction
   static CastInst *CreateTruncOrBitCast(
     Value *S,                ///< The value to be casted (operand 0)
@@ -830,6 +1017,10 @@ class CmpInst : public Instruction {
   }
 
 protected:
+  CmpInst(Type *ty, Instruction::OtherOps op, Predicate pred, Value *LHS,
+          Value *RHS, const Twine &Name, BasicBlock::iterator InsertBefore,
+          Instruction *FlagsSource = nullptr);
+
   CmpInst(Type *ty, Instruction::OtherOps op, Predicate pred,
           Value *LHS, Value *RHS, const Twine &Name = "",
           Instruction *InsertBefore = nullptr,
@@ -844,6 +1035,13 @@ class CmpInst : public Instruction {
   void *operator new(size_t S) { return User::operator new(S, 2); }
   void operator delete(void *Ptr) { User::operator delete(Ptr); }
 
+  /// Construct a compare instruction, given the opcode, the predicate and
+  /// the two operands. Insert the instruction into a BasicBlock right before
+  /// the specified instruction.
+  /// Create a CmpInst
+  static CmpInst *Create(OtherOps Op, Predicate predicate, Value *S1, Value *S2,
+                         const Twine &Name, BasicBlock::iterator InsertBefore);
+
   /// Construct a compare instruction, given the opcode, the predicate and
   /// the two operands.  Optionally (if InstBefore is specified) insert the
   /// instruction into a BasicBlock right before the specified instruction.
@@ -1300,6 +1498,15 @@ class CallBase : public Instruction {
 public:
   using Instruction::getContext;
 
+  /// Create a clone of \p CB with a different set of operand bundles and
+  /// insert it before \p InsertPt.
+  ///
+  /// The returned call instruction is identical \p CB in every way except that
+  /// the operand bundles for the new instruction are set to the operand bundles
+  /// in \p Bundles.
+  static CallBase *Create(CallBase *CB, ArrayRef<OperandBundleDef> Bundles,
+                          BasicBlock::iterator InsertPt);
+
   /// Create a clone of \p CB with a different set of operand bundles and
   /// insert it before \p InsertPt.
   ///
@@ -1309,6 +1516,14 @@ class CallBase : public Instruction {
   static CallBase *Create(CallBase *CB, ArrayRef<OperandBundleDef> Bundles,
                           Instruction *InsertPt = nullptr);
 
+  /// Create a clone of \p CB with the operand bundle with the tag matching
+  /// ...
[truncated]

Copy link

⚠️ C/C++ code formatter, clang-format found issues in your code. ⚠️

You can test this locally with the following command:
git-clang-format --diff be083dba95dfbbb0286d798cc06fbe021715bc03 e49779b5e5bcb016ee96d0d169bea5b263a1c9f3 -- llvm/include/llvm/IR/InstrTypes.h llvm/include/llvm/IR/Instruction.h llvm/include/llvm/IR/Instructions.h llvm/lib/IR/Instruction.cpp llvm/lib/IR/Instructions.cpp
View the diff from clang-format here.
diff --git a/llvm/include/llvm/IR/InstrTypes.h b/llvm/include/llvm/IR/InstrTypes.h
index 4ee51cd192..87985b4ed7 100644
--- a/llvm/include/llvm/IR/InstrTypes.h
+++ b/llvm/include/llvm/IR/InstrTypes.h
@@ -105,8 +105,8 @@ class UnaryOperator : public UnaryInstruction {
   void AssertOK();
 
 protected:
-  UnaryOperator(UnaryOps iType, Value *S, Type *Ty,
-                const Twine &Name, BasicBlock::iterator InsertBefore);
+  UnaryOperator(UnaryOps iType, Value *S, Type *Ty, const Twine &Name,
+                BasicBlock::iterator InsertBefore);
   UnaryOperator(UnaryOps iType, Value *S, Type *Ty,
                 const Twine &Name, Instruction *InsertBefore);
   UnaryOperator(UnaryOps iType, Value *S, Type *Ty,
@@ -162,10 +162,10 @@ public:
     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,               \
+                                    BasicBlock::iterator It) {                 \
+    return Create(Instruction::OPC, V, Name, It);                              \
   }
 #include "llvm/IR/Instruction.def"
 
@@ -286,10 +286,10 @@ public:
     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,  \
+                                     BasicBlock::iterator It) {                \
+    return Create(Instruction::OPC, V1, V2, Name, It);                         \
   }
 #include "llvm/IR/Instruction.def"
 
@@ -642,10 +642,10 @@ public:
 
   /// Create a ZExt or BitCast cast instruction
   static CastInst *CreateZExtOrBitCast(
-    Value *S,                ///< The value to be casted (operand 0)
-    Type *Ty,          ///< The type to which cast should be made
-    const Twine &Name, ///< Name for the instruction
-    BasicBlock::iterator InsertBefore ///< Place to insert the instruction
+      Value *S,          ///< The value to be casted (operand 0)
+      Type *Ty,          ///< The type to which cast should be made
+      const Twine &Name, ///< Name for the instruction
+      BasicBlock::iterator InsertBefore ///< Place to insert the instruction
   );
 
   /// Create a ZExt or BitCast cast instruction
@@ -666,10 +666,10 @@ public:
 
   /// Create a SExt or BitCast cast instruction
   static CastInst *CreateSExtOrBitCast(
-    Value *S,                ///< The value to be casted (operand 0)
-    Type *Ty,          ///< The type to which cast should be made
-    const Twine &Name, ///< Name for the instruction
-    BasicBlock::iterator InsertBefore ///< Place to insert the instruction
+      Value *S,          ///< The value to be casted (operand 0)
+      Type *Ty,          ///< The type to which cast should be made
+      const Twine &Name, ///< Name for the instruction
+      BasicBlock::iterator InsertBefore ///< Place to insert the instruction
   );
 
   /// Create a SExt or BitCast cast instruction
@@ -698,10 +698,10 @@ public:
 
   /// Create a BitCast, AddrSpaceCast or a PtrToInt cast instruction.
   static CastInst *CreatePointerCast(
-    Value *S,                ///< The pointer value to be casted (operand 0)
-    Type *Ty,          ///< The type to which cast should be made
-    const Twine &Name, ///< Name for the instruction
-    BasicBlock::iterator InsertBefore ///< Place to insert the instruction
+      Value *S,          ///< The pointer value to be casted (operand 0)
+      Type *Ty,          ///< The type to which cast should be made
+      const Twine &Name, ///< Name for the instruction
+      BasicBlock::iterator InsertBefore ///< Place to insert the instruction
   );
 
   /// Create a BitCast, AddrSpaceCast or a PtrToInt cast instruction.
@@ -722,10 +722,10 @@ public:
 
   /// Create a BitCast or an AddrSpaceCast cast instruction.
   static CastInst *CreatePointerBitCastOrAddrSpaceCast(
-    Value *S,                ///< The pointer value to be casted (operand 0)
-    Type *Ty,          ///< The type to which cast should be made
-    const Twine &Name, ///< Name for the instruction
-    BasicBlock::iterator InsertBefore ///< Place to insert the instruction
+      Value *S,          ///< The pointer value to be casted (operand 0)
+      Type *Ty,          ///< The type to which cast should be made
+      const Twine &Name, ///< Name for the instruction
+      BasicBlock::iterator InsertBefore ///< Place to insert the instruction
   );
 
   /// Create a BitCast or an AddrSpaceCast cast instruction.
@@ -743,10 +743,10 @@ public:
   /// destination a pointer type, creates an IntToPtr cast. Otherwise, creates
   /// a bitcast.
   static CastInst *CreateBitOrPointerCast(
-    Value *S,                ///< The pointer value to be casted (operand 0)
-    Type *Ty,          ///< The type to which cast should be made
-    const Twine &Name, ///< Name for the instruction
-    BasicBlock::iterator InsertBefore ///< Place to insert the instruction
+      Value *S,          ///< The pointer value to be casted (operand 0)
+      Type *Ty,          ///< The type to which cast should be made
+      const Twine &Name, ///< Name for the instruction
+      BasicBlock::iterator InsertBefore ///< Place to insert the instruction
   );
 
   /// Create a BitCast, a PtrToInt, or an IntToPTr cast instruction.
@@ -764,11 +764,11 @@ public:
 
   /// Create a ZExt, BitCast, or Trunc for int -> int casts.
   static CastInst *CreateIntegerCast(
-    Value *S,                ///< The pointer value to be casted (operand 0)
-    Type *Ty,          ///< The type to which cast should be made
-    bool isSigned,           ///< Whether to regard S as signed or not
-    const Twine &Name, ///< Name for the instruction
-    BasicBlock::iterator InsertBefore ///< Place to insert the instruction
+      Value *S,          ///< The pointer value to be casted (operand 0)
+      Type *Ty,          ///< The type to which cast should be made
+      bool isSigned,     ///< Whether to regard S as signed or not
+      const Twine &Name, ///< Name for the instruction
+      BasicBlock::iterator InsertBefore ///< Place to insert the instruction
   );
 
   /// Create a ZExt, BitCast, or Trunc for int -> int casts.
@@ -791,10 +791,10 @@ public:
 
   /// Create an FPExt, BitCast, or FPTrunc for fp -> fp casts
   static CastInst *CreateFPCast(
-    Value *S,                ///< The floating point value to be casted
-    Type *Ty,          ///< The floating point type to cast to
-    const Twine &Name, ///< Name for the instruction
-    BasicBlock::iterator InsertBefore ///< Place to insert the instruction
+      Value *S,          ///< The floating point value to be casted
+      Type *Ty,          ///< The floating point type to cast to
+      const Twine &Name, ///< Name for the instruction
+      BasicBlock::iterator InsertBefore ///< Place to insert the instruction
   );
 
   /// Create an FPExt, BitCast, or FPTrunc for fp -> fp casts
@@ -815,10 +815,10 @@ public:
 
   /// Create a Trunc or BitCast cast instruction
   static CastInst *CreateTruncOrBitCast(
-    Value *S,                ///< The value to be casted (operand 0)
-    Type *Ty,          ///< The type to which cast should be made
-    const Twine &Name, ///< Name for the instruction
-    BasicBlock::iterator InsertBefore ///< Place to insert the instruction
+      Value *S,          ///< The value to be casted (operand 0)
+      Type *Ty,          ///< The type to which cast should be made
+      const Twine &Name, ///< Name for the instruction
+      BasicBlock::iterator InsertBefore ///< Place to insert the instruction
   );
 
   /// Create a Trunc or BitCast cast instruction
diff --git a/llvm/include/llvm/IR/Instructions.h b/llvm/include/llvm/IR/Instructions.h
index bc357074e5..c644ce2e90 100644
--- a/llvm/include/llvm/IR/Instructions.h
+++ b/llvm/include/llvm/IR/Instructions.h
@@ -1267,17 +1267,16 @@ protected:
 
 public:
   /// Constructor with insert-before-instruction semantics.
-  ICmpInst(
-    BasicBlock::iterator InsertBefore,  ///< Where to insert
-    Predicate pred,  ///< The predicate to use for the comparison
-    Value *LHS,      ///< The left-hand-side of the expression
-    Value *RHS,      ///< The right-hand-side of the expression
-    const Twine &NameStr = ""  ///< Name of the instruction
-  ) : CmpInst(makeCmpResultType(LHS->getType()),
-              Instruction::ICmp, pred, LHS, RHS, NameStr,
-              InsertBefore) {
+  ICmpInst(BasicBlock::iterator InsertBefore, ///< Where to insert
+           Predicate pred, ///< The predicate to use for the comparison
+           Value *LHS,     ///< The left-hand-side of the expression
+           Value *RHS,     ///< The right-hand-side of the expression
+           const Twine &NameStr = "" ///< Name of the instruction
+           )
+      : CmpInst(makeCmpResultType(LHS->getType()), Instruction::ICmp, pred, LHS,
+                RHS, NameStr, InsertBefore) {
 #ifndef NDEBUG
-  AssertOK();
+    AssertOK();
 #endif
   }
 
@@ -1454,15 +1453,14 @@ protected:
 
 public:
   /// Constructor with insert-before-instruction semantics.
-  FCmpInst(
-    BasicBlock::iterator InsertBefore, ///< Where to insert
-    Predicate pred,  ///< The predicate to use for the comparison
-    Value *LHS,      ///< The left-hand-side of the expression
-    Value *RHS,      ///< The right-hand-side of the expression
-    const Twine &NameStr = ""  ///< Name of the instruction
-  ) : CmpInst(makeCmpResultType(LHS->getType()),
-              Instruction::FCmp, pred, LHS, RHS, NameStr,
-              InsertBefore) {
+  FCmpInst(BasicBlock::iterator InsertBefore, ///< Where to insert
+           Predicate pred, ///< The predicate to use for the comparison
+           Value *LHS,     ///< The left-hand-side of the expression
+           Value *RHS,     ///< The right-hand-side of the expression
+           const Twine &NameStr = "" ///< Name of the instruction
+           )
+      : CmpInst(makeCmpResultType(LHS->getType()), Instruction::FCmp, pred, LHS,
+                RHS, NameStr, InsertBefore) {
     AssertOK();
   }
 
@@ -2700,8 +2698,7 @@ public:
   static ExtractValueInst *Create(Value *Agg, ArrayRef<unsigned> Idxs,
                                   const Twine &NameStr,
                                   BasicBlock::iterator InsertBefore) {
-    return new
-      ExtractValueInst(Agg, Idxs, NameStr, InsertBefore);
+    return new ExtractValueInst(Agg, Idxs, NameStr, InsertBefore);
   }
 
   static ExtractValueInst *Create(Value *Agg,
@@ -2918,13 +2915,12 @@ struct OperandTraits<InsertValueInst> :
   public FixedNumOperandTraits<InsertValueInst, 2> {
 };
 
-InsertValueInst::InsertValueInst(Value *Agg,
-                                 Value *Val,
-                                 ArrayRef<unsigned> Idxs,
-                                 const Twine &NameStr,
+InsertValueInst::InsertValueInst(Value *Agg, Value *Val,
+                                 ArrayRef<unsigned> Idxs, const Twine &NameStr,
                                  BasicBlock::iterator InsertBefore)
-  : Instruction(Agg->getType(), InsertValue, OperandTraits<InsertValueInst>::op_begin(this),
-                2, InsertBefore) {
+    : Instruction(Agg->getType(), InsertValue,
+                  OperandTraits<InsertValueInst>::op_begin(this), 2,
+                  InsertBefore) {
   init(Agg, Val, Idxs, NameStr);
 }
 
@@ -3489,7 +3485,7 @@ public:
 
   static BranchInst *Create(BasicBlock *IfTrue,
                             BasicBlock::iterator InsertBefore) {
-    return new(1) BranchInst(IfTrue, InsertBefore);
+    return new (1) BranchInst(IfTrue, InsertBefore);
   }
 
   static BranchInst *Create(BasicBlock *IfTrue,
@@ -3499,7 +3495,7 @@ public:
 
   static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse,
                             Value *Cond, BasicBlock::iterator InsertBefore) {
-    return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertBefore);
+    return new (3) BranchInst(IfTrue, IfFalse, Cond, InsertBefore);
   }
 
   static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse,
@@ -5347,10 +5343,10 @@ protected:
 public:
   /// Constructor with insert-before-instruction semantics
   TruncInst(
-    Value *S,                           ///< The value to be truncated
-    Type *Ty,                           ///< The (smaller) type to truncate to
-    const Twine &NameStr,               ///< A name for the new instruction
-    BasicBlock::iterator InsertBefore   ///< Where to insert the new instruction
+      Value *S,                         ///< The value to be truncated
+      Type *Ty,                         ///< The (smaller) type to truncate to
+      const Twine &NameStr,             ///< A name for the new instruction
+      BasicBlock::iterator InsertBefore ///< Where to insert the new instruction
   );
 
   /// Constructor with insert-before-instruction semantics
@@ -5394,10 +5390,10 @@ protected:
 public:
   /// Constructor with insert-before-instruction semantics
   ZExtInst(
-    Value *S,                           ///< The value to be zero extended
-    Type *Ty,                           ///< The type to zero extend to
-    const Twine &NameStr,               ///< A name for the new instruction
-    BasicBlock::iterator InsertBefore   ///< Where to insert the new instruction
+      Value *S,                         ///< The value to be zero extended
+      Type *Ty,                         ///< The type to zero extend to
+      const Twine &NameStr,             ///< A name for the new instruction
+      BasicBlock::iterator InsertBefore ///< Where to insert the new instruction
   );
 
   /// Constructor with insert-before-instruction semantics
@@ -5441,10 +5437,10 @@ protected:
 public:
   /// Constructor with insert-before-instruction semantics
   SExtInst(
-    Value *S,                           ///< The value to be sign extended
-    Type *Ty,                           ///< The type to sign extend to
-    const Twine &NameStr,               ///< A name for the new instruction
-    BasicBlock::iterator InsertBefore   ///< Where to insert the new instruction
+      Value *S,                         ///< The value to be sign extended
+      Type *Ty,                         ///< The type to sign extend to
+      const Twine &NameStr,             ///< A name for the new instruction
+      BasicBlock::iterator InsertBefore ///< Where to insert the new instruction
   );
 
   /// Constructor with insert-before-instruction semantics
@@ -5488,10 +5484,10 @@ protected:
 public:
   /// Constructor with insert-before-instruction semantics
   FPTruncInst(
-    Value *S,                           ///< The value to be truncated
-    Type *Ty,                           ///< The type to truncate to
-    const Twine &NameStr,               ///< A name for the new instruction
-    BasicBlock::iterator InsertBefore   ///< Where to insert the new instruction
+      Value *S,                         ///< The value to be truncated
+      Type *Ty,                         ///< The type to truncate to
+      const Twine &NameStr,             ///< A name for the new instruction
+      BasicBlock::iterator InsertBefore ///< Where to insert the new instruction
   );
 
   /// Constructor with insert-before-instruction semantics
@@ -5535,10 +5531,10 @@ protected:
 public:
   /// Constructor with insert-before-instruction semantics
   FPExtInst(
-    Value *S,                           ///< The value to be extended
-    Type *Ty,                           ///< The type to extend to
-    const Twine &NameStr,               ///< A name for the new instruction
-    BasicBlock::iterator InsertBefore   ///< Where to insert the new instruction
+      Value *S,                         ///< The value to be extended
+      Type *Ty,                         ///< The type to extend to
+      const Twine &NameStr,             ///< A name for the new instruction
+      BasicBlock::iterator InsertBefore ///< Where to insert the new instruction
   );
 
   /// Constructor with insert-before-instruction semantics
@@ -5582,10 +5578,10 @@ protected:
 public:
   /// Constructor with insert-before-instruction semantics
   UIToFPInst(
-    Value *S,                           ///< The value to be converted
-    Type *Ty,                           ///< The type to convert to
-    const Twine &NameStr,               ///< A name for the new instruction
-    BasicBlock::iterator InsertBefore   ///< Where to insert the new instruction
+      Value *S,                         ///< The value to be converted
+      Type *Ty,                         ///< The type to convert to
+      const Twine &NameStr,             ///< A name for the new instruction
+      BasicBlock::iterator InsertBefore ///< Where to insert the new instruction
   );
 
   /// Constructor with insert-before-instruction semantics
@@ -5629,10 +5625,10 @@ protected:
 public:
   /// Constructor with insert-before-instruction semantics
   SIToFPInst(
-    Value *S,                           ///< The value to be converted
-    Type *Ty,                           ///< The type to convert to
-    const Twine &NameStr,               ///< A name for the new instruction
-    BasicBlock::iterator InsertBefore   ///< Where to insert the new instruction
+      Value *S,                         ///< The value to be converted
+      Type *Ty,                         ///< The type to convert to
+      const Twine &NameStr,             ///< A name for the new instruction
+      BasicBlock::iterator InsertBefore ///< Where to insert the new instruction
   );
 
   /// Constructor with insert-before-instruction semantics
@@ -5676,10 +5672,10 @@ protected:
 public:
   /// Constructor with insert-before-instruction semantics
   FPToUIInst(
-    Value *S,                           ///< The value to be converted
-    Type *Ty,                           ///< The type to convert to
-    const Twine &NameStr,               ///< A name for the new instruction
-    BasicBlock::iterator InsertBefore   ///< Where to insert the new instruction
+      Value *S,                         ///< The value to be converted
+      Type *Ty,                         ///< The type to convert to
+      const Twine &NameStr,             ///< A name for the new instruction
+      BasicBlock::iterator InsertBefore ///< Where to insert the new instruction
   );
 
   /// Constructor with insert-before-instruction semantics
@@ -5723,10 +5719,10 @@ protected:
 public:
   /// Constructor with insert-before-instruction semantics
   FPToSIInst(
-    Value *S,                           ///< The value to be converted
-    Type *Ty,                           ///< The type to convert to
-    const Twine &NameStr,               ///< A name for the new instruction
-    BasicBlock::iterator InsertBefore   ///< Where to insert the new instruction
+      Value *S,                         ///< The value to be converted
+      Type *Ty,                         ///< The type to convert to
+      const Twine &NameStr,             ///< A name for the new instruction
+      BasicBlock::iterator InsertBefore ///< Where to insert the new instruction
   );
 
   /// Constructor with insert-before-instruction semantics
@@ -5766,10 +5762,10 @@ public:
 
   /// Constructor with insert-before-instruction semantics
   IntToPtrInst(
-    Value *S,                           ///< The value to be converted
-    Type *Ty,                           ///< The type to convert to
-    const Twine &NameStr,               ///< A name for the new instruction
-    BasicBlock::iterator InsertBefore   ///< Where to insert the new instruction
+      Value *S,                         ///< The value to be converted
+      Type *Ty,                         ///< The type to convert to
+      const Twine &NameStr,             ///< A name for the new instruction
+      BasicBlock::iterator InsertBefore ///< Where to insert the new instruction
   );
 
   /// Constructor with insert-before-instruction semantics
@@ -5821,10 +5817,10 @@ protected:
 public:
   /// Constructor with insert-before-instruction semantics
   PtrToIntInst(
-    Value *S,                           ///< The value to be converted
-    Type *Ty,                           ///< The type to convert to
-    const Twine &NameStr,               ///< A name for the new instruction
-    BasicBlock::iterator InsertBefore   ///< Where to insert the new instruction
+      Value *S,                         ///< The value to be converted
+      Type *Ty,                         ///< The type to convert to
+      const Twine &NameStr,             ///< A name for the new instruction
+      BasicBlock::iterator InsertBefore ///< Where to insert the new instruction
   );
 
   /// Constructor with insert-before-instruction semantics
@@ -5880,10 +5876,10 @@ protected:
 public:
   /// Constructor with insert-before-instruction semantics
   BitCastInst(
-    Value *S,                           ///< The value to be casted
-    Type *Ty,                           ///< The type to casted to
-    const Twine &NameStr,               ///< A name for the new instruction
-    BasicBlock::iterator InsertBefore   ///< Where to insert the new instruction
+      Value *S,                         ///< The value to be casted
+      Type *Ty,                         ///< The type to casted to
+      const Twine &NameStr,             ///< A name for the new instruction
+      BasicBlock::iterator InsertBefore ///< Where to insert the new instruction
   );
 
   /// Constructor with insert-before-instruction semantics
@@ -5928,10 +5924,10 @@ protected:
 public:
   /// Constructor with insert-before-instruction semantics
   AddrSpaceCastInst(
-    Value *S,                           ///< The value to be casted
-    Type *Ty,                           ///< The type to casted to
-    const Twine &NameStr,               ///< A name for the new instruction
-    BasicBlock::iterator InsertBefore   ///< Where to insert the new instruction
+      Value *S,                         ///< The value to be casted
+      Type *Ty,                         ///< The type to casted to
+      const Twine &NameStr,             ///< A name for the new instruction
+      BasicBlock::iterator InsertBefore ///< Where to insert the new instruction
   );
 
   /// Constructor with insert-before-instruction semantics
diff --git a/llvm/lib/IR/Instructions.cpp b/llvm/lib/IR/Instructions.cpp
index 25778570eb..ebfb56b993 100644
--- a/llvm/lib/IR/Instructions.cpp
+++ b/llvm/lib/IR/Instructions.cpp
@@ -990,8 +990,7 @@ ReturnInst::ReturnInst(LLVMContext &C, Value *retVal,
     Op<0>() = retVal;
 }
 
-ReturnInst::ReturnInst(LLVMContext &C, Value *retVal,
-                       Instruction *InsertBefore)
+ReturnInst::ReturnInst(LLVMContext &C, Value *retVal, Instruction *InsertBefore)
     : Instruction(Type::getVoidTy(C), Instruction::Ret,
                   OperandTraits<ReturnInst>::op_end(this) - !!retVal, !!retVal,
                   InsertBefore) {
@@ -3610,20 +3609,34 @@ CastInst *CastInst::Create(Instruction::CastOps op, Value *S, Type *Ty,
   assert(castIsValid(op, S, Ty) && "Invalid cast!");
   // Construct and return the appropriate CastInst subclass
   switch (op) {
-  case Trunc:         return new TruncInst         (S, Ty, Name, InsertBefore);
-  case ZExt:          return new ZExtInst          (S, Ty, Name, InsertBefore);
-  case SExt:          return new SExtInst          (S, Ty, Name, InsertBefore);
-  case FPTrunc:       return new FPTruncInst       (S, Ty, Name, InsertBefore);
-  case FPExt:         return new FPExtInst         (S, Ty, Name, InsertBefore);
-  case UIToFP:        return new UIToFPInst        (S, Ty, Name, InsertBefore);
-  case SIToFP:        return new SIToFPInst        (S, Ty, Name, InsertBefore);
-  case FPToUI:        return new FPToUIInst        (S, Ty, Name, InsertBefore);
-  case FPToSI:        return new FPToSIInst        (S, Ty, Name, InsertBefore);
-  case PtrToInt:      return new PtrToIntInst      (S, Ty, Name, InsertBefore);
-  case IntToPtr:      return new IntToPtrInst      (S, Ty, Name, InsertBefore);
-  case BitCast:       return new BitCastInst       (S, Ty, Name, InsertBefore);
-  case AddrSpaceCast: return new AddrSpaceCastInst (S, Ty, Name, InsertBefore);
-  default: llvm_unreachable("Invalid opcode provided");
+  case Trunc:
+    return new TruncInst(S, Ty, Name, InsertBefore);
+  case ZExt:
+    return new ZExtInst(S, Ty, Name, InsertBefore);
+  case SExt:
+    return new SExtInst(S, Ty, Name, InsertBefore);
+  case FPTrunc:
+    return new FPTruncInst(S, Ty, Name, InsertBefore);
+  case FPExt:
+    return new FPExtInst(S, Ty, Name, InsertBefore);
+  case UIToFP:
+    return new UIToFPInst(S, Ty, Name, InsertBefore);
+  case SIToFP:
+    return new SIToFPInst(S, Ty, Name, InsertBefore);
+  case FPToUI:
+    return new FPToUIInst(S, Ty, Name, InsertBefore);
+  case FPToSI:
+    return new FPToSIInst(S, Ty, Name, InsertBefore);
+  case PtrToInt:
+    return new PtrToIntInst(S, Ty, Name, InsertBefore);
+  case IntToPtr:
+    return new IntToPtrInst(S, Ty, Name, InsertBefore);
+  case BitCast:
+    return new BitCastInst(S, Ty, Name, InsertBefore);
+  case AddrSpaceCast:
+    return new AddrSpaceCastInst(S, Ty, Name, InsertBefore);
+  default:
+    llvm_unreachable("Invalid opcode provided");
   }
 }
 
@@ -3848,9 +3861,11 @@ CastInst *CastInst::CreateIntegerCast(Value *C, Type *Ty, bool isSigned,
   unsigned SrcBits = C->getType()->getScalarSizeInBits();
   unsigned DstBits = Ty->getScalarSizeInBits();
   Instruction::CastOps opcode =
-    (SrcBits == DstBits ? Instruction::BitCast :
-     (SrcBits > DstBits ? Instruction::Trunc :
-      (isSigned ? Instruction::SExt : Instruction::ZExt)));
+      (SrcBits == DstBits
+           ? Instruction::BitCast
+           : (SrcBits > DstBits
+                  ? Instruction::Trunc
+                  : (isSigned ? Instruction::SExt : Instruction::ZExt)));
   return Create(opcode, C, Ty, Name, InsertBefore);
 }
 
@@ -3889,8 +3904,9 @@ CastInst *CastInst::CreateFPCast(Value *C, Type *Ty, const Twine &Name,
   unsigned SrcBits = C->getType()->getScalarSizeInBits();
   unsigned DstBits = Ty->getScalarSizeInBits();
   Instruction::CastOps opcode =
-    (SrcBits == DstBits ? Instruction::BitCast :
-     (SrcBits > DstBits ? Instruction::FPTrunc : Instruction::FPExt));
+      (SrcBits == DstBits
+           ? Instruction::BitCast
+           : (SrcBits > DstBits ? Instruction::FPTrunc : Instruction::FPExt));
   return Create(opcode, C, Ty, Name, InsertBefore);
 }
 

@jmorse
Copy link
Member Author

jmorse commented Feb 23, 2024

NB: adding all these extra lines in headers that all of LLVM includes leads to a 0.15% increase in stage2 compile time [0], which is unfortunate. This is another things that transitional though: we're also going to be deleting the instruction-taking methods, so we'll eventually return back to the same place.

[0] http://llvm-compile-time-tracker.com/compare.php?from=ddba6b271c07b4bb640b2f2b742710557a762142&to=f8100ed09d6b4b9bfb31e179d027b2d14d3b454d&stat=instructions%3Au

Copy link
Contributor

@OCHyams OCHyams left a comment

Choose a reason for hiding this comment

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

However, I figure it's worth /some/ review of the general approach, just to confirm that I haven't missed anything obvious that's going on.

I looked at the whole thing (agree it is quite boring, but I can't imagine it was much more fun to write... thank you!).

What do you think we should do with the Instruction* versions?

  • Are there remaining uses in LLVM? If so, should those be updated now/immediately?
  • When should they be removed?

LGTM

/// the specified instruction.
/// Create a CmpInst
static CmpInst *Create(OtherOps Op, Predicate predicate, Value *S1, Value *S2,
const Twine &Name, BasicBlock::iterator InsertBefore);
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: formatting is different here (for others it looks like the formatting is identical to the Instruction* versions?). Not sure which is correctly clang-formatted, just pointing it out in case it's an accident.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yarp; I ran clang-format-patch and filtered in everything in the newly added functions. Differences with the existing code are because the existing formatting isn't compliant, again to reduce the size of the diff I didn't want those to be updated.

const Twine &NameStr,
BasicBlock::iterator InsertBefore,
Instruction *MDFrom = nullptr) {
SelectInst *Sel = new (3) SelectInst(C, S1, S2, NameStr, InsertBefore);
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: existing format is new(3) (yours is new (3) with a space). Feel free to ignore if clang-format is happy.

Copy link
Member Author

Choose a reason for hiding this comment

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

clang-format wanted the space, it also wanted me to fix the existing code but I felt that'd make it harder to review

@jmorse
Copy link
Member Author

jmorse commented Feb 26, 2024

Are there remaining uses in LLVM? If so, should those be updated now/immediately?

Many many uses, all this patch does is add the alternatives (see the discourse topic for RemoveDIs, they're already needed, oops).

When should they be removed?

Two competing narratives:

  • People downstream need time to fix up their passes, we should go slow and gently,
  • Using the wrong inserter risks producing the wrong debug-info, in rare case compiler-crashes, and it's better to fix everything up rapidly rather than having "death by a thousand cuts"

I feel like the latter is more persuasive, especially as the fix for 99% of scenarios is entirely mechanical, i.e. call getIterator or don't-dereference-the-iterator.

@jmorse
Copy link
Member Author

jmorse commented Feb 26, 2024

Ran a test again locally and this all looks good; thanks for wading through so many lines!

@jmorse jmorse merged commit 76dd4bc into llvm:main Feb 26, 2024
4 of 6 checks passed
@fel-cab
Copy link
Contributor

fel-cab commented Mar 4, 2024

This commit requires changing: llvm/examples/ParallelJIT/ParallelJIT.cpp, line 107
Value *CondInst = new ICmpInst(*BB, ICmpInst::ICMP_SLE, ArgX, Two, "cond");
for
Value *CondInst = new ICmpInst(BB, ICmpInst::ICMP_SLE, ArgX, Two, "cond");
As it breaks LLVM build

@jmorse
Copy link
Member Author

jmorse commented Mar 4, 2024

Fixed in df52521; apologies, I must have missed a buildbot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants