[llvm] [BOLT] Add sink block to flow CFG in profile inference (PR #95047)

shaw young via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 12 14:24:56 PDT 2024


================
@@ -309,23 +309,28 @@ createFlowFunction(const BinaryFunction::BasicBlockOrderType &BlockOrder) {
   FlowFunction Func;
 
   // Add a special "dummy" source so that there is always a unique entry point.
-  // Because of the extra source, for all other blocks in FlowFunction it holds
-  // that Block.Index == BB->getIndex() + 1
   FlowBlock EntryBlock;
   EntryBlock.Index = 0;
   Func.Blocks.push_back(EntryBlock);
 
-  // Create FlowBlock for every basic block in the binary function
+  // Create FlowBlock for every basic block in the binary function.
   for (const BinaryBasicBlock *BB : BlockOrder) {
     Func.Blocks.emplace_back();
     FlowBlock &Block = Func.Blocks.back();
     Block.Index = Func.Blocks.size() - 1;
+    Block.IsExit = BB->successors().empty();
     (void)BB;
     assert(Block.Index == BB->getIndex() + 1 &&
            "incorrectly assigned basic block index");
   }
 
-  // Create FlowJump for each jump between basic blocks in the binary function
+  // Add a special "dummy" sink block so there is always a unique sink.
----------------
shawbyoung wrote:

In order to construct the artificial sink block and edges from exit blocks to the sink block, BinaryBasicBlock information is/will be needed, which is not currently exposed to SampleProfileInference/profi. For instance, identifying calls to functions that pass control back outside of the function (i.e. calls to std::terminate) requires BinaryBasicBlock information. (Identifying these calls is something I plan to implement in a subsequent commit). I think it also makes sense organizationally to do this in the construction of the flow function - it would be inelegant to expose BinaryBasicBlock information to profi (code duplicity) just to add the sink block. The construction of the entry block could be more easily moved to profi, but given that sink block should be constructed within createFlowFunction it makes sense for that block's construction to remain where it is as well.

https://github.com/llvm/llvm-project/pull/95047


More information about the llvm-commits mailing list