Skip to content

[ctxprof][nfc] Move profile annotator to Analysis #135871

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions llvm/include/llvm/Analysis/CtxProfAnalysis.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,34 @@ class CtxProfAnalysisPrinterPass
const PrintMode Mode;
};

/// Utility that propagates counter values to each basic block and to each edge
/// when a basic block has more than one outgoing edge, using an adaptation of
/// PGOUseFunc::populateCounters.
// FIXME(mtrofin): look into factoring the code to share one implementation.
class ProfileAnnotatorImpl;
class ProfileAnnotator {
std::unique_ptr<ProfileAnnotatorImpl> PImpl;

public:
ProfileAnnotator(const Function &F, ArrayRef<uint64_t> RawCounters);
uint64_t getBBCount(const BasicBlock &BB) const;

// Finds the true and false counts for the given select instruction. Returns
// false if the select doesn't have instrumentation or if the count of the
// parent BB is 0.
bool getSelectInstrProfile(SelectInst &SI, uint64_t &TrueCount,
uint64_t &FalseCount) const;
// Clears Profile and populates it with the edge weights, in the same order as
// they need to appear in the MD_prof metadata. Also computes the max of those
// weights an returns it in MaxCount. Returs false if:
// - the BB has less than 2 successors
// - the counts are 0
bool getOutgoingBranchWeights(BasicBlock &BB,
SmallVectorImpl<uint64_t> &Profile,
uint64_t &MaxCount) const;
~ProfileAnnotator();
};

/// Assign a GUID to functions as metadata. GUID calculation takes linkage into
/// account, which may change especially through and after thinlto. By
/// pre-computing and assigning as metadata, this mechanism is resilient to such
Expand Down
Loading
Loading