JonChesterfield created this revision. JonChesterfield added reviewers: yaxunl, t-tye, kzhuravl, ronlieb, b-sumner. Herald added subscribers: kerbowa, pengfei, tpr, dstuttard, nhaehnle, jvesely. JonChesterfield requested review of this revision. Herald added subscribers: cfe-commits, sstefan1, wdng. Herald added a reviewer: jdoerfert. Herald added a project: clang.
[clang][amdgpu] Use implicit code object default At present, clang always passes amdhsa-code-object-version on to -cc1. That is great for certainty over what object version is being used when debugging. Unfortunately, the command line argument is in AMDGPUBaseInfo.cpp in the amdgpu target. If clang is used with an llvm compiled with DLLVM_TARGETS_TO_BUILD that excludes amdgpu, this will be diagnosed (as discovered via D98658 <https://reviews.llvm.org/D98658>): - Unknown command line argument '--amdhsa-code-object-version=3' This means that clang, built only for X86, can be used to compile the nvptx devicertl for openmp but not the amdgpu one. That would shortly spawn fragile logic in the devicertl cmake to try to guess whether the clang used will work. This change omits the amdhsa-code-object-version parameter when it matches the default that AMDGPUBaseInfo.cpp specifies, with a comment to indicate why. As this is the only part of clang's codegen for amdgpu that depends on the target in the back end it suffices to build the openmp runtime on most (all?) systems. It is a non-functional change, though observable in the updated tests and when compiling with -###. It may cause minor disruption to the amd-stg-open branch. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D98746 Files: clang/lib/Driver/ToolChains/Clang.cpp clang/test/Driver/amdgpu-features-as.s clang/test/Driver/amdgpu-features.c Index: clang/test/Driver/amdgpu-features.c =================================================================== --- clang/test/Driver/amdgpu-features.c +++ clang/test/Driver/amdgpu-features.c @@ -1,6 +1,5 @@ // RUN: %clang -### -target amdgcn-amd-amdhsa -mcpu=gfx700 -mcode-object-v3 %s 2>&1 | FileCheck --check-prefix=CODE-OBJECT-V3 %s // CODE-OBJECT-V3: warning: argument '-mcode-object-v3' is deprecated, use '-mcode-object-version=3' instead [-Wdeprecated] -// CODE-OBJECT-V3: "-mllvm" "--amdhsa-code-object-version=3" // RUN: %clang -### -target amdgcn-amd-amdhsa amdgcn -mcpu=gfx700 -mno-code-object-v3 %s 2>&1 | FileCheck --check-prefix=NO-CODE-OBJECT-V3 %s // NO-CODE-OBJECT-V3: warning: argument '-mno-code-object-v3' is deprecated, use '-mcode-object-version=2' instead [-Wdeprecated] @@ -8,7 +7,6 @@ // RUN: %clang -### -target amdgcn-amd-amdhsa -mcpu=gfx700 -mcode-object-v3 -mno-code-object-v3 -mcode-object-v3 %s 2>&1 | FileCheck --check-prefix=MUL-CODE-OBJECT-V3 %s // MUL-CODE-OBJECT-V3: warning: argument '-mcode-object-v3' is deprecated, use '-mcode-object-version=3' instead [-Wdeprecated] -// MUL-CODE-OBJECT-V3: "-mllvm" "--amdhsa-code-object-version=3" // RUN: %clang -### -target amdgcn-amdhsa -mcpu=gfx900:xnack+ %s 2>&1 | FileCheck --check-prefix=XNACK %s // XNACK: "-target-feature" "+xnack" Index: clang/test/Driver/amdgpu-features-as.s =================================================================== --- clang/test/Driver/amdgpu-features-as.s +++ clang/test/Driver/amdgpu-features-as.s @@ -1,6 +1,5 @@ // RUN: %clang -### -target amdgcn-amd-amdhsa -mcpu=gfx900 -mcode-object-v3 %s 2>&1 | FileCheck --check-prefix=CODE-OBJECT-V3 %s // CODE-OBJECT-V3: warning: argument '-mcode-object-v3' is deprecated, use '-mcode-object-version=3' instead [-Wdeprecated] -// CODE-OBJECT-V3: "-mllvm" "--amdhsa-code-object-version=3" // RUN: %clang -### -target amdgcn-amd-amdhsa amdgcn -mcpu=gfx900 -mno-code-object-v3 %s 2>&1 | FileCheck --check-prefix=NO-CODE-OBJECT-V3 %s // NO-CODE-OBJECT-V3: warning: argument '-mno-code-object-v3' is deprecated, use '-mcode-object-version=2' instead [-Wdeprecated] @@ -8,4 +7,3 @@ // RUN: %clang -### -target amdgcn-amd-amdhsa -mcpu=gfx900 -mcode-object-v3 -mno-code-object-v3 -mcode-object-v3 %s 2>&1 | FileCheck --check-prefix=MUL-CODE-OBJECT-V3 %s // MUL-CODE-OBJECT-V3: warning: argument '-mcode-object-v3' is deprecated, use '-mcode-object-version=3' instead [-Wdeprecated] -// MUL-CODE-OBJECT-V3: "-mllvm" "--amdhsa-code-object-version=3" Index: clang/lib/Driver/ToolChains/Clang.cpp =================================================================== --- clang/lib/Driver/ToolChains/Clang.cpp +++ clang/lib/Driver/ToolChains/Clang.cpp @@ -1112,10 +1112,15 @@ const ArgList &Args, ArgStringList &CmdArgs) { unsigned CodeObjVer = getOrCheckAMDGPUCodeObjectVersion(D, Args); - CmdArgs.insert(CmdArgs.begin() + 1, - Args.MakeArgString(Twine("--amdhsa-code-object-version=") + - Twine(CodeObjVer))); - CmdArgs.insert(CmdArgs.begin() + 1, "-mllvm"); + // Currently defaults to 3 in AMDGPUBaseInfo.cpp + // Using that default lets clang emit IR for amdgcn when llvm has been built + // without that target, provided the user wants this code object version + if (CodeObjVer != 3) { + CmdArgs.insert(CmdArgs.begin() + 1, + Args.MakeArgString(Twine("--amdhsa-code-object-version=") + + Twine(CodeObjVer))); + CmdArgs.insert(CmdArgs.begin() + 1, "-mllvm"); + } } void Clang::AddPreprocessingOptions(Compilation &C, const JobAction &JA,
Index: clang/test/Driver/amdgpu-features.c =================================================================== --- clang/test/Driver/amdgpu-features.c +++ clang/test/Driver/amdgpu-features.c @@ -1,6 +1,5 @@ // RUN: %clang -### -target amdgcn-amd-amdhsa -mcpu=gfx700 -mcode-object-v3 %s 2>&1 | FileCheck --check-prefix=CODE-OBJECT-V3 %s // CODE-OBJECT-V3: warning: argument '-mcode-object-v3' is deprecated, use '-mcode-object-version=3' instead [-Wdeprecated] -// CODE-OBJECT-V3: "-mllvm" "--amdhsa-code-object-version=3" // RUN: %clang -### -target amdgcn-amd-amdhsa amdgcn -mcpu=gfx700 -mno-code-object-v3 %s 2>&1 | FileCheck --check-prefix=NO-CODE-OBJECT-V3 %s // NO-CODE-OBJECT-V3: warning: argument '-mno-code-object-v3' is deprecated, use '-mcode-object-version=2' instead [-Wdeprecated] @@ -8,7 +7,6 @@ // RUN: %clang -### -target amdgcn-amd-amdhsa -mcpu=gfx700 -mcode-object-v3 -mno-code-object-v3 -mcode-object-v3 %s 2>&1 | FileCheck --check-prefix=MUL-CODE-OBJECT-V3 %s // MUL-CODE-OBJECT-V3: warning: argument '-mcode-object-v3' is deprecated, use '-mcode-object-version=3' instead [-Wdeprecated] -// MUL-CODE-OBJECT-V3: "-mllvm" "--amdhsa-code-object-version=3" // RUN: %clang -### -target amdgcn-amdhsa -mcpu=gfx900:xnack+ %s 2>&1 | FileCheck --check-prefix=XNACK %s // XNACK: "-target-feature" "+xnack" Index: clang/test/Driver/amdgpu-features-as.s =================================================================== --- clang/test/Driver/amdgpu-features-as.s +++ clang/test/Driver/amdgpu-features-as.s @@ -1,6 +1,5 @@ // RUN: %clang -### -target amdgcn-amd-amdhsa -mcpu=gfx900 -mcode-object-v3 %s 2>&1 | FileCheck --check-prefix=CODE-OBJECT-V3 %s // CODE-OBJECT-V3: warning: argument '-mcode-object-v3' is deprecated, use '-mcode-object-version=3' instead [-Wdeprecated] -// CODE-OBJECT-V3: "-mllvm" "--amdhsa-code-object-version=3" // RUN: %clang -### -target amdgcn-amd-amdhsa amdgcn -mcpu=gfx900 -mno-code-object-v3 %s 2>&1 | FileCheck --check-prefix=NO-CODE-OBJECT-V3 %s // NO-CODE-OBJECT-V3: warning: argument '-mno-code-object-v3' is deprecated, use '-mcode-object-version=2' instead [-Wdeprecated] @@ -8,4 +7,3 @@ // RUN: %clang -### -target amdgcn-amd-amdhsa -mcpu=gfx900 -mcode-object-v3 -mno-code-object-v3 -mcode-object-v3 %s 2>&1 | FileCheck --check-prefix=MUL-CODE-OBJECT-V3 %s // MUL-CODE-OBJECT-V3: warning: argument '-mcode-object-v3' is deprecated, use '-mcode-object-version=3' instead [-Wdeprecated] -// MUL-CODE-OBJECT-V3: "-mllvm" "--amdhsa-code-object-version=3" Index: clang/lib/Driver/ToolChains/Clang.cpp =================================================================== --- clang/lib/Driver/ToolChains/Clang.cpp +++ clang/lib/Driver/ToolChains/Clang.cpp @@ -1112,10 +1112,15 @@ const ArgList &Args, ArgStringList &CmdArgs) { unsigned CodeObjVer = getOrCheckAMDGPUCodeObjectVersion(D, Args); - CmdArgs.insert(CmdArgs.begin() + 1, - Args.MakeArgString(Twine("--amdhsa-code-object-version=") + - Twine(CodeObjVer))); - CmdArgs.insert(CmdArgs.begin() + 1, "-mllvm"); + // Currently defaults to 3 in AMDGPUBaseInfo.cpp + // Using that default lets clang emit IR for amdgcn when llvm has been built + // without that target, provided the user wants this code object version + if (CodeObjVer != 3) { + CmdArgs.insert(CmdArgs.begin() + 1, + Args.MakeArgString(Twine("--amdhsa-code-object-version=") + + Twine(CodeObjVer))); + CmdArgs.insert(CmdArgs.begin() + 1, "-mllvm"); + } } void Clang::AddPreprocessingOptions(Compilation &C, const JobAction &JA,
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits