diff options
author | Chandler Carruth <chandlerc@gmail.com> | 2019-01-07 07:31:49 +0000 |
---|---|---|
committer | Chandler Carruth <chandlerc@gmail.com> | 2019-01-07 07:31:49 +0000 |
commit | 90c09232a2e508da54ee67e61dcdc6b507b5b1f9 (patch) | |
tree | 5a6319a8876f0d34aa30ca4bfe7892c5b1a64b17 /llvm/lib | |
parent | 57578aaf96129bb2afbb75bc2523aa47fc1aa993 (diff) | |
download | bcm5719-llvm-90c09232a2e508da54ee67e61dcdc6b507b5b1f9.tar.gz bcm5719-llvm-90c09232a2e508da54ee67e61dcdc6b507b5b1f9.zip |
[CallSite removal] Move the rest of IR implementation code away from
`CallSite`.
With this change, the remaining `CallSite` usages are just for
implementing the wrapper type itself.
This does update the C API but leaves the names of that API alone and
only updates their implementation.
Differential Revision: https://reviews.llvm.org/D56184
llvm-svn: 350509
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/IR/AsmWriter.cpp | 15 | ||||
-rw-r--r-- | llvm/lib/IR/Core.cpp | 37 | ||||
-rw-r--r-- | llvm/lib/IR/Function.cpp | 17 | ||||
-rw-r--r-- | llvm/lib/IR/Value.cpp | 26 |
4 files changed, 44 insertions, 51 deletions
diff --git a/llvm/lib/IR/AsmWriter.cpp b/llvm/lib/IR/AsmWriter.cpp index 36f4f3aa876..a5dc623e1a3 100644 --- a/llvm/lib/IR/AsmWriter.cpp +++ b/llvm/lib/IR/AsmWriter.cpp @@ -36,7 +36,6 @@ #include "llvm/IR/Attributes.h" #include "llvm/IR/BasicBlock.h" #include "llvm/IR/CFG.h" -#include "llvm/IR/CallSite.h" #include "llvm/IR/CallingConv.h" #include "llvm/IR/Comdat.h" #include "llvm/IR/Constant.h" @@ -998,9 +997,9 @@ void SlotTracker::processFunction() { // We allow direct calls to any llvm.foo function here, because the // target may not be linked into the optimizer. - if (auto CS = ImmutableCallSite(&I)) { + if (const auto *Call = dyn_cast<CallBase>(&I)) { // Add all the call attributes to the table. - AttributeSet Attrs = CS.getAttributes().getFnAttributes(); + AttributeSet Attrs = Call->getAttributes().getFnAttributes(); if (Attrs.hasAttributes()) CreateAttributeSetSlot(Attrs); } @@ -2359,7 +2358,7 @@ public: void writeOperand(const Value *Op, bool PrintType); void writeParamOperand(const Value *Operand, AttributeSet Attrs); - void writeOperandBundles(ImmutableCallSite CS); + void writeOperandBundles(const CallBase *Call); void writeSyncScope(const LLVMContext &Context, SyncScope::ID SSID); void writeAtomic(const LLVMContext &Context, @@ -2510,15 +2509,15 @@ void AssemblyWriter::writeParamOperand(const Value *Operand, WriteAsOperandInternal(Out, Operand, &TypePrinter, &Machine, TheModule); } -void AssemblyWriter::writeOperandBundles(ImmutableCallSite CS) { - if (!CS.hasOperandBundles()) +void AssemblyWriter::writeOperandBundles(const CallBase *Call) { + if (!Call->hasOperandBundles()) return; Out << " [ "; bool FirstBundle = true; - for (unsigned i = 0, e = CS.getNumOperandBundles(); i != e; ++i) { - OperandBundleUse BU = CS.getOperandBundleAt(i); + for (unsigned i = 0, e = Call->getNumOperandBundles(); i != e; ++i) { + OperandBundleUse BU = Call->getOperandBundleAt(i); if (!FirstBundle) Out << ", "; diff --git a/llvm/lib/IR/Core.cpp b/llvm/lib/IR/Core.cpp index ce79fdc9ceb..4064b674fa0 100644 --- a/llvm/lib/IR/Core.cpp +++ b/llvm/lib/IR/Core.cpp @@ -15,7 +15,6 @@ #include "llvm-c/Core.h" #include "llvm/ADT/StringSwitch.h" #include "llvm/IR/Attributes.h" -#include "llvm/IR/CallSite.h" #include "llvm/IR/Constants.h" #include "llvm/IR/DebugInfoMetadata.h" #include "llvm/IR/DerivedTypes.h" @@ -2656,43 +2655,43 @@ unsigned LLVMGetNumArgOperands(LLVMValueRef Instr) { if (FuncletPadInst *FPI = dyn_cast<FuncletPadInst>(unwrap(Instr))) { return FPI->getNumArgOperands(); } - return CallSite(unwrap<Instruction>(Instr)).getNumArgOperands(); + return unwrap<CallBase>(Instr)->getNumArgOperands(); } /*--.. Call and invoke instructions ........................................--*/ unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr) { - return CallSite(unwrap<Instruction>(Instr)).getCallingConv(); + return unwrap<CallBase>(Instr)->getCallingConv(); } void LLVMSetInstructionCallConv(LLVMValueRef Instr, unsigned CC) { - return CallSite(unwrap<Instruction>(Instr)) - .setCallingConv(static_cast<CallingConv::ID>(CC)); + return unwrap<CallBase>(Instr)->setCallingConv( + static_cast<CallingConv::ID>(CC)); } void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index, unsigned align) { - CallSite Call = CallSite(unwrap<Instruction>(Instr)); + auto *Call = unwrap<CallBase>(Instr); Attribute AlignAttr = Attribute::getWithAlignment(Call->getContext(), align); - Call.addAttribute(index, AlignAttr); + Call->addAttribute(index, AlignAttr); } void LLVMAddCallSiteAttribute(LLVMValueRef C, LLVMAttributeIndex Idx, LLVMAttributeRef A) { - CallSite(unwrap<Instruction>(C)).addAttribute(Idx, unwrap(A)); + unwrap<CallBase>(C)->addAttribute(Idx, unwrap(A)); } unsigned LLVMGetCallSiteAttributeCount(LLVMValueRef C, LLVMAttributeIndex Idx) { - auto CS = CallSite(unwrap<Instruction>(C)); - auto AS = CS.getAttributes().getAttributes(Idx); + auto *Call = unwrap<CallBase>(C); + auto AS = Call->getAttributes().getAttributes(Idx); return AS.getNumAttributes(); } void LLVMGetCallSiteAttributes(LLVMValueRef C, LLVMAttributeIndex Idx, LLVMAttributeRef *Attrs) { - auto CS = CallSite(unwrap<Instruction>(C)); - auto AS = CS.getAttributes().getAttributes(Idx); + auto *Call = unwrap<CallBase>(C); + auto AS = Call->getAttributes().getAttributes(Idx); for (auto A : AS) *Attrs++ = wrap(A); } @@ -2700,30 +2699,28 @@ void LLVMGetCallSiteAttributes(LLVMValueRef C, LLVMAttributeIndex Idx, LLVMAttributeRef LLVMGetCallSiteEnumAttribute(LLVMValueRef C, LLVMAttributeIndex Idx, unsigned KindID) { - return wrap(CallSite(unwrap<Instruction>(C)) - .getAttribute(Idx, (Attribute::AttrKind)KindID)); + return wrap( + unwrap<CallBase>(C)->getAttribute(Idx, (Attribute::AttrKind)KindID)); } LLVMAttributeRef LLVMGetCallSiteStringAttribute(LLVMValueRef C, LLVMAttributeIndex Idx, const char *K, unsigned KLen) { - return wrap(CallSite(unwrap<Instruction>(C)) - .getAttribute(Idx, StringRef(K, KLen))); + return wrap(unwrap<CallBase>(C)->getAttribute(Idx, StringRef(K, KLen))); } void LLVMRemoveCallSiteEnumAttribute(LLVMValueRef C, LLVMAttributeIndex Idx, unsigned KindID) { - CallSite(unwrap<Instruction>(C)) - .removeAttribute(Idx, (Attribute::AttrKind)KindID); + unwrap<CallBase>(C)->removeAttribute(Idx, (Attribute::AttrKind)KindID); } void LLVMRemoveCallSiteStringAttribute(LLVMValueRef C, LLVMAttributeIndex Idx, const char *K, unsigned KLen) { - CallSite(unwrap<Instruction>(C)).removeAttribute(Idx, StringRef(K, KLen)); + unwrap<CallBase>(C)->removeAttribute(Idx, StringRef(K, KLen)); } LLVMValueRef LLVMGetCalledValue(LLVMValueRef Instr) { - return wrap(CallSite(unwrap<Instruction>(Instr)).getCalledValue()); + return wrap(unwrap<CallBase>(Instr)->getCalledValue()); } /*--.. Operations on call instructions (only) ..............................--*/ diff --git a/llvm/lib/IR/Function.cpp b/llvm/lib/IR/Function.cpp index ec094812ceb..a88478b89bf 100644 --- a/llvm/lib/IR/Function.cpp +++ b/llvm/lib/IR/Function.cpp @@ -24,7 +24,6 @@ #include "llvm/IR/Argument.h" #include "llvm/IR/Attributes.h" #include "llvm/IR/BasicBlock.h" -#include "llvm/IR/CallSite.h" #include "llvm/IR/Constant.h" #include "llvm/IR/Constants.h" #include "llvm/IR/DerivedTypes.h" @@ -1257,13 +1256,13 @@ bool Function::hasAddressTaken(const User* *PutOffender) const { const User *FU = U.getUser(); if (isa<BlockAddress>(FU)) continue; - if (!isa<CallInst>(FU) && !isa<InvokeInst>(FU)) { + const auto *Call = dyn_cast<CallBase>(FU); + if (!Call) { if (PutOffender) *PutOffender = FU; return true; } - ImmutableCallSite CS(cast<Instruction>(FU)); - if (!CS.isCallee(&U)) { + if (!Call->isCallee(&U)) { if (PutOffender) *PutOffender = FU; return true; @@ -1289,12 +1288,10 @@ bool Function::isDefTriviallyDead() const { /// callsFunctionThatReturnsTwice - Return true if the function has a call to /// setjmp or other function that gcc recognizes as "returning twice". bool Function::callsFunctionThatReturnsTwice() const { - for (const_inst_iterator - I = inst_begin(this), E = inst_end(this); I != E; ++I) { - ImmutableCallSite CS(&*I); - if (CS && CS.hasFnAttr(Attribute::ReturnsTwice)) - return true; - } + for (const Instruction &I : instructions(this)) + if (const auto *Call = dyn_cast<CallBase>(&I)) + if (Call->hasFnAttr(Attribute::ReturnsTwice)) + return true; return false; } diff --git a/llvm/lib/IR/Value.cpp b/llvm/lib/IR/Value.cpp index dc8af6b68e7..80b993c89f7 100644 --- a/llvm/lib/IR/Value.cpp +++ b/llvm/lib/IR/Value.cpp @@ -16,7 +16,6 @@ #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/SmallString.h" #include "llvm/ADT/SetVector.h" -#include "llvm/IR/CallSite.h" #include "llvm/IR/Constant.h" #include "llvm/IR/Constants.h" #include "llvm/IR/DataLayout.h" @@ -503,8 +502,8 @@ static const Value *stripPointerCastsAndOffsets(const Value *V) { return V; V = GA->getAliasee(); } else { - if (auto CS = ImmutableCallSite(V)) { - if (const Value *RV = CS.getReturnedArgOperand()) { + if (const auto *Call = dyn_cast<CallBase>(V)) { + if (const Value *RV = Call->getReturnedArgOperand()) { V = RV; continue; } @@ -512,9 +511,9 @@ static const Value *stripPointerCastsAndOffsets(const Value *V) { // but it can't be marked with returned attribute, that's why it needs // special case. if (StripKind == PSK_ZeroIndicesAndAliasesAndInvariantGroups && - (CS.getIntrinsicID() == Intrinsic::launder_invariant_group || - CS.getIntrinsicID() == Intrinsic::strip_invariant_group)) { - V = CS.getArgOperand(0); + (Call->getIntrinsicID() == Intrinsic::launder_invariant_group || + Call->getIntrinsicID() == Intrinsic::strip_invariant_group)) { + V = Call->getArgOperand(0); continue; } } @@ -573,8 +572,8 @@ Value::stripAndAccumulateInBoundsConstantOffsets(const DataLayout &DL, } else if (auto *GA = dyn_cast<GlobalAlias>(V)) { V = GA->getAliasee(); } else { - if (auto CS = ImmutableCallSite(V)) - if (const Value *RV = CS.getReturnedArgOperand()) { + if (const auto *Call = dyn_cast<CallBase>(V)) + if (const Value *RV = Call->getReturnedArgOperand()) { V = RV; continue; } @@ -608,10 +607,11 @@ uint64_t Value::getPointerDereferenceableBytes(const DataLayout &DL, DerefBytes = A->getDereferenceableOrNullBytes(); CanBeNull = true; } - } else if (auto CS = ImmutableCallSite(this)) { - DerefBytes = CS.getDereferenceableBytes(AttributeList::ReturnIndex); + } else if (const auto *Call = dyn_cast<CallBase>(this)) { + DerefBytes = Call->getDereferenceableBytes(AttributeList::ReturnIndex); if (DerefBytes == 0) { - DerefBytes = CS.getDereferenceableOrNullBytes(AttributeList::ReturnIndex); + DerefBytes = + Call->getDereferenceableOrNullBytes(AttributeList::ReturnIndex); CanBeNull = true; } } else if (const LoadInst *LI = dyn_cast<LoadInst>(this)) { @@ -683,8 +683,8 @@ unsigned Value::getPointerAlignment(const DataLayout &DL) const { if (AllocatedType->isSized()) Align = DL.getPrefTypeAlignment(AllocatedType); } - } else if (auto CS = ImmutableCallSite(this)) - Align = CS.getAttributes().getRetAlignment(); + } else if (const auto *Call = dyn_cast<CallBase>(this)) + Align = Call->getAttributes().getRetAlignment(); else if (const LoadInst *LI = dyn_cast<LoadInst>(this)) if (MDNode *MD = LI->getMetadata(LLVMContext::MD_align)) { ConstantInt *CI = mdconst::extract<ConstantInt>(MD->getOperand(0)); |