Index: clang/include/clang/Basic/DiagnosticDriverKinds.td =================================================================== --- clang/include/clang/Basic/DiagnosticDriverKinds.td +++ clang/include/clang/Basic/DiagnosticDriverKinds.td @@ -118,6 +118,9 @@ def warn_drv_unsupported_diag_option_for_flang : Warning< "The warning option '-%0' is not supported">, InGroup; +def warn_drv_unsupported_option_for_processor : Warning< + "ignoring '%0' option as it is not currently supported for processor '%1'">, + InGroup; def err_drv_invalid_thread_model_for_target : Error< "invalid thread model '%0' in '%1' for this target">; Index: clang/lib/Basic/Targets/AMDGPU.h =================================================================== --- clang/lib/Basic/Targets/AMDGPU.h +++ clang/lib/Basic/Targets/AMDGPU.h @@ -43,6 +43,9 @@ unsigned GPUFeatures; unsigned WavefrontSize; + /// Whether to use cumode or WGP mode. True for cumode. False for WGP mode. + bool CUMode; + /// Target ID is device name followed by optional feature name postfixed /// by plus or minus sign delimitted by colon, e.g. gfx908:xnack+:sramecc-. /// If the target ID contains feature+, map it to true. @@ -443,6 +446,10 @@ assert(F.front() == '+' || F.front() == '-'); if (F == "+wavefrontsize64") WavefrontSize = 64; + else if (F == "+cumode") + CUMode = true; + else if (F == "-cumode") + CUMode = false; bool IsOn = F.front() == '+'; StringRef Name = StringRef(F).drop_front(); if (!llvm::is_contained(TargetIDFeatures, Name)) Index: clang/lib/Basic/Targets/AMDGPU.cpp =================================================================== --- clang/lib/Basic/Targets/AMDGPU.cpp +++ clang/lib/Basic/Targets/AMDGPU.cpp @@ -17,7 +17,6 @@ #include "clang/Basic/LangOptions.h" #include "clang/Basic/MacroBuilder.h" #include "clang/Basic/TargetBuiltins.h" - using namespace clang; using namespace clang::targets; @@ -244,6 +243,7 @@ } MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 64; + CUMode = !(GPUFeatures & llvm::AMDGPU::FEATURE_WGP); } void AMDGPUTargetInfo::adjust(DiagnosticsEngine &Diags, LangOptions &Opts) { @@ -315,6 +315,7 @@ Builder.defineMacro("FP_FAST_FMA"); Builder.defineMacro("__AMDGCN_WAVEFRONT_SIZE", Twine(WavefrontSize)); + Builder.defineMacro("__AMDGCN_CUMODE__", Twine(CUMode)); } void AMDGPUTargetInfo::setAuxTarget(const TargetInfo *Aux) { Index: clang/lib/Driver/ToolChains/AMDGPU.cpp =================================================================== --- clang/lib/Driver/ToolChains/AMDGPU.cpp +++ clang/lib/Driver/ToolChains/AMDGPU.cpp @@ -582,8 +582,8 @@ options::OPT_mno_wavefrontsize64, false)) Features.push_back("+wavefrontsize64"); - handleTargetFeaturesGroup( - Args, Features, options::OPT_m_amdgpu_Features_Group); + handleTargetFeaturesGroup(D, Triple, Args, Features, + options::OPT_m_amdgpu_Features_Group); } /// AMDGPU Toolchain Index: clang/lib/Driver/ToolChains/Arch/PPC.cpp =================================================================== --- clang/lib/Driver/ToolChains/Arch/PPC.cpp +++ clang/lib/Driver/ToolChains/Arch/PPC.cpp @@ -116,7 +116,8 @@ if (Triple.getSubArch() == llvm::Triple::PPCSubArch_spe) Features.push_back("+spe"); - handleTargetFeaturesGroup(Args, Features, options::OPT_m_ppc_Features_Group); + handleTargetFeaturesGroup(D, Triple, Args, Features, + options::OPT_m_ppc_Features_Group); ppc::FloatABI FloatABI = ppc::getPPCFloatABI(D, Args); if (FloatABI == ppc::FloatABI::Soft) Index: clang/lib/Driver/ToolChains/Arch/RISCV.cpp =================================================================== --- clang/lib/Driver/ToolChains/Arch/RISCV.cpp +++ clang/lib/Driver/ToolChains/Arch/RISCV.cpp @@ -169,7 +169,8 @@ // Now add any that the user explicitly requested on the command line, // which may override the defaults. - handleTargetFeaturesGroup(Args, Features, options::OPT_m_riscv_Features_Group); + handleTargetFeaturesGroup(D, Triple, Args, Features, + options::OPT_m_riscv_Features_Group); } StringRef riscv::getRISCVABI(const ArgList &Args, const llvm::Triple &Triple) { Index: clang/lib/Driver/ToolChains/CommonArgs.h =================================================================== --- clang/lib/Driver/ToolChains/CommonArgs.h +++ clang/lib/Driver/ToolChains/CommonArgs.h @@ -188,7 +188,8 @@ /// Note: Since \p Features may contain default values before calling /// this function, or may be appended with entries to override arguments, /// entries in \p Features are not unique. -void handleTargetFeaturesGroup(const llvm::opt::ArgList &Args, +void handleTargetFeaturesGroup(const Driver &D, const llvm::Triple &Triple, + const llvm::opt::ArgList &Args, std::vector &Features, llvm::opt::OptSpecifier Group); Index: clang/lib/Driver/ToolChains/CommonArgs.cpp =================================================================== --- clang/lib/Driver/ToolChains/CommonArgs.cpp +++ clang/lib/Driver/ToolChains/CommonArgs.cpp @@ -131,15 +131,33 @@ "opt-remarks-hotness-threshold=" + A->getValue())); } +static bool shouldIgnoreUnsupportedTargetFeature(const Arg &TargetFeatureArg, + llvm::Triple T, + StringRef Processor) { + // Warn no-cumode for AMDGCN processors not supporing WGP mode. + if (!T.isAMDGPU()) + return false; + auto GPUKind = T.isAMDGCN() ? llvm::AMDGPU::parseArchAMDGCN(Processor) + : llvm::AMDGPU::parseArchR600(Processor); + auto GPUFeatures = T.isAMDGCN() ? llvm::AMDGPU::getArchAttrAMDGCN(GPUKind) + : llvm::AMDGPU::getArchAttrR600(GPUKind); + if (GPUFeatures & llvm::AMDGPU::FEATURE_WGP) + return false; + return TargetFeatureArg.getOption().matches(options::OPT_mno_cumode); +} + void tools::addPathIfExists(const Driver &D, const Twine &Path, ToolChain::path_list &Paths) { if (D.getVFS().exists(Path)) Paths.push_back(Path.str()); } -void tools::handleTargetFeaturesGroup(const ArgList &Args, +void tools::handleTargetFeaturesGroup(const Driver &D, + const llvm::Triple &Triple, + const ArgList &Args, std::vector &Features, OptSpecifier Group) { + std::set Warned; for (const Arg *A : Args.filtered(Group)) { StringRef Name = A->getOption().getName(); A->claim(); @@ -148,9 +166,21 @@ assert(Name.startswith("m") && "Invalid feature name."); Name = Name.substr(1); + auto Proc = getCPUName(D, Args, Triple); + if (shouldIgnoreUnsupportedTargetFeature(*A, Triple, Proc)) { + if (Warned.count(Name) == 0) { + D.getDiags().Report( + clang::diag::warn_drv_unsupported_option_for_processor) + << A->getAsString(Args) << Proc; + Warned.insert(Name); + } + continue; + } + bool IsNegative = Name.startswith("no-"); if (IsNegative) Name = Name.substr(3); + Features.push_back(Args.MakeArgString((IsNegative ? "-" : "+") + Name)); } } @@ -463,9 +493,12 @@ } } -static void getWebAssemblyTargetFeatures(const ArgList &Args, +static void getWebAssemblyTargetFeatures(const Driver &D, + const llvm::Triple &Triple, + const ArgList &Args, std::vector &Features) { - handleTargetFeaturesGroup(Args, Features, options::OPT_m_wasm_Features_Group); + handleTargetFeaturesGroup(D, Triple, Args, Features, + options::OPT_m_wasm_Features_Group); } void tools::getTargetFeatures(const Driver &D, const llvm::Triple &Triple, @@ -510,11 +543,11 @@ x86::getX86TargetFeatures(D, Triple, Args, Features); break; case llvm::Triple::hexagon: - hexagon::getHexagonTargetFeatures(D, Args, Features); + hexagon::getHexagonTargetFeatures(D, Triple, Args, Features); break; case llvm::Triple::wasm32: case llvm::Triple::wasm64: - getWebAssemblyTargetFeatures(Args, Features); + getWebAssemblyTargetFeatures(D, Triple, Args, Features); break; case llvm::Triple::sparc: case llvm::Triple::sparcel: Index: clang/lib/Driver/ToolChains/Hexagon.h =================================================================== --- clang/lib/Driver/ToolChains/Hexagon.h +++ clang/lib/Driver/ToolChains/Hexagon.h @@ -50,7 +50,8 @@ const char *LinkingOutput) const override; }; -void getHexagonTargetFeatures(const Driver &D, const llvm::opt::ArgList &Args, +void getHexagonTargetFeatures(const Driver &D, const llvm::Triple &Triple, + const llvm::opt::ArgList &Args, std::vector &Features); } // end namespace hexagon. Index: clang/lib/Driver/ToolChains/Hexagon.cpp =================================================================== --- clang/lib/Driver/ToolChains/Hexagon.cpp +++ clang/lib/Driver/ToolChains/Hexagon.cpp @@ -159,9 +159,11 @@ } // Hexagon target features. -void hexagon::getHexagonTargetFeatures(const Driver &D, const ArgList &Args, +void hexagon::getHexagonTargetFeatures(const Driver &D, + const llvm::Triple &Triple, + const ArgList &Args, std::vector &Features) { - handleTargetFeaturesGroup(Args, Features, + handleTargetFeaturesGroup(D, Triple, Args, Features, options::OPT_m_hexagon_Features_Group); bool UseLongCalls = false; Index: clang/test/CodeGenHIP/hip-cumode.hip =================================================================== --- /dev/null +++ clang/test/CodeGenHIP/hip-cumode.hip @@ -0,0 +1,20 @@ +// REQUIRES: amdgpu-registered-target + +// RUN: %clang -S -o - --offload-arch=gfx906 --cuda-device-only -nogpuinc -nogpulib \ +// RUN: %s 2>&1 | FileCheck --check-prefix=NOWGP %s +// RUN: %clang -S -o - --offload-arch=gfx906 --cuda-device-only -nogpuinc -nogpulib -mcumode \ +// RUN: %s 2>&1 | FileCheck --check-prefix=NOWGP %s +// RUN: %clang -S -o - --offload-arch=gfx906 --cuda-device-only -nogpuinc -nogpulib -mno-cumode \ +// RUN: %s 2>&1 | FileCheck --check-prefixes=NOWGP,WARN-CUMODE %s +// RUN: %clang -S -o - --offload-arch=gfx1030 --cuda-device-only -nogpuinc -nogpulib \ +// RUN: %s 2>&1 | FileCheck --check-prefix=CUMODE-OFF %s +// RUN: %clang -S -o - --offload-arch=gfx1030 --cuda-device-only -nogpuinc -nogpulib -mcumode \ +// RUN: %s 2>&1 | FileCheck --check-prefix=CUMODE-ON %s +// RUN: %clang -S -o - --offload-arch=gfx1030 --cuda-device-only -nogpuinc -nogpulib -mno-cumode \ +// RUN: %s 2>&1 | FileCheck --check-prefix=CUMODE-OFF %s +// WARN-CUMODE: warning: ignoring '-mno-cumode' option as it is not currently supported for processor 'gfx906' [-Woption-ignored] +// NOWGP-NOT: .amdhsa_workgroup_processor_mode +// CUMODE-ON: .amdhsa_workgroup_processor_mode 0 +// CUMODE-OFF: .amdhsa_workgroup_processor_mode 1 + +__attribute__((global)) void kernel() {} Index: clang/test/Driver/amdgpu-macros.cl =================================================================== --- clang/test/Driver/amdgpu-macros.cl +++ clang/test/Driver/amdgpu-macros.cl @@ -158,3 +158,19 @@ // RUN: -mwavefrontsize64 %s 2>&1 | FileCheck --check-prefix=WAVE64 %s // WAVE64-DAG: #define __AMDGCN_WAVEFRONT_SIZE 64 // WAVE32-DAG: #define __AMDGCN_WAVEFRONT_SIZE 32 + +// RUN: %clang -E -dM -target amdgcn -mcpu=gfx906 \ +// RUN: %s 2>&1 | FileCheck --check-prefix=CUMODE-ON %s +// RUN: %clang -E -dM -target amdgcn -mcpu=gfx906 -mcumode \ +// RUN: %s 2>&1 | FileCheck --check-prefix=CUMODE-ON %s +// RUN: %clang -E -dM -target amdgcn -mcpu=gfx906 -mno-cumode \ +// RUN: %s 2>&1 | FileCheck --check-prefixes=CUMODE-ON,WARN-CUMODE %s +// RUN: %clang -E -dM -target amdgcn -mcpu=gfx1030 \ +// RUN: %s 2>&1 | FileCheck --check-prefix=CUMODE-OFF %s +// RUN: %clang -E -dM -target amdgcn -mcpu=gfx1030 -mcumode \ +// RUN: %s 2>&1 | FileCheck --check-prefix=CUMODE-ON %s +// RUN: %clang -E -dM -target amdgcn -mcpu=gfx1030 -mno-cumode \ +// RUN: %s 2>&1 | FileCheck --check-prefix=CUMODE-OFF %s +// WARN-CUMODE-DAG: warning: ignoring '-mno-cumode' option as it is not currently supported for processor 'gfx906' [-Woption-ignored] +// CUMODE-ON-DAG: #define __AMDGCN_CUMODE__ 1 +// CUMODE-OFF-DAG: #define __AMDGCN_CUMODE__ 0 Index: clang/test/Driver/hip-macros.hip =================================================================== --- clang/test/Driver/hip-macros.hip +++ clang/test/Driver/hip-macros.hip @@ -19,3 +19,26 @@ // RUN: -mwavefrontsize64 %s 2>&1 | FileCheck --check-prefixes=WAVE64 %s // WAVE64-DAG: #define __AMDGCN_WAVEFRONT_SIZE 64 // WAVE32-DAG: #define __AMDGCN_WAVEFRONT_SIZE 32 + +// RUN: %clang -E -dM --offload-arch=gfx906 --cuda-device-only -nogpuinc -nogpulib \ +// RUN: %s 2>&1 | FileCheck --check-prefix=CUMODE-ON %s +// RUN: %clang -E -dM --offload-arch=gfx906 --cuda-device-only -nogpuinc -nogpulib -mcumode \ +// RUN: %s 2>&1 | FileCheck --check-prefix=CUMODE-ON %s +// RUN: %clang -E -dM --offload-arch=gfx906 --cuda-device-only -nogpuinc -nogpulib -mno-cumode \ +// RUN: %s 2>&1 | FileCheck --check-prefixes=CUMODE-ON,WARN-CUMODE %s +// RUN: %clang -E -dM --offload-arch=gfx1030 --cuda-device-only -nogpuinc -nogpulib \ +// RUN: %s 2>&1 | FileCheck --check-prefix=CUMODE-OFF %s +// RUN: %clang -E -dM --offload-arch=gfx1030 --cuda-device-only -nogpuinc -nogpulib -mcumode \ +// RUN: %s 2>&1 | FileCheck --check-prefix=CUMODE-ON %s +// RUN: %clang -E -dM --offload-arch=gfx1030 --cuda-device-only -nogpuinc -nogpulib -mno-cumode \ +// RUN: %s 2>&1 | FileCheck --check-prefix=CUMODE-OFF %s + +// Check no duplicate warnings. +// RUN: %clang -E -dM --offload-arch=gfx906 --cuda-device-only -nogpuinc -nogpulib -mcumode \ +// RUN: -mno-cumode -mno-cumode \ +// RUN: %s 2>&1 | FileCheck --check-prefixes=CUMODE-ON,WARN-CUMODE %s + +// WARN-CUMODE-DAG: warning: ignoring '-mno-cumode' option as it is not currently supported for processor 'gfx906' [-Woption-ignored] +// WARN-CUMODE-NOT: warning: ignoring '-mno-cumode' option as it is not currently supported for processor 'gfx906' [-Woption-ignored] +// CUMODE-ON-DAG: #define __AMDGCN_CUMODE__ 1 +// CUMODE-OFF-DAG: #define __AMDGCN_CUMODE__ 0 Index: llvm/include/llvm/TargetParser/TargetParser.h =================================================================== --- llvm/include/llvm/TargetParser/TargetParser.h +++ llvm/include/llvm/TargetParser/TargetParser.h @@ -137,6 +137,9 @@ // Sram-ecc is available. FEATURE_SRAMECC = 1 << 8, + + // WGP mode is supported. + FEATURE_WGP = 1 << 9, }; StringRef getArchNameAMDGCN(GPUKind AK); Index: llvm/lib/TargetParser/TargetParser.cpp =================================================================== --- llvm/lib/TargetParser/TargetParser.cpp +++ llvm/lib/TargetParser/TargetParser.cpp @@ -107,21 +107,21 @@ {{"gfx940"}, {"gfx940"}, GK_GFX940, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_XNACK|FEATURE_SRAMECC}, {{"gfx941"}, {"gfx941"}, GK_GFX941, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_XNACK|FEATURE_SRAMECC}, {{"gfx942"}, {"gfx942"}, GK_GFX942, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_XNACK|FEATURE_SRAMECC}, - {{"gfx1010"}, {"gfx1010"}, GK_GFX1010, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32|FEATURE_XNACK}, - {{"gfx1011"}, {"gfx1011"}, GK_GFX1011, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32|FEATURE_XNACK}, - {{"gfx1012"}, {"gfx1012"}, GK_GFX1012, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32|FEATURE_XNACK}, - {{"gfx1013"}, {"gfx1013"}, GK_GFX1013, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32|FEATURE_XNACK}, - {{"gfx1030"}, {"gfx1030"}, GK_GFX1030, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32}, - {{"gfx1031"}, {"gfx1031"}, GK_GFX1031, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32}, - {{"gfx1032"}, {"gfx1032"}, GK_GFX1032, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32}, - {{"gfx1033"}, {"gfx1033"}, GK_GFX1033, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32}, - {{"gfx1034"}, {"gfx1034"}, GK_GFX1034, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32}, - {{"gfx1035"}, {"gfx1035"}, GK_GFX1035, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32}, - {{"gfx1036"}, {"gfx1036"}, GK_GFX1036, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32}, - {{"gfx1100"}, {"gfx1100"}, GK_GFX1100, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32}, - {{"gfx1101"}, {"gfx1101"}, GK_GFX1101, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32}, - {{"gfx1102"}, {"gfx1102"}, GK_GFX1102, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32}, - {{"gfx1103"}, {"gfx1103"}, GK_GFX1103, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32}, + {{"gfx1010"}, {"gfx1010"}, GK_GFX1010, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32|FEATURE_XNACK|FEATURE_WGP}, + {{"gfx1011"}, {"gfx1011"}, GK_GFX1011, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32|FEATURE_XNACK|FEATURE_WGP}, + {{"gfx1012"}, {"gfx1012"}, GK_GFX1012, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32|FEATURE_XNACK|FEATURE_WGP}, + {{"gfx1013"}, {"gfx1013"}, GK_GFX1013, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32|FEATURE_XNACK|FEATURE_WGP}, + {{"gfx1030"}, {"gfx1030"}, GK_GFX1030, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32|FEATURE_WGP}, + {{"gfx1031"}, {"gfx1031"}, GK_GFX1031, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32|FEATURE_WGP}, + {{"gfx1032"}, {"gfx1032"}, GK_GFX1032, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32|FEATURE_WGP}, + {{"gfx1033"}, {"gfx1033"}, GK_GFX1033, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32|FEATURE_WGP}, + {{"gfx1034"}, {"gfx1034"}, GK_GFX1034, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32|FEATURE_WGP}, + {{"gfx1035"}, {"gfx1035"}, GK_GFX1035, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32|FEATURE_WGP}, + {{"gfx1036"}, {"gfx1036"}, GK_GFX1036, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32|FEATURE_WGP}, + {{"gfx1100"}, {"gfx1100"}, GK_GFX1100, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32|FEATURE_WGP}, + {{"gfx1101"}, {"gfx1101"}, GK_GFX1101, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32|FEATURE_WGP}, + {{"gfx1102"}, {"gfx1102"}, GK_GFX1102, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32|FEATURE_WGP}, + {{"gfx1103"}, {"gfx1103"}, GK_GFX1103, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32|FEATURE_WGP}, }; const GPUInfo *getArchEntry(AMDGPU::GPUKind AK, ArrayRef Table) {