[Mlir-commits] [mlir] [mlir][SPIRV] Lower ptr dialect to PBA addresses (PR #206159)
Igor Wodiany
llvmlistbot at llvm.org
Mon Jun 29 02:05:34 PDT 2026
================
@@ -0,0 +1,297 @@
+//===- PtrToSPIRV.cpp - Ptr to SPIR-V dialect conversion -----------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "mlir/Conversion/PtrToSPIRV/PtrToSPIRV.h"
+
+#include "mlir/Dialect/Ptr/IR/PtrOps.h"
+#include "mlir/Dialect/Ptr/IR/PtrTypes.h"
+#include "mlir/Dialect/SPIRV/IR/SPIRVAttributes.h"
+#include "mlir/Dialect/SPIRV/IR/SPIRVDialect.h"
+#include "mlir/Dialect/SPIRV/IR/SPIRVOps.h"
+#include "mlir/Dialect/SPIRV/Transforms/SPIRVConversion.h"
+#include "mlir/Transforms/DialectConversion.h"
+#include "llvm/ADT/StringRef.h"
+#include <limits>
+
+namespace mlir {
+#define GEN_PASS_DEF_CONVERTPTRTOSPIRVPASS
+#include "mlir/Conversion/Passes.h.inc"
+} // namespace mlir
+
+using namespace mlir;
+
+namespace {
+
+static FailureOr<Type> getAddressType(spirv::TargetEnvAttr targetAttr,
+ MLIRContext *context) {
+ spirv::AddressingModel addressingModel =
+ spirv::getAddressingModel(targetAttr, /*use64bitAddress=*/true);
+ if (addressingModel == spirv::AddressingModel::PhysicalStorageBuffer64)
+ return IntegerType::get(context, 64);
+
+ return failure();
+}
+
+static LogicalResult getMemoryAccessAttrs(std::optional<int64_t> alignment,
+ Builder &builder,
+ spirv::MemoryAccessAttr &accessAttr,
+ IntegerAttr &alignmentAttr) {
+ if (!alignment)
+ return success();
+ if (*alignment > std::numeric_limits<uint32_t>::max())
+ return failure();
+
+ accessAttr = spirv::MemoryAccessAttr::get(builder.getContext(),
+ spirv::MemoryAccess::Aligned);
+ alignmentAttr = builder.getI32IntegerAttr(*alignment);
+ return success();
+}
+
+static LogicalResult checkSupportedPtrLoad(ptr::LoadOp op,
----------------
IgWod wrote:
You can merge this function with the one below by using a template, since other than the type they are identical.
https://github.com/llvm/llvm-project/pull/206159
More information about the Mlir-commits
mailing list