Skip to content

Commit 09b7fcf

Browse files
uniform address spaces
1 parent 7be8ec1 commit 09b7fcf

File tree

6 files changed

+134
-122
lines changed

6 files changed

+134
-122
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-
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
40+
llvm::AMDGPUAS::FLAT_ADDRESS, // Default
41+
llvm::AMDGPUAS::GLOBAL_ADDRESS, // opencl_global
42+
llvm::AMDGPUAS::LOCAL_ADDRESS, // opencl_local
43+
llvm::AMDGPUAS::CONSTANT_ADDRESS, // opencl_constant
44+
llvm::AMDGPUAS::PRIVATE_ADDRESS, // opencl_private
45+
llvm::AMDGPUAS::FLAT_ADDRESS, // opencl_generic
46+
llvm::AMDGPUAS::GLOBAL_ADDRESS, // opencl_global_device
47+
llvm::AMDGPUAS::GLOBAL_ADDRESS, // opencl_global_host
48+
llvm::AMDGPUAS::GLOBAL_ADDRESS, // cuda_device
49+
llvm::AMDGPUAS::CONSTANT_ADDRESS, // cuda_constant
50+
llvm::AMDGPUAS::LOCAL_ADDRESS, // cuda_shared
51+
llvm::AMDGPUAS::GLOBAL_ADDRESS, // sycl_global
52+
llvm::AMDGPUAS::GLOBAL_ADDRESS, // sycl_global_device
53+
llvm::AMDGPUAS::GLOBAL_ADDRESS, // sycl_global_host
54+
llvm::AMDGPUAS::LOCAL_ADDRESS, // sycl_local
55+
llvm::AMDGPUAS::PRIVATE_ADDRESS, // sycl_private
56+
llvm::AMDGPUAS::FLAT_ADDRESS, // ptr32_sptr
57+
llvm::AMDGPUAS::FLAT_ADDRESS, // ptr32_uptr
58+
llvm::AMDGPUAS::FLAT_ADDRESS, // ptr64
59+
llvm::AMDGPUAS::FLAT_ADDRESS, // hlsl_groupshared
6060
};
6161

6262
const LangASMap AMDGPUTargetInfo::AMDGPUDefIsPrivMap = {
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
63+
llvm::AMDGPUAS::PRIVATE_ADDRESS, // Default
64+
llvm::AMDGPUAS::GLOBAL_ADDRESS, // opencl_global
65+
llvm::AMDGPUAS::LOCAL_ADDRESS, // opencl_local
66+
llvm::AMDGPUAS::CONSTANT_ADDRESS, // opencl_constant
67+
llvm::AMDGPUAS::PRIVATE_ADDRESS, // opencl_private
68+
llvm::AMDGPUAS::FLAT_ADDRESS, // opencl_generic
69+
llvm::AMDGPUAS::GLOBAL_ADDRESS, // opencl_global_device
70+
llvm::AMDGPUAS::GLOBAL_ADDRESS, // opencl_global_host
71+
llvm::AMDGPUAS::GLOBAL_ADDRESS, // cuda_device
72+
llvm::AMDGPUAS::CONSTANT_ADDRESS, // cuda_constant
73+
llvm::AMDGPUAS::LOCAL_ADDRESS, // cuda_shared
7474
// SYCL address space values for this map are dummy
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
75+
llvm::AMDGPUAS::FLAT_ADDRESS, // sycl_global
76+
llvm::AMDGPUAS::FLAT_ADDRESS, // sycl_global_device
77+
llvm::AMDGPUAS::FLAT_ADDRESS, // sycl_global_host
78+
llvm::AMDGPUAS::FLAT_ADDRESS, // sycl_local
79+
llvm::AMDGPUAS::FLAT_ADDRESS, // sycl_private
80+
llvm::AMDGPUAS::FLAT_ADDRESS, // ptr32_sptr
81+
llvm::AMDGPUAS::FLAT_ADDRESS, // ptr32_uptr
82+
llvm::AMDGPUAS::FLAT_ADDRESS, // ptr64
83+
llvm::AMDGPUAS::FLAT_ADDRESS, // hlsl_groupshared
8484

8585
};
8686
} // namespace targets

clang/lib/Basic/Targets/AMDGPU.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "clang/Basic/TargetInfo.h"
1818
#include "clang/Basic/TargetOptions.h"
1919
#include "llvm/ADT/StringSet.h"
20+
#include "llvm/Support/AMDGPUAddrSpace.h"
2021
#include "llvm/Support/Compiler.h"
2122
#include "llvm/TargetParser/TargetParser.h"
2223
#include "llvm/TargetParser/Triple.h"
@@ -99,7 +100,8 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUTargetInfo final : public TargetInfo {
99100
return 32;
100101
unsigned TargetAS = getTargetAddressSpace(AS);
101102

102-
if (TargetAS == llvm::AMDGPU::Private || TargetAS == llvm::AMDGPU::Local)
103+
if (TargetAS == llvm::AMDGPUAS::PRIVATE_ADDRESS ||
104+
TargetAS == llvm::AMDGPUAS::LOCAL_ADDRESS)
103105
return 32;
104106

105107
return 64;
@@ -369,7 +371,7 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUTargetInfo final : public TargetInfo {
369371
}
370372

371373
std::optional<LangAS> getConstantAddressSpace() const override {
372-
return getLangASFromTargetAS(llvm::AMDGPU::Constant);
374+
return getLangASFromTargetAS(llvm::AMDGPUAS::CONSTANT_ADDRESS);
373375
}
374376

375377
const llvm::omp::GV &getGridValue() const override {
@@ -385,7 +387,7 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUTargetInfo final : public TargetInfo {
385387

386388
/// \returns Target specific vtbl ptr address space.
387389
unsigned getVtblPtrAddressSpace() const override {
388-
return static_cast<unsigned>(llvm::AMDGPU::Constant);
390+
return static_cast<unsigned>(llvm::AMDGPUAS::CONSTANT_ADDRESS);
389391
}
390392

391393
/// \returns If a target requires an address within a target specific address
@@ -398,9 +400,9 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUTargetInfo final : public TargetInfo {
398400
getDWARFAddressSpace(unsigned AddressSpace) const override {
399401
const unsigned DWARF_Private = 1;
400402
const unsigned DWARF_Local = 2;
401-
if (AddressSpace == llvm::AMDGPU::Private) {
403+
if (AddressSpace == llvm::AMDGPUAS::PRIVATE_ADDRESS) {
402404
return DWARF_Private;
403-
} else if (AddressSpace == llvm::AMDGPU::Local) {
405+
} else if (AddressSpace == llvm::AMDGPUAS::LOCAL_ADDRESS) {
404406
return DWARF_Local;
405407
} else {
406408
return std::nullopt;

flang/lib/Frontend/FrontendActions.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
#include "llvm/Passes/PassBuilder.h"
5959
#include "llvm/Passes/PassPlugin.h"
6060
#include "llvm/Passes/StandardInstrumentations.h"
61+
#include "llvm/Support/AMDGPUAddrSpace.h"
6162
#include "llvm/Support/Error.h"
6263
#include "llvm/Support/ErrorHandling.h"
6364
#include "llvm/Support/FileSystem.h"
@@ -302,7 +303,7 @@ static void addAMDGPUSpecificMLIRItems(mlir::ModuleOp &mlirModule,
302303
originalGVOp.setValueAttr(
303304
builder.getIntegerAttr(int32Type, oclcABIVERsion));
304305
originalGVOp.setUnnamedAddr(mlir::LLVM::UnnamedAddr::Local);
305-
originalGVOp.setAddrSpace(llvm::AMDGPU::Constant);
306+
originalGVOp.setAddrSpace(llvm::AMDGPUAS::CONSTANT_ADDRESS);
306307
originalGVOp.setVisibility_(mlir::LLVM::Visibility::Hidden);
307308
return;
308309
}
@@ -313,7 +314,7 @@ static void addAMDGPUSpecificMLIRItems(mlir::ModuleOp &mlirModule,
313314
/* Name */ codeObjectVersionGlobalOpName,
314315
/* Value */ builder.getIntegerAttr(int32Type, oclcABIVERsion));
315316
covInfo.setUnnamedAddr(mlir::LLVM::UnnamedAddr::Local);
316-
covInfo.setAddrSpace(llvm::AMDGPU::Constant);
317+
covInfo.setAddrSpace(llvm::AMDGPUAS::CONSTANT_ADDRESS);
317318
covInfo.setVisibility_(mlir::LLVM::Visibility::Hidden);
318319
builder.setInsertionPointToStart(mlirModule.getBody());
319320
builder.insert(covInfo);
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
//===---------------- AMDGPUAddrSpace.h -------------------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
//
9+
/// \file
10+
/// AMDGPU address space definition
11+
///
12+
//
13+
//===----------------------------------------------------------------------===//
14+
15+
#ifndef LLVM_SUPPORT_AMDGPUADDRSPACE_H
16+
#define LLVM_SUPPORT_AMDGPUADDRSPACE_H
17+
18+
namespace llvm {
19+
/// OpenCL uses address spaces to differentiate between
20+
/// various memory regions on the hardware. On the CPU
21+
/// all of the address spaces point to the same memory,
22+
/// however on the GPU, each address space points to
23+
/// a separate piece of memory that is unique from other
24+
/// memory locations.
25+
namespace AMDGPUAS {
26+
enum : unsigned {
27+
// The maximum value for flat, generic, local, private, constant and region.
28+
MAX_AMDGPU_ADDRESS = 8,
29+
30+
FLAT_ADDRESS = 0, ///< Address space for flat memory.
31+
GLOBAL_ADDRESS = 1, ///< Address space for global memory (RAT0, VTX0).
32+
REGION_ADDRESS = 2, ///< Address space for region memory. (GDS)
33+
34+
CONSTANT_ADDRESS = 4, ///< Address space for constant memory (VTX2).
35+
LOCAL_ADDRESS = 3, ///< Address space for local memory.
36+
PRIVATE_ADDRESS = 5, ///< Address space for private memory.
37+
38+
CONSTANT_ADDRESS_32BIT = 6, ///< Address space for 32-bit constant memory.
39+
40+
BUFFER_FAT_POINTER = 7, ///< Address space for 160-bit buffer fat pointers.
41+
///< Not used in backend.
42+
43+
BUFFER_RESOURCE = 8, ///< Address space for 128-bit buffer resources.
44+
45+
/// Internal address spaces. Can be freely renumbered.
46+
STREAMOUT_REGISTER = 128, ///< Address space for GS NGG Streamout registers.
47+
/// end Internal address spaces.
48+
49+
/// Address space for direct addressable parameter memory (CONST0).
50+
PARAM_D_ADDRESS = 6,
51+
/// Address space for indirect addressable parameter memory (VTX1).
52+
PARAM_I_ADDRESS = 7,
53+
54+
// Do not re-order the CONSTANT_BUFFER_* enums. Several places depend on
55+
// this order to be able to dynamically index a constant buffer, for
56+
// example:
57+
//
58+
// ConstantBufferAS = CONSTANT_BUFFER_0 + CBIdx
59+
60+
CONSTANT_BUFFER_0 = 8,
61+
CONSTANT_BUFFER_1 = 9,
62+
CONSTANT_BUFFER_2 = 10,
63+
CONSTANT_BUFFER_3 = 11,
64+
CONSTANT_BUFFER_4 = 12,
65+
CONSTANT_BUFFER_5 = 13,
66+
CONSTANT_BUFFER_6 = 14,
67+
CONSTANT_BUFFER_7 = 15,
68+
CONSTANT_BUFFER_8 = 16,
69+
CONSTANT_BUFFER_9 = 17,
70+
CONSTANT_BUFFER_10 = 18,
71+
CONSTANT_BUFFER_11 = 19,
72+
CONSTANT_BUFFER_12 = 20,
73+
CONSTANT_BUFFER_13 = 21,
74+
CONSTANT_BUFFER_14 = 22,
75+
CONSTANT_BUFFER_15 = 23,
76+
77+
// Some places use this if the address space can't be determined.
78+
UNKNOWN_ADDRESS_SPACE = ~0u,
79+
};
80+
} // end namespace AMDGPUAS
81+
} // end namespace llvm
82+
83+
#endif // LLVM_SUPPORT_AMDGPUADDRSPACE_H

llvm/include/llvm/TargetParser/TargetParser.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,6 @@ 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-
4334
/// GPU kinds supported by the AMDGPU target.
4435
enum GPUKind : uint32_t {
4536
// Not specified processor.

llvm/lib/Target/AMDGPU/AMDGPU.h

Lines changed: 1 addition & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#include "llvm/IR/PassManager.h"
1414
#include "llvm/Pass.h"
15+
#include "llvm/Support/AMDGPUAddrSpace.h"
1516
#include "llvm/Support/CodeGen.h"
1617

1718
namespace llvm {
@@ -390,72 +391,6 @@ enum TargetIndex {
390391
TI_SCRATCH_RSRC_DWORD2,
391392
TI_SCRATCH_RSRC_DWORD3
392393
};
393-
}
394-
395-
/// OpenCL uses address spaces to differentiate between
396-
/// various memory regions on the hardware. On the CPU
397-
/// all of the address spaces point to the same memory,
398-
/// however on the GPU, each address space points to
399-
/// a separate piece of memory that is unique from other
400-
/// memory locations.
401-
namespace AMDGPUAS {
402-
enum : unsigned {
403-
// The maximum value for flat, generic, local, private, constant and region.
404-
MAX_AMDGPU_ADDRESS = 8,
405-
406-
FLAT_ADDRESS = 0, ///< Address space for flat memory.
407-
GLOBAL_ADDRESS = 1, ///< Address space for global memory (RAT0, VTX0).
408-
REGION_ADDRESS = 2, ///< Address space for region memory. (GDS)
409-
410-
CONSTANT_ADDRESS = 4, ///< Address space for constant memory (VTX2).
411-
LOCAL_ADDRESS = 3, ///< Address space for local memory.
412-
PRIVATE_ADDRESS = 5, ///< Address space for private memory.
413-
414-
CONSTANT_ADDRESS_32BIT = 6, ///< Address space for 32-bit constant memory.
415-
416-
BUFFER_FAT_POINTER = 7, ///< Address space for 160-bit buffer fat pointers.
417-
///< Not used in backend.
418-
419-
BUFFER_RESOURCE = 8, ///< Address space for 128-bit buffer resources.
420-
421-
/// Internal address spaces. Can be freely renumbered.
422-
STREAMOUT_REGISTER = 128, ///< Address space for GS NGG Streamout registers.
423-
/// end Internal address spaces.
424-
425-
/// Address space for direct addressable parameter memory (CONST0).
426-
PARAM_D_ADDRESS = 6,
427-
/// Address space for indirect addressable parameter memory (VTX1).
428-
PARAM_I_ADDRESS = 7,
429-
430-
// Do not re-order the CONSTANT_BUFFER_* enums. Several places depend on
431-
// this order to be able to dynamically index a constant buffer, for
432-
// example:
433-
//
434-
// ConstantBufferAS = CONSTANT_BUFFER_0 + CBIdx
435-
436-
CONSTANT_BUFFER_0 = 8,
437-
CONSTANT_BUFFER_1 = 9,
438-
CONSTANT_BUFFER_2 = 10,
439-
CONSTANT_BUFFER_3 = 11,
440-
CONSTANT_BUFFER_4 = 12,
441-
CONSTANT_BUFFER_5 = 13,
442-
CONSTANT_BUFFER_6 = 14,
443-
CONSTANT_BUFFER_7 = 15,
444-
CONSTANT_BUFFER_8 = 16,
445-
CONSTANT_BUFFER_9 = 17,
446-
CONSTANT_BUFFER_10 = 18,
447-
CONSTANT_BUFFER_11 = 19,
448-
CONSTANT_BUFFER_12 = 20,
449-
CONSTANT_BUFFER_13 = 21,
450-
CONSTANT_BUFFER_14 = 22,
451-
CONSTANT_BUFFER_15 = 23,
452-
453-
// Some places use this if the address space can't be determined.
454-
UNKNOWN_ADDRESS_SPACE = ~0u,
455-
};
456-
}
457-
458-
namespace AMDGPU {
459394

460395
// FIXME: Missing constant_32bit
461396
inline bool isFlatGlobalAddrSpace(unsigned AS) {

0 commit comments

Comments
 (0)