@@ -202,55 +202,59 @@ void printCallGraphFlowConservationStats(
202202 TotalFlowMap.CallGraphIncomingFlows ;
203203
204204 // Only consider functions that are not a program entry.
205- if (CallGraphIncomingFlows.find (FunctionNum) !=
206- CallGraphIncomingFlows.end ()) {
207- uint64_t EntryInflow = 0 ;
208- uint64_t EntryOutflow = 0 ;
209- uint32_t NumConsideredEntryBlocks = 0 ;
210-
211- Function->forEachEntryPoint ([&](uint64_t Offset, const MCSymbol *Label) {
212- const BinaryBasicBlock *EntryBB =
213- Function->getBasicBlockAtOffset (Offset);
214- if (!EntryBB || EntryBB->succ_size () == 0 )
215- return true ;
216- NumConsideredEntryBlocks++;
217- EntryInflow += IncomingFlows[EntryBB->getLayoutIndex ()];
218- EntryOutflow += OutgoingFlows[EntryBB->getLayoutIndex ()];
205+ if (CallGraphIncomingFlows.find (FunctionNum) == CallGraphIncomingFlows.end ()) {
206+ CallGraphGaps.push_back (0.0 );
207+ continue ;
208+ }
209+
210+ uint64_t EntryInflow = 0 ;
211+ uint64_t EntryOutflow = 0 ;
212+ uint32_t NumConsideredEntryBlocks = 0 ;
213+
214+ Function->forEachEntryPoint ([&](uint64_t Offset, const MCSymbol *Label) {
215+ const BinaryBasicBlock *EntryBB =
216+ Function->getBasicBlockAtOffset (Offset);
217+ if (!EntryBB || EntryBB->succ_size () == 0 )
219218 return true ;
220- });
221-
222- uint64_t NetEntryOutflow = 0 ;
223- if (EntryOutflow < EntryInflow) {
224- if (opts::Verbosity >= 2 ) {
225- // We expect entry blocks' CFG outflow >= inflow, i.e., it has a
226- // non-negative net outflow. If this is not the case, then raise a
227- // warning if requested.
228- OS << " BOLT WARNING: unexpected entry block CFG outflow < inflow "
229- " in function "
230- << Function->getPrintName () << " \n " ;
231- if (opts::Verbosity >= 3 )
232- Function->dump ();
233- }
234- } else {
235- NetEntryOutflow = EntryOutflow - EntryInflow;
236- }
237- if (NumConsideredEntryBlocks > 0 ) {
238- const uint64_t CallGraphInflow =
239- TotalFlowMap.CallGraphIncomingFlows [Function->getFunctionNumber ()];
240- const uint64_t Min = std::min (NetEntryOutflow, CallGraphInflow);
241- const uint64_t Max = std::max (NetEntryOutflow, CallGraphInflow);
242- const double CallGraphGap = 1 - (double )Min / Max;
243-
244- if (opts::Verbosity >= 2 && CallGraphGap >= 0.5 ) {
245- OS << " Nontrivial call graph gap of size "
246- << formatv (" {0:P}" , CallGraphGap) << " observed in function "
247- << Function->getPrintName () << " \n " ;
248- if (opts::Verbosity >= 3 )
249- Function->dump ();
250- }
219+ NumConsideredEntryBlocks++;
220+ EntryInflow += IncomingFlows[EntryBB->getLayoutIndex ()];
221+ EntryOutflow += OutgoingFlows[EntryBB->getLayoutIndex ()];
222+ return true ;
223+ });
251224
252- CallGraphGaps.push_back (CallGraphGap);
225+ uint64_t NetEntryOutflow = 0 ;
226+ if (EntryOutflow < EntryInflow) {
227+ if (opts::Verbosity >= 2 ) {
228+ // We expect entry blocks' CFG outflow >= inflow, i.e., it has a
229+ // non-negative net outflow. If this is not the case, then raise a
230+ // warning if requested.
231+ OS << " BOLT WARNING: unexpected entry block CFG outflow < inflow "
232+ " in function "
233+ << Function->getPrintName () << " \n " ;
234+ if (opts::Verbosity >= 3 )
235+ Function->dump ();
253236 }
237+ } else {
238+ NetEntryOutflow = EntryOutflow - EntryInflow;
239+ }
240+ if (NumConsideredEntryBlocks > 0 ) {
241+ const uint64_t CallGraphInflow =
242+ TotalFlowMap.CallGraphIncomingFlows [Function->getFunctionNumber ()];
243+ const uint64_t Min = std::min (NetEntryOutflow, CallGraphInflow);
244+ const uint64_t Max = std::max (NetEntryOutflow, CallGraphInflow);
245+ const double CallGraphGap = 1 - (double )Min / Max;
246+
247+ if (opts::Verbosity >= 2 && CallGraphGap >= 0.5 ) {
248+ OS << " Nontrivial call graph gap of size "
249+ << formatv (" {0:P}" , CallGraphGap) << " observed in function "
250+ << Function->getPrintName () << " \n " ;
251+ if (opts::Verbosity >= 3 )
252+ Function->dump ();
253+ }
254+
255+ CallGraphGaps.push_back (CallGraphGap);
256+ } else {
257+ CallGraphGaps.push_back (0.0 );
254258 }
255259 }
256260
0 commit comments