@@ -157,6 +157,34 @@ class CtxProfAnalysisPrinterPass
157157 const PrintMode Mode;
158158};
159159
160+ // / Utility that propagates counter values to each basic block and to each edge
161+ // / when a basic block has more than one outgoing edge, using an adaptation of
162+ // / PGOUseFunc::populateCounters.
163+ // FIXME(mtrofin): look into factoring the code to share one implementation.
164+ class ProfileAnnotatorImpl ;
165+ class ProfileAnnotator {
166+ std::unique_ptr<ProfileAnnotatorImpl> PImpl;
167+
168+ public:
169+ ProfileAnnotator (const Function &F, ArrayRef<uint64_t > RawCounters);
170+ uint64_t getBBCount (const BasicBlock &BB) const ;
171+
172+ // Finds the true and false counts for the given select instruction. Returns
173+ // false if the select doesn't have instrumentation or if the count of the
174+ // parent BB is 0.
175+ bool getSelectInstrProfile (SelectInst &SI, uint64_t &TrueCount,
176+ uint64_t &FalseCount) const ;
177+ // Clears Profile and populates it with the edge weights, in the same order as
178+ // they need to appear in the MD_prof metadata. Also computes the max of those
179+ // weights an returns it in MaxCount. Returs false if:
180+ // - the BB has less than 2 successors
181+ // - the counts are 0
182+ bool getOutgoingBranchWeights (BasicBlock &BB,
183+ SmallVectorImpl<uint64_t > &Profile,
184+ uint64_t &MaxCount) const ;
185+ ~ProfileAnnotator ();
186+ };
187+
160188// / Assign a GUID to functions as metadata. GUID calculation takes linkage into
161189// / account, which may change especially through and after thinlto. By
162190// / pre-computing and assigning as metadata, this mechanism is resilient to such
0 commit comments