//
//===----------------------------------------------------------------------===//
-#include "llvm/BasicBlock.h"
#include "llvm/Constants.h"
#include "llvm/DerivedTypes.h"
#include "llvm/Function.h"
else
cast<InvokeInst>(I)->setCallingConv(CC);
}
-const PAListPtr &CallSite::getParamAttrs() const {
+const AttrListPtr &CallSite::getAttributes() const {
if (CallInst *CI = dyn_cast<CallInst>(I))
- return CI->getParamAttrs();
+ return CI->getAttributes();
else
- return cast<InvokeInst>(I)->getParamAttrs();
+ return cast<InvokeInst>(I)->getAttributes();
}
-void CallSite::setParamAttrs(const PAListPtr &PAL) {
+void CallSite::setAttributes(const AttrListPtr &PAL) {
if (CallInst *CI = dyn_cast<CallInst>(I))
- CI->setParamAttrs(PAL);
+ CI->setAttributes(PAL);
else
- cast<InvokeInst>(I)->setParamAttrs(PAL);
+ cast<InvokeInst>(I)->setAttributes(PAL);
}
-bool CallSite::paramHasAttr(uint16_t i, ParameterAttributes attr) const {
+bool CallSite::paramHasAttr(uint16_t i, Attributes attr) const {
if (CallInst *CI = dyn_cast<CallInst>(I))
return CI->paramHasAttr(i, attr);
else
else
return cast<InvokeInst>(I)->doesNotAccessMemory();
}
+void CallSite::setDoesNotAccessMemory(bool doesNotAccessMemory) {
+ if (CallInst *CI = dyn_cast<CallInst>(I))
+ CI->setDoesNotAccessMemory(doesNotAccessMemory);
+ else
+ cast<InvokeInst>(I)->setDoesNotAccessMemory(doesNotAccessMemory);
+}
bool CallSite::onlyReadsMemory() const {
if (CallInst *CI = dyn_cast<CallInst>(I))
return CI->onlyReadsMemory();
else
return cast<InvokeInst>(I)->onlyReadsMemory();
}
+void CallSite::setOnlyReadsMemory(bool onlyReadsMemory) {
+ if (CallInst *CI = dyn_cast<CallInst>(I))
+ CI->setOnlyReadsMemory(onlyReadsMemory);
+ else
+ cast<InvokeInst>(I)->setOnlyReadsMemory(onlyReadsMemory);
+}
+bool CallSite::doesNotReturn() const {
+ if (CallInst *CI = dyn_cast<CallInst>(I))
+ return CI->doesNotReturn();
+ else
+ return cast<InvokeInst>(I)->doesNotReturn();
+}
+void CallSite::setDoesNotReturn(bool doesNotReturn) {
+ if (CallInst *CI = dyn_cast<CallInst>(I))
+ CI->setDoesNotReturn(doesNotReturn);
+ else
+ cast<InvokeInst>(I)->setDoesNotReturn(doesNotReturn);
+}
bool CallSite::doesNotThrow() const {
if (CallInst *CI = dyn_cast<CallInst>(I))
return CI->doesNotThrow();
cast<InvokeInst>(I)->setDoesNotThrow(doesNotThrow);
}
+bool CallSite::hasArgument(const Value *Arg) const {
+ for (arg_iterator AI = this->arg_begin(), E = this->arg_end(); AI != E; ++AI)
+ if (AI->get() == Arg)
+ return true;
+ return false;
+}
+
//===----------------------------------------------------------------------===//
// TerminatorInst Class
//===----------------------------------------------------------------------===//
UnaryInstruction::~UnaryInstruction() {
}
+//===----------------------------------------------------------------------===//
+// SelectInst Class
+//===----------------------------------------------------------------------===//
+
+/// areInvalidOperands - Return a string if the specified operands are invalid
+/// for a select operation, otherwise return null.
+const char *SelectInst::areInvalidOperands(Value *Op0, Value *Op1, Value *Op2) {
+ if (Op1->getType() != Op2->getType())
+ return "both values to select must have same type";
+
+ if (const VectorType *VT = dyn_cast<VectorType>(Op0->getType())) {
+ // Vector select.
+ if (VT->getElementType() != Type::Int1Ty)
+ return "vector select condition element type must be i1";
+ const VectorType *ET = dyn_cast<VectorType>(Op1->getType());
+ if (ET == 0)
+ return "selected values for vector select must be vectors";
+ if (ET->getNumElements() != VT->getNumElements())
+ return "vector select requires selected vectors to have "
+ "the same vector length as select condition";
+ } else if (Op0->getType() != Type::Int1Ty) {
+ return "select condition must be i1 or <n x i1>";
+ }
+ return 0;
+}
+
+
//===----------------------------------------------------------------------===//
// PHINode Class
//===----------------------------------------------------------------------===//
}
PHINode::~PHINode() {
- dropHungoffUses(OperandList);
+ if (OperandList)
+ dropHungoffUses(OperandList);
}
// removeIncomingValue - Remove an incoming value. This is useful if a
ReservedSpace = NumOps;
Use *OldOps = OperandList;
Use *NewOps = allocHungoffUses(NumOps);
- for (unsigned i = 0; i != e; ++i) {
- NewOps[i] = OldOps[i];
- }
+ std::copy(OldOps, OldOps + e, NewOps);
OperandList = NewOps;
if (OldOps) Use::zap(OldOps, OldOps + e, true);
}
: Instruction(CI.getType(), Instruction::Call,
OperandTraits<CallInst>::op_end(this) - CI.getNumOperands(),
CI.getNumOperands()) {
- setParamAttrs(CI.getParamAttrs());
+ setAttributes(CI.getAttributes());
SubclassData = CI.SubclassData;
Use *OL = OperandList;
Use *InOL = CI.OperandList;
OL[i] = InOL[i];
}
-void CallInst::addParamAttr(unsigned i, ParameterAttributes attr) {
- PAListPtr PAL = getParamAttrs();
+void CallInst::addAttribute(unsigned i, Attributes attr) {
+ AttrListPtr PAL = getAttributes();
PAL = PAL.addAttr(i, attr);
- setParamAttrs(PAL);
+ setAttributes(PAL);
}
-bool CallInst::paramHasAttr(unsigned i, ParameterAttributes attr) const {
- if (ParamAttrs.paramHasAttr(i, attr))
+void CallInst::removeAttribute(unsigned i, Attributes attr) {
+ AttrListPtr PAL = getAttributes();
+ PAL = PAL.removeAttr(i, attr);
+ setAttributes(PAL);
+}
+
+bool CallInst::paramHasAttr(unsigned i, Attributes attr) const {
+ if (AttributeList.paramHasAttr(i, attr))
return true;
if (const Function *F = getCalledFunction())
return F->paramHasAttr(i, attr);
return false;
}
-void CallInst::setDoesNotThrow(bool doesNotThrow) {
- PAListPtr PAL = getParamAttrs();
- if (doesNotThrow)
- PAL = PAL.addAttr(0, ParamAttr::NoUnwind);
- else
- PAL = PAL.removeAttr(0, ParamAttr::NoUnwind);
- setParamAttrs(PAL);
-}
-
//===----------------------------------------------------------------------===//
// InvokeInst Implementation
OperandTraits<InvokeInst>::op_end(this)
- II.getNumOperands(),
II.getNumOperands()) {
- setParamAttrs(II.getParamAttrs());
+ setAttributes(II.getAttributes());
SubclassData = II.SubclassData;
Use *OL = OperandList, *InOL = II.OperandList;
for (unsigned i = 0, e = II.getNumOperands(); i != e; ++i)
return setSuccessor(idx, B);
}
-bool InvokeInst::paramHasAttr(unsigned i, ParameterAttributes attr) const {
- if (ParamAttrs.paramHasAttr(i, attr))
+bool InvokeInst::paramHasAttr(unsigned i, Attributes attr) const {
+ if (AttributeList.paramHasAttr(i, attr))
return true;
if (const Function *F = getCalledFunction())
return F->paramHasAttr(i, attr);
return false;
}
-void InvokeInst::addParamAttr(unsigned i, ParameterAttributes attr) {
- PAListPtr PAL = getParamAttrs();
+void InvokeInst::addAttribute(unsigned i, Attributes attr) {
+ AttrListPtr PAL = getAttributes();
PAL = PAL.addAttr(i, attr);
- setParamAttrs(PAL);
+ setAttributes(PAL);
}
-void InvokeInst::setDoesNotThrow(bool doesNotThrow) {
- PAListPtr PAL = getParamAttrs();
- if (doesNotThrow)
- PAL = PAL.addAttr(0, ParamAttr::NoUnwind);
- else
- PAL = PAL.removeAttr(0, ParamAttr::NoUnwind);
- setParamAttrs(PAL);
+void InvokeInst::removeAttribute(unsigned i, Attributes attr) {
+ AttrListPtr PAL = getAttributes();
+ PAL = PAL.removeAttr(i, attr);
+ setAttributes(PAL);
}
ReturnInst::ReturnInst(const ReturnInst &RI)
: TerminatorInst(Type::VoidTy, Instruction::Ret,
- OperandTraits<ReturnInst>::op_end(this)
- - RI.getNumOperands(),
+ OperandTraits<ReturnInst>::op_end(this) -
+ RI.getNumOperands(),
RI.getNumOperands()) {
- unsigned N = RI.getNumOperands();
- if (N == 1)
+ if (RI.getNumOperands())
Op<0>() = RI.Op<0>();
- else if (N) {
- Use *OL = OperandList;
- for (unsigned i = 0; i < N; ++i)
- OL[i] = RI.getOperand(i);
- }
}
ReturnInst::ReturnInst(Value *retVal, Instruction *InsertBefore)
: TerminatorInst(Type::VoidTy, Instruction::Ret,
- OperandTraits<ReturnInst>::op_end(this) - (retVal != 0),
- retVal != 0, InsertBefore) {
+ OperandTraits<ReturnInst>::op_end(this) - !!retVal, !!retVal,
+ InsertBefore) {
if (retVal)
- init(&retVal, 1);
+ Op<0>() = retVal;
}
ReturnInst::ReturnInst(Value *retVal, BasicBlock *InsertAtEnd)
: TerminatorInst(Type::VoidTy, Instruction::Ret,
- OperandTraits<ReturnInst>::op_end(this) - (retVal != 0),
- retVal != 0, InsertAtEnd) {
+ OperandTraits<ReturnInst>::op_end(this) - !!retVal, !!retVal,
+ InsertAtEnd) {
if (retVal)
- init(&retVal, 1);
+ Op<0>() = retVal;
}
ReturnInst::ReturnInst(BasicBlock *InsertAtEnd)
: TerminatorInst(Type::VoidTy, Instruction::Ret,
- OperandTraits<ReturnInst>::op_end(this),
- 0, InsertAtEnd) {
-}
-
-ReturnInst::ReturnInst(Value * const* retVals, unsigned N,
- Instruction *InsertBefore)
- : TerminatorInst(Type::VoidTy, Instruction::Ret,
- OperandTraits<ReturnInst>::op_end(this) - N,
- N, InsertBefore) {
- if (N != 0)
- init(retVals, N);
-}
-ReturnInst::ReturnInst(Value * const* retVals, unsigned N,
- BasicBlock *InsertAtEnd)
- : TerminatorInst(Type::VoidTy, Instruction::Ret,
- OperandTraits<ReturnInst>::op_end(this) - N,
- N, InsertAtEnd) {
- if (N != 0)
- init(retVals, N);
-}
-
-void ReturnInst::init(Value * const* retVals, unsigned N) {
- assert (N > 0 && "Invalid operands numbers in ReturnInst init");
-
- NumOperands = N;
- if (NumOperands == 1) {
- Value *V = *retVals;
- if (V->getType() == Type::VoidTy)
- return;
- Op<0>() = V;
- return;
- }
-
- Use *OL = OperandList;
- for (unsigned i = 0; i < NumOperands; ++i) {
- Value *V = *retVals++;
- assert(!isa<BasicBlock>(V) &&
- "Cannot return basic block. Probably using the incorrect ctor");
- OL[i] = V;
- }
+ OperandTraits<ReturnInst>::op_end(this), 0, InsertAtEnd) {
}
unsigned ReturnInst::getNumSuccessorsV() const {
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.
+bool AllocaInst::isStaticAlloca() const {
+ // Must be constant size.
+ if (!isa<ConstantInt>(getArraySize())) return false;
+
+ // Must be in the entry block.
+ const BasicBlock *Parent = getParent();
+ return Parent == &Parent->getParent()->front();
+}
+
MallocInst::MallocInst(const MallocInst &MI)
: AllocationInst(MI.getType()->getElementType(), (Value*)MI.getOperand(0),
Instruction::Malloc, MI.getAlignment()) {
//===----------------------------------------------------------------------===//
void StoreInst::AssertOK() {
+ assert(getOperand(0) && getOperand(1) && "Both operands must be non-null!");
assert(isa<PointerType>(getOperand(1)->getType()) &&
"Ptr must have pointer type!");
assert(getOperand(0)->getType() ==
return cast<PointerType>(Val->getType())->getAddressSpace();
}
-void GetElementPtrInst::init(Value *Ptr, Value* const *Idx, unsigned NumIdx) {
+void GetElementPtrInst::init(Value *Ptr, Value* const *Idx, unsigned NumIdx,
+ const std::string &Name) {
assert(NumOperands == 1+NumIdx && "NumOperands not initialized?");
Use *OL = OperandList;
OL[0] = Ptr;
for (unsigned i = 0; i != NumIdx; ++i)
OL[i+1] = Idx[i];
+
+ setName(Name);
}
-void GetElementPtrInst::init(Value *Ptr, Value *Idx) {
+void GetElementPtrInst::init(Value *Ptr, Value *Idx, const std::string &Name) {
assert(NumOperands == 2 && "NumOperands not initialized?");
Use *OL = OperandList;
OL[0] = Ptr;
OL[1] = Idx;
+
+ setName(Name);
}
GetElementPtrInst::GetElementPtrInst(const GetElementPtrInst &GEPI)
- : Instruction(reinterpret_cast<const Type*>(GEPI.getType()), GetElementPtr,
+ : Instruction(GEPI.getType(), GetElementPtr,
OperandTraits<GetElementPtrInst>::op_end(this)
- GEPI.getNumOperands(),
GEPI.getNumOperands()) {
GetElementPtr,
OperandTraits<GetElementPtrInst>::op_end(this) - 2,
2, InBe) {
- init(Ptr, Idx);
- setName(Name);
+ init(Ptr, Idx, Name);
}
GetElementPtrInst::GetElementPtrInst(Value *Ptr, Value *Idx,
GetElementPtr,
OperandTraits<GetElementPtrInst>::op_end(this) - 2,
2, IAE) {
- init(Ptr, Idx);
- setName(Name);
+ init(Ptr, Idx, Name);
}
// getIndexedType - Returns the type of the element that would be loaded with
// a load instruction with the specified parameters.
//
+// The Idxs pointer should point to a continuous piece of memory containing the
+// indices, either as Value* or uint64_t.
+//
// A null type is returned if the indices are invalid for the specified
// pointer type.
//
-const Type* GetElementPtrInst::getIndexedType(const Type *Ptr,
- Value* const *Idxs,
- unsigned NumIdx) {
+template <typename IndexTy>
+static const Type* getIndexedTypeInternal(const Type *Ptr,
+ IndexTy const *Idxs,
+ unsigned NumIdx) {
const PointerType *PTy = dyn_cast<PointerType>(Ptr);
if (!PTy) return 0; // Type isn't a pointer type!
const Type *Agg = PTy->getElementType();
if (NumIdx == 0)
return Agg;
- return ExtractValueInst::getIndexedType(Agg, Idxs+1, Idxs+NumIdx);
+ unsigned CurIdx = 1;
+ for (; CurIdx != NumIdx; ++CurIdx) {
+ const CompositeType *CT = dyn_cast<CompositeType>(Agg);
+ if (!CT || isa<PointerType>(CT)) return 0;
+ IndexTy Index = Idxs[CurIdx];
+ if (!CT->indexValid(Index)) return 0;
+ Agg = CT->getTypeAtIndex(Index);
+
+ // If the new type forwards to another type, then it is in the middle
+ // of being refined to another type (and hence, may have dropped all
+ // references to what it was using before). So, use the new forwarded
+ // type.
+ if (const Type *Ty = Agg->getForwardedType())
+ Agg = Ty;
+ }
+ return CurIdx == NumIdx ? Agg : 0;
+}
+
+const Type* GetElementPtrInst::getIndexedType(const Type *Ptr,
+ Value* const *Idxs,
+ unsigned NumIdx) {
+ return getIndexedTypeInternal(Ptr, Idxs, NumIdx);
+}
+
+const Type* GetElementPtrInst::getIndexedType(const Type *Ptr,
+ uint64_t const *Idxs,
+ unsigned NumIdx) {
+ return getIndexedTypeInternal(Ptr, Idxs, NumIdx);
}
const Type* GetElementPtrInst::getIndexedType(const Type *Ptr, Value *Idx) {
ShuffleVectorInst::ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
const std::string &Name,
Instruction *InsertBefore)
- : Instruction(V1->getType(), ShuffleVector,
- OperandTraits<ShuffleVectorInst>::op_begin(this),
- OperandTraits<ShuffleVectorInst>::operands(this),
- InsertBefore) {
+: Instruction(VectorType::get(cast<VectorType>(V1->getType())->getElementType(),
+ cast<VectorType>(Mask->getType())->getNumElements()),
+ ShuffleVector,
+ OperandTraits<ShuffleVectorInst>::op_begin(this),
+ OperandTraits<ShuffleVectorInst>::operands(this),
+ InsertBefore) {
assert(isValidOperands(V1, V2, Mask) &&
"Invalid shuffle vector instruction operands!");
Op<0>() = V1;
}
ShuffleVectorInst::ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
- const std::string &Name,
+ const std::string &Name,
BasicBlock *InsertAtEnd)
: Instruction(V1->getType(), ShuffleVector,
OperandTraits<ShuffleVectorInst>::op_begin(this),
setName(Name);
}
-bool ShuffleVectorInst::isValidOperands(const Value *V1, const Value *V2,
+bool ShuffleVectorInst::isValidOperands(const Value *V1, const Value *V2,
const Value *Mask) {
- if (!isa<VectorType>(V1->getType()) ||
- V1->getType() != V2->getType())
+ if (!isa<VectorType>(V1->getType()) || V1->getType() != V2->getType())
return false;
const VectorType *MaskTy = dyn_cast<VectorType>(Mask->getType());
if (!isa<Constant>(Mask) || MaskTy == 0 ||
- MaskTy->getElementType() != Type::Int32Ty ||
- MaskTy->getNumElements() !=
- cast<VectorType>(V1->getType())->getNumElements())
+ MaskTy->getElementType() != Type::Int32Ty)
return false;
return true;
}
// InsertValueInst Class
//===----------------------------------------------------------------------===//
-void InsertValueInst::init(Value *Agg, Value *Val, Value* const *Idx, unsigned NumIdx) {
- assert(NumOperands == 1+NumIdx && "NumOperands not initialized?");
- Use *OL = OperandList;
- OL[0] = Agg;
- OL[1] = Val;
+void InsertValueInst::init(Value *Agg, Value *Val, const unsigned *Idx,
+ unsigned NumIdx, const std::string &Name) {
+ assert(NumOperands == 2 && "NumOperands not initialized?");
+ Op<0>() = Agg;
+ Op<1>() = Val;
- for (unsigned i = 0; i != NumIdx; ++i)
- OL[i+2] = Idx[i];
+ Indices.insert(Indices.end(), Idx, Idx + NumIdx);
+ setName(Name);
}
-void InsertValueInst::init(Value *Agg, Value *Val, Value *Idx) {
- assert(NumOperands == 3 && "NumOperands not initialized?");
- Use *OL = OperandList;
- OL[0] = Agg;
- OL[1] = Val;
- OL[2] = Idx;
+void InsertValueInst::init(Value *Agg, Value *Val, unsigned Idx,
+ const std::string &Name) {
+ assert(NumOperands == 2 && "NumOperands not initialized?");
+ Op<0>() = Agg;
+ Op<1>() = Val;
+
+ Indices.push_back(Idx);
+ setName(Name);
}
InsertValueInst::InsertValueInst(const InsertValueInst &IVI)
- : Instruction(reinterpret_cast<const Type*>(IVI.getType()), InsertValue,
- OperandTraits<InsertValueInst>::op_end(this)
- - IVI.getNumOperands(),
- IVI.getNumOperands()) {
- Use *OL = OperandList;
- Use *IVIOL = IVI.OperandList;
- for (unsigned i = 0, E = NumOperands; i != E; ++i)
- OL[i] = IVIOL[i];
+ : Instruction(IVI.getType(), InsertValue,
+ OperandTraits<InsertValueInst>::op_begin(this), 2),
+ Indices(IVI.Indices) {
+ Op<0>() = IVI.getOperand(0);
+ Op<1>() = IVI.getOperand(1);
+}
+
+InsertValueInst::InsertValueInst(Value *Agg,
+ Value *Val,
+ unsigned Idx,
+ const std::string &Name,
+ Instruction *InsertBefore)
+ : Instruction(Agg->getType(), InsertValue,
+ OperandTraits<InsertValueInst>::op_begin(this),
+ 2, InsertBefore) {
+ init(Agg, Val, Idx, Name);
+}
+
+InsertValueInst::InsertValueInst(Value *Agg,
+ Value *Val,
+ unsigned Idx,
+ const std::string &Name,
+ BasicBlock *InsertAtEnd)
+ : Instruction(Agg->getType(), InsertValue,
+ OperandTraits<InsertValueInst>::op_begin(this),
+ 2, InsertAtEnd) {
+ init(Agg, Val, Idx, Name);
}
//===----------------------------------------------------------------------===//
// ExtractValueInst Class
//===----------------------------------------------------------------------===//
-void ExtractValueInst::init(Value *Agg, Value* const *Idx, unsigned NumIdx) {
- assert(NumOperands == 1+NumIdx && "NumOperands not initialized?");
- Use *OL = OperandList;
- OL[0] = Agg;
+void ExtractValueInst::init(const unsigned *Idx, unsigned NumIdx,
+ const std::string &Name) {
+ assert(NumOperands == 1 && "NumOperands not initialized?");
- for (unsigned i = 0; i != NumIdx; ++i)
- OL[i+1] = Idx[i];
+ Indices.insert(Indices.end(), Idx, Idx + NumIdx);
+ setName(Name);
}
-void ExtractValueInst::init(Value *Agg, Value *Idx) {
- assert(NumOperands == 2 && "NumOperands not initialized?");
- Use *OL = OperandList;
- OL[0] = Agg;
- OL[1] = Idx;
+void ExtractValueInst::init(unsigned Idx, const std::string &Name) {
+ assert(NumOperands == 1 && "NumOperands not initialized?");
+
+ Indices.push_back(Idx);
+ setName(Name);
}
ExtractValueInst::ExtractValueInst(const ExtractValueInst &EVI)
- : Instruction(reinterpret_cast<const Type*>(EVI.getType()), ExtractValue,
- OperandTraits<ExtractValueInst>::op_end(this)
- - EVI.getNumOperands(),
- EVI.getNumOperands()) {
- Use *OL = OperandList;
- Use *EVIOL = EVI.OperandList;
- for (unsigned i = 0, E = NumOperands; i != E; ++i)
- OL[i] = EVIOL[i];
+ : UnaryInstruction(EVI.getType(), ExtractValue, EVI.getOperand(0)),
+ Indices(EVI.Indices) {
}
// getIndexedType - Returns the type of the element that would be extracted
// pointer type.
//
const Type* ExtractValueInst::getIndexedType(const Type *Agg,
- Value* const *Idxs,
+ const unsigned *Idxs,
unsigned NumIdx) {
unsigned CurIdx = 0;
for (; CurIdx != NumIdx; ++CurIdx) {
const CompositeType *CT = dyn_cast<CompositeType>(Agg);
- if (!CT || isa<PointerType>(CT)) return 0;
- Value *Index = Idxs[CurIdx];
+ if (!CT || isa<PointerType>(CT) || isa<VectorType>(CT)) return 0;
+ unsigned Index = Idxs[CurIdx];
if (!CT->indexValid(Index)) return 0;
Agg = CT->getTypeAtIndex(Index);
return CurIdx == NumIdx ? Agg : 0;
}
+const Type* ExtractValueInst::getIndexedType(const Type *Agg,
+ unsigned Idx) {
+ return getIndexedType(Agg, &Idx, 1);
+}
+
//===----------------------------------------------------------------------===//
// BinaryOperator Class
//===----------------------------------------------------------------------===//
case AShr:
assert(getType() == LHS->getType() &&
"Shift operation should return same type as operands!");
- assert(getType()->isInteger() &&
- "Shift operation requires integer operands");
+ assert((getType()->isInteger() ||
+ (isa<VectorType>(getType()) &&
+ cast<VectorType>(getType())->getElementType()->isInteger())) &&
+ "Tried to create a shift operation on a non-integral type!");
break;
case And: case Or:
case Xor:
} else if (const VectorType *PTy = dyn_cast<VectorType>(SrcTy)) {
assert(DestBits == PTy->getBitWidth() &&
"Casting vector to integer of different width");
+ PTy = NULL;
return BitCast; // Same size, no-op cast
} else {
assert(isa<PointerType>(SrcTy) &&
} else if (const VectorType *PTy = dyn_cast<VectorType>(SrcTy)) {
assert(DestBits == PTy->getBitWidth() &&
"Casting vector to floating point of different width");
- return BitCast; // same size, no-op cast
+ PTy = NULL;
+ return BitCast; // same size, no-op cast
} else {
assert(0 && "Casting pointer or non-first class to float");
}
if (const VectorType *SrcPTy = dyn_cast<VectorType>(SrcTy)) {
assert(DestPTy->getBitWidth() == SrcPTy->getBitWidth() &&
"Casting vector to vector of different widths");
+ SrcPTy = NULL;
return BitCast; // vector -> vector
} else if (DestPTy->getBitWidth() == SrcBits) {
return BitCast; // float/int -> vector
switch (op) {
default: return false; // This is an input error
case Instruction::Trunc:
- return SrcTy->isInteger() && DstTy->isInteger()&& SrcBitSize > DstBitSize;
+ return SrcTy->isIntOrIntVector() &&
+ DstTy->isIntOrIntVector()&& SrcBitSize > DstBitSize;
case Instruction::ZExt:
- return SrcTy->isInteger() && DstTy->isInteger()&& SrcBitSize < DstBitSize;
+ return SrcTy->isIntOrIntVector() &&
+ DstTy->isIntOrIntVector()&& SrcBitSize < DstBitSize;
case Instruction::SExt:
- return SrcTy->isInteger() && DstTy->isInteger()&& SrcBitSize < DstBitSize;
+ return SrcTy->isIntOrIntVector() &&
+ DstTy->isIntOrIntVector()&& SrcBitSize < DstBitSize;
case Instruction::FPTrunc:
- return SrcTy->isFloatingPoint() && DstTy->isFloatingPoint() &&
- SrcBitSize > DstBitSize;
+ return SrcTy->isFPOrFPVector() &&
+ DstTy->isFPOrFPVector() &&
+ SrcBitSize > DstBitSize;
case Instruction::FPExt:
- return SrcTy->isFloatingPoint() && DstTy->isFloatingPoint() &&
- SrcBitSize < DstBitSize;
+ return SrcTy->isFPOrFPVector() &&
+ DstTy->isFPOrFPVector() &&
+ SrcBitSize < DstBitSize;
case Instruction::UIToFP:
case Instruction::SIToFP:
if (const VectorType *SVTy = dyn_cast<VectorType>(SrcTy)) {
if (const VectorType *DVTy = dyn_cast<VectorType>(DstTy)) {
- return SVTy->getElementType()->isInteger() &&
- DVTy->getElementType()->isFloatingPoint() &&
+ return SVTy->getElementType()->isIntOrIntVector() &&
+ DVTy->getElementType()->isFPOrFPVector() &&
SVTy->getNumElements() == DVTy->getNumElements();
}
}
- return SrcTy->isInteger() && DstTy->isFloatingPoint();
+ return SrcTy->isIntOrIntVector() && DstTy->isFPOrFPVector();
case Instruction::FPToUI:
case Instruction::FPToSI:
if (const VectorType *SVTy = dyn_cast<VectorType>(SrcTy)) {
if (const VectorType *DVTy = dyn_cast<VectorType>(DstTy)) {
- return SVTy->getElementType()->isFloatingPoint() &&
- DVTy->getElementType()->isInteger() &&
+ return SVTy->getElementType()->isFPOrFPVector() &&
+ DVTy->getElementType()->isIntOrIntVector() &&
SVTy->getNumElements() == DVTy->getNumElements();
}
}
- return SrcTy->isFloatingPoint() && DstTy->isInteger();
+ return SrcTy->isFPOrFPVector() && DstTy->isIntOrIntVector();
case Instruction::PtrToInt:
return isa<PointerType>(SrcTy) && DstTy->isInteger();
case Instruction::IntToPtr:
}
-ICmpInst::Predicate ICmpInst::getInversePredicate(Predicate pred) {
+CmpInst::Predicate CmpInst::getInversePredicate(Predicate pred) {
switch (pred) {
- default:
- assert(!"Unknown icmp predicate!");
+ default: assert(!"Unknown cmp predicate!");
case ICMP_EQ: return ICMP_NE;
case ICMP_NE: return ICMP_EQ;
case ICMP_UGT: return ICMP_ULE;
case ICMP_SLT: return ICMP_SGE;
case ICMP_SGE: return ICMP_SLT;
case ICMP_SLE: return ICMP_SGT;
- }
-}
-ICmpInst::Predicate ICmpInst::getSwappedPredicate(Predicate pred) {
- switch (pred) {
- default: assert(! "Unknown icmp predicate!");
- case ICMP_EQ: case ICMP_NE:
- return pred;
- case ICMP_SGT: return ICMP_SLT;
- case ICMP_SLT: return ICMP_SGT;
- case ICMP_SGE: return ICMP_SLE;
- case ICMP_SLE: return ICMP_SGE;
- case ICMP_UGT: return ICMP_ULT;
- case ICMP_ULT: return ICMP_UGT;
- case ICMP_UGE: return ICMP_ULE;
- case ICMP_ULE: return ICMP_UGE;
+ case FCMP_OEQ: return FCMP_UNE;
+ case FCMP_ONE: return FCMP_UEQ;
+ case FCMP_OGT: return FCMP_ULE;
+ case FCMP_OLT: return FCMP_UGE;
+ case FCMP_OGE: return FCMP_ULT;
+ case FCMP_OLE: return FCMP_UGT;
+ case FCMP_UEQ: return FCMP_ONE;
+ case FCMP_UNE: return FCMP_OEQ;
+ case FCMP_UGT: return FCMP_OLE;
+ case FCMP_ULT: return FCMP_OGE;
+ case FCMP_UGE: return FCMP_OLT;
+ case FCMP_ULE: return FCMP_OGT;
+ case FCMP_ORD: return FCMP_UNO;
+ case FCMP_UNO: return FCMP_ORD;
+ case FCMP_TRUE: return FCMP_FALSE;
+ case FCMP_FALSE: return FCMP_TRUE;
}
}
return ConstantRange(Lower, Upper);
}
-FCmpInst::Predicate FCmpInst::getInversePredicate(Predicate pred) {
- switch (pred) {
- default:
- assert(!"Unknown icmp predicate!");
- case FCMP_OEQ: return FCMP_UNE;
- case FCMP_ONE: return FCMP_UEQ;
- case FCMP_OGT: return FCMP_ULE;
- case FCMP_OLT: return FCMP_UGE;
- case FCMP_OGE: return FCMP_ULT;
- case FCMP_OLE: return FCMP_UGT;
- case FCMP_UEQ: return FCMP_ONE;
- case FCMP_UNE: return FCMP_OEQ;
- case FCMP_UGT: return FCMP_OLE;
- case FCMP_ULT: return FCMP_OGE;
- case FCMP_UGE: return FCMP_OLT;
- case FCMP_ULE: return FCMP_OGT;
- case FCMP_ORD: return FCMP_UNO;
- case FCMP_UNO: return FCMP_ORD;
- case FCMP_TRUE: return FCMP_FALSE;
- case FCMP_FALSE: return FCMP_TRUE;
- }
-}
-
-FCmpInst::Predicate FCmpInst::getSwappedPredicate(Predicate pred) {
+CmpInst::Predicate CmpInst::getSwappedPredicate(Predicate pred) {
switch (pred) {
- default: assert(!"Unknown fcmp predicate!");
+ default: assert(!"Unknown cmp predicate!");
+ case ICMP_EQ: case ICMP_NE:
+ return pred;
+ case ICMP_SGT: return ICMP_SLT;
+ case ICMP_SLT: return ICMP_SGT;
+ case ICMP_SGE: return ICMP_SLE;
+ case ICMP_SLE: return ICMP_SGE;
+ case ICMP_UGT: return ICMP_ULT;
+ case ICMP_ULT: return ICMP_UGT;
+ case ICMP_UGE: return ICMP_ULE;
+ case ICMP_ULE: return ICMP_UGE;
+
case FCMP_FALSE: case FCMP_TRUE:
case FCMP_OEQ: case FCMP_ONE:
case FCMP_UEQ: case FCMP_UNE:
setSuccessor(idx, B);
}
-//===----------------------------------------------------------------------===//
-// GetResultInst Implementation
-//===----------------------------------------------------------------------===//
-
-GetResultInst::GetResultInst(Value *Aggregate, unsigned Index,
- const std::string &Name,
- Instruction *InsertBef)
- : UnaryInstruction(cast<StructType>(Aggregate->getType())
- ->getElementType(Index),
- GetResult, Aggregate, InsertBef),
- Idx(Index) {
- assert(isValidOperands(Aggregate, Index)
- && "Invalid GetResultInst operands!");
- setName(Name);
-}
-
-bool GetResultInst::isValidOperands(const Value *Aggregate, unsigned Index) {
- if (!Aggregate)
- return false;
-
- if (const StructType *STy = dyn_cast<StructType>(Aggregate->getType())) {
- unsigned NumElements = STy->getNumElements();
- if (Index >= NumElements || NumElements == 0)
- return false;
-
- // getresult aggregate value's element types are restricted to
- // avoid nested aggregates.
- for (unsigned i = 0; i < NumElements; ++i)
- if (!STy->getElementType(i)->isFirstClassType())
- return false;
-
- // Otherwise, Aggregate is valid.
- return true;
- }
- return false;
-}
-
// Define these methods here so vtables don't get emitted into every translation
// unit that uses these classes.
}
ExtractValueInst *ExtractValueInst::clone() const {
- return new(getNumOperands()) ExtractValueInst(*this);
+ return new ExtractValueInst(*this);
}
InsertValueInst *InsertValueInst::clone() const {
- return new(getNumOperands()) InsertValueInst(*this);
+ return new InsertValueInst(*this);
}
}
UnwindInst *UnwindInst::clone() const { return new UnwindInst(); }
UnreachableInst *UnreachableInst::clone() const { return new UnreachableInst();}
-GetResultInst *GetResultInst::clone() const { return new GetResultInst(*this); }