Skip to content

Commit 9fd288e

Browse files
authored
clang/AMDGPU: Enable opencl 2.0 features for unknown target (#170308)
Assume amdhsa triples support flat addressing, which matches the backend logic for the default target. This fixes the rocm device-libs build.
1 parent 9dd3346 commit 9fd288e

File tree

4 files changed

+21
-5
lines changed

4 files changed

+21
-5
lines changed

clang/lib/Basic/Targets/AMDGPU.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,18 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUTargetInfo final : public TargetInfo {
8484
return TT.getArch() == llvm::Triple::r600;
8585
}
8686

87+
bool hasFlatSupport() const {
88+
if (GPUKind >= llvm::AMDGPU::GK_GFX700)
89+
return true;
90+
91+
// Dummy target is assumed to be gfx700+ for amdhsa.
92+
if (GPUKind == llvm::AMDGPU::GK_NONE &&
93+
getTriple().getOS() == llvm::Triple::AMDHSA)
94+
return true;
95+
96+
return false;
97+
}
98+
8799
public:
88100
AMDGPUTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts);
89101

@@ -325,7 +337,7 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUTargetInfo final : public TargetInfo {
325337
Opts["__opencl_c_atomic_order_seq_cst"] = true;
326338
Opts["__opencl_c_atomic_scope_all_devices"] = true;
327339

328-
if (GPUKind >= llvm::AMDGPU::GK_GFX700) {
340+
if (hasFlatSupport()) {
329341
Opts["__opencl_c_generic_address_space"] = true;
330342
Opts["__opencl_c_device_enqueue"] = true;
331343
}

clang/test/CodeGenOpenCL/address-spaces.cl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
// RUN: %clang_cc1 %s -O0 -cl-std=CL3.0 -cl-ext=-all -ffake-address-space-map -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,SPIR
33
// RUN: %clang_cc1 %s -O0 -cl-std=clc++2021 -cl-ext=-all -ffake-address-space-map -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,SPIR
44
// RUN: %clang_cc1 %s -O0 -DCL20 -cl-std=CL2.0 -ffake-address-space-map -emit-llvm -o - | FileCheck %s --check-prefixes=CL20,CL20SPIR
5-
// RUN: %clang_cc1 %s -O0 -triple amdgcn-amd-amdhsa -emit-llvm -o - | FileCheck --check-prefixes=CHECK,AMDGCN %s
6-
// RUN: %clang_cc1 %s -O0 -triple amdgcn-amd-amdhsa -cl-std=CL3.0 -emit-llvm -o - | FileCheck --check-prefixes=CHECK,AMDGCN %s
5+
// RUN: %clang_cc1 %s -O0 -triple amdgcn-amd-mesa3d -emit-llvm -o - | FileCheck --check-prefixes=CHECK,AMDGCN %s
6+
// RUN: %clang_cc1 %s -O0 -triple amdgcn-amd-mesa3d -cl-std=CL3.0 -emit-llvm -o - | FileCheck --check-prefixes=CHECK,AMDGCN %s
77
// RUN: %clang_cc1 %s -O0 -triple amdgcn-amd-amdhsa -DCL20 -cl-std=CL2.0 -emit-llvm -o - | FileCheck %s --check-prefixes=CL20,CL20AMDGCN
8+
// RUN: %clang_cc1 %s -O0 -triple amdgcn-amd-amdhsa -DCL20 -cl-std=CL3.0 -emit-llvm -o - | FileCheck %s --check-prefixes=CL20,CL20AMDGCN
89
// RUN: %clang_cc1 %s -O0 -triple amdgcn-mesa-mesa3d -emit-llvm -o - | FileCheck --check-prefixes=CHECK,AMDGCN %s
910
// RUN: %clang_cc1 %s -O0 -triple amdgcn-mesa-mesa3d -cl-std=CL3.0 -emit-llvm -o - | FileCheck --check-prefixes=CHECK,AMDGCN %s
1011
// RUN: %clang_cc1 %s -O0 -triple r600-- -emit-llvm -o - | FileCheck --check-prefixes=CHECK,AMDGCN %s

clang/test/CodeGenOpenCL/builtins-alloca.cl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
// RUN: -emit-llvm -o - | FileCheck --check-prefixes=OPENCL12 %s
44
// RUN: %clang_cc1 %s -O0 -triple amdgcn-amd-amdhsa -cl-std=CL2.0 \
55
// RUN: -emit-llvm -o - | FileCheck --check-prefixes=OPENCL20 %s
6-
// RUN: %clang_cc1 %s -O0 -triple amdgcn-amd-amdhsa -cl-std=CL3.0 \
6+
// RUN: %clang_cc1 %s -O0 -triple amdgcn-amd-mesa3d -target-cpu gfx600 -cl-std=CL3.0 \
77
// RUN: -emit-llvm -o - | FileCheck --check-prefixes=OPENCL30 %s
8-
// RUN: %clang_cc1 %s -O0 -triple amdgcn-amd-amdhsa -cl-std=CL3.0 -cl-ext=+__opencl_c_generic_address_space \
8+
// RUN: %clang_cc1 %s -O0 -triple amdgcn-amd-amdhsa -cl-std=CL3.0 \
99
// RUN: -emit-llvm -o - | FileCheck --check-prefixes=OPENCL30GAS %s
1010

1111
// OPENCL-LABEL: define dso_local void @test1_builtin_alloca(

clang/test/Misc/amdgcn.languageOptsOpenCL.cl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
// RUN: %clang_cc1 -x cl -cl-std=CL3.0 %s -verify -triple amdgcn-unknown-unknown -Wpedantic-core-features -DTEST_CORE_FEATURES
1212
// RUN: %clang_cc1 -x cl -cl-std=CL3.0 %s -verify -triple amdgcn-unknown-unknown -target-cpu gfx700 -Wpedantic-core-features -DTEST_CORE_FEATURES -DFLAT_SUPPORT
1313

14+
// Test none target with amdhsa triple, which implies >= gfx700
15+
// RUN: %clang_cc1 -x cl -cl-std=CL3.0 %s -verify -triple amdgcn-unknown-amdhsa -Wpedantic-core-features -DTEST_CORE_FEATURES -DFLAT_SUPPORT
16+
1417
// Extensions in all versions
1518
#ifndef cl_clang_storage_class_specifiers
1619
#error "Missing cl_clang_storage_class_specifiers define"

0 commit comments

Comments
 (0)