22#define DEBUG_TYPE "abstract-call-sites"
24STATISTIC(NumCallbackCallSites,
"Number of callback call sites created");
26 "Number of direct abstract call sites created");
28 "Number of invalid abstract call sites created (unknown use)");
30 "Number of invalid abstract call sites created (unknown callee)");
32 "Number of invalid abstract call sites created (no callback)");
40 MDNode *CallbackMD = Callee->getMetadata(LLVMContext::MD_callback);
45 MDNode *OpMD = cast<MDNode>(
Op.get());
46 auto *CBCalleeIdxAsCM = cast<ConstantAsMetadata>(OpMD->
getOperand(0));
48 cast<ConstantInt>(CBCalleeIdxAsCM->getValue())->getZExtValue();
65 if (
ConstantExpr *CE = dyn_cast<ConstantExpr>(U->getUser()))
66 if (CE->hasOneUse() && CE->isCast()) {
67 U = &*CE->use_begin();
68 CB = dyn_cast<CallBase>(U->getUser());
72 NumInvalidAbstractCallSitesUnknownUse++;
80 NumDirectAbstractCallSites++;
88 NumInvalidAbstractCallSitesUnknownCallee++;
93 MDNode *CallbackMD = Callee->getMetadata(LLVMContext::MD_callback);
95 NumInvalidAbstractCallSitesNoCallback++;
101 MDNode *CallbackEncMD =
nullptr;
103 MDNode *OpMD = cast<MDNode>(
Op.get());
104 auto *CBCalleeIdxAsCM = cast<ConstantAsMetadata>(OpMD->
getOperand(0));
106 cast<ConstantInt>(CBCalleeIdxAsCM->getValue())->getZExtValue();
107 if (CBCalleeIdx != UseIdx)
109 CallbackEncMD = OpMD;
113 if (!CallbackEncMD) {
114 NumInvalidAbstractCallSitesNoCallback++;
119 NumCallbackCallSites++;
123 unsigned NumCallOperands = CB->
arg_size();
125 for (
unsigned u = 0, e = CallbackEncMD->
getNumOperands() - 1; u < e; u++) {
127 auto *OpAsCM = cast<ConstantAsMetadata>(OpAsM);
128 assert(OpAsCM->getType()->isIntegerTy(64) &&
129 "Malformed !callback metadata");
131 int64_t
Idx = cast<ConstantInt>(OpAsCM->getValue())->getSExtValue();
133 "Out-of-bounds !callback metadata index");
138 if (!Callee->isVarArg())
143 auto *VarArgFlagAsCM = cast<ConstantAsMetadata>(VarArgFlagAsM);
144 assert(VarArgFlagAsCM->getType()->isIntegerTy(1) &&
145 "Malformed !callback metadata var-arg flag");
147 if (VarArgFlagAsCM->getValue()->isNullValue())
151 for (
unsigned u = Callee->arg_size(); u < NumCallOperands; u++)
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
static void getCallbackUses(const CallBase &CB, SmallVectorImpl< const Use * > &CallbackUses)
Add operand uses of CB that represent callback uses into CallbackUses.
AbstractCallSite(const Use *U)
Sole constructor for abstract call sites (ACS).
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
Function * getCalledFunction() const
Returns the function called, or null if this is an indirect function invocation or the function signa...
User::op_iterator arg_begin()
Return the iterator pointing to the beginning of the argument list.
bool isCallee(Value::const_user_iterator UI) const
Determine whether the passed iterator points to the callee operand's Use.
unsigned getArgOperandNo(const Use *U) const
Given a use for a arg operand, get the arg operand number that corresponds to it.
unsigned arg_size() const
A constant value that is initialized with an expression using other constant values.
This class represents an Operation in the Expression.
const MDOperand & getOperand(unsigned I) const
ArrayRef< MDOperand > operands() const
unsigned getNumOperands() const
Return number of MDNode operands.
Tracking metadata reference owned by Metadata.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void push_back(const T &Elt)
A Use represents the edge between a Value definition and its users.
This is an optimization pass for GlobalISel generic memory operations.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
ParameterEncodingTy ParameterEncoding