@@ -49,6 +49,11 @@ cl::opt<bool> EnableExtTspBlockPlacement(
49
49
cl::desc(" Enable machine block placement based on the ext-tsp model, "
50
50
" optimizing I-cache utilization." ));
51
51
52
+ cl::opt<bool > ApplyExtTspWithoutProfile (
53
+ " ext-tsp-apply-without-profile" ,
54
+ cl::desc (" Whether to apply ext-tsp placement for instances w/o profile" ),
55
+ cl::init(true ), cl::Hidden, cl::ZeroOrMore);
56
+
52
57
// Algorithm-specific constants. The values are tuned for the best performance
53
58
// of large-scale front-end bound binaries.
54
59
static cl::opt<double >
@@ -67,6 +72,12 @@ static cl::opt<unsigned> BackwardDistance(
67
72
" ext-tsp-backward-distance" , cl::Hidden, cl::init(640 ),
68
73
cl::desc(" The maximum distance (in bytes) of a backward jump for ExtTSP" ));
69
74
75
+ // The maximum size of a chain created by the algorithm. The size is bounded
76
+ // so that the algorithm can efficiently process extremely large instance.
77
+ static cl::opt<unsigned >
78
+ MaxChainSize (" ext-tsp-max-chain-size" , cl::Hidden, cl::init(4096 ),
79
+ cl::desc(" The maximum size of a chain to create." ));
80
+
70
81
// The maximum size of a chain for splitting. Larger values of the threshold
71
82
// may yield better quality at the cost of worsen run-time.
72
83
static cl::opt<unsigned > ChainSplitThreshold (
@@ -226,6 +237,8 @@ class Chain {
226
237
227
238
const std::vector<Block *> &blocks () const { return Blocks; }
228
239
240
+ size_t numBlocks () const { return Blocks.size (); }
241
+
229
242
const std::vector<std::pair<Chain *, ChainEdge *>> &edges () const {
230
243
return Edges;
231
244
}
@@ -502,7 +515,7 @@ class ExtTSPImpl {
502
515
AllEdges.reserve (AllJumps.size ());
503
516
for (auto &Block : AllBlocks) {
504
517
for (auto &Jump : Block.OutJumps ) {
505
- const auto SuccBlock = Jump->Target ;
518
+ auto SuccBlock = Jump->Target ;
506
519
auto CurEdge = Block.CurChain ->getEdge (SuccBlock->CurChain );
507
520
// this edge is already present in the graph
508
521
if (CurEdge != nullptr ) {
@@ -592,6 +605,10 @@ class ExtTSPImpl {
592
605
if (ChainPred == ChainSucc)
593
606
continue ;
594
607
608
+ // Stop early if the combined chain violates the maximum allowed size
609
+ if (ChainPred->numBlocks () + ChainSucc->numBlocks () >= MaxChainSize)
610
+ continue ;
611
+
595
612
// Compute the gain of merging the two chains
596
613
auto CurGain = getBestMergeGain (ChainPred, ChainSucc, ChainEdge);
597
614
if (CurGain.score () <= EPS)
0 commit comments