LLVM: lib/IR/AbstractCallSite.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

19

20using namespace llvm;

21

22#define DEBUG_TYPE "abstract-call-sites"

23

24STATISTIC(NumCallbackCallSites, "Number of callback call sites created");

26 "Number of direct abstract call sites created");

27STATISTIC(NumInvalidAbstractCallSitesUnknownUse,

28 "Number of invalid abstract call sites created (unknown use)");

29STATISTIC(NumInvalidAbstractCallSitesUnknownCallee,

30 "Number of invalid abstract call sites created (unknown callee)");

31STATISTIC(NumInvalidAbstractCallSitesNoCallback,

32 "Number of invalid abstract call sites created (no callback)");

33

36 const Function *Callee = CB.getCalledFunction();

37 if (!Callee)

38 return;

39

40 MDNode *CallbackMD = Callee->getMetadata(LLVMContext::MD_callback);

41 if (!CallbackMD)

42 return;

43

49 if (CBCalleeIdx < CB.arg_size())

50 CallbackUses.push_back(CB.arg_begin() + CBCalleeIdx);

51 }

52}

53

54

57

58

59 if (!CB) {

60

61

62

63

64

66 if (CE->hasOneUse() && CE->isCast()) {

67 U = &*CE->use_begin();

69 }

70

71 if (!CB) {

72 NumInvalidAbstractCallSitesUnknownUse++;

73 return;

74 }

75 }

76

77

78

79 if (CB->isCallee(U)) {

80 NumDirectAbstractCallSites++;

81 return;

82 }

83

84

85

86 Function *Callee = CB->getCalledFunction();

87 if (!Callee) {

88 NumInvalidAbstractCallSitesUnknownCallee++;

89 CB = nullptr;

90 return;

91 }

92

93 MDNode *CallbackMD = Callee->getMetadata(LLVMContext::MD_callback);

94 if (!CallbackMD) {

95 NumInvalidAbstractCallSitesNoCallback++;

96 CB = nullptr;

97 return;

98 }

99

100 unsigned UseIdx = CB->getArgOperandNo(U);

101 MDNode *CallbackEncMD = nullptr;

103 MDNode *OpMD = cast(Op.get());

104 auto *CBCalleeIdxAsCM = cast(OpMD->getOperand(0));

105 uint64_t CBCalleeIdx =

106 cast(CBCalleeIdxAsCM->getValue())->getZExtValue();

107 if (CBCalleeIdx != UseIdx)

108 continue;

109 CallbackEncMD = OpMD;

110 break;

111 }

112

113 if (!CallbackEncMD) {

114 NumInvalidAbstractCallSitesNoCallback++;

115 CB = nullptr;

116 return;

117 }

118

119 NumCallbackCallSites++;

120

121 assert(CallbackEncMD->getNumOperands() >= 2 && "Incomplete !callback metadata");

122

123 unsigned NumCallOperands = CB->arg_size();

124

125 for (unsigned u = 0, e = CallbackEncMD->getNumOperands() - 1; u < e; u++) {

128 assert(OpAsCM->getType()->isIntegerTy(64) &&

129 "Malformed !callback metadata");

130

131 int64_t Idx = cast(OpAsCM->getValue())->getSExtValue();

132 assert(-1 <= Idx && Idx <= NumCallOperands &&

133 "Out-of-bounds !callback metadata index");

134

135 CI.ParameterEncoding.push_back(Idx);

136 }

137

138 if (!Callee->isVarArg())

139 return;

140

144 assert(VarArgFlagAsCM->getType()->isIntegerTy(1) &&

145 "Malformed !callback metadata var-arg flag");

146

147 if (VarArgFlagAsCM->getValue()->isNullValue())

148 return;

149

150

151 for (unsigned u = Callee->arg_size(); u < NumCallOperands; u++)

152 CI.ParameterEncoding.push_back(u);

153}

assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")

This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...

#define STATISTIC(VARNAME, DESC)

static LLVM_ABI void getCallbackUses(const CallBase &CB, SmallVectorImpl< const Use * > &CallbackUses)

Add operand uses of CB that represent callback uses into CallbackUses.

Definition AbstractCallSite.cpp:34

LLVM_ABI AbstractCallSite(const Use *U)

Sole constructor for abstract call sites (ACS).

Definition AbstractCallSite.cpp:55

Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...

A constant value that is initialized with an expression using other constant values.

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 - Return the argument parameter cast to the specified type.

DWARFExpression::Operation Op

decltype(auto) cast(const From &Val)

cast - Return the argument parameter cast to the specified type.