// CallSite Class
//===----------------------------------------------------------------------===//
+#define CALLSITE_DELEGATE_GETTER(METHOD) \
+ Instruction *II(getInstruction()); \
+ return isCall() \
+ ? cast<CallInst>(II)->METHOD \
+ : cast<InvokeInst>(II)->METHOD
+
+#define CALLSITE_DELEGATE_SETTER(METHOD) \
+ Instruction *II(getInstruction()); \
+ if (isCall()) \
+ cast<CallInst>(II)->METHOD; \
+ else \
+ cast<InvokeInst>(II)->METHOD
+
CallSite::CallSite(Instruction *C) {
assert((isa<CallInst>(C) || isa<InvokeInst>(C)) && "Not a call!");
- I = C;
+ I.setPointer(C);
+ I.setInt(isa<CallInst>(C));
}
unsigned CallSite::getCallingConv() const {
- if (CallInst *CI = dyn_cast<CallInst>(I))
- return CI->getCallingConv();
- else
- return cast<InvokeInst>(I)->getCallingConv();
+ CALLSITE_DELEGATE_GETTER(getCallingConv());
}
void CallSite::setCallingConv(unsigned CC) {
- if (CallInst *CI = dyn_cast<CallInst>(I))
- CI->setCallingConv(CC);
- else
- cast<InvokeInst>(I)->setCallingConv(CC);
+ CALLSITE_DELEGATE_SETTER(setCallingConv(CC));
}
const AttrListPtr &CallSite::getAttributes() const {
- if (CallInst *CI = dyn_cast<CallInst>(I))
- return CI->getAttributes();
- else
- return cast<InvokeInst>(I)->getAttributes();
+ CALLSITE_DELEGATE_GETTER(getAttributes());
}
void CallSite::setAttributes(const AttrListPtr &PAL) {
- if (CallInst *CI = dyn_cast<CallInst>(I))
- CI->setAttributes(PAL);
- else
- cast<InvokeInst>(I)->setAttributes(PAL);
+ CALLSITE_DELEGATE_SETTER(setAttributes(PAL));
}
bool CallSite::paramHasAttr(uint16_t i, Attributes attr) const {
- if (CallInst *CI = dyn_cast<CallInst>(I))
- return CI->paramHasAttr(i, attr);
- else
- return cast<InvokeInst>(I)->paramHasAttr(i, attr);
+ CALLSITE_DELEGATE_GETTER(paramHasAttr(i, attr));
}
uint16_t CallSite::getParamAlignment(uint16_t i) const {
- if (CallInst *CI = dyn_cast<CallInst>(I))
- return CI->getParamAlignment(i);
- else
- return cast<InvokeInst>(I)->getParamAlignment(i);
+ CALLSITE_DELEGATE_GETTER(getParamAlignment(i));
}
-
bool CallSite::doesNotAccessMemory() const {
- if (CallInst *CI = dyn_cast<CallInst>(I))
- return CI->doesNotAccessMemory();
- else
- return cast<InvokeInst>(I)->doesNotAccessMemory();
+ CALLSITE_DELEGATE_GETTER(doesNotAccessMemory());
}
void CallSite::setDoesNotAccessMemory(bool doesNotAccessMemory) {
- if (CallInst *CI = dyn_cast<CallInst>(I))
- CI->setDoesNotAccessMemory(doesNotAccessMemory);
- else
- cast<InvokeInst>(I)->setDoesNotAccessMemory(doesNotAccessMemory);
+ CALLSITE_DELEGATE_SETTER(setDoesNotAccessMemory(doesNotAccessMemory));
}
bool CallSite::onlyReadsMemory() const {
- if (CallInst *CI = dyn_cast<CallInst>(I))
- return CI->onlyReadsMemory();
- else
- return cast<InvokeInst>(I)->onlyReadsMemory();
+ CALLSITE_DELEGATE_GETTER(onlyReadsMemory());
}
void CallSite::setOnlyReadsMemory(bool onlyReadsMemory) {
- if (CallInst *CI = dyn_cast<CallInst>(I))
- CI->setOnlyReadsMemory(onlyReadsMemory);
- else
- cast<InvokeInst>(I)->setOnlyReadsMemory(onlyReadsMemory);
+ CALLSITE_DELEGATE_SETTER(setOnlyReadsMemory(onlyReadsMemory));
}
bool CallSite::doesNotReturn() const {
- if (CallInst *CI = dyn_cast<CallInst>(I))
- return CI->doesNotReturn();
- else
- return cast<InvokeInst>(I)->doesNotReturn();
+ CALLSITE_DELEGATE_GETTER(doesNotReturn());
}
void CallSite::setDoesNotReturn(bool doesNotReturn) {
- if (CallInst *CI = dyn_cast<CallInst>(I))
- CI->setDoesNotReturn(doesNotReturn);
- else
- cast<InvokeInst>(I)->setDoesNotReturn(doesNotReturn);
+ CALLSITE_DELEGATE_SETTER(setDoesNotReturn(doesNotReturn));
}
bool CallSite::doesNotThrow() const {
- if (CallInst *CI = dyn_cast<CallInst>(I))
- return CI->doesNotThrow();
- else
- return cast<InvokeInst>(I)->doesNotThrow();
+ CALLSITE_DELEGATE_GETTER(doesNotThrow());
}
void CallSite::setDoesNotThrow(bool doesNotThrow) {
- if (CallInst *CI = dyn_cast<CallInst>(I))
- CI->setDoesNotThrow(doesNotThrow);
- else
- cast<InvokeInst>(I)->setDoesNotThrow(doesNotThrow);
+ CALLSITE_DELEGATE_SETTER(setDoesNotThrow(doesNotThrow));
}
bool CallSite::hasArgument(const Value *Arg) const {
return false;
}
+#undef CALLSITE_DELEGATE_GETTER
+#undef CALLSITE_DELEGATE_SETTER
+
//===----------------------------------------------------------------------===//
// 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
//===----------------------------------------------------------------------===//
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 ExtractValueInst::init(const unsigned *Idx, unsigned NumIdx,
- const std::string &Name) {
+ const std::string &Name) {
assert(NumOperands == 1 && "NumOperands not initialized?");
Indices.insert(Indices.end(), Idx, Idx + NumIdx);
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