[llvm] [flang] [clang] [NFC][AMDGPU] Move address space enum to LLVM directory (PR #73944)

Dominik Adamski via cfe-commits cfe-commits at lists.llvm.org
Fri Dec 8 02:40:11 PST 2023


https://github.com/DominikAdamski updated https://github.com/llvm/llvm-project/pull/73944

>From 60ceda3d1025891f5037f020a2efe35108f62ca3 Mon Sep 17 00:00:00 2001
From: Dominik Adamski <dominik.adamski at amd.com>
Date: Thu, 30 Nov 2023 08:06:12 -0600
Subject: [PATCH 1/4] [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.
---
 clang/lib/Basic/Targets/AMDGPU.cpp            | 80 +++++++++----------
 clang/lib/Basic/Targets/AMDGPU.h              | 17 ++--
 flang/lib/Frontend/FrontendActions.cpp        | 10 +--
 llvm/include/llvm/TargetParser/TargetParser.h |  9 +++
 4 files changed, 56 insertions(+), 60 deletions(-)

diff --git a/clang/lib/Basic/Targets/AMDGPU.cpp b/clang/lib/Basic/Targets/AMDGPU.cpp
index 409ae32ab4242..3fe9f9fa9c42d 100644
--- a/clang/lib/Basic/Targets/AMDGPU.cpp
+++ b/clang/lib/Basic/Targets/AMDGPU.cpp
@@ -37,50 +37,50 @@ static const char *const DataLayoutStringAMDGCN =
     "-ni:7:8";
 
 const LangASMap AMDGPUTargetInfo::AMDGPUDefIsGenMap = {
-    Generic,  // Default
-    Global,   // opencl_global
-    Local,    // opencl_local
-    Constant, // opencl_constant
-    Private,  // opencl_private
-    Generic,  // opencl_generic
-    Global,   // opencl_global_device
-    Global,   // opencl_global_host
-    Global,   // cuda_device
-    Constant, // cuda_constant
-    Local,    // cuda_shared
-    Global,   // sycl_global
-    Global,   // sycl_global_device
-    Global,   // sycl_global_host
-    Local,    // sycl_local
-    Private,  // sycl_private
-    Generic,  // ptr32_sptr
-    Generic,  // ptr32_uptr
-    Generic,  // ptr64
-    Generic,  // hlsl_groupshared
+    llvm::AMDGPU::Generic,  // Default
+    llvm::AMDGPU::Global,   // opencl_global
+    llvm::AMDGPU::Local,    // opencl_local
+    llvm::AMDGPU::Constant, // opencl_constant
+    llvm::AMDGPU::Private,  // opencl_private
+    llvm::AMDGPU::Generic,  // opencl_generic
+    llvm::AMDGPU::Global,   // opencl_global_device
+    llvm::AMDGPU::Global,   // opencl_global_host
+    llvm::AMDGPU::Global,   // cuda_device
+    llvm::AMDGPU::Constant, // cuda_constant
+    llvm::AMDGPU::Local,    // cuda_shared
+    llvm::AMDGPU::Global,   // sycl_global
+    llvm::AMDGPU::Global,   // sycl_global_device
+    llvm::AMDGPU::Global,   // sycl_global_host
+    llvm::AMDGPU::Local,    // sycl_local
+    llvm::AMDGPU::Private,  // sycl_private
+    llvm::AMDGPU::Generic,  // ptr32_sptr
+    llvm::AMDGPU::Generic,  // ptr32_uptr
+    llvm::AMDGPU::Generic,  // ptr64
+    llvm::AMDGPU::Generic,  // hlsl_groupshared
 };
 
 const LangASMap AMDGPUTargetInfo::AMDGPUDefIsPrivMap = {
-    Private,  // Default
-    Global,   // opencl_global
-    Local,    // opencl_local
-    Constant, // opencl_constant
-    Private,  // opencl_private
-    Generic,  // opencl_generic
-    Global,   // opencl_global_device
-    Global,   // opencl_global_host
-    Global,   // cuda_device
-    Constant, // cuda_constant
-    Local,    // cuda_shared
+    llvm::AMDGPU::Private,  // Default
+    llvm::AMDGPU::Global,   // opencl_global
+    llvm::AMDGPU::Local,    // opencl_local
+    llvm::AMDGPU::Constant, // opencl_constant
+    llvm::AMDGPU::Private,  // opencl_private
+    llvm::AMDGPU::Generic,  // opencl_generic
+    llvm::AMDGPU::Global,   // opencl_global_device
+    llvm::AMDGPU::Global,   // opencl_global_host
+    llvm::AMDGPU::Global,   // cuda_device
+    llvm::AMDGPU::Constant, // cuda_constant
+    llvm::AMDGPU::Local,    // cuda_shared
     // SYCL address space values for this map are dummy
-    Generic, // sycl_global
-    Generic, // sycl_global_device
-    Generic, // sycl_global_host
-    Generic, // sycl_local
-    Generic, // sycl_private
-    Generic, // ptr32_sptr
-    Generic, // ptr32_uptr
-    Generic, // ptr64
-    Generic, // hlsl_groupshared
+    llvm::AMDGPU::Generic, // sycl_global
+    llvm::AMDGPU::Generic, // sycl_global_device
+    llvm::AMDGPU::Generic, // sycl_global_host
+    llvm::AMDGPU::Generic, // sycl_local
+    llvm::AMDGPU::Generic, // sycl_private
+    llvm::AMDGPU::Generic, // ptr32_sptr
+    llvm::AMDGPU::Generic, // ptr32_uptr
+    llvm::AMDGPU::Generic, // ptr64
+    llvm::AMDGPU::Generic, // hlsl_groupshared
 
 };
 } // namespace targets
diff --git a/clang/lib/Basic/Targets/AMDGPU.h b/clang/lib/Basic/Targets/AMDGPU.h
index 300d9691d8a0f..1e12f9e12af59 100644
--- a/clang/lib/Basic/Targets/AMDGPU.h
+++ b/clang/lib/Basic/Targets/AMDGPU.h
@@ -29,13 +29,6 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUTargetInfo final : public TargetInfo {
 
   static const char *const GCCRegNames[];
 
-  enum AddrSpace {
-    Generic = 0,
-    Global = 1,
-    Local = 3,
-    Constant = 4,
-    Private = 5
-  };
   static const LangASMap AMDGPUDefIsGenMap;
   static const LangASMap AMDGPUDefIsPrivMap;
 
@@ -106,7 +99,7 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUTargetInfo final : public TargetInfo {
       return 32;
     unsigned TargetAS = getTargetAddressSpace(AS);
 
-    if (TargetAS == Private || TargetAS == Local)
+    if (TargetAS == llvm::AMDGPU::Private || TargetAS == llvm::AMDGPU::Local)
       return 32;
 
     return 64;
@@ -376,7 +369,7 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUTargetInfo final : public TargetInfo {
   }
 
   std::optional<LangAS> getConstantAddressSpace() const override {
-    return getLangASFromTargetAS(Constant);
+    return getLangASFromTargetAS(llvm::AMDGPU::Constant);
   }
 
   const llvm::omp::GV &getGridValue() const override {
@@ -392,7 +385,7 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUTargetInfo final : public TargetInfo {
 
   /// \returns Target specific vtbl ptr address space.
   unsigned getVtblPtrAddressSpace() const override {
-    return static_cast<unsigned>(Constant);
+    return static_cast<unsigned>(llvm::AMDGPU::Constant);
   }
 
   /// \returns If a target requires an address within a target specific address
@@ -405,9 +398,9 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUTargetInfo final : public TargetInfo {
   getDWARFAddressSpace(unsigned AddressSpace) const override {
     const unsigned DWARF_Private = 1;
     const unsigned DWARF_Local = 2;
-    if (AddressSpace == Private) {
+    if (AddressSpace == llvm::AMDGPU::Private) {
       return DWARF_Private;
-    } else if (AddressSpace == Local) {
+    } else if (AddressSpace == llvm::AMDGPU::Local) {
       return DWARF_Local;
     } else {
       return std::nullopt;
diff --git a/flang/lib/Frontend/FrontendActions.cpp b/flang/lib/Frontend/FrontendActions.cpp
index 1be95cc27f42c..3741668eea67d 100644
--- a/flang/lib/Frontend/FrontendActions.cpp
+++ b/flang/lib/Frontend/FrontendActions.cpp
@@ -272,12 +272,6 @@ static void addAMDGPUSpecificMLIRItems(mlir::ModuleOp &mlirModule,
   const llvm::Triple triple(targetOpts.triple);
   const llvm::StringRef codeObjectVersionGlobalOpName = "__oclc_ABI_version";
 
-  // TODO: Share address spaces enumeration between Clang and Flang.
-  // Currently this enumeration is defined in Clang specific class
-  // defined in file: clang/lib/Basic/Targets/AMDGPU.h .
-  // and we need to move it to LLVM directory.
-  const int constantAddressSpace = 4;
-
   if (!triple.isAMDGPU()) {
     return;
   }
@@ -308,7 +302,7 @@ static void addAMDGPUSpecificMLIRItems(mlir::ModuleOp &mlirModule,
     originalGVOp.setValueAttr(
         builder.getIntegerAttr(int32Type, oclcABIVERsion));
     originalGVOp.setUnnamedAddr(mlir::LLVM::UnnamedAddr::Local);
-    originalGVOp.setAddrSpace(constantAddressSpace);
+    originalGVOp.setAddrSpace(llvm::AMDGPU::Constant);
     originalGVOp.setVisibility_(mlir::LLVM::Visibility::Hidden);
     return;
   }
@@ -319,7 +313,7 @@ static void addAMDGPUSpecificMLIRItems(mlir::ModuleOp &mlirModule,
       /* Name */ codeObjectVersionGlobalOpName,
       /* Value */ builder.getIntegerAttr(int32Type, oclcABIVERsion));
   covInfo.setUnnamedAddr(mlir::LLVM::UnnamedAddr::Local);
-  covInfo.setAddrSpace(constantAddressSpace);
+  covInfo.setAddrSpace(llvm::AMDGPU::Constant);
   covInfo.setVisibility_(mlir::LLVM::Visibility::Hidden);
   builder.setInsertionPointToStart(mlirModule.getBody());
   builder.insert(covInfo);
diff --git a/llvm/include/llvm/TargetParser/TargetParser.h b/llvm/include/llvm/TargetParser/TargetParser.h
index 6464285980f00..b0df831c47567 100644
--- a/llvm/include/llvm/TargetParser/TargetParser.h
+++ b/llvm/include/llvm/TargetParser/TargetParser.h
@@ -31,6 +31,15 @@ class Triple;
 // back-end to TableGen to create these clean tables.
 namespace AMDGPU {
 
+/// Address space values for AMD GPUs
+enum AddrSpace {
+  Generic = 0,
+  Global = 1,
+  Local = 3,
+  Constant = 4,
+  Private = 5
+};
+
 /// GPU kinds supported by the AMDGPU target.
 enum GPUKind : uint32_t {
   // Not specified processor.

>From 0d2ea7f38ed247b6f900ed85833fbe40b7a04a12 Mon Sep 17 00:00:00 2001
From: Dominik Adamski <dominik.adamski at amd.com>
Date: Tue, 5 Dec 2023 06:51:18 -0600
Subject: [PATCH 2/4] Applied review remarks

---
 clang/lib/Basic/Targets/AMDGPU.cpp            | 86 ++++++++++---------
 clang/lib/Basic/Targets/AMDGPU.h              | 15 ++--
 flang/lib/Frontend/FrontendActions.cpp        |  7 +-
 llvm/include/llvm/Support/AMDGPUAddrSpace.h   | 31 +++++++
 llvm/include/llvm/TargetParser/TargetParser.h |  9 --
 5 files changed, 92 insertions(+), 56 deletions(-)
 create mode 100644 llvm/include/llvm/Support/AMDGPUAddrSpace.h

diff --git a/clang/lib/Basic/Targets/AMDGPU.cpp b/clang/lib/Basic/Targets/AMDGPU.cpp
index 3fe9f9fa9c42d..082029f93f2f2 100644
--- a/clang/lib/Basic/Targets/AMDGPU.cpp
+++ b/clang/lib/Basic/Targets/AMDGPU.cpp
@@ -37,50 +37,56 @@ static const char *const DataLayoutStringAMDGCN =
     "-ni:7:8";
 
 const LangASMap AMDGPUTargetInfo::AMDGPUDefIsGenMap = {
-    llvm::AMDGPU::Generic,  // Default
-    llvm::AMDGPU::Global,   // opencl_global
-    llvm::AMDGPU::Local,    // opencl_local
-    llvm::AMDGPU::Constant, // opencl_constant
-    llvm::AMDGPU::Private,  // opencl_private
-    llvm::AMDGPU::Generic,  // opencl_generic
-    llvm::AMDGPU::Global,   // opencl_global_device
-    llvm::AMDGPU::Global,   // opencl_global_host
-    llvm::AMDGPU::Global,   // cuda_device
-    llvm::AMDGPU::Constant, // cuda_constant
-    llvm::AMDGPU::Local,    // cuda_shared
-    llvm::AMDGPU::Global,   // sycl_global
-    llvm::AMDGPU::Global,   // sycl_global_device
-    llvm::AMDGPU::Global,   // sycl_global_host
-    llvm::AMDGPU::Local,    // sycl_local
-    llvm::AMDGPU::Private,  // sycl_private
-    llvm::AMDGPU::Generic,  // ptr32_sptr
-    llvm::AMDGPU::Generic,  // ptr32_uptr
-    llvm::AMDGPU::Generic,  // ptr64
-    llvm::AMDGPU::Generic,  // hlsl_groupshared
+    static_cast<unsigned>(llvm::AMDGPU::AddrSpace::Generic),  // Default
+    static_cast<unsigned>(llvm::AMDGPU::AddrSpace::Global),   // opencl_global
+    static_cast<unsigned>(llvm::AMDGPU::AddrSpace::Local),    // opencl_local
+    static_cast<unsigned>(llvm::AMDGPU::AddrSpace::Constant), // opencl_constant
+    static_cast<unsigned>(llvm::AMDGPU::AddrSpace::Private),  // opencl_private
+    static_cast<unsigned>(llvm::AMDGPU::AddrSpace::Generic),  // opencl_generic
+    static_cast<unsigned>(
+        llvm::AMDGPU::AddrSpace::Global), // opencl_global_device
+    static_cast<unsigned>(
+        llvm::AMDGPU::AddrSpace::Global), // opencl_global_host
+    static_cast<unsigned>(llvm::AMDGPU::AddrSpace::Global),   // cuda_device
+    static_cast<unsigned>(llvm::AMDGPU::AddrSpace::Constant), // cuda_constant
+    static_cast<unsigned>(llvm::AMDGPU::AddrSpace::Local),    // cuda_shared
+    static_cast<unsigned>(llvm::AMDGPU::AddrSpace::Global),   // sycl_global
+    static_cast<unsigned>(
+        llvm::AMDGPU::AddrSpace::Global), // sycl_global_device
+    static_cast<unsigned>(llvm::AMDGPU::AddrSpace::Global),  // sycl_global_host
+    static_cast<unsigned>(llvm::AMDGPU::AddrSpace::Local),   // sycl_local
+    static_cast<unsigned>(llvm::AMDGPU::AddrSpace::Private), // sycl_private
+    static_cast<unsigned>(llvm::AMDGPU::AddrSpace::Generic), // ptr32_sptr
+    static_cast<unsigned>(llvm::AMDGPU::AddrSpace::Generic), // ptr32_uptr
+    static_cast<unsigned>(llvm::AMDGPU::AddrSpace::Generic), // ptr64
+    static_cast<unsigned>(llvm::AMDGPU::AddrSpace::Generic), // hlsl_groupshared
 };
 
 const LangASMap AMDGPUTargetInfo::AMDGPUDefIsPrivMap = {
-    llvm::AMDGPU::Private,  // Default
-    llvm::AMDGPU::Global,   // opencl_global
-    llvm::AMDGPU::Local,    // opencl_local
-    llvm::AMDGPU::Constant, // opencl_constant
-    llvm::AMDGPU::Private,  // opencl_private
-    llvm::AMDGPU::Generic,  // opencl_generic
-    llvm::AMDGPU::Global,   // opencl_global_device
-    llvm::AMDGPU::Global,   // opencl_global_host
-    llvm::AMDGPU::Global,   // cuda_device
-    llvm::AMDGPU::Constant, // cuda_constant
-    llvm::AMDGPU::Local,    // cuda_shared
+    static_cast<unsigned>(llvm::AMDGPU::AddrSpace::Private),  // Default
+    static_cast<unsigned>(llvm::AMDGPU::AddrSpace::Global),   // opencl_global
+    static_cast<unsigned>(llvm::AMDGPU::AddrSpace::Local),    // opencl_local
+    static_cast<unsigned>(llvm::AMDGPU::AddrSpace::Constant), // opencl_constant
+    static_cast<unsigned>(llvm::AMDGPU::AddrSpace::Private),  // opencl_private
+    static_cast<unsigned>(llvm::AMDGPU::AddrSpace::Generic),  // opencl_generic
+    static_cast<unsigned>(
+        llvm::AMDGPU::AddrSpace::Global), // opencl_global_device
+    static_cast<unsigned>(
+        llvm::AMDGPU::AddrSpace::Global), // opencl_global_host
+    static_cast<unsigned>(llvm::AMDGPU::AddrSpace::Global),   // cuda_device
+    static_cast<unsigned>(llvm::AMDGPU::AddrSpace::Constant), // cuda_constant
+    static_cast<unsigned>(llvm::AMDGPU::AddrSpace::Local),    // cuda_shared
     // SYCL address space values for this map are dummy
-    llvm::AMDGPU::Generic, // sycl_global
-    llvm::AMDGPU::Generic, // sycl_global_device
-    llvm::AMDGPU::Generic, // sycl_global_host
-    llvm::AMDGPU::Generic, // sycl_local
-    llvm::AMDGPU::Generic, // sycl_private
-    llvm::AMDGPU::Generic, // ptr32_sptr
-    llvm::AMDGPU::Generic, // ptr32_uptr
-    llvm::AMDGPU::Generic, // ptr64
-    llvm::AMDGPU::Generic, // hlsl_groupshared
+    static_cast<unsigned>(llvm::AMDGPU::AddrSpace::Generic), // sycl_global
+    static_cast<unsigned>(
+        llvm::AMDGPU::AddrSpace::Generic), // sycl_global_device
+    static_cast<unsigned>(llvm::AMDGPU::AddrSpace::Generic), // sycl_global_host
+    static_cast<unsigned>(llvm::AMDGPU::AddrSpace::Generic), // sycl_local
+    static_cast<unsigned>(llvm::AMDGPU::AddrSpace::Generic), // sycl_private
+    static_cast<unsigned>(llvm::AMDGPU::AddrSpace::Generic), // ptr32_sptr
+    static_cast<unsigned>(llvm::AMDGPU::AddrSpace::Generic), // ptr32_uptr
+    static_cast<unsigned>(llvm::AMDGPU::AddrSpace::Generic), // ptr64
+    static_cast<unsigned>(llvm::AMDGPU::AddrSpace::Generic), // hlsl_groupshared
 
 };
 } // namespace targets
diff --git a/clang/lib/Basic/Targets/AMDGPU.h b/clang/lib/Basic/Targets/AMDGPU.h
index 1e12f9e12af59..5d909785490a1 100644
--- a/clang/lib/Basic/Targets/AMDGPU.h
+++ b/clang/lib/Basic/Targets/AMDGPU.h
@@ -17,6 +17,7 @@
 #include "clang/Basic/TargetInfo.h"
 #include "clang/Basic/TargetOptions.h"
 #include "llvm/ADT/StringSet.h"
+#include "llvm/Support/AMDGPUAddrSpace.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/TargetParser/TargetParser.h"
 #include "llvm/TargetParser/Triple.h"
@@ -99,7 +100,8 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUTargetInfo final : public TargetInfo {
       return 32;
     unsigned TargetAS = getTargetAddressSpace(AS);
 
-    if (TargetAS == llvm::AMDGPU::Private || TargetAS == llvm::AMDGPU::Local)
+    if (TargetAS == static_cast<unsigned>(llvm::AMDGPU::AddrSpace::Private) ||
+        TargetAS == static_cast<unsigned>(llvm::AMDGPU::AddrSpace::Local))
       return 32;
 
     return 64;
@@ -369,7 +371,8 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUTargetInfo final : public TargetInfo {
   }
 
   std::optional<LangAS> getConstantAddressSpace() const override {
-    return getLangASFromTargetAS(llvm::AMDGPU::Constant);
+    return getLangASFromTargetAS(
+        static_cast<unsigned>(llvm::AMDGPU::AddrSpace::Constant));
   }
 
   const llvm::omp::GV &getGridValue() const override {
@@ -385,7 +388,7 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUTargetInfo final : public TargetInfo {
 
   /// \returns Target specific vtbl ptr address space.
   unsigned getVtblPtrAddressSpace() const override {
-    return static_cast<unsigned>(llvm::AMDGPU::Constant);
+    return static_cast<unsigned>(llvm::AMDGPU::AddrSpace::Constant);
   }
 
   /// \returns If a target requires an address within a target specific address
@@ -398,9 +401,11 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUTargetInfo final : public TargetInfo {
   getDWARFAddressSpace(unsigned AddressSpace) const override {
     const unsigned DWARF_Private = 1;
     const unsigned DWARF_Local = 2;
-    if (AddressSpace == llvm::AMDGPU::Private) {
+    if (AddressSpace ==
+        static_cast<unsigned>(llvm::AMDGPU::AddrSpace::Private)) {
       return DWARF_Private;
-    } else if (AddressSpace == llvm::AMDGPU::Local) {
+    } else if (AddressSpace ==
+               static_cast<unsigned>(llvm::AMDGPU::AddrSpace::Local)) {
       return DWARF_Local;
     } else {
       return std::nullopt;
diff --git a/flang/lib/Frontend/FrontendActions.cpp b/flang/lib/Frontend/FrontendActions.cpp
index 3741668eea67d..a9b695e9c388b 100644
--- a/flang/lib/Frontend/FrontendActions.cpp
+++ b/flang/lib/Frontend/FrontendActions.cpp
@@ -58,6 +58,7 @@
 #include "llvm/Passes/PassBuilder.h"
 #include "llvm/Passes/PassPlugin.h"
 #include "llvm/Passes/StandardInstrumentations.h"
+#include "llvm/Support/AMDGPUAddrSpace.h"
 #include "llvm/Support/Error.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/FileSystem.h"
@@ -302,7 +303,8 @@ static void addAMDGPUSpecificMLIRItems(mlir::ModuleOp &mlirModule,
     originalGVOp.setValueAttr(
         builder.getIntegerAttr(int32Type, oclcABIVERsion));
     originalGVOp.setUnnamedAddr(mlir::LLVM::UnnamedAddr::Local);
-    originalGVOp.setAddrSpace(llvm::AMDGPU::Constant);
+    originalGVOp.setAddrSpace(
+        static_cast<unsigned>(llvm::AMDGPU::AddrSpace::Constant));
     originalGVOp.setVisibility_(mlir::LLVM::Visibility::Hidden);
     return;
   }
@@ -313,7 +315,8 @@ static void addAMDGPUSpecificMLIRItems(mlir::ModuleOp &mlirModule,
       /* Name */ codeObjectVersionGlobalOpName,
       /* Value */ builder.getIntegerAttr(int32Type, oclcABIVERsion));
   covInfo.setUnnamedAddr(mlir::LLVM::UnnamedAddr::Local);
-  covInfo.setAddrSpace(llvm::AMDGPU::Constant);
+  covInfo.setAddrSpace(
+      static_cast<unsigned>(llvm::AMDGPU::AddrSpace::Constant));
   covInfo.setVisibility_(mlir::LLVM::Visibility::Hidden);
   builder.setInsertionPointToStart(mlirModule.getBody());
   builder.insert(covInfo);
diff --git a/llvm/include/llvm/Support/AMDGPUAddrSpace.h b/llvm/include/llvm/Support/AMDGPUAddrSpace.h
new file mode 100644
index 0000000000000..7923524ea5568
--- /dev/null
+++ b/llvm/include/llvm/Support/AMDGPUAddrSpace.h
@@ -0,0 +1,31 @@
+//===---------------- AMDGPUAddrSpace.h -------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+/// \file
+/// AMDGPU address space definition
+///
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_SUPPORT_AMDGPUADDRSPACE_H
+#define LLVM_SUPPORT_AMDGPUADDRSPACE_H
+
+namespace llvm {
+namespace AMDGPU {
+enum class AddrSpace {
+  Generic = 0,
+  Global = 1,
+  Local = 3,
+  Constant = 4,
+  Private = 5
+};
+
+} // end namespace AMDGPU
+} // end namespace llvm
+
+#endif // LLVM_SUPPORT_AMDGPUADDRSPACE_H
diff --git a/llvm/include/llvm/TargetParser/TargetParser.h b/llvm/include/llvm/TargetParser/TargetParser.h
index b0df831c47567..6464285980f00 100644
--- a/llvm/include/llvm/TargetParser/TargetParser.h
+++ b/llvm/include/llvm/TargetParser/TargetParser.h
@@ -31,15 +31,6 @@ class Triple;
 // back-end to TableGen to create these clean tables.
 namespace AMDGPU {
 
-/// Address space values for AMD GPUs
-enum AddrSpace {
-  Generic = 0,
-  Global = 1,
-  Local = 3,
-  Constant = 4,
-  Private = 5
-};
-
 /// GPU kinds supported by the AMDGPU target.
 enum GPUKind : uint32_t {
   // Not specified processor.

>From 7be8ec19c9cf418c9ed5d2e7e13882d9dc0a3ac2 Mon Sep 17 00:00:00 2001
From: Dominik Adamski <dominik.adamski at amd.com>
Date: Thu, 7 Dec 2023 06:36:25 -0600
Subject: [PATCH 3/4] Revert "Applied review remarks"

This reverts commit 0d2ea7f38ed247b6f900ed85833fbe40b7a04a12.
---
 clang/lib/Basic/Targets/AMDGPU.cpp            | 86 +++++++++----------
 clang/lib/Basic/Targets/AMDGPU.h              | 15 ++--
 flang/lib/Frontend/FrontendActions.cpp        |  7 +-
 llvm/include/llvm/Support/AMDGPUAddrSpace.h   | 31 -------
 llvm/include/llvm/TargetParser/TargetParser.h |  9 ++
 5 files changed, 56 insertions(+), 92 deletions(-)
 delete mode 100644 llvm/include/llvm/Support/AMDGPUAddrSpace.h

diff --git a/clang/lib/Basic/Targets/AMDGPU.cpp b/clang/lib/Basic/Targets/AMDGPU.cpp
index 082029f93f2f2..3fe9f9fa9c42d 100644
--- a/clang/lib/Basic/Targets/AMDGPU.cpp
+++ b/clang/lib/Basic/Targets/AMDGPU.cpp
@@ -37,56 +37,50 @@ static const char *const DataLayoutStringAMDGCN =
     "-ni:7:8";
 
 const LangASMap AMDGPUTargetInfo::AMDGPUDefIsGenMap = {
-    static_cast<unsigned>(llvm::AMDGPU::AddrSpace::Generic),  // Default
-    static_cast<unsigned>(llvm::AMDGPU::AddrSpace::Global),   // opencl_global
-    static_cast<unsigned>(llvm::AMDGPU::AddrSpace::Local),    // opencl_local
-    static_cast<unsigned>(llvm::AMDGPU::AddrSpace::Constant), // opencl_constant
-    static_cast<unsigned>(llvm::AMDGPU::AddrSpace::Private),  // opencl_private
-    static_cast<unsigned>(llvm::AMDGPU::AddrSpace::Generic),  // opencl_generic
-    static_cast<unsigned>(
-        llvm::AMDGPU::AddrSpace::Global), // opencl_global_device
-    static_cast<unsigned>(
-        llvm::AMDGPU::AddrSpace::Global), // opencl_global_host
-    static_cast<unsigned>(llvm::AMDGPU::AddrSpace::Global),   // cuda_device
-    static_cast<unsigned>(llvm::AMDGPU::AddrSpace::Constant), // cuda_constant
-    static_cast<unsigned>(llvm::AMDGPU::AddrSpace::Local),    // cuda_shared
-    static_cast<unsigned>(llvm::AMDGPU::AddrSpace::Global),   // sycl_global
-    static_cast<unsigned>(
-        llvm::AMDGPU::AddrSpace::Global), // sycl_global_device
-    static_cast<unsigned>(llvm::AMDGPU::AddrSpace::Global),  // sycl_global_host
-    static_cast<unsigned>(llvm::AMDGPU::AddrSpace::Local),   // sycl_local
-    static_cast<unsigned>(llvm::AMDGPU::AddrSpace::Private), // sycl_private
-    static_cast<unsigned>(llvm::AMDGPU::AddrSpace::Generic), // ptr32_sptr
-    static_cast<unsigned>(llvm::AMDGPU::AddrSpace::Generic), // ptr32_uptr
-    static_cast<unsigned>(llvm::AMDGPU::AddrSpace::Generic), // ptr64
-    static_cast<unsigned>(llvm::AMDGPU::AddrSpace::Generic), // hlsl_groupshared
+    llvm::AMDGPU::Generic,  // Default
+    llvm::AMDGPU::Global,   // opencl_global
+    llvm::AMDGPU::Local,    // opencl_local
+    llvm::AMDGPU::Constant, // opencl_constant
+    llvm::AMDGPU::Private,  // opencl_private
+    llvm::AMDGPU::Generic,  // opencl_generic
+    llvm::AMDGPU::Global,   // opencl_global_device
+    llvm::AMDGPU::Global,   // opencl_global_host
+    llvm::AMDGPU::Global,   // cuda_device
+    llvm::AMDGPU::Constant, // cuda_constant
+    llvm::AMDGPU::Local,    // cuda_shared
+    llvm::AMDGPU::Global,   // sycl_global
+    llvm::AMDGPU::Global,   // sycl_global_device
+    llvm::AMDGPU::Global,   // sycl_global_host
+    llvm::AMDGPU::Local,    // sycl_local
+    llvm::AMDGPU::Private,  // sycl_private
+    llvm::AMDGPU::Generic,  // ptr32_sptr
+    llvm::AMDGPU::Generic,  // ptr32_uptr
+    llvm::AMDGPU::Generic,  // ptr64
+    llvm::AMDGPU::Generic,  // hlsl_groupshared
 };
 
 const LangASMap AMDGPUTargetInfo::AMDGPUDefIsPrivMap = {
-    static_cast<unsigned>(llvm::AMDGPU::AddrSpace::Private),  // Default
-    static_cast<unsigned>(llvm::AMDGPU::AddrSpace::Global),   // opencl_global
-    static_cast<unsigned>(llvm::AMDGPU::AddrSpace::Local),    // opencl_local
-    static_cast<unsigned>(llvm::AMDGPU::AddrSpace::Constant), // opencl_constant
-    static_cast<unsigned>(llvm::AMDGPU::AddrSpace::Private),  // opencl_private
-    static_cast<unsigned>(llvm::AMDGPU::AddrSpace::Generic),  // opencl_generic
-    static_cast<unsigned>(
-        llvm::AMDGPU::AddrSpace::Global), // opencl_global_device
-    static_cast<unsigned>(
-        llvm::AMDGPU::AddrSpace::Global), // opencl_global_host
-    static_cast<unsigned>(llvm::AMDGPU::AddrSpace::Global),   // cuda_device
-    static_cast<unsigned>(llvm::AMDGPU::AddrSpace::Constant), // cuda_constant
-    static_cast<unsigned>(llvm::AMDGPU::AddrSpace::Local),    // cuda_shared
+    llvm::AMDGPU::Private,  // Default
+    llvm::AMDGPU::Global,   // opencl_global
+    llvm::AMDGPU::Local,    // opencl_local
+    llvm::AMDGPU::Constant, // opencl_constant
+    llvm::AMDGPU::Private,  // opencl_private
+    llvm::AMDGPU::Generic,  // opencl_generic
+    llvm::AMDGPU::Global,   // opencl_global_device
+    llvm::AMDGPU::Global,   // opencl_global_host
+    llvm::AMDGPU::Global,   // cuda_device
+    llvm::AMDGPU::Constant, // cuda_constant
+    llvm::AMDGPU::Local,    // cuda_shared
     // SYCL address space values for this map are dummy
-    static_cast<unsigned>(llvm::AMDGPU::AddrSpace::Generic), // sycl_global
-    static_cast<unsigned>(
-        llvm::AMDGPU::AddrSpace::Generic), // sycl_global_device
-    static_cast<unsigned>(llvm::AMDGPU::AddrSpace::Generic), // sycl_global_host
-    static_cast<unsigned>(llvm::AMDGPU::AddrSpace::Generic), // sycl_local
-    static_cast<unsigned>(llvm::AMDGPU::AddrSpace::Generic), // sycl_private
-    static_cast<unsigned>(llvm::AMDGPU::AddrSpace::Generic), // ptr32_sptr
-    static_cast<unsigned>(llvm::AMDGPU::AddrSpace::Generic), // ptr32_uptr
-    static_cast<unsigned>(llvm::AMDGPU::AddrSpace::Generic), // ptr64
-    static_cast<unsigned>(llvm::AMDGPU::AddrSpace::Generic), // hlsl_groupshared
+    llvm::AMDGPU::Generic, // sycl_global
+    llvm::AMDGPU::Generic, // sycl_global_device
+    llvm::AMDGPU::Generic, // sycl_global_host
+    llvm::AMDGPU::Generic, // sycl_local
+    llvm::AMDGPU::Generic, // sycl_private
+    llvm::AMDGPU::Generic, // ptr32_sptr
+    llvm::AMDGPU::Generic, // ptr32_uptr
+    llvm::AMDGPU::Generic, // ptr64
+    llvm::AMDGPU::Generic, // hlsl_groupshared
 
 };
 } // namespace targets
diff --git a/clang/lib/Basic/Targets/AMDGPU.h b/clang/lib/Basic/Targets/AMDGPU.h
index 5d909785490a1..1e12f9e12af59 100644
--- a/clang/lib/Basic/Targets/AMDGPU.h
+++ b/clang/lib/Basic/Targets/AMDGPU.h
@@ -17,7 +17,6 @@
 #include "clang/Basic/TargetInfo.h"
 #include "clang/Basic/TargetOptions.h"
 #include "llvm/ADT/StringSet.h"
-#include "llvm/Support/AMDGPUAddrSpace.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/TargetParser/TargetParser.h"
 #include "llvm/TargetParser/Triple.h"
@@ -100,8 +99,7 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUTargetInfo final : public TargetInfo {
       return 32;
     unsigned TargetAS = getTargetAddressSpace(AS);
 
-    if (TargetAS == static_cast<unsigned>(llvm::AMDGPU::AddrSpace::Private) ||
-        TargetAS == static_cast<unsigned>(llvm::AMDGPU::AddrSpace::Local))
+    if (TargetAS == llvm::AMDGPU::Private || TargetAS == llvm::AMDGPU::Local)
       return 32;
 
     return 64;
@@ -371,8 +369,7 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUTargetInfo final : public TargetInfo {
   }
 
   std::optional<LangAS> getConstantAddressSpace() const override {
-    return getLangASFromTargetAS(
-        static_cast<unsigned>(llvm::AMDGPU::AddrSpace::Constant));
+    return getLangASFromTargetAS(llvm::AMDGPU::Constant);
   }
 
   const llvm::omp::GV &getGridValue() const override {
@@ -388,7 +385,7 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUTargetInfo final : public TargetInfo {
 
   /// \returns Target specific vtbl ptr address space.
   unsigned getVtblPtrAddressSpace() const override {
-    return static_cast<unsigned>(llvm::AMDGPU::AddrSpace::Constant);
+    return static_cast<unsigned>(llvm::AMDGPU::Constant);
   }
 
   /// \returns If a target requires an address within a target specific address
@@ -401,11 +398,9 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUTargetInfo final : public TargetInfo {
   getDWARFAddressSpace(unsigned AddressSpace) const override {
     const unsigned DWARF_Private = 1;
     const unsigned DWARF_Local = 2;
-    if (AddressSpace ==
-        static_cast<unsigned>(llvm::AMDGPU::AddrSpace::Private)) {
+    if (AddressSpace == llvm::AMDGPU::Private) {
       return DWARF_Private;
-    } else if (AddressSpace ==
-               static_cast<unsigned>(llvm::AMDGPU::AddrSpace::Local)) {
+    } else if (AddressSpace == llvm::AMDGPU::Local) {
       return DWARF_Local;
     } else {
       return std::nullopt;
diff --git a/flang/lib/Frontend/FrontendActions.cpp b/flang/lib/Frontend/FrontendActions.cpp
index a9b695e9c388b..3741668eea67d 100644
--- a/flang/lib/Frontend/FrontendActions.cpp
+++ b/flang/lib/Frontend/FrontendActions.cpp
@@ -58,7 +58,6 @@
 #include "llvm/Passes/PassBuilder.h"
 #include "llvm/Passes/PassPlugin.h"
 #include "llvm/Passes/StandardInstrumentations.h"
-#include "llvm/Support/AMDGPUAddrSpace.h"
 #include "llvm/Support/Error.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/FileSystem.h"
@@ -303,8 +302,7 @@ static void addAMDGPUSpecificMLIRItems(mlir::ModuleOp &mlirModule,
     originalGVOp.setValueAttr(
         builder.getIntegerAttr(int32Type, oclcABIVERsion));
     originalGVOp.setUnnamedAddr(mlir::LLVM::UnnamedAddr::Local);
-    originalGVOp.setAddrSpace(
-        static_cast<unsigned>(llvm::AMDGPU::AddrSpace::Constant));
+    originalGVOp.setAddrSpace(llvm::AMDGPU::Constant);
     originalGVOp.setVisibility_(mlir::LLVM::Visibility::Hidden);
     return;
   }
@@ -315,8 +313,7 @@ static void addAMDGPUSpecificMLIRItems(mlir::ModuleOp &mlirModule,
       /* Name */ codeObjectVersionGlobalOpName,
       /* Value */ builder.getIntegerAttr(int32Type, oclcABIVERsion));
   covInfo.setUnnamedAddr(mlir::LLVM::UnnamedAddr::Local);
-  covInfo.setAddrSpace(
-      static_cast<unsigned>(llvm::AMDGPU::AddrSpace::Constant));
+  covInfo.setAddrSpace(llvm::AMDGPU::Constant);
   covInfo.setVisibility_(mlir::LLVM::Visibility::Hidden);
   builder.setInsertionPointToStart(mlirModule.getBody());
   builder.insert(covInfo);
diff --git a/llvm/include/llvm/Support/AMDGPUAddrSpace.h b/llvm/include/llvm/Support/AMDGPUAddrSpace.h
deleted file mode 100644
index 7923524ea5568..0000000000000
--- a/llvm/include/llvm/Support/AMDGPUAddrSpace.h
+++ /dev/null
@@ -1,31 +0,0 @@
-//===---------------- AMDGPUAddrSpace.h -------------------------*- C++ -*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-//
-/// \file
-/// AMDGPU address space definition
-///
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_SUPPORT_AMDGPUADDRSPACE_H
-#define LLVM_SUPPORT_AMDGPUADDRSPACE_H
-
-namespace llvm {
-namespace AMDGPU {
-enum class AddrSpace {
-  Generic = 0,
-  Global = 1,
-  Local = 3,
-  Constant = 4,
-  Private = 5
-};
-
-} // end namespace AMDGPU
-} // end namespace llvm
-
-#endif // LLVM_SUPPORT_AMDGPUADDRSPACE_H
diff --git a/llvm/include/llvm/TargetParser/TargetParser.h b/llvm/include/llvm/TargetParser/TargetParser.h
index 6464285980f00..b0df831c47567 100644
--- a/llvm/include/llvm/TargetParser/TargetParser.h
+++ b/llvm/include/llvm/TargetParser/TargetParser.h
@@ -31,6 +31,15 @@ class Triple;
 // back-end to TableGen to create these clean tables.
 namespace AMDGPU {
 
+/// Address space values for AMD GPUs
+enum AddrSpace {
+  Generic = 0,
+  Global = 1,
+  Local = 3,
+  Constant = 4,
+  Private = 5
+};
+
 /// GPU kinds supported by the AMDGPU target.
 enum GPUKind : uint32_t {
   // Not specified processor.

>From 09b7fcf2201ba3225784e31f10c68cfb0cbed9d7 Mon Sep 17 00:00:00 2001
From: Dominik Adamski <dominik.adamski at amd.com>
Date: Fri, 8 Dec 2023 03:09:29 -0600
Subject: [PATCH 4/4] uniform address spaces

---
 clang/lib/Basic/Targets/AMDGPU.cpp            | 80 +++++++++---------
 clang/lib/Basic/Targets/AMDGPU.h              | 12 +--
 flang/lib/Frontend/FrontendActions.cpp        |  5 +-
 llvm/include/llvm/Support/AMDGPUAddrSpace.h   | 83 +++++++++++++++++++
 llvm/include/llvm/TargetParser/TargetParser.h |  9 --
 llvm/lib/Target/AMDGPU/AMDGPU.h               | 67 +--------------
 6 files changed, 134 insertions(+), 122 deletions(-)
 create mode 100644 llvm/include/llvm/Support/AMDGPUAddrSpace.h

diff --git a/clang/lib/Basic/Targets/AMDGPU.cpp b/clang/lib/Basic/Targets/AMDGPU.cpp
index 3fe9f9fa9c42d..719fc51bfc286 100644
--- a/clang/lib/Basic/Targets/AMDGPU.cpp
+++ b/clang/lib/Basic/Targets/AMDGPU.cpp
@@ -37,50 +37,50 @@ static const char *const DataLayoutStringAMDGCN =
     "-ni:7:8";
 
 const LangASMap AMDGPUTargetInfo::AMDGPUDefIsGenMap = {
-    llvm::AMDGPU::Generic,  // Default
-    llvm::AMDGPU::Global,   // opencl_global
-    llvm::AMDGPU::Local,    // opencl_local
-    llvm::AMDGPU::Constant, // opencl_constant
-    llvm::AMDGPU::Private,  // opencl_private
-    llvm::AMDGPU::Generic,  // opencl_generic
-    llvm::AMDGPU::Global,   // opencl_global_device
-    llvm::AMDGPU::Global,   // opencl_global_host
-    llvm::AMDGPU::Global,   // cuda_device
-    llvm::AMDGPU::Constant, // cuda_constant
-    llvm::AMDGPU::Local,    // cuda_shared
-    llvm::AMDGPU::Global,   // sycl_global
-    llvm::AMDGPU::Global,   // sycl_global_device
-    llvm::AMDGPU::Global,   // sycl_global_host
-    llvm::AMDGPU::Local,    // sycl_local
-    llvm::AMDGPU::Private,  // sycl_private
-    llvm::AMDGPU::Generic,  // ptr32_sptr
-    llvm::AMDGPU::Generic,  // ptr32_uptr
-    llvm::AMDGPU::Generic,  // ptr64
-    llvm::AMDGPU::Generic,  // hlsl_groupshared
+    llvm::AMDGPUAS::FLAT_ADDRESS,     // Default
+    llvm::AMDGPUAS::GLOBAL_ADDRESS,   // opencl_global
+    llvm::AMDGPUAS::LOCAL_ADDRESS,    // opencl_local
+    llvm::AMDGPUAS::CONSTANT_ADDRESS, // opencl_constant
+    llvm::AMDGPUAS::PRIVATE_ADDRESS,  // opencl_private
+    llvm::AMDGPUAS::FLAT_ADDRESS,     // opencl_generic
+    llvm::AMDGPUAS::GLOBAL_ADDRESS,   // opencl_global_device
+    llvm::AMDGPUAS::GLOBAL_ADDRESS,   // opencl_global_host
+    llvm::AMDGPUAS::GLOBAL_ADDRESS,   // cuda_device
+    llvm::AMDGPUAS::CONSTANT_ADDRESS, // cuda_constant
+    llvm::AMDGPUAS::LOCAL_ADDRESS,    // cuda_shared
+    llvm::AMDGPUAS::GLOBAL_ADDRESS,   // sycl_global
+    llvm::AMDGPUAS::GLOBAL_ADDRESS,   // sycl_global_device
+    llvm::AMDGPUAS::GLOBAL_ADDRESS,   // sycl_global_host
+    llvm::AMDGPUAS::LOCAL_ADDRESS,    // sycl_local
+    llvm::AMDGPUAS::PRIVATE_ADDRESS,  // sycl_private
+    llvm::AMDGPUAS::FLAT_ADDRESS,     // ptr32_sptr
+    llvm::AMDGPUAS::FLAT_ADDRESS,     // ptr32_uptr
+    llvm::AMDGPUAS::FLAT_ADDRESS,     // ptr64
+    llvm::AMDGPUAS::FLAT_ADDRESS,     // hlsl_groupshared
 };
 
 const LangASMap AMDGPUTargetInfo::AMDGPUDefIsPrivMap = {
-    llvm::AMDGPU::Private,  // Default
-    llvm::AMDGPU::Global,   // opencl_global
-    llvm::AMDGPU::Local,    // opencl_local
-    llvm::AMDGPU::Constant, // opencl_constant
-    llvm::AMDGPU::Private,  // opencl_private
-    llvm::AMDGPU::Generic,  // opencl_generic
-    llvm::AMDGPU::Global,   // opencl_global_device
-    llvm::AMDGPU::Global,   // opencl_global_host
-    llvm::AMDGPU::Global,   // cuda_device
-    llvm::AMDGPU::Constant, // cuda_constant
-    llvm::AMDGPU::Local,    // cuda_shared
+    llvm::AMDGPUAS::PRIVATE_ADDRESS,  // Default
+    llvm::AMDGPUAS::GLOBAL_ADDRESS,   // opencl_global
+    llvm::AMDGPUAS::LOCAL_ADDRESS,    // opencl_local
+    llvm::AMDGPUAS::CONSTANT_ADDRESS, // opencl_constant
+    llvm::AMDGPUAS::PRIVATE_ADDRESS,  // opencl_private
+    llvm::AMDGPUAS::FLAT_ADDRESS,     // opencl_generic
+    llvm::AMDGPUAS::GLOBAL_ADDRESS,   // opencl_global_device
+    llvm::AMDGPUAS::GLOBAL_ADDRESS,   // opencl_global_host
+    llvm::AMDGPUAS::GLOBAL_ADDRESS,   // cuda_device
+    llvm::AMDGPUAS::CONSTANT_ADDRESS, // cuda_constant
+    llvm::AMDGPUAS::LOCAL_ADDRESS,    // cuda_shared
     // SYCL address space values for this map are dummy
-    llvm::AMDGPU::Generic, // sycl_global
-    llvm::AMDGPU::Generic, // sycl_global_device
-    llvm::AMDGPU::Generic, // sycl_global_host
-    llvm::AMDGPU::Generic, // sycl_local
-    llvm::AMDGPU::Generic, // sycl_private
-    llvm::AMDGPU::Generic, // ptr32_sptr
-    llvm::AMDGPU::Generic, // ptr32_uptr
-    llvm::AMDGPU::Generic, // ptr64
-    llvm::AMDGPU::Generic, // hlsl_groupshared
+    llvm::AMDGPUAS::FLAT_ADDRESS, // sycl_global
+    llvm::AMDGPUAS::FLAT_ADDRESS, // sycl_global_device
+    llvm::AMDGPUAS::FLAT_ADDRESS, // sycl_global_host
+    llvm::AMDGPUAS::FLAT_ADDRESS, // sycl_local
+    llvm::AMDGPUAS::FLAT_ADDRESS, // sycl_private
+    llvm::AMDGPUAS::FLAT_ADDRESS, // ptr32_sptr
+    llvm::AMDGPUAS::FLAT_ADDRESS, // ptr32_uptr
+    llvm::AMDGPUAS::FLAT_ADDRESS, // ptr64
+    llvm::AMDGPUAS::FLAT_ADDRESS, // hlsl_groupshared
 
 };
 } // namespace targets
diff --git a/clang/lib/Basic/Targets/AMDGPU.h b/clang/lib/Basic/Targets/AMDGPU.h
index 1e12f9e12af59..1819ba544ccf8 100644
--- a/clang/lib/Basic/Targets/AMDGPU.h
+++ b/clang/lib/Basic/Targets/AMDGPU.h
@@ -17,6 +17,7 @@
 #include "clang/Basic/TargetInfo.h"
 #include "clang/Basic/TargetOptions.h"
 #include "llvm/ADT/StringSet.h"
+#include "llvm/Support/AMDGPUAddrSpace.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/TargetParser/TargetParser.h"
 #include "llvm/TargetParser/Triple.h"
@@ -99,7 +100,8 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUTargetInfo final : public TargetInfo {
       return 32;
     unsigned TargetAS = getTargetAddressSpace(AS);
 
-    if (TargetAS == llvm::AMDGPU::Private || TargetAS == llvm::AMDGPU::Local)
+    if (TargetAS == llvm::AMDGPUAS::PRIVATE_ADDRESS ||
+        TargetAS == llvm::AMDGPUAS::LOCAL_ADDRESS)
       return 32;
 
     return 64;
@@ -369,7 +371,7 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUTargetInfo final : public TargetInfo {
   }
 
   std::optional<LangAS> getConstantAddressSpace() const override {
-    return getLangASFromTargetAS(llvm::AMDGPU::Constant);
+    return getLangASFromTargetAS(llvm::AMDGPUAS::CONSTANT_ADDRESS);
   }
 
   const llvm::omp::GV &getGridValue() const override {
@@ -385,7 +387,7 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUTargetInfo final : public TargetInfo {
 
   /// \returns Target specific vtbl ptr address space.
   unsigned getVtblPtrAddressSpace() const override {
-    return static_cast<unsigned>(llvm::AMDGPU::Constant);
+    return static_cast<unsigned>(llvm::AMDGPUAS::CONSTANT_ADDRESS);
   }
 
   /// \returns If a target requires an address within a target specific address
@@ -398,9 +400,9 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUTargetInfo final : public TargetInfo {
   getDWARFAddressSpace(unsigned AddressSpace) const override {
     const unsigned DWARF_Private = 1;
     const unsigned DWARF_Local = 2;
-    if (AddressSpace == llvm::AMDGPU::Private) {
+    if (AddressSpace == llvm::AMDGPUAS::PRIVATE_ADDRESS) {
       return DWARF_Private;
-    } else if (AddressSpace == llvm::AMDGPU::Local) {
+    } else if (AddressSpace == llvm::AMDGPUAS::LOCAL_ADDRESS) {
       return DWARF_Local;
     } else {
       return std::nullopt;
diff --git a/flang/lib/Frontend/FrontendActions.cpp b/flang/lib/Frontend/FrontendActions.cpp
index 3741668eea67d..6713377aa9fdc 100644
--- a/flang/lib/Frontend/FrontendActions.cpp
+++ b/flang/lib/Frontend/FrontendActions.cpp
@@ -58,6 +58,7 @@
 #include "llvm/Passes/PassBuilder.h"
 #include "llvm/Passes/PassPlugin.h"
 #include "llvm/Passes/StandardInstrumentations.h"
+#include "llvm/Support/AMDGPUAddrSpace.h"
 #include "llvm/Support/Error.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/FileSystem.h"
@@ -302,7 +303,7 @@ static void addAMDGPUSpecificMLIRItems(mlir::ModuleOp &mlirModule,
     originalGVOp.setValueAttr(
         builder.getIntegerAttr(int32Type, oclcABIVERsion));
     originalGVOp.setUnnamedAddr(mlir::LLVM::UnnamedAddr::Local);
-    originalGVOp.setAddrSpace(llvm::AMDGPU::Constant);
+    originalGVOp.setAddrSpace(llvm::AMDGPUAS::CONSTANT_ADDRESS);
     originalGVOp.setVisibility_(mlir::LLVM::Visibility::Hidden);
     return;
   }
@@ -313,7 +314,7 @@ static void addAMDGPUSpecificMLIRItems(mlir::ModuleOp &mlirModule,
       /* Name */ codeObjectVersionGlobalOpName,
       /* Value */ builder.getIntegerAttr(int32Type, oclcABIVERsion));
   covInfo.setUnnamedAddr(mlir::LLVM::UnnamedAddr::Local);
-  covInfo.setAddrSpace(llvm::AMDGPU::Constant);
+  covInfo.setAddrSpace(llvm::AMDGPUAS::CONSTANT_ADDRESS);
   covInfo.setVisibility_(mlir::LLVM::Visibility::Hidden);
   builder.setInsertionPointToStart(mlirModule.getBody());
   builder.insert(covInfo);
diff --git a/llvm/include/llvm/Support/AMDGPUAddrSpace.h b/llvm/include/llvm/Support/AMDGPUAddrSpace.h
new file mode 100644
index 0000000000000..72caf8d458c7a
--- /dev/null
+++ b/llvm/include/llvm/Support/AMDGPUAddrSpace.h
@@ -0,0 +1,83 @@
+//===---------------- AMDGPUAddrSpace.h -------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+/// \file
+/// AMDGPU address space definition
+///
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_SUPPORT_AMDGPUADDRSPACE_H
+#define LLVM_SUPPORT_AMDGPUADDRSPACE_H
+
+namespace llvm {
+/// OpenCL uses address spaces to differentiate between
+/// various memory regions on the hardware. On the CPU
+/// all of the address spaces point to the same memory,
+/// however on the GPU, each address space points to
+/// a separate piece of memory that is unique from other
+/// memory locations.
+namespace AMDGPUAS {
+enum : unsigned {
+  // The maximum value for flat, generic, local, private, constant and region.
+  MAX_AMDGPU_ADDRESS = 8,
+
+  FLAT_ADDRESS = 0,   ///< Address space for flat memory.
+  GLOBAL_ADDRESS = 1, ///< Address space for global memory (RAT0, VTX0).
+  REGION_ADDRESS = 2, ///< Address space for region memory. (GDS)
+
+  CONSTANT_ADDRESS = 4, ///< Address space for constant memory (VTX2).
+  LOCAL_ADDRESS = 3,    ///< Address space for local memory.
+  PRIVATE_ADDRESS = 5,  ///< Address space for private memory.
+
+  CONSTANT_ADDRESS_32BIT = 6, ///< Address space for 32-bit constant memory.
+
+  BUFFER_FAT_POINTER = 7, ///< Address space for 160-bit buffer fat pointers.
+                          ///< Not used in backend.
+
+  BUFFER_RESOURCE = 8, ///< Address space for 128-bit buffer resources.
+
+  /// Internal address spaces. Can be freely renumbered.
+  STREAMOUT_REGISTER = 128, ///< Address space for GS NGG Streamout registers.
+  /// end Internal address spaces.
+
+  /// Address space for direct addressable parameter memory (CONST0).
+  PARAM_D_ADDRESS = 6,
+  /// Address space for indirect addressable parameter memory (VTX1).
+  PARAM_I_ADDRESS = 7,
+
+  // Do not re-order the CONSTANT_BUFFER_* enums.  Several places depend on
+  // this order to be able to dynamically index a constant buffer, for
+  // example:
+  //
+  // ConstantBufferAS = CONSTANT_BUFFER_0 + CBIdx
+
+  CONSTANT_BUFFER_0 = 8,
+  CONSTANT_BUFFER_1 = 9,
+  CONSTANT_BUFFER_2 = 10,
+  CONSTANT_BUFFER_3 = 11,
+  CONSTANT_BUFFER_4 = 12,
+  CONSTANT_BUFFER_5 = 13,
+  CONSTANT_BUFFER_6 = 14,
+  CONSTANT_BUFFER_7 = 15,
+  CONSTANT_BUFFER_8 = 16,
+  CONSTANT_BUFFER_9 = 17,
+  CONSTANT_BUFFER_10 = 18,
+  CONSTANT_BUFFER_11 = 19,
+  CONSTANT_BUFFER_12 = 20,
+  CONSTANT_BUFFER_13 = 21,
+  CONSTANT_BUFFER_14 = 22,
+  CONSTANT_BUFFER_15 = 23,
+
+  // Some places use this if the address space can't be determined.
+  UNKNOWN_ADDRESS_SPACE = ~0u,
+};
+} // end namespace AMDGPUAS
+} // end namespace llvm
+
+#endif // LLVM_SUPPORT_AMDGPUADDRSPACE_H
diff --git a/llvm/include/llvm/TargetParser/TargetParser.h b/llvm/include/llvm/TargetParser/TargetParser.h
index b0df831c47567..6464285980f00 100644
--- a/llvm/include/llvm/TargetParser/TargetParser.h
+++ b/llvm/include/llvm/TargetParser/TargetParser.h
@@ -31,15 +31,6 @@ class Triple;
 // back-end to TableGen to create these clean tables.
 namespace AMDGPU {
 
-/// Address space values for AMD GPUs
-enum AddrSpace {
-  Generic = 0,
-  Global = 1,
-  Local = 3,
-  Constant = 4,
-  Private = 5
-};
-
 /// GPU kinds supported by the AMDGPU target.
 enum GPUKind : uint32_t {
   // Not specified processor.
diff --git a/llvm/lib/Target/AMDGPU/AMDGPU.h b/llvm/lib/Target/AMDGPU/AMDGPU.h
index 323560a46f31d..2afda2b51fcbf 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPU.h
+++ b/llvm/lib/Target/AMDGPU/AMDGPU.h
@@ -12,6 +12,7 @@
 
 #include "llvm/IR/PassManager.h"
 #include "llvm/Pass.h"
+#include "llvm/Support/AMDGPUAddrSpace.h"
 #include "llvm/Support/CodeGen.h"
 
 namespace llvm {
@@ -390,72 +391,6 @@ enum TargetIndex {
   TI_SCRATCH_RSRC_DWORD2,
   TI_SCRATCH_RSRC_DWORD3
 };
-}
-
-/// OpenCL uses address spaces to differentiate between
-/// various memory regions on the hardware. On the CPU
-/// all of the address spaces point to the same memory,
-/// however on the GPU, each address space points to
-/// a separate piece of memory that is unique from other
-/// memory locations.
-namespace AMDGPUAS {
-enum : unsigned {
-  // The maximum value for flat, generic, local, private, constant and region.
-  MAX_AMDGPU_ADDRESS = 8,
-
-  FLAT_ADDRESS = 0,   ///< Address space for flat memory.
-  GLOBAL_ADDRESS = 1, ///< Address space for global memory (RAT0, VTX0).
-  REGION_ADDRESS = 2, ///< Address space for region memory. (GDS)
-
-  CONSTANT_ADDRESS = 4, ///< Address space for constant memory (VTX2).
-  LOCAL_ADDRESS = 3,    ///< Address space for local memory.
-  PRIVATE_ADDRESS = 5,  ///< Address space for private memory.
-
-  CONSTANT_ADDRESS_32BIT = 6, ///< Address space for 32-bit constant memory.
-
-  BUFFER_FAT_POINTER = 7, ///< Address space for 160-bit buffer fat pointers.
-                          ///< Not used in backend.
-
-  BUFFER_RESOURCE = 8, ///< Address space for 128-bit buffer resources.
-
-  /// Internal address spaces. Can be freely renumbered.
-  STREAMOUT_REGISTER = 128, ///< Address space for GS NGG Streamout registers.
-  /// end Internal address spaces.
-
-  /// Address space for direct addressable parameter memory (CONST0).
-  PARAM_D_ADDRESS = 6,
-  /// Address space for indirect addressable parameter memory (VTX1).
-  PARAM_I_ADDRESS = 7,
-
-  // Do not re-order the CONSTANT_BUFFER_* enums.  Several places depend on
-  // this order to be able to dynamically index a constant buffer, for
-  // example:
-  //
-  // ConstantBufferAS = CONSTANT_BUFFER_0 + CBIdx
-
-  CONSTANT_BUFFER_0 = 8,
-  CONSTANT_BUFFER_1 = 9,
-  CONSTANT_BUFFER_2 = 10,
-  CONSTANT_BUFFER_3 = 11,
-  CONSTANT_BUFFER_4 = 12,
-  CONSTANT_BUFFER_5 = 13,
-  CONSTANT_BUFFER_6 = 14,
-  CONSTANT_BUFFER_7 = 15,
-  CONSTANT_BUFFER_8 = 16,
-  CONSTANT_BUFFER_9 = 17,
-  CONSTANT_BUFFER_10 = 18,
-  CONSTANT_BUFFER_11 = 19,
-  CONSTANT_BUFFER_12 = 20,
-  CONSTANT_BUFFER_13 = 21,
-  CONSTANT_BUFFER_14 = 22,
-  CONSTANT_BUFFER_15 = 23,
-
-  // Some places use this if the address space can't be determined.
-  UNKNOWN_ADDRESS_SPACE = ~0u,
-};
-}
-
-namespace AMDGPU {
 
 // FIXME: Missing constant_32bit
 inline bool isFlatGlobalAddrSpace(unsigned AS) {



More information about the cfe-commits mailing list