|
| 1 | +//===-- PtrAttrDefs.td - Ptr Attributes definition file ----*- tablegen -*-===// |
| 2 | +// |
| 3 | +// Part of the LLVM Project, 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_ATTRDEFS |
| 10 | +#define PTR_ATTRDEFS |
| 11 | + |
| 12 | +include "mlir/Dialect/Ptr/IR/PtrDialect.td" |
| 13 | +include "mlir/IR/AttrTypeBase.td" |
| 14 | + |
| 15 | +// All of the attributes will extend this class. |
| 16 | +class Ptr_Attr<string name, string attrMnemonic, |
| 17 | + list<Trait> traits = [], |
| 18 | + string baseCppClass = "::mlir::Attribute"> |
| 19 | + : AttrDef<Ptr_Dialect, name, traits, baseCppClass> { |
| 20 | + let mnemonic = attrMnemonic; |
| 21 | +} |
| 22 | + |
| 23 | +//===----------------------------------------------------------------------===// |
| 24 | +// SpecAttr |
| 25 | +//===----------------------------------------------------------------------===// |
| 26 | + |
| 27 | +def Ptr_SpecAttr : Ptr_Attr<"Spec", "spec"> { |
| 28 | + let summary = "ptr data layout spec"; |
| 29 | + let description = [{ |
| 30 | + Defines the data layout spec for a pointer type. This attribute has 4 |
| 31 | + fields: |
| 32 | + - [Required] size: size of the pointer in bits. |
| 33 | + - [Required] abi: ABI-required alignment for the pointer in bits. |
| 34 | + - [Required] preferred: preferred alignment for the pointer in bits. |
| 35 | + - [Optional] index: bitwidth that should be used when performing index |
| 36 | + computations for the type. Setting the field to `kOptionalSpecValue`, means |
| 37 | + the field is optional. |
| 38 | + |
| 39 | + Furthermore, the attribute will verify that all present values are divisible |
| 40 | + by 8 (number of bits in a byte), and that `preferred` > `abi`. |
| 41 | + |
| 42 | + Example: |
| 43 | + ```mlir |
| 44 | + // Spec for a 64 bit ptr, with a required alignment of 64 bits, but with |
| 45 | + // a preferred alignment of 128 bits and an index bitwidth of 64 bits. |
| 46 | + #ptr.spec<size = 64, abi = 64, preferred = 128, index = 64> |
| 47 | + ``` |
| 48 | + }]; |
| 49 | + let parameters = (ins |
| 50 | + "uint32_t":$size, |
| 51 | + "uint32_t":$abi, |
| 52 | + "uint32_t":$preferred, |
| 53 | + DefaultValuedParameter<"uint32_t", "kOptionalSpecValue">:$index |
| 54 | + ); |
| 55 | + let skipDefaultBuilders = 1; |
| 56 | + let builders = [ |
| 57 | + AttrBuilder<(ins "uint32_t":$size, "uint32_t":$abi, "uint32_t":$preferred, |
| 58 | + CArg<"uint32_t", "kOptionalSpecValue">:$index), [{ |
| 59 | + return $_get($_ctxt, size, abi, preferred, index); |
| 60 | + }]> |
| 61 | + ]; |
| 62 | + let assemblyFormat = "`<` struct(params) `>`"; |
| 63 | + let extraClassDeclaration = [{ |
| 64 | + /// Constant for specifying a spec entry is optional. |
| 65 | + static constexpr uint32_t kOptionalSpecValue = std::numeric_limits<uint32_t>::max(); |
| 66 | + }]; |
| 67 | + let genVerifyDecl = 1; |
| 68 | +} |
| 69 | + |
| 70 | +#endif // PTR_ATTRDEFS |
0 commit comments