xref: /llvm-project/mlir/include/mlir/Dialect/Ptr/IR/PtrDialect.td (revision e035ef0e7423c1a4c78e922508da817dbd5b6a02)
1//===- PtrDialect.td - Pointer dialect ---------------------*- tablegen -*-===//
2//
3// This file is licensed under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef PTR_DIALECT
10#define PTR_DIALECT
11
12include "mlir/Interfaces/DataLayoutInterfaces.td"
13include "mlir/IR/AttrTypeBase.td"
14include "mlir/IR/BuiltinTypeInterfaces.td"
15include "mlir/IR/OpBase.td"
16
17//===----------------------------------------------------------------------===//
18// Pointer dialect definition.
19//===----------------------------------------------------------------------===//
20
21def Ptr_Dialect : Dialect {
22  let name = "ptr";
23  let summary = "Pointer dialect";
24  let cppNamespace = "::mlir::ptr";
25  let useDefaultTypePrinterParser = 1;
26  let useDefaultAttributePrinterParser = 1;
27}
28
29//===----------------------------------------------------------------------===//
30// Pointer type definitions
31//===----------------------------------------------------------------------===//
32
33class Ptr_Type<string name, string typeMnemonic, list<Trait> traits = []>
34    : TypeDef<Ptr_Dialect, name, traits> {
35  let mnemonic = typeMnemonic;
36}
37
38def Ptr_PtrType : Ptr_Type<"Ptr", "ptr", [
39    MemRefElementTypeInterface,
40    DeclareTypeInterfaceMethods<DataLayoutTypeInterface, [
41      "areCompatible", "getIndexBitwidth", "verifyEntries"]>
42  ]> {
43  let summary = "pointer type";
44  let description = [{
45    The `ptr` type is an opaque pointer type. This type typically represents a
46    handle to an object in memory or target-dependent values like `nullptr`.
47    Pointers are optionally parameterized by a memory space.
48
49    Syntax:
50
51    ```mlir
52    pointer ::= `ptr` (`<` memory-space `>`)?
53    memory-space ::= attribute-value
54    ```
55  }];
56  let parameters = (ins OptionalParameter<"Attribute">:$memorySpace);
57  let assemblyFormat = "(`<` $memorySpace^ `>`)?";
58  let builders = [
59    TypeBuilder<(ins CArg<"Attribute", "nullptr">:$memorySpace), [{
60      return $_get($_ctxt, memorySpace);
61    }]>
62  ];
63  let skipDefaultBuilders = 1;
64}
65
66//===----------------------------------------------------------------------===//
67// Base address operation definition.
68//===----------------------------------------------------------------------===//
69
70class Pointer_Op<string mnemonic, list<Trait> traits = []> :
71        Op<Ptr_Dialect, mnemonic, traits>;
72
73#endif // PTR_DIALECT
74