Skip to content

Commit 9ed87a5

Browse files
committed
[C++20] [Modules] Don't emit function bodies which is noinline and availabl externally
A workaround for llvm#60996 As the title suggested, we can avoid emitting available externally functions which is marked as noinline already. Such functions should contribute nothing for optimizations. The update for docs will be sent seperately if this god approved.
1 parent dae91f5 commit 9ed87a5

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3847,6 +3847,9 @@ bool CodeGenModule::shouldEmitFunction(GlobalDecl GD) {
38473847
if (CodeGenOpts.OptimizationLevel == 0 && !F->hasAttr<AlwaysInlineAttr>())
38483848
return false;
38493849

3850+
if (F->hasAttr<NoInlineAttr>())
3851+
return false;
3852+
38503853
if (F->hasAttr<DLLImportAttr>() && !F->hasAttr<AlwaysInlineAttr>()) {
38513854
// Check whether it would be safe to inline this dllimport function.
38523855
DLLImportFunctionVisitor Visitor;
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// RUN: rm -rf %t
2+
// RUN: split-file %s %t
3+
// RUN: cd %t
4+
//
5+
// RUN: %clang_cc1 -std=c++20 -O1 -triple %itanium_abi_triple %t/a.cppm \
6+
// RUN: -emit-module-interface -o %t/a.pcm
7+
// RUN: %clang_cc1 -std=c++20 -O1 -triple %itanium_abi_triple %t/b.cppm \
8+
// RUN: -emit-module-interface -fprebuilt-module-path=%t -o %t/b.pcm
9+
// RUN: %clang_cc1 -std=c++20 -O1 -triple %itanium_abi_triple %t/c.cppm \
10+
// RUN: -emit-module-interface -fprebuilt-module-path=%t -o %t/c.pcm
11+
// RUN: %clang_cc1 -std=c++20 -O1 -triple %itanium_abi_triple %t/c.pcm -S \
12+
// RUN: -emit-llvm -disable-llvm-passes -o - | FileCheck %t/c.cppm
13+
14+
//--- a.cppm
15+
export module a;
16+
export int a() {
17+
return 43;
18+
}
19+
export __attribute__((noinline)) int a_noinline() {
20+
return 44;
21+
}
22+
23+
//--- b.cppm
24+
export module b;
25+
export import a;
26+
export int b() {
27+
return 43 + a();
28+
}
29+
30+
export __attribute__((noinline)) int b_noinline() {
31+
return 43 + a();
32+
}
33+
34+
//--- c.cppm
35+
export module c;
36+
export import b;
37+
export int c() {
38+
return 43 + b() + a() + b_noinline() + a_noinline();
39+
}
40+
41+
// CHECK: define{{.*}}available_externally{{.*}}@_ZW1b1bv(
42+
// CHECK: define{{.*}}available_externally{{.*}}@_ZW1a1av(
43+
44+
// CHECK: declare{{.*}}@_ZW1b10b_noinlinev()
45+
// CHECK: declare{{.*}}@_ZW1a10a_noinlinev()

0 commit comments

Comments
 (0)