@@ -26,6 +26,10 @@ static llvm::cl::opt<bool>
26
26
IgnoreHash (" profile-ignore-hash" ,
27
27
cl::desc (" ignore hash while reading function profile" ),
28
28
cl::Hidden, cl::cat(BoltOptCategory));
29
+
30
+ llvm::cl::opt<bool > ProfileUseDFS (" profile-use-dfs" ,
31
+ cl::desc (" use DFS order for YAML profile" ),
32
+ cl::Hidden, cl::cat(BoltOptCategory));
29
33
}
30
34
31
35
namespace llvm {
@@ -90,7 +94,7 @@ bool YAMLProfileReader::parseFunctionProfile(
90
94
FuncRawBranchCount += YamlSI.Count ;
91
95
BF.setRawBranchCount (FuncRawBranchCount);
92
96
93
- if (!opts::IgnoreHash && YamlBF.Hash != BF.computeHash (/* UseDFS= */ true )) {
97
+ if (!opts::IgnoreHash && YamlBF.Hash != BF.computeHash (opts::ProfileUseDFS )) {
94
98
if (opts::Verbosity >= 1 )
95
99
errs () << " BOLT-WARNING: function hash mismatch\n " ;
96
100
ProfileMatched = false ;
@@ -102,18 +106,22 @@ bool YAMLProfileReader::parseFunctionProfile(
102
106
ProfileMatched = false ;
103
107
}
104
108
105
- BinaryFunction::BasicBlockOrderType DFSOrder = BF.dfs ();
109
+ BinaryFunction::BasicBlockOrderType Order;
110
+ if (opts::ProfileUseDFS)
111
+ llvm::copy (BF.dfs (), std::back_inserter (Order));
112
+ else
113
+ llvm::copy (BF.getLayout ().blocks (), std::back_inserter (Order));
106
114
107
115
for (const yaml::bolt::BinaryBasicBlockProfile &YamlBB : YamlBF.Blocks ) {
108
- if (YamlBB.Index >= DFSOrder .size ()) {
116
+ if (YamlBB.Index >= Order .size ()) {
109
117
if (opts::Verbosity >= 2 )
110
118
errs () << " BOLT-WARNING: index " << YamlBB.Index
111
119
<< " is out of bounds\n " ;
112
120
++MismatchedBlocks;
113
121
continue ;
114
122
}
115
123
116
- BinaryBasicBlock &BB = *DFSOrder [YamlBB.Index ];
124
+ BinaryBasicBlock &BB = *Order [YamlBB.Index ];
117
125
118
126
// Basic samples profile (without LBR) does not have branches information
119
127
// and needs a special processing.
@@ -197,14 +205,14 @@ bool YAMLProfileReader::parseFunctionProfile(
197
205
}
198
206
199
207
for (const yaml::bolt::SuccessorInfo &YamlSI : YamlBB.Successors ) {
200
- if (YamlSI.Index >= DFSOrder .size ()) {
208
+ if (YamlSI.Index >= Order .size ()) {
201
209
if (opts::Verbosity >= 1 )
202
210
errs () << " BOLT-WARNING: index out of bounds for profiled block\n " ;
203
211
++MismatchedEdges;
204
212
continue ;
205
213
}
206
214
207
- BinaryBasicBlock &SuccessorBB = *DFSOrder [YamlSI.Index ];
215
+ BinaryBasicBlock &SuccessorBB = *Order [YamlSI.Index ];
208
216
if (!BB.getSuccessor (SuccessorBB.getLabel ())) {
209
217
if (opts::Verbosity >= 1 )
210
218
errs () << " BOLT-WARNING: no successor for block " << BB.getName ()
@@ -338,7 +346,7 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) {
338
346
339
347
// Recompute hash once per function.
340
348
if (!opts::IgnoreHash)
341
- Function.computeHash (/* UseDFS= */ true );
349
+ Function.computeHash (opts::ProfileUseDFS );
342
350
343
351
for (StringRef FunctionName : Function.getNames ()) {
344
352
auto PI = ProfileNameToProfile.find (FunctionName);
0 commit comments