-
Notifications
You must be signed in to change notification settings - Fork 10.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[flang]Add support for -moutline-atomics and -mno-outline-atomics #78755
Conversation
@llvm/pr-subscribers-flang-fir-hlfir @llvm/pr-subscribers-clang-driver Author: Mats Petersson (Leporacanthicus) ChangesThis adds the support to add the target-feature. It will be fully supported once the generic support for adding target-cpu and target-features attributes to functions has landed. See #78289. Regression tests for that will be added once that PR lands. Full diff: https://github.com/llvm/llvm-project/pull/78755.diff 6 Files Affected:
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index d2e6c3ff721c27..b8be694bf0bf80 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4960,10 +4960,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, FC1Option]>,
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, FC1Option]>,
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/Flang.cpp b/clang/lib/Driver/ToolChains/Flang.cpp
index 03d68c3df7fb37..7394ef6f601c7e 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -354,6 +354,27 @@ void Flang::addTargetOptions(const ArgList &Args,
CmdArgs.push_back(Args.MakeArgString(CPU));
}
+ 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");
+ }
+
// Add the target features.
switch (TC.getArch()) {
default:
@@ -674,7 +695,7 @@ void Flang::ConstructJob(Compilation &C, const JobAction &JA,
CmdArgs.push_back(Args.MakeArgString(TripleStr));
if (isa<PreprocessJobAction>(JA)) {
- CmdArgs.push_back("-E");
+ CmdArgs.push_back("-E");
} else if (isa<CompileJobAction>(JA) || isa<BackendJobAction>(JA)) {
if (JA.getType() == types::TY_Nothing) {
CmdArgs.push_back("-fsyntax-only");
diff --git a/flang/lib/Frontend/CompilerInvocation.cpp b/flang/lib/Frontend/CompilerInvocation.cpp
index a3c41fb4611f56..74127327e798e6 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -402,6 +402,21 @@ static void parseTargetArgs(TargetOptions &opts, llvm::opt::ArgList &args) {
for (const llvm::opt::Arg *currentArg :
args.filtered(clang::driver::options::OPT_target_feature))
opts.featuresAsWritten.emplace_back(currentArg->getValue());
+
+ llvm::Triple targetTriple{llvm::Triple(opts.triple)};
+ if (const llvm::opt::Arg *A =
+ args.getLastArg(clang::driver::options::OPT_moutline_atomics,
+ clang::driver::options::OPT_mno_outline_atomics)) {
+ // Option -moutline-atomics supported for AArch64 target only.
+ if (!targetTriple.isAArch64()) {
+ if (A->getOption().matches(
+ clang::driver::options::OPT_moutline_atomics)) {
+ opts.featuresAsWritten.push_back("+outline-atomics");
+ } else {
+ opts.featuresAsWritten.push_back("-outline-atomics");
+ }
+ }
+ }
}
// Tweak the frontend configuration based on the frontend action
diff --git a/flang/test/Driver/aarch64-outline-atomics.f90 b/flang/test/Driver/aarch64-outline-atomics.f90
new file mode 100644
index 00000000000000..f469d50290ef04
--- /dev/null
+++ b/flang/test/Driver/aarch64-outline-atomics.f90
@@ -0,0 +1,11 @@
+! 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"
+
+! 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 426b0e5a1c367d..13698b65ae461b 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 221da6439764b4..73f5d6ee846d3a 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>
@@ -246,8 +248,10 @@
! HELP-FC1-NEXT: -mframe-pointer=<value> Specify which frame pointers to retain.
! HELP-FC1-NEXT: -mllvm <value> Additional arguments to forward to LLVM's option processing
! HELP-FC1-NEXT: -mmlir <value> Additional arguments to forward to MLIR's option processing
+! HELP-FC1-NEXT: -mno-outline-atomics Don't generate local calls to out-of-line atomic operations
! HELP-FC1-NEXT: -module-dir <dir> Put MODULE files in <dir>
! HELP-FC1-NEXT: -module-suffix <suffix> Use <suffix> as the suffix for module files (the default value is `.mod`)
+! HELP-FC1-NEXT: -moutline-atomics Generate local calls to out-of-line atomic operations
! HELP-FC1-NEXT: -mreassociate Allow reassociation transformations for floating-point instructions
! HELP-FC1-NEXT: -mrelocation-model <value>
! HELP-FC1-NEXT: The relocation model to use
|
! 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" | ||
|
||
! 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' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should there be a test to check the behaviour when no outline flags are specified and the target is aarch64
?
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"); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this code be shared with Clang
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's usually done in places like https://github.com/llvm/llvm-project/blob/main/clang/lib/Driver/ToolChains/CommonArgs.cpp
args.getLastArg(clang::driver::options::OPT_moutline_atomics, | ||
clang::driver::options::OPT_mno_outline_atomics)) { | ||
// Option -moutline-atomics supported for AArch64 target only. | ||
if (!targetTriple.isAArch64()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this condition the wrong way around?
Clang has support for genarting atomic operations as functions rather than inline atomic operations, using a target feature. This is useful for code-size, some cases of debugging, and it also affects the ability to inline functions from C into Fortran or the other way around when using LTO - the inliner will check the target features to make sure functions are compatible, and a difference in outline-atomics would disable the inlining of an outline-atomics into a non-outline-atomics function.
Also invert condition pointed out in review.
7dcafdd
to
26e268b
Compare
✅ With the latest revision this PR passed the C/C++ code formatter. |
@@ -2790,3 +2790,27 @@ 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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is probably a clang-format issue here.
void addOutlineAtomicsArgs(const Driver &D, const ToolChain &TC, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs, const llvm::Triple &Triple); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: clang-format
} // end namespace tools | ||
} // end namespace driver | ||
} // end namespace clang | ||
|
||
clang::CodeGenOptions::FramePointerKind | ||
getFramePointerKind(const llvm::opt::ArgList &Args, const llvm::Triple &Triple); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: accidental change?
CmdArgs.push_back("-E"); | ||
CmdArgs.push_back("-E"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: accidental change.
llvm::Triple targetTriple{llvm::Triple(opts.triple)}; | ||
if (const llvm::opt::Arg *A = | ||
args.getLastArg(clang::driver::options::OPT_moutline_atomics, | ||
clang::driver::options::OPT_mno_outline_atomics)) { | ||
// Option -moutline-atomics supported for AArch64 target only. | ||
if (targetTriple.isAArch64()) { | ||
if (A->getOption().matches( | ||
clang::driver::options::OPT_moutline_atomics)) { | ||
opts.featuresAsWritten.push_back("+outline-atomics"); | ||
} else { | ||
opts.featuresAsWritten.push_back("-outline-atomics"); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this required? I did not see a corresponding change in Clang frontend driver.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LG. Please address or reply to comments before submitting.
@@ -0,0 +1,18 @@ | |||
! RUN: %flang -S -emit-llvm --target=aarch64-none-none -moutline-atomics -o - %s | FileCheck %s --check-prefixes=CHECKON,CHECKALL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is better if this is in the integration test directory.
This is breaking couple of arm buildbots. |
Thanks for letting me klnow. I have a fix in #80717
I'm not entirely sure why it's broken on Arm but not x86 - the tests run on both, and should give identical output [but clearly doesn't].
…--
Mats
[https://opengraph.githubassets.com/ce56cc443042f8ad8e40eab60d1e7385e82143e2d8f23e4ebfed483158d90a84/llvm/llvm-project/pull/80717]<https://github.com/llvm/llvm-project/pull/80717>
Fix broken ARM processor features test by Leporacanthicus ・ Pull Request #80717 ・ llvm/llvm-project<#80717>
This test failed when I pulled latest changes. I suspect it's my fault...
github.com
________________________________
From: Valentin Clement (バレンタイン クレメン) ***@***.***>
Sent: 05 February 2024 18:14
To: llvm/llvm-project ***@***.***>
Cc: Mats Petersson ***@***.***>; State change ***@***.***>
Subject: Re: [llvm/llvm-project] [flang]Add support for -moutline-atomics and -mno-outline-atomics (PR #78755)
This is breaking couple of arm buildbots.
―
Reply to this email directly, view it on GitHub<#78755 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/ABUDZBN3CSJ627INV3FTEMTYSEOPDAVCNFSM6AAAAABCCL4I56VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSMRXGY4DIOBUGU>.
You are receiving this because you modified the open/close state.Message ID: ***@***.***>
IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.
|
If you think this is the right fix then you should push it to solve the buildbots or revert the initial commit. |
…vm#78755) This adds the support to add the target-feature to outline atomic operations (calling the runtime library instead).
This adds the support to add the target-feature.
It will be fully supported once the generic support for adding target-cpu and target-features attributes to functions has landed. See #78289. Regression tests for that will be added once that PR lands.