Skip to content

Commit eebc35e

Browse files
committed
[Clang][Driver] Add -fno-inline-functions-called-once; expose positive form in --help
Signed-off-by: Karthikdhondi <[email protected]>
1 parent 5e58c59 commit eebc35e

File tree

5 files changed

+64
-5
lines changed

5 files changed

+64
-5
lines changed

clang/include/clang/Driver/Options.td

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6959,8 +6959,12 @@ defm merge_constants : BooleanFFlag<"merge-constants">, Group<clang_ignored_gcc_
69596959
defm modulo_sched : BooleanFFlag<"modulo-sched">, Group<clang_ignored_gcc_optimization_f_Group>;
69606960
defm modulo_sched_allow_regmoves : BooleanFFlag<"modulo-sched-allow-regmoves">,
69616961
Group<clang_ignored_gcc_optimization_f_Group>;
6962-
defm inline_functions_called_once : BooleanFFlag<"inline-functions-called-once">,
6963-
Group<clang_ignored_gcc_optimization_f_Group>;
6962+
defm inline_functions_called_once
6963+
: BooleanFFlag<"inline-functions-called-once">,
6964+
Group<f_clang_Group>,
6965+
Visibility<[ClangOption, CC1Option]>,
6966+
HelpText<"Control inlining of TU-local functions called exactly once "
6967+
"(use -fno-inline-functions-called-once to inhibit it)">;
69646968
def finline_limit_EQ : Joined<["-"], "finline-limit=">, Group<clang_ignored_gcc_optimization_f_Group>;
69656969
defm finline_limit : BooleanFFlag<"inline-limit">, Group<clang_ignored_gcc_optimization_f_Group>;
69666970
defm inline_small_functions : BooleanFFlag<"inline-small-functions">,

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7266,6 +7266,12 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
72667266

72677267
Args.AddLastArg(CmdArgs, options::OPT_finline_max_stacksize_EQ);
72687268

7269+
// Forward -fno-inline-functions-called-once to LLVM so the pass is enabled.
7270+
if (Args.hasArg(options::OPT_fno_inline_functions_called_once)) {
7271+
CmdArgs.push_back("-mllvm");
7272+
CmdArgs.push_back("-no-inline-functions-called-once");
7273+
}
7274+
72697275
// FIXME: Find a better way to determine whether we are in C++20.
72707276
bool HaveCxx20 =
72717277
Std &&
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// REQUIRES: x86-registered-target
2+
// RUN: %clang -O1 -S -emit-llvm %s -fno-inline-functions-called-once -o - | FileCheck %s --check-prefix=NOINLINE
3+
4+
// We verify three things:
5+
// 1) There is a surviving call to bad_function (so it wasn’t inlined).
6+
// 2) bad_function’s definition exists and carries an attribute group id.
7+
// 3) That attribute group includes 'noinline'.
8+
9+
// The call is earlier in the IR than the callee/attributes, so use -DAG for the
10+
// first two checks to avoid order constraints, then pin the attributes match.
11+
12+
// NOINLINE-DAG: call{{.*}} @bad_function{{.*}}
13+
// NOINLINE-DAG: define internal{{.*}} @bad_function{{.*}} #[[ATTR:[0-9]+]]
14+
// NOINLINE: attributes #[[ATTR]] = { {{.*}}noinline{{.*}} }
15+
16+
volatile int G;
17+
18+
static void bad_function(void) {
19+
// Volatile side effect ensures the call can’t be DCE’d.
20+
G++;
21+
}
22+
23+
static void test(void) {
24+
// Exactly one TU-local caller of bad_function.
25+
bad_function();
26+
}
27+
28+
int main(void) {
29+
// Make the caller reachable so it survives global DCE.
30+
test();
31+
return 0;
32+
}

clang/test/Driver/clang_f_opts.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,6 @@
277277
// RUN: -fgcse-las \
278278
// RUN: -fgcse-sm \
279279
// RUN: -fipa-cp \
280-
// RUN: -finline-functions-called-once \
281280
// RUN: -fmodulo-sched \
282281
// RUN: -fmodulo-sched-allow-regmoves \
283282
// RUN: -fpeel-loops \
@@ -349,7 +348,6 @@
349348
// RUN: -fgcse-las \
350349
// RUN: -fgcse-sm \
351350
// RUN: -fipa-cp \
352-
// RUN: -finline-functions-called-once \
353351
// RUN: -fmodulo-sched \
354352
// RUN: -fmodulo-sched-allow-regmoves \
355353
// RUN: -fpeel-loops \
@@ -409,7 +407,6 @@
409407
// CHECK-WARNING-DAG: optimization flag '-fgcse-las' is not supported
410408
// CHECK-WARNING-DAG: optimization flag '-fgcse-sm' is not supported
411409
// CHECK-WARNING-DAG: optimization flag '-fipa-cp' is not supported
412-
// CHECK-WARNING-DAG: optimization flag '-finline-functions-called-once' is not supported
413410
// CHECK-WARNING-DAG: optimization flag '-fmodulo-sched' is not supported
414411
// CHECK-WARNING-DAG: optimization flag '-fmodulo-sched-allow-regmoves' is not supported
415412
// CHECK-WARNING-DAG: optimization flag '-fpeel-loops' is not supported
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// REQUIRES: x86-registered-target
2+
3+
// Check that -fno-inline-functions-called-once is forwarded to LLVM.
4+
// RUN: %clang -### -S %s -fno-inline-functions-called-once 2>&1 \
5+
// RUN: | FileCheck %s --check-prefix=FWD
6+
// FWD: "-mllvm" "-no-inline-functions-called-once"
7+
8+
// Check that the positive form does NOT forward anything to -mllvm.
9+
// RUN: %clang -### -S %s -finline-functions-called-once 2>&1 \
10+
// RUN: | FileCheck %s --check-prefix=POS
11+
// POS-NOT: -mllvm
12+
// POS-NOT: -no-inline-functions-called-once
13+
14+
// Help text should show both flags (order-independent).
15+
// RUN: %clang --help 2>&1 | FileCheck %s --check-prefix=HELP
16+
// HELP-DAG: -finline-functions-called-once
17+
// HELP-DAG: -fno-inline-functions-called-once
18+
19+
int x;
20+

0 commit comments

Comments
 (0)