[clang] [CIR] Infrastructure and MemorySpaceAttrInterface for Address Spaces (PR #179073)

2026-02-27 Thread David Rivera via cfe-commits

https://github.com/RiverDave closed 
https://github.com/llvm/llvm-project/pull/179073
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [CIR] Infrastructure and MemorySpaceAttrInterface for Address Spaces (PR #179073)

2026-02-27 Thread David Rivera via cfe-commits

https://github.com/RiverDave updated 
https://github.com/llvm/llvm-project/pull/179073

>From e71fcdfb4f7ba18cbb98246193530937d7202b7c Mon Sep 17 00:00:00 2001
From: David Rivera 
Date: Sat, 31 Jan 2026 17:48:05 -0500
Subject: [PATCH 1/9] [CIR] Infrastructure and MemorySpaceAttrInterface for
 Address Spaces

---
 .../CIR/Dialect/Builder/CIRBaseBuilder.h  |  20 +-
 clang/include/clang/CIR/Dialect/IR/CIRAttrs.h |   1 +
 .../include/clang/CIR/Dialect/IR/CIRAttrs.td  |  55 +-
 .../clang/CIR/Dialect/IR/CIREnumAttr.td   |  19 ++
 clang/include/clang/CIR/Dialect/IR/CIRTypes.h |  17 +-
 .../include/clang/CIR/Dialect/IR/CIRTypes.td  |  10 +-
 clang/lib/CIR/CodeGen/Address.h   |   3 +-
 clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp   |   2 +-
 clang/lib/CIR/CodeGen/CIRGenExpr.cpp  |   5 +-
 clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp|   1 +
 clang/lib/CIR/CodeGen/CIRGenTypeCache.h   |   5 +-
 clang/lib/CIR/CodeGen/TargetInfo.cpp  |   1 +
 clang/lib/CIR/CodeGen/TargetInfo.h|   3 +-
 clang/lib/CIR/Dialect/IR/CIRAttrs.cpp | 108 +-
 clang/lib/CIR/Dialect/IR/CIRTypes.cpp | 187 ++
 .../CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp |  17 +-
 clang/test/CIR/IR/address-space.cir   |  41 
 clang/test/CIR/IR/invalid-addrspace.cir   |  32 ++-
 18 files changed, 451 insertions(+), 76 deletions(-)
 create mode 100644 clang/test/CIR/IR/address-space.cir

diff --git a/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h 
b/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h
index efae3d9d894ed..f62dedb1f3f00 100644
--- a/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h
+++ b/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h
@@ -155,29 +155,27 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
 return cir::PointerType::get(ty);
   }
 
-  cir::PointerType getPointerTo(mlir::Type ty, cir::TargetAddressSpaceAttr as) 
{
+  cir::PointerType getPointerTo(mlir::Type ty,
+mlir::ptr::MemorySpaceAttrInterface as) {
+if (!as)
+  return cir::PointerType::get(ty);
 return cir::PointerType::get(ty, as);
   }
 
   cir::PointerType getPointerTo(mlir::Type ty, clang::LangAS langAS) {
-if (langAS == clang::LangAS::Default) // Default address space.
+if (langAS == clang::LangAS::Default)
   return getPointerTo(ty);
 
-if (clang::isTargetAddressSpace(langAS)) {
-  unsigned addrSpace = clang::toTargetAddressSpace(langAS);
-  auto asAttr = cir::TargetAddressSpaceAttr::get(
-  getContext(), getUI32IntegerAttr(addrSpace));
-  return getPointerTo(ty, asAttr);
-}
-
-llvm_unreachable("language-specific address spaces NYI");
+mlir::ptr::MemorySpaceAttrInterface addrSpaceAttr =
+cir::toCIRAddressSpaceAttr(getContext(), langAS);
+return getPointerTo(ty, addrSpaceAttr);
   }
 
   cir::PointerType getVoidPtrTy(clang::LangAS langAS = clang::LangAS::Default) 
{
 return getPointerTo(cir::VoidType::get(getContext()), langAS);
   }
 
-  cir::PointerType getVoidPtrTy(cir::TargetAddressSpaceAttr as) {
+  cir::PointerType getVoidPtrTy(mlir::ptr::MemorySpaceAttrInterface as) {
 return getPointerTo(cir::VoidType::get(getContext()), as);
   }
 
diff --git a/clang/include/clang/CIR/Dialect/IR/CIRAttrs.h 
b/clang/include/clang/CIR/Dialect/IR/CIRAttrs.h
index eb87dc083b0f5..f6674a10af66b 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIRAttrs.h
+++ b/clang/include/clang/CIR/Dialect/IR/CIRAttrs.h
@@ -13,6 +13,7 @@
 #ifndef CLANG_CIR_DIALECT_IR_CIRATTRS_H
 #define CLANG_CIR_DIALECT_IR_CIRATTRS_H
 
+#include "mlir/Dialect/Ptr/IR/MemorySpaceInterfaces.h"
 #include "mlir/IR/Attributes.h"
 #include "mlir/IR/BuiltinAttributeInterfaces.h"
 #include "clang/Basic/AddressSpaces.h"
diff --git a/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td 
b/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td
index 845ec4a85fa7d..b1be1d5daf4e0 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td
@@ -14,6 +14,7 @@
 #define CLANG_CIR_DIALECT_IR_CIRATTRS_TD
 
 include "mlir/IR/BuiltinAttributeInterfaces.td"
+include "mlir/Dialect/Ptr/IR/MemorySpaceInterfaces.td"
 
 include "clang/CIR/Dialect/IR/CIRAttrConstraints.td"
 include "clang/CIR/Dialect/IR/CIRDialect.td"
@@ -783,16 +784,64 @@ def CIR_DynamicCastInfoAttr : CIR_Attr<"DynamicCastInfo", 
"dyn_cast_info"> {
   }];
 }
 
+//===--===//
+// LangAddressSpaceAttr
+//===--===//
+
+def CIR_LangAddressSpaceAttr : CIR_EnumAttr
+]> {
+  let summary = "Represents a language address space";
+  let description = [{
+Encodes the semantic address spaces defined by the front-end language
+(e.g. `__shared__`, `__constant__`, `__local__`). Values are stored using 
the
+`cir::LangAddressSpace` enum, keeping the representation 

[clang] [CIR] Infrastructure and MemorySpaceAttrInterface for Address Spaces (PR #179073)

2026-02-25 Thread David Rivera via cfe-commits

https://github.com/RiverDave updated 
https://github.com/llvm/llvm-project/pull/179073

>From e71fcdfb4f7ba18cbb98246193530937d7202b7c Mon Sep 17 00:00:00 2001
From: David Rivera 
Date: Sat, 31 Jan 2026 17:48:05 -0500
Subject: [PATCH 1/6] [CIR] Infrastructure and MemorySpaceAttrInterface for
 Address Spaces

---
 .../CIR/Dialect/Builder/CIRBaseBuilder.h  |  20 +-
 clang/include/clang/CIR/Dialect/IR/CIRAttrs.h |   1 +
 .../include/clang/CIR/Dialect/IR/CIRAttrs.td  |  55 +-
 .../clang/CIR/Dialect/IR/CIREnumAttr.td   |  19 ++
 clang/include/clang/CIR/Dialect/IR/CIRTypes.h |  17 +-
 .../include/clang/CIR/Dialect/IR/CIRTypes.td  |  10 +-
 clang/lib/CIR/CodeGen/Address.h   |   3 +-
 clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp   |   2 +-
 clang/lib/CIR/CodeGen/CIRGenExpr.cpp  |   5 +-
 clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp|   1 +
 clang/lib/CIR/CodeGen/CIRGenTypeCache.h   |   5 +-
 clang/lib/CIR/CodeGen/TargetInfo.cpp  |   1 +
 clang/lib/CIR/CodeGen/TargetInfo.h|   3 +-
 clang/lib/CIR/Dialect/IR/CIRAttrs.cpp | 108 +-
 clang/lib/CIR/Dialect/IR/CIRTypes.cpp | 187 ++
 .../CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp |  17 +-
 clang/test/CIR/IR/address-space.cir   |  41 
 clang/test/CIR/IR/invalid-addrspace.cir   |  32 ++-
 18 files changed, 451 insertions(+), 76 deletions(-)
 create mode 100644 clang/test/CIR/IR/address-space.cir

diff --git a/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h 
b/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h
index efae3d9d894ed..f62dedb1f3f00 100644
--- a/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h
+++ b/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h
@@ -155,29 +155,27 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
 return cir::PointerType::get(ty);
   }
 
-  cir::PointerType getPointerTo(mlir::Type ty, cir::TargetAddressSpaceAttr as) 
{
+  cir::PointerType getPointerTo(mlir::Type ty,
+mlir::ptr::MemorySpaceAttrInterface as) {
+if (!as)
+  return cir::PointerType::get(ty);
 return cir::PointerType::get(ty, as);
   }
 
   cir::PointerType getPointerTo(mlir::Type ty, clang::LangAS langAS) {
-if (langAS == clang::LangAS::Default) // Default address space.
+if (langAS == clang::LangAS::Default)
   return getPointerTo(ty);
 
-if (clang::isTargetAddressSpace(langAS)) {
-  unsigned addrSpace = clang::toTargetAddressSpace(langAS);
-  auto asAttr = cir::TargetAddressSpaceAttr::get(
-  getContext(), getUI32IntegerAttr(addrSpace));
-  return getPointerTo(ty, asAttr);
-}
-
-llvm_unreachable("language-specific address spaces NYI");
+mlir::ptr::MemorySpaceAttrInterface addrSpaceAttr =
+cir::toCIRAddressSpaceAttr(getContext(), langAS);
+return getPointerTo(ty, addrSpaceAttr);
   }
 
   cir::PointerType getVoidPtrTy(clang::LangAS langAS = clang::LangAS::Default) 
{
 return getPointerTo(cir::VoidType::get(getContext()), langAS);
   }
 
-  cir::PointerType getVoidPtrTy(cir::TargetAddressSpaceAttr as) {
+  cir::PointerType getVoidPtrTy(mlir::ptr::MemorySpaceAttrInterface as) {
 return getPointerTo(cir::VoidType::get(getContext()), as);
   }
 
diff --git a/clang/include/clang/CIR/Dialect/IR/CIRAttrs.h 
b/clang/include/clang/CIR/Dialect/IR/CIRAttrs.h
index eb87dc083b0f5..f6674a10af66b 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIRAttrs.h
+++ b/clang/include/clang/CIR/Dialect/IR/CIRAttrs.h
@@ -13,6 +13,7 @@
 #ifndef CLANG_CIR_DIALECT_IR_CIRATTRS_H
 #define CLANG_CIR_DIALECT_IR_CIRATTRS_H
 
+#include "mlir/Dialect/Ptr/IR/MemorySpaceInterfaces.h"
 #include "mlir/IR/Attributes.h"
 #include "mlir/IR/BuiltinAttributeInterfaces.h"
 #include "clang/Basic/AddressSpaces.h"
diff --git a/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td 
b/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td
index 845ec4a85fa7d..b1be1d5daf4e0 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td
@@ -14,6 +14,7 @@
 #define CLANG_CIR_DIALECT_IR_CIRATTRS_TD
 
 include "mlir/IR/BuiltinAttributeInterfaces.td"
+include "mlir/Dialect/Ptr/IR/MemorySpaceInterfaces.td"
 
 include "clang/CIR/Dialect/IR/CIRAttrConstraints.td"
 include "clang/CIR/Dialect/IR/CIRDialect.td"
@@ -783,16 +784,64 @@ def CIR_DynamicCastInfoAttr : CIR_Attr<"DynamicCastInfo", 
"dyn_cast_info"> {
   }];
 }
 
+//===--===//
+// LangAddressSpaceAttr
+//===--===//
+
+def CIR_LangAddressSpaceAttr : CIR_EnumAttr
+]> {
+  let summary = "Represents a language address space";
+  let description = [{
+Encodes the semantic address spaces defined by the front-end language
+(e.g. `__shared__`, `__constant__`, `__local__`). Values are stored using 
the
+`cir::LangAddressSpace` enum, keeping the representation 

[clang] [CIR] Infrastructure and MemorySpaceAttrInterface for Address Spaces (PR #179073)

2026-02-25 Thread David Rivera via cfe-commits

https://github.com/RiverDave updated 
https://github.com/llvm/llvm-project/pull/179073

>From e71fcdfb4f7ba18cbb98246193530937d7202b7c Mon Sep 17 00:00:00 2001
From: David Rivera 
Date: Sat, 31 Jan 2026 17:48:05 -0500
Subject: [PATCH 1/5] [CIR] Infrastructure and MemorySpaceAttrInterface for
 Address Spaces

---
 .../CIR/Dialect/Builder/CIRBaseBuilder.h  |  20 +-
 clang/include/clang/CIR/Dialect/IR/CIRAttrs.h |   1 +
 .../include/clang/CIR/Dialect/IR/CIRAttrs.td  |  55 +-
 .../clang/CIR/Dialect/IR/CIREnumAttr.td   |  19 ++
 clang/include/clang/CIR/Dialect/IR/CIRTypes.h |  17 +-
 .../include/clang/CIR/Dialect/IR/CIRTypes.td  |  10 +-
 clang/lib/CIR/CodeGen/Address.h   |   3 +-
 clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp   |   2 +-
 clang/lib/CIR/CodeGen/CIRGenExpr.cpp  |   5 +-
 clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp|   1 +
 clang/lib/CIR/CodeGen/CIRGenTypeCache.h   |   5 +-
 clang/lib/CIR/CodeGen/TargetInfo.cpp  |   1 +
 clang/lib/CIR/CodeGen/TargetInfo.h|   3 +-
 clang/lib/CIR/Dialect/IR/CIRAttrs.cpp | 108 +-
 clang/lib/CIR/Dialect/IR/CIRTypes.cpp | 187 ++
 .../CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp |  17 +-
 clang/test/CIR/IR/address-space.cir   |  41 
 clang/test/CIR/IR/invalid-addrspace.cir   |  32 ++-
 18 files changed, 451 insertions(+), 76 deletions(-)
 create mode 100644 clang/test/CIR/IR/address-space.cir

diff --git a/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h 
b/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h
index efae3d9d894ed..f62dedb1f3f00 100644
--- a/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h
+++ b/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h
@@ -155,29 +155,27 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
 return cir::PointerType::get(ty);
   }
 
-  cir::PointerType getPointerTo(mlir::Type ty, cir::TargetAddressSpaceAttr as) 
{
+  cir::PointerType getPointerTo(mlir::Type ty,
+mlir::ptr::MemorySpaceAttrInterface as) {
+if (!as)
+  return cir::PointerType::get(ty);
 return cir::PointerType::get(ty, as);
   }
 
   cir::PointerType getPointerTo(mlir::Type ty, clang::LangAS langAS) {
-if (langAS == clang::LangAS::Default) // Default address space.
+if (langAS == clang::LangAS::Default)
   return getPointerTo(ty);
 
-if (clang::isTargetAddressSpace(langAS)) {
-  unsigned addrSpace = clang::toTargetAddressSpace(langAS);
-  auto asAttr = cir::TargetAddressSpaceAttr::get(
-  getContext(), getUI32IntegerAttr(addrSpace));
-  return getPointerTo(ty, asAttr);
-}
-
-llvm_unreachable("language-specific address spaces NYI");
+mlir::ptr::MemorySpaceAttrInterface addrSpaceAttr =
+cir::toCIRAddressSpaceAttr(getContext(), langAS);
+return getPointerTo(ty, addrSpaceAttr);
   }
 
   cir::PointerType getVoidPtrTy(clang::LangAS langAS = clang::LangAS::Default) 
{
 return getPointerTo(cir::VoidType::get(getContext()), langAS);
   }
 
-  cir::PointerType getVoidPtrTy(cir::TargetAddressSpaceAttr as) {
+  cir::PointerType getVoidPtrTy(mlir::ptr::MemorySpaceAttrInterface as) {
 return getPointerTo(cir::VoidType::get(getContext()), as);
   }
 
diff --git a/clang/include/clang/CIR/Dialect/IR/CIRAttrs.h 
b/clang/include/clang/CIR/Dialect/IR/CIRAttrs.h
index eb87dc083b0f5..f6674a10af66b 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIRAttrs.h
+++ b/clang/include/clang/CIR/Dialect/IR/CIRAttrs.h
@@ -13,6 +13,7 @@
 #ifndef CLANG_CIR_DIALECT_IR_CIRATTRS_H
 #define CLANG_CIR_DIALECT_IR_CIRATTRS_H
 
+#include "mlir/Dialect/Ptr/IR/MemorySpaceInterfaces.h"
 #include "mlir/IR/Attributes.h"
 #include "mlir/IR/BuiltinAttributeInterfaces.h"
 #include "clang/Basic/AddressSpaces.h"
diff --git a/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td 
b/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td
index 845ec4a85fa7d..b1be1d5daf4e0 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td
@@ -14,6 +14,7 @@
 #define CLANG_CIR_DIALECT_IR_CIRATTRS_TD
 
 include "mlir/IR/BuiltinAttributeInterfaces.td"
+include "mlir/Dialect/Ptr/IR/MemorySpaceInterfaces.td"
 
 include "clang/CIR/Dialect/IR/CIRAttrConstraints.td"
 include "clang/CIR/Dialect/IR/CIRDialect.td"
@@ -783,16 +784,64 @@ def CIR_DynamicCastInfoAttr : CIR_Attr<"DynamicCastInfo", 
"dyn_cast_info"> {
   }];
 }
 
+//===--===//
+// LangAddressSpaceAttr
+//===--===//
+
+def CIR_LangAddressSpaceAttr : CIR_EnumAttr
+]> {
+  let summary = "Represents a language address space";
+  let description = [{
+Encodes the semantic address spaces defined by the front-end language
+(e.g. `__shared__`, `__constant__`, `__local__`). Values are stored using 
the
+`cir::LangAddressSpace` enum, keeping the representation 

[clang] [CIR] Infrastructure and MemorySpaceAttrInterface for Address Spaces (PR #179073)

2026-02-13 Thread Konstantinos Parasyris via cfe-commits

https://github.com/koparasy approved this pull request.


https://github.com/llvm/llvm-project/pull/179073
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [CIR] Infrastructure and MemorySpaceAttrInterface for Address Spaces (PR #179073)

2026-02-05 Thread Bruno Cardoso Lopes via cfe-commits

https://github.com/bcardosolopes approved this pull request.


https://github.com/llvm/llvm-project/pull/179073
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [CIR] Infrastructure and MemorySpaceAttrInterface for Address Spaces (PR #179073)

2026-02-04 Thread David Rivera via cfe-commits

https://github.com/RiverDave updated 
https://github.com/llvm/llvm-project/pull/179073

>From 8fee86d3d86a565db540246d1d7ce18c84012ce4 Mon Sep 17 00:00:00 2001
From: David Rivera 
Date: Sat, 31 Jan 2026 17:48:05 -0500
Subject: [PATCH 1/3] [CIR] Infrastructure and MemorySpaceAttrInterface for
 Address Spaces

---
 .../CIR/Dialect/Builder/CIRBaseBuilder.h  |  20 +-
 clang/include/clang/CIR/Dialect/IR/CIRAttrs.h |   1 +
 .../include/clang/CIR/Dialect/IR/CIRAttrs.td  |  55 +-
 .../clang/CIR/Dialect/IR/CIREnumAttr.td   |  19 ++
 clang/include/clang/CIR/Dialect/IR/CIRTypes.h |  17 +-
 .../include/clang/CIR/Dialect/IR/CIRTypes.td  |  10 +-
 clang/lib/CIR/CodeGen/Address.h   |   3 +-
 clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp   |   2 +-
 clang/lib/CIR/CodeGen/CIRGenExpr.cpp  |  16 +-
 clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp|   5 +-
 clang/lib/CIR/CodeGen/CIRGenTypeCache.h   |   5 +-
 clang/lib/CIR/CodeGen/TargetInfo.cpp  |   6 +-
 clang/lib/CIR/CodeGen/TargetInfo.h|  11 +-
 clang/lib/CIR/Dialect/IR/CIRAttrs.cpp | 108 +-
 clang/lib/CIR/Dialect/IR/CIRTypes.cpp | 187 ++
 .../CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp |  23 ++-
 clang/test/CIR/IR/address-space.cir   |  41 
 clang/test/CIR/IR/invalid-addrspace.cir   |  32 ++-
 18 files changed, 468 insertions(+), 93 deletions(-)
 create mode 100644 clang/test/CIR/IR/address-space.cir

diff --git a/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h 
b/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h
index 229bf1e205994..8fe2e85432a74 100644
--- a/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h
+++ b/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h
@@ -153,29 +153,27 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
 return cir::PointerType::get(ty);
   }
 
-  cir::PointerType getPointerTo(mlir::Type ty, cir::TargetAddressSpaceAttr as) 
{
+  cir::PointerType getPointerTo(mlir::Type ty,
+mlir::ptr::MemorySpaceAttrInterface as) {
+if (!as)
+  return cir::PointerType::get(ty);
 return cir::PointerType::get(ty, as);
   }
 
   cir::PointerType getPointerTo(mlir::Type ty, clang::LangAS langAS) {
-if (langAS == clang::LangAS::Default) // Default address space.
+if (langAS == clang::LangAS::Default)
   return getPointerTo(ty);
 
-if (clang::isTargetAddressSpace(langAS)) {
-  unsigned addrSpace = clang::toTargetAddressSpace(langAS);
-  auto asAttr = cir::TargetAddressSpaceAttr::get(
-  getContext(), getUI32IntegerAttr(addrSpace));
-  return getPointerTo(ty, asAttr);
-}
-
-llvm_unreachable("language-specific address spaces NYI");
+mlir::ptr::MemorySpaceAttrInterface addrSpaceAttr =
+cir::toCIRAddressSpaceAttr(getContext(), langAS);
+return getPointerTo(ty, addrSpaceAttr);
   }
 
   cir::PointerType getVoidPtrTy(clang::LangAS langAS = clang::LangAS::Default) 
{
 return getPointerTo(cir::VoidType::get(getContext()), langAS);
   }
 
-  cir::PointerType getVoidPtrTy(cir::TargetAddressSpaceAttr as) {
+  cir::PointerType getVoidPtrTy(mlir::ptr::MemorySpaceAttrInterface as) {
 return getPointerTo(cir::VoidType::get(getContext()), as);
   }
 
diff --git a/clang/include/clang/CIR/Dialect/IR/CIRAttrs.h 
b/clang/include/clang/CIR/Dialect/IR/CIRAttrs.h
index 858d4d6350bed..1d61bd998c216 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIRAttrs.h
+++ b/clang/include/clang/CIR/Dialect/IR/CIRAttrs.h
@@ -13,6 +13,7 @@
 #ifndef CLANG_CIR_DIALECT_IR_CIRATTRS_H
 #define CLANG_CIR_DIALECT_IR_CIRATTRS_H
 
+#include "mlir/Dialect/Ptr/IR/MemorySpaceInterfaces.h"
 #include "mlir/IR/Attributes.h"
 #include "mlir/IR/BuiltinAttributeInterfaces.h"
 #include "clang/Basic/AddressSpaces.h"
diff --git a/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td 
b/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td
index d7938bc350925..bc6b1c61a4f6b 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td
@@ -14,6 +14,7 @@
 #define CLANG_CIR_DIALECT_IR_CIRATTRS_TD
 
 include "mlir/IR/BuiltinAttributeInterfaces.td"
+include "mlir/Dialect/Ptr/IR/MemorySpaceInterfaces.td"
 
 include "clang/CIR/Dialect/IR/CIRAttrConstraints.td"
 include "clang/CIR/Dialect/IR/CIRDialect.td"
@@ -781,16 +782,64 @@ def CIR_DynamicCastInfoAttr : CIR_Attr<"DynamicCastInfo", 
"dyn_cast_info"> {
   }];
 }
 
+//===--===//
+// LangAddressSpaceAttr
+//===--===//
+
+def CIR_LangAddressSpaceAttr : CIR_EnumAttr
+]> {
+  let summary = "Represents a language address space";
+  let description = [{
+Encodes the semantic address spaces defined by the front-end language
+(e.g. `__shared__`, `__constant__`, `__local__`). Values are stored using 
the
+`cir::LangAddressSpace` enum, keeping the representati

[clang] [CIR] Infrastructure and MemorySpaceAttrInterface for Address Spaces (PR #179073)

2026-02-04 Thread via cfe-commits

github-actions[bot] wrote:


# :penguin: Linux x64 Test Results

* 86997 tests passed
* 757 tests skipped
* 2 tests failed

## Failed Tests
(click on a test name to see its output)

### Clang

Clang.CIR/CodeGenBuiltins/builtin_call.cpp

```
Exit Code: -11

Command Output (stdout):
--
# RUN: at line 1
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/clang -cc1 
-internal-isystem 
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/lib/clang/23/include
 -nostdsysteminc -std=c++11 -triple x86_64-unknown-linux-gnu -Wno-unused-value 
-fclangir -emit-cir 
/home/gha/actions-runner/_work/llvm-project/llvm-project/clang/test/CIR/CodeGenBuiltins/builtin_call.cpp
 -o 
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/clang/test/CIR/CodeGenBuiltins/Output/builtin_call.cpp.tmp.cir
# executed command: 
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/clang -cc1 
-internal-isystem 
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/lib/clang/23/include
 -nostdsysteminc -std=c++11 -triple x86_64-unknown-linux-gnu -Wno-unused-value 
-fclangir -emit-cir 
/home/gha/actions-runner/_work/llvm-project/llvm-project/clang/test/CIR/CodeGenBuiltins/builtin_call.cpp
 -o 
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/clang/test/CIR/CodeGenBuiltins/Output/builtin_call.cpp.tmp.cir
# .---command stderr
# | 
/home/gha/actions-runner/_work/llvm-project/llvm-project/clang/test/CIR/CodeGenBuiltins/builtin_call.cpp:8:31:
 warning: '__builtin_is_constant_evaluated' will always evaluate to 'true' in a 
manifestly constant-evaluated expression [-Wconstant-evaluated]
# | 8 | constexpr extern int cx_var = __builtin_is_constant_evaluated();
# |   |   ^
# | 
/home/gha/actions-runner/_work/llvm-project/llvm-project/clang/test/CIR/CodeGenBuiltins/builtin_call.cpp:81:20:
 warning: null passed to a callee that requires a non-null argument [-Wnonnull]
# |81 |   __builtin_printf(nullptr);
# |   |^~~
# | PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ 
and include the crash backtrace, preprocessed source, and associated run script.
# | Stack dump:
# | 0.  Program arguments: 
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/clang -cc1 
-internal-isystem 
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/lib/clang/23/include
 -nostdsysteminc -std=c++11 -triple x86_64-unknown-linux-gnu -Wno-unused-value 
-fclangir -emit-cir 
/home/gha/actions-runner/_work/llvm-project/llvm-project/clang/test/CIR/CodeGenBuiltins/builtin_call.cpp
 -o 
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/clang/test/CIR/CodeGenBuiltins/Output/builtin_call.cpp.tmp.cir
# | 1.  
/home/gha/actions-runner/_work/llvm-project/llvm-project/clang/test/CIR/CodeGenBuiltins/builtin_call.cpp:292:1:
 current parser token 'bool'
# |  #0 0x09c19418 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) 
/home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/lib/Support/Unix/Signals.inc:842:13
# |  #1 0x09c16b45 llvm::sys::RunSignalHandlers() 
/home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/lib/Support/Signals.cpp:109:18
# |  #2 0x09c1a1e1 SignalHandler(int, siginfo_t*, void*) 
/home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/lib/Support/Unix/Signals.inc:429:38
# |  #3 0x79bd8f149330 (/lib/x86_64-linux-gnu/libc.so.6+0x45330)
# |  #4 0x0cce52e3 getAbstractAttribute 
/home/gha/actions-runner/_work/llvm-project/llvm-project/mlir/include/mlir/IR/AttributeSupport.h:177:5
# |  #5 0x0cce52e3 getDialect 
/home/gha/actions-runner/_work/llvm-project/llvm-project/mlir/include/mlir/IR/Attributes.h:59:18
# |  #6 0x0cce52e3 mlir::Attribute::getContext() const 
/home/gha/actions-runner/_work/llvm-project/llvm-project/mlir/lib/IR/Attributes.cpp:37:53
# |  #7 0x0c76a558 
cir::isMatchingAddressSpace(mlir::ptr::MemorySpaceAttrInterface, clang::LangAS) 
/home/gha/actions-runner/_work/llvm-project/llvm-project/clang/lib/CIR/Dialect/IR/CIRTypes.cpp:1077:10
# |  #8 0x0addb98f emitBuiltinAlloca(clang::CIRGen::CIRGenFunction&, 
clang::CallExpr const*, unsigned int) 
/home/gha/actions-runner/_work/llvm-project/llvm-project/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp:340:7
# |  #9 0x0add8653 
clang::CIRGen::CIRGenFunction::emitBuiltinExpr(clang::GlobalDecl const&, 
unsigned int, clang::CallExpr const*, clang::CIRGen::ReturnValueSlot) 
/home/gha/actions-runner/_work/llvm-project/llvm-project/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp:1288:5
# | #10 0x0adcd1e6 
clang::CIRGen::CIRGenFunction::emitCallExpr(clang::CallExpr const*, 
clang::CIRGen::ReturnValueSlot) 
/home/gha/actions-runner/_work/llvm-project/llvm-project/clang/lib/CIR/CodeGen/CIRGenExpr.cpp:2148:5
# | #11 0x0ae1c452 isScalar 
/home/gha/actions-runner/_work/llvm-project/llvm-project/clang/lib/CIR/