Skip to content

Commit

Permalink
[AMDGPU] Correctly exclude the HIP host from arch macros
Browse files Browse the repository at this point in the history
Summary:
This logic was wrong and accidentally appling to OpenCL.
  • Loading branch information
jhuber6 committed Jan 30, 2024
1 parent 85a847f commit 6fecfbc
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions clang/lib/Basic/Targets/AMDGPU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,14 +275,15 @@ void AMDGPUTargetInfo::getTargetDefines(const LangOptions &Opts,
Builder.defineMacro("__R600__");

// Legacy HIP host code relies on these default attributes to be defined.
if (GPUKind == llvm::AMDGPU::GK_NONE && !(Opts.HIP && !Opts.CUDAIsDevice))
bool IsHIPHost = Opts.HIP && !Opts.CUDAIsDevice;
if (GPUKind == llvm::AMDGPU::GK_NONE && !IsHIPHost)
return;

StringRef CanonName = isAMDGCN(getTriple()) ? getArchNameAMDGCN(GPUKind)
: getArchNameR600(GPUKind);
Builder.defineMacro(Twine("__") + Twine(CanonName) + Twine("__"));
// Emit macros for gfx family e.g. gfx906 -> __GFX9__, gfx1030 -> __GFX10___
if (isAMDGCN(getTriple()) && Opts.CUDAIsDevice) {
if (isAMDGCN(getTriple()) && !IsHIPHost) {
assert(CanonName.starts_with("gfx") && "Invalid amdgcn canonical name");
Builder.defineMacro(Twine("__") + Twine(CanonName.drop_back(2).upper()) +
Twine("__"));
Expand Down

0 comments on commit 6fecfbc

Please sign in to comment.