@@ -1025,10 +1025,6 @@ class CDSortImpl {
1025
1025
// Merge pairs of chains while improving the objective.
1026
1026
mergeChainPairs ();
1027
1027
1028
- LLVM_DEBUG (dbgs () << " Cache-directed function sorting reduced the number"
1029
- << " of chains from " << NumNodes << " to "
1030
- << HotChains.size () << " \n " );
1031
-
1032
1028
// Collect nodes from all the chains.
1033
1029
return concatChains ();
1034
1030
}
@@ -1074,16 +1070,13 @@ class CDSortImpl {
1074
1070
1075
1071
// Initialize chains.
1076
1072
AllChains.reserve (NumNodes);
1077
- HotChains.reserve (NumNodes);
1078
1073
for (NodeT &Node : AllNodes) {
1079
1074
// Adjust execution counts.
1080
1075
Node.ExecutionCount = std::max (Node.ExecutionCount , Node.inCount ());
1081
1076
Node.ExecutionCount = std::max (Node.ExecutionCount , Node.outCount ());
1082
1077
// Create chain.
1083
1078
AllChains.emplace_back (Node.Index , &Node);
1084
1079
Node.CurChain = &AllChains.back ();
1085
- if (Node.ExecutionCount > 0 )
1086
- HotChains.push_back (&AllChains.back ());
1087
1080
}
1088
1081
1089
1082
// Initialize chain edges.
@@ -1116,8 +1109,12 @@ class CDSortImpl {
1116
1109
std::set<ChainEdge *, decltype (GainComparator)> Queue (GainComparator);
1117
1110
1118
1111
// Insert the edges into the queue.
1119
- for (ChainT *ChainPred : HotChains) {
1120
- for (const auto &[_, Edge] : ChainPred->Edges ) {
1112
+ [[maybe_unused]] size_t NumActiveChains = 0 ;
1113
+ for (NodeT &Node : AllNodes) {
1114
+ if (Node.ExecutionCount == 0 )
1115
+ continue ;
1116
+ ++NumActiveChains;
1117
+ for (const auto &[_, Edge] : Node.CurChain ->Edges ) {
1121
1118
// Ignore self-edges.
1122
1119
if (Edge->isSelfEdge ())
1123
1120
continue ;
@@ -1152,6 +1149,7 @@ class CDSortImpl {
1152
1149
MergeGainT BestGain = BestEdge->getMergeGain ();
1153
1150
mergeChains (BestSrcChain, BestDstChain, BestGain.mergeOffset (),
1154
1151
BestGain.mergeType ());
1152
+ --NumActiveChains;
1155
1153
1156
1154
// Insert newly created edges into the queue.
1157
1155
for (const auto &[_, Edge] : BestSrcChain->Edges ) {
@@ -1167,6 +1165,10 @@ class CDSortImpl {
1167
1165
Queue.insert (Edge);
1168
1166
}
1169
1167
}
1168
+
1169
+ LLVM_DEBUG (dbgs () << " Cache-directed function sorting reduced the number"
1170
+ << " of chains from " << NumNodes << " to "
1171
+ << NumActiveChains << " \n " );
1170
1172
}
1171
1173
1172
1174
// / Compute the gain of merging two chains.
@@ -1301,9 +1303,6 @@ class CDSortImpl {
1301
1303
// Merge the edges.
1302
1304
Into->mergeEdges (From);
1303
1305
From->clear ();
1304
-
1305
- // Remove the chain from the list of active chains.
1306
- llvm::erase_value (HotChains, From);
1307
1306
}
1308
1307
1309
1308
// / Concatenate all chains into the final order.
@@ -1370,9 +1369,6 @@ class CDSortImpl {
1370
1369
// / All edges between the chains.
1371
1370
std::vector<ChainEdge> AllEdges;
1372
1371
1373
- // / Active chains. The vector gets updated at runtime when chains are merged.
1374
- std::vector<ChainT *> HotChains;
1375
-
1376
1372
// / The total number of samples in the graph.
1377
1373
uint64_t TotalSamples{0 };
1378
1374
0 commit comments