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; + /// User explicitly specify -mcumode or -mno-cumode. + std::optional CUModeOpt; + /// 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") + CUModeOpt = true; + else if (F == "-cumode") + CUModeOpt = 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 @@ -487,6 +487,8 @@ Builder.defineMacro("FP_FAST_FMA"); Builder.defineMacro("__AMDGCN_WAVEFRONT_SIZE", Twine(WavefrontSize)); + if (CUModeOpt) + Builder.defineMacro("__AMDGCN_CUMODE_OPTION", Twine(CUModeOpt.value())); } void AMDGPUTargetInfo::setAuxTarget(const TargetInfo *Aux) { Index: clang/test/Driver/amdgpu-macros.cl =================================================================== --- clang/test/Driver/amdgpu-macros.cl +++ clang/test/Driver/amdgpu-macros.cl @@ -156,3 +156,14 @@ // 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=gfx1030 \ +// RUN: %s 2>&1 | FileCheck --check-prefix=CUMODE-DEFAULT %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 +// CUMODE-DEFAULT-NOT: #define __AMDGCN_CUMODE_OPTION +// CUMODE-DEFAULT-NOT: #define __AMDGCN_CUMODE_OPTION +// CUMODE-ON-DAG: #define __AMDGCN_CUMODE_OPTION 1 +// CUMODE-OFF-DAG: #define __AMDGCN_CUMODE_OPTION 0 Index: clang/test/Driver/hip-macros.hip =================================================================== --- clang/test/Driver/hip-macros.hip +++ clang/test/Driver/hip-macros.hip @@ -19,3 +19,14 @@ // 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=gfx1030 --cuda-device-only -nogpuinc -nogpulib \ +// RUN: %s 2>&1 | FileCheck --check-prefix=CUMODE-DEFAULT %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 +// CUMODE-DEFAULT-NOT: #define __AMDGCN_CUMODE_OPTION +// CUMODE-DEFAULT-NOT: #define __AMDGCN_CUMODE_OPTION +// CUMODE-ON-DAG: #define __AMDGCN_CUMODE_OPTION 1 +// CUMODE-OFF-DAG: #define __AMDGCN_CUMODE_OPTION 0