//
//===----------------------------------------------------------------------===//
+#include "LLVMContextImpl.h"
#include "llvm/Constants.h"
#include "llvm/DerivedTypes.h"
#include "llvm/Function.h"
#include "llvm/Support/CallSite.h"
#include "llvm/Support/ConstantRange.h"
#include "llvm/Support/MathExtras.h"
+
using namespace llvm;
//===----------------------------------------------------------------------===//
// Create the call to Malloc.
BasicBlock* BB = InsertBefore ? InsertBefore->getParent() : InsertAtEnd;
Module* M = BB->getParent()->getParent();
- const Type *BPTy = PointerType::getUnqual(Type::getInt8Ty(BB->getContext()));
+ const Type *BPTy = Type::getInt8PtrTy(BB->getContext());
// prototype malloc as "void *malloc(size_t)"
Constant *MallocF = M->getOrInsertFunction("malloc", BPTy, IntPtrTy, NULL);
if (!cast<Function>(MallocF)->doesNotAlias(0))
cast<GEPOperator>(this)->setIsInBounds(B);
}
+bool GetElementPtrInst::isInBounds() const {
+ return cast<GEPOperator>(this)->isInBounds();
+}
+
//===----------------------------------------------------------------------===//
// ExtractElementInst Implementation
//===----------------------------------------------------------------------===//
cast<SDivOperator>(this)->setIsExact(b);
}
+bool BinaryOperator::hasNoUnsignedWrap() const {
+ return cast<OverflowingBinaryOperator>(this)->hasNoUnsignedWrap();
+}
+
+bool BinaryOperator::hasNoSignedWrap() const {
+ return cast<OverflowingBinaryOperator>(this)->hasNoSignedWrap();
+}
+
+bool BinaryOperator::isExact() const {
+ return cast<SDivOperator>(this)->isExact();
+}
+
//===----------------------------------------------------------------------===//
// CastInst Class
//===----------------------------------------------------------------------===//
// Define these methods here so vtables don't get emitted into every translation
// unit that uses these classes.
-GetElementPtrInst *GetElementPtrInst::clone(LLVMContext&) const {
+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;
}
-BinaryOperator *BinaryOperator::clone(LLVMContext&) const {
+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;
}
-FCmpInst* FCmpInst::clone(LLVMContext &Context) const {
+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(LLVMContext &Context) const {
+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;
}
-ExtractValueInst *ExtractValueInst::clone(LLVMContext&) const {
+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(LLVMContext&) const {
+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;
}
-MallocInst *MallocInst::clone(LLVMContext&) const {
+MallocInst *MallocInst::clone() const {
MallocInst *New = new MallocInst(getAllocatedType(),
(Value*)getOperand(0),
getAlignment());
New->SubclassOptionalData = SubclassOptionalData;
+ if (hasMetadata()) {
+ LLVMContext &Context = getContext();
+ Context.pImpl->TheMetadata.ValueIsCloned(this, New);
+ }
return New;
}
-AllocaInst *AllocaInst::clone(LLVMContext&) const {
+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;
}
-FreeInst *FreeInst::clone(LLVMContext&) const {
+FreeInst *FreeInst::clone() const {
FreeInst *New = new FreeInst(getOperand(0));
New->SubclassOptionalData = SubclassOptionalData;
+ if (hasMetadata()) {
+ LLVMContext &Context = getContext();
+ Context.pImpl->TheMetadata.ValueIsCloned(this, New);
+ }
return New;
}
-LoadInst *LoadInst::clone(LLVMContext&) const {
+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;
}
-StoreInst *StoreInst::clone(LLVMContext&) const {
+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;
}
-TruncInst *TruncInst::clone(LLVMContext&) const {
+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;
}
-ZExtInst *ZExtInst::clone(LLVMContext&) const {
+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;
}
-SExtInst *SExtInst::clone(LLVMContext&) const {
+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;
}
-FPTruncInst *FPTruncInst::clone(LLVMContext&) const {
+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;
}
-FPExtInst *FPExtInst::clone(LLVMContext&) const {
+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;
}
-UIToFPInst *UIToFPInst::clone(LLVMContext&) const {
+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;
}
-SIToFPInst *SIToFPInst::clone(LLVMContext&) const {
+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;
}
-FPToUIInst *FPToUIInst::clone(LLVMContext&) const {
+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;
}
-FPToSIInst *FPToSIInst::clone(LLVMContext&) const {
+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;
}
-PtrToIntInst *PtrToIntInst::clone(LLVMContext&) const {
+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;
}
-IntToPtrInst *IntToPtrInst::clone(LLVMContext&) const {
+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;
}
-BitCastInst *BitCastInst::clone(LLVMContext&) const {
+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;
}
-CallInst *CallInst::clone(LLVMContext&) const {
+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;
}
-SelectInst *SelectInst::clone(LLVMContext&) const {
+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;
}
-VAArgInst *VAArgInst::clone(LLVMContext&) const {
+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;
}
-ExtractElementInst *ExtractElementInst::clone(LLVMContext&) const {
+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;
}
-InsertElementInst *InsertElementInst::clone(LLVMContext&) const {
+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;
}
-ShuffleVectorInst *ShuffleVectorInst::clone(LLVMContext&) const {
+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;
}
-PHINode *PHINode::clone(LLVMContext&) const {
+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;
}
-ReturnInst *ReturnInst::clone(LLVMContext&) const {
+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;
}
-BranchInst *BranchInst::clone(LLVMContext&) const {
+BranchInst *BranchInst::clone() 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;
}
-SwitchInst *SwitchInst::clone(LLVMContext&) const {
+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;
}
-InvokeInst *InvokeInst::clone(LLVMContext&) const {
+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;
}
-UnwindInst *UnwindInst::clone(LLVMContext &C) const {
- UnwindInst *New = new UnwindInst(C);
+UnwindInst *UnwindInst::clone() const {
+ LLVMContext &Context = getContext();
+ UnwindInst *New = new UnwindInst(Context);
New->SubclassOptionalData = SubclassOptionalData;
+ if (hasMetadata())
+ Context.pImpl->TheMetadata.ValueIsCloned(this, New);
return New;
}
-UnreachableInst *UnreachableInst::clone(LLVMContext &C) const {
- UnreachableInst *New = new UnreachableInst(C);
+UnreachableInst *UnreachableInst::clone() const {
+ LLVMContext &Context = getContext();
+ UnreachableInst *New = new UnreachableInst(Context);
New->SubclassOptionalData = SubclassOptionalData;
+ if (hasMetadata())
+ Context.pImpl->TheMetadata.ValueIsCloned(this, New);
return New;
}