diff --git a/llvm/include/llvm/IR/InstrTypes.h b/llvm/include/llvm/IR/InstrTypes.h index e8c2cba8418dc..41cc14d438a83 100644 --- a/llvm/include/llvm/IR/InstrTypes.h +++ b/llvm/include/llvm/IR/InstrTypes.h @@ -59,13 +59,13 @@ class UnaryInstruction : public Instruction { : 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) { + UnaryInstruction(Type *Ty, unsigned iType, Value *V, Instruction *IB) + : Instruction(Ty, iType, &Op<0>(), 1, IB) { Op<0>() = V; } - UnaryInstruction(Type *Ty, unsigned iType, Value *V, BasicBlock *IAE) - : Instruction(Ty, iType, &Op<0>(), 1, IAE) { + UnaryInstruction(Type *Ty, unsigned iType, Value *V, + BasicBlock *IAE = nullptr) + : Instruction(Ty, iType, &Op<0>(), 1, IAE) { Op<0>() = V; } @@ -131,17 +131,16 @@ class UnaryOperator : public UnaryInstruction { /// into a BasicBlock right before the specified instruction. The specified /// Instruction is allowed to be a dereferenced end iterator. /// - static UnaryOperator *Create(UnaryOps Op, Value *S, - const Twine &Name = Twine(), - Instruction *InsertBefore = nullptr); + static UnaryOperator *Create(UnaryOps Op, Value *S, const Twine &Name, + Instruction *InsertBefore); /// Construct a unary instruction, given the opcode and an operand. /// Also automatically insert this instruction to the end of the /// BasicBlock specified. /// static UnaryOperator *Create(UnaryOps Op, Value *S, - const Twine &Name, - BasicBlock *InsertAtEnd); + const Twine &Name = Twine(), + BasicBlock *InsertAtEnd = nullptr); /// These methods just forward to Create, and are useful when you /// statically know what type of instruction you're going to create. These @@ -178,11 +177,20 @@ class UnaryOperator : public UnaryInstruction { return UO; } + static UnaryOperator *CreateWithCopiedFlags(UnaryOps Opc, Value *V, + Instruction *CopyO, + const Twine &Name, + Instruction *InsertBefore) { + UnaryOperator *UO = Create(Opc, V, Name, InsertBefore); + UO->copyIRFlags(CopyO); + return UO; + } + static UnaryOperator * CreateWithCopiedFlags(UnaryOps Opc, Value *V, Instruction *CopyO, const Twine &Name = "", - Instruction *InsertBefore = nullptr) { - UnaryOperator *UO = Create(Opc, V, Name, InsertBefore); + BasicBlock *InsertAtEnd = nullptr) { + UnaryOperator *UO = Create(Opc, V, Name, InsertAtEnd); UO->copyIRFlags(CopyO); return UO; } @@ -195,12 +203,19 @@ class UnaryOperator : public UnaryInstruction { } static UnaryOperator *CreateFNegFMF(Value *Op, Instruction *FMFSource, - const Twine &Name = "", - Instruction *InsertBefore = nullptr) { + const Twine &Name, + Instruction *InsertBefore) { return CreateWithCopiedFlags(Instruction::FNeg, Op, FMFSource, Name, InsertBefore); } + static UnaryOperator *CreateFNegFMF(Value *Op, Instruction *FMFSource, + const Twine &Name = "", + BasicBlock *InsertAtEnd = nullptr) { + return CreateWithCopiedFlags(Instruction::FNeg, Op, FMFSource, Name, + InsertAtEnd); + } + UnaryOps getOpcode() const { return static_cast(Instruction::getOpcode()); } @@ -256,15 +271,15 @@ class BinaryOperator : public Instruction { /// Instruction is allowed to be a dereferenced end iterator. /// static BinaryOperator *Create(BinaryOps Op, Value *S1, Value *S2, - const Twine &Name = Twine(), - Instruction *InsertBefore = nullptr); + const Twine &Name, Instruction *InsertBefore); /// Construct a binary instruction, given the opcode and the two /// operands. Also automatically insert this instruction to the end of the /// BasicBlock specified. /// static BinaryOperator *Create(BinaryOps Op, Value *S1, Value *S2, - const Twine &Name, BasicBlock *InsertAtEnd); + const Twine &Name = Twine(), + BasicBlock *InsertAtEnd = nullptr); /// These methods just forward to Create, and are useful when you /// statically know what type of instruction you're going to create. These @@ -302,11 +317,20 @@ class BinaryOperator : public Instruction { return BO; } + static BinaryOperator *CreateWithCopiedFlags(BinaryOps Opc, Value *V1, + Value *V2, Value *CopyO, + const Twine &Name, + Instruction *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, const Twine &Name = "", - Instruction *InsertBefore = nullptr) { - BinaryOperator *BO = Create(Opc, V1, V2, Name, InsertBefore); + BasicBlock *InsertAtEnd = nullptr) { + BinaryOperator *BO = Create(Opc, V1, V2, Name, InsertAtEnd); BO->copyIRFlags(CopyO); return BO; } @@ -472,22 +496,22 @@ class BinaryOperator : public Instruction { BasicBlock *InsertAtEnd = nullptr); 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); + Instruction *InsertBefore); + static BinaryOperator *CreateNSWNeg(Value *Op, const Twine &Name = "", + BasicBlock *InsertAtEnd = nullptr); 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); + Instruction *InsertBefore); + static BinaryOperator *CreateNUWNeg(Value *Op, const Twine &Name = "", + BasicBlock *InsertAtEnd = nullptr); 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, - BasicBlock *InsertAtEnd); + Instruction *InsertBefore); + static BinaryOperator *CreateNot(Value *Op, const Twine &Name = "", + BasicBlock *InsertAtEnd = nullptr); BinaryOps getOpcode() const { return static_cast(Instruction::getOpcode()); @@ -586,15 +610,15 @@ class CastInst : public UnaryInstruction { setName(NameStr); } /// Constructor with insert-before-instruction semantics for subclasses - CastInst(Type *Ty, unsigned iType, Value *S, - const Twine &NameStr = "", Instruction *InsertBefore = nullptr) - : UnaryInstruction(Ty, iType, S, InsertBefore) { + CastInst(Type *Ty, unsigned iType, Value *S, const Twine &NameStr, + Instruction *InsertBefore) + : UnaryInstruction(Ty, iType, S, InsertBefore) { setName(NameStr); } /// Constructor with insert-at-end-of-block semantics for subclasses - CastInst(Type *Ty, unsigned iType, Value *S, - const Twine &NameStr, BasicBlock *InsertAtEnd) - : UnaryInstruction(Ty, iType, S, InsertAtEnd) { + CastInst(Type *Ty, unsigned iType, Value *S, const Twine &NameStr = "", + BasicBlock *InsertAtEnd = nullptr) + : UnaryInstruction(Ty, iType, S, InsertAtEnd) { setName(NameStr); } @@ -618,12 +642,12 @@ class CastInst : public UnaryInstruction { /// constructor has insert-before-instruction semantics to automatically /// insert the new CastInst before InsertBefore (if it is non-null). /// 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 - Instruction *InsertBefore = nullptr ///< Place to insert the instruction + 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 + Instruction *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 @@ -631,12 +655,13 @@ class CastInst : public UnaryInstruction { /// to automatically insert the new CastInst at the end of InsertAtEnd (if /// its non-null). /// Construct any of the CastInst subclasses - static CastInst *Create( - Instruction::CastOps, ///< The opcode for the cast instruction - Value *S, ///< The value to be casted (operand 0) - Type *Ty, ///< The type to which operand is casted - const Twine &Name, ///< The name for the instruction - BasicBlock *InsertAtEnd ///< The block to insert the instruction into + static CastInst * + Create(Instruction::CastOps, ///< The opcode for the cast instruction + Value *S, ///< The value to be casted (operand 0) + Type *Ty, ///< The type to which operand is casted + const Twine &Name = "", ///< The name for the instruction + BasicBlock *InsertAtEnd = + nullptr ///< The block to insert the instruction into ); /// Create a ZExt or BitCast cast instruction @@ -649,18 +674,19 @@ class CastInst : public UnaryInstruction { /// 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 - Instruction *InsertBefore = nullptr ///< 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 + Instruction *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) - Type *Ty, ///< The type to which operand is casted - const Twine &Name, ///< The name for the instruction - BasicBlock *InsertAtEnd ///< The block to insert the instruction into + static CastInst * + CreateZExtOrBitCast(Value *S, ///< The value to be casted (operand 0) + Type *Ty, ///< The type to which operand is casted + const Twine &Name = "", ///< The name for the instruction + BasicBlock *InsertAtEnd = + nullptr ///< The block to insert the instruction into ); /// Create a SExt or BitCast cast instruction @@ -673,26 +699,28 @@ class CastInst : public UnaryInstruction { /// 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 - Instruction *InsertBefore = nullptr ///< 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 + Instruction *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) - Type *Ty, ///< The type to which operand is casted - const Twine &Name, ///< The name for the instruction - BasicBlock *InsertAtEnd ///< The block to insert the instruction into + static CastInst * + CreateSExtOrBitCast(Value *S, ///< The value to be casted (operand 0) + Type *Ty, ///< The type to which operand is casted + const Twine &Name = "", ///< The name for the instruction + BasicBlock *InsertAtEnd = + nullptr ///< 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 operand is casted - const Twine &Name, ///< The name for the instruction - BasicBlock *InsertAtEnd ///< The block to insert the instruction into + static CastInst * + CreatePointerCast(Value *S, ///< The pointer value to be casted (operand 0) + Type *Ty, ///< The type to which operand is casted + const Twine &Name = "", ///< The name for the instruction + BasicBlock *InsertAtEnd = + nullptr ///< The block to insert the instruction into ); /// Create a BitCast, AddrSpaceCast or a PtrToInt cast instruction. @@ -705,18 +733,19 @@ class CastInst : public UnaryInstruction { /// 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 - Instruction *InsertBefore = nullptr ///< 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 + Instruction *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) - Type *Ty, ///< The type to which operand is casted - const Twine &Name, ///< The name for the instruction - BasicBlock *InsertAtEnd ///< The block to insert the instruction into + Value *S, ///< The pointer value to be casted (operand 0) + Type *Ty, ///< The type to which operand is casted + const Twine &Name = "", ///< The name for the instruction + BasicBlock *InsertAtEnd = + nullptr ///< The block to insert the instruction into ); /// Create a BitCast or an AddrSpaceCast cast instruction. @@ -729,10 +758,10 @@ class CastInst : public UnaryInstruction { /// 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 - Instruction *InsertBefore = nullptr ///< 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 + Instruction *InsertBefore ///< Place to insert the instruction ); /// Create a BitCast, a PtrToInt, or an IntToPTr cast instruction. @@ -755,10 +784,23 @@ class CastInst : public UnaryInstruction { /// 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 - Instruction *InsertBefore = nullptr ///< 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 + Instruction *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, + /// 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 *InsertAtEnd = nullptr ///< Place to insert the instruction ); /// Create a ZExt, BitCast, or Trunc for int -> int casts. @@ -772,20 +814,21 @@ class CastInst : public UnaryInstruction { /// 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 - Instruction *InsertBefore = nullptr ///< 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 + Instruction *InsertBefore ///< Place to insert the instruction ); /// Create a ZExt, BitCast, or Trunc for int -> int casts. - static CastInst *CreateIntegerCast( - Value *S, ///< The integer value to be casted (operand 0) - Type *Ty, ///< The integer type to which operand is casted - bool isSigned, ///< Whether to regard S as signed or not - const Twine &Name, ///< The name for the instruction - BasicBlock *InsertAtEnd ///< The block to insert the instruction into + static CastInst * + CreateIntegerCast(Value *S, ///< The integer value to be casted (operand 0) + Type *Ty, ///< The integer type to which operand is casted + bool isSigned, ///< Whether to regard S as signed or not + const Twine &Name = "", ///< The name for the instruction + BasicBlock *InsertAtEnd = + nullptr ///< The block to insert the instruction into ); /// Create an FPExt, BitCast, or FPTrunc for fp -> fp casts @@ -797,19 +840,20 @@ class CastInst : public UnaryInstruction { ); /// 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 - Instruction *InsertBefore = nullptr ///< Place to insert the instruction + 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 + Instruction *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 - Type *Ty, ///< The floating point type to cast to - const Twine &Name, ///< The name for the instruction - BasicBlock *InsertAtEnd ///< The block to insert the instruction into + static CastInst * + CreateFPCast(Value *S, ///< The floating point value to be casted + Type *Ty, ///< The floating point type to cast to + const Twine &Name = "", ///< The name for the instruction + BasicBlock *InsertAtEnd = + nullptr ///< The block to insert the instruction into ); /// Create a Trunc or BitCast cast instruction @@ -822,18 +866,19 @@ class CastInst : public UnaryInstruction { /// 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 - Instruction *InsertBefore = nullptr ///< 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 + Instruction *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) - Type *Ty, ///< The type to which operand is casted - const Twine &Name, ///< The name for the instruction - BasicBlock *InsertAtEnd ///< The block to insert the instruction into + static CastInst * + CreateTruncOrBitCast(Value *S, ///< The value to be casted (operand 0) + Type *Ty, ///< The type to which operand is casted + const Twine &Name = "", ///< The name for the instruction + BasicBlock *InsertAtEnd = + nullptr ///< The block to insert the instruction into ); /// Check whether a bitcast between these types is valid @@ -1020,14 +1065,13 @@ class CmpInst : public Instruction { 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, + CmpInst(Type *ty, Instruction::OtherOps op, Predicate pred, Value *LHS, + Value *RHS, const Twine &Name, Instruction *InsertBefore, Instruction *FlagsSource = nullptr); - CmpInst(Type *ty, Instruction::OtherOps op, Predicate pred, - Value *LHS, Value *RHS, const Twine &Name, - BasicBlock *InsertAtEnd); + CmpInst(Type *ty, Instruction::OtherOps op, Predicate pred, Value *LHS, + Value *RHS, const Twine &Name = "", + BasicBlock *InsertAtEnd = nullptr); public: // allocate space for exactly two operands @@ -1046,17 +1090,16 @@ class CmpInst : public Instruction { /// instruction into a BasicBlock right before the specified instruction. /// The specified Instruction is allowed to be a dereferenced end iterator. /// Create a CmpInst - static CmpInst *Create(OtherOps Op, - Predicate predicate, Value *S1, - Value *S2, const Twine &Name = "", - Instruction *InsertBefore = nullptr); + static CmpInst *Create(OtherOps Op, Predicate predicate, Value *S1, Value *S2, + const Twine &Name, Instruction *InsertBefore); /// Construct a compare instruction, given the opcode, the predicate and the /// two operands. Also automatically insert this instruction to the end of /// the BasicBlock specified. /// Create a CmpInst - static CmpInst *Create(OtherOps Op, Predicate predicate, Value *S1, - Value *S2, const Twine &Name, BasicBlock *InsertAtEnd); + static CmpInst *Create(OtherOps Op, Predicate predicate, Value *S1, Value *S2, + const Twine &Name = "", + BasicBlock *InsertAtEnd = nullptr); /// Get the opcode casted to the right type OtherOps getOpcode() const { @@ -1513,7 +1556,16 @@ class CallBase : public Instruction { /// the operand bundles for the new instruction are set to the operand bundles /// in \p Bundles. static CallBase *Create(CallBase *CB, ArrayRef Bundles, - Instruction *InsertPt = nullptr); + Instruction *InsertPt); + + /// Create a clone of \p CB with a different set of operand bundles and + /// insert it at the end of \p InsertAtEnd. + /// + /// 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 Bundles, + BasicBlock *InsertAtEnd = nullptr); /// Create a clone of \p CB with the operand bundle with the tag matching /// \p Bundle's tag replaced with Bundle, and insert it before \p InsertPt. @@ -1528,14 +1580,26 @@ class CallBase : public Instruction { /// /// The returned call instruction is identical \p CI in every way except that /// the specified operand bundle has been replaced. - static CallBase *Create(CallBase *CB, - OperandBundleDef Bundle, - Instruction *InsertPt = nullptr); + static CallBase *Create(CallBase *CB, OperandBundleDef Bundle, + Instruction *InsertPt); + + /// Create a clone of \p CB with the operand bundle with the tag matching + /// \p Bundle's tag replaced with Bundle, and insert it at the end of \p + /// InsertAtEnd. + /// + /// The returned call instruction is identical \p CI in every way except that + /// the specified operand bundle has been replaced. + static CallBase *Create(CallBase *CB, OperandBundleDef Bundle, + BasicBlock *InsertAtEnd = nullptr); + + /// Create a clone of \p CB with operand bundle \p OB added. + static CallBase *addOperandBundle(CallBase *CB, uint32_t ID, + OperandBundleDef OB, Instruction *InsertPt); /// Create a clone of \p CB with operand bundle \p OB added. static CallBase *addOperandBundle(CallBase *CB, uint32_t ID, OperandBundleDef OB, - Instruction *InsertPt = nullptr); + BasicBlock *InsertAtEnd = nullptr); /// Create a clone of \p CB with operand bundle \p OB added. static CallBase *addOperandBundle(CallBase *CB, uint32_t ID, @@ -1544,7 +1608,11 @@ class CallBase : public Instruction { /// Create a clone of \p CB with operand bundle \p ID removed. static CallBase *removeOperandBundle(CallBase *CB, uint32_t ID, - Instruction *InsertPt = nullptr); + Instruction *InsertPt); + + /// Create a clone of \p CB with operand bundle \p ID removed. + static CallBase *removeOperandBundle(CallBase *CB, uint32_t ID, + BasicBlock *InsertAtEnd = nullptr); /// Create a clone of \p CB with operand bundle \p ID removed. static CallBase *removeOperandBundle(CallBase *CB, uint32_t ID, diff --git a/llvm/include/llvm/IR/Instruction.h b/llvm/include/llvm/IR/Instruction.h index 6e0874c5b04f2..08e305a6eb141 100644 --- a/llvm/include/llvm/IR/Instruction.h +++ b/llvm/include/llvm/IR/Instruction.h @@ -1012,9 +1012,9 @@ class Instruction : public User, Instruction(Type *Ty, unsigned iType, Use *Ops, unsigned NumOps, InstListType::iterator InsertBefore); Instruction(Type *Ty, unsigned iType, Use *Ops, unsigned NumOps, - Instruction *InsertBefore = nullptr); + Instruction *InsertBefore); Instruction(Type *Ty, unsigned iType, Use *Ops, unsigned NumOps, - BasicBlock *InsertAtEnd); + BasicBlock *InsertAtEnd = nullptr); private: /// Create a copy of this instruction. diff --git a/llvm/include/llvm/IR/Instructions.h b/llvm/include/llvm/IR/Instructions.h index 4e4cf71a349d7..58303225d341d 100644 --- a/llvm/include/llvm/IR/Instructions.h +++ b/llvm/include/llvm/IR/Instructions.h @@ -90,9 +90,9 @@ class AllocaInst : public UnaryInstruction { AllocaInst(Type *Ty, unsigned AddrSpace, Value *ArraySize, Align Align, const Twine &Name, BasicBlock::iterator); AllocaInst(Type *Ty, unsigned AddrSpace, Value *ArraySize, Align Align, - const Twine &Name = "", Instruction *InsertBefore = nullptr); + const Twine &Name, Instruction *InsertBefore); AllocaInst(Type *Ty, unsigned AddrSpace, Value *ArraySize, Align Align, - const Twine &Name, BasicBlock *InsertAtEnd); + const Twine &Name = "", BasicBlock *InsertAtEnd = nullptr); /// Return true if there is an allocation size parameter to the allocation /// instruction that is not 1. @@ -212,19 +212,19 @@ class LoadInst : public UnaryInstruction { LoadInst(Type *Ty, Value *Ptr, const Twine &NameStr, bool isVolatile, Align Align, BasicBlock::iterator InsertBefore); LoadInst(Type *Ty, Value *Ptr, const Twine &NameStr, bool isVolatile, - Align Align, Instruction *InsertBefore = nullptr); + Align Align, Instruction *InsertBefore); LoadInst(Type *Ty, Value *Ptr, const Twine &NameStr, bool isVolatile, - Align Align, BasicBlock *InsertAtEnd); + Align Align, BasicBlock *InsertAtEnd = nullptr); LoadInst(Type *Ty, Value *Ptr, const Twine &NameStr, bool isVolatile, Align Align, AtomicOrdering Order, SyncScope::ID SSID, BasicBlock::iterator InsertBefore); + LoadInst(Type *Ty, Value *Ptr, const Twine &NameStr, bool isVolatile, + Align Align, AtomicOrdering Order, SyncScope::ID SSID, + Instruction *InsertBefore); LoadInst(Type *Ty, Value *Ptr, const Twine &NameStr, bool isVolatile, Align Align, AtomicOrdering Order, SyncScope::ID SSID = SyncScope::System, - Instruction *InsertBefore = nullptr); - LoadInst(Type *Ty, Value *Ptr, const Twine &NameStr, bool isVolatile, - Align Align, AtomicOrdering Order, SyncScope::ID SSID, - BasicBlock *InsertAtEnd); + BasicBlock *InsertAtEnd = nullptr); /// Return true if this is a load from a volatile memory location. bool isVolatile() const { return getSubclassData(); } @@ -339,16 +339,17 @@ class StoreInst : public Instruction { StoreInst(Value *Val, Value *Ptr, bool isVolatile, BasicBlock::iterator InsertBefore); StoreInst(Value *Val, Value *Ptr, bool isVolatile, Align Align, - Instruction *InsertBefore = nullptr); + Instruction *InsertBefore); StoreInst(Value *Val, Value *Ptr, bool isVolatile, Align Align, - BasicBlock *InsertAtEnd); + BasicBlock *InsertAtEnd = nullptr); StoreInst(Value *Val, Value *Ptr, bool isVolatile, Align Align, BasicBlock::iterator InsertBefore); StoreInst(Value *Val, Value *Ptr, bool isVolatile, Align Align, - AtomicOrdering Order, SyncScope::ID SSID = SyncScope::System, - Instruction *InsertBefore = nullptr); + AtomicOrdering Order, SyncScope::ID SSID, + Instruction *InsertBefore); StoreInst(Value *Val, Value *Ptr, bool isVolatile, Align Align, - AtomicOrdering Order, SyncScope::ID SSID, BasicBlock *InsertAtEnd); + AtomicOrdering Order, SyncScope::ID SSID = SyncScope::System, + BasicBlock *InsertAtEnd = nullptr); StoreInst(Value *Val, Value *Ptr, bool isVolatile, Align Align, AtomicOrdering Order, SyncScope::ID SSID, BasicBlock::iterator InsertBefore); @@ -473,11 +474,11 @@ class FenceInst : public Instruction { // SequentiallyConsistent. FenceInst(LLVMContext &C, AtomicOrdering Ordering, SyncScope::ID SSID, BasicBlock::iterator InsertBefore); + FenceInst(LLVMContext &C, AtomicOrdering Ordering, SyncScope::ID SSID, + Instruction *InsertBefore); FenceInst(LLVMContext &C, AtomicOrdering Ordering, SyncScope::ID SSID = SyncScope::System, - Instruction *InsertBefore = nullptr); - FenceInst(LLVMContext &C, AtomicOrdering Ordering, SyncScope::ID SSID, - BasicBlock *InsertAtEnd); + BasicBlock *InsertAtEnd = nullptr); // allocate space for exactly zero operands void *operator new(size_t S) { return User::operator new(S, 0); } @@ -560,11 +561,11 @@ class AtomicCmpXchgInst : public Instruction { AtomicCmpXchgInst(Value *Ptr, Value *Cmp, Value *NewVal, Align Alignment, AtomicOrdering SuccessOrdering, AtomicOrdering FailureOrdering, SyncScope::ID SSID, - Instruction *InsertBefore = nullptr); + Instruction *InsertBefore); AtomicCmpXchgInst(Value *Ptr, Value *Cmp, Value *NewVal, Align Alignment, AtomicOrdering SuccessOrdering, AtomicOrdering FailureOrdering, SyncScope::ID SSID, - BasicBlock *InsertAtEnd); + BasicBlock *InsertAtEnd = nullptr); // allocate space for exactly three operands void *operator new(size_t S) { return User::operator new(S, 3); } @@ -824,10 +825,10 @@ class AtomicRMWInst : public Instruction { BasicBlock::iterator InsertBefore); AtomicRMWInst(BinOp Operation, Value *Ptr, Value *Val, Align Alignment, AtomicOrdering Ordering, SyncScope::ID SSID, - Instruction *InsertBefore = nullptr); + Instruction *InsertBefore); AtomicRMWInst(BinOp Operation, Value *Ptr, Value *Val, Align Alignment, AtomicOrdering Ordering, SyncScope::ID SSID, - BasicBlock *InsertAtEnd); + BasicBlock *InsertAtEnd = nullptr); // allocate space for exactly two operands void *operator new(size_t S) { return User::operator new(S, 2); } @@ -1012,8 +1013,8 @@ class GetElementPtrInst : public Instruction { static GetElementPtrInst *Create(Type *PointeeType, Value *Ptr, ArrayRef IdxList, - const Twine &NameStr = "", - Instruction *InsertBefore = nullptr) { + const Twine &NameStr, + Instruction *InsertBefore) { unsigned Values = 1 + unsigned(IdxList.size()); assert(PointeeType && "Must specify element type"); return new (Values) GetElementPtrInst(PointeeType, Ptr, IdxList, Values, @@ -1022,8 +1023,8 @@ class GetElementPtrInst : public Instruction { static GetElementPtrInst *Create(Type *PointeeType, Value *Ptr, ArrayRef IdxList, - const Twine &NameStr, - BasicBlock *InsertAtEnd) { + const Twine &NameStr = "", + BasicBlock *InsertAtEnd = nullptr) { unsigned Values = 1 + unsigned(IdxList.size()); assert(PointeeType && "Must specify element type"); return new (Values) GetElementPtrInst(PointeeType, Ptr, IdxList, Values, @@ -1042,10 +1043,10 @@ class GetElementPtrInst : public Instruction { return GEP; } - static GetElementPtrInst * - CreateInBounds(Type *PointeeType, Value *Ptr, ArrayRef IdxList, - const Twine &NameStr = "", - Instruction *InsertBefore = nullptr) { + static GetElementPtrInst *CreateInBounds(Type *PointeeType, Value *Ptr, + ArrayRef IdxList, + const Twine &NameStr, + Instruction *InsertBefore) { GetElementPtrInst *GEP = Create(PointeeType, Ptr, IdxList, NameStr, InsertBefore); GEP->setIsInBounds(true); @@ -1054,8 +1055,8 @@ class GetElementPtrInst : public Instruction { static GetElementPtrInst *CreateInBounds(Type *PointeeType, Value *Ptr, ArrayRef IdxList, - const Twine &NameStr, - BasicBlock *InsertAtEnd) { + const Twine &NameStr = "", + BasicBlock *InsertAtEnd = nullptr) { GetElementPtrInst *GEP = Create(PointeeType, Ptr, IdxList, NameStr, InsertAtEnd); GEP->setIsInBounds(true); @@ -1622,8 +1623,8 @@ class CallInst : public CallBase { return new (ComputeNumOperands(0)) CallInst(Ty, F, NameStr, InsertBefore); } - static CallInst *Create(FunctionType *Ty, Value *F, const Twine &NameStr = "", - Instruction *InsertBefore = nullptr) { + static CallInst *Create(FunctionType *Ty, Value *F, const Twine &NameStr, + Instruction *InsertBefore) { return new (ComputeNumOperands(0)) CallInst(Ty, F, NameStr, InsertBefore); } @@ -1635,8 +1636,7 @@ class CallInst : public CallBase { } static CallInst *Create(FunctionType *Ty, Value *Func, ArrayRef Args, - const Twine &NameStr, - Instruction *InsertBefore = nullptr) { + const Twine &NameStr, Instruction *InsertBefore) { return new (ComputeNumOperands(Args.size())) CallInst(Ty, Func, Args, std::nullopt, NameStr, InsertBefore); } @@ -1654,9 +1654,8 @@ class CallInst : public CallBase { } static CallInst *Create(FunctionType *Ty, Value *Func, ArrayRef Args, - ArrayRef Bundles = std::nullopt, - const Twine &NameStr = "", - Instruction *InsertBefore = nullptr) { + ArrayRef Bundles, + const Twine &NameStr, Instruction *InsertBefore) { const int NumOperands = ComputeNumOperands(Args.size(), CountBundleInputs(Bundles)); const unsigned DescriptorBytes = Bundles.size() * sizeof(BundleOpInfo); @@ -1665,20 +1664,22 @@ class CallInst : public CallBase { CallInst(Ty, Func, Args, Bundles, NameStr, InsertBefore); } - static CallInst *Create(FunctionType *Ty, Value *F, const Twine &NameStr, - BasicBlock *InsertAtEnd) { + static CallInst *Create(FunctionType *Ty, Value *F, const Twine &NameStr = "", + BasicBlock *InsertAtEnd = nullptr) { return new (ComputeNumOperands(0)) CallInst(Ty, F, NameStr, InsertAtEnd); } static CallInst *Create(FunctionType *Ty, Value *Func, ArrayRef Args, - const Twine &NameStr, BasicBlock *InsertAtEnd) { + const Twine &NameStr, + BasicBlock *InsertAtEnd = nullptr) { return new (ComputeNumOperands(Args.size())) CallInst(Ty, Func, Args, std::nullopt, NameStr, InsertAtEnd); } static CallInst *Create(FunctionType *Ty, Value *Func, ArrayRef Args, - ArrayRef Bundles, - const Twine &NameStr, BasicBlock *InsertAtEnd) { + ArrayRef Bundles = std::nullopt, + const Twine &NameStr = "", + BasicBlock *InsertAtEnd = nullptr) { const int NumOperands = ComputeNumOperands(Args.size(), CountBundleInputs(Bundles)); const unsigned DescriptorBytes = Bundles.size() * sizeof(BundleOpInfo); @@ -1693,8 +1694,8 @@ class CallInst : public CallBase { InsertBefore); } - static CallInst *Create(FunctionCallee Func, const Twine &NameStr = "", - Instruction *InsertBefore = nullptr) { + static CallInst *Create(FunctionCallee Func, const Twine &NameStr, + Instruction *InsertBefore) { return Create(Func.getFunctionType(), Func.getCallee(), NameStr, InsertBefore); } @@ -1708,9 +1709,8 @@ class CallInst : public CallBase { } static CallInst *Create(FunctionCallee Func, ArrayRef Args, - ArrayRef Bundles = std::nullopt, - const Twine &NameStr = "", - Instruction *InsertBefore = nullptr) { + ArrayRef Bundles, + const Twine &NameStr, Instruction *InsertBefore) { return Create(Func.getFunctionType(), Func.getCallee(), Args, Bundles, NameStr, InsertBefore); } @@ -1723,27 +1723,28 @@ class CallInst : public CallBase { } static CallInst *Create(FunctionCallee Func, ArrayRef Args, - const Twine &NameStr, - Instruction *InsertBefore = nullptr) { + const Twine &NameStr, Instruction *InsertBefore) { return Create(Func.getFunctionType(), Func.getCallee(), Args, NameStr, InsertBefore); } - static CallInst *Create(FunctionCallee Func, const Twine &NameStr, - BasicBlock *InsertAtEnd) { + static CallInst *Create(FunctionCallee Func, const Twine &NameStr = "", + BasicBlock *InsertAtEnd = nullptr) { return Create(Func.getFunctionType(), Func.getCallee(), NameStr, InsertAtEnd); } static CallInst *Create(FunctionCallee Func, ArrayRef Args, - const Twine &NameStr, BasicBlock *InsertAtEnd) { + const Twine &NameStr, + BasicBlock *InsertAtEnd = nullptr) { return Create(Func.getFunctionType(), Func.getCallee(), Args, NameStr, InsertAtEnd); } static CallInst *Create(FunctionCallee Func, ArrayRef Args, - ArrayRef Bundles, - const Twine &NameStr, BasicBlock *InsertAtEnd) { + ArrayRef Bundles = std::nullopt, + const Twine &NameStr = "", + BasicBlock *InsertAtEnd = nullptr) { return Create(Func.getFunctionType(), Func.getCallee(), Args, Bundles, NameStr, InsertAtEnd); } @@ -1757,7 +1758,9 @@ class CallInst : public CallBase { static CallInst *Create(CallInst *CI, ArrayRef Bundles, BasicBlock::iterator InsertPt); static CallInst *Create(CallInst *CI, ArrayRef Bundles, - Instruction *InsertPt = nullptr); + Instruction *InsertPt); + static CallInst *Create(CallInst *CI, ArrayRef Bundles, + BasicBlock *InsertAtEnd = nullptr); // Note that 'musttail' implies 'tail'. enum TailCallKind : unsigned { @@ -1907,8 +1910,7 @@ class SelectInst : public Instruction { } static SelectInst *Create(Value *C, Value *S1, Value *S2, - const Twine &NameStr = "", - Instruction *InsertBefore = nullptr, + const Twine &NameStr, Instruction *InsertBefore, Instruction *MDFrom = nullptr) { SelectInst *Sel = new(3) SelectInst(C, S1, S2, NameStr, InsertBefore); if (MDFrom) @@ -1917,8 +1919,8 @@ class SelectInst : public Instruction { } static SelectInst *Create(Value *C, Value *S1, Value *S2, - const Twine &NameStr, - BasicBlock *InsertAtEnd) { + const Twine &NameStr = "", + BasicBlock *InsertAtEnd = nullptr) { return new(3) SelectInst(C, S1, S2, NameStr, InsertAtEnd); } @@ -1984,15 +1986,15 @@ class VAArgInst : public UnaryInstruction { setName(NameStr); } - VAArgInst(Value *List, Type *Ty, const Twine &NameStr = "", - Instruction *InsertBefore = nullptr) - : UnaryInstruction(Ty, VAArg, List, InsertBefore) { + VAArgInst(Value *List, Type *Ty, const Twine &NameStr, + Instruction *InsertBefore) + : UnaryInstruction(Ty, VAArg, List, InsertBefore) { setName(NameStr); } - VAArgInst(Value *List, Type *Ty, const Twine &NameStr, - BasicBlock *InsertAtEnd) - : UnaryInstruction(Ty, VAArg, List, InsertAtEnd) { + VAArgInst(Value *List, Type *Ty, const Twine &NameStr = "", + BasicBlock *InsertAtEnd = nullptr) + : UnaryInstruction(Ty, VAArg, List, InsertAtEnd) { setName(NameStr); } @@ -2019,10 +2021,10 @@ class VAArgInst : public UnaryInstruction { class ExtractElementInst : public Instruction { ExtractElementInst(Value *Vec, Value *Idx, const Twine &NameStr, BasicBlock::iterator InsertBefore); - ExtractElementInst(Value *Vec, Value *Idx, const Twine &NameStr = "", - Instruction *InsertBefore = nullptr); ExtractElementInst(Value *Vec, Value *Idx, const Twine &NameStr, - BasicBlock *InsertAtEnd); + Instruction *InsertBefore); + ExtractElementInst(Value *Vec, Value *Idx, const Twine &NameStr = "", + BasicBlock *InsertAtEnd = nullptr); protected: // Note: Instruction needs to be a friend here to call cloneImpl. @@ -2038,14 +2040,14 @@ class ExtractElementInst : public Instruction { } static ExtractElementInst *Create(Value *Vec, Value *Idx, - const Twine &NameStr = "", - Instruction *InsertBefore = nullptr) { + const Twine &NameStr, + Instruction *InsertBefore) { return new(2) ExtractElementInst(Vec, Idx, NameStr, InsertBefore); } static ExtractElementInst *Create(Value *Vec, Value *Idx, - const Twine &NameStr, - BasicBlock *InsertAtEnd) { + const Twine &NameStr = "", + BasicBlock *InsertAtEnd = nullptr) { return new(2) ExtractElementInst(Vec, Idx, NameStr, InsertAtEnd); } @@ -2091,11 +2093,11 @@ DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ExtractElementInst, Value) class InsertElementInst : public Instruction { InsertElementInst(Value *Vec, Value *NewElt, Value *Idx, const Twine &NameStr, BasicBlock::iterator InsertBefore); + InsertElementInst(Value *Vec, Value *NewElt, Value *Idx, const Twine &NameStr, + Instruction *InsertBefore); InsertElementInst(Value *Vec, Value *NewElt, Value *Idx, const Twine &NameStr = "", - Instruction *InsertBefore = nullptr); - InsertElementInst(Value *Vec, Value *NewElt, Value *Idx, const Twine &NameStr, - BasicBlock *InsertAtEnd); + BasicBlock *InsertAtEnd = nullptr); protected: // Note: Instruction needs to be a friend here to call cloneImpl. @@ -2111,14 +2113,14 @@ class InsertElementInst : public Instruction { } static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx, - const Twine &NameStr = "", - Instruction *InsertBefore = nullptr) { + const Twine &NameStr, + Instruction *InsertBefore) { return new(3) InsertElementInst(Vec, NewElt, Idx, NameStr, InsertBefore); } static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx, - const Twine &NameStr, - BasicBlock *InsertAtEnd) { + const Twine &NameStr = "", + BasicBlock *InsertAtEnd = nullptr) { return new(3) InsertElementInst(Vec, NewElt, Idx, NameStr, InsertAtEnd); } @@ -2181,30 +2183,30 @@ class ShuffleVectorInst : public Instruction { public: ShuffleVectorInst(Value *V1, Value *Mask, const Twine &NameStr, BasicBlock::iterator InsertBefore); - ShuffleVectorInst(Value *V1, Value *Mask, const Twine &NameStr = "", - Instruction *InsertBefore = nullptr); ShuffleVectorInst(Value *V1, Value *Mask, const Twine &NameStr, - BasicBlock *InsertAtEnd); + Instruction *InsertBefore); + ShuffleVectorInst(Value *V1, Value *Mask, const Twine &NameStr = "", + BasicBlock *InsertAtEnd = nullptr); ShuffleVectorInst(Value *V1, ArrayRef Mask, const Twine &NameStr, BasicBlock::iterator InsertBefore); - ShuffleVectorInst(Value *V1, ArrayRef Mask, const Twine &NameStr = "", - Instruction *InsertBefore = nullptr); ShuffleVectorInst(Value *V1, ArrayRef Mask, const Twine &NameStr, - BasicBlock *InsertAtEnd); + Instruction *InsertBefore); + ShuffleVectorInst(Value *V1, ArrayRef Mask, const Twine &NameStr = "", + BasicBlock *InsertAtEnd = nullptr); + ShuffleVectorInst(Value *V1, Value *V2, Value *Mask, const Twine &NameStr, + BasicBlock::iterator InsertBefore); ShuffleVectorInst(Value *V1, Value *V2, Value *Mask, const Twine &NameStr, - BasicBlock::iterator InsertBefor); + Instruction *InsertBefore); ShuffleVectorInst(Value *V1, Value *V2, Value *Mask, const Twine &NameStr = "", - Instruction *InsertBefor = nullptr); - ShuffleVectorInst(Value *V1, Value *V2, Value *Mask, - const Twine &NameStr, BasicBlock *InsertAtEnd); + BasicBlock *InsertAtEnd = nullptr); ShuffleVectorInst(Value *V1, Value *V2, ArrayRef Mask, - const Twine &NameStr, BasicBlock::iterator InsertBefor); + const Twine &NameStr, BasicBlock::iterator InsertBefore); ShuffleVectorInst(Value *V1, Value *V2, ArrayRef Mask, - const Twine &NameStr = "", - Instruction *InsertBefor = nullptr); + const Twine &NameStr, Instruction *InsertBefore); ShuffleVectorInst(Value *V1, Value *V2, ArrayRef Mask, - const Twine &NameStr, BasicBlock *InsertAtEnd); + const Twine &NameStr = "", + BasicBlock *InsertAtEnd = nullptr); void *operator new(size_t S) { return User::operator new(S, 2); } void operator delete(void *Ptr) { return User::operator delete(Ptr); } @@ -2704,18 +2706,16 @@ class ExtractValueInst : public UnaryInstruction { ExtractValueInst(Agg, Idxs, NameStr, InsertBefore); } - static ExtractValueInst *Create(Value *Agg, - ArrayRef Idxs, - const Twine &NameStr = "", - Instruction *InsertBefore = nullptr) { + static ExtractValueInst *Create(Value *Agg, ArrayRef Idxs, + const Twine &NameStr, + Instruction *InsertBefore) { return new ExtractValueInst(Agg, Idxs, NameStr, InsertBefore); } - static ExtractValueInst *Create(Value *Agg, - ArrayRef Idxs, - const Twine &NameStr, - BasicBlock *InsertAtEnd) { + static ExtractValueInst *Create(Value *Agg, ArrayRef Idxs, + const Twine &NameStr = "", + BasicBlock *InsertAtEnd = nullptr) { return new ExtractValueInst(Agg, Idxs, NameStr, InsertAtEnd); } @@ -2821,11 +2821,10 @@ class InsertValueInst : public Instruction { /// one and two index insertvalue instructions are so common. InsertValueInst(Value *Agg, Value *Val, unsigned Idx, const Twine &NameStr, BasicBlock::iterator InsertBefore); - InsertValueInst(Value *Agg, Value *Val, unsigned Idx, - const Twine &NameStr = "", - Instruction *InsertBefore = nullptr); InsertValueInst(Value *Agg, Value *Val, unsigned Idx, const Twine &NameStr, - BasicBlock *InsertAtEnd); + Instruction *InsertBefore); + InsertValueInst(Value *Agg, Value *Val, unsigned Idx, + const Twine &NameStr = "", BasicBlock *InsertAtEnd = nullptr); void init(Value *Agg, Value *Val, ArrayRef Idxs, const Twine &NameStr); @@ -2848,16 +2847,15 @@ class InsertValueInst : public Instruction { } static InsertValueInst *Create(Value *Agg, Value *Val, - ArrayRef Idxs, - const Twine &NameStr = "", - Instruction *InsertBefore = nullptr) { + ArrayRef Idxs, const Twine &NameStr, + Instruction *InsertBefore) { return new InsertValueInst(Agg, Val, Idxs, NameStr, InsertBefore); } static InsertValueInst *Create(Value *Agg, Value *Val, ArrayRef Idxs, - const Twine &NameStr, - BasicBlock *InsertAtEnd) { + const Twine &NameStr = "", + BasicBlock *InsertAtEnd = nullptr) { return new InsertValueInst(Agg, Val, Idxs, NameStr, InsertAtEnd); } @@ -2976,20 +2974,19 @@ class PHINode : public Instruction { allocHungoffUses(ReservedSpace); } - explicit PHINode(Type *Ty, unsigned NumReservedValues, - const Twine &NameStr = "", - Instruction *InsertBefore = nullptr) - : Instruction(Ty, Instruction::PHI, nullptr, 0, InsertBefore), - ReservedSpace(NumReservedValues) { + explicit PHINode(Type *Ty, unsigned NumReservedValues, const Twine &NameStr, + Instruction *InsertBefore) + : Instruction(Ty, Instruction::PHI, nullptr, 0, InsertBefore), + ReservedSpace(NumReservedValues) { assert(!Ty->isTokenTy() && "PHI nodes cannot have token type!"); setName(NameStr); allocHungoffUses(ReservedSpace); } - PHINode(Type *Ty, unsigned NumReservedValues, const Twine &NameStr, - BasicBlock *InsertAtEnd) - : Instruction(Ty, Instruction::PHI, nullptr, 0, InsertAtEnd), - ReservedSpace(NumReservedValues) { + PHINode(Type *Ty, unsigned NumReservedValues, const Twine &NameStr = "", + BasicBlock *InsertAtEnd = nullptr) + : Instruction(Ty, Instruction::PHI, nullptr, 0, InsertAtEnd), + ReservedSpace(NumReservedValues) { assert(!Ty->isTokenTy() && "PHI nodes cannot have token type!"); setName(NameStr); allocHungoffUses(ReservedSpace); @@ -3018,13 +3015,13 @@ class PHINode : public Instruction { } static PHINode *Create(Type *Ty, unsigned NumReservedValues, - const Twine &NameStr = "", - Instruction *InsertBefore = nullptr) { + const Twine &NameStr, Instruction *InsertBefore) { return new PHINode(Ty, NumReservedValues, NameStr, InsertBefore); } static PHINode *Create(Type *Ty, unsigned NumReservedValues, - const Twine &NameStr, BasicBlock *InsertAtEnd) { + const Twine &NameStr = "", + BasicBlock *InsertAtEnd = nullptr) { return new PHINode(Ty, NumReservedValues, NameStr, InsertAtEnd); } @@ -3270,10 +3267,11 @@ class LandingPadInst : public Instruction { const Twine &NameStr, BasicBlock::iterator InsertBefore); static LandingPadInst *Create(Type *RetTy, unsigned NumReservedClauses, - const Twine &NameStr = "", - Instruction *InsertBefore = nullptr); + const Twine &NameStr, + Instruction *InsertBefore); static LandingPadInst *Create(Type *RetTy, unsigned NumReservedClauses, - const Twine &NameStr, BasicBlock *InsertAtEnd); + const Twine &NameStr = "", + BasicBlock *InsertAtEnd = nullptr); /// Provide fast operand accessors DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); @@ -3354,9 +3352,9 @@ class ReturnInst : public Instruction { // if it was passed NULL. explicit ReturnInst(LLVMContext &C, Value *retVal, BasicBlock::iterator InsertBefore); - explicit ReturnInst(LLVMContext &C, Value *retVal = nullptr, - Instruction *InsertBefore = nullptr); - ReturnInst(LLVMContext &C, Value *retVal, BasicBlock *InsertAtEnd); + explicit ReturnInst(LLVMContext &C, Value *retVal, Instruction *InsertBefore); + ReturnInst(LLVMContext &C, Value *retVal = nullptr, + BasicBlock *InsertAtEnd = nullptr); explicit ReturnInst(LLVMContext &C, BasicBlock *InsertAtEnd); protected: @@ -3371,13 +3369,13 @@ class ReturnInst : public Instruction { return new (!!retVal) ReturnInst(C, retVal, InsertBefore); } - static ReturnInst* Create(LLVMContext &C, Value *retVal = nullptr, - Instruction *InsertBefore = nullptr) { + static ReturnInst *Create(LLVMContext &C, Value *retVal, + Instruction *InsertBefore) { return new(!!retVal) ReturnInst(C, retVal, InsertBefore); } - static ReturnInst* Create(LLVMContext &C, Value *retVal, - BasicBlock *InsertAtEnd) { + static ReturnInst *Create(LLVMContext &C, Value *retVal = nullptr, + BasicBlock *InsertAtEnd = nullptr) { return new(!!retVal) ReturnInst(C, retVal, InsertAtEnd); } @@ -3444,12 +3442,12 @@ class BranchInst : public Instruction { explicit BranchInst(BasicBlock *IfTrue, BasicBlock::iterator InsertBefore); BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond, BasicBlock::iterator InsertBefore); - explicit BranchInst(BasicBlock *IfTrue, Instruction *InsertBefore = nullptr); + explicit BranchInst(BasicBlock *IfTrue, Instruction *InsertBefore); BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond, - Instruction *InsertBefore = nullptr); - BranchInst(BasicBlock *IfTrue, BasicBlock *InsertAtEnd); + Instruction *InsertBefore); + BranchInst(BasicBlock *IfTrue, BasicBlock *InsertAtEnd = nullptr); BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond, - BasicBlock *InsertAtEnd); + BasicBlock *InsertAtEnd = nullptr); void AssertOK(); @@ -3492,8 +3490,7 @@ class BranchInst : public Instruction { return new(1) BranchInst(IfTrue, InsertBefore); } - static BranchInst *Create(BasicBlock *IfTrue, - Instruction *InsertBefore = nullptr) { + static BranchInst *Create(BasicBlock *IfTrue, Instruction *InsertBefore) { return new(1) BranchInst(IfTrue, InsertBefore); } @@ -3503,16 +3500,17 @@ class BranchInst : public Instruction { } static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse, - Value *Cond, Instruction *InsertBefore = nullptr) { + Value *Cond, Instruction *InsertBefore) { return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertBefore); } - static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *InsertAtEnd) { + static BranchInst *Create(BasicBlock *IfTrue, + BasicBlock *InsertAtEnd = nullptr) { return new(1) BranchInst(IfTrue, InsertAtEnd); } static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse, - Value *Cond, BasicBlock *InsertAtEnd) { + Value *Cond, BasicBlock *InsertAtEnd = nullptr) { return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertAtEnd); } @@ -3788,13 +3786,13 @@ class SwitchInst : public Instruction { } static SwitchInst *Create(Value *Value, BasicBlock *Default, - unsigned NumCases, - Instruction *InsertBefore = nullptr) { + unsigned NumCases, Instruction *InsertBefore) { return new SwitchInst(Value, Default, NumCases, InsertBefore); } static SwitchInst *Create(Value *Value, BasicBlock *Default, - unsigned NumCases, BasicBlock *InsertAtEnd) { + unsigned NumCases, + BasicBlock *InsertAtEnd = nullptr) { return new SwitchInst(Value, Default, NumCases, InsertAtEnd); } @@ -4074,12 +4072,12 @@ class IndirectBrInst : public Instruction { } static IndirectBrInst *Create(Value *Address, unsigned NumDests, - Instruction *InsertBefore = nullptr) { + Instruction *InsertBefore) { return new IndirectBrInst(Address, NumDests, InsertBefore); } static IndirectBrInst *Create(Value *Address, unsigned NumDests, - BasicBlock *InsertAtEnd) { + BasicBlock *InsertAtEnd = nullptr) { return new IndirectBrInst(Address, NumDests, InsertAtEnd); } @@ -4209,8 +4207,7 @@ class InvokeInst : public CallBase { static InvokeInst *Create(FunctionType *Ty, Value *Func, BasicBlock *IfNormal, BasicBlock *IfException, ArrayRef Args, - const Twine &NameStr, - Instruction *InsertBefore = nullptr) { + const Twine &NameStr, Instruction *InsertBefore) { int NumOperands = ComputeNumOperands(Args.size()); return new (NumOperands) InvokeInst(Ty, Func, IfNormal, IfException, Args, std::nullopt, @@ -4233,9 +4230,8 @@ class InvokeInst : public CallBase { static InvokeInst *Create(FunctionType *Ty, Value *Func, BasicBlock *IfNormal, BasicBlock *IfException, ArrayRef Args, - ArrayRef Bundles = std::nullopt, - const Twine &NameStr = "", - Instruction *InsertBefore = nullptr) { + ArrayRef Bundles, + const Twine &NameStr, Instruction *InsertBefore) { int NumOperands = ComputeNumOperands(Args.size(), CountBundleInputs(Bundles)); unsigned DescriptorBytes = Bundles.size() * sizeof(BundleOpInfo); @@ -4247,7 +4243,8 @@ class InvokeInst : public CallBase { static InvokeInst *Create(FunctionType *Ty, Value *Func, BasicBlock *IfNormal, BasicBlock *IfException, ArrayRef Args, - const Twine &NameStr, BasicBlock *InsertAtEnd) { + const Twine &NameStr, + BasicBlock *InsertAtEnd = nullptr) { int NumOperands = ComputeNumOperands(Args.size()); return new (NumOperands) InvokeInst(Ty, Func, IfNormal, IfException, Args, std::nullopt, @@ -4256,8 +4253,9 @@ class InvokeInst : public CallBase { static InvokeInst *Create(FunctionType *Ty, Value *Func, BasicBlock *IfNormal, BasicBlock *IfException, ArrayRef Args, - ArrayRef Bundles, - const Twine &NameStr, BasicBlock *InsertAtEnd) { + ArrayRef Bundles = std::nullopt, + const Twine &NameStr = "", + BasicBlock *InsertAtEnd = nullptr) { int NumOperands = ComputeNumOperands(Args.size(), CountBundleInputs(Bundles)); unsigned DescriptorBytes = Bundles.size() * sizeof(BundleOpInfo); @@ -4277,8 +4275,7 @@ class InvokeInst : public CallBase { static InvokeInst *Create(FunctionCallee Func, BasicBlock *IfNormal, BasicBlock *IfException, ArrayRef Args, - const Twine &NameStr, - Instruction *InsertBefore = nullptr) { + const Twine &NameStr, Instruction *InsertBefore) { return Create(Func.getFunctionType(), Func.getCallee(), IfNormal, IfException, Args, std::nullopt, NameStr, InsertBefore); } @@ -4294,24 +4291,25 @@ class InvokeInst : public CallBase { static InvokeInst *Create(FunctionCallee Func, BasicBlock *IfNormal, BasicBlock *IfException, ArrayRef Args, - ArrayRef Bundles = std::nullopt, - const Twine &NameStr = "", - Instruction *InsertBefore = nullptr) { + ArrayRef Bundles, + const Twine &NameStr, Instruction *InsertBefore) { return Create(Func.getFunctionType(), Func.getCallee(), IfNormal, IfException, Args, Bundles, NameStr, InsertBefore); } static InvokeInst *Create(FunctionCallee Func, BasicBlock *IfNormal, BasicBlock *IfException, ArrayRef Args, - const Twine &NameStr, BasicBlock *InsertAtEnd) { + const Twine &NameStr, + BasicBlock *InsertAtEnd = nullptr) { return Create(Func.getFunctionType(), Func.getCallee(), IfNormal, IfException, Args, NameStr, InsertAtEnd); } static InvokeInst *Create(FunctionCallee Func, BasicBlock *IfNormal, BasicBlock *IfException, ArrayRef Args, - ArrayRef Bundles, - const Twine &NameStr, BasicBlock *InsertAtEnd) { + ArrayRef Bundles = std::nullopt, + const Twine &NameStr = "", + BasicBlock *InsertAtEnd = nullptr) { return Create(Func.getFunctionType(), Func.getCallee(), IfNormal, IfException, Args, Bundles, NameStr, InsertAtEnd); } @@ -4325,7 +4323,9 @@ class InvokeInst : public CallBase { static InvokeInst *Create(InvokeInst *II, ArrayRef Bundles, BasicBlock::iterator InsertPt); static InvokeInst *Create(InvokeInst *II, ArrayRef Bundles, - Instruction *InsertPt = nullptr); + Instruction *InsertPt); + static InvokeInst *Create(InvokeInst *II, ArrayRef Bundles, + BasicBlock *InsertAtEnd = nullptr); // get*Dest - Return the destination basic blocks... BasicBlock *getNormalDest() const { @@ -4477,7 +4477,7 @@ class CallBrInst : public CallBase { BasicBlock *DefaultDest, ArrayRef IndirectDests, ArrayRef Args, const Twine &NameStr, - Instruction *InsertBefore = nullptr) { + Instruction *InsertBefore) { int NumOperands = ComputeNumOperands(Args.size(), IndirectDests.size()); return new (NumOperands) CallBrInst(Ty, Func, DefaultDest, IndirectDests, Args, std::nullopt, @@ -4498,11 +4498,12 @@ class CallBrInst : public CallBase { NumOperands, NameStr, InsertBefore); } - static CallBrInst * - Create(FunctionType *Ty, Value *Func, BasicBlock *DefaultDest, - ArrayRef IndirectDests, ArrayRef Args, - ArrayRef Bundles = std::nullopt, - const Twine &NameStr = "", Instruction *InsertBefore = nullptr) { + static CallBrInst *Create(FunctionType *Ty, Value *Func, + BasicBlock *DefaultDest, + ArrayRef IndirectDests, + ArrayRef Args, + ArrayRef Bundles, + const Twine &NameStr, Instruction *InsertBefore) { int NumOperands = ComputeNumOperands(Args.size(), IndirectDests.size(), CountBundleInputs(Bundles)); unsigned DescriptorBytes = Bundles.size() * sizeof(BundleOpInfo); @@ -4516,19 +4517,18 @@ class CallBrInst : public CallBase { BasicBlock *DefaultDest, ArrayRef IndirectDests, ArrayRef Args, const Twine &NameStr, - BasicBlock *InsertAtEnd) { + BasicBlock *InsertAtEnd = nullptr) { int NumOperands = ComputeNumOperands(Args.size(), IndirectDests.size()); return new (NumOperands) CallBrInst(Ty, Func, DefaultDest, IndirectDests, Args, std::nullopt, NumOperands, NameStr, InsertAtEnd); } - static CallBrInst *Create(FunctionType *Ty, Value *Func, - BasicBlock *DefaultDest, - ArrayRef IndirectDests, - ArrayRef Args, - ArrayRef Bundles, - const Twine &NameStr, BasicBlock *InsertAtEnd) { + static CallBrInst * + Create(FunctionType *Ty, Value *Func, BasicBlock *DefaultDest, + ArrayRef IndirectDests, ArrayRef Args, + ArrayRef Bundles = std::nullopt, + const Twine &NameStr = "", BasicBlock *InsertAtEnd = nullptr) { int NumOperands = ComputeNumOperands(Args.size(), IndirectDests.size(), CountBundleInputs(Bundles)); unsigned DescriptorBytes = Bundles.size() * sizeof(BundleOpInfo); @@ -4549,7 +4549,7 @@ class CallBrInst : public CallBase { static CallBrInst *Create(FunctionCallee Func, BasicBlock *DefaultDest, ArrayRef IndirectDests, ArrayRef Args, const Twine &NameStr, - Instruction *InsertBefore = nullptr) { + Instruction *InsertBefore) { return Create(Func.getFunctionType(), Func.getCallee(), DefaultDest, IndirectDests, Args, NameStr, InsertBefore); } @@ -4567,9 +4567,8 @@ class CallBrInst : public CallBase { static CallBrInst *Create(FunctionCallee Func, BasicBlock *DefaultDest, ArrayRef IndirectDests, ArrayRef Args, - ArrayRef Bundles = std::nullopt, - const Twine &NameStr = "", - Instruction *InsertBefore = nullptr) { + ArrayRef Bundles, + const Twine &NameStr, Instruction *InsertBefore) { return Create(Func.getFunctionType(), Func.getCallee(), DefaultDest, IndirectDests, Args, Bundles, NameStr, InsertBefore); } @@ -4577,17 +4576,17 @@ class CallBrInst : public CallBase { static CallBrInst *Create(FunctionCallee Func, BasicBlock *DefaultDest, ArrayRef IndirectDests, ArrayRef Args, const Twine &NameStr, - BasicBlock *InsertAtEnd) { + BasicBlock *InsertAtEnd = nullptr) { return Create(Func.getFunctionType(), Func.getCallee(), DefaultDest, IndirectDests, Args, NameStr, InsertAtEnd); } - static CallBrInst *Create(FunctionCallee Func, - BasicBlock *DefaultDest, + static CallBrInst *Create(FunctionCallee Func, BasicBlock *DefaultDest, ArrayRef IndirectDests, ArrayRef Args, - ArrayRef Bundles, - const Twine &NameStr, BasicBlock *InsertAtEnd) { + ArrayRef Bundles = std::nullopt, + const Twine &NameStr = "", + BasicBlock *InsertAtEnd = nullptr) { return Create(Func.getFunctionType(), Func.getCallee(), DefaultDest, IndirectDests, Args, Bundles, NameStr, InsertAtEnd); } @@ -4600,9 +4599,10 @@ class CallBrInst : public CallBase { /// operand bundles in \p Bundles. static CallBrInst *Create(CallBrInst *CBI, ArrayRef Bundles, BasicBlock::iterator InsertPt); - static CallBrInst *Create(CallBrInst *CBI, - ArrayRef Bundles, - Instruction *InsertPt = nullptr); + static CallBrInst *Create(CallBrInst *CBI, ArrayRef Bundles, + Instruction *InsertPt); + static CallBrInst *Create(CallBrInst *CBI, ArrayRef Bundles, + BasicBlock *InsertAtEnd = nullptr); /// Return the number of callbr indirect dest labels. /// @@ -4729,11 +4729,11 @@ class ResumeInst : public Instruction { return new (1) ResumeInst(Exn, InsertBefore); } - static ResumeInst *Create(Value *Exn, Instruction *InsertBefore = nullptr) { + static ResumeInst *Create(Value *Exn, Instruction *InsertBefore) { return new(1) ResumeInst(Exn, InsertBefore); } - static ResumeInst *Create(Value *Exn, BasicBlock *InsertAtEnd) { + static ResumeInst *Create(Value *Exn, BasicBlock *InsertAtEnd = nullptr) { return new(1) ResumeInst(Exn, InsertAtEnd); } @@ -4832,16 +4832,16 @@ class CatchSwitchInst : public Instruction { } static CatchSwitchInst *Create(Value *ParentPad, BasicBlock *UnwindDest, - unsigned NumHandlers, - const Twine &NameStr = "", - Instruction *InsertBefore = nullptr) { + unsigned NumHandlers, const Twine &NameStr, + Instruction *InsertBefore) { return new CatchSwitchInst(ParentPad, UnwindDest, NumHandlers, NameStr, InsertBefore); } static CatchSwitchInst *Create(Value *ParentPad, BasicBlock *UnwindDest, - unsigned NumHandlers, const Twine &NameStr, - BasicBlock *InsertAtEnd) { + unsigned NumHandlers, + const Twine &NameStr = "", + BasicBlock *InsertAtEnd = nullptr) { return new CatchSwitchInst(ParentPad, UnwindDest, NumHandlers, NameStr, InsertAtEnd); } @@ -4993,17 +4993,18 @@ class CleanupPadInst : public FuncletPadInst { CleanupPadInst(ParentPad, Args, Values, NameStr, InsertBefore); } - static CleanupPadInst *Create(Value *ParentPad, - ArrayRef Args = std::nullopt, - const Twine &NameStr = "", - Instruction *InsertBefore = nullptr) { + static CleanupPadInst *Create(Value *ParentPad, ArrayRef Args, + const Twine &NameStr, + Instruction *InsertBefore) { unsigned Values = 1 + Args.size(); return new (Values) CleanupPadInst(ParentPad, Args, Values, NameStr, InsertBefore); } - static CleanupPadInst *Create(Value *ParentPad, ArrayRef Args, - const Twine &NameStr, BasicBlock *InsertAtEnd) { + static CleanupPadInst *Create(Value *ParentPad, + ArrayRef Args = std::nullopt, + const Twine &NameStr = "", + BasicBlock *InsertAtEnd = nullptr) { unsigned Values = 1 + Args.size(); return new (Values) CleanupPadInst(ParentPad, Args, Values, NameStr, InsertAtEnd); @@ -5049,15 +5050,15 @@ class CatchPadInst : public FuncletPadInst { } static CatchPadInst *Create(Value *CatchSwitch, ArrayRef Args, - const Twine &NameStr = "", - Instruction *InsertBefore = nullptr) { + const Twine &NameStr, Instruction *InsertBefore) { unsigned Values = 1 + Args.size(); return new (Values) CatchPadInst(CatchSwitch, Args, Values, NameStr, InsertBefore); } static CatchPadInst *Create(Value *CatchSwitch, ArrayRef Args, - const Twine &NameStr, BasicBlock *InsertAtEnd) { + const Twine &NameStr = "", + BasicBlock *InsertAtEnd = nullptr) { unsigned Values = 1 + Args.size(); return new (Values) CatchPadInst(CatchSwitch, Args, Values, NameStr, InsertAtEnd); @@ -5109,14 +5110,14 @@ class CatchReturnInst : public Instruction { } static CatchReturnInst *Create(Value *CatchPad, BasicBlock *BB, - Instruction *InsertBefore = nullptr) { + Instruction *InsertBefore) { assert(CatchPad); assert(BB); return new (2) CatchReturnInst(CatchPad, BB, InsertBefore); } static CatchReturnInst *Create(Value *CatchPad, BasicBlock *BB, - BasicBlock *InsertAtEnd) { + BasicBlock *InsertAtEnd = nullptr) { assert(CatchPad); assert(BB); return new (2) CatchReturnInst(CatchPad, BB, InsertAtEnd); @@ -5183,9 +5184,9 @@ class CleanupReturnInst : public Instruction { CleanupReturnInst(Value *CleanupPad, BasicBlock *UnwindBB, unsigned Values, BasicBlock::iterator InsertBefore); CleanupReturnInst(Value *CleanupPad, BasicBlock *UnwindBB, unsigned Values, - Instruction *InsertBefore = nullptr); + Instruction *InsertBefore); CleanupReturnInst(Value *CleanupPad, BasicBlock *UnwindBB, unsigned Values, - BasicBlock *InsertAtEnd); + BasicBlock *InsertAtEnd = nullptr); void init(Value *CleanupPad, BasicBlock *UnwindBB); @@ -5206,9 +5207,8 @@ class CleanupReturnInst : public Instruction { CleanupReturnInst(CleanupPad, UnwindBB, Values, InsertBefore); } - static CleanupReturnInst *Create(Value *CleanupPad, - BasicBlock *UnwindBB = nullptr, - Instruction *InsertBefore = nullptr) { + static CleanupReturnInst *Create(Value *CleanupPad, BasicBlock *UnwindBB, + Instruction *InsertBefore) { assert(CleanupPad); unsigned Values = 1; if (UnwindBB) @@ -5217,8 +5217,9 @@ class CleanupReturnInst : public Instruction { CleanupReturnInst(CleanupPad, UnwindBB, Values, InsertBefore); } - static CleanupReturnInst *Create(Value *CleanupPad, BasicBlock *UnwindBB, - BasicBlock *InsertAtEnd) { + static CleanupReturnInst *Create(Value *CleanupPad, + BasicBlock *UnwindBB = nullptr, + BasicBlock *InsertAtEnd = nullptr) { assert(CleanupPad); unsigned Values = 1; if (UnwindBB) @@ -5304,8 +5305,8 @@ class UnreachableInst : public Instruction { public: explicit UnreachableInst(LLVMContext &C, BasicBlock::iterator InsertBefore); - explicit UnreachableInst(LLVMContext &C, Instruction *InsertBefore = nullptr); - explicit UnreachableInst(LLVMContext &C, BasicBlock *InsertAtEnd); + explicit UnreachableInst(LLVMContext &C, Instruction *InsertBefore); + explicit UnreachableInst(LLVMContext &C, BasicBlock *InsertAtEnd = nullptr); // allocate space for exactly zero operands void *operator new(size_t S) { return User::operator new(S, 0); } @@ -5354,19 +5355,18 @@ class TruncInst : public CastInst { ); /// 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 - Instruction *InsertBefore = nullptr ///< Where to insert the new instruction + 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 + Instruction *InsertBefore ///< Where to insert the new instruction ); /// Constructor with insert-at-end-of-block 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 *InsertAtEnd ///< The block to insert the instruction into + 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 *InsertAtEnd = nullptr ///< The block to insert at the end of ); /// Methods for support type inquiry through isa, cast, and dyn_cast: @@ -5401,19 +5401,18 @@ class ZExtInst : public CastInst { ); /// 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 - Instruction *InsertBefore = nullptr ///< Where to insert the new instruction + 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 + Instruction *InsertBefore ///< Where to insert the new instruction ); /// Constructor with insert-at-end 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 *InsertAtEnd ///< The block to insert the instruction into + 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 *InsertAtEnd = nullptr ///< The block to insert at the end of ); /// Methods for support type inquiry through isa, cast, and dyn_cast: @@ -5448,19 +5447,18 @@ class SExtInst : public CastInst { ); /// 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 - Instruction *InsertBefore = nullptr ///< Where to insert the new instruction + 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 + Instruction *InsertBefore ///< Where to insert the new instruction ); /// Constructor with insert-at-end-of-block 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 *InsertAtEnd ///< The block to insert the instruction into + 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 *InsertAtEnd = nullptr ///< The block to insert at the end of ); /// Methods for support type inquiry through isa, cast, and dyn_cast: @@ -5495,19 +5493,18 @@ class FPTruncInst : public CastInst { ); /// 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 - Instruction *InsertBefore = nullptr ///< Where to insert the new instruction + FPTruncInst(Value *S, ///< The value to be truncated + Type *Ty, ///< The type to truncate to + const Twine &NameStr, ///< A name for the new instruction + Instruction *InsertBefore ///< Where to insert the new instruction ); /// 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 *InsertAtEnd ///< The block to insert the instruction into + Value *S, ///< The value to be truncated + Type *Ty, ///< The type to truncate to + const Twine &NameStr = "", ///< A name for the new instruction + BasicBlock *InsertAtEnd = nullptr ///< The block to insert at the end of ); /// Methods for support type inquiry through isa, cast, and dyn_cast: @@ -5542,19 +5539,18 @@ class FPExtInst : public CastInst { ); /// 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 - Instruction *InsertBefore = nullptr ///< Where to insert the new instruction + FPExtInst(Value *S, ///< The value to be extended + Type *Ty, ///< The type to extend to + const Twine &NameStr, ///< A name for the new instruction + Instruction *InsertBefore ///< Where to insert the new instruction ); /// Constructor with insert-at-end-of-block 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 *InsertAtEnd ///< The block to insert the instruction into + Value *S, ///< The value to be extended + Type *Ty, ///< The type to extend to + const Twine &NameStr = "", ///< A name for the new instruction + BasicBlock *InsertAtEnd = nullptr ///< The block to insert at the end of ); /// Methods for support type inquiry through isa, cast, and dyn_cast: @@ -5589,19 +5585,18 @@ class UIToFPInst : public CastInst { ); /// 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 - Instruction *InsertBefore = nullptr ///< Where to insert the new instruction + UIToFPInst(Value *S, ///< The value to be converted + Type *Ty, ///< The type to convert to + const Twine &NameStr, ///< A name for the new instruction + Instruction *InsertBefore ///< Where to insert the new instruction ); /// Constructor with insert-at-end-of-block 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 *InsertAtEnd ///< The block to insert the instruction into + Value *S, ///< The value to be converted + Type *Ty, ///< The type to convert to + const Twine &NameStr = "", ///< A name for the new instruction + BasicBlock *InsertAtEnd = nullptr ///< The block to insert at the end of ); /// Methods for support type inquiry through isa, cast, and dyn_cast: @@ -5636,19 +5631,18 @@ class SIToFPInst : public CastInst { ); /// 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 - Instruction *InsertBefore = nullptr ///< Where to insert the new instruction + SIToFPInst(Value *S, ///< The value to be converted + Type *Ty, ///< The type to convert to + const Twine &NameStr, ///< A name for the new instruction + Instruction *InsertBefore ///< Where to insert the new instruction ); /// Constructor with insert-at-end-of-block 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 *InsertAtEnd ///< The block to insert the instruction into + Value *S, ///< The value to be converted + Type *Ty, ///< The type to convert to + const Twine &NameStr = "", ///< A name for the new instruction + BasicBlock *InsertAtEnd = nullptr ///< The block to insert at the end of ); /// Methods for support type inquiry through isa, cast, and dyn_cast: @@ -5683,19 +5677,18 @@ class FPToUIInst : public CastInst { ); /// 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 - Instruction *InsertBefore = nullptr ///< Where to insert the new instruction + FPToUIInst(Value *S, ///< The value to be converted + Type *Ty, ///< The type to convert to + const Twine &NameStr, ///< A name for the new instruction + Instruction *InsertBefore ///< Where to insert the new instruction ); /// Constructor with insert-at-end-of-block 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 *InsertAtEnd ///< 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 *InsertAtEnd = nullptr ///< The block to insert at the end of ); /// Methods for support type inquiry through isa, cast, and dyn_cast: @@ -5730,19 +5723,18 @@ class FPToSIInst : public CastInst { ); /// 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 - Instruction *InsertBefore = nullptr ///< Where to insert the new instruction + FPToSIInst(Value *S, ///< The value to be converted + Type *Ty, ///< The type to convert to + const Twine &NameStr, ///< A name for the new instruction + Instruction *InsertBefore ///< Where to insert the new instruction ); /// Constructor with insert-at-end-of-block 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 *InsertAtEnd ///< The block to insert the instruction into + Value *S, ///< The value to be converted + Type *Ty, ///< The type to convert to + const Twine &NameStr = "", ///< A name for the new instruction + BasicBlock *InsertAtEnd = nullptr ///< The block to insert at the end of ); /// Methods for support type inquiry through isa, cast, and dyn_cast: @@ -5774,18 +5766,18 @@ class IntToPtrInst : public CastInst { /// 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 - Instruction *InsertBefore = nullptr ///< 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 + Instruction *InsertBefore ///< Where to insert the new instruction ); /// Constructor with insert-at-end-of-block 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 *InsertAtEnd ///< The block to insert the instruction into + Value *S, ///< The value to be converted + Type *Ty, ///< The type to convert to + const Twine &NameStr = "", ///< A name for the new instruction + BasicBlock *InsertAtEnd = nullptr ///< The block to insert at the end of ); /// Clone an identical IntToPtrInst. @@ -5829,18 +5821,18 @@ class PtrToIntInst : public CastInst { /// 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 - Instruction *InsertBefore = nullptr ///< 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 + Instruction *InsertBefore ///< Where to insert the new instruction ); /// Constructor with insert-at-end-of-block 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 *InsertAtEnd ///< The block to insert the instruction into + Value *S, ///< The value to be converted + Type *Ty, ///< The type to convert to + const Twine &NameStr = "", ///< A name for the new instruction + BasicBlock *InsertAtEnd = nullptr ///< The block to insert at the end of ); /// Gets the pointer operand. @@ -5887,19 +5879,18 @@ class BitCastInst : public CastInst { ); /// 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 - Instruction *InsertBefore = nullptr ///< Where to insert the new instruction + BitCastInst(Value *S, ///< The value to be casted + Type *Ty, ///< The type to casted to + const Twine &NameStr, ///< A name for the new instruction + Instruction *InsertBefore ///< Where to insert the new instruction ); /// Constructor with insert-at-end-of-block 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 *InsertAtEnd ///< The block to insert the instruction into + Value *S, ///< The value to be casted + Type *Ty, ///< The type to casted to + const Twine &NameStr = "", ///< A name for the new instruction + BasicBlock *InsertAtEnd = nullptr ///< The block to insert at the end of ); // Methods for support type inquiry through isa, cast, and dyn_cast: @@ -5936,18 +5927,18 @@ class AddrSpaceCastInst : public CastInst { /// 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 - Instruction *InsertBefore = nullptr ///< 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 + Instruction *InsertBefore ///< Where to insert the new instruction ); /// Constructor with insert-at-end-of-block 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 *InsertAtEnd ///< The block to insert the instruction into + Value *S, ///< The value to be casted + Type *Ty, ///< The type to casted to + const Twine &NameStr = "", ///< A name for the new instruction + BasicBlock *InsertAtEnd = nullptr ///< The block to insert at the end of ); // Methods for support type inquiry through isa, cast, and dyn_cast: @@ -6078,10 +6069,10 @@ class FreezeInst : public UnaryInstruction { public: explicit FreezeInst(Value *S, const Twine &NameStr, BasicBlock::iterator InsertBefore); - explicit FreezeInst(Value *S, - const Twine &NameStr = "", - Instruction *InsertBefore = nullptr); - FreezeInst(Value *S, const Twine &NameStr, BasicBlock *InsertAtEnd); + explicit FreezeInst(Value *S, const Twine &NameStr, + Instruction *InsertBefore); + FreezeInst(Value *S, const Twine &NameStr = "", + BasicBlock *InsertAtEnd = nullptr); // Methods for support type inquiry through isa, cast, and dyn_cast: static inline bool classof(const Instruction *I) { diff --git a/llvm/lib/IR/Instructions.cpp b/llvm/lib/IR/Instructions.cpp index 494d50f89e374..4190df1a8fa36 100644 --- a/llvm/lib/IR/Instructions.cpp +++ b/llvm/lib/IR/Instructions.cpp @@ -332,6 +332,20 @@ CallBase *CallBase::Create(CallBase *CB, ArrayRef Bundles, } } +CallBase *CallBase::Create(CallBase *CB, ArrayRef Bundles, + BasicBlock *InsertAtEnd) { + switch (CB->getOpcode()) { + case Instruction::Call: + return CallInst::Create(cast(CB), Bundles, InsertAtEnd); + case Instruction::Invoke: + return InvokeInst::Create(cast(CB), Bundles, InsertAtEnd); + case Instruction::CallBr: + return CallBrInst::Create(cast(CB), Bundles, InsertAtEnd); + default: + llvm_unreachable("Unknown CallBase sub-class!"); + } +} + CallBase *CallBase::Create(CallBase *CI, OperandBundleDef OpB, Instruction *InsertPt) { SmallVector OpDefs; @@ -344,6 +358,17 @@ CallBase *CallBase::Create(CallBase *CI, OperandBundleDef OpB, return CallBase::Create(CI, OpDefs, InsertPt); } +CallBase *CallBase::Create(CallBase *CI, OperandBundleDef OpB, + BasicBlock *InsertAtEnd) { + SmallVector OpDefs; + for (unsigned i = 0, e = CI->getNumOperandBundles(); i < e; ++i) { + auto ChildOB = CI->getOperandBundleAt(i); + if (ChildOB.getTagName() != OpB.getTag()) + OpDefs.emplace_back(ChildOB); + } + OpDefs.emplace_back(OpB); + return CallBase::Create(CI, OpDefs, InsertAtEnd); +} Function *CallBase::getCaller() { return getParent()->getParent(); } @@ -637,6 +662,23 @@ CallBase *CallBase::removeOperandBundle(CallBase *CB, uint32_t ID, return CreateNew ? Create(CB, Bundles, InsertPt) : CB; } +CallBase *CallBase::removeOperandBundle(CallBase *CB, uint32_t ID, + BasicBlock *InsertAtEnd) { + SmallVector Bundles; + bool CreateNew = false; + + for (unsigned I = 0, E = CB->getNumOperandBundles(); I != E; ++I) { + auto Bundle = CB->getOperandBundleAt(I); + if (Bundle.getTagID() == ID) { + CreateNew = true; + continue; + } + Bundles.emplace_back(Bundle); + } + + return CreateNew ? Create(CB, Bundles, InsertAtEnd) : CB; +} + bool CallBase::hasReadingOperandBundles() const { // Implementation note: this is a conservative implementation of operand // bundle semantics, where *any* non-assume operand bundle (other than @@ -829,6 +871,20 @@ CallInst *CallInst::Create(CallInst *CI, ArrayRef OpB, return NewCI; } +CallInst *CallInst::Create(CallInst *CI, ArrayRef OpB, + BasicBlock *InsertAtEnd) { + std::vector Args(CI->arg_begin(), CI->arg_end()); + + auto *NewCI = CallInst::Create(CI->getFunctionType(), CI->getCalledOperand(), + Args, OpB, CI->getName(), InsertAtEnd); + NewCI->setTailCallKind(CI->getTailCallKind()); + NewCI->setCallingConv(CI->getCallingConv()); + NewCI->SubclassOptionalData = CI->SubclassOptionalData; + NewCI->setAttributes(CI->getAttributes()); + NewCI->setDebugLoc(CI->getDebugLoc()); + return NewCI; +} + // Update profile weight for call instruction by scaling it using the ratio // of S/T. The meaning of "branch_weights" meta data for call instruction is // transfered to represent call count. @@ -966,6 +1022,20 @@ InvokeInst *InvokeInst::Create(InvokeInst *II, ArrayRef OpB, return NewII; } +InvokeInst *InvokeInst::Create(InvokeInst *II, ArrayRef OpB, + BasicBlock *InsertAtEnd) { + std::vector Args(II->arg_begin(), II->arg_end()); + + auto *NewII = InvokeInst::Create( + II->getFunctionType(), II->getCalledOperand(), II->getNormalDest(), + II->getUnwindDest(), Args, OpB, II->getName(), InsertAtEnd); + NewII->setCallingConv(II->getCallingConv()); + NewII->SubclassOptionalData = II->SubclassOptionalData; + NewII->setAttributes(II->getAttributes()); + NewII->setDebugLoc(II->getDebugLoc()); + return NewII; +} + LandingPadInst *InvokeInst::getLandingPadInst() const { return cast(getUnwindDest()->getFirstNonPHI()); } @@ -1055,6 +1125,21 @@ CallBrInst *CallBrInst::Create(CallBrInst *CBI, ArrayRef OpB, return NewCBI; } +CallBrInst *CallBrInst::Create(CallBrInst *CBI, ArrayRef OpB, + BasicBlock *InsertAtEnd) { + std::vector Args(CBI->arg_begin(), CBI->arg_end()); + + auto *NewCBI = CallBrInst::Create( + CBI->getFunctionType(), CBI->getCalledOperand(), CBI->getDefaultDest(), + CBI->getIndirectDests(), Args, OpB, CBI->getName(), InsertAtEnd); + NewCBI->setCallingConv(CBI->getCallingConv()); + NewCBI->SubclassOptionalData = CBI->SubclassOptionalData; + NewCBI->setAttributes(CBI->getAttributes()); + NewCBI->setDebugLoc(CBI->getDebugLoc()); + NewCBI->NumIndirectDests = CBI->NumIndirectDests; + return NewCBI; +} + //===----------------------------------------------------------------------===// // ReturnInst Implementation //===----------------------------------------------------------------------===// @@ -3190,9 +3275,7 @@ UnaryOperator *UnaryOperator::Create(UnaryOps Op, Value *S, UnaryOperator *UnaryOperator::Create(UnaryOps Op, Value *S, const Twine &Name, BasicBlock *InsertAtEnd) { - UnaryOperator *Res = Create(Op, S, Name); - Res->insertInto(InsertAtEnd, InsertAtEnd->end()); - return Res; + return new UnaryOperator(Op, S, S->getType(), Name, InsertAtEnd); } void UnaryOperator::AssertOK() { @@ -3340,9 +3423,9 @@ BinaryOperator *BinaryOperator::Create(BinaryOps Op, Value *S1, Value *S2, BinaryOperator *BinaryOperator::Create(BinaryOps Op, Value *S1, Value *S2, const Twine &Name, BasicBlock *InsertAtEnd) { - BinaryOperator *Res = Create(Op, S1, S2, Name); - Res->insertInto(InsertAtEnd, InsertAtEnd->end()); - return Res; + assert(S1->getType() == S2->getType() && + "Cannot create binary operator with two operands of differing type!"); + return new BinaryOperator(Op, S1, S2, S1->getType(), Name, InsertAtEnd); } BinaryOperator *BinaryOperator::CreateNeg(Value *Op, const Twine &Name, @@ -3957,6 +4040,17 @@ CastInst *CastInst::CreateBitOrPointerCast(Value *S, Type *Ty, return Create(Instruction::BitCast, S, Ty, Name, InsertBefore); } +CastInst *CastInst::CreateBitOrPointerCast(Value *S, Type *Ty, + const Twine &Name, + BasicBlock *InsertAtEnd) { + if (S->getType()->isPointerTy() && Ty->isIntegerTy()) + return Create(Instruction::PtrToInt, S, Ty, Name, InsertAtEnd); + if (S->getType()->isIntegerTy() && Ty->isPointerTy()) + return Create(Instruction::IntToPtr, S, Ty, Name, InsertAtEnd); + + return Create(Instruction::BitCast, S, Ty, Name, InsertAtEnd); +} + CastInst *CastInst::CreateIntegerCast(Value *C, Type *Ty, bool isSigned, const Twine &Name, BasicBlock::iterator InsertBefore) {