Skip to content

Commit 57d54f4

Browse files
wdx727lifengxiang1025zcfh
authored andcommitted
Adding Matching and Inference Functionality to Propeller-PR3: Read basic block hashes from propeller profile. (llvm#164223)
Adding Matching and Inference Functionality to Propeller. For detailed information, please refer to the following RFC: https://discourse.llvm.org/t/rfc-adding-matching-and-inference-functionality-to-propeller/86238. This is the third PR, which is used to read basic block hashes from the propeller profile. The associated PRs are: PR1: llvm#160706 PR2: llvm#162963 co-authors: lifengxiang1025 [[email protected]](mailto:[email protected]); zcfh [[email protected]](mailto:[email protected]) Co-authored-by: lifengxiang1025 <[email protected]> Co-authored-by: zcfh <[email protected]>
1 parent 1e20d0b commit 57d54f4

File tree

4 files changed

+88
-0
lines changed

4 files changed

+88
-0
lines changed

llvm/include/llvm/CodeGen/BasicBlockSectionsProfileReader.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ 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. The Hashes are stored for every original block
58+
// (not cloned blocks), hence the map key being unsigned instead of
59+
// UniqueBBID.
60+
DenseMap<unsigned, uint64_t> BBHashes;
5761
};
5862

5963
class BasicBlockSectionsProfileReader {

llvm/lib/CodeGen/BasicBlockSectionsProfileReader.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,25 @@ 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(
303+
Twine("unsigned integer expected in hex format: '") + HashStr +
304+
"'");
305+
FI->second.BBHashes[BBID] = Hash;
306+
}
307+
continue;
308+
}
290309
default:
291310
return createProfileParseError(Twine("invalid specifier: '") +
292311
Twine(Specifier) + "'");
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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+
12+
; These commands read BB hashes from SHT_LLVM_BB_ADDR_MAP
13+
; and put them into the basic blocks sections profile.
14+
; RUN: grep -E '^\s+(- ID:|Hash:)' %t.yaml | \
15+
; RUN: grep -B1 'Hash:' | \
16+
; RUN: sed 's/^\s*//; s/^- ID: *//; s/Hash: *0x//' | \
17+
; RUN: paste -d: - - | \
18+
; RUN: tr '\n' ' ' | \
19+
; RUN: sed 's/ $/\n/; s/^/h /' >> %t
20+
;
21+
; RUN: llc < %s -O0 -mtriple=x86_64-pc-linux -function-sections -basic-block-sections=%t | FileCheck %s
22+
;
23+
define void @foo(i1 zeroext) nounwind {
24+
%2 = alloca i8, align 1
25+
%3 = zext i1 %0 to i8
26+
store i8 %3, ptr %2, align 1
27+
%4 = load i8, ptr %2, align 1
28+
%5 = trunc i8 %4 to i1
29+
br i1 %5, label %6, label %8
30+
31+
6: ; preds = %1
32+
%7 = call i32 @bar()
33+
br label %10
34+
35+
8: ; preds = %1
36+
%9 = call i32 @baz()
37+
br label %10
38+
39+
10: ; preds = %8, %6
40+
ret void
41+
}
42+
43+
declare i32 @bar() #1
44+
45+
declare i32 @baz() #1
46+
47+
; CHECK: .section .text.foo,"ax",@progbits
48+
; CHECK: callq baz
49+
; CHECK: retq
50+
; CHECK: .section .text.split.foo,"ax",@progbits
51+
; 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 in hex format: '111111111111111g'
7286

7387

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

0 commit comments

Comments
 (0)