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
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
//===----------------------------------------------------------------------===//
: 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);
}
-void CallInst::removeParamAttr(unsigned i, ParameterAttributes attr) {
- PAListPtr PAL = getParamAttrs();
+void CallInst::removeAttribute(unsigned i, Attributes attr) {
+ AttrListPtr PAL = getAttributes();
PAL = PAL.removeAttr(i, attr);
- setParamAttrs(PAL);
+ setAttributes(PAL);
}
-bool CallInst::paramHasAttr(unsigned i, ParameterAttributes attr) const {
- if (ParamAttrs.paramHasAttr(i, attr))
+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);
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::removeParamAttr(unsigned i, ParameterAttributes attr) {
- PAListPtr PAL = getParamAttrs();
+void InvokeInst::removeAttribute(unsigned i, Attributes attr) {
+ AttrListPtr PAL = getAttributes();
PAL = PAL.removeAttr(i, attr);
- setParamAttrs(PAL);
+ setAttributes(PAL);
}
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() ==
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;
}
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: