Skip to content

Commit 8a47e7c

Browse files
committed
Add MaxChainSize to CDSortConfig
1 parent ebde38a commit 8a47e7c

File tree

3 files changed

+13
-16
lines changed

3 files changed

+13
-16
lines changed

llvm/include/llvm/Transforms/Utils/CodeLayout.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ struct CDSortConfig {
6565
unsigned CacheEntries = 16;
6666
/// The size of a line in the cache.
6767
unsigned CacheSize = 2048;
68+
/// The maximum size of a chain to create.
69+
unsigned MaxChainSize = 128;
6870
/// The power exponent for the distance-based locality.
6971
double DistancePower = 0.25;
7072
/// The scale factor for the frequency-based locality.

llvm/lib/Transforms/Utils/CodeLayout.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,6 @@ cl::opt<bool> ApplyExtTspWithoutProfile(
6262
"ext-tsp-apply-without-profile",
6363
cl::desc("Whether to apply ext-tsp placement for instances w/o profile"),
6464
cl::init(true), cl::Hidden);
65-
66-
namespace codelayout {
67-
cl::opt<unsigned>
68-
CDMaxChainSize("cdsort-max-chain-size", cl::Hidden, cl::init(128),
69-
cl::desc("The maximum size of a chain to create"));
70-
}
7165
} // namespace llvm
7266

7367
// Algorithm-specific params for Ext-TSP. The values are tuned for the best
@@ -129,6 +123,10 @@ static cl::opt<unsigned> CacheEntries("cds-cache-entries", cl::ReallyHidden,
129123
static cl::opt<unsigned> CacheSize("cds-cache-size", cl::ReallyHidden,
130124
cl::desc("The size of a line in the cache"));
131125

126+
static cl::opt<unsigned>
127+
CDMaxChainSize("cdsort-max-chain-size", cl::ReallyHidden,
128+
cl::desc("The maximum size of a chain to create"));
129+
132130
static cl::opt<double> DistancePower(
133131
"cds-distance-power", cl::ReallyHidden,
134132
cl::desc("The power exponent for the distance-based locality"));
@@ -1163,7 +1161,7 @@ class CDSortImpl {
11631161
if (Edge->isSelfEdge())
11641162
continue;
11651163
if (Edge->srcChain()->numBlocks() + Edge->dstChain()->numBlocks() >
1166-
CDMaxChainSize)
1164+
Config.MaxChainSize)
11671165
continue;
11681166

11691167
// Compute the gain of merging the two chains.
@@ -1461,6 +1459,8 @@ std::vector<uint64_t> codelayout::computeCacheDirectedLayout(
14611459
Config.CacheEntries = CacheEntries;
14621460
if (CacheSize.getNumOccurrences() > 0)
14631461
Config.CacheSize = CacheSize;
1462+
if (CDMaxChainSize.getNumOccurrences() > 0)
1463+
Config.MaxChainSize = CDMaxChainSize;
14641464
if (DistancePower.getNumOccurrences() > 0)
14651465
Config.DistancePower = DistancePower;
14661466
if (FrequencyScale.getNumOccurrences() > 0)

llvm/unittests/Transforms/Utils/CodeLayoutTest.cpp

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#include "llvm/Transforms/Utils/CodeLayout.h"
2-
#include "llvm/Support/CommandLine.h"
32
#include "gmock/gmock.h"
43
#include "gtest/gtest.h"
54
#include <vector>
@@ -8,10 +7,6 @@ using namespace llvm;
87
using namespace llvm::codelayout;
98
using testing::ElementsAreArray;
109

11-
namespace llvm::codelayout {
12-
extern cl::opt<unsigned> CDMaxChainSize;
13-
}
14-
1510
namespace {
1611
TEST(CodeLayout, ThreeFunctions) {
1712
// Place the most likely successor (2) first.
@@ -48,11 +43,11 @@ TEST(CodeLayout, HotChain) {
4843

4944
// -cdsort-max-chain-size disables forming a larger chain and therefore may
5045
// change the result.
51-
unsigned Saved = CDMaxChainSize;
52-
CDMaxChainSize.setValue(3);
53-
Order = computeCacheDirectedLayout(Sizes, Counts, Edges, CallOffsets);
46+
CDSortConfig Config;
47+
Config.MaxChainSize = 3;
48+
Order =
49+
computeCacheDirectedLayout(Config, Sizes, Counts, Edges, CallOffsets);
5450
EXPECT_THAT(Order, ElementsAreArray({0, 3, 4, 1, 2}));
55-
CDMaxChainSize.setValue(Saved);
5651
}
5752
}
5853

0 commit comments

Comments
 (0)