Skip to content

Commit 60ceda3

Browse files
[NFC][AMDGPU] Move address space enum to LLVM directory
Types of AMDGPU address space were defined in Clang-specific class. In consequence this enum cannot be reused by other frontends like Flang. If we move address space enum to LLVM directory, then we can reuse it in other frontends like Flang.
1 parent 5ba5211 commit 60ceda3

File tree

4 files changed

+56
-60
lines changed

4 files changed

+56
-60
lines changed

clang/lib/Basic/Targets/AMDGPU.cpp

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -37,50 +37,50 @@ static const char *const DataLayoutStringAMDGCN =
3737
"-ni:7:8";
3838

3939
const LangASMap AMDGPUTargetInfo::AMDGPUDefIsGenMap = {
40-
Generic, // Default
41-
Global, // opencl_global
42-
Local, // opencl_local
43-
Constant, // opencl_constant
44-
Private, // opencl_private
45-
Generic, // opencl_generic
46-
Global, // opencl_global_device
47-
Global, // opencl_global_host
48-
Global, // cuda_device
49-
Constant, // cuda_constant
50-
Local, // cuda_shared
51-
Global, // sycl_global
52-
Global, // sycl_global_device
53-
Global, // sycl_global_host
54-
Local, // sycl_local
55-
Private, // sycl_private
56-
Generic, // ptr32_sptr
57-
Generic, // ptr32_uptr
58-
Generic, // ptr64
59-
Generic, // hlsl_groupshared
40+
llvm::AMDGPU::Generic, // Default
41+
llvm::AMDGPU::Global, // opencl_global
42+
llvm::AMDGPU::Local, // opencl_local
43+
llvm::AMDGPU::Constant, // opencl_constant
44+
llvm::AMDGPU::Private, // opencl_private
45+
llvm::AMDGPU::Generic, // opencl_generic
46+
llvm::AMDGPU::Global, // opencl_global_device
47+
llvm::AMDGPU::Global, // opencl_global_host
48+
llvm::AMDGPU::Global, // cuda_device
49+
llvm::AMDGPU::Constant, // cuda_constant
50+
llvm::AMDGPU::Local, // cuda_shared
51+
llvm::AMDGPU::Global, // sycl_global
52+
llvm::AMDGPU::Global, // sycl_global_device
53+
llvm::AMDGPU::Global, // sycl_global_host
54+
llvm::AMDGPU::Local, // sycl_local
55+
llvm::AMDGPU::Private, // sycl_private
56+
llvm::AMDGPU::Generic, // ptr32_sptr
57+
llvm::AMDGPU::Generic, // ptr32_uptr
58+
llvm::AMDGPU::Generic, // ptr64
59+
llvm::AMDGPU::Generic, // hlsl_groupshared
6060
};
6161

6262
const LangASMap AMDGPUTargetInfo::AMDGPUDefIsPrivMap = {
63-
Private, // Default
64-
Global, // opencl_global
65-
Local, // opencl_local
66-
Constant, // opencl_constant
67-
Private, // opencl_private
68-
Generic, // opencl_generic
69-
Global, // opencl_global_device
70-
Global, // opencl_global_host
71-
Global, // cuda_device
72-
Constant, // cuda_constant
73-
Local, // cuda_shared
63+
llvm::AMDGPU::Private, // Default
64+
llvm::AMDGPU::Global, // opencl_global
65+
llvm::AMDGPU::Local, // opencl_local
66+
llvm::AMDGPU::Constant, // opencl_constant
67+
llvm::AMDGPU::Private, // opencl_private
68+
llvm::AMDGPU::Generic, // opencl_generic
69+
llvm::AMDGPU::Global, // opencl_global_device
70+
llvm::AMDGPU::Global, // opencl_global_host
71+
llvm::AMDGPU::Global, // cuda_device
72+
llvm::AMDGPU::Constant, // cuda_constant
73+
llvm::AMDGPU::Local, // cuda_shared
7474
// SYCL address space values for this map are dummy
75-
Generic, // sycl_global
76-
Generic, // sycl_global_device
77-
Generic, // sycl_global_host
78-
Generic, // sycl_local
79-
Generic, // sycl_private
80-
Generic, // ptr32_sptr
81-
Generic, // ptr32_uptr
82-
Generic, // ptr64
83-
Generic, // hlsl_groupshared
75+
llvm::AMDGPU::Generic, // sycl_global
76+
llvm::AMDGPU::Generic, // sycl_global_device
77+
llvm::AMDGPU::Generic, // sycl_global_host
78+
llvm::AMDGPU::Generic, // sycl_local
79+
llvm::AMDGPU::Generic, // sycl_private
80+
llvm::AMDGPU::Generic, // ptr32_sptr
81+
llvm::AMDGPU::Generic, // ptr32_uptr
82+
llvm::AMDGPU::Generic, // ptr64
83+
llvm::AMDGPU::Generic, // hlsl_groupshared
8484

8585
};
8686
} // namespace targets

clang/lib/Basic/Targets/AMDGPU.h

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,6 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUTargetInfo final : public TargetInfo {
2929

3030
static const char *const GCCRegNames[];
3131

32-
enum AddrSpace {
33-
Generic = 0,
34-
Global = 1,
35-
Local = 3,
36-
Constant = 4,
37-
Private = 5
38-
};
3932
static const LangASMap AMDGPUDefIsGenMap;
4033
static const LangASMap AMDGPUDefIsPrivMap;
4134

@@ -106,7 +99,7 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUTargetInfo final : public TargetInfo {
10699
return 32;
107100
unsigned TargetAS = getTargetAddressSpace(AS);
108101

109-
if (TargetAS == Private || TargetAS == Local)
102+
if (TargetAS == llvm::AMDGPU::Private || TargetAS == llvm::AMDGPU::Local)
110103
return 32;
111104

112105
return 64;
@@ -376,7 +369,7 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUTargetInfo final : public TargetInfo {
376369
}
377370

378371
std::optional<LangAS> getConstantAddressSpace() const override {
379-
return getLangASFromTargetAS(Constant);
372+
return getLangASFromTargetAS(llvm::AMDGPU::Constant);
380373
}
381374

382375
const llvm::omp::GV &getGridValue() const override {
@@ -392,7 +385,7 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUTargetInfo final : public TargetInfo {
392385

393386
/// \returns Target specific vtbl ptr address space.
394387
unsigned getVtblPtrAddressSpace() const override {
395-
return static_cast<unsigned>(Constant);
388+
return static_cast<unsigned>(llvm::AMDGPU::Constant);
396389
}
397390

398391
/// \returns If a target requires an address within a target specific address
@@ -405,9 +398,9 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUTargetInfo final : public TargetInfo {
405398
getDWARFAddressSpace(unsigned AddressSpace) const override {
406399
const unsigned DWARF_Private = 1;
407400
const unsigned DWARF_Local = 2;
408-
if (AddressSpace == Private) {
401+
if (AddressSpace == llvm::AMDGPU::Private) {
409402
return DWARF_Private;
410-
} else if (AddressSpace == Local) {
403+
} else if (AddressSpace == llvm::AMDGPU::Local) {
411404
return DWARF_Local;
412405
} else {
413406
return std::nullopt;

flang/lib/Frontend/FrontendActions.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -272,12 +272,6 @@ static void addAMDGPUSpecificMLIRItems(mlir::ModuleOp &mlirModule,
272272
const llvm::Triple triple(targetOpts.triple);
273273
const llvm::StringRef codeObjectVersionGlobalOpName = "__oclc_ABI_version";
274274

275-
// TODO: Share address spaces enumeration between Clang and Flang.
276-
// Currently this enumeration is defined in Clang specific class
277-
// defined in file: clang/lib/Basic/Targets/AMDGPU.h .
278-
// and we need to move it to LLVM directory.
279-
const int constantAddressSpace = 4;
280-
281275
if (!triple.isAMDGPU()) {
282276
return;
283277
}
@@ -308,7 +302,7 @@ static void addAMDGPUSpecificMLIRItems(mlir::ModuleOp &mlirModule,
308302
originalGVOp.setValueAttr(
309303
builder.getIntegerAttr(int32Type, oclcABIVERsion));
310304
originalGVOp.setUnnamedAddr(mlir::LLVM::UnnamedAddr::Local);
311-
originalGVOp.setAddrSpace(constantAddressSpace);
305+
originalGVOp.setAddrSpace(llvm::AMDGPU::Constant);
312306
originalGVOp.setVisibility_(mlir::LLVM::Visibility::Hidden);
313307
return;
314308
}
@@ -319,7 +313,7 @@ static void addAMDGPUSpecificMLIRItems(mlir::ModuleOp &mlirModule,
319313
/* Name */ codeObjectVersionGlobalOpName,
320314
/* Value */ builder.getIntegerAttr(int32Type, oclcABIVERsion));
321315
covInfo.setUnnamedAddr(mlir::LLVM::UnnamedAddr::Local);
322-
covInfo.setAddrSpace(constantAddressSpace);
316+
covInfo.setAddrSpace(llvm::AMDGPU::Constant);
323317
covInfo.setVisibility_(mlir::LLVM::Visibility::Hidden);
324318
builder.setInsertionPointToStart(mlirModule.getBody());
325319
builder.insert(covInfo);

llvm/include/llvm/TargetParser/TargetParser.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,15 @@ class Triple;
3131
// back-end to TableGen to create these clean tables.
3232
namespace AMDGPU {
3333

34+
/// Address space values for AMD GPUs
35+
enum AddrSpace {
36+
Generic = 0,
37+
Global = 1,
38+
Local = 3,
39+
Constant = 4,
40+
Private = 5
41+
};
42+
3443
/// GPU kinds supported by the AMDGPU target.
3544
enum GPUKind : uint32_t {
3645
// Not specified processor.

0 commit comments

Comments
 (0)