From 58cfa3b13752579c86cf85270d49f9ced0942f2f Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Tue, 25 Aug 2009 22:11:20 +0000 Subject: [PATCH] Rename Instruction::isIdenticalTo to Instruction::isIdenticalToWhenDefined, and introduce a new Instruction::isIdenticalTo which tests for full identity, including the SubclassOptionalData flags. Also, fix the Instruction::clone implementations to preserve the SubclassOptionalData flags. Finally, teach several optimizations how to handle SubclassOptionalData correctly, given these changes. This fixes the counterintuitive behavior of isIdenticalTo not comparing the full value, and clone not returning an identical clone, as well as some subtle bugs that could be caused by these. Thanks to Nick Lewycky for reporting this, and for an initial patch! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@80038 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/InstrTypes.h | 7 - include/llvm/Instruction.h | 5 + include/llvm/Instructions.h | 81 +------ include/llvm/Value.h | 12 ++ lib/Transforms/IPO/MergeFunctions.cpp | 3 +- .../Scalar/InstructionCombining.cpp | 6 +- lib/Transforms/Utils/BasicBlockUtils.cpp | 8 +- lib/Transforms/Utils/SimplifyCFG.cpp | 6 +- lib/VMCore/Instruction.cpp | 8 + lib/VMCore/Instructions.cpp | 197 ++++++++++++------ 10 files changed, 176 insertions(+), 157 deletions(-) diff --git a/include/llvm/InstrTypes.h b/include/llvm/InstrTypes.h index 35fec63ddfe..9b59c80326e 100644 --- a/include/llvm/InstrTypes.h +++ b/include/llvm/InstrTypes.h @@ -90,7 +90,6 @@ public: class UnaryInstruction : public Instruction { void *operator new(size_t, unsigned); // Do not implement - UnaryInstruction(const UnaryInstruction&); // Do not implement protected: UnaryInstruction(const Type *Ty, unsigned iType, Value *V, @@ -315,12 +314,6 @@ DEFINE_TRANSPARENT_OPERAND_ACCESSORS(BinaryOperator, Value) /// if (isa(Instr)) { ... } /// @brief Base class of casting instructions. class CastInst : public UnaryInstruction { - /// @brief Copy constructor - CastInst(const CastInst &CI) - : UnaryInstruction(CI.getType(), CI.getOpcode(), CI.getOperand(0)) { - } - /// @brief Do not allow default construction - CastInst(); protected: /// @brief Constructor with insert-before-instruction semantics for subclasses CastInst(const Type *Ty, unsigned iType, Value *S, diff --git a/include/llvm/Instruction.h b/include/llvm/Instruction.h index 924b19554a8..189c34a5021 100644 --- a/include/llvm/Instruction.h +++ b/include/llvm/Instruction.h @@ -54,6 +54,11 @@ public: /// extra information (e.g. load is volatile) agree. bool isIdenticalTo(const Instruction *I) const; + /// isIdenticalToWhenDefined - This is like isIdenticalTo, except that it + /// ignores the SubclassOptionalData flags, which specify conditions + /// under which the instruction's result is undefined. + bool isIdenticalToWhenDefined(const Instruction *I) const; + /// This function determines if the specified instruction executes the same /// operation as the current one. This means that the opcodes, type, operand /// types and any other factors affecting the operation must be the same. This diff --git a/include/llvm/Instructions.h b/include/llvm/Instructions.h index 33af5bcd7a9..5163342f332 100644 --- a/include/llvm/Instructions.h +++ b/include/llvm/Instructions.h @@ -99,7 +99,6 @@ public: /// MallocInst - an instruction to allocated memory on the heap /// class MallocInst : public AllocationInst { - MallocInst(const MallocInst &MI); public: explicit MallocInst(const Type *Ty, Value *ArraySize = 0, const Twine &NameStr = "", @@ -148,7 +147,6 @@ public: /// AllocaInst - an instruction to allocate memory on the stack /// class AllocaInst : public AllocationInst { - AllocaInst(const AllocaInst &); public: explicit AllocaInst(const Type *Ty, Value *ArraySize = 0, @@ -234,16 +232,6 @@ public: /// SubclassData field in Value to store whether or not the load is volatile. /// class LoadInst : public UnaryInstruction { - - LoadInst(const LoadInst &LI) - : UnaryInstruction(LI.getType(), Load, LI.getOperand(0)) { - setVolatile(LI.isVolatile()); - setAlignment(LI.getAlignment()); - -#ifndef NDEBUG - AssertOK(); -#endif - } void AssertOK(); public: LoadInst(Value *Ptr, const Twine &NameStr, Instruction *InsertBefore); @@ -308,18 +296,6 @@ public: /// class StoreInst : public Instruction { void *operator new(size_t, unsigned); // DO NOT IMPLEMENT - - StoreInst(const StoreInst &SI) : Instruction(SI.getType(), Store, - &Op<0>(), 2) { - Op<0>() = SI.Op<0>(); - Op<1>() = SI.Op<1>(); - setVolatile(SI.isVolatile()); - setAlignment(SI.getAlignment()); - -#ifndef NDEBUG - AssertOK(); -#endif - } void AssertOK(); public: // allocate space for exactly two operands @@ -1196,10 +1172,6 @@ class SelectInst : public Instruction { Op<2>() = S2; } - SelectInst(const SelectInst &SI) - : Instruction(SI.getType(), SI.getOpcode(), &Op<0>(), 3) { - init(SI.Op<0>(), SI.Op<1>(), SI.Op<2>()); - } SelectInst(Value *C, Value *S1, Value *S2, const Twine &NameStr, Instruction *InsertBefore) : Instruction(S1->getType(), Instruction::Select, @@ -1267,8 +1239,6 @@ DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SelectInst, Value) /// an argument of the specified type given a va_list and increments that list /// class VAArgInst : public UnaryInstruction { - VAArgInst(const VAArgInst &VAA) - : UnaryInstruction(VAA.getType(), VAArg, VAA.getOperand(0)) {} public: VAArgInst(Value *List, const Type *Ty, const Twine &NameStr = "", Instruction *InsertBefore = 0) @@ -1301,19 +1271,13 @@ public: /// element from a VectorType value /// class ExtractElementInst : public Instruction { - ExtractElementInst(const ExtractElementInst &EE) : - Instruction(EE.getType(), ExtractElement, &Op<0>(), 2) { - Op<0>() = EE.Op<0>(); - Op<1>() = EE.Op<1>(); - } - ExtractElementInst(Value *Vec, Value *Idx, const Twine &NameStr = "", Instruction *InsertBefore = 0); ExtractElementInst(Value *Vec, Value *Idx, const Twine &NameStr, BasicBlock *InsertAtEnd); public: static ExtractElementInst *Create(const ExtractElementInst &EE) { - return new(EE.getNumOperands()) ExtractElementInst(EE); + return Create(EE.getOperand(0), EE.getOperand(1)); } static ExtractElementInst *Create(Value *Vec, Value *Idx, @@ -1360,7 +1324,6 @@ DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ExtractElementInst, Value) /// element into a VectorType value /// class InsertElementInst : public Instruction { - InsertElementInst(const InsertElementInst &IE); InsertElementInst(Value *Vec, Value *NewElt, Value *Idx, const Twine &NameStr = "", Instruction *InsertBefore = 0); @@ -1368,7 +1331,7 @@ class InsertElementInst : public Instruction { const Twine &NameStr, BasicBlock *InsertAtEnd); public: static InsertElementInst *Create(const InsertElementInst &IE) { - return new(IE.getNumOperands()) InsertElementInst(IE); + return Create(IE.getOperand(0), IE.getOperand(1), IE.getOperand(2)); } static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx, const Twine &NameStr = "", @@ -1421,7 +1384,6 @@ DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertElementInst, Value) /// input vectors. /// class ShuffleVectorInst : public Instruction { - ShuffleVectorInst(const ShuffleVectorInst &IE); public: // allocate space for exactly three operands void *operator new(size_t s) { @@ -2658,10 +2620,6 @@ private: /// @brief This class represents a truncation of integer types. class TruncInst : public CastInst { - /// Private copy constructor - TruncInst(const TruncInst &CI) - : CastInst(CI.getType(), Trunc, CI.getOperand(0)) { - } public: /// @brief Constructor with insert-before-instruction semantics TruncInst( @@ -2698,10 +2656,6 @@ public: /// @brief This class represents zero extension of integer types. class ZExtInst : public CastInst { - /// @brief Private copy constructor - ZExtInst(const ZExtInst &CI) - : CastInst(CI.getType(), ZExt, CI.getOperand(0)) { - } public: /// @brief Constructor with insert-before-instruction semantics ZExtInst( @@ -2738,10 +2692,6 @@ public: /// @brief This class represents a sign extension of integer types. class SExtInst : public CastInst { - /// @brief Private copy constructor - SExtInst(const SExtInst &CI) - : CastInst(CI.getType(), SExt, CI.getOperand(0)) { - } public: /// @brief Constructor with insert-before-instruction semantics SExtInst( @@ -2778,9 +2728,6 @@ public: /// @brief This class represents a truncation of floating point types. class FPTruncInst : public CastInst { - FPTruncInst(const FPTruncInst &CI) - : CastInst(CI.getType(), FPTrunc, CI.getOperand(0)) { - } public: /// @brief Constructor with insert-before-instruction semantics FPTruncInst( @@ -2817,9 +2764,6 @@ public: /// @brief This class represents an extension of floating point types. class FPExtInst : public CastInst { - FPExtInst(const FPExtInst &CI) - : CastInst(CI.getType(), FPExt, CI.getOperand(0)) { - } public: /// @brief Constructor with insert-before-instruction semantics FPExtInst( @@ -2856,9 +2800,6 @@ public: /// @brief This class represents a cast unsigned integer to floating point. class UIToFPInst : public CastInst { - UIToFPInst(const UIToFPInst &CI) - : CastInst(CI.getType(), UIToFP, CI.getOperand(0)) { - } public: /// @brief Constructor with insert-before-instruction semantics UIToFPInst( @@ -2895,9 +2836,6 @@ public: /// @brief This class represents a cast from signed integer to floating point. class SIToFPInst : public CastInst { - SIToFPInst(const SIToFPInst &CI) - : CastInst(CI.getType(), SIToFP, CI.getOperand(0)) { - } public: /// @brief Constructor with insert-before-instruction semantics SIToFPInst( @@ -2934,9 +2872,6 @@ public: /// @brief This class represents a cast from floating point to unsigned integer class FPToUIInst : public CastInst { - FPToUIInst(const FPToUIInst &CI) - : CastInst(CI.getType(), FPToUI, CI.getOperand(0)) { - } public: /// @brief Constructor with insert-before-instruction semantics FPToUIInst( @@ -2973,9 +2908,6 @@ public: /// @brief This class represents a cast from floating point to signed integer. class FPToSIInst : public CastInst { - FPToSIInst(const FPToSIInst &CI) - : CastInst(CI.getType(), FPToSI, CI.getOperand(0)) { - } public: /// @brief Constructor with insert-before-instruction semantics FPToSIInst( @@ -3012,9 +2944,6 @@ public: /// @brief This class represents a cast from an integer to a pointer. class IntToPtrInst : public CastInst { - IntToPtrInst(const IntToPtrInst &CI) - : CastInst(CI.getType(), IntToPtr, CI.getOperand(0)) { - } public: /// @brief Constructor with insert-before-instruction semantics IntToPtrInst( @@ -3051,9 +2980,6 @@ public: /// @brief This class represents a cast from a pointer to an integer class PtrToIntInst : public CastInst { - PtrToIntInst(const PtrToIntInst &CI) - : CastInst(CI.getType(), PtrToInt, CI.getOperand(0)) { - } public: /// @brief Constructor with insert-before-instruction semantics PtrToIntInst( @@ -3090,9 +3016,6 @@ public: /// @brief This class represents a no-op cast from one type to another. class BitCastInst : public CastInst { - BitCastInst(const BitCastInst &CI) - : CastInst(CI.getType(), BitCast, CI.getOperand(0)) { - } public: /// @brief Constructor with insert-before-instruction semantics BitCastInst( diff --git a/include/llvm/Value.h b/include/llvm/Value.h index 47933f01966..fdc3aeb9567 100644 --- a/include/llvm/Value.h +++ b/include/llvm/Value.h @@ -240,6 +240,18 @@ public: return SubclassID; } + /// hasSameSubclassOptionalData - Test whether the optional flags contained + /// in this value are equal to the optional flags in the given value. + bool hasSameSubclassOptionalData(const Value *V) const { + return SubclassOptionalData == V->SubclassOptionalData; + } + + /// intersectOptionalDataWith - Clear any optional flags in this value + /// that are not also set in the given value. + void intersectOptionalDataWith(const Value *V) { + SubclassOptionalData &= V->SubclassOptionalData; + } + // Methods for support type inquiry through isa, cast, and dyn_cast: static inline bool classof(const Value *) { return true; // Values are always values. diff --git a/lib/Transforms/IPO/MergeFunctions.cpp b/lib/Transforms/IPO/MergeFunctions.cpp index f037c4fa209..9c8592e8eb1 100644 --- a/lib/Transforms/IPO/MergeFunctions.cpp +++ b/lib/Transforms/IPO/MergeFunctions.cpp @@ -188,7 +188,8 @@ static bool isEquivalentOperation(const Instruction *I1, const Instruction *I2) { if (I1->getOpcode() != I2->getOpcode() || I1->getNumOperands() != I2->getNumOperands() || - !isEquivalentType(I1->getType(), I2->getType())) + !isEquivalentType(I1->getType(), I2->getType()) || + !I1->hasSameSubclassOptionalData(I2)) return false; // We have two instructions of identical opcode and #operands. Check to see diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp index 6dd2641ad4c..cca428e7c45 100644 --- a/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/lib/Transforms/Scalar/InstructionCombining.cpp @@ -11815,12 +11815,16 @@ static bool equivalentAddressValues(Value *A, Value *B) { if (A == B) return true; // Test if the values come form identical arithmetic instructions. + // This uses isIdenticalToWhenDefined instead of isIdenticalTo because + // its only used to compare two uses within the same basic block, which + // means that they'll always either have the same value or one of them + // will have an undefined value. if (isa(A) || isa(A) || isa(A) || isa(A)) if (Instruction *BI = dyn_cast(B)) - if (cast(A)->isIdenticalTo(BI)) + if (cast(A)->isIdenticalToWhenDefined(BI)) return true; // Otherwise they may not be equivalent. diff --git a/lib/Transforms/Utils/BasicBlockUtils.cpp b/lib/Transforms/Utils/BasicBlockUtils.cpp index 3072cee61c2..c3d6194801d 100644 --- a/lib/Transforms/Utils/BasicBlockUtils.cpp +++ b/lib/Transforms/Utils/BasicBlockUtils.cpp @@ -504,11 +504,15 @@ static bool AreEquivalentAddressValues(const Value *A, const Value *B) { // Test if the values are trivially equivalent. if (A == B) return true; - // Test if the values come form identical arithmetic instructions. + // Test if the values come from identical arithmetic instructions. + // Use isIdenticalToWhenDefined instead of isIdenticalTo because + // this function is only used when one address use dominates the + // other, which means that they'll always either have the same + // value or one of them will have an undefined value. if (isa(A) || isa(A) || isa(A) || isa(A)) if (const Instruction *BI = dyn_cast(B)) - if (cast(A)->isIdenticalTo(BI)) + if (cast(A)->isIdenticalToWhenDefined(BI)) return true; // Otherwise they may not be equivalent. diff --git a/lib/Transforms/Utils/SimplifyCFG.cpp b/lib/Transforms/Utils/SimplifyCFG.cpp index 7b7495e665f..0938c44c96a 100644 --- a/lib/Transforms/Utils/SimplifyCFG.cpp +++ b/lib/Transforms/Utils/SimplifyCFG.cpp @@ -872,7 +872,7 @@ static bool HoistThenElseCodeToIf(BranchInst *BI) { while (isa(I2)) I2 = BB2_Itr++; if (I1->getOpcode() != I2->getOpcode() || isa(I1) || - !I1->isIdenticalTo(I2) || + !I1->isIdenticalToWhenDefined(I2) || (isa(I1) && !isSafeToHoistInvoke(BB1, BB2, I1, I2))) return false; @@ -891,6 +891,7 @@ static bool HoistThenElseCodeToIf(BranchInst *BI) { BIParent->getInstList().splice(BI, BB1->getInstList(), I1); if (!I2->use_empty()) I2->replaceAllUsesWith(I1); + I1->intersectOptionalDataWith(I2); BB2->getInstList().erase(I2); I1 = BB1_Itr++; @@ -899,7 +900,8 @@ static bool HoistThenElseCodeToIf(BranchInst *BI) { I2 = BB2_Itr++; while (isa(I2)) I2 = BB2_Itr++; - } while (I1->getOpcode() == I2->getOpcode() && I1->isIdenticalTo(I2)); + } while (I1->getOpcode() == I2->getOpcode() && + I1->isIdenticalToWhenDefined(I2)); return true; diff --git a/lib/VMCore/Instruction.cpp b/lib/VMCore/Instruction.cpp index e19ad1c16f9..332ecf9782d 100644 --- a/lib/VMCore/Instruction.cpp +++ b/lib/VMCore/Instruction.cpp @@ -168,6 +168,14 @@ const char *Instruction::getOpcodeName(unsigned OpCode) { /// identical to the current one. This means that all operands match and any /// extra information (e.g. load is volatile) agree. bool Instruction::isIdenticalTo(const Instruction *I) const { + return isIdenticalTo(I) && + SubclassOptionalData == I->SubclassOptionalData; +} + +/// isIdenticalToWenDefined - This is like isIdenticalTo, except that it +/// ignores the SubclassOptionalData flags, which specify conditions +/// under which the instruction's result is undefined. +bool Instruction::isIdenticalToWhenDefined(const Instruction *I) const { if (getOpcode() != I->getOpcode() || getNumOperands() != I->getNumOperands() || getType() != I->getType()) diff --git a/lib/VMCore/Instructions.cpp b/lib/VMCore/Instructions.cpp index bbea62bdeda..12a4045a14e 100644 --- a/lib/VMCore/Instructions.cpp +++ b/lib/VMCore/Instructions.cpp @@ -154,6 +154,7 @@ PHINode::PHINode(const PHINode &PN) OL[i] = PN.getOperand(i); OL[i+1] = PN.getOperand(i+1); } + SubclassOptionalData = PN.SubclassOptionalData; } PHINode::~PHINode() { @@ -403,6 +404,7 @@ CallInst::CallInst(const CallInst &CI) Use *InOL = CI.OperandList; for (unsigned i = 0, e = CI.getNumOperands(); i != e; ++i) OL[i] = InOL[i]; + SubclassOptionalData = CI.SubclassOptionalData; } void CallInst::addAttribute(unsigned i, Attributes attr) { @@ -464,6 +466,7 @@ InvokeInst::InvokeInst(const InvokeInst &II) Use *OL = OperandList, *InOL = II.OperandList; for (unsigned i = 0, e = II.getNumOperands(); i != e; ++i) OL[i] = InOL[i]; + SubclassOptionalData = II.SubclassOptionalData; } BasicBlock *InvokeInst::getSuccessorV(unsigned idx) const { @@ -508,6 +511,7 @@ ReturnInst::ReturnInst(const ReturnInst &RI) RI.getNumOperands()) { if (RI.getNumOperands()) Op<0>() = RI.Op<0>(); + SubclassOptionalData = RI.SubclassOptionalData; } ReturnInst::ReturnInst(LLVMContext &C, Value *retVal, Instruction *InsertBefore) @@ -663,6 +667,7 @@ BranchInst::BranchInst(const BranchInst &BI) : Op<-3>() = BI.Op<-3>(); Op<-2>() = BI.Op<-2>(); } + SubclassOptionalData = BI.SubclassOptionalData; } @@ -757,12 +762,6 @@ const Type *AllocationInst::getAllocatedType() const { return getType()->getElementType(); } -AllocaInst::AllocaInst(const AllocaInst &AI) - : AllocationInst(AI.getType()->getElementType(), - (Value*)AI.getOperand(0), Instruction::Alloca, - AI.getAlignment()) { -} - /// isStaticAlloca - Return true if this alloca is in the entry block of the /// function and is a constant size. If so, the code generator will fold it /// into the prolog/epilog code, so it is basically free. @@ -775,12 +774,6 @@ bool AllocaInst::isStaticAlloca() const { return Parent == &Parent->getParent()->front(); } -MallocInst::MallocInst(const MallocInst &MI) - : AllocationInst(MI.getType()->getElementType(), - (Value*)MI.getOperand(0), Instruction::Malloc, - MI.getAlignment()) { -} - //===----------------------------------------------------------------------===// // FreeInst Implementation //===----------------------------------------------------------------------===// @@ -1048,6 +1041,7 @@ GetElementPtrInst::GetElementPtrInst(const GetElementPtrInst &GEPI) Use *GEPIOL = GEPI.OperandList; for (unsigned i = 0, E = NumOperands; i != E; ++i) OL[i] = GEPIOL[i]; + SubclassOptionalData = GEPI.SubclassOptionalData; } GetElementPtrInst::GetElementPtrInst(Value *Ptr, Value *Idx, @@ -1211,13 +1205,6 @@ bool ExtractElementInst::isValidOperands(const Value *Val, const Value *Index) { // InsertElementInst Implementation //===----------------------------------------------------------------------===// -InsertElementInst::InsertElementInst(const InsertElementInst &IE) - : Instruction(IE.getType(), InsertElement, - OperandTraits::op_begin(this), 3) { - Op<0>() = IE.Op<0>(); - Op<1>() = IE.Op<1>(); - Op<2>() = IE.Op<2>(); -} InsertElementInst::InsertElementInst(Value *Vec, Value *Elt, Value *Index, const Twine &Name, Instruction *InsertBef) @@ -1265,15 +1252,6 @@ bool InsertElementInst::isValidOperands(const Value *Vec, const Value *Elt, // ShuffleVectorInst Implementation //===----------------------------------------------------------------------===// -ShuffleVectorInst::ShuffleVectorInst(const ShuffleVectorInst &SV) - : Instruction(SV.getType(), ShuffleVector, - OperandTraits::op_begin(this), - OperandTraits::operands(this)) { - Op<0>() = SV.Op<0>(); - Op<1>() = SV.Op<1>(); - Op<2>() = SV.Op<2>(); -} - ShuffleVectorInst::ShuffleVectorInst(Value *V1, Value *V2, Value *Mask, const Twine &Name, Instruction *InsertBefore) @@ -1364,6 +1342,7 @@ InsertValueInst::InsertValueInst(const InsertValueInst &IVI) Indices(IVI.Indices) { Op<0>() = IVI.getOperand(0); Op<1>() = IVI.getOperand(1); + SubclassOptionalData = IVI.SubclassOptionalData; } InsertValueInst::InsertValueInst(Value *Agg, @@ -1410,6 +1389,7 @@ void ExtractValueInst::init(unsigned Idx, const Twine &Name) { ExtractValueInst::ExtractValueInst(const ExtractValueInst &EVI) : UnaryInstruction(EVI.getType(), ExtractValue, EVI.getOperand(0)), Indices(EVI.Indices) { + SubclassOptionalData = EVI.SubclassOptionalData; } // getIndexedType - Returns the type of the element that would be extracted @@ -2790,6 +2770,7 @@ SwitchInst::SwitchInst(const SwitchInst &SI) OL[i] = InOL[i]; OL[i+1] = InOL[i+1]; } + SubclassOptionalData = SI.SubclassOptionalData; } SwitchInst::~SwitchInst() { @@ -2882,144 +2863,230 @@ void SwitchInst::setSuccessorV(unsigned idx, BasicBlock *B) { // unit that uses these classes. GetElementPtrInst *GetElementPtrInst::clone(LLVMContext&) const { - return new(getNumOperands()) GetElementPtrInst(*this); + GetElementPtrInst *New = new(getNumOperands()) GetElementPtrInst(*this); + New->SubclassOptionalData = SubclassOptionalData; + return New; } BinaryOperator *BinaryOperator::clone(LLVMContext&) const { - return Create(getOpcode(), Op<0>(), Op<1>()); + BinaryOperator *New = Create(getOpcode(), Op<0>(), Op<1>()); + New->SubclassOptionalData = SubclassOptionalData; + return New; } FCmpInst* FCmpInst::clone(LLVMContext &Context) const { - return new FCmpInst(Context, getPredicate(), Op<0>(), Op<1>()); + FCmpInst *New = new FCmpInst(Context, getPredicate(), Op<0>(), Op<1>()); + New->SubclassOptionalData = SubclassOptionalData; + return New; } ICmpInst* ICmpInst::clone(LLVMContext &Context) const { - return new ICmpInst(Context, getPredicate(), Op<0>(), Op<1>()); + ICmpInst *New = new ICmpInst(Context, getPredicate(), Op<0>(), Op<1>()); + New->SubclassOptionalData = SubclassOptionalData; + return New; } ExtractValueInst *ExtractValueInst::clone(LLVMContext&) const { - return new ExtractValueInst(*this); + ExtractValueInst *New = new ExtractValueInst(*this); + New->SubclassOptionalData = SubclassOptionalData; + return New; } InsertValueInst *InsertValueInst::clone(LLVMContext&) const { - return new InsertValueInst(*this); + InsertValueInst *New = new InsertValueInst(*this); + New->SubclassOptionalData = SubclassOptionalData; + return New; } MallocInst *MallocInst::clone(LLVMContext&) const { - return new MallocInst(*this); + MallocInst *New = new MallocInst(getAllocatedType(), + (Value*)getOperand(0), + getAlignment()); + New->SubclassOptionalData = SubclassOptionalData; + return New; } AllocaInst *AllocaInst::clone(LLVMContext&) const { - return new AllocaInst(*this); + AllocaInst *New = new AllocaInst(getAllocatedType(), + (Value*)getOperand(0), + getAlignment()); + New->SubclassOptionalData = SubclassOptionalData; + return New; } FreeInst *FreeInst::clone(LLVMContext&) const { - return new FreeInst(getOperand(0)); + FreeInst *New = new FreeInst(getOperand(0)); + New->SubclassOptionalData = SubclassOptionalData; + return New; } LoadInst *LoadInst::clone(LLVMContext&) const { - return new LoadInst(*this); + LoadInst *New = new LoadInst(getOperand(0), + Twine(), isVolatile(), + getAlignment()); + New->SubclassOptionalData = SubclassOptionalData; + return New; } StoreInst *StoreInst::clone(LLVMContext&) const { - return new StoreInst(*this); + StoreInst *New = new StoreInst(getOperand(0), getOperand(1), + isVolatile(), getAlignment()); + New->SubclassOptionalData = SubclassOptionalData; + return New; } CastInst *TruncInst::clone(LLVMContext&) const { - return new TruncInst(*this); + TruncInst *New = new TruncInst(getOperand(0), getType()); + New->SubclassOptionalData = SubclassOptionalData; + return New; } CastInst *ZExtInst::clone(LLVMContext&) const { - return new ZExtInst(*this); + ZExtInst *New = new ZExtInst(getOperand(0), getType()); + New->SubclassOptionalData = SubclassOptionalData; + return New; } CastInst *SExtInst::clone(LLVMContext&) const { - return new SExtInst(*this); + SExtInst *New = new SExtInst(getOperand(0), getType()); + New->SubclassOptionalData = SubclassOptionalData; + return New; } CastInst *FPTruncInst::clone(LLVMContext&) const { - return new FPTruncInst(*this); + FPTruncInst *New = new FPTruncInst(getOperand(0), getType()); + New->SubclassOptionalData = SubclassOptionalData; + return New; } CastInst *FPExtInst::clone(LLVMContext&) const { - return new FPExtInst(*this); + FPExtInst *New = new FPExtInst(getOperand(0), getType()); + New->SubclassOptionalData = SubclassOptionalData; + return New; } CastInst *UIToFPInst::clone(LLVMContext&) const { - return new UIToFPInst(*this); + UIToFPInst *New = new UIToFPInst(getOperand(0), getType()); + New->SubclassOptionalData = SubclassOptionalData; + return New; } CastInst *SIToFPInst::clone(LLVMContext&) const { - return new SIToFPInst(*this); + SIToFPInst *New = new SIToFPInst(getOperand(0), getType()); + New->SubclassOptionalData = SubclassOptionalData; + return New; } CastInst *FPToUIInst::clone(LLVMContext&) const { - return new FPToUIInst(*this); + FPToUIInst *New = new FPToUIInst(getOperand(0), getType()); + New->SubclassOptionalData = SubclassOptionalData; + return New; } CastInst *FPToSIInst::clone(LLVMContext&) const { - return new FPToSIInst(*this); + FPToSIInst *New = new FPToSIInst(getOperand(0), getType()); + New->SubclassOptionalData = SubclassOptionalData; + return New; } CastInst *PtrToIntInst::clone(LLVMContext&) const { - return new PtrToIntInst(*this); + PtrToIntInst *New = new PtrToIntInst(getOperand(0), getType()); + New->SubclassOptionalData = SubclassOptionalData; + return New; } CastInst *IntToPtrInst::clone(LLVMContext&) const { - return new IntToPtrInst(*this); + IntToPtrInst *New = new IntToPtrInst(getOperand(0), getType()); + New->SubclassOptionalData = SubclassOptionalData; + return New; } CastInst *BitCastInst::clone(LLVMContext&) const { - return new BitCastInst(*this); + BitCastInst *New = new BitCastInst(getOperand(0), getType()); + New->SubclassOptionalData = SubclassOptionalData; + return New; } CallInst *CallInst::clone(LLVMContext&) const { - return new(getNumOperands()) CallInst(*this); + CallInst *New = new(getNumOperands()) CallInst(*this); + New->SubclassOptionalData = SubclassOptionalData; + return New; } -SelectInst *SelectInst::clone(LLVMContext&) const { - return new(getNumOperands()) SelectInst(*this); +SelectInst *SelectInst::clone(LLVMContext&) const { + SelectInst *New = SelectInst::Create(getOperand(0), + getOperand(1), + getOperand(2)); + New->SubclassOptionalData = SubclassOptionalData; + return New; } VAArgInst *VAArgInst::clone(LLVMContext&) const { - return new VAArgInst(*this); + VAArgInst *New = new VAArgInst(getOperand(0), getType()); + New->SubclassOptionalData = SubclassOptionalData; + return New; } ExtractElementInst *ExtractElementInst::clone(LLVMContext&) const { - return ExtractElementInst::Create(*this); + ExtractElementInst *New = ExtractElementInst::Create(getOperand(0), + getOperand(1)); + New->SubclassOptionalData = SubclassOptionalData; + return New; } InsertElementInst *InsertElementInst::clone(LLVMContext&) const { - return InsertElementInst::Create(*this); + InsertElementInst *New = InsertElementInst::Create(getOperand(0), + getOperand(1), + getOperand(2)); + New->SubclassOptionalData = SubclassOptionalData; + return New; } ShuffleVectorInst *ShuffleVectorInst::clone(LLVMContext&) const { - return new ShuffleVectorInst(*this); + ShuffleVectorInst *New = new ShuffleVectorInst(getOperand(0), + getOperand(1), + getOperand(2)); + New->SubclassOptionalData = SubclassOptionalData; + return New; } PHINode *PHINode::clone(LLVMContext&) const { - return new PHINode(*this); + PHINode *New = new PHINode(*this); + New->SubclassOptionalData = SubclassOptionalData; + return New; } ReturnInst *ReturnInst::clone(LLVMContext&) const { - return new(getNumOperands()) ReturnInst(*this); + ReturnInst *New = new(getNumOperands()) ReturnInst(*this); + New->SubclassOptionalData = SubclassOptionalData; + return New; } BranchInst *BranchInst::clone(LLVMContext&) const { unsigned Ops(getNumOperands()); - return new(Ops, Ops == 1) BranchInst(*this); + BranchInst *New = new(Ops, Ops == 1) BranchInst(*this); + New->SubclassOptionalData = SubclassOptionalData; + return New; } SwitchInst *SwitchInst::clone(LLVMContext&) const { - return new SwitchInst(*this); + SwitchInst *New = new SwitchInst(*this); + New->SubclassOptionalData = SubclassOptionalData; + return New; } InvokeInst *InvokeInst::clone(LLVMContext&) const { - return new(getNumOperands()) InvokeInst(*this); + InvokeInst *New = new(getNumOperands()) InvokeInst(*this); + New->SubclassOptionalData = SubclassOptionalData; + return New; } UnwindInst *UnwindInst::clone(LLVMContext &C) const { - return new UnwindInst(C); + UnwindInst *New = new UnwindInst(C); + New->SubclassOptionalData = SubclassOptionalData; + return New; } UnreachableInst *UnreachableInst::clone(LLVMContext &C) const { - return new UnreachableInst(C); + UnreachableInst *New = new UnreachableInst(C); + New->SubclassOptionalData = SubclassOptionalData; + return New; }