-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[Flang][Driver][AMDGPU] Fix -mcode-object-version #134230
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
Conversation
This patch updates flang to follow clang's behavior when processing the `-mcode-object-version option`. It is now used to populate an LLVM module flag called `amdhsa_code_object_version` expected by the backend and also updates the driver to add the `--amdhsa-code-object-version` option to the frontend invocation for device compilation of AMDGPU targets.
@llvm/pr-subscribers-clang-driver @llvm/pr-subscribers-clang Author: Sergio Afonso (skatrak) ChangesThis patch updates flang to follow clang's behavior when processing the It is now used to populate an LLVM module flag called Full diff: https://github.com/llvm/llvm-project/pull/134230.diff 5 Files Affected:
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp b/clang/lib/Driver/ToolChains/Flang.cpp
index 8312234e33a64..82d5201e4f337 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -410,6 +410,9 @@ void Flang::AddAMDGPUTargetArgs(const ArgList &Args,
if (Arg *A = Args.getLastArg(options::OPT_mcode_object_version_EQ)) {
StringRef Val = A->getValue();
CmdArgs.push_back(Args.MakeArgString("-mcode-object-version=" + Val));
+ CmdArgs.push_back(Args.MakeArgString("-mllvm"));
+ CmdArgs.push_back(
+ Args.MakeArgString("--amdhsa-code-object-version=" + Val));
}
const ToolChain &TC = getToolChain();
diff --git a/flang/include/flang/Frontend/CodeGenOptions.h b/flang/include/flang/Frontend/CodeGenOptions.h
index 23d99e1f0897a..2b4e823b3fef4 100644
--- a/flang/include/flang/Frontend/CodeGenOptions.h
+++ b/flang/include/flang/Frontend/CodeGenOptions.h
@@ -95,7 +95,7 @@ class CodeGenOptions : public CodeGenOptionsBase {
/// \brief Code object version for AMDGPU.
llvm::CodeObjectVersionKind CodeObjectVersion =
- llvm::CodeObjectVersionKind::COV_5;
+ llvm::CodeObjectVersionKind::COV_None;
/// Optimization remark with an optional regular expression pattern.
struct OptRemark {
diff --git a/flang/lib/Frontend/FrontendActions.cpp b/flang/lib/Frontend/FrontendActions.cpp
index bd2c0632cb35d..d304e74f34f5c 100644
--- a/flang/lib/Frontend/FrontendActions.cpp
+++ b/flang/lib/Frontend/FrontendActions.cpp
@@ -804,6 +804,17 @@ void CodeGenAction::generateLLVMIR() {
llvmModule->addModuleFlag(
llvm::Module::Error, "target-abi",
llvm::MDString::get(llvmModule->getContext(), targetOpts.abi));
+
+ if (triple.isAMDGPU() ||
+ (triple.isSPIRV() && triple.getVendor() == llvm::Triple::AMD)) {
+ // Emit amdhsa_code_object_version module flag, which is code object version
+ // times 100.
+ if (opts.CodeObjectVersion != llvm::CodeObjectVersionKind::COV_None) {
+ llvmModule->addModuleFlag(llvm::Module::Error,
+ "amdhsa_code_object_version",
+ opts.CodeObjectVersion);
+ }
+ }
}
static std::unique_ptr<llvm::raw_pwrite_stream>
diff --git a/flang/test/Driver/code-object-version.f90 b/flang/test/Driver/code-object-version.f90
index e10877563c4d0..430cc864d03ec 100644
--- a/flang/test/Driver/code-object-version.f90
+++ b/flang/test/Driver/code-object-version.f90
@@ -5,5 +5,12 @@
! RUN: %flang -target x86_64-unknown-linux-gnu -mcode-object-version=3 -S %s -o \
! RUN: /dev/null 2>&1 | FileCheck --check-prefix=UNUSED_PARAM %s
+! RUN: %flang -target amdgcn-amd-amdhsa -mcpu=gfx908 -mcode-object-version=5 -nogpulib -c %s -### 2>&1 \
+! RUN: | FileCheck %s -check-prefix=VALID_USE
+
! INVALID_VERSION: error: invalid integral value '3' in '-mcode-object-version=3'
! UNUSED_PARAM: warning: argument unused during compilation: '-mcode-object-version=3' [-Wunused-command-line-argument]
+
+! VALID_USE: "-fc1" "-triple" "amdgcn-amd-amdhsa"
+! VALID_USE-SAME: "-mcode-object-version=5"
+! VALID_USE-SAME: "-mllvm" "--amdhsa-code-object-version=5"
diff --git a/flang/test/Integration/amdgpu-code-object-version.f90 b/flang/test/Integration/amdgpu-code-object-version.f90
new file mode 100644
index 0000000000000..c5194d2007f2a
--- /dev/null
+++ b/flang/test/Integration/amdgpu-code-object-version.f90
@@ -0,0 +1,22 @@
+!REQUIRES: amdgpu-registered-target
+
+!RUN: %flang_fc1 -emit-llvm -triple amdgcn-amd-amdhsa -target-cpu gfx908 %s -o - | FileCheck --check-prefix=COV-DEFAULT %s
+!RUN: %flang_fc1 -emit-llvm -triple amdgcn-amd-amdhsa -target-cpu gfx908 -mcode-object-version=none %s -o - | FileCheck --check-prefix=COV-NONE %s
+!RUN: %flang_fc1 -emit-llvm -triple amdgcn-amd-amdhsa -target-cpu gfx908 -mcode-object-version=4 %s -o - | FileCheck --check-prefix=COV-4 %s
+!RUN: %flang_fc1 -emit-llvm -triple amdgcn-amd-amdhsa -target-cpu gfx908 -mcode-object-version=5 %s -o - | FileCheck --check-prefix=COV-5 %s
+!RUN: %flang_fc1 -emit-llvm -triple amdgcn-amd-amdhsa -target-cpu gfx908 -mcode-object-version=6 %s -o - | FileCheck --check-prefix=COV-6 %s
+
+!COV-DEFAULT-NOT: !{{.*}} = !{{{.*}}, !"amdhsa_code_object_version", {{.*}}}
+!COV-NONE-NOT: !{{.*}} = !{{{.*}}, !"amdhsa_code_object_version", {{.*}}}
+
+!COV-4: !llvm.module.flags = !{{{.*}}, ![[COV_FLAG:.*]]}
+!COV-4: ![[COV_FLAG]] = !{i32 1, !"amdhsa_code_object_version", i32 400}
+
+!COV-5: !llvm.module.flags = !{{{.*}}, ![[COV_FLAG:.*]]}
+!COV-5: ![[COV_FLAG]] = !{i32 1, !"amdhsa_code_object_version", i32 500}
+
+!COV-6: !llvm.module.flags = !{{{.*}}, ![[COV_FLAG:.*]]}
+!COV-6: ![[COV_FLAG]] = !{i32 1, !"amdhsa_code_object_version", i32 600}
+
+subroutine target_simple
+end subroutine
|
This patch adds the `-L` lines in clang cfg files also to flang, making them the same. This is currently needed, in addition to llvm/llvm-project#134230, to get the `-mcode-object-version` option to work properly for flang.
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.
LGTM. Thanks.
This patch adds the `-L` lines in clang cfg files also to flang, making them the same. This is currently needed, in addition to llvm/llvm-project#134230, to get the `-mcode-object-version` option to work properly for flang.
breaks many smoke-fort, ovo, sollve tests This reverts commit a17d496.
…vm#134230)"" This reverts commit bf5c354.
This patch updates flang to follow clang's behavior when processing the
-mcode-object-version
option.It is now used to populate an LLVM module flag called
amdhsa_code_object_version
expected by the backend and also updates the driver to add the--amdhsa-code-object-version
option to the frontend invocation for device compilation of AMDGPU targets.