Index: llvm/include/llvm/IR/InstrTypes.h =================================================================== --- llvm/include/llvm/IR/InstrTypes.h +++ llvm/include/llvm/IR/InstrTypes.h @@ -1185,6 +1185,14 @@ /// Return true if the callsite is an indirect call. bool isIndirectCall() const; + /// Determine whether the passed iterator points to the callee operand's Use. + bool isCallee(Value::const_user_iterator UI) const { + return isCallee(&UI.getUse()); + } + + /// Determine whether this Use is the callee operand's Use. + bool isCallee(const Use *U) const { return &getCalledOperandUse() == U; } + /// Helper to get the caller (the parent function). Function *getCaller(); const Function *getCaller() const { Index: llvm/include/llvm/IR/PatternMatch.h =================================================================== --- llvm/include/llvm/IR/PatternMatch.h +++ llvm/include/llvm/IR/PatternMatch.h @@ -31,7 +31,6 @@ #include "llvm/ADT/APFloat.h" #include "llvm/ADT/APInt.h" -#include "llvm/IR/CallSite.h" #include "llvm/IR/Constant.h" #include "llvm/IR/Constants.h" #include "llvm/IR/InstrTypes.h" @@ -1486,8 +1485,9 @@ Argument_match(unsigned OpIdx, const Opnd_t &V) : OpI(OpIdx), Val(V) {} template bool match(OpTy *V) { - CallSite CS(V); - return CS.isCall() && Val.match(CS.getArgument(OpI)); + // FIXME: Should likely be switched to use `CallBase`. + auto *CI = dyn_cast(V); + return CI && Val.match(CI->getArgOperand(OpI)); } }; Index: llvm/lib/IR/AsmWriter.cpp =================================================================== --- llvm/lib/IR/AsmWriter.cpp +++ 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 @@ // 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(&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 @@ 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 @@ 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 << ", "; Index: llvm/lib/IR/Core.cpp =================================================================== --- llvm/lib/IR/Core.cpp +++ 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" @@ -2648,43 +2647,43 @@ if (FuncletPadInst *FPI = dyn_cast(unwrap(Instr))) { return FPI->getNumArgOperands(); } - return CallSite(unwrap(Instr)).getNumArgOperands(); + return unwrap(Instr)->getNumArgOperands(); } /*--.. Call and invoke instructions ........................................--*/ unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr) { - return CallSite(unwrap(Instr)).getCallingConv(); + return unwrap(Instr)->getCallingConv(); } void LLVMSetInstructionCallConv(LLVMValueRef Instr, unsigned CC) { - return CallSite(unwrap(Instr)) - .setCallingConv(static_cast(CC)); + return unwrap(Instr)->setCallingConv( + static_cast(CC)); } void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index, unsigned align) { - CallSite Call = CallSite(unwrap(Instr)); + auto *Call = unwrap(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(C)).addAttribute(Idx, unwrap(A)); + unwrap(C)->addAttribute(Idx, unwrap(A)); } unsigned LLVMGetCallSiteAttributeCount(LLVMValueRef C, LLVMAttributeIndex Idx) { - auto CS = CallSite(unwrap(C)); - auto AS = CS.getAttributes().getAttributes(Idx); + auto *Call = unwrap(C); + auto AS = Call->getAttributes().getAttributes(Idx); return AS.getNumAttributes(); } void LLVMGetCallSiteAttributes(LLVMValueRef C, LLVMAttributeIndex Idx, LLVMAttributeRef *Attrs) { - auto CS = CallSite(unwrap(C)); - auto AS = CS.getAttributes().getAttributes(Idx); + auto *Call = unwrap(C); + auto AS = Call->getAttributes().getAttributes(Idx); for (auto A : AS) *Attrs++ = wrap(A); } @@ -2692,30 +2691,28 @@ LLVMAttributeRef LLVMGetCallSiteEnumAttribute(LLVMValueRef C, LLVMAttributeIndex Idx, unsigned KindID) { - return wrap(CallSite(unwrap(C)) - .getAttribute(Idx, (Attribute::AttrKind)KindID)); + return wrap( + unwrap(C)->getAttribute(Idx, (Attribute::AttrKind)KindID)); } LLVMAttributeRef LLVMGetCallSiteStringAttribute(LLVMValueRef C, LLVMAttributeIndex Idx, const char *K, unsigned KLen) { - return wrap(CallSite(unwrap(C)) - .getAttribute(Idx, StringRef(K, KLen))); + return wrap(unwrap(C)->getAttribute(Idx, StringRef(K, KLen))); } void LLVMRemoveCallSiteEnumAttribute(LLVMValueRef C, LLVMAttributeIndex Idx, unsigned KindID) { - CallSite(unwrap(C)) - .removeAttribute(Idx, (Attribute::AttrKind)KindID); + unwrap(C)->removeAttribute(Idx, (Attribute::AttrKind)KindID); } void LLVMRemoveCallSiteStringAttribute(LLVMValueRef C, LLVMAttributeIndex Idx, const char *K, unsigned KLen) { - CallSite(unwrap(C)).removeAttribute(Idx, StringRef(K, KLen)); + unwrap(C)->removeAttribute(Idx, StringRef(K, KLen)); } LLVMValueRef LLVMGetCalledValue(LLVMValueRef Instr) { - return wrap(CallSite(unwrap(Instr)).getCalledValue()); + return wrap(unwrap(Instr)->getCalledValue()); } /*--.. Operations on call instructions (only) ..............................--*/ Index: llvm/lib/IR/Function.cpp =================================================================== --- llvm/lib/IR/Function.cpp +++ 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 @@ const User *FU = U.getUser(); if (isa(FU)) continue; - if (!isa(FU) && !isa(FU)) { + const auto *Call = dyn_cast(FU); + if (!Call) { if (PutOffender) *PutOffender = FU; return true; } - ImmutableCallSite CS(cast(FU)); - if (!CS.isCallee(&U)) { + if (!Call->isCallee(&U)) { if (PutOffender) *PutOffender = FU; return true; @@ -1291,8 +1290,8 @@ 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)) + const auto *Call = dyn_cast(&*I); + if (Call && Call->hasFnAttr(Attribute::ReturnsTwice)) return true; } Index: llvm/lib/IR/Value.cpp =================================================================== --- llvm/lib/IR/Value.cpp +++ 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 @@ return V; V = GA->getAliasee(); } else { - if (auto CS = ImmutableCallSite(V)) { - if (const Value *RV = CS.getReturnedArgOperand()) { + if (const auto *Call = dyn_cast(V)) { + if (const Value *RV = Call->getReturnedArgOperand()) { V = RV; continue; } @@ -512,9 +511,9 @@ // 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 @@ } else if (auto *GA = dyn_cast(V)) { V = GA->getAliasee(); } else { - if (auto CS = ImmutableCallSite(V)) - if (const Value *RV = CS.getReturnedArgOperand()) { + if (const auto *Call = dyn_cast(V)) + if (const Value *RV = Call->getReturnedArgOperand()) { V = RV; continue; } @@ -608,10 +607,11 @@ DerefBytes = A->getDereferenceableOrNullBytes(); CanBeNull = true; } - } else if (auto CS = ImmutableCallSite(this)) { - DerefBytes = CS.getDereferenceableBytes(AttributeList::ReturnIndex); + } else if (const auto *Call = dyn_cast(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(this)) { @@ -683,8 +683,8 @@ if (AllocatedType->isSized()) Align = DL.getPrefTypeAlignment(AllocatedType); } - } else if (auto CS = ImmutableCallSite(this)) - Align = CS.getAttributes().getRetAlignment(); + } else if (const auto *Call = dyn_cast(this)) + Align = Call->getAttributes().getRetAlignment(); else if (const LoadInst *LI = dyn_cast(this)) if (MDNode *MD = LI->getMetadata(LLVMContext::MD_align)) { ConstantInt *CI = mdconst::extract(MD->getOperand(0));