[clang] 992d852 - [flang]Add support for -moutline-atomics and -mno-outline-atomics (#78755)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Feb 5 05:54:16 PST 2024
Author: Mats Petersson
Date: 2024-02-05T13:54:12Z
New Revision: 992d8527585817af685bba0d82ed4e808bc613bb
URL: https://github.com/llvm/llvm-project/commit/992d8527585817af685bba0d82ed4e808bc613bb
DIFF: https://github.com/llvm/llvm-project/commit/992d8527585817af685bba0d82ed4e808bc613bb.diff
LOG: [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).
Added:
flang/test/Driver/aarch64-outline-atomics.f90
flang/test/Integration/aarch64-outline-atomics.f90
Modified:
clang/include/clang/Driver/Options.td
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Driver/ToolChains/CommonArgs.cpp
clang/lib/Driver/ToolChains/CommonArgs.h
clang/lib/Driver/ToolChains/Flang.cpp
flang/test/Driver/driver-help-hidden.f90
flang/test/Driver/driver-help.f90
Removed:
################################################################################
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index fb5f50ef452c2..4b232b8aab722 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4994,10 +4994,10 @@ def mno_fmv : Flag<["-"], "mno-fmv">, Group<f_clang_Group>,
Visibility<[ClangOption, CC1Option]>,
HelpText<"Disable function multiversioning">;
def moutline_atomics : Flag<["-"], "moutline-atomics">, Group<f_clang_Group>,
- Visibility<[ClangOption, CC1Option]>,
+ Visibility<[ClangOption, CC1Option, FlangOption]>,
HelpText<"Generate local calls to out-of-line atomic operations">;
def mno_outline_atomics : Flag<["-"], "mno-outline-atomics">, Group<f_clang_Group>,
- Visibility<[ClangOption, CC1Option]>,
+ Visibility<[ClangOption, CC1Option, FlangOption]>,
HelpText<"Don't generate local calls to out-of-line atomic operations">;
def mno_implicit_float : Flag<["-"], "mno-implicit-float">, Group<m_Group>,
HelpText<"Don't generate implicit floating point or vector instructions">;
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index 46595852b1d80..13bf242115437 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -7673,26 +7673,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
addMachineOutlinerArgs(D, Args, CmdArgs, Triple, /*IsLTO=*/false);
- if (Arg *A = Args.getLastArg(options::OPT_moutline_atomics,
- options::OPT_mno_outline_atomics)) {
- // Option -moutline-atomics supported for AArch64 target only.
- if (!Triple.isAArch64()) {
- D.Diag(diag::warn_drv_moutline_atomics_unsupported_opt)
- << Triple.getArchName() << A->getOption().getName();
- } else {
- if (A->getOption().matches(options::OPT_moutline_atomics)) {
- CmdArgs.push_back("-target-feature");
- CmdArgs.push_back("+outline-atomics");
- } else {
- CmdArgs.push_back("-target-feature");
- CmdArgs.push_back("-outline-atomics");
- }
- }
- } else if (Triple.isAArch64() &&
- getToolChain().IsAArch64OutlineAtomicsDefault(Args)) {
- CmdArgs.push_back("-target-feature");
- CmdArgs.push_back("+outline-atomics");
- }
+ addOutlineAtomicsArgs(D, getToolChain(), Args, CmdArgs, Triple);
if (Triple.isAArch64() &&
(Args.hasArg(options::OPT_mno_fmv) ||
diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 5d570c90e5340..0fd7b8424eb4b 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -2796,3 +2796,28 @@ void tools::addHIPRuntimeLibArgs(const ToolChain &TC, Compilation &C,
}
}
}
+
+void tools::addOutlineAtomicsArgs(const Driver &D, const ToolChain &TC,
+ const llvm::opt::ArgList &Args,
+ llvm::opt::ArgStringList &CmdArgs,
+ const llvm::Triple &Triple) {
+ if (Arg *A = Args.getLastArg(options::OPT_moutline_atomics,
+ options::OPT_mno_outline_atomics)) {
+ // Option -moutline-atomics supported for AArch64 target only.
+ if (!Triple.isAArch64()) {
+ D.Diag(diag::warn_drv_moutline_atomics_unsupported_opt)
+ << Triple.getArchName() << A->getOption().getName();
+ } else {
+ if (A->getOption().matches(options::OPT_moutline_atomics)) {
+ CmdArgs.push_back("-target-feature");
+ CmdArgs.push_back("+outline-atomics");
+ } else {
+ CmdArgs.push_back("-target-feature");
+ CmdArgs.push_back("-outline-atomics");
+ }
+ }
+ } else if (Triple.isAArch64() && TC.IsAArch64OutlineAtomicsDefault(Args)) {
+ CmdArgs.push_back("-target-feature");
+ CmdArgs.push_back("+outline-atomics");
+ }
+}
diff --git a/clang/lib/Driver/ToolChains/CommonArgs.h b/clang/lib/Driver/ToolChains/CommonArgs.h
index 807867f13a5c3..2db0f889ca820 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.h
+++ b/clang/lib/Driver/ToolChains/CommonArgs.h
@@ -215,6 +215,12 @@ void addMachineOutlinerArgs(const Driver &D, const llvm::opt::ArgList &Args,
void addOpenMPDeviceRTL(const Driver &D, const llvm::opt::ArgList &DriverArgs,
llvm::opt::ArgStringList &CC1Args,
StringRef BitcodeSuffix, const llvm::Triple &Triple);
+
+void addOutlineAtomicsArgs(const Driver &D, const ToolChain &TC,
+ const llvm::opt::ArgList &Args,
+ llvm::opt::ArgStringList &CmdArgs,
+ const llvm::Triple &Triple);
+
} // end namespace tools
} // end namespace driver
} // end namespace clang
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp b/clang/lib/Driver/ToolChains/Flang.cpp
index b659521df88ff..23da08aa593f2 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -352,6 +352,8 @@ void Flang::addTargetOptions(const ArgList &Args,
CmdArgs.push_back(Args.MakeArgString(CPU));
}
+ addOutlineAtomicsArgs(D, getToolChain(), Args, CmdArgs, Triple);
+
// Add the target features.
switch (TC.getArch()) {
default:
diff --git a/flang/test/Driver/aarch64-outline-atomics.f90 b/flang/test/Driver/aarch64-outline-atomics.f90
new file mode 100644
index 0000000000000..a1c874c20df5c
--- /dev/null
+++ b/flang/test/Driver/aarch64-outline-atomics.f90
@@ -0,0 +1,15 @@
+! Test that flang-new forwards the -moutline-atomics and -mno-outline-atomics.
+! RUN: %flang -moutline-atomics --target=aarch64-none-none -### %s -o %t 2>&1 | FileCheck %s
+! CHECK: "-target-feature" "+outline-atomics"
+
+! RUN: %flang -mno-outline-atomics --target=aarch64-none-none -### %s -o %t 2>&1 | FileCheck %s --check-prefix=CHECK-NOOUTLINE
+! CHECK-NOOUTLINE: "-target-feature" "-outline-atomics"
+
+! Use Fuchsia to ensure the outline atomics is enabled.
+! RUN: %flang --target=aarch64-none-fuchsia -### %s -o %t 2>&1 | FileCheck %s --check-prefix=CHECK-DEFAULT
+! CHECK-DEFAULT: "-target-feature" "+outline-atomics"
+
+! RUN: %flang -mno-outline-atomics --target=x86-none-none -### %s -o %t 2>&1 | FileCheck %s --check-prefix=CHECK-ERRMSG
+! CHECK-ERRMSG: warning: 'x86' does not support '-mno-outline-atomics'
+
+
diff --git a/flang/test/Driver/driver-help-hidden.f90 b/flang/test/Driver/driver-help-hidden.f90
index 25dfcf3c70d8e..36b7d207ad36a 100644
--- a/flang/test/Driver/driver-help-hidden.f90
+++ b/flang/test/Driver/driver-help-hidden.f90
@@ -122,7 +122,9 @@
! CHECK-NEXT: -mllvm=<arg> Alias for -mllvm
! CHECK-NEXT: -mllvm <value> Additional arguments to forward to LLVM's option processing
! CHECK-NEXT: -mmlir <value> Additional arguments to forward to MLIR's option processing
+! CHECK-NEXT: -mno-outline-atomics Don't generate local calls to out-of-line atomic operations
! CHECK-NEXT: -module-dir <dir> Put MODULE files in <dir>
+! CHECK-NEXT: -moutline-atomics Generate local calls to out-of-line atomic operations
! CHECK-NEXT: -mrvv-vector-bits=<value>
! CHECK-NEXT: Specify the size in bits of an RVV vector register
! CHECK-NEXT: -msve-vector-bits=<value>
diff --git a/flang/test/Driver/driver-help.f90 b/flang/test/Driver/driver-help.f90
index 9f0aae51c3f5d..f69f43712446e 100644
--- a/flang/test/Driver/driver-help.f90
+++ b/flang/test/Driver/driver-help.f90
@@ -108,7 +108,9 @@
! HELP-NEXT: -mllvm=<arg> Alias for -mllvm
! HELP-NEXT: -mllvm <value> Additional arguments to forward to LLVM's option processing
! HELP-NEXT: -mmlir <value> Additional arguments to forward to MLIR's option processing
+! HELP-NEXT: -mno-outline-atomics Don't generate local calls to out-of-line atomic operations
! HELP-NEXT: -module-dir <dir> Put MODULE files in <dir>
+! HELP-NEXT: -moutline-atomics Generate local calls to out-of-line atomic operations
! HELP-NEXT: -mrvv-vector-bits=<value>
! HELP-NEXT: Specify the size in bits of an RVV vector register
! HELP-NEXT: -msve-vector-bits=<value>
diff --git a/flang/test/Integration/aarch64-outline-atomics.f90 b/flang/test/Integration/aarch64-outline-atomics.f90
new file mode 100644
index 0000000000000..6c0367077f2d4
--- /dev/null
+++ b/flang/test/Integration/aarch64-outline-atomics.f90
@@ -0,0 +1,18 @@
+! RUN: %flang -S -emit-llvm --target=aarch64-none-none -moutline-atomics -o - %s | FileCheck %s --check-prefixes=CHECKON,CHECKALL
+! RUN: %flang -S -emit-llvm --target=aarch64-none-none -mno-outline-atomics -o - %s | FileCheck %s --check-prefixes=CHECKOFF,CHECKALL
+! REQUIRES: aarch64-registered-target
+
+subroutine test()
+ integer :: i
+
+ do i = 1, 10
+ end do
+end subroutine
+
+! CHECKALL-LABEL: define void @test_()
+! CHECKALL-SAME: #[[ATTR:[0-9]*]]
+! CHECKALL: attributes #[[ATTR]] =
+! Use CHECK-SAME to allow arbitrary other attributes to be present.
+! CHECKALL-SAME: target-features
+! CHECKON-SAME: +outline-atomics
+! CHECKOFF-SAME: -outline-atomics
More information about the cfe-commits
mailing list