virtual BasicBlock *getSuccessorV(unsigned idx) const = 0;
virtual unsigned getNumSuccessorsV() const = 0;
virtual void setSuccessorV(unsigned idx, BasicBlock *B) = 0;
+ virtual TerminatorInst *clone_impl() const = 0;
public:
- virtual TerminatorInst *clone() const = 0;
-
/// getNumSuccessors - Return the number of successors that this terminator
/// has.
unsigned getNumSuccessors() const {
const Twine &Name, Instruction *InsertBefore);
BinaryOperator(BinaryOps iType, Value *S1, Value *S2, const Type *Ty,
const Twine &Name, BasicBlock *InsertAtEnd);
+ virtual BinaryOperator *clone_impl() const;
public:
// allocate space for exactly two operands
void *operator new(size_t s) {
return static_cast<BinaryOps>(Instruction::getOpcode());
}
- virtual BinaryOperator *clone() const;
-
/// swapOperands - Exchange the two operands to this instruction.
/// This instruction is safe to use on any binary instruction and
/// does not modify the semantics of the instruction. If the instruction
Instruction *InsertBefore = 0);
Instruction(const Type *Ty, unsigned iType, Use *Ops, unsigned NumOps,
BasicBlock *InsertAtEnd);
+ virtual Instruction *clone_impl() const = 0;
public:
// Out of line virtual method, so the vtable, etc has a home.
~Instruction();
/// * The instruction has no parent
/// * The instruction has no name
///
- virtual Instruction *clone() const = 0;
+ Instruction *clone() const;
/// isIdenticalTo - Return true if the specified instruction is exactly
/// identical to the current one. This means that all operands match and any
/// AllocaInst - an instruction to allocate memory on the stack
///
class AllocaInst : public UnaryInstruction {
+protected:
+ virtual AllocaInst *clone_impl() const;
public:
explicit AllocaInst(const Type *Ty, Value *ArraySize = 0,
const Twine &Name = "", Instruction *InsertBefore = 0);
/// into the prolog/epilog code, so it is basically free.
bool isStaticAlloca() const;
- virtual AllocaInst *clone() const;
-
// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const AllocaInst *) { return true; }
static inline bool classof(const Instruction *I) {
///
class LoadInst : public UnaryInstruction {
void AssertOK();
+protected:
+ virtual LoadInst *clone_impl() const;
public:
LoadInst(Value *Ptr, const Twine &NameStr, Instruction *InsertBefore);
LoadInst(Value *Ptr, const Twine &NameStr, BasicBlock *InsertAtEnd);
SubclassData = (SubclassData & ~1) | (V ? 1 : 0);
}
- virtual LoadInst *clone() const;
-
/// getAlignment - Return the alignment of the access that is being performed
///
unsigned getAlignment() const {
class StoreInst : public Instruction {
void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
void AssertOK();
+protected:
+ virtual StoreInst *clone_impl() const;
public:
// allocate space for exactly two operands
void *operator new(size_t s) {
void setAlignment(unsigned Align);
- virtual StoreInst *clone() const;
-
Value *getPointerOperand() { return getOperand(1); }
const Value *getPointerOperand() const { return getOperand(1); }
static unsigned getPointerOperandIndex() { return 1U; }
Instruction *InsertBefore = 0);
GetElementPtrInst(Value *Ptr, Value *Idx,
const Twine &NameStr, BasicBlock *InsertAtEnd);
+protected:
+ virtual GetElementPtrInst *clone_impl() const;
public:
template<typename InputIterator>
static GetElementPtrInst *Create(Value *Ptr, InputIterator IdxBegin,
return GEP;
}
- virtual GetElementPtrInst *clone() const;
-
/// Transparently provide more efficient getOperand methods.
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
/// must be identical types.
/// @brief Represent an integer comparison operator.
class ICmpInst: public CmpInst {
+protected:
+ /// @brief Clone an indentical ICmpInst
+ virtual ICmpInst *clone_impl() const;
public:
/// @brief Constructor with insert-before-instruction semantics.
ICmpInst(
Op<0>().swap(Op<1>());
}
- virtual ICmpInst *clone() const;
-
// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const ICmpInst *) { return true; }
static inline bool classof(const Instruction *I) {
/// vectors of floating point values. The operands must be identical types.
/// @brief Represents a floating point comparison operator.
class FCmpInst: public CmpInst {
+protected:
+ /// @brief Clone an indentical FCmpInst
+ virtual FCmpInst *clone_impl() const;
public:
/// @brief Constructor with insert-before-instruction semantics.
FCmpInst(
Op<0>().swap(Op<1>());
}
- virtual FCmpInst *clone() const;
-
/// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const FCmpInst *) { return true; }
static inline bool classof(const Instruction *I) {
explicit CallInst(Value *F, const Twine &NameStr,
Instruction *InsertBefore);
CallInst(Value *F, const Twine &NameStr, BasicBlock *InsertAtEnd);
+protected:
+ virtual CallInst *clone_impl() const;
public:
template<typename InputIterator>
static CallInst *Create(Value *Func,
SubclassData = (SubclassData & ~1) | unsigned(isTC);
}
- virtual CallInst *clone() const;
-
/// Provide fast operand accessors
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
init(C, S1, S2);
setName(NameStr);
}
+protected:
+ virtual SelectInst *clone_impl() const;
public:
static SelectInst *Create(Value *C, Value *S1, Value *S2,
const Twine &NameStr = "",
return static_cast<OtherOps>(Instruction::getOpcode());
}
- virtual SelectInst *clone() const;
-
// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const SelectInst *) { return true; }
static inline bool classof(const Instruction *I) {
/// an argument of the specified type given a va_list and increments that list
///
class VAArgInst : public UnaryInstruction {
+protected:
+ virtual VAArgInst *clone_impl() const;
+
public:
VAArgInst(Value *List, const Type *Ty, const Twine &NameStr = "",
Instruction *InsertBefore = 0)
setName(NameStr);
}
- virtual VAArgInst *clone() const;
-
// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const VAArgInst *) { return true; }
static inline bool classof(const Instruction *I) {
Instruction *InsertBefore = 0);
ExtractElementInst(Value *Vec, Value *Idx, const Twine &NameStr,
BasicBlock *InsertAtEnd);
+protected:
+ virtual ExtractElementInst *clone_impl() const;
+
public:
static ExtractElementInst *Create(Value *Vec, Value *Idx,
const Twine &NameStr = "",
/// formed with the specified operands.
static bool isValidOperands(const Value *Vec, const Value *Idx);
- virtual ExtractElementInst *clone() const;
-
Value *getVectorOperand() { return Op<0>(); }
Value *getIndexOperand() { return Op<1>(); }
const Value *getVectorOperand() const { return Op<0>(); }
Instruction *InsertBefore = 0);
InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
const Twine &NameStr, BasicBlock *InsertAtEnd);
+protected:
+ virtual InsertElementInst *clone_impl() const;
+
public:
static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx,
const Twine &NameStr = "",
static bool isValidOperands(const Value *Vec, const Value *NewElt,
const Value *Idx);
- virtual InsertElementInst *clone() const;
-
/// getType - Overload to return most specific vector type.
///
const VectorType *getType() const {
/// input vectors.
///
class ShuffleVectorInst : public Instruction {
+protected:
+ virtual ShuffleVectorInst *clone_impl() const;
+
public:
// allocate space for exactly three operands
void *operator new(size_t s) {
static bool isValidOperands(const Value *V1, const Value *V2,
const Value *Mask);
- virtual ShuffleVectorInst *clone() const;
-
/// getType - Overload to return most specific vector type.
///
const VectorType *getType() const {
void *operator new(size_t s) {
return User::operator new(s, 1);
}
+protected:
+ virtual ExtractValueInst *clone_impl() const;
public:
template<typename InputIterator>
return new ExtractValueInst(Agg, Idxs, Idxs + 1, NameStr, InsertAtEnd);
}
- virtual ExtractValueInst *clone() const;
-
/// getIndexedType - Returns the type of the element that would be extracted
/// with an extractvalue instruction with the specified parameters.
///
Instruction *InsertBefore = 0);
InsertValueInst(Value *Agg, Value *Val, unsigned Idx,
const Twine &NameStr, BasicBlock *InsertAtEnd);
+protected:
+ virtual InsertValueInst *clone_impl() const;
public:
// allocate space for exactly two operands
void *operator new(size_t s) {
return new InsertValueInst(Agg, Val, Idx, NameStr, InsertAtEnd);
}
- virtual InsertValueInst *clone() const;
-
/// Transparently provide more efficient getOperand methods.
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
ReservedSpace(0) {
setName(NameStr);
}
+protected:
+ virtual PHINode *clone_impl() const;
public:
static PHINode *Create(const Type *Ty, const Twine &NameStr = "",
Instruction *InsertBefore = 0) {
resizeOperands(NumValues*2);
}
- virtual PHINode *clone() const;
-
/// Provide fast operand accessors
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
Instruction *InsertBefore = 0);
ReturnInst(LLVMContext &C, Value *retVal, BasicBlock *InsertAtEnd);
explicit ReturnInst(LLVMContext &C, BasicBlock *InsertAtEnd);
+protected:
+ virtual ReturnInst *clone_impl() const;
public:
static ReturnInst* Create(LLVMContext &C, Value *retVal = 0,
Instruction *InsertBefore = 0) {
}
virtual ~ReturnInst();
- virtual ReturnInst *clone() const;
-
/// Provide fast operand accessors
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
BranchInst(BasicBlock *IfTrue, BasicBlock *InsertAtEnd);
BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
BasicBlock *InsertAtEnd);
+protected:
+ virtual BranchInst *clone_impl() const;
public:
static BranchInst *Create(BasicBlock *IfTrue, Instruction *InsertBefore = 0) {
return new(1, true) BranchInst(IfTrue, InsertBefore);
/// Transparently provide more efficient getOperand methods.
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
- virtual BranchInst *clone() const;
-
bool isUnconditional() const { return getNumOperands() == 1; }
bool isConditional() const { return getNumOperands() == 3; }
/// constructor also autoinserts at the end of the specified BasicBlock.
SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
BasicBlock *InsertAtEnd);
+protected:
+ virtual SwitchInst *clone_impl() const;
public:
static SwitchInst *Create(Value *Value, BasicBlock *Default,
unsigned NumCases, Instruction *InsertBefore = 0) {
///
void removeCase(unsigned idx);
- virtual SwitchInst *clone() const;
-
unsigned getNumSuccessors() const { return getNumOperands()/2; }
BasicBlock *getSuccessor(unsigned idx) const {
assert(idx < getNumSuccessors() &&"Successor idx out of range for switch!");
/// make memory allocation more efficient. This constructor also autoinserts
/// at the end of the specified BasicBlock.
IndBrInst(Value *Address, unsigned NumDests, BasicBlock *InsertAtEnd);
+protected:
+ virtual IndBrInst *clone_impl() const;
public:
static IndBrInst *Create(Value *Address, unsigned NumDests,
Instruction *InsertBefore = 0) {
/// indbr instruction.
void removeDestination(unsigned i);
- virtual IndBrInst *clone() const;
-
unsigned getNumSuccessors() const { return getNumOperands()-1; }
BasicBlock *getSuccessor(unsigned i) const {
return cast<BasicBlock>(getOperand(i+1));
InputIterator ArgBegin, InputIterator ArgEnd,
unsigned Values,
const Twine &NameStr, BasicBlock *InsertAtEnd);
+protected:
+ virtual InvokeInst *clone_impl() const;
public:
template<typename InputIterator>
static InvokeInst *Create(Value *Func,
Values, NameStr, InsertAtEnd);
}
- virtual InvokeInst *clone() const;
-
/// Provide fast operand accessors
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
///
class UnwindInst : public TerminatorInst {
void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
+protected:
+ virtual UnwindInst *clone_impl() const;
public:
// allocate space for exactly zero operands
void *operator new(size_t s) {
explicit UnwindInst(LLVMContext &C, Instruction *InsertBefore = 0);
explicit UnwindInst(LLVMContext &C, BasicBlock *InsertAtEnd);
- virtual UnwindInst *clone() const;
-
unsigned getNumSuccessors() const { return 0; }
// Methods for support type inquiry through isa, cast, and dyn_cast:
///
class UnreachableInst : public TerminatorInst {
void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
+protected:
+ virtual UnreachableInst *clone_impl() const;
+
public:
// allocate space for exactly zero operands
void *operator new(size_t s) {
explicit UnreachableInst(LLVMContext &C, Instruction *InsertBefore = 0);
explicit UnreachableInst(LLVMContext &C, BasicBlock *InsertAtEnd);
- virtual UnreachableInst *clone() const;
-
unsigned getNumSuccessors() const { return 0; }
// Methods for support type inquiry through isa, cast, and dyn_cast:
/// @brief This class represents a truncation of integer types.
class TruncInst : public CastInst {
+protected:
+ /// @brief Clone an identical TruncInst
+ virtual TruncInst *clone_impl() const;
+
public:
/// @brief Constructor with insert-before-instruction semantics
TruncInst(
BasicBlock *InsertAtEnd ///< The block to insert the instruction into
);
- /// @brief Clone an identical TruncInst
- virtual TruncInst *clone() const;
-
/// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const TruncInst *) { return true; }
static inline bool classof(const Instruction *I) {
/// @brief This class represents zero extension of integer types.
class ZExtInst : public CastInst {
+protected:
+ /// @brief Clone an identical ZExtInst
+ virtual ZExtInst *clone_impl() const;
+
public:
/// @brief Constructor with insert-before-instruction semantics
ZExtInst(
BasicBlock *InsertAtEnd ///< The block to insert the instruction into
);
- /// @brief Clone an identical ZExtInst
- virtual ZExtInst *clone() const;
-
/// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const ZExtInst *) { return true; }
static inline bool classof(const Instruction *I) {
/// @brief This class represents a sign extension of integer types.
class SExtInst : public CastInst {
+protected:
+ /// @brief Clone an identical SExtInst
+ virtual SExtInst *clone_impl() const;
+
public:
/// @brief Constructor with insert-before-instruction semantics
SExtInst(
BasicBlock *InsertAtEnd ///< The block to insert the instruction into
);
- /// @brief Clone an identical SExtInst
- virtual SExtInst *clone() const;
-
/// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const SExtInst *) { return true; }
static inline bool classof(const Instruction *I) {
/// @brief This class represents a truncation of floating point types.
class FPTruncInst : public CastInst {
+protected:
+ /// @brief Clone an identical FPTruncInst
+ virtual FPTruncInst *clone_impl() const;
+
public:
/// @brief Constructor with insert-before-instruction semantics
FPTruncInst(
BasicBlock *InsertAtEnd ///< The block to insert the instruction into
);
- /// @brief Clone an identical FPTruncInst
- virtual FPTruncInst *clone() const;
-
/// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const FPTruncInst *) { return true; }
static inline bool classof(const Instruction *I) {
/// @brief This class represents an extension of floating point types.
class FPExtInst : public CastInst {
+protected:
+ /// @brief Clone an identical FPExtInst
+ virtual FPExtInst *clone_impl() const;
+
public:
/// @brief Constructor with insert-before-instruction semantics
FPExtInst(
BasicBlock *InsertAtEnd ///< The block to insert the instruction into
);
- /// @brief Clone an identical FPExtInst
- virtual FPExtInst *clone() const;
-
/// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const FPExtInst *) { return true; }
static inline bool classof(const Instruction *I) {
/// @brief This class represents a cast unsigned integer to floating point.
class UIToFPInst : public CastInst {
+protected:
+ /// @brief Clone an identical UIToFPInst
+ virtual UIToFPInst *clone_impl() const;
+
public:
/// @brief Constructor with insert-before-instruction semantics
UIToFPInst(
BasicBlock *InsertAtEnd ///< The block to insert the instruction into
);
- /// @brief Clone an identical UIToFPInst
- virtual UIToFPInst *clone() const;
-
/// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const UIToFPInst *) { return true; }
static inline bool classof(const Instruction *I) {
/// @brief This class represents a cast from signed integer to floating point.
class SIToFPInst : public CastInst {
+protected:
+ /// @brief Clone an identical SIToFPInst
+ virtual SIToFPInst *clone_impl() const;
+
public:
/// @brief Constructor with insert-before-instruction semantics
SIToFPInst(
BasicBlock *InsertAtEnd ///< The block to insert the instruction into
);
- /// @brief Clone an identical SIToFPInst
- virtual SIToFPInst *clone() const;
-
/// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const SIToFPInst *) { return true; }
static inline bool classof(const Instruction *I) {
/// @brief This class represents a cast from floating point to unsigned integer
class FPToUIInst : public CastInst {
+protected:
+ /// @brief Clone an identical FPToUIInst
+ virtual FPToUIInst *clone_impl() const;
+
public:
/// @brief Constructor with insert-before-instruction semantics
FPToUIInst(
BasicBlock *InsertAtEnd ///< Where to insert the new instruction
);
- /// @brief Clone an identical FPToUIInst
- virtual FPToUIInst *clone() const;
-
/// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const FPToUIInst *) { return true; }
static inline bool classof(const Instruction *I) {
/// @brief This class represents a cast from floating point to signed integer.
class FPToSIInst : public CastInst {
+protected:
+ /// @brief Clone an identical FPToSIInst
+ virtual FPToSIInst *clone_impl() const;
+
public:
/// @brief Constructor with insert-before-instruction semantics
FPToSIInst(
BasicBlock *InsertAtEnd ///< The block to insert the instruction into
);
- /// @brief Clone an identical FPToSIInst
- virtual FPToSIInst *clone() const;
-
/// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const FPToSIInst *) { return true; }
static inline bool classof(const Instruction *I) {
);
/// @brief Clone an identical IntToPtrInst
- virtual IntToPtrInst *clone() const;
+ virtual IntToPtrInst *clone_impl() const;
// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const IntToPtrInst *) { return true; }
/// @brief This class represents a cast from a pointer to an integer
class PtrToIntInst : public CastInst {
+protected:
+ /// @brief Clone an identical PtrToIntInst
+ virtual PtrToIntInst *clone_impl() const;
+
public:
/// @brief Constructor with insert-before-instruction semantics
PtrToIntInst(
BasicBlock *InsertAtEnd ///< The block to insert the instruction into
);
- /// @brief Clone an identical PtrToIntInst
- virtual PtrToIntInst *clone() const;
-
// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const PtrToIntInst *) { return true; }
static inline bool classof(const Instruction *I) {
/// @brief This class represents a no-op cast from one type to another.
class BitCastInst : public CastInst {
+protected:
+ /// @brief Clone an identical BitCastInst
+ virtual BitCastInst *clone_impl() const;
+
public:
/// @brief Constructor with insert-before-instruction semantics
BitCastInst(
BasicBlock *InsertAtEnd ///< The block to insert the instruction into
);
- /// @brief Clone an identical BitCastInst
- virtual BitCastInst *clone() const;
-
// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const BitCastInst *) { return true; }
static inline bool classof(const Instruction *I) {
if (NumPreds != 1) {
// Clone the PHI and delete the original one. This lets IVUsers and
// any other maps purge the original user from their records.
- PHINode *NewPN = PN->clone();
+ PHINode *NewPN = cast<PHINode>(PN->clone());
NewPN->takeName(PN);
NewPN->insertBefore(PN);
PN->replaceAllUsesWith(NewPN);
if (I != I->getParent()->begin()) {
BasicBlock::iterator BBI = I; --BBI;
if (DbgStopPointInst *DSPI = dyn_cast<DbgStopPointInst>(BBI)) {
- CallInst *newDSPI = DSPI->clone();
+ CallInst *newDSPI = cast<CallInst>(DSPI->clone());
newDSPI->insertBefore(InsertPos);
}
}
return false; // Misc instructions which have effects
}
}
+
+Instruction *Instruction::clone() const {
+ Instruction *New = clone_impl();
+ New->SubclassOptionalData = SubclassOptionalData;
+ if (hasMetadata())
+ getContext().pImpl->TheMetadata.ValueIsCloned(this, New);
+ return New;
+}
}
//===----------------------------------------------------------------------===//
-// clone() implementations
+// clone_impl() implementations
//===----------------------------------------------------------------------===//
// Define these methods here so vtables don't get emitted into every translation
// unit that uses these classes.
-GetElementPtrInst *GetElementPtrInst::clone() const {
- GetElementPtrInst *New = new(getNumOperands()) GetElementPtrInst(*this);
- New->SubclassOptionalData = SubclassOptionalData;
- if (hasMetadata()) {
- LLVMContext &Context = getContext();
- Context.pImpl->TheMetadata.ValueIsCloned(this, New);
- }
- return New;
+GetElementPtrInst *GetElementPtrInst::clone_impl() const {
+ return new (getNumOperands()) GetElementPtrInst(*this);
}
-BinaryOperator *BinaryOperator::clone() const {
- BinaryOperator *New = Create(getOpcode(), Op<0>(), Op<1>());
- New->SubclassOptionalData = SubclassOptionalData;
- if (hasMetadata()) {
- LLVMContext &Context = getContext();
- Context.pImpl->TheMetadata.ValueIsCloned(this, New);
- }
- return New;
+BinaryOperator *BinaryOperator::clone_impl() const {
+ return Create(getOpcode(), Op<0>(), Op<1>());
}
-FCmpInst* FCmpInst::clone() const {
- FCmpInst *New = new FCmpInst(getPredicate(), Op<0>(), Op<1>());
- New->SubclassOptionalData = SubclassOptionalData;
- if (hasMetadata()) {
- LLVMContext &Context = getContext();
- Context.pImpl->TheMetadata.ValueIsCloned(this, New);
- }
- return New;
-}
-ICmpInst* ICmpInst::clone() const {
- ICmpInst *New = new ICmpInst(getPredicate(), Op<0>(), Op<1>());
- New->SubclassOptionalData = SubclassOptionalData;
- if (hasMetadata()) {
- LLVMContext &Context = getContext();
- Context.pImpl->TheMetadata.ValueIsCloned(this, New);
- }
- return New;
+FCmpInst* FCmpInst::clone_impl() const {
+ return new FCmpInst(getPredicate(), Op<0>(), Op<1>());
}
-ExtractValueInst *ExtractValueInst::clone() const {
- ExtractValueInst *New = new ExtractValueInst(*this);
- New->SubclassOptionalData = SubclassOptionalData;
- if (hasMetadata()) {
- LLVMContext &Context = getContext();
- Context.pImpl->TheMetadata.ValueIsCloned(this, New);
- }
- return New;
-}
-InsertValueInst *InsertValueInst::clone() const {
- InsertValueInst *New = new InsertValueInst(*this);
- New->SubclassOptionalData = SubclassOptionalData;
- if (hasMetadata()) {
- LLVMContext &Context = getContext();
- Context.pImpl->TheMetadata.ValueIsCloned(this, New);
- }
- return New;
+ICmpInst* ICmpInst::clone_impl() const {
+ return new ICmpInst(getPredicate(), Op<0>(), Op<1>());
}
-AllocaInst *AllocaInst::clone() const {
- AllocaInst *New = new AllocaInst(getAllocatedType(),
- (Value*)getOperand(0),
- getAlignment());
- New->SubclassOptionalData = SubclassOptionalData;
- if (hasMetadata()) {
- LLVMContext &Context = getContext();
- Context.pImpl->TheMetadata.ValueIsCloned(this, New);
- }
- return New;
+ExtractValueInst *ExtractValueInst::clone_impl() const {
+ return new ExtractValueInst(*this);
}
-LoadInst *LoadInst::clone() const {
- LoadInst *New = new LoadInst(getOperand(0),
- Twine(), isVolatile(),
- getAlignment());
- New->SubclassOptionalData = SubclassOptionalData;
- if (hasMetadata()) {
- LLVMContext &Context = getContext();
- Context.pImpl->TheMetadata.ValueIsCloned(this, New);
- }
- return New;
+InsertValueInst *InsertValueInst::clone_impl() const {
+ return new InsertValueInst(*this);
}
-StoreInst *StoreInst::clone() const {
- StoreInst *New = new StoreInst(getOperand(0), getOperand(1),
- isVolatile(), getAlignment());
- New->SubclassOptionalData = SubclassOptionalData;
- if (hasMetadata()) {
- LLVMContext &Context = getContext();
- Context.pImpl->TheMetadata.ValueIsCloned(this, New);
- }
- return New;
+AllocaInst *AllocaInst::clone_impl() const {
+ return new AllocaInst(getAllocatedType(),
+ (Value*)getOperand(0),
+ getAlignment());
}
-TruncInst *TruncInst::clone() const {
- TruncInst *New = new TruncInst(getOperand(0), getType());
- New->SubclassOptionalData = SubclassOptionalData;
- if (hasMetadata()) {
- LLVMContext &Context = getContext();
- Context.pImpl->TheMetadata.ValueIsCloned(this, New);
- }
- return New;
+LoadInst *LoadInst::clone_impl() const {
+ return new LoadInst(getOperand(0),
+ Twine(), isVolatile(),
+ getAlignment());
}
-ZExtInst *ZExtInst::clone() const {
- ZExtInst *New = new ZExtInst(getOperand(0), getType());
- New->SubclassOptionalData = SubclassOptionalData;
- if (hasMetadata()) {
- LLVMContext &Context = getContext();
- Context.pImpl->TheMetadata.ValueIsCloned(this, New);
- }
- return New;
+StoreInst *StoreInst::clone_impl() const {
+ return new StoreInst(getOperand(0), getOperand(1),
+ isVolatile(), getAlignment());
}
-SExtInst *SExtInst::clone() const {
- SExtInst *New = new SExtInst(getOperand(0), getType());
- New->SubclassOptionalData = SubclassOptionalData;
- if (hasMetadata()) {
- LLVMContext &Context = getContext();
- Context.pImpl->TheMetadata.ValueIsCloned(this, New);
- }
- return New;
+TruncInst *TruncInst::clone_impl() const {
+ return new TruncInst(getOperand(0), getType());
}
-FPTruncInst *FPTruncInst::clone() const {
- FPTruncInst *New = new FPTruncInst(getOperand(0), getType());
- New->SubclassOptionalData = SubclassOptionalData;
- if (hasMetadata()) {
- LLVMContext &Context = getContext();
- Context.pImpl->TheMetadata.ValueIsCloned(this, New);
- }
- return New;
+ZExtInst *ZExtInst::clone_impl() const {
+ return new ZExtInst(getOperand(0), getType());
}
-FPExtInst *FPExtInst::clone() const {
- FPExtInst *New = new FPExtInst(getOperand(0), getType());
- New->SubclassOptionalData = SubclassOptionalData;
- if (hasMetadata()) {
- LLVMContext &Context = getContext();
- Context.pImpl->TheMetadata.ValueIsCloned(this, New);
- }
- return New;
+SExtInst *SExtInst::clone_impl() const {
+ return new SExtInst(getOperand(0), getType());
}
-UIToFPInst *UIToFPInst::clone() const {
- UIToFPInst *New = new UIToFPInst(getOperand(0), getType());
- New->SubclassOptionalData = SubclassOptionalData;
- if (hasMetadata()) {
- LLVMContext &Context = getContext();
- Context.pImpl->TheMetadata.ValueIsCloned(this, New);
- }
- return New;
+FPTruncInst *FPTruncInst::clone_impl() const {
+ return new FPTruncInst(getOperand(0), getType());
}
-SIToFPInst *SIToFPInst::clone() const {
- SIToFPInst *New = new SIToFPInst(getOperand(0), getType());
- New->SubclassOptionalData = SubclassOptionalData;
- if (hasMetadata()) {
- LLVMContext &Context = getContext();
- Context.pImpl->TheMetadata.ValueIsCloned(this, New);
- }
- return New;
+FPExtInst *FPExtInst::clone_impl() const {
+ return new FPExtInst(getOperand(0), getType());
}
-FPToUIInst *FPToUIInst::clone() const {
- FPToUIInst *New = new FPToUIInst(getOperand(0), getType());
- New->SubclassOptionalData = SubclassOptionalData;
- if (hasMetadata()) {
- LLVMContext &Context = getContext();
- Context.pImpl->TheMetadata.ValueIsCloned(this, New);
- }
- return New;
+UIToFPInst *UIToFPInst::clone_impl() const {
+ return new UIToFPInst(getOperand(0), getType());
}
-FPToSIInst *FPToSIInst::clone() const {
- FPToSIInst *New = new FPToSIInst(getOperand(0), getType());
- New->SubclassOptionalData = SubclassOptionalData;
- if (hasMetadata()) {
- LLVMContext &Context = getContext();
- Context.pImpl->TheMetadata.ValueIsCloned(this, New);
- }
- return New;
+SIToFPInst *SIToFPInst::clone_impl() const {
+ return new SIToFPInst(getOperand(0), getType());
}
-PtrToIntInst *PtrToIntInst::clone() const {
- PtrToIntInst *New = new PtrToIntInst(getOperand(0), getType());
- New->SubclassOptionalData = SubclassOptionalData;
- if (hasMetadata()) {
- LLVMContext &Context = getContext();
- Context.pImpl->TheMetadata.ValueIsCloned(this, New);
- }
- return New;
+FPToUIInst *FPToUIInst::clone_impl() const {
+ return new FPToUIInst(getOperand(0), getType());
}
-IntToPtrInst *IntToPtrInst::clone() const {
- IntToPtrInst *New = new IntToPtrInst(getOperand(0), getType());
- New->SubclassOptionalData = SubclassOptionalData;
- if (hasMetadata()) {
- LLVMContext &Context = getContext();
- Context.pImpl->TheMetadata.ValueIsCloned(this, New);
- }
- return New;
+FPToSIInst *FPToSIInst::clone_impl() const {
+ return new FPToSIInst(getOperand(0), getType());
}
-BitCastInst *BitCastInst::clone() const {
- BitCastInst *New = new BitCastInst(getOperand(0), getType());
- New->SubclassOptionalData = SubclassOptionalData;
- if (hasMetadata()) {
- LLVMContext &Context = getContext();
- Context.pImpl->TheMetadata.ValueIsCloned(this, New);
- }
- return New;
+PtrToIntInst *PtrToIntInst::clone_impl() const {
+ return new PtrToIntInst(getOperand(0), getType());
}
-CallInst *CallInst::clone() const {
- CallInst *New = new(getNumOperands()) CallInst(*this);
- New->SubclassOptionalData = SubclassOptionalData;
- if (hasMetadata()) {
- LLVMContext &Context = getContext();
- Context.pImpl->TheMetadata.ValueIsCloned(this, New);
- }
- return New;
+IntToPtrInst *IntToPtrInst::clone_impl() const {
+ return new IntToPtrInst(getOperand(0), getType());
}
-SelectInst *SelectInst::clone() const {
- SelectInst *New = SelectInst::Create(getOperand(0),
- getOperand(1),
- getOperand(2));
- New->SubclassOptionalData = SubclassOptionalData;
- if (hasMetadata()) {
- LLVMContext &Context = getContext();
- Context.pImpl->TheMetadata.ValueIsCloned(this, New);
- }
- return New;
+BitCastInst *BitCastInst::clone_impl() const {
+ return new BitCastInst(getOperand(0), getType());
}
-VAArgInst *VAArgInst::clone() const {
- VAArgInst *New = new VAArgInst(getOperand(0), getType());
- New->SubclassOptionalData = SubclassOptionalData;
- if (hasMetadata()) {
- LLVMContext &Context = getContext();
- Context.pImpl->TheMetadata.ValueIsCloned(this, New);
- }
- return New;
+CallInst *CallInst::clone_impl() const {
+ return new(getNumOperands()) CallInst(*this);
}
-ExtractElementInst *ExtractElementInst::clone() const {
- ExtractElementInst *New = ExtractElementInst::Create(getOperand(0),
- getOperand(1));
- New->SubclassOptionalData = SubclassOptionalData;
- if (hasMetadata()) {
- LLVMContext &Context = getContext();
- Context.pImpl->TheMetadata.ValueIsCloned(this, New);
- }
- return New;
+SelectInst *SelectInst::clone_impl() const {
+ return SelectInst::Create(getOperand(0), getOperand(1), getOperand(2));
}
-InsertElementInst *InsertElementInst::clone() const {
- InsertElementInst *New = InsertElementInst::Create(getOperand(0),
- getOperand(1),
- getOperand(2));
- New->SubclassOptionalData = SubclassOptionalData;
- if (hasMetadata()) {
- LLVMContext &Context = getContext();
- Context.pImpl->TheMetadata.ValueIsCloned(this, New);
- }
- return New;
+VAArgInst *VAArgInst::clone_impl() const {
+ return new VAArgInst(getOperand(0), getType());
}
-ShuffleVectorInst *ShuffleVectorInst::clone() const {
- ShuffleVectorInst *New = new ShuffleVectorInst(getOperand(0),
- getOperand(1),
- getOperand(2));
- New->SubclassOptionalData = SubclassOptionalData;
- if (hasMetadata()) {
- LLVMContext &Context = getContext();
- Context.pImpl->TheMetadata.ValueIsCloned(this, New);
- }
- return New;
+ExtractElementInst *ExtractElementInst::clone_impl() const {
+ return ExtractElementInst::Create(getOperand(0), getOperand(1));
}
-PHINode *PHINode::clone() const {
- PHINode *New = new PHINode(*this);
- New->SubclassOptionalData = SubclassOptionalData;
- if (hasMetadata()) {
- LLVMContext &Context = getContext();
- Context.pImpl->TheMetadata.ValueIsCloned(this, New);
- }
- return New;
+InsertElementInst *InsertElementInst::clone_impl() const {
+ return InsertElementInst::Create(getOperand(0),
+ getOperand(1),
+ getOperand(2));
}
-ReturnInst *ReturnInst::clone() const {
- ReturnInst *New = new(getNumOperands()) ReturnInst(*this);
- New->SubclassOptionalData = SubclassOptionalData;
- if (hasMetadata()) {
- LLVMContext &Context = getContext();
- Context.pImpl->TheMetadata.ValueIsCloned(this, New);
- }
- return New;
+ShuffleVectorInst *ShuffleVectorInst::clone_impl() const {
+ return new ShuffleVectorInst(getOperand(0),
+ getOperand(1),
+ getOperand(2));
}
-BranchInst *BranchInst::clone() const {
+PHINode *PHINode::clone_impl() const {
+ return new PHINode(*this);
+}
+
+ReturnInst *ReturnInst::clone_impl() const {
+ return new(getNumOperands()) ReturnInst(*this);
+}
+
+BranchInst *BranchInst::clone_impl() const {
unsigned Ops(getNumOperands());
- BranchInst *New = new(Ops, Ops == 1) BranchInst(*this);
- New->SubclassOptionalData = SubclassOptionalData;
- if (hasMetadata()) {
- LLVMContext &Context = getContext();
- Context.pImpl->TheMetadata.ValueIsCloned(this, New);
- }
- return New;
+ return new(Ops, Ops == 1) BranchInst(*this);
}
-SwitchInst *SwitchInst::clone() const {
- SwitchInst *New = new SwitchInst(*this);
- New->SubclassOptionalData = SubclassOptionalData;
- if (hasMetadata()) {
- LLVMContext &Context = getContext();
- Context.pImpl->TheMetadata.ValueIsCloned(this, New);
- }
- return New;
+SwitchInst *SwitchInst::clone_impl() const {
+ return new SwitchInst(*this);
}
-IndBrInst *IndBrInst::clone() const {
- IndBrInst *New = new IndBrInst(*this);
- New->SubclassOptionalData = SubclassOptionalData;
- if (hasMetadata())
- getContext().pImpl->TheMetadata.ValueIsCloned(this, New);
- return New;
+IndBrInst *IndBrInst::clone_impl() const {
+ return new IndBrInst(*this);
}
-InvokeInst *InvokeInst::clone() const {
- InvokeInst *New = new(getNumOperands()) InvokeInst(*this);
- New->SubclassOptionalData = SubclassOptionalData;
- if (hasMetadata()) {
- LLVMContext &Context = getContext();
- Context.pImpl->TheMetadata.ValueIsCloned(this, New);
- }
- return New;
+InvokeInst *InvokeInst::clone_impl() const {
+ return new(getNumOperands()) InvokeInst(*this);
}
-UnwindInst *UnwindInst::clone() const {
+UnwindInst *UnwindInst::clone_impl() const {
LLVMContext &Context = getContext();
- UnwindInst *New = new UnwindInst(Context);
- New->SubclassOptionalData = SubclassOptionalData;
- if (hasMetadata())
- Context.pImpl->TheMetadata.ValueIsCloned(this, New);
- return New;
+ return new UnwindInst(Context);
}
-UnreachableInst *UnreachableInst::clone() const {
+UnreachableInst *UnreachableInst::clone_impl() const {
LLVMContext &Context = getContext();
- UnreachableInst *New = new UnreachableInst(Context);
- New->SubclassOptionalData = SubclassOptionalData;
- if (hasMetadata())
- Context.pImpl->TheMetadata.ValueIsCloned(this, New);
- return New;
+ return new UnreachableInst(Context);
}
BinaryOperator *Sub = BinaryOperator::Create(Instruction::Sub, V, V);
BinaryOperator *Mul = BinaryOperator::Create(Instruction::Mul, V, V);
- EXPECT_FALSE(Add->clone()->hasNoUnsignedWrap());
- EXPECT_FALSE(Add->clone()->hasNoSignedWrap());
- EXPECT_FALSE(Sub->clone()->hasNoUnsignedWrap());
- EXPECT_FALSE(Sub->clone()->hasNoSignedWrap());
- EXPECT_FALSE(Mul->clone()->hasNoUnsignedWrap());
- EXPECT_FALSE(Mul->clone()->hasNoSignedWrap());
+ EXPECT_FALSE(cast<BinaryOperator>(Add->clone())->hasNoUnsignedWrap());
+ EXPECT_FALSE(cast<BinaryOperator>(Add->clone())->hasNoSignedWrap());
+ EXPECT_FALSE(cast<BinaryOperator>(Sub->clone())->hasNoUnsignedWrap());
+ EXPECT_FALSE(cast<BinaryOperator>(Sub->clone())->hasNoSignedWrap());
+ EXPECT_FALSE(cast<BinaryOperator>(Mul->clone())->hasNoUnsignedWrap());
+ EXPECT_FALSE(cast<BinaryOperator>(Mul->clone())->hasNoSignedWrap());
Add->setHasNoUnsignedWrap();
Sub->setHasNoUnsignedWrap();
Mul->setHasNoUnsignedWrap();
- EXPECT_TRUE(Add->clone()->hasNoUnsignedWrap());
- EXPECT_FALSE(Add->clone()->hasNoSignedWrap());
- EXPECT_TRUE(Sub->clone()->hasNoUnsignedWrap());
- EXPECT_FALSE(Sub->clone()->hasNoSignedWrap());
- EXPECT_TRUE(Mul->clone()->hasNoUnsignedWrap());
- EXPECT_FALSE(Mul->clone()->hasNoSignedWrap());
+ EXPECT_TRUE(cast<BinaryOperator>(Add->clone())->hasNoUnsignedWrap());
+ EXPECT_FALSE(cast<BinaryOperator>(Add->clone())->hasNoSignedWrap());
+ EXPECT_TRUE(cast<BinaryOperator>(Sub->clone())->hasNoUnsignedWrap());
+ EXPECT_FALSE(cast<BinaryOperator>(Sub->clone())->hasNoSignedWrap());
+ EXPECT_TRUE(cast<BinaryOperator>(Mul->clone())->hasNoUnsignedWrap());
+ EXPECT_FALSE(cast<BinaryOperator>(Mul->clone())->hasNoSignedWrap());
Add->setHasNoSignedWrap();
Sub->setHasNoSignedWrap();
Mul->setHasNoSignedWrap();
- EXPECT_TRUE(Add->clone()->hasNoUnsignedWrap());
- EXPECT_TRUE(Add->clone()->hasNoSignedWrap());
- EXPECT_TRUE(Sub->clone()->hasNoUnsignedWrap());
- EXPECT_TRUE(Sub->clone()->hasNoSignedWrap());
- EXPECT_TRUE(Mul->clone()->hasNoUnsignedWrap());
- EXPECT_TRUE(Mul->clone()->hasNoSignedWrap());
+ EXPECT_TRUE(cast<BinaryOperator>(Add->clone())->hasNoUnsignedWrap());
+ EXPECT_TRUE(cast<BinaryOperator>(Add->clone())->hasNoSignedWrap());
+ EXPECT_TRUE(cast<BinaryOperator>(Sub->clone())->hasNoUnsignedWrap());
+ EXPECT_TRUE(cast<BinaryOperator>(Sub->clone())->hasNoSignedWrap());
+ EXPECT_TRUE(cast<BinaryOperator>(Mul->clone())->hasNoUnsignedWrap());
+ EXPECT_TRUE(cast<BinaryOperator>(Mul->clone())->hasNoSignedWrap());
Add->setHasNoUnsignedWrap(false);
Sub->setHasNoUnsignedWrap(false);
Mul->setHasNoUnsignedWrap(false);
- EXPECT_FALSE(Add->clone()->hasNoUnsignedWrap());
- EXPECT_TRUE(Add->clone()->hasNoSignedWrap());
- EXPECT_FALSE(Sub->clone()->hasNoUnsignedWrap());
- EXPECT_TRUE(Sub->clone()->hasNoSignedWrap());
- EXPECT_FALSE(Mul->clone()->hasNoUnsignedWrap());
- EXPECT_TRUE(Mul->clone()->hasNoSignedWrap());
+ EXPECT_FALSE(cast<BinaryOperator>(Add->clone())->hasNoUnsignedWrap());
+ EXPECT_TRUE(cast<BinaryOperator>(Add->clone())->hasNoSignedWrap());
+ EXPECT_FALSE(cast<BinaryOperator>(Sub->clone())->hasNoUnsignedWrap());
+ EXPECT_TRUE(cast<BinaryOperator>(Sub->clone())->hasNoSignedWrap());
+ EXPECT_FALSE(cast<BinaryOperator>(Mul->clone())->hasNoUnsignedWrap());
+ EXPECT_TRUE(cast<BinaryOperator>(Mul->clone())->hasNoSignedWrap());
}
TEST(CloneInstruction, Inbounds) {
std::vector<Value *> ops;
ops.push_back(Z);
GetElementPtrInst *GEP = GetElementPtrInst::Create(V, ops.begin(), ops.end());
- EXPECT_FALSE(GEP->clone()->isInBounds());
+ EXPECT_FALSE(cast<GetElementPtrInst>(GEP->clone())->isInBounds());
GEP->setIsInBounds();
- EXPECT_TRUE(GEP->clone()->isInBounds());
+ EXPECT_TRUE(cast<GetElementPtrInst>(GEP->clone())->isInBounds());
}
TEST(CloneInstruction, Exact) {
Value *V = new Argument(Type::getInt32Ty(context));
BinaryOperator *SDiv = BinaryOperator::Create(Instruction::SDiv, V, V);
- EXPECT_FALSE(SDiv->clone()->isExact());
+ EXPECT_FALSE(cast<BinaryOperator>(SDiv->clone())->isExact());
SDiv->setIsExact(true);
- EXPECT_TRUE(SDiv->clone()->isExact());
+ EXPECT_TRUE(cast<BinaryOperator>(SDiv->clone())->isExact());
}