//===-- PtrAttrDefs.td - Ptr Attributes definition file ----*- tablegen -*-===// // // 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 // //===----------------------------------------------------------------------===// #ifndef PTR_ATTRDEFS #define PTR_ATTRDEFS include "mlir/Dialect/Ptr/IR/PtrDialect.td" include "mlir/Dialect/Ptr/IR/MemorySpaceInterfaces.td" include "mlir/IR/AttrTypeBase.td" include "mlir/IR/BuiltinAttributeInterfaces.td" // All of the attributes will extend this class. class Ptr_Attr traits = [], string baseCppClass = "::mlir::Attribute"> : AttrDef { let mnemonic = attrMnemonic; } //===----------------------------------------------------------------------===// // AddressAttr //===----------------------------------------------------------------------===// def Ptr_AddressAttr : Ptr_Attr<"Address", "address", [ DeclareAttrInterfaceMethods ]> { let summary = "Address attribute"; let description = [{ The `address` attribute represents a raw memory address, expressed in bytes. Example: ```mlir #ptr.address<0x1000> : !ptr.ptr<#ptr.generic_space> ``` }]; let parameters = (ins AttributeSelfTypeParameter<"", "PtrType">:$type, APIntParameter<"">:$value); let builders = [ AttrBuilderWithInferredContext<(ins "PtrType":$type, "const llvm::APInt &":$value), [{ return $_get(type.getContext(), type, value); }]> ]; let assemblyFormat = "`<` $value `>`"; } //===----------------------------------------------------------------------===// // GenericSpaceAttr //===----------------------------------------------------------------------===// def Ptr_GenericSpaceAttr : Ptr_Attr<"GenericSpace", "generic_space", [ DeclareAttrInterfaceMethods ]> { let summary = "Generic memory space"; let description = [{ The `generic_space` attribute defines a memory space attribute with the following properties: - Load and store operations are always valid, regardless of the type. - Atomic operations are always valid, regardless of the type. - Cast operations to `generic_space` are always valid. Example: ```mlir #ptr.generic_space : !ptr.ptr<#ptr.generic_space> ``` }]; let assemblyFormat = ""; } //===----------------------------------------------------------------------===// // NullAttr //===----------------------------------------------------------------------===// def Ptr_NullAttr : Ptr_Attr<"Null", "null", [ DeclareAttrInterfaceMethods ]> { let summary = "Null pointer attribute"; let description = [{ The `null` attribute represents a null pointer. Example: ```mlir #ptr.null ``` }]; let parameters = (ins AttributeSelfTypeParameter<"", "PtrType">:$type); let builders = [ AttrBuilderWithInferredContext<(ins "PtrType":$type), [{ return $_get(type.getContext(), type); }]> ]; let assemblyFormat = ""; } //===----------------------------------------------------------------------===// // SpecAttr //===----------------------------------------------------------------------===// def Ptr_SpecAttr : Ptr_Attr<"Spec", "spec"> { let summary = "ptr data layout spec"; let description = [{ Defines the data layout spec for a pointer type. This attribute has 4 fields: - [Required] size: size of the pointer in bits. - [Required] abi: ABI-required alignment for the pointer in bits. - [Required] preferred: preferred alignment for the pointer in bits. - [Optional] index: bitwidth that should be used when performing index computations for the type. Setting the field to `kOptionalSpecValue`, means the field is optional. Furthermore, the attribute will verify that all present values are divisible by 8 (number of bits in a byte), and that `preferred` > `abi`. Example: ```mlir // Spec for a 64 bit ptr, with a required alignment of 64 bits, but with // a preferred alignment of 128 bits and an index bitwidth of 64 bits. #ptr.spec ``` }]; let parameters = (ins "uint32_t":$size, "uint32_t":$abi, "uint32_t":$preferred, DefaultValuedParameter<"uint32_t", "kOptionalSpecValue">:$index ); let skipDefaultBuilders = 1; let builders = [ AttrBuilder<(ins "uint32_t":$size, "uint32_t":$abi, "uint32_t":$preferred, CArg<"uint32_t", "kOptionalSpecValue">:$index), [{ return $_get($_ctxt, size, abi, preferred, index); }]> ]; let assemblyFormat = "`<` struct(params) `>`"; let extraClassDeclaration = [{ /// Constant for specifying a spec entry is optional. static constexpr uint32_t kOptionalSpecValue = std::numeric_limits::max(); }]; let genVerifyDecl = 1; } #endif // PTR_ATTRDEFS