56 std::vector<Metadata *> Entries;
59 for (
auto &Entry : DetailedSummary) {
81 bool AddPartialProfileRatioField) {
82 const char *KindStr[3] = {
"InstrProf",
"CSInstrProf",
"SampleProfile"};
96 if (AddPartialProfileRatioField)
99 Components.
push_back(getDetailedSummaryMD(Context));
111 if (!KeyMD || !ValMD)
120 if (
auto *ValMD =
getValMD(MD, Key)) {
121 Val = cast<ConstantInt>(ValMD->getValue())->getZExtValue();
128 if (
auto *ValMD =
getValMD(MD, Key)) {
129 Val = cast<ConstantFP>(ValMD->getValue())->getValueAPF().convertToDouble();
141 if (!KeyMD || !ValMD)
153 if (!KeyMD || KeyMD->
getString() !=
"DetailedSummary")
158 for (
auto &&MDOp : EntriesMD->
operands()) {
159 MDTuple *EntryMD = dyn_cast<MDTuple>(MDOp);
163 dyn_cast<ConstantAsMetadata>(EntryMD->
getOperand(0));
165 dyn_cast<ConstantAsMetadata>(EntryMD->
getOperand(1));
167 dyn_cast<ConstantAsMetadata>(EntryMD->
getOperand(2));
169 if (!Op0 || !Op1 || !Op2)
171 Summary.emplace_back(cast<ConstantInt>(Op0->
getValue())->getZExtValue(),
172 cast<ConstantInt>(Op1->
getValue())->getZExtValue(),
173 cast<ConstantInt>(Op2->
getValue())->getZExtValue());
180template <
typename ValueType>
195 MDTuple *Tuple = dyn_cast_or_null<MDTuple>(MD);
202 if (
isKeyValuePair(dyn_cast_or_null<MDTuple>(FormatMD),
"ProfileFormat",
205 else if (
isKeyValuePair(dyn_cast_or_null<MDTuple>(FormatMD),
"ProfileFormat",
208 else if (
isKeyValuePair(dyn_cast_or_null<MDTuple>(FormatMD),
"ProfileFormat",
214 uint64_t NumCounts, TotalCount, NumFunctions, MaxFunctionCount, MaxCount,
238 double PartialProfileRatio = 0;
239 if (!
getOptionalVal(Tuple,
I,
"PartialProfileRatio", PartialProfileRatio))
245 return new ProfileSummary(SummaryKind, std::move(Summary), TotalCount,
246 MaxCount, MaxInternalCount, MaxFunctionCount,
247 NumCounts, NumFunctions, IsPartialProfile,
248 PartialProfileRatio);
252 OS <<
"Total functions: " << NumFunctions <<
"\n";
253 OS <<
"Maximum function count: " << MaxFunctionCount <<
"\n";
254 OS <<
"Maximum block count: " << MaxCount <<
"\n";
255 OS <<
"Total number of blocks: " << NumCounts <<
"\n";
256 OS <<
"Total count: " << TotalCount <<
"\n";
260 OS <<
"Detailed summary:\n";
261 for (
const auto &Entry : DetailedSummary) {
262 OS << Entry.NumCounts <<
" blocks with count >= " << Entry.MinCount
264 <<
format(
"%0.6g", (
float)Entry.Cutoff /
Scale * 100)
265 <<
" percentage of the total counts.\n";
This file contains the declarations for the subclasses of Constant, which represent the different fla...
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
static ConstantAsMetadata * getValMD(MDTuple *MD, const char *Key)
static Metadata * getKeyFPValMD(LLVMContext &Context, const char *Key, double Val)
static bool isKeyValuePair(MDTuple *MD, const char *Key, const char *Val)
static bool getOptionalVal(MDTuple *Tuple, unsigned &Idx, const char *Key, ValueType &Value)
static bool getSummaryFromMD(MDTuple *MD, SummaryEntryVector &Summary)
static Metadata * getKeyValMD(LLVMContext &Context, const char *Key, uint64_t Val)
static bool getVal(MDTuple *MD, const char *Key, uint64_t &Val)
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.
StringRef getString() const
static MDString * get(LLVMContext &Context, StringRef Str)
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
uint64_t getTotalCount() const
uint64_t getMaxCount() const
Metadata * getMD(LLVMContext &Context, bool AddPartialField=true, bool AddPartialProfileRatioField=true)
Return summary information as metadata.
uint32_t getNumCounts() const
void printDetailedSummary(raw_ostream &OS) const
uint64_t getMaxInternalCount() const
bool isPartialProfile() const
static ProfileSummary * getFromMD(Metadata *MD)
Construct profile summary from metdata.
uint64_t getMaxFunctionCount() const
void printSummary(raw_ostream &OS) const
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 Type * getDoubleTy(LLVMContext &C)
static IntegerType * getInt32Ty(LLVMContext &C)
static IntegerType * getInt64Ty(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.
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
std::vector< ProfileSummaryEntry > SummaryEntryVector