Skip to content

Commit 4be7cf4

Browse files
SC llvm teamSC llvm team
authored andcommitted
Merged main:91423d71938d7a1dba27188e6d854148a750a3dd into amd-gfx:c4a99e6e24d7
Local branch amd-gfx c4a99e6 Merged main:89d0937348ebd4b55f17d503910be9300aa44a13 into amd-gfx:414c0c907997 Remote branch main 91423d7 [BOLT][NFC] Dont assign YAML profile to functions with no CFG (llvm#92487)
2 parents c4a99e6 + 91423d7 commit 4be7cf4

File tree

6 files changed

+289
-127
lines changed

6 files changed

+289
-127
lines changed

bolt/lib/Profile/YAMLProfileReader.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ bool YAMLProfileReader::parseFunctionProfile(
9999
FuncRawBranchCount += YamlSI.Count;
100100
BF.setRawBranchCount(FuncRawBranchCount);
101101

102+
if (BF.empty())
103+
return true;
104+
102105
if (!opts::IgnoreHash &&
103106
YamlBF.Hash != BF.computeHash(IsDFSOrder, HashFunction)) {
104107
if (opts::Verbosity >= 1)

bolt/test/X86/yaml-non-simple.test

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
## Check that YAML profile for non-simple function is not reported as stale.
2+
3+
# RUN: split-file %s %t
4+
# RUN: llvm-mc -filetype=obj -triple x86_64-unknown-unknown %t/main.s -o %t.o
5+
# RUN: %clang %cflags %t.o -o %t.exe -nostdlib
6+
# RUN: llvm-bolt %t.exe -o %t.out --data %t/yaml --profile-ignore-hash -v=1 \
7+
# RUN: --report-stale 2>&1 | FileCheck %s
8+
9+
# CHECK: BOLT-INFO: could not disassemble function main. Will ignore.
10+
# CHECK: BOLT-INFO: could not disassemble function main.cold. Will ignore.
11+
# CHECK: BOLT-INFO: 0 out of 2 functions in the binary (0.0%) have non-empty execution profile
12+
# CHECK: BOLT-INFO: 1 function with profile could not be optimized
13+
14+
#--- main.s
15+
.globl main
16+
.type main, @function
17+
main:
18+
.cfi_startproc
19+
.LBB00:
20+
pushq %rbp
21+
movq %rsp, %rbp
22+
subq $16, %rsp
23+
testq %rax, %rax
24+
js .LBB03
25+
.LBB01:
26+
jne .LBB04
27+
.LBB02:
28+
nop
29+
.LBB03:
30+
xorl %eax, %eax
31+
addq $16, %rsp
32+
popq %rbp
33+
retq
34+
.LBB04:
35+
xorl %eax, %eax
36+
addq $16, %rsp
37+
popq %rbp
38+
retq
39+
.cfi_endproc
40+
.size main, .-main
41+
42+
.globl main.cold
43+
.type main.cold, @function
44+
main.cold:
45+
.cfi_startproc
46+
nop
47+
.cfi_endproc
48+
.size main.cold, .-main.cold
49+
50+
#--- yaml
51+
---
52+
header:
53+
profile-version: 1
54+
binary-name: 'yaml-non-simple.s.tmp.exe'
55+
binary-build-id: '<unknown>'
56+
profile-flags: [ lbr ]
57+
profile-origin: branch profile reader
58+
profile-events: ''
59+
dfs-order: false
60+
hash-func: xxh3
61+
functions:
62+
- name: main
63+
fid: 0
64+
hash: 0x0000000000000000
65+
exec: 1
66+
nblocks: 5
67+
blocks:
68+
- bid: 1
69+
insns: 1
70+
succ: [ { bid: 3, cnt: 1} ]
71+
...

clang/lib/Serialization/ASTReaderDecl.cpp

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4186,12 +4186,35 @@ void ASTReader::PassInterestingDeclsToConsumer() {
41864186
GetDecl(ID);
41874187
EagerlyDeserializedDecls.clear();
41884188

4189-
while (!PotentiallyInterestingDecls.empty()) {
4190-
Decl *D = PotentiallyInterestingDecls.front();
4191-
PotentiallyInterestingDecls.pop_front();
4189+
auto ConsumingPotentialInterestingDecls = [this]() {
4190+
while (!PotentiallyInterestingDecls.empty()) {
4191+
Decl *D = PotentiallyInterestingDecls.front();
4192+
PotentiallyInterestingDecls.pop_front();
4193+
if (isConsumerInterestedIn(D))
4194+
PassInterestingDeclToConsumer(D);
4195+
}
4196+
};
4197+
std::deque<Decl *> MaybeInterestingDecls =
4198+
std::move(PotentiallyInterestingDecls);
4199+
assert(PotentiallyInterestingDecls.empty());
4200+
while (!MaybeInterestingDecls.empty()) {
4201+
Decl *D = MaybeInterestingDecls.front();
4202+
MaybeInterestingDecls.pop_front();
4203+
// Since we load the variable's initializers lazily, it'd be problematic
4204+
// if the initializers dependent on each other. So here we try to load the
4205+
// initializers of static variables to make sure they are passed to code
4206+
// generator by order. If we read anything interesting, we would consume
4207+
// that before emitting the current declaration.
4208+
if (auto *VD = dyn_cast<VarDecl>(D);
4209+
VD && VD->isFileVarDecl() && !VD->isExternallyVisible())
4210+
VD->getInit();
4211+
ConsumingPotentialInterestingDecls();
41924212
if (isConsumerInterestedIn(D))
41934213
PassInterestingDeclToConsumer(D);
41944214
}
4215+
4216+
// If we add any new potential interesting decl in the last call, consume it.
4217+
ConsumingPotentialInterestingDecls();
41954218
}
41964219

41974220
void ASTReader::loadDeclUpdateRecords(PendingUpdateRecord &Record) {

clang/test/Modules/pr91418.cppm

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// RUN: rm -rf %t
2+
// RUN: mkdir -p %t
3+
// RUN: split-file %s %t
4+
//
5+
// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++20 -x c++-header %t/foo.h \
6+
// RUN: -emit-pch -o %t/foo.pch
7+
// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++20 %t/use.cpp -include-pch \
8+
// RUN: %t/foo.pch -emit-llvm -o - | FileCheck %t/use.cpp
9+
10+
//--- foo.h
11+
#ifndef FOO_H
12+
#define FOO_H
13+
typedef float __m128 __attribute__((__vector_size__(16), __aligned__(16)));
14+
15+
static __inline__ __m128 __attribute__((__always_inline__, __min_vector_width__(128)))
16+
_mm_setr_ps(float __z, float __y, float __x, float __w)
17+
{
18+
return __extension__ (__m128){ __z, __y, __x, __w };
19+
}
20+
21+
typedef __m128 VR;
22+
23+
inline VR MakeVR( float X, float Y, float Z, float W )
24+
{
25+
return _mm_setr_ps( X, Y, Z, W );
26+
}
27+
28+
extern "C" float sqrtf(float);
29+
30+
namespace VectorSinConstantsSSE
31+
{
32+
float a = (16 * sqrtf(0.225f));
33+
VR A = MakeVR(a, a, a, a);
34+
static const float b = (16 * sqrtf(0.225f));
35+
static const VR B = MakeVR(b, b, b, b);
36+
}
37+
38+
#endif // FOO_H
39+
40+
//--- use.cpp
41+
#include "foo.h"
42+
float use() {
43+
return VectorSinConstantsSSE::A[0] + VectorSinConstantsSSE::A[1] +
44+
VectorSinConstantsSSE::A[2] + VectorSinConstantsSSE::A[3] +
45+
VectorSinConstantsSSE::B[0] + VectorSinConstantsSSE::B[1] +
46+
VectorSinConstantsSSE::B[2] + VectorSinConstantsSSE::B[3];
47+
}
48+
49+
// CHECK: define{{.*}}@__cxx_global_var_init(
50+
// CHECK: store{{.*}}, ptr @_ZN21VectorSinConstantsSSE1aE
51+
52+
// CHECK: define{{.*}}@__cxx_global_var_init.1(
53+
// CHECK: store{{.*}}, ptr @_ZN21VectorSinConstantsSSE1AE
54+
55+
// CHECK: define{{.*}}@__cxx_global_var_init.2(
56+
// CHECK: store{{.*}}, ptr @_ZN21VectorSinConstantsSSEL1BE
57+
58+
// CHECK: define{{.*}}@__cxx_global_var_init.3(
59+
// CHECK: store{{.*}}, ptr @_ZN21VectorSinConstantsSSEL1bE
60+
61+
// CHECK: @_GLOBAL__sub_I_use.cpp
62+
// CHECK: call{{.*}}@__cxx_global_var_init(
63+
// CHECK: call{{.*}}@__cxx_global_var_init.1(
64+
// CHECK: call{{.*}}@__cxx_global_var_init.3(
65+
// CHECK: call{{.*}}@__cxx_global_var_init.2(

0 commit comments

Comments
 (0)