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

1

2

3

4

5

6

7

8

9

10

11

12

13

21

22using namespace llvm;

23

24

25

33

41

42

43

45 const char *Val) {

48}

49

50

51

52

53

54

56 std::vector<Metadata *> Entries;

59 for (auto &Entry : DetailedSummary) {

65 }

69}

70

71

72

73

74

75

76

77

78

79

81 bool AddPartialProfileRatioField) {

82 const char *KindStr[3] = {"InstrProf", "CSInstrProf", "SampleProfile"};

93 if (AddPartialField)

96 if (AddPartialProfileRatioField)

99 Components.push_back(getDetailedSummaryMD(Context));

101}

102

103

105 if (!MD)

106 return nullptr;

108 return nullptr;

111 if (!KeyMD || !ValMD)

112 return nullptr;

114 return nullptr;

115 return ValMD;

116}

117

118

122 return true;

123 }

124 return false;

125}

126

129 Val = cast(ValMD->getValue())->getValueAPF().convertToDouble();

130 return true;

131 }

132 return false;

133}

134

135

138 return false;

141 if (!KeyMD || !ValMD)

142 return false;

144 return false;

145 return true;

146}

147

148

151 return false;

153 if (!KeyMD || KeyMD->getString() != "DetailedSummary")

154 return false;

156 if (!EntriesMD)

157 return false;

158 for (auto &&MDOp : EntriesMD->operands()) {

161 return false;

168

169 if (!Op0 || !Op1 || !Op2)

170 return false;

174 }

175 return true;

176}

177

178

179

180template

184 Idx++;

185

186

187

188 return Idx < Tuple->getNumOperands();

189 }

190

191 return true;

192}

193

196 if (!Tuple || Tuple->getNumOperands() < 8 || Tuple->getNumOperands() > 10)

197 return nullptr;

198

199 unsigned I = 0;

200 auto &FormatMD = Tuple->getOperand(I++);

203 "SampleProfile"))

206 "InstrProf"))

209 "CSInstrProf"))

211 else

212 return nullptr;

213

214 uint64_t NumCounts, TotalCount, NumFunctions, MaxFunctionCount, MaxCount,

215 MaxInternalCount;

217 TotalCount))

218 return nullptr;

220 return nullptr;

222 MaxInternalCount))

223 return nullptr;

225 MaxFunctionCount))

226 return nullptr;

228 NumCounts))

229 return nullptr;

231 NumFunctions))

232 return nullptr;

233

234

235 uint64_t IsPartialProfile = 0;

236 if (getOptionalVal(Tuple, I, "IsPartialProfile", IsPartialProfile))

237 return nullptr;

238 double PartialProfileRatio = 0;

239 if (getOptionalVal(Tuple, I, "PartialProfileRatio", PartialProfileRatio))

240 return nullptr;

241

244 return nullptr;

245 return new ProfileSummary(SummaryKind, std::move(Summary), TotalCount,

246 MaxCount, MaxInternalCount, MaxFunctionCount,

247 NumCounts, NumFunctions, IsPartialProfile,

248 PartialProfileRatio);

249}

250

252 OS << "Total functions: " << NumFunctions << "\n";

253 OS << "Maximum function count: " << MaxFunctionCount << "\n";

254 OS << "Maximum internal block count: " << MaxInternalCount << "\n";

255 OS << "Total number of blocks: " << NumCounts << "\n";

256 OS << "Total count: " << TotalCount << "\n";

257}

258

260 OS << "Detailed summary:\n";

261 for (const auto &Entry : DetailedSummary) {

262 OS << Entry.NumCounts << " blocks "

263 << format("(%.2f%%)",

264 NumCounts ? (100.f * Entry.NumCounts / NumCounts) : 0)

265 << " with count >= " << Entry.MinCount << " account for "

266 << format("%0.6g", 100.f * Entry.Cutoff / Scale)

267 << "% of the total counts.\n";

268 }

269}

This file contains the declarations for the subclasses of Constant, which represent the different fla...

const AbstractManglingParser< Derived, Alloc >::OperatorInfo AbstractManglingParser< Derived, Alloc >::Ops[]

static ConstantAsMetadata * getValMD(MDTuple *MD, const char *Key)

Definition ProfileSummary.cpp:104

static Metadata * getKeyFPValMD(LLVMContext &Context, const char *Key, double Val)

Definition ProfileSummary.cpp:34

static bool isKeyValuePair(MDTuple *MD, const char *Key, const char *Val)

Definition ProfileSummary.cpp:136

static bool getOptionalVal(MDTuple *Tuple, unsigned &Idx, const char *Key, ValueType &Value)

Definition ProfileSummary.cpp:181

static bool getSummaryFromMD(MDTuple *MD, SummaryEntryVector &Summary)

Definition ProfileSummary.cpp:149

static Metadata * getKeyValMD(LLVMContext &Context, const char *Key, uint64_t Val)

Definition ProfileSummary.cpp:26

static bool getVal(MDTuple *MD, const char *Key, uint64_t &Val)

Definition ProfileSummary.cpp:119

This is an important class for using LLVM in a threaded context.

const MDOperand & getOperand(unsigned I) const

ArrayRef< MDOperand > operands() const

unsigned getNumOperands() const

Return number of MDNode operands.

LLVM_ABI StringRef getString() const

static LLVM_ABI MDString * get(LLVMContext &Context, StringRef Str)

static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)

uint64_t getTotalCount() const

uint64_t getMaxCount() const

LLVM_ABI Metadata * getMD(LLVMContext &Context, bool AddPartialField=true, bool AddPartialProfileRatioField=true)

Return summary information as metadata.

Definition ProfileSummary.cpp:80

uint32_t getNumCounts() const

ProfileSummary(Kind K, const SummaryEntryVector &DetailedSummary, uint64_t TotalCount, uint64_t MaxCount, uint64_t MaxInternalCount, uint64_t MaxFunctionCount, uint32_t NumCounts, uint32_t NumFunctions, bool Partial=false, double PartialProfileRatio=0)

LLVM_ABI void printDetailedSummary(raw_ostream &OS) const

Definition ProfileSummary.cpp:259

uint64_t getMaxInternalCount() const

bool isPartialProfile() const

static LLVM_ABI ProfileSummary * getFromMD(Metadata *MD)

Construct profile summary from metdata.

Definition ProfileSummary.cpp:194

uint64_t getMaxFunctionCount() const

LLVM_ABI void printSummary(raw_ostream &OS) const

Definition ProfileSummary.cpp:251

double getPartialProfileRatio() const

uint32_t getNumFunctions() const

void push_back(const T &Elt)

This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.

The instances of the Type class are immutable: once they are created, they are never changed.

static LLVM_ABI IntegerType * getInt64Ty(LLVMContext &C)

static LLVM_ABI IntegerType * getInt32Ty(LLVMContext &C)

static LLVM_ABI Type * getDoubleTy(LLVMContext &C)

LLVM Value Representation.

This class implements an extremely fast bulk output stream that can only output to a stream.

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.

FunctionAddr VTableAddr uintptr_t uintptr_t Int32Ty

auto dyn_cast_or_null(const Y &Val)

format_object< Ts... > format(const char *Fmt, const Ts &... Vals)

These are helper functions used to produce formatted output.

LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key

decltype(auto) cast(const From &Val)

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

PointerUnion< const Value *, const PseudoSourceValue * > ValueType

std::vector< ProfileSummaryEntry > SummaryEntryVector