Skip to content

Commit adac2e6

Browse files
committed
Fix the source drift test.
1 parent efbb802 commit adac2e6

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

llvm/lib/CodeGen/BasicBlockSections.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,7 @@ updateBranches(MachineFunction &MF,
183183
// clusters are ordered in increasing order of their IDs, with the "Exception"
184184
// and "Cold" succeeding all other clusters.
185185
// FuncClusterInfo represents the cluster information for basic blocks. It
186-
// maps from BBID of basic blocks to their cluster information. If this is
187-
// empty, it means unique sections for all basic blocks in the function.
186+
// maps from BBID of basic blocks to their cluster information.
188187
static void
189188
assignSections(MachineFunction &MF,
190189
const DenseMap<UniqueBBID, BBClusterInfo> &FuncClusterInfo) {
@@ -197,10 +196,8 @@ assignSections(MachineFunction &MF,
197196
for (auto &MBB : MF) {
198197
// With the 'all' option, every basic block is placed in a unique section.
199198
// With the 'list' option, every basic block is placed in a section
200-
// associated with its cluster, unless we want individual unique sections
201-
// for every basic block in this function (if FuncClusterInfo is empty).
202-
if (MF.getTarget().getBBSectionsType() == llvm::BasicBlockSection::All ||
203-
FuncClusterInfo.empty()) {
199+
// associated with its cluster.
200+
if (MF.getTarget().getBBSectionsType() == llvm::BasicBlockSection::All) {
204201
// If unique sections are desired for all basic blocks of the function, we
205202
// set every basic block's section ID equal to its original position in
206203
// the layout (which is equal to its number). This ensures that basic
@@ -308,19 +305,21 @@ bool BasicBlockSections::handleBBSections(MachineFunction &MF) {
308305
if (BBSectionsType == BasicBlockSection::List &&
309306
hasInstrProfHashMismatch(MF))
310307
return false;
311-
// Renumber blocks before sorting them. This is useful for accessing the
312-
// original layout positions and finding the original fallthroughs.
313-
MF.RenumberBlocks();
314308

315309
DenseMap<UniqueBBID, BBClusterInfo> FuncClusterInfo;
316310
if (BBSectionsType == BasicBlockSection::List) {
317311
auto ClusterInfo = getAnalysis<BasicBlockSectionsProfileReaderWrapperPass>()
318312
.getClusterInfoForFunction(MF.getName());
313+
if (ClusterInfo.empty()) return false;
319314
for (auto &BBClusterInfo : ClusterInfo) {
320315
FuncClusterInfo.try_emplace(BBClusterInfo.BBID, BBClusterInfo);
321316
}
322317
}
323318

319+
// Renumber blocks before sorting them. This is useful for accessing the
320+
// original layout positions and finding the original fallthroughs.
321+
MF.RenumberBlocks();
322+
324323
MF.setBBSectionsType(BBSectionsType);
325324
assignSections(MF, FuncClusterInfo);
326325

llvm/test/CodeGen/X86/basic-block-sections-source-drift.ll

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
; RUN: echo "!foo" > %t.order.txt
2-
; RUN: llc < %s -mtriple=x86_64-pc-linux -basic-block-sections=%t.order.txt | FileCheck --check-prefix=SOURCE-DRIFT %s
3-
; RUN: llc < %s -mtriple=x86_64-pc-linux -basic-block-sections=%t.order.txt -bbsections-detect-source-drift=false | FileCheck --check-prefix=HASH-CHECK-DISABLED %s
1+
; RUN: echo "v1" > %t
2+
; RUN: echo "f foo" >> %t
3+
; RUN: echo "c 0" >> %t
4+
; RUN: llc < %s -mtriple=x86_64-pc-linux -basic-block-sections=%t | FileCheck --check-prefix=SOURCE-DRIFT %s
5+
; RUN: llc < %s -mtriple=x86_64-pc-linux -basic-block-sections=%t -bbsections-detect-source-drift=false | FileCheck --check-prefix=HASH-CHECK-DISABLED %s
46

57
define dso_local i32 @foo(i1 zeroext %0, i1 zeroext %1) !annotation !1 {
68
br i1 %0, label %5, label %3

0 commit comments

Comments
 (0)