diff options
author | Fabian Parzefall <parzefall@fb.com> | 2022-07-16 17:23:21 -0700 |
---|---|---|
committer | Fabian Parzefall <parzefall@fb.com> | 2022-07-16 17:23:24 -0700 |
commit | 8477bc67614a45d9bbd5caa407bb376069789c7b (patch) | |
tree | 9f61f156fb259ed70e2b10e67902ad3719cc117c /bolt/lib/Passes/ReorderAlgorithm.cpp | |
parent | b7173553d723342d7790143e32dd5d0477941f69 (diff) | |
download | llvm-8477bc67614a45d9bbd5caa407bb376069789c7b.zip llvm-8477bc67614a45d9bbd5caa407bb376069789c7b.tar.gz llvm-8477bc67614a45d9bbd5caa407bb376069789c7b.tar.bz2 |
[BOLT] Add function layout class
This patch adds a dedicated class to keep track of each function's
layout. It also lays the groundwork for splitting functions into
multiple fragments (as opposed to a strict hot/cold split).
Reviewed By: maksfb
Differential Revision: https://reviews.llvm.org/D129518
Diffstat (limited to 'bolt/lib/Passes/ReorderAlgorithm.cpp')
-rw-r--r-- | bolt/lib/Passes/ReorderAlgorithm.cpp | 36 |
1 files changed, 19 insertions, 17 deletions
diff --git a/bolt/lib/Passes/ReorderAlgorithm.cpp b/bolt/lib/Passes/ReorderAlgorithm.cpp index ba99622..0a69f71 100644 --- a/bolt/lib/Passes/ReorderAlgorithm.cpp +++ b/bolt/lib/Passes/ReorderAlgorithm.cpp @@ -136,10 +136,10 @@ void GreedyClusterAlgorithm::clusterBasicBlocks(const BinaryFunction &BF, // Initialize inter-cluster weights. if (ComputeEdges) - ClusterEdges.resize(BF.layout_size()); + ClusterEdges.resize(BF.getLayout().block_size()); // Initialize clusters and edge queue. - for (BinaryBasicBlock *BB : BF.layout()) { + for (BinaryBasicBlock *BB : BF.getLayout().blocks()) { // Create a cluster for this BB. uint32_t I = Clusters.size(); Clusters.emplace_back(); @@ -169,7 +169,7 @@ void GreedyClusterAlgorithm::clusterBasicBlocks(const BinaryFunction &BF, LLVM_DEBUG(dbgs() << "Popped edge "; E.print(dbgs()); dbgs() << "\n"); // Case 1: BBSrc and BBDst are the same. Ignore this edge - if (SrcBB == DstBB || DstBB == *BF.layout_begin()) { + if (SrcBB == DstBB || DstBB == *BF.getLayout().block_begin()) { LLVM_DEBUG(dbgs() << "\tIgnored (same src, dst)\n"); continue; } @@ -276,7 +276,8 @@ int64_t MinBranchGreedyClusterAlgorithm::calculateWeight( "overflow detected"); // Ignore edges with same source and destination, edges that target the // entry block as well as the edge E itself. - if (SuccBB != SrcBB && SuccBB != *BF.layout_begin() && SuccBB != DstBB) + if (SuccBB != SrcBB && SuccBB != *BF.getLayout().block_begin() && + SuccBB != DstBB) W -= (int64_t)BI->Count; ++BI; } @@ -340,7 +341,7 @@ void MinBranchGreedyClusterAlgorithm::adjustQueue(std::vector<EdgeTy> &Queue, // Case 1: SrcBB and DstBB are the same or DstBB is the entry block. Ignore // this edge. - if (SrcBB == DstBB || DstBB == *BF.layout_begin()) { + if (SrcBB == DstBB || DstBB == *BF.getLayout().block_begin()) { LLVM_DEBUG(dbgs() << "\tAdjustment: Ignored edge "; E.print(dbgs()); dbgs() << " (same src, dst)\n"); continue; @@ -403,17 +404,17 @@ void TSPReorderAlgorithm::reorderBasicBlocks(const BinaryFunction &BF, std::vector<std::vector<uint64_t>> Weight; std::vector<BinaryBasicBlock *> IndexToBB; - const size_t N = BF.layout_size(); + const size_t N = BF.getLayout().block_size(); assert(N <= std::numeric_limits<uint64_t>::digits && "cannot use TSP solution for sizes larger than bits in uint64_t"); // Populating weight map and index map - for (BinaryBasicBlock *BB : BF.layout()) { + for (BinaryBasicBlock *BB : BF.getLayout().blocks()) { BB->setLayoutIndex(IndexToBB.size()); IndexToBB.push_back(BB); } Weight.resize(N); - for (BinaryBasicBlock *BB : BF.layout()) { + for (BinaryBasicBlock *BB : BF.getLayout().blocks()) { auto BI = BB->branch_info_begin(); Weight[BB->getLayoutIndex()].resize(N); for (BinaryBasicBlock *SuccBB : BB->successors()) { @@ -495,14 +496,14 @@ void TSPReorderAlgorithm::reorderBasicBlocks(const BinaryFunction &BF, // Finalize layout with BBs that weren't assigned to the layout using the // input layout. - for (BinaryBasicBlock *BB : BF.layout()) + for (BinaryBasicBlock *BB : BF.getLayout().blocks()) if (Visited[BB->getLayoutIndex()] == false) Order.push_back(BB); } void OptimizeReorderAlgorithm::reorderBasicBlocks( const BinaryFunction &BF, BasicBlockOrder &Order) const { - if (BF.layout_empty()) + if (BF.getLayout().block_empty()) return; // Cluster basic blocks. @@ -518,7 +519,7 @@ void OptimizeReorderAlgorithm::reorderBasicBlocks( void OptimizeBranchReorderAlgorithm::reorderBasicBlocks( const BinaryFunction &BF, BasicBlockOrder &Order) const { - if (BF.layout_empty()) + if (BF.getLayout().block_empty()) return; // Cluster basic blocks. @@ -623,11 +624,12 @@ void OptimizeBranchReorderAlgorithm::reorderBasicBlocks( void OptimizeCacheReorderAlgorithm::reorderBasicBlocks( const BinaryFunction &BF, BasicBlockOrder &Order) const { - if (BF.layout_empty()) + if (BF.getLayout().block_empty()) return; const uint64_t ColdThreshold = - opts::ColdThreshold * (*BF.layout_begin())->getExecutionCount() / 1000; + opts::ColdThreshold * + (*BF.getLayout().block_begin())->getExecutionCount() / 1000; // Cluster basic blocks. CAlgo->clusterBasicBlocks(BF); @@ -676,18 +678,18 @@ void OptimizeCacheReorderAlgorithm::reorderBasicBlocks( void ReverseReorderAlgorithm::reorderBasicBlocks(const BinaryFunction &BF, BasicBlockOrder &Order) const { - if (BF.layout_empty()) + if (BF.getLayout().block_empty()) return; - BinaryBasicBlock *FirstBB = *BF.layout_begin(); + BinaryBasicBlock *FirstBB = *BF.getLayout().block_begin(); Order.push_back(FirstBB); - for (auto RLI = BF.layout_rbegin(); *RLI != FirstBB; ++RLI) + for (auto RLI = BF.getLayout().block_rbegin(); *RLI != FirstBB; ++RLI) Order.push_back(*RLI); } void RandomClusterReorderAlgorithm::reorderBasicBlocks( const BinaryFunction &BF, BasicBlockOrder &Order) const { - if (BF.layout_empty()) + if (BF.getLayout().block_empty()) return; // Cluster basic blocks. |