[profi][NFC] Refactor SampleProfileInference::initFunction
authorAmir Ayupov <aaupov@fb.com>
Fri, 9 Jun 2023 19:40:37 +0000 (12:40 -0700)
committerAmir Ayupov <aaupov@fb.com>
Fri, 9 Jun 2023 19:41:12 +0000 (12:41 -0700)
Initialize and return `FlowFunction` from initFunction->createFlowFunction.
Aligns the interface to `createFlowFunction` in D144500, intent to reuse
in a follow-up.

Reviewed By: spupyrev

Differential Revision: https://reviews.llvm.org/D152216

llvm/include/llvm/Transforms/Utils/SampleProfileInference.h

index ea7ae0f57b7965568942ccb27b19a05b2781fbf7..e9bc3d18bdcbf879bf6aa835c876a5241f6e8c15 100644 (file)
@@ -136,9 +136,9 @@ public:
 
 private:
   /// Initialize flow function blocks, jumps and misc metadata.
-  void initFunction(FlowFunction &Func,
-                    const std::vector<const BasicBlockT *> &BasicBlocks,
-                    DenseMap<const BasicBlockT *, uint64_t> &BlockIndex);
+  FlowFunction
+  createFlowFunction(const std::vector<const BasicBlockT *> &BasicBlocks,
+                     DenseMap<const BasicBlockT *, uint64_t> &BlockIndex);
 
   /// Try to infer branch probabilities mimicking implementation of
   /// BranchProbabilityInfo. Unlikely taken branches are marked so that the
@@ -207,8 +207,7 @@ void SampleProfileInference<BT>::apply(BlockWeightMap &BlockWeights,
   }
 
   // Create necessary objects
-  FlowFunction Func;
-  initFunction(Func, BasicBlocks, BlockIndex);
+  FlowFunction Func = createFlowFunction(BasicBlocks, BlockIndex);
 
   // Create and apply the inference network model.
   applyFlowInference(Func);
@@ -240,9 +239,10 @@ void SampleProfileInference<BT>::apply(BlockWeightMap &BlockWeights,
 }
 
 template <typename BT>
-void SampleProfileInference<BT>::initFunction(
-    FlowFunction &Func, const std::vector<const BasicBlockT *> &BasicBlocks,
+FlowFunction SampleProfileInference<BT>::createFlowFunction(
+    const std::vector<const BasicBlockT *> &BasicBlocks,
     DenseMap<const BasicBlockT *, uint64_t> &BlockIndex) {
+  FlowFunction Func;
   Func.Blocks.reserve(BasicBlocks.size());
   // Create FlowBlocks
   for (const auto *BB : BasicBlocks) {
@@ -293,6 +293,8 @@ void SampleProfileInference<BT>::initFunction(
     EntryBlock.Weight = 1;
     EntryBlock.HasUnknownWeight = false;
   }
+
+  return Func;
 }
 
 template <typename BT>