[clang] [CIR] Upstream `AddressSpace` support for `PointerType` (PR #161028)
Henrich Lauko via cfe-commits
cfe-commits at lists.llvm.org
Tue Sep 30 11:46:54 PDT 2025
================
@@ -766,30 +800,93 @@ mlir::LogicalResult cir::VectorType::verify(
}
//===----------------------------------------------------------------------===//
-// PointerType Definitions
-//===----------------------------------------------------------------------===//
-
-llvm::TypeSize
-PointerType::getTypeSizeInBits(const ::mlir::DataLayout &dataLayout,
- ::mlir::DataLayoutEntryListRef params) const {
- // FIXME: improve this in face of address spaces
- return llvm::TypeSize::getFixed(64);
+// AddressSpace definitions
+//===----------------------------------------------------------------------===//
+
+cir::AddressSpace cir::toCIRAddressSpace(clang::LangAS langAS) {
+ using clang::LangAS;
+ switch (langAS) {
+ case LangAS::Default:
+ return AddressSpace::Default;
+ case LangAS::opencl_global:
+ return AddressSpace::OffloadGlobal;
+ case LangAS::opencl_local:
+ case LangAS::cuda_shared:
+ // Local means local among the work-group (OpenCL) or block (CUDA).
+ // All threads inside the kernel can access local memory.
+ return AddressSpace::OffloadLocal;
+ case LangAS::cuda_device:
+ return AddressSpace::OffloadGlobal;
+ case LangAS::opencl_constant:
+ case LangAS::cuda_constant:
+ return AddressSpace::OffloadConstant;
+ case LangAS::opencl_private:
+ return AddressSpace::OffloadPrivate;
+ case LangAS::opencl_generic:
+ return AddressSpace::OffloadGeneric;
+ case LangAS::opencl_global_device:
+ case LangAS::opencl_global_host:
+ case LangAS::sycl_global:
+ case LangAS::sycl_global_device:
+ case LangAS::sycl_global_host:
+ case LangAS::sycl_local:
+ case LangAS::sycl_private:
+ case LangAS::ptr32_sptr:
+ case LangAS::ptr32_uptr:
+ case LangAS::ptr64:
+ case LangAS::hlsl_groupshared:
+ case LangAS::wasm_funcref:
+ llvm_unreachable("NYI");
+ default:
+ // Target address space offset arithmetics
+ return static_cast<cir::AddressSpace>(clang::toTargetAddressSpace(langAS) +
+ cir::getMaxEnumValForAddressSpace());
+ }
}
-uint64_t
-PointerType::getABIAlignment(const ::mlir::DataLayout &dataLayout,
- ::mlir::DataLayoutEntryListRef params) const {
- // FIXME: improve this in face of address spaces
- return 8;
-}
+mlir::ParseResult parseAddressSpaceValue(mlir::AsmParser &p,
+ cir::AddressSpace &addrSpace) {
+ llvm::SMLoc loc = p.getCurrentLocation();
+ mlir::FailureOr<cir::AddressSpace> result =
+ mlir::FieldParser<cir::AddressSpace>::parse(p);
+ if (mlir::failed(result))
+ return p.emitError(loc, "expected address space keyword");
+
+ // Address space is either a target address space or a regular one.
+ // - If it is a target address space, we expect a value to follow in the form
+ // of `<value>`, where value is an integer that represents the target address
+ // space value. This value is kept in the address space enum as an offset
+ // from the maximum address space value, which is defined in
+ // `cir::getMaxEnumValForAddressSpace()`. This allows us to use
+ // the same enum for both regular and target address spaces.
+ // - Otherwise, we just use the parsed value.
+ if (cir::isTargetAddressSpace(result.value())) {
+ if (p.parseLess())
+ return p.emitError(loc, "expected '<' after target address space");
+
+ int64_t targetValue;
+ if (p.parseInteger(targetValue) || p.parseGreater())
+ return p.emitError(loc, "expected target address space value");
+
+ addrSpace = cir::computeTargetAddressSpace(targetValue);
+ } else {
+ addrSpace = result.value();
+ }
-mlir::LogicalResult
-PointerType::verify(llvm::function_ref<mlir::InFlightDiagnostic()> emitError,
----------------
xlauko wrote:
Yes, I believe it covers all necessery things implicitly.
https://github.com/llvm/llvm-project/pull/161028
More information about the cfe-commits
mailing list