Skip to content

Commit b86fc14

Browse files
committed
Expand the test case to prefetch hints.
1 parent e9a2af5 commit b86fc14

File tree

3 files changed

+32
-11
lines changed

3 files changed

+32
-11
lines changed

llvm/lib/CodeGen/BasicBlockSectionsProfileReader.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -358,10 +358,12 @@ Error BasicBlockSectionsProfileReader::ReadV1Profile() {
358358
// past-the-end element.
359359
if (FI == ProgramPathAndClusterInfo.end())
360360
continue;
361-
assert(Values.size() == 2);
361+
if (Values.size() != 2)
362+
return createProfileParseError(Twine("Prefetch hint expected: "+ S));
362363
SmallVector<StringRef, 2> PrefetchSiteStr;
363364
Values[0].split(PrefetchSiteStr, ',');
364-
assert(PrefetchSiteStr.size() == 2);
365+
if (PrefetchSiteStr.size() != 2)
366+
return createProfileParseError(Twine("Prefetch site expected: ") + Values[0]);
365367
auto SiteBBID = parseUniqueBBID(PrefetchSiteStr[0]);
366368
if (!SiteBBID)
367369
return SiteBBID.takeError();
@@ -372,7 +374,8 @@ Error BasicBlockSectionsProfileReader::ReadV1Profile() {
372374

373375
SmallVector<StringRef, 3> PrefetchTargetStr;
374376
Values[1].split(PrefetchTargetStr, ',');
375-
assert(PrefetchTargetStr.size() == 3);
377+
if (PrefetchTargetStr.size() != 3)
378+
return createProfileParseError(Twine("Prefetch target target expected: ") + Values[1]);
376379
auto TargetBBID = parseUniqueBBID(PrefetchTargetStr[1]);
377380
if (!TargetBBID)
378381
return TargetBBID.takeError();
@@ -392,10 +395,12 @@ Error BasicBlockSectionsProfileReader::ReadV1Profile() {
392395
if (FI == ProgramPathAndClusterInfo.end())
393396
continue;
394397
SmallVector<StringRef, 2> PrefetchTargetStr;
398+
if (Values.size() != 1)
399+
return createProfileParseError(Twine("Prefetch target expected: ")+ S);
400+
SmallVector<StringRef, 2> PrefetchTargetStr;
395401
Values[0].split(PrefetchTargetStr, ',');
396402
if (PrefetchTargetStr.size() != 2)
397-
return createProfileParseError(Twine("Callsite target expected: ") +
398-
Values[0]);
403+
return createProfileParseError(Twine("Prefetch target expected: ")+ Values[0]);
399404
auto TargetBBID = parseUniqueBBID(PrefetchTargetStr[0]);
400405
if (!TargetBBID)
401406
return TargetBBID.takeError();

llvm/lib/CodeGen/InsertCodePrefetch.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ bool InsertCodePrefetch::runOnMachineFunction(MachineFunction &MF) {
110110
DenseMap<UniqueBBID, SmallVector<PrefetchHint>> PrefetchHintsBySiteBBID;
111111
for (const auto &H : PrefetchHints)
112112
PrefetchHintsBySiteBBID[H.SiteID.BBID].push_back(H);
113-
for (auto &[SiteBBID, H] : PrefetchHintsBySiteBBID) {
114-
llvm::sort(H, [](const PrefetchHint &H1, const PrefetchHint &H2) {
113+
for (auto &[SiteBBID, Hints] : PrefetchHintsBySiteBBID) {
114+
llvm::sort(Hints, [](const PrefetchHint &H1, const PrefetchHint &H2) {
115115
return H1.SiteID.SubblockIndex < H2.SiteID.SubblockIndex;
116116
});
117117
}
@@ -127,13 +127,13 @@ bool InsertCodePrefetch::runOnMachineFunction(MachineFunction &MF) {
127127
auto InstrIt = BB.begin();
128128
for (auto HintIt = PrefetchHints.begin(); HintIt != PrefetchHints.end();) {
129129
auto NextInstrIt = InstrIt == BB.end() ? BB.end() : std::next(InstrIt);
130-
while (NumCallsInBB >= HintIt->SiteID.SubblockIndex) {
130+
while (HintIt != PrefetchHints.end() && NumCallsInBB >= HintIt->SiteID.SubblockIndex) {
131131
auto *GV = MF.getFunction().getParent()->getOrInsertGlobal(
132132
getPrefetchTargetSymbolName(HintIt->TargetFunction,
133133
HintIt->TargetID.BBID,
134134
HintIt->TargetID.SubblockIndex),
135135
PtrTy);
136-
TII->insertCodePrefetchInstr(BB, NextInstrIt, GV);
136+
TII->insertCodePrefetchInstr(BB, InstrIt, GV);
137137
++HintIt;
138138
}
139139
if (InstrIt == BB.end())

llvm/test/CodeGen/X86/basic-block-sections-code-prefetch.ll

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,19 @@
77
; RUN: echo 't 1,0' >> %t
88
; RUN: echo 't 1,1' >> %t
99
; RUN: echo 't 2,1' >> %t
10+
<<<<<<< HEAD
1011
; RUN: echo 't 3,0' >> %t
12+
=======
13+
; RUN: echo 't 4,0' >> %t
14+
; RUN: echo 'i 3@0 _Z3barv@0@0' >> %t
15+
; RUN: echo 'i 2@1 _Z3foob@1@0' >> %t
16+
>>>>>>> d2ddce6b2050 (Expand the test case to prefetch hints.)
1117
; RUN: echo 'f _Z3barv' >> %t
1218
; RUN: echo 't 0,0' >> %t
1319
; RUN: echo 't 21,1' >> %t
20+
; RUN: echo 'i 0@1 _Z3foob@0@0' >> %t
1421
;;
15-
; RUN: llc < %s -mtriple=x86_64-pc-linux -asm-verbose=false -function-sections -basic-block-sections=%t -O0 | FileCheck %s
22+
; RUN: llc < %s -O0 -mtriple=x86_64-pc-linux -asm-verbose=false -function-sections -basic-block-sections=%t | FileCheck %s
1623

1724
define i32 @_Z3foob(i1 zeroext %0) nounwind {
1825
%2 = alloca i32, align 4
@@ -45,21 +52,30 @@ define i32 @_Z3foob(i1 zeroext %0) nounwind {
4552
; CHECK: callq _Z3bazv@PLT
4653
; CHECK-NEXT: .globl __llvm_prefetch_target__Z3foob_2_1
4754
; CHECK-NEXT: __llvm_prefetch_target__Z3foob_2_1:
55+
; CHECK-NEXT: prefetchit1 __llvm_prefetch_target__Z3foob_1_0(%rip)
4856

4957
13: ; preds = %11, %9
5058
%14 = load i32, ptr %2, align 4
5159
ret i32 %14
5260
; CHECK: .LBB0_3:
5361
; CHECK-NEXT: .globl __llvm_prefetch_target__Z3foob_3_0
5462
; CHECK-NEXT: __llvm_prefetch_target__Z3foob_3_0:
63+
; CHECK-NEXT: prefetchit1 __llvm_prefetch_target__Z3barv_0_0(%rip)
64+
; CHECK: retq
65+
66+
>>>>>>> d2ddce6b2050 (Expand the test case to prefetch hints.)
5567
}
5668

5769
define weak i32 @_Z3barv() nounwind {
5870
%1 = call i32 @_Z3bazv()
59-
ret i32 %1
71+
br label %2
6072
; CHECK: _Z3barv:
6173
; CHECK-NEXT: .weak __llvm_prefetch_target__Z3barv_0_0
6274
; CHECK-NEXT: __llvm_prefetch_target__Z3barv_0_0:
75+
; CHECK: callq _Z3bazv@PLT
76+
; CHECK-NEXT: prefetchit1 __llvm_prefetch_target__Z3foob_0_0(%rip)
77+
2:
78+
ret i32 %1
6379
}
6480

6581
declare i32 @_Z3bazv() #1

0 commit comments

Comments
 (0)