Skip to content

Commit 992d852

Browse files
[flang]Add support for -moutline-atomics and -mno-outline-atomics (#78755)
This adds the support to add the target-feature to outline atomic operations (calling the runtime library instead).
1 parent bc6370a commit 992d852

File tree

9 files changed

+73
-22
lines changed

9 files changed

+73
-22
lines changed

clang/include/clang/Driver/Options.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4994,10 +4994,10 @@ def mno_fmv : Flag<["-"], "mno-fmv">, Group<f_clang_Group>,
49944994
Visibility<[ClangOption, CC1Option]>,
49954995
HelpText<"Disable function multiversioning">;
49964996
def moutline_atomics : Flag<["-"], "moutline-atomics">, Group<f_clang_Group>,
4997-
Visibility<[ClangOption, CC1Option]>,
4997+
Visibility<[ClangOption, CC1Option, FlangOption]>,
49984998
HelpText<"Generate local calls to out-of-line atomic operations">;
49994999
def mno_outline_atomics : Flag<["-"], "mno-outline-atomics">, Group<f_clang_Group>,
5000-
Visibility<[ClangOption, CC1Option]>,
5000+
Visibility<[ClangOption, CC1Option, FlangOption]>,
50015001
HelpText<"Don't generate local calls to out-of-line atomic operations">;
50025002
def mno_implicit_float : Flag<["-"], "mno-implicit-float">, Group<m_Group>,
50035003
HelpText<"Don't generate implicit floating point or vector instructions">;

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7673,26 +7673,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
76737673

76747674
addMachineOutlinerArgs(D, Args, CmdArgs, Triple, /*IsLTO=*/false);
76757675

7676-
if (Arg *A = Args.getLastArg(options::OPT_moutline_atomics,
7677-
options::OPT_mno_outline_atomics)) {
7678-
// Option -moutline-atomics supported for AArch64 target only.
7679-
if (!Triple.isAArch64()) {
7680-
D.Diag(diag::warn_drv_moutline_atomics_unsupported_opt)
7681-
<< Triple.getArchName() << A->getOption().getName();
7682-
} else {
7683-
if (A->getOption().matches(options::OPT_moutline_atomics)) {
7684-
CmdArgs.push_back("-target-feature");
7685-
CmdArgs.push_back("+outline-atomics");
7686-
} else {
7687-
CmdArgs.push_back("-target-feature");
7688-
CmdArgs.push_back("-outline-atomics");
7689-
}
7690-
}
7691-
} else if (Triple.isAArch64() &&
7692-
getToolChain().IsAArch64OutlineAtomicsDefault(Args)) {
7693-
CmdArgs.push_back("-target-feature");
7694-
CmdArgs.push_back("+outline-atomics");
7695-
}
7676+
addOutlineAtomicsArgs(D, getToolChain(), Args, CmdArgs, Triple);
76967677

76977678
if (Triple.isAArch64() &&
76987679
(Args.hasArg(options::OPT_mno_fmv) ||

clang/lib/Driver/ToolChains/CommonArgs.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2796,3 +2796,28 @@ void tools::addHIPRuntimeLibArgs(const ToolChain &TC, Compilation &C,
27962796
}
27972797
}
27982798
}
2799+
2800+
void tools::addOutlineAtomicsArgs(const Driver &D, const ToolChain &TC,
2801+
const llvm::opt::ArgList &Args,
2802+
llvm::opt::ArgStringList &CmdArgs,
2803+
const llvm::Triple &Triple) {
2804+
if (Arg *A = Args.getLastArg(options::OPT_moutline_atomics,
2805+
options::OPT_mno_outline_atomics)) {
2806+
// Option -moutline-atomics supported for AArch64 target only.
2807+
if (!Triple.isAArch64()) {
2808+
D.Diag(diag::warn_drv_moutline_atomics_unsupported_opt)
2809+
<< Triple.getArchName() << A->getOption().getName();
2810+
} else {
2811+
if (A->getOption().matches(options::OPT_moutline_atomics)) {
2812+
CmdArgs.push_back("-target-feature");
2813+
CmdArgs.push_back("+outline-atomics");
2814+
} else {
2815+
CmdArgs.push_back("-target-feature");
2816+
CmdArgs.push_back("-outline-atomics");
2817+
}
2818+
}
2819+
} else if (Triple.isAArch64() && TC.IsAArch64OutlineAtomicsDefault(Args)) {
2820+
CmdArgs.push_back("-target-feature");
2821+
CmdArgs.push_back("+outline-atomics");
2822+
}
2823+
}

clang/lib/Driver/ToolChains/CommonArgs.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,12 @@ void addMachineOutlinerArgs(const Driver &D, const llvm::opt::ArgList &Args,
215215
void addOpenMPDeviceRTL(const Driver &D, const llvm::opt::ArgList &DriverArgs,
216216
llvm::opt::ArgStringList &CC1Args,
217217
StringRef BitcodeSuffix, const llvm::Triple &Triple);
218+
219+
void addOutlineAtomicsArgs(const Driver &D, const ToolChain &TC,
220+
const llvm::opt::ArgList &Args,
221+
llvm::opt::ArgStringList &CmdArgs,
222+
const llvm::Triple &Triple);
223+
218224
} // end namespace tools
219225
} // end namespace driver
220226
} // end namespace clang

clang/lib/Driver/ToolChains/Flang.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,8 @@ void Flang::addTargetOptions(const ArgList &Args,
352352
CmdArgs.push_back(Args.MakeArgString(CPU));
353353
}
354354

355+
addOutlineAtomicsArgs(D, getToolChain(), Args, CmdArgs, Triple);
356+
355357
// Add the target features.
356358
switch (TC.getArch()) {
357359
default:
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
! Test that flang-new forwards the -moutline-atomics and -mno-outline-atomics.
2+
! RUN: %flang -moutline-atomics --target=aarch64-none-none -### %s -o %t 2>&1 | FileCheck %s
3+
! CHECK: "-target-feature" "+outline-atomics"
4+
5+
! RUN: %flang -mno-outline-atomics --target=aarch64-none-none -### %s -o %t 2>&1 | FileCheck %s --check-prefix=CHECK-NOOUTLINE
6+
! CHECK-NOOUTLINE: "-target-feature" "-outline-atomics"
7+
8+
! Use Fuchsia to ensure the outline atomics is enabled.
9+
! RUN: %flang --target=aarch64-none-fuchsia -### %s -o %t 2>&1 | FileCheck %s --check-prefix=CHECK-DEFAULT
10+
! CHECK-DEFAULT: "-target-feature" "+outline-atomics"
11+
12+
! RUN: %flang -mno-outline-atomics --target=x86-none-none -### %s -o %t 2>&1 | FileCheck %s --check-prefix=CHECK-ERRMSG
13+
! CHECK-ERRMSG: warning: 'x86' does not support '-mno-outline-atomics'
14+
15+

flang/test/Driver/driver-help-hidden.f90

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,9 @@
122122
! CHECK-NEXT: -mllvm=<arg> Alias for -mllvm
123123
! CHECK-NEXT: -mllvm <value> Additional arguments to forward to LLVM's option processing
124124
! CHECK-NEXT: -mmlir <value> Additional arguments to forward to MLIR's option processing
125+
! CHECK-NEXT: -mno-outline-atomics Don't generate local calls to out-of-line atomic operations
125126
! CHECK-NEXT: -module-dir <dir> Put MODULE files in <dir>
127+
! CHECK-NEXT: -moutline-atomics Generate local calls to out-of-line atomic operations
126128
! CHECK-NEXT: -mrvv-vector-bits=<value>
127129
! CHECK-NEXT: Specify the size in bits of an RVV vector register
128130
! CHECK-NEXT: -msve-vector-bits=<value>

flang/test/Driver/driver-help.f90

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,9 @@
108108
! HELP-NEXT: -mllvm=<arg> Alias for -mllvm
109109
! HELP-NEXT: -mllvm <value> Additional arguments to forward to LLVM's option processing
110110
! HELP-NEXT: -mmlir <value> Additional arguments to forward to MLIR's option processing
111+
! HELP-NEXT: -mno-outline-atomics Don't generate local calls to out-of-line atomic operations
111112
! HELP-NEXT: -module-dir <dir> Put MODULE files in <dir>
113+
! HELP-NEXT: -moutline-atomics Generate local calls to out-of-line atomic operations
112114
! HELP-NEXT: -mrvv-vector-bits=<value>
113115
! HELP-NEXT: Specify the size in bits of an RVV vector register
114116
! HELP-NEXT: -msve-vector-bits=<value>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
! RUN: %flang -S -emit-llvm --target=aarch64-none-none -moutline-atomics -o - %s | FileCheck %s --check-prefixes=CHECKON,CHECKALL
2+
! RUN: %flang -S -emit-llvm --target=aarch64-none-none -mno-outline-atomics -o - %s | FileCheck %s --check-prefixes=CHECKOFF,CHECKALL
3+
! REQUIRES: aarch64-registered-target
4+
5+
subroutine test()
6+
integer :: i
7+
8+
do i = 1, 10
9+
end do
10+
end subroutine
11+
12+
! CHECKALL-LABEL: define void @test_()
13+
! CHECKALL-SAME: #[[ATTR:[0-9]*]]
14+
! CHECKALL: attributes #[[ATTR]] =
15+
! Use CHECK-SAME to allow arbitrary other attributes to be present.
16+
! CHECKALL-SAME: target-features
17+
! CHECKON-SAME: +outline-atomics
18+
! CHECKOFF-SAME: -outline-atomics

0 commit comments

Comments
 (0)