Changeset View
Changeset View
Standalone View
Standalone View
llvm/trunk/lib/IR/Instructions.cpp
Show First 20 Lines • Show All 313 Lines • ▼ Show 20 Lines | void CallInst::init(Value *Func, const Twine &NameStr) { | ||||
assert(getNumOperands() == 1 && "NumOperands not set up?"); | assert(getNumOperands() == 1 && "NumOperands not set up?"); | ||||
Op<-1>() = Func; | Op<-1>() = Func; | ||||
assert(FTy->getNumParams() == 0 && "Calling a function with bad signature"); | assert(FTy->getNumParams() == 0 && "Calling a function with bad signature"); | ||||
setName(NameStr); | setName(NameStr); | ||||
} | } | ||||
CallInst::CallInst(Value *Func, const Twine &Name, | CallInst::CallInst(Value *Func, const Twine &Name, Instruction *InsertBefore) | ||||
Instruction *InsertBefore) | : CallBase<CallInst>( | ||||
: Instruction(cast<FunctionType>(cast<PointerType>(Func->getType()) | cast<FunctionType>( | ||||
->getElementType())->getReturnType(), | cast<PointerType>(Func->getType())->getElementType()) | ||||
->getReturnType(), | |||||
Instruction::Call, | Instruction::Call, | ||||
OperandTraits<CallInst>::op_end(this) - 1, | OperandTraits<CallBase<CallInst>>::op_end(this) - 1, 1, | ||||
1, InsertBefore) { | InsertBefore) { | ||||
init(Func, Name); | init(Func, Name); | ||||
} | } | ||||
CallInst::CallInst(Value *Func, const Twine &Name, | CallInst::CallInst(Value *Func, const Twine &Name, BasicBlock *InsertAtEnd) | ||||
BasicBlock *InsertAtEnd) | : CallBase<CallInst>( | ||||
: Instruction(cast<FunctionType>(cast<PointerType>(Func->getType()) | cast<FunctionType>( | ||||
->getElementType())->getReturnType(), | cast<PointerType>(Func->getType())->getElementType()) | ||||
->getReturnType(), | |||||
Instruction::Call, | Instruction::Call, | ||||
OperandTraits<CallInst>::op_end(this) - 1, | OperandTraits<CallBase<CallInst>>::op_end(this) - 1, 1, InsertAtEnd) { | ||||
1, InsertAtEnd) { | |||||
init(Func, Name); | init(Func, Name); | ||||
} | } | ||||
CallInst::CallInst(const CallInst &CI) | CallInst::CallInst(const CallInst &CI) | ||||
: Instruction(CI.getType(), Instruction::Call, | : CallBase<CallInst>(CI.Attrs, CI.FTy, CI.getType(), Instruction::Call, | ||||
OperandTraits<CallInst>::op_end(this) - CI.getNumOperands(), | OperandTraits<CallBase<CallInst>>::op_end(this) - | ||||
CI.getNumOperands()), | CI.getNumOperands(), | ||||
Attrs(CI.Attrs), FTy(CI.FTy) { | CI.getNumOperands()) { | ||||
setTailCallKind(CI.getTailCallKind()); | setTailCallKind(CI.getTailCallKind()); | ||||
setCallingConv(CI.getCallingConv()); | setCallingConv(CI.getCallingConv()); | ||||
std::copy(CI.op_begin(), CI.op_end(), op_begin()); | std::copy(CI.op_begin(), CI.op_end(), op_begin()); | ||||
std::copy(CI.bundle_op_info_begin(), CI.bundle_op_info_end(), | std::copy(CI.bundle_op_info_begin(), CI.bundle_op_info_end(), | ||||
bundle_op_info_begin()); | bundle_op_info_begin()); | ||||
SubclassOptionalData = CI.SubclassOptionalData; | SubclassOptionalData = CI.SubclassOptionalData; | ||||
} | } | ||||
CallInst *CallInst::Create(CallInst *CI, ArrayRef<OperandBundleDef> OpB, | CallInst *CallInst::Create(CallInst *CI, ArrayRef<OperandBundleDef> OpB, | ||||
Instruction *InsertPt) { | Instruction *InsertPt) { | ||||
std::vector<Value *> Args(CI->arg_begin(), CI->arg_end()); | std::vector<Value *> Args(CI->arg_begin(), CI->arg_end()); | ||||
auto *NewCI = CallInst::Create(CI->getCalledValue(), Args, OpB, CI->getName(), | auto *NewCI = CallInst::Create(CI->getCalledValue(), Args, OpB, CI->getName(), | ||||
InsertPt); | InsertPt); | ||||
NewCI->setTailCallKind(CI->getTailCallKind()); | NewCI->setTailCallKind(CI->getTailCallKind()); | ||||
NewCI->setCallingConv(CI->getCallingConv()); | NewCI->setCallingConv(CI->getCallingConv()); | ||||
NewCI->SubclassOptionalData = CI->SubclassOptionalData; | NewCI->SubclassOptionalData = CI->SubclassOptionalData; | ||||
NewCI->setAttributes(CI->getAttributes()); | NewCI->setAttributes(CI->getAttributes()); | ||||
NewCI->setDebugLoc(CI->getDebugLoc()); | NewCI->setDebugLoc(CI->getDebugLoc()); | ||||
return NewCI; | return NewCI; | ||||
} | } | ||||
Value *CallInst::getReturnedArgOperand() const { | |||||
unsigned Index; | |||||
if (Attrs.hasAttrSomewhere(Attribute::Returned, &Index) && Index) | |||||
return getArgOperand(Index - AttributeList::FirstArgIndex); | |||||
if (const Function *F = getCalledFunction()) | |||||
if (F->getAttributes().hasAttrSomewhere(Attribute::Returned, &Index) && | |||||
Index) | |||||
return getArgOperand(Index - AttributeList::FirstArgIndex); | |||||
return nullptr; | |||||
} | |||||
void CallInst::addAttribute(unsigned i, Attribute::AttrKind Kind) { | |||||
AttributeList PAL = getAttributes(); | |||||
PAL = PAL.addAttribute(getContext(), i, Kind); | |||||
setAttributes(PAL); | |||||
} | |||||
void CallInst::addAttribute(unsigned i, Attribute Attr) { | |||||
AttributeList PAL = getAttributes(); | |||||
PAL = PAL.addAttribute(getContext(), i, Attr); | |||||
setAttributes(PAL); | |||||
} | |||||
void CallInst::addParamAttr(unsigned ArgNo, Attribute::AttrKind Kind) { | |||||
assert(ArgNo < getNumArgOperands() && "Out of bounds"); | |||||
AttributeList PAL = getAttributes(); | |||||
PAL = PAL.addParamAttribute(getContext(), ArgNo, Kind); | |||||
setAttributes(PAL); | |||||
} | |||||
void CallInst::addParamAttr(unsigned ArgNo, Attribute Attr) { | |||||
assert(ArgNo < getNumArgOperands() && "Out of bounds"); | |||||
AttributeList PAL = getAttributes(); | |||||
PAL = PAL.addParamAttribute(getContext(), ArgNo, Attr); | |||||
setAttributes(PAL); | |||||
} | |||||
void CallInst::removeAttribute(unsigned i, Attribute::AttrKind Kind) { | |||||
AttributeList PAL = getAttributes(); | |||||
PAL = PAL.removeAttribute(getContext(), i, Kind); | |||||
setAttributes(PAL); | |||||
} | |||||
void CallInst::removeAttribute(unsigned i, StringRef Kind) { | |||||
AttributeList PAL = getAttributes(); | |||||
PAL = PAL.removeAttribute(getContext(), i, Kind); | |||||
setAttributes(PAL); | |||||
} | |||||
void CallInst::removeParamAttr(unsigned ArgNo, Attribute::AttrKind Kind) { | |||||
assert(ArgNo < getNumArgOperands() && "Out of bounds"); | |||||
AttributeList PAL = getAttributes(); | |||||
PAL = PAL.removeParamAttribute(getContext(), ArgNo, Kind); | |||||
setAttributes(PAL); | |||||
} | |||||
void CallInst::removeParamAttr(unsigned ArgNo, StringRef Kind) { | |||||
assert(ArgNo < getNumArgOperands() && "Out of bounds"); | |||||
AttributeList PAL = getAttributes(); | |||||
PAL = PAL.removeParamAttribute(getContext(), ArgNo, Kind); | |||||
setAttributes(PAL); | |||||
} | |||||
void CallInst::addDereferenceableAttr(unsigned i, uint64_t Bytes) { | |||||
AttributeList PAL = getAttributes(); | |||||
PAL = PAL.addDereferenceableAttr(getContext(), i, Bytes); | |||||
setAttributes(PAL); | |||||
} | |||||
void CallInst::addDereferenceableOrNullAttr(unsigned i, uint64_t Bytes) { | |||||
AttributeList PAL = getAttributes(); | |||||
PAL = PAL.addDereferenceableOrNullAttr(getContext(), i, Bytes); | |||||
setAttributes(PAL); | |||||
} | |||||
bool CallInst::hasRetAttr(Attribute::AttrKind Kind) const { | |||||
if (Attrs.hasAttribute(AttributeList::ReturnIndex, Kind)) | |||||
return true; | |||||
// Look at the callee, if available. | |||||
if (const Function *F = getCalledFunction()) | |||||
return F->getAttributes().hasAttribute(AttributeList::ReturnIndex, Kind); | |||||
return false; | |||||
} | |||||
bool CallInst::paramHasAttr(unsigned i, Attribute::AttrKind Kind) const { | |||||
assert(i < getNumArgOperands() && "Param index out of bounds!"); | |||||
if (Attrs.hasParamAttribute(i, Kind)) | |||||
return true; | |||||
if (const Function *F = getCalledFunction()) | |||||
return F->getAttributes().hasParamAttribute(i, Kind); | |||||
return false; | |||||
} | |||||
bool CallInst::dataOperandHasImpliedAttr(unsigned i, | |||||
Attribute::AttrKind Kind) const { | |||||
// There are getNumOperands() - 1 data operands. The last operand is the | |||||
// callee. | |||||
assert(i < getNumOperands() && "Data operand index out of bounds!"); | |||||
// The attribute A can either be directly specified, if the operand in | |||||
// question is a call argument; or be indirectly implied by the kind of its | |||||
// containing operand bundle, if the operand is a bundle operand. | |||||
if (i == AttributeList::ReturnIndex) | |||||
return hasRetAttr(Kind); | |||||
// FIXME: Avoid these i - 1 calculations and update the API to use zero-based | |||||
// indices. | |||||
if (i < (getNumArgOperands() + 1)) | |||||
return paramHasAttr(i - 1, Kind); | |||||
assert(hasOperandBundles() && i >= (getBundleOperandsStartIndex() + 1) && | |||||
"Must be either a call argument or an operand bundle!"); | |||||
return bundleOperandHasAttr(i - 1, Kind); | |||||
} | |||||
/// IsConstantOne - Return true only if val is constant int 1 | /// IsConstantOne - Return true only if val is constant int 1 | ||||
static bool IsConstantOne(Value *val) { | static bool IsConstantOne(Value *val) { | ||||
assert(val && "IsConstantOne does not work with nullptr val"); | assert(val && "IsConstantOne does not work with nullptr val"); | ||||
const ConstantInt *CVal = dyn_cast<ConstantInt>(val); | const ConstantInt *CVal = dyn_cast<ConstantInt>(val); | ||||
return CVal && CVal->isOne(); | return CVal && CVal->isOne(); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 219 Lines • ▼ Show 20 Lines | #endif | ||||
auto It = populateBundleOperandInfos(Bundles, Args.size()); | auto It = populateBundleOperandInfos(Bundles, Args.size()); | ||||
(void)It; | (void)It; | ||||
assert(It + 3 == op_end() && "Should add up!"); | assert(It + 3 == op_end() && "Should add up!"); | ||||
setName(NameStr); | setName(NameStr); | ||||
} | } | ||||
InvokeInst::InvokeInst(const InvokeInst &II) | InvokeInst::InvokeInst(const InvokeInst &II) | ||||
: TerminatorInst(II.getType(), Instruction::Invoke, | : CallBase<InvokeInst>(II.Attrs, II.FTy, II.getType(), Instruction::Invoke, | ||||
OperandTraits<InvokeInst>::op_end(this) - | OperandTraits<CallBase<InvokeInst>>::op_end(this) - | ||||
II.getNumOperands(), | II.getNumOperands(), | ||||
II.getNumOperands()), | II.getNumOperands()) { | ||||
Attrs(II.Attrs), FTy(II.FTy) { | |||||
setCallingConv(II.getCallingConv()); | setCallingConv(II.getCallingConv()); | ||||
std::copy(II.op_begin(), II.op_end(), op_begin()); | std::copy(II.op_begin(), II.op_end(), op_begin()); | ||||
std::copy(II.bundle_op_info_begin(), II.bundle_op_info_end(), | std::copy(II.bundle_op_info_begin(), II.bundle_op_info_end(), | ||||
bundle_op_info_begin()); | bundle_op_info_begin()); | ||||
SubclassOptionalData = II.SubclassOptionalData; | SubclassOptionalData = II.SubclassOptionalData; | ||||
} | } | ||||
InvokeInst *InvokeInst::Create(InvokeInst *II, ArrayRef<OperandBundleDef> OpB, | InvokeInst *InvokeInst::Create(InvokeInst *II, ArrayRef<OperandBundleDef> OpB, | ||||
Instruction *InsertPt) { | Instruction *InsertPt) { | ||||
std::vector<Value *> Args(II->arg_begin(), II->arg_end()); | std::vector<Value *> Args(II->arg_begin(), II->arg_end()); | ||||
auto *NewII = InvokeInst::Create(II->getCalledValue(), II->getNormalDest(), | auto *NewII = InvokeInst::Create(II->getCalledValue(), II->getNormalDest(), | ||||
II->getUnwindDest(), Args, OpB, | II->getUnwindDest(), Args, OpB, | ||||
II->getName(), InsertPt); | II->getName(), InsertPt); | ||||
NewII->setCallingConv(II->getCallingConv()); | NewII->setCallingConv(II->getCallingConv()); | ||||
NewII->SubclassOptionalData = II->SubclassOptionalData; | NewII->SubclassOptionalData = II->SubclassOptionalData; | ||||
NewII->setAttributes(II->getAttributes()); | NewII->setAttributes(II->getAttributes()); | ||||
NewII->setDebugLoc(II->getDebugLoc()); | NewII->setDebugLoc(II->getDebugLoc()); | ||||
return NewII; | return NewII; | ||||
} | } | ||||
Value *InvokeInst::getReturnedArgOperand() const { | |||||
unsigned Index; | |||||
if (Attrs.hasAttrSomewhere(Attribute::Returned, &Index) && Index) | |||||
return getArgOperand(Index - AttributeList::FirstArgIndex); | |||||
if (const Function *F = getCalledFunction()) | |||||
if (F->getAttributes().hasAttrSomewhere(Attribute::Returned, &Index) && | |||||
Index) | |||||
return getArgOperand(Index - AttributeList::FirstArgIndex); | |||||
return nullptr; | |||||
} | |||||
bool InvokeInst::hasRetAttr(Attribute::AttrKind Kind) const { | |||||
if (Attrs.hasAttribute(AttributeList::ReturnIndex, Kind)) | |||||
return true; | |||||
// Look at the callee, if available. | |||||
if (const Function *F = getCalledFunction()) | |||||
return F->getAttributes().hasAttribute(AttributeList::ReturnIndex, Kind); | |||||
return false; | |||||
} | |||||
bool InvokeInst::paramHasAttr(unsigned i, Attribute::AttrKind Kind) const { | |||||
assert(i < getNumArgOperands() && "Param index out of bounds!"); | |||||
if (Attrs.hasParamAttribute(i, Kind)) | |||||
return true; | |||||
if (const Function *F = getCalledFunction()) | |||||
return F->getAttributes().hasParamAttribute(i, Kind); | |||||
return false; | |||||
} | |||||
bool InvokeInst::dataOperandHasImpliedAttr(unsigned i, | |||||
Attribute::AttrKind Kind) const { | |||||
// There are getNumOperands() - 3 data operands. The last three operands are | |||||
// the callee and the two successor basic blocks. | |||||
assert(i < (getNumOperands() - 2) && "Data operand index out of bounds!"); | |||||
// The attribute A can either be directly specified, if the operand in | |||||
// question is an invoke argument; or be indirectly implied by the kind of its | |||||
// containing operand bundle, if the operand is a bundle operand. | |||||
if (i == AttributeList::ReturnIndex) | |||||
return hasRetAttr(Kind); | |||||
// FIXME: Avoid these i - 1 calculations and update the API to use zero-based | |||||
// indices. | |||||
if (i < (getNumArgOperands() + 1)) | |||||
return paramHasAttr(i - 1, Kind); | |||||
assert(hasOperandBundles() && i >= (getBundleOperandsStartIndex() + 1) && | |||||
"Must be either an invoke argument or an operand bundle!"); | |||||
return bundleOperandHasAttr(i - 1, Kind); | |||||
} | |||||
void InvokeInst::addAttribute(unsigned i, Attribute::AttrKind Kind) { | |||||
AttributeList PAL = getAttributes(); | |||||
PAL = PAL.addAttribute(getContext(), i, Kind); | |||||
setAttributes(PAL); | |||||
} | |||||
void InvokeInst::addAttribute(unsigned i, Attribute Attr) { | |||||
AttributeList PAL = getAttributes(); | |||||
PAL = PAL.addAttribute(getContext(), i, Attr); | |||||
setAttributes(PAL); | |||||
} | |||||
void InvokeInst::addParamAttr(unsigned ArgNo, Attribute::AttrKind Kind) { | |||||
AttributeList PAL = getAttributes(); | |||||
PAL = PAL.addParamAttribute(getContext(), ArgNo, Kind); | |||||
setAttributes(PAL); | |||||
} | |||||
void InvokeInst::removeAttribute(unsigned i, Attribute::AttrKind Kind) { | |||||
AttributeList PAL = getAttributes(); | |||||
PAL = PAL.removeAttribute(getContext(), i, Kind); | |||||
setAttributes(PAL); | |||||
} | |||||
void InvokeInst::removeAttribute(unsigned i, StringRef Kind) { | |||||
AttributeList PAL = getAttributes(); | |||||
PAL = PAL.removeAttribute(getContext(), i, Kind); | |||||
setAttributes(PAL); | |||||
} | |||||
void InvokeInst::removeParamAttr(unsigned ArgNo, Attribute::AttrKind Kind) { | |||||
AttributeList PAL = getAttributes(); | |||||
PAL = PAL.removeParamAttribute(getContext(), ArgNo, Kind); | |||||
setAttributes(PAL); | |||||
} | |||||
void InvokeInst::addDereferenceableAttr(unsigned i, uint64_t Bytes) { | |||||
AttributeList PAL = getAttributes(); | |||||
PAL = PAL.addDereferenceableAttr(getContext(), i, Bytes); | |||||
setAttributes(PAL); | |||||
} | |||||
void InvokeInst::addDereferenceableOrNullAttr(unsigned i, uint64_t Bytes) { | |||||
AttributeList PAL = getAttributes(); | |||||
PAL = PAL.addDereferenceableOrNullAttr(getContext(), i, Bytes); | |||||
setAttributes(PAL); | |||||
} | |||||
LandingPadInst *InvokeInst::getLandingPadInst() const { | LandingPadInst *InvokeInst::getLandingPadInst() const { | ||||
return cast<LandingPadInst>(getUnwindDest()->getFirstNonPHI()); | return cast<LandingPadInst>(getUnwindDest()->getFirstNonPHI()); | ||||
} | } | ||||
//===----------------------------------------------------------------------===// | //===----------------------------------------------------------------------===// | ||||
// ReturnInst Implementation | // ReturnInst Implementation | ||||
//===----------------------------------------------------------------------===// | //===----------------------------------------------------------------------===// | ||||
▲ Show 20 Lines • Show All 3,124 Lines • Show Last 20 Lines |