[Mlir-commits] [mlir] [mlir][Ptr] Init the Ptr dialect with the `!ptr.ptr` type. (PR #86860)
Christian Ulmann
llvmlistbot at llvm.org
Fri Mar 29 02:21:46 PDT 2024
================
@@ -0,0 +1,83 @@
+//===- PtrDialect.td - Pointer dialect ---------------------*- tablegen -*-===//
+//
+// This file is licensed 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
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef PTR_DIALECT
+#define PTR_DIALECT
+
+include "mlir/Interfaces/DataLayoutInterfaces.td"
+include "mlir/IR/AttrTypeBase.td"
+include "mlir/IR/BuiltinTypeInterfaces.td"
+include "mlir/IR/OpBase.td"
+
+//===----------------------------------------------------------------------===//
+// Pointer dialect definition.
+//===----------------------------------------------------------------------===//
+
+def Ptr_Dialect : Dialect {
+ let name = "ptr";
+ let summary = "Pointer dialect";
+ let cppNamespace = "::mlir::ptr";
+ let useDefaultTypePrinterParser = 1;
+ let useDefaultAttributePrinterParser = 0;
+}
+
+//===----------------------------------------------------------------------===//
+// Pointer type definitions
+//===----------------------------------------------------------------------===//
+
+class Ptr_Type<string name, string typeMnemonic, list<Trait> traits = []>
+ : TypeDef<Ptr_Dialect, name, traits> {
+ let mnemonic = typeMnemonic;
+}
+
+def Ptr_PtrType : Ptr_Type<"Ptr", "ptr", [
+ MemRefElementTypeInterface,
+ DeclareTypeInterfaceMethods<DataLayoutTypeInterface, [
+ "areCompatible", "getIndexBitwidth", "verifyEntries"]>
+ ]> {
+ let summary = "pointer type";
+ let description = [{
+ The `ptr` type is an opaque pointer type. This type typically represents
+ a reference to an object in memory. Pointers are optionally parameterized
+ by a memory space.
+ Syntax:
+
+ ```mlir
+ pointer ::= `ptr` (`<` memory-space `>`)?
+ memory-space ::= attribute-value
+ ```
+ }];
+ let parameters = (ins OptionalParameter<"Attribute">:$memorySpace);
+ let assemblyFormat = "(`<` $memorySpace^ `>`)?";
+ let builders = [
+ TypeBuilder<(ins CArg<"Attribute", "nullptr">:$addressSpace), [{
+ return $_get($_ctxt, addressSpace);
+ }]>,
+ TypeBuilder<(ins CArg<"unsigned">:$addressSpace), [{
+ return $_get($_ctxt, IntegerAttr::get(IntegerType::get($_ctxt, 32),
+ addressSpace));
+ }]>
+ ];
+ let skipDefaultBuilders = 1;
+ let extraClassDeclaration = [{
+ /// Returns the default memory space.
+ Attribute getDefaultMemorySpace() const;
+
+ /// Returns the memory space as an unsigned number.
+ int64_t getAddressSpace() const;
----------------
Dinistro wrote:
Should this be a ` uint64_t` then? What is expected to happen when the "memory space" is a non-integer attribute? Does it just return the default address space then?
https://github.com/llvm/llvm-project/pull/86860
More information about the Mlir-commits
mailing list