Skip to content

Commit d1db0ae

Browse files
wdx727lifengxiang1025zcfh
committed
Adding Matching and Inference Functionality to Propeller-PR3: Read basic block hashes from propeller profile.
Co-authored-by: lifengxiang1025 <lifengxiang@kuaishou.com> Co-authored-by: zcfh <wuminghui03@kuaishou.com>
1 parent 20c323a commit d1db0ae

File tree

4 files changed

+82
-0
lines changed

4 files changed

+82
-0
lines changed

llvm/include/llvm/CodeGen/BasicBlockSectionsProfileReader.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ struct FunctionPathAndClusterInfo {
5454
DenseMap<UniqueBBID, uint64_t> NodeCounts;
5555
// Edge counts for each edge, stored as a nested map.
5656
DenseMap<UniqueBBID, DenseMap<UniqueBBID, uint64_t>> EdgeCounts;
57+
// Hash for each basic block.
58+
DenseMap<unsigned, uint64_t> BBHashes;
5759
};
5860

5961
class BasicBlockSectionsProfileReader {

llvm/lib/CodeGen/BasicBlockSectionsProfileReader.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,24 @@ Error BasicBlockSectionsProfileReader::ReadV1Profile() {
287287
}
288288
continue;
289289
}
290+
case 'h': { // Basic block hash secifier.
291+
// Skip the profile when the profile iterator (FI) refers to the
292+
// past-the-end element.
293+
if (FI == ProgramPathAndClusterInfo.end())
294+
continue;
295+
for (auto BBIDHashStr : Values) {
296+
auto [BBIDStr, HashStr] = BBIDHashStr.split(':');
297+
unsigned long long BBID = 0, Hash = 0;
298+
if (getAsUnsignedInteger(BBIDStr, 10, BBID))
299+
return createProfileParseError(Twine("unsigned integer expected: '") +
300+
BBIDStr + "'");
301+
if (getAsUnsignedInteger(HashStr, 16, Hash))
302+
return createProfileParseError(Twine("unsigned integer expected: '") +
303+
HashStr + "'");
304+
FI->second.BBHashes[BBID] = Hash;
305+
}
306+
continue;
307+
}
290308
default:
291309
return createProfileParseError(Twine("invalid specifier: '") +
292310
Twine(Specifier) + "'");
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
; BB section test with basic block hashes.
2+
;
3+
; RUN: llc %s -O0 -mtriple=x86_64-pc-linux -function-sections -filetype=obj -basic-block-address-map -emit-bb-hash -o %t.o
4+
; RUN: obj2yaml %t.o -o %t.yaml
5+
;
6+
;; Profile for version 1:
7+
; RUN: echo 'v1' > %t
8+
; RUN: echo 'f foo' >> %t
9+
; RUN: echo 'g 0:10,1:9,2:1 1:8,3:8 2:2,3:2 3:11' >> %t
10+
; RUN: echo 'c 0 2 3' >> %t
11+
; RUN: grep -E '^\s+(- ID:|Hash:)' %t.yaml | \
12+
; RUN: grep -B1 'Hash:' | \
13+
; RUN: sed 's/^\s*//; s/^- ID: *//; s/Hash: *0x//' | \
14+
; RUN: paste -d: - - | \
15+
; RUN: tr '\n' ' ' | \
16+
; RUN: sed 's/ $/\n/; s/^/h /' >> %t
17+
;
18+
; RUN: llc < %s -O0 -mtriple=x86_64-pc-linux -function-sections -basic-block-sections=%t | FileCheck %s
19+
;
20+
define void @foo(i1 zeroext) nounwind {
21+
%2 = alloca i8, align 1
22+
%3 = zext i1 %0 to i8
23+
store i8 %3, ptr %2, align 1
24+
%4 = load i8, ptr %2, align 1
25+
%5 = trunc i8 %4 to i1
26+
br i1 %5, label %6, label %8
27+
28+
6: ; preds = %1
29+
%7 = call i32 @bar()
30+
br label %10
31+
32+
8: ; preds = %1
33+
%9 = call i32 @baz()
34+
br label %10
35+
36+
10: ; preds = %8, %6
37+
ret void
38+
}
39+
40+
declare i32 @bar() #1
41+
42+
declare i32 @baz() #1
43+
44+
; CHECK: .section .text.foo,"ax",@progbits
45+
; CHECK: callq baz
46+
; CHECK: retq
47+
; CHECK: .section .text.split.foo,"ax",@progbits
48+
; CHECK: callq bar

llvm/test/CodeGen/X86/basic-block-sections-clusters-error.ll

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,20 @@
6969
; RUN: echo 'g 0:4,1:2:3' >> %t15
7070
; RUN: not --crash llc < %s -O0 -mtriple=x86_64 -function-sections -basic-block-sections=%t15 2>&1 | FileCheck %s --check-prefix=CHECK-ERROR15
7171
; CHECK-ERROR15: LLVM ERROR: invalid profile {{.*}} at line 4: unsigned integer expected: '2:3'
72+
; RUN: echo 'v1' > %t16
73+
; RUN: echo 'f dummy1' >> %t16
74+
; RUN: echo 'c 0 1' >> %t16
75+
; RUN: echo 'g 0:4,1:2' >> %t16
76+
; RUN: echo 'h a:1111111111111111 1:ffffffffffffffff' >> %t16
77+
; RUN: not --crash llc < %s -O0 -mtriple=x86_64 -function-sections -basic-block-sections=%t16 2>&1 | FileCheck %s --check-prefix=CHECK-ERROR16
78+
; CHECK-ERROR16: LLVM ERROR: invalid profile {{.*}} at line 5: unsigned integer expected: 'a'
79+
; RUN: echo 'v1' > %t17
80+
; RUN: echo 'f dummy1' >> %t17
81+
; RUN: echo 'c 0 1' >> %t17
82+
; RUN: echo 'g 0:4,1:2' >> %t17
83+
; RUN: echo 'h 0:111111111111111g 1:ffffffffffffffff' >> %t17
84+
; RUN: not --crash llc < %s -O0 -mtriple=x86_64 -function-sections -basic-block-sections=%t17 2>&1 | FileCheck %s --check-prefix=CHECK-ERROR17
85+
; CHECK-ERROR17: LLVM ERROR: invalid profile {{.*}} at line 5: unsigned integer expected: '111111111111111g'
7286

7387

7488
define i32 @dummy1(i32 %x, i32 %y, i32 %z) {

0 commit comments

Comments
 (0)