31
31
//===----------------------------------------------------------------------===//
33
#define CALLSITE_DELEGATE_GETTER(METHOD) \
34
Instruction *II(getInstruction()); \
36
? cast<CallInst>(II)->METHOD \
37
: cast<InvokeInst>(II)->METHOD
39
#define CALLSITE_DELEGATE_SETTER(METHOD) \
40
Instruction *II(getInstruction()); \
42
cast<CallInst>(II)->METHOD; \
44
cast<InvokeInst>(II)->METHOD
46
CallSite::CallSite(Instruction *C) {
47
assert((isa<CallInst>(C) || isa<InvokeInst>(C)) && "Not a call!");
49
I.setInt(isa<CallInst>(C));
51
CallingConv::ID CallSite::getCallingConv() const {
52
CALLSITE_DELEGATE_GETTER(getCallingConv());
54
void CallSite::setCallingConv(CallingConv::ID CC) {
55
CALLSITE_DELEGATE_SETTER(setCallingConv(CC));
57
const AttrListPtr &CallSite::getAttributes() const {
58
CALLSITE_DELEGATE_GETTER(getAttributes());
60
void CallSite::setAttributes(const AttrListPtr &PAL) {
61
CALLSITE_DELEGATE_SETTER(setAttributes(PAL));
63
bool CallSite::paramHasAttr(uint16_t i, Attributes attr) const {
64
CALLSITE_DELEGATE_GETTER(paramHasAttr(i, attr));
66
uint16_t CallSite::getParamAlignment(uint16_t i) const {
67
CALLSITE_DELEGATE_GETTER(getParamAlignment(i));
69
bool CallSite::doesNotAccessMemory() const {
70
CALLSITE_DELEGATE_GETTER(doesNotAccessMemory());
72
void CallSite::setDoesNotAccessMemory(bool doesNotAccessMemory) {
73
CALLSITE_DELEGATE_SETTER(setDoesNotAccessMemory(doesNotAccessMemory));
75
bool CallSite::onlyReadsMemory() const {
76
CALLSITE_DELEGATE_GETTER(onlyReadsMemory());
78
void CallSite::setOnlyReadsMemory(bool onlyReadsMemory) {
79
CALLSITE_DELEGATE_SETTER(setOnlyReadsMemory(onlyReadsMemory));
81
bool CallSite::doesNotReturn() const {
82
CALLSITE_DELEGATE_GETTER(doesNotReturn());
84
void CallSite::setDoesNotReturn(bool doesNotReturn) {
85
CALLSITE_DELEGATE_SETTER(setDoesNotReturn(doesNotReturn));
87
bool CallSite::doesNotThrow() const {
88
CALLSITE_DELEGATE_GETTER(doesNotThrow());
90
void CallSite::setDoesNotThrow(bool doesNotThrow) {
91
CALLSITE_DELEGATE_SETTER(setDoesNotThrow(doesNotThrow));
94
bool CallSite::hasArgument(const Value *Arg) const {
95
for (arg_iterator AI = this->arg_begin(), E = this->arg_end(); AI != E; ++AI)
101
#undef CALLSITE_DELEGATE_GETTER
102
#undef CALLSITE_DELEGATE_SETTER
33
User::op_iterator CallSite::getCallee() const {
34
Instruction *II(getInstruction());
36
? cast<CallInst>(II)->op_end() - 1 // Skip Callee
37
: cast<InvokeInst>(II)->op_end() - 3; // Skip BB, BB, Callee
104
40
//===----------------------------------------------------------------------===//
105
41
// TerminatorInst Class
309
244
assert((i >= FTy->getNumParams() ||
310
245
FTy->getParamType(i) == Params[i]->getType()) &&
311
246
"Calling a function with a bad signature!");
247
OperandList[i] = Params[i];
316
251
void CallInst::init(Value *Func, Value *Actual1, Value *Actual2) {
317
252
assert(NumOperands == 3 && "NumOperands not set up?");
318
Use *OL = OperandList;
323
257
const FunctionType *FTy =
324
258
cast<FunctionType>(cast<PointerType>(Func->getType())->getElementType());
537
469
Instruction *CallInst::CreateMalloc(Instruction *InsertBefore,
538
470
const Type *IntPtrTy, const Type *AllocTy,
539
471
Value *AllocSize, Value *ArraySize,
540
473
const Twine &Name) {
541
474
return createMalloc(InsertBefore, NULL, IntPtrTy, AllocTy, AllocSize,
542
ArraySize, NULL, Name);
475
ArraySize, MallocF, Name);
545
478
/// CreateMalloc - Generate the IR for a call to malloc:
593
526
/// CreateFree - Generate the IR for a call to the builtin free function.
594
void CallInst::CreateFree(Value* Source, Instruction *InsertBefore) {
595
createFree(Source, InsertBefore, NULL);
527
Instruction * CallInst::CreateFree(Value* Source, Instruction *InsertBefore) {
528
return createFree(Source, InsertBefore, NULL);
598
531
/// CreateFree - Generate the IR for a call to the builtin free function.
611
544
void InvokeInst::init(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
612
545
Value* const *Args, unsigned NumArgs) {
613
546
assert(NumOperands == 3+NumArgs && "NumOperands not set up?");
614
Use *OL = OperandList;
549
Op<-1>() = IfException;
618
550
const FunctionType *FTy =
619
551
cast<FunctionType>(cast<PointerType>(Fn->getType())->getElementType());
620
552
FTy = FTy; // silence warning.
622
554
assert(((NumArgs == FTy->getNumParams()) ||
623
555
(FTy->isVarArg() && NumArgs > FTy->getNumParams())) &&
624
"Calling a function with bad signature");
556
"Invoking a function with bad signature");
558
Use *OL = OperandList;
626
559
for (unsigned i = 0, e = NumArgs; i != e; i++) {
627
560
assert((i >= FTy->getNumParams() ||
628
561
FTy->getParamType(i) == Args[i]->getType()) &&
629
562
"Invoking a function with a bad signature!");
1094
1029
void LoadInst::setAlignment(unsigned Align) {
1095
1030
assert((Align & (Align-1)) == 0 && "Alignment is not a power of 2!");
1031
assert(Align <= MaximumAlignment &&
1032
"Alignment is greater than MaximumAlignment!");
1096
1033
setInstructionSubclassData((getSubclassDataFromInstruction() & 1) |
1097
1034
((Log2_32(Align)+1)<<1));
1035
assert(getAlignment() == Align && "Alignment representation error!");
1100
1038
//===----------------------------------------------------------------------===//
1190
1128
void StoreInst::setAlignment(unsigned Align) {
1191
1129
assert((Align & (Align-1)) == 0 && "Alignment is not a power of 2!");
1130
assert(Align <= MaximumAlignment &&
1131
"Alignment is greater than MaximumAlignment!");
1192
1132
setInstructionSubclassData((getSubclassDataFromInstruction() & 1) |
1193
1133
((Log2_32(Align)+1) << 1));
1134
assert(getAlignment() == Align && "Alignment representation error!");
1196
1137
//===----------------------------------------------------------------------===//
1491
1432
const VectorType *MaskTy = dyn_cast<VectorType>(Mask->getType());
1492
if (!isa<Constant>(Mask) || MaskTy == 0 ||
1493
!MaskTy->getElementType()->isIntegerTy(32))
1433
if (MaskTy == 0 || !MaskTy->getElementType()->isIntegerTy(32))
1436
// Check to see if Mask is valid.
1437
if (const ConstantVector *MV = dyn_cast<ConstantVector>(Mask)) {
1438
const VectorType *VTy = cast<VectorType>(V1->getType());
1439
for (unsigned i = 0, e = MV->getNumOperands(); i != e; ++i) {
1440
if (ConstantInt* CI = dyn_cast<ConstantInt>(MV->getOperand(i))) {
1441
if (CI->uge(VTy->getNumElements()*2))
1443
} else if (!isa<UndefValue>(MV->getOperand(i))) {
1448
else if (!isa<UndefValue>(Mask) && !isa<ConstantAggregateZero>(Mask))
1626
1582
// BinaryOperator Class
1627
1583
//===----------------------------------------------------------------------===//
1629
/// AdjustIType - Map Add, Sub, and Mul to FAdd, FSub, and FMul when the
1630
/// type is floating-point, to help provide compatibility with an older API.
1632
static BinaryOperator::BinaryOps AdjustIType(BinaryOperator::BinaryOps iType,
1634
// API compatibility: Adjust integer opcodes to floating-point opcodes.
1635
if (Ty->isFPOrFPVectorTy()) {
1636
if (iType == BinaryOperator::Add) iType = BinaryOperator::FAdd;
1637
else if (iType == BinaryOperator::Sub) iType = BinaryOperator::FSub;
1638
else if (iType == BinaryOperator::Mul) iType = BinaryOperator::FMul;
1643
1585
BinaryOperator::BinaryOperator(BinaryOps iType, Value *S1, Value *S2,
1644
1586
const Type *Ty, const Twine &Name,
1645
1587
Instruction *InsertBefore)
1646
: Instruction(Ty, AdjustIType(iType, Ty),
1588
: Instruction(Ty, iType,
1647
1589
OperandTraits<BinaryOperator>::op_begin(this),
1648
1590
OperandTraits<BinaryOperator>::operands(this),
1649
1591
InsertBefore) {
1652
init(AdjustIType(iType, Ty));
1656
1598
BinaryOperator::BinaryOperator(BinaryOps iType, Value *S1, Value *S2,
1657
1599
const Type *Ty, const Twine &Name,
1658
1600
BasicBlock *InsertAtEnd)
1659
: Instruction(Ty, AdjustIType(iType, Ty),
1601
: Instruction(Ty, iType,
1660
1602
OperandTraits<BinaryOperator>::op_begin(this),
1661
1603
OperandTraits<BinaryOperator>::operands(this),
1665
init(AdjustIType(iType, Ty));
1989
1931
/// # bitcast i32* %x to i8*
1990
1932
/// # bitcast <2 x i32> %x to <4 x i16>
1991
1933
/// # ptrtoint i32* %x to i32 ; on 32-bit plaforms only
1992
/// @brief Determine if a cast is a no-op.
1993
bool CastInst::isNoopCast(const Type *IntPtrTy) const {
1994
switch (getOpcode()) {
1934
/// @brief Determine if the described cast is a no-op.
1935
bool CastInst::isNoopCast(Instruction::CastOps Opcode,
1938
const Type *IntPtrTy) {
1996
1941
assert(!"Invalid CastOp");
1997
1942
case Instruction::Trunc:
2008
1953
return true; // BitCast never modifies bits.
2009
1954
case Instruction::PtrToInt:
2010
1955
return IntPtrTy->getScalarSizeInBits() ==
2011
getType()->getScalarSizeInBits();
1956
DestTy->getScalarSizeInBits();
2012
1957
case Instruction::IntToPtr:
2013
1958
return IntPtrTy->getScalarSizeInBits() ==
2014
getOperand(0)->getType()->getScalarSizeInBits();
1959
SrcTy->getScalarSizeInBits();
1963
/// @brief Determine if a cast is a no-op.
1964
bool CastInst::isNoopCast(const Type *IntPtrTy) const {
1965
return isNoopCast(getOpcode(), getOperand(0)->getType(), getType(), IntPtrTy);
2018
1968
/// This function determines if a pair of casts can be eliminated and what
2019
1969
/// opcode should be used in the elimination. This assumes that there are two
2020
1970
/// instructions like this:
2047
1997
// FPEXT < FloatPt n/a FloatPt n/a
2048
1998
// PTRTOINT n/a Pointer n/a Integral Unsigned
2049
1999
// INTTOPTR n/a Integral Unsigned Pointer n/a
2050
// BITCONVERT = FirstClass n/a FirstClass n/a
2000
// BITCAST = FirstClass n/a FirstClass n/a
2052
2002
// NOTE: some transforms are safe, but we consider them to be non-profitable.
2053
2003
// For example, we could merge "fptoui double to i32" + "zext i32 to i64",
2077
2027
{ 99,99,99,99,99,99,99,99,99,13,99,12 }, // IntToPtr |
2078
2028
{ 5, 5, 5, 6, 6, 5, 5, 6, 6,11, 5, 1 }, // BitCast -+
2031
// If either of the casts are a bitcast from scalar to vector, disallow the
2033
if ((firstOp == Instruction::BitCast &&
2034
isa<VectorType>(SrcTy) != isa<VectorType>(MidTy)) ||
2035
(secondOp == Instruction::BitCast &&
2036
isa<VectorType>(MidTy) != isa<VectorType>(DstTy)))
2037
return 0; // Disallowed
2081
2039
int ElimCase = CastResults[firstOp-Instruction::CastOpsBegin]
2082
2040
[secondOp-Instruction::CastOpsBegin];