| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,292 @@ | ||
| //===-- 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/IR/AttrTypeBase.td" | ||
|
|
||
| // All of the attributes will extend this class. | ||
| class Ptr_Attr<string name, string attrMnemonic, | ||
| list<Trait> traits = [], | ||
| string baseCppClass = "::mlir::Attribute"> | ||
| : AttrDef<Ptr_Dialect, name, traits, baseCppClass> { | ||
| let mnemonic = attrMnemonic; | ||
| } | ||
|
|
||
| //===----------------------------------------------------------------------===// | ||
| // AliasScopeDomainAttr | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| def Ptr_AliasScopeDomainAttr : Ptr_Attr<"AliasScopeDomain", | ||
| "alias_scope_domain"> { | ||
| let parameters = (ins | ||
| "DistinctAttr":$id, | ||
| OptionalParameter<"StringAttr">:$description | ||
| ); | ||
|
|
||
| let builders = [ | ||
| AttrBuilder<(ins CArg<"StringAttr", "{}">:$description), [{ | ||
| return $_get($_ctxt, | ||
| DistinctAttr::create(UnitAttr::get($_ctxt)), description); | ||
| }]> | ||
| ]; | ||
|
|
||
| let summary = "Ptr dialect alias scope domain metadata"; | ||
|
|
||
| let description = [{ | ||
| Defines a domain that may be associated with an alias scope. | ||
|
|
||
| See the following link for more details: | ||
| https://llvm.org/docs/LangRef.html#noalias-and-alias-scope-metadata | ||
| }]; | ||
|
|
||
| let assemblyFormat = "`<` struct(params) `>`"; | ||
| } | ||
|
|
||
| //===----------------------------------------------------------------------===// | ||
| // AliasScopeAttr | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| def Ptr_AliasScopeAttr : Ptr_Attr<"AliasScope", "alias_scope"> { | ||
| let parameters = (ins | ||
| "DistinctAttr":$id, | ||
| "AliasScopeDomainAttr":$domain, | ||
| OptionalParameter<"StringAttr">:$description | ||
| ); | ||
|
|
||
| let builders = [ | ||
| AttrBuilderWithInferredContext<(ins | ||
| "AliasScopeDomainAttr":$domain, | ||
| CArg<"StringAttr", "{}">:$description | ||
| ), [{ | ||
| MLIRContext *ctx = domain.getContext(); | ||
| return $_get(ctx, DistinctAttr::create(UnitAttr::get(ctx)), domain, description); | ||
| }]> | ||
| ]; | ||
|
|
||
| let description = [{ | ||
| Defines an alias scope that can be attached to a memory-accessing operation. | ||
| Such scopes can be used in combination with `noalias` metadata to indicate | ||
| that sets of memory-affecting operations in one scope do not alias with | ||
| memory-affecting operations in another scope. | ||
|
|
||
| Example: | ||
| ```mlir | ||
| #domain = #ptr.alias_scope_domain<id = distinct[1]<>, description = "Optional domain description"> | ||
| #scope1 = #ptr.alias_scope<id = distinct[2]<>, domain = #domain> | ||
| #scope2 = #ptr.alias_scope<id = distinct[3]<>, domain = #domain, description = "Optional scope description"> | ||
| ptr.func @foo(%ptr1 : !ptr.ptr) { | ||
| %c0 = llvm.mlir.constant(0 : i32) : i32 | ||
| %c4 = llvm.mlir.constant(4 : i32) : i32 | ||
| %1 = ptr.ptrtoint %ptr1 : !ptr.ptr to i32 | ||
| %2 = llvm.add %1, %c1 : i32 | ||
| %ptr2 = ptr.inttoptr %2 : i32 to !ptr.ptr | ||
| ptr.store %c0, %ptr1 { alias_scopes = [#scope1], ptr.noalias = [#scope2] } : i32, !ptr.ptr | ||
| ptr.store %c4, %ptr2 { alias_scopes = [#scope2], ptr.noalias = [#scope1] } : i32, !ptr.ptr | ||
| llvm.return | ||
| } | ||
| ``` | ||
|
|
||
| See the following link for more details: | ||
| https://llvm.org/docs/LangRef.html#noalias-and-alias-scope-metadata | ||
| }]; | ||
|
|
||
| let summary = "Ptr dialect alias scope"; | ||
|
|
||
| let assemblyFormat = "`<` struct(params) `>`"; | ||
| } | ||
|
|
||
| def Ptr_AliasScopeArrayAttr | ||
| : TypedArrayAttrBase<Ptr_AliasScopeAttr, | ||
| Ptr_AliasScopeAttr.summary # " array"> { | ||
| let constBuilderCall = ?; | ||
| } | ||
|
|
||
| //===----------------------------------------------------------------------===// | ||
| // AccessGroupAttr | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| def Ptr_AccessGroupAttr : Ptr_Attr<"AccessGroup", "access_group"> { | ||
|
|
||
| let parameters = (ins "DistinctAttr":$id); | ||
|
|
||
| let builders = [ | ||
| AttrBuilder<(ins), [{ | ||
| return $_get($_ctxt, DistinctAttr::create(UnitAttr::get($_ctxt))); | ||
| }]> | ||
| ]; | ||
|
|
||
| let summary = "Ptr dialect access group metadata"; | ||
|
|
||
| let description = [{ | ||
| Defines an access group metadata that can be set on any instruction | ||
| that potentially accesses memory via the `AccessGroupOpInterface` or on | ||
| branch instructions in the loop latch block via the `parallelAccesses` | ||
| parameter of `LLVM::LoopAnnotationAttr`. | ||
|
|
||
| See the following link for more details: | ||
| https://llvm.org/docs/LangRef.html#llvm-access-group-metadata | ||
| }]; | ||
|
|
||
| let assemblyFormat = "`<` struct(params) `>`"; | ||
| } | ||
|
|
||
| def Ptr_AccessGroupArrayAttr | ||
| : TypedArrayAttrBase<Ptr_AccessGroupAttr, | ||
| Ptr_AccessGroupAttr.summary # " array"> { | ||
| let constBuilderCall = ?; | ||
| } | ||
|
|
||
| //===----------------------------------------------------------------------===// | ||
| // TBAARootAttr | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| def Ptr_TBAARootAttr : Ptr_Attr<"TBAARoot", "tbaa_root", [], "TBAANodeAttr"> { | ||
| let parameters = (ins OptionalParameter<"StringAttr">:$id); | ||
|
|
||
| let summary = "Ptr dialect TBAA root metadata"; | ||
| let description = [{ | ||
| Defines a TBAA root node. | ||
|
|
||
| Example: | ||
| ```mlir | ||
| #cpp_root = #ptr.tbaa_root<identity = "Simple C/C++ TBAA"> | ||
| #other_root = #ptr.tbaa_root | ||
| ``` | ||
|
|
||
| See the following link for more details: | ||
| https://llvm.org/docs/LangRef.html#tbaa-metadata | ||
| }]; | ||
|
|
||
| let assemblyFormat = "(`<` struct(params)^ `>`)?"; | ||
| } | ||
|
|
||
| //===----------------------------------------------------------------------===// | ||
| // TBAATypeDescriptorAttr | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| def Ptr_TBAAMemberAttr : Ptr_Attr<"TBAAMember", "tbaa_member"> { | ||
| let parameters = (ins | ||
| "TBAANodeAttr":$typeDesc, | ||
| "int64_t":$offset | ||
| ); | ||
|
|
||
| let builders = [ | ||
| AttrBuilderWithInferredContext<(ins "TBAANodeAttr":$typeDesc, | ||
| "int64_t":$offset), [{ | ||
| return $_get(typeDesc.getContext(), typeDesc, offset); | ||
| }]> | ||
| ]; | ||
|
|
||
| let assemblyFormat = "`<` params `>`"; | ||
| } | ||
|
|
||
| def Ptr_TBAAMemberAttrArray : ArrayRefParameter<"TBAAMemberAttr"> { | ||
| let printer = [{ | ||
| $_printer << '{'; | ||
| llvm::interleaveComma($_self, $_printer, [&](TBAAMemberAttr attr) { | ||
| $_printer.printStrippedAttrOrType(attr); | ||
| }); | ||
| $_printer << '}'; | ||
| }]; | ||
|
|
||
| let parser = [{ | ||
| [&]() -> FailureOr<SmallVector<TBAAMemberAttr>> { | ||
| using Result = SmallVector<TBAAMemberAttr>; | ||
| if ($_parser.parseLBrace()) | ||
| return failure(); | ||
| FailureOr<Result> result = FieldParser<Result>::parse($_parser); | ||
| if (failed(result)) | ||
| return failure(); | ||
| if ($_parser.parseRBrace()) | ||
| return failure(); | ||
| return result; | ||
| }() | ||
| }]; | ||
| } | ||
|
|
||
| def Ptr_TBAATypeDescriptorAttr : Ptr_Attr<"TBAATypeDescriptor", | ||
| "tbaa_type_desc", [], "TBAANodeAttr"> { | ||
| let parameters = (ins | ||
| StringRefParameter<>:$id, | ||
| Ptr_TBAAMemberAttrArray:$members | ||
| ); | ||
|
|
||
| let summary = "Ptr dialect TBAA type metadata"; | ||
|
|
||
| let description = [{ | ||
| Defines a TBAA node describing a type. | ||
|
|
||
| Example: | ||
| ```mlir | ||
| #tbaa_root = #ptr.tbaa_root<identity = "Simple C/C++ TBAA"> | ||
| #tbaa_type_desc1 = #ptr.tbaa_type_desc<id = "omnipotent char", members = {<#tbaa_root, 0>}> | ||
| #tbaa_type_desc2 = #ptr.tbaa_type_desc<id = "long long", members = {<#tbaa_root, 0>}> | ||
| #tbaa_type_desc3 = #ptr.tbaa_type_desc<id = "agg2_t", members = {<#tbaa_type_desc2, 0>, <#tbaa_type_desc2, 8>}> | ||
| #tbaa_type_desc4 = #ptr.tbaa_type_desc<id = "int", members = {<#tbaa_type_desc1, 0>}> | ||
| #tbaa_type_desc5 = #ptr.tbaa_type_desc<id = "agg1_t", members = {<#tbaa_type_desc4, 0>, <#tbaa_type_desc4, 4>}> | ||
| ``` | ||
|
|
||
| See the following link for more details: | ||
| https://llvm.org/docs/LangRef.html#tbaa-metadata | ||
| }]; | ||
|
|
||
| let assemblyFormat = "`<` struct(params) `>`"; | ||
| } | ||
|
|
||
| //===----------------------------------------------------------------------===// | ||
| // TBAATagAttr | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| def Ptr_TBAATagAttr : Ptr_Attr<"TBAATag", "tbaa_tag"> { | ||
| let parameters = (ins | ||
| "TBAATypeDescriptorAttr":$base_type, | ||
| "TBAATypeDescriptorAttr":$access_type, | ||
| "int64_t":$offset, | ||
| DefaultValuedParameter<"bool", "false">:$constant | ||
| ); | ||
|
|
||
| let builders = [ | ||
| AttrBuilderWithInferredContext<(ins "TBAATypeDescriptorAttr":$baseType, | ||
| "TBAATypeDescriptorAttr":$accessType, | ||
| "int64_t":$offset), [{ | ||
| return $_get(baseType.getContext(), baseType, accessType, offset, | ||
| /*constant=*/false); | ||
| }]> | ||
| ]; | ||
|
|
||
| let summary = "Ptr dialect TBAA tag metadata"; | ||
|
|
||
| let description = [{ | ||
| Defines a TBAA node describing a memory access. | ||
|
|
||
| Example: | ||
| ```mlir | ||
| #tbaa_root = #ptr.tbaa_root<identity = "Simple C/C++ TBAA"> | ||
| #tbaa_type_desc1 = #ptr.tbaa_type_desc<id = "omnipotent char", members = {<#tbaa_root, 0>}> | ||
| #tbaa_type_desc2 = #ptr.tbaa_type_desc<id = "int", members = {<#tbaa_type_desc1, 0>}> | ||
| #tbaa_type_desc3 = #ptr.tbaa_type_desc<id = "agg1_t", members = {<#tbaa_type_desc4, 0>, <#tbaa_type_desc4, 4>}> | ||
| #tbaa_tag = #ptr.tbaa_tag<base_type = #tbaa_type_desc3, access_type = #tbaa_type_desc2, offset = 0, constant = true> | ||
| ``` | ||
|
|
||
| See the following link for more details: | ||
| https://llvm.org/docs/LangRef.html#tbaa-metadata | ||
| }]; | ||
|
|
||
| let assemblyFormat = "`<` struct(params) `>`"; | ||
| } | ||
|
|
||
| def Ptr_TBAATagArrayAttr | ||
| : TypedArrayAttrBase<Ptr_TBAATagAttr, | ||
| Ptr_TBAATagAttr.summary # " array"> { | ||
| let constBuilderCall = ?; | ||
| } | ||
|
|
||
| #endif // PTR_ATTRDEFS |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| //===- PointerDialect.h - Pointer dialect -----------------------*- C++ -*-===// | ||
| // | ||
| // 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 | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // This file defines the Ptr dialect. | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #ifndef MLIR_DIALECT_PTR_IR_PTRDIALECT_H | ||
| #define MLIR_DIALECT_PTR_IR_PTRDIALECT_H | ||
|
|
||
| #include "mlir/IR/Dialect.h" | ||
|
|
||
| #include "mlir/Dialect/Ptr/IR/PtrOpsDialect.h.inc" | ||
|
|
||
| #endif // MLIR_DIALECT_PTR_IR_PTRDIALECT_H |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| //===- PointerDialect.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/AsmInterfaces.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 = 1; | ||
| } | ||
|
|
||
| //===----------------------------------------------------------------------===// | ||
| // 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"]>, | ||
| DeclareTypeInterfaceMethods<TypeAsmAliasTypeInterface, [ | ||
| "getAliasDialect"]> | ||
| ]> { | ||
| 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; | ||
|
|
||
| /// Returns the memory space attribute wrapped in the `MemoryModel` class. | ||
| MemoryModel getMemoryModel() const; | ||
| }]; | ||
| } | ||
|
|
||
| //===----------------------------------------------------------------------===// | ||
| // Base address operation definition. | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| class Pointer_Op<string mnemonic, list<Trait> traits = []> : | ||
| Op<Ptr_Dialect, mnemonic, traits>; | ||
|
|
||
| #endif // PTR_DIALECT |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| //===-- PtrEnums.td - Ptr dialect enumerations -------------*- 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_ENUMS | ||
| #define PTR_ENUMS | ||
|
|
||
| include "mlir/IR/EnumAttr.td" | ||
|
|
||
| //===----------------------------------------------------------------------===// | ||
| // Atomic binary op enum attribute | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| def AtomicBinOpXchg : I64EnumAttrCase<"xchg", 0, "xchg">; | ||
| def AtomicBinOpAdd : I64EnumAttrCase<"add", 1, "add">; | ||
| def AtomicBinOpSub : I64EnumAttrCase<"sub", 2, "sub">; | ||
| def AtomicBinOpAnd : I64EnumAttrCase<"_and", 3, "_and">; | ||
| def AtomicBinOpNand : I64EnumAttrCase<"nand", 4, "nand">; | ||
| def AtomicBinOpOr : I64EnumAttrCase<"_or", 5, "_or">; | ||
| def AtomicBinOpXor : I64EnumAttrCase<"_xor", 6, "_xor">; | ||
| def AtomicBinOpMax : I64EnumAttrCase<"max", 7, "max">; | ||
| def AtomicBinOpMin : I64EnumAttrCase<"min", 8, "min">; | ||
| def AtomicBinOpUMax : I64EnumAttrCase<"umax", 9, "umax">; | ||
| def AtomicBinOpUMin : I64EnumAttrCase<"umin", 10, "umin">; | ||
| def AtomicBinOpFAdd : I64EnumAttrCase<"fadd", 11, "fadd">; | ||
| def AtomicBinOpFSub : I64EnumAttrCase<"fsub", 12, "fsub">; | ||
| def AtomicBinOpFMax : I64EnumAttrCase<"fmax", 13, "fmax">; | ||
| def AtomicBinOpFMin : I64EnumAttrCase<"fmin", 14, "fmin">; | ||
| def AtomicBinOpUIncWrap : I64EnumAttrCase<"uinc_wrap", 15, "uinc_wrap">; | ||
| def AtomicBinOpUDecWrap : I64EnumAttrCase<"udec_wrap", 16, "udec_wrap">; | ||
|
|
||
| def AtomicBinOp : I64EnumAttr< | ||
| "AtomicBinOp", | ||
| "ptr.atomicrmw binary operations", | ||
| [AtomicBinOpXchg, AtomicBinOpAdd, AtomicBinOpSub, AtomicBinOpAnd, | ||
| AtomicBinOpNand, AtomicBinOpOr, AtomicBinOpXor, AtomicBinOpMax, | ||
| AtomicBinOpMin, AtomicBinOpUMax, AtomicBinOpUMin, AtomicBinOpFAdd, | ||
| AtomicBinOpFSub, AtomicBinOpFMax, AtomicBinOpFMin, AtomicBinOpUIncWrap, | ||
| AtomicBinOpUDecWrap]> { | ||
| let cppNamespace = "::mlir::ptr"; | ||
| } | ||
|
|
||
| //===----------------------------------------------------------------------===// | ||
| // Atomic ordering enum attribute | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| def AtomicOrderingNotAtomic : I64EnumAttrCase<"not_atomic", 0, "not_atomic">; | ||
| def AtomicOrderingUnordered : I64EnumAttrCase<"unordered", 1, "unordered">; | ||
| def AtomicOrderingMonotonic : I64EnumAttrCase<"monotonic", 2, "monotonic">; | ||
| def AtomicOrderingAcquire : I64EnumAttrCase<"acquire", 3, "acquire">; | ||
| def AtomicOrderingRelease : I64EnumAttrCase<"release", 4, "release">; | ||
| def AtomicOrderingAcqRel : I64EnumAttrCase<"acq_rel", 5, "acq_rel">; | ||
| def AtomicOrderingSeqCst : I64EnumAttrCase<"seq_cst", 6, "seq_cst">; | ||
|
|
||
| def AtomicOrdering : I64EnumAttr< | ||
| "AtomicOrdering", | ||
| "Atomic ordering for LLVM's memory model", | ||
| [AtomicOrderingNotAtomic, AtomicOrderingUnordered, AtomicOrderingMonotonic, | ||
| AtomicOrderingAcquire, AtomicOrderingRelease, AtomicOrderingAcqRel, | ||
| AtomicOrderingSeqCst | ||
| ]> { | ||
| let cppNamespace = "::mlir::ptr"; | ||
| } | ||
|
|
||
| #endif // PTR_ENUMS |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| //===- PtrInterfaces.h - Ptr Interfaces -------------------------*- C++ -*-===// | ||
| // | ||
| // 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 | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // This file defines op interfaces for the Ptr dialect in MLIR. | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #ifndef MLIR_DIALECT_PTR_IR_PTRINTERFACES_H | ||
| #define MLIR_DIALECT_PTR_IR_PTRINTERFACES_H | ||
|
|
||
| #include "mlir/Dialect/Ptr/IR/PtrAttrs.h" | ||
|
|
||
| namespace mlir { | ||
| namespace ptr { | ||
| namespace detail { | ||
| /// Verifies the access groups attribute of memory operations that implement the | ||
| /// access group interface. | ||
| LogicalResult verifyAccessGroupOpInterface(Operation *op); | ||
|
|
||
| /// Verifies the alias analysis attributes of memory operations that implement | ||
| /// the alias analysis interface. | ||
| LogicalResult verifyAliasAnalysisOpInterface(Operation *op); | ||
| } // namespace detail | ||
| } // namespace ptr | ||
| } // namespace mlir | ||
|
|
||
| #include "mlir/Dialect/Ptr/IR/PtrInterfaces.h.inc" | ||
|
|
||
| #endif // MLIR_DIALECT_PTR_IR_PTRINTERFACES_H |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,152 @@ | ||
| //===-- PtrInterfaces.td - Ptr dialect interfaces ----------*- 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 | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // This file defines ptr dialect interfaces. | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #ifndef PTR_INTERFACES | ||
| #define PTR_INTERFACES | ||
|
|
||
| include "mlir/IR/OpBase.td" | ||
|
|
||
| //===----------------------------------------------------------------------===// | ||
| // Access group interface. | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| def AccessGroupOpInterface : OpInterface<"AccessGroupOpInterface"> { | ||
| let description = [{ | ||
| An interface for memory operations that can carry access groups metadata. | ||
| It provides setters and getters for the operation's access groups attribute. | ||
| The default implementations of the interface methods expect the operation | ||
| to have an attribute of type ArrayAttr named access_groups. | ||
| }]; | ||
|
|
||
| let cppNamespace = "::mlir::ptr"; | ||
| let verify = [{ return detail::verifyAccessGroupOpInterface($_op); }]; | ||
|
|
||
| let methods = [ | ||
| InterfaceMethod< | ||
| /*desc=*/ "Returns the access groups attribute or nullptr", | ||
| /*returnType=*/ "ArrayAttr", | ||
| /*methodName=*/ "getAccessGroupsOrNull", | ||
| /*args=*/ (ins), | ||
| /*methodBody=*/ [{}], | ||
| /*defaultImpl=*/ [{ | ||
| auto op = cast<ConcreteOp>(this->getOperation()); | ||
| return op.getAccessGroupsAttr(); | ||
| }] | ||
| >, | ||
| InterfaceMethod< | ||
| /*desc=*/ "Sets the access groups attribute", | ||
| /*returnType=*/ "void", | ||
| /*methodName=*/ "setAccessGroups", | ||
| /*args=*/ (ins "const ArrayAttr":$attr), | ||
| /*methodBody=*/ [{}], | ||
| /*defaultImpl=*/ [{ | ||
| auto op = cast<ConcreteOp>(this->getOperation()); | ||
| op.setAccessGroupsAttr(attr); | ||
| }] | ||
| > | ||
| ]; | ||
| } | ||
|
|
||
| //===----------------------------------------------------------------------===// | ||
| // Alias analysis interface. | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| def AliasAnalysisOpInterface : OpInterface<"AliasAnalysisOpInterface"> { | ||
| let description = [{ | ||
| An interface for memory operations that can carry alias analysis metadata. | ||
| It provides setters and getters for the operation's alias analysis | ||
| attributes. The default implementations of the interface methods expect | ||
| the operation to have attributes of type ArrayAttr named alias_scopes, | ||
| noalias_scopes, and tbaa. | ||
| }]; | ||
|
|
||
| let cppNamespace = "::mlir::ptr"; | ||
| let verify = [{ return detail::verifyAliasAnalysisOpInterface($_op); }]; | ||
|
|
||
| let methods = [ | ||
| InterfaceMethod< | ||
| /*desc=*/ "Returns the alias scopes attribute or nullptr", | ||
| /*returnType=*/ "ArrayAttr", | ||
| /*methodName=*/ "getAliasScopesOrNull", | ||
| /*args=*/ (ins), | ||
| /*methodBody=*/ [{}], | ||
| /*defaultImpl=*/ [{ | ||
| auto op = cast<ConcreteOp>(this->getOperation()); | ||
| return op.getAliasScopesAttr(); | ||
| }] | ||
| >, | ||
| InterfaceMethod< | ||
| /*desc=*/ "Sets the alias scopes attribute", | ||
| /*returnType=*/ "void", | ||
| /*methodName=*/ "setAliasScopes", | ||
| /*args=*/ (ins "const ArrayAttr":$attr), | ||
| /*methodBody=*/ [{}], | ||
| /*defaultImpl=*/ [{ | ||
| auto op = cast<ConcreteOp>(this->getOperation()); | ||
| op.setAliasScopesAttr(attr); | ||
| }] | ||
| >, | ||
| InterfaceMethod< | ||
| /*desc=*/ "Returns the noalias scopes attribute or nullptr", | ||
| /*returnType=*/ "ArrayAttr", | ||
| /*methodName=*/ "getNoAliasScopesOrNull", | ||
| /*args=*/ (ins), | ||
| /*methodBody=*/ [{}], | ||
| /*defaultImpl=*/ [{ | ||
| auto op = cast<ConcreteOp>(this->getOperation()); | ||
| return op.getNoaliasScopesAttr(); | ||
| }] | ||
| >, | ||
| InterfaceMethod< | ||
| /*desc=*/ "Sets the noalias scopes attribute", | ||
| /*returnType=*/ "void", | ||
| /*methodName=*/ "setNoAliasScopes", | ||
| /*args=*/ (ins "const ArrayAttr":$attr), | ||
| /*methodBody=*/ [{}], | ||
| /*defaultImpl=*/ [{ | ||
| auto op = cast<ConcreteOp>(this->getOperation()); | ||
| op.setNoaliasScopesAttr(attr); | ||
| }] | ||
| >, | ||
| InterfaceMethod< | ||
| /*desc=*/ "Returns the tbaa attribute or nullptr", | ||
| /*returnType=*/ "ArrayAttr", | ||
| /*methodName=*/ "getTBAATagsOrNull", | ||
| /*args=*/ (ins), | ||
| /*methodBody=*/ [{}], | ||
| /*defaultImpl=*/ [{ | ||
| auto op = cast<ConcreteOp>(this->getOperation()); | ||
| return op.getTbaaAttr(); | ||
| }] | ||
| >, | ||
| InterfaceMethod< | ||
| /*desc=*/ "Sets the tbaa attribute", | ||
| /*returnType=*/ "void", | ||
| /*methodName=*/ "setTBAATags", | ||
| /*args=*/ (ins "const ArrayAttr":$attr), | ||
| /*methodBody=*/ [{}], | ||
| /*defaultImpl=*/ [{ | ||
| auto op = cast<ConcreteOp>(this->getOperation()); | ||
| op.setTbaaAttr(attr); | ||
| }] | ||
| >, | ||
| InterfaceMethod< | ||
| /*desc=*/ "Returns a list of all pointer operands accessed by the " | ||
| "operation", | ||
| /*returnType=*/ "::llvm::SmallVector<::mlir::Value>", | ||
| /*methodName=*/ "getAccessedOperands", | ||
| /*args=*/ (ins) | ||
| > | ||
| ]; | ||
| } | ||
|
|
||
| #endif // PTR_MEMORYSPACEINTERFACES |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| //===- PointerDialect.h - Pointer dialect -----------------------*- C++ -*-===// | ||
| // | ||
| // 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 | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // This file defines the Pointer dialect. | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #ifndef MLIR_DIALECT_PTR_IR_PTROPS_H | ||
| #define MLIR_DIALECT_PTR_IR_PTROPS_H | ||
|
|
||
| #include "mlir/Bytecode/BytecodeOpInterface.h" | ||
| #include "mlir/Dialect/Ptr/IR/PtrAttrs.h" | ||
| #include "mlir/Dialect/Ptr/IR/PtrDialect.h" | ||
| #include "mlir/Dialect/Ptr/IR/PtrInterfaces.h" | ||
| #include "mlir/Dialect/Ptr/IR/PtrTypes.h" | ||
| #include "mlir/IR/OpDefinition.h" | ||
| #include "mlir/Interfaces/MemorySlotInterfaces.h" | ||
| #include "mlir/Interfaces/SideEffectInterfaces.h" | ||
|
|
||
| #define GET_OP_CLASSES | ||
| #include "mlir/Dialect/Ptr/IR/PtrOps.h.inc" | ||
|
|
||
| #endif // MLIR_DIALECT_PTR_IR_PTROPS_H |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| //===- PointerTypes.h - Pointer types ---------------------------*- C++ -*-===// | ||
| // | ||
| // 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 | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // This file defines the Pointer dialect types. | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #ifndef MLIR_DIALECT_PTR_IR_PTRTYPES_H | ||
| #define MLIR_DIALECT_PTR_IR_PTRTYPES_H | ||
|
|
||
| #include "mlir/Dialect/Ptr/IR/MemoryModel.h" | ||
| #include "mlir/IR/AsmInterfaces.h" | ||
| #include "mlir/IR/Types.h" | ||
| #include "mlir/Interfaces/DataLayoutInterfaces.h" | ||
|
|
||
| namespace mlir { | ||
| namespace ptr { | ||
| /// The positions of different values in the data layout entry for pointers. | ||
| enum class PtrDLEntryPos { Size = 0, Abi = 1, Preferred = 2, Index = 3 }; | ||
|
|
||
| /// Returns the value that corresponds to named position `pos` from the | ||
| /// data layout entry `attr` assuming it's a dense integer elements attribute. | ||
| /// Returns `std::nullopt` if `pos` is not present in the entry. | ||
| /// Currently only `PtrDLEntryPos::Index` is optional, and all other positions | ||
| /// may be assumed to be present. | ||
| std::optional<uint64_t> extractPointerSpecValue(Attribute attr, | ||
| PtrDLEntryPos pos); | ||
| } // namespace ptr | ||
| } // namespace mlir | ||
|
|
||
| #define GET_TYPEDEF_CLASSES | ||
| #include "mlir/Dialect/Ptr/IR/PtrOpsTypes.h.inc" | ||
|
|
||
| #endif // MLIR_DIALECT_PTR_IR_PTRTYPES_H |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| //===- AsmInterfaces.h - Asm Interfaces -------------------------*- C++ -*-===// | ||
| // | ||
| // 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 MLIR_IR_ASMINTERFACES_H | ||
| #define MLIR_IR_ASMINTERFACES_H | ||
|
|
||
| #include "mlir/IR/Attributes.h" | ||
| #include "mlir/IR/Types.h" | ||
|
|
||
| #include "mlir/IR/AsmAttrInterfaces.h.inc" | ||
|
|
||
| #include "mlir/IR/AsmTypeInterfaces.h.inc" | ||
|
|
||
| #endif // MLIR_IR_ASMINTERFACES_H |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| //===- AsmInterfaces.td - Asm Interfaces -------------------*- 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 | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // This file contains interfaces and other utilities for interacting with the | ||
| // AsmParser and AsmPrinter. | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #ifndef MLIR_IR_ASMINTERFACES_TD | ||
| #define MLIR_IR_ASMINTERFACES_TD | ||
|
|
||
| include "mlir/IR/AttrTypeBase.td" | ||
| include "mlir/IR/OpBase.td" | ||
|
|
||
| //===----------------------------------------------------------------------===// | ||
| // AttrAsmAliasAttrInterface | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| def AttrAsmAliasAttrInterface : AttrInterface<"AttrAsmAliasAttrInterface"> { | ||
| let cppNamespace = "::mlir"; | ||
| let description = [{ | ||
| This interface allows aliasing an attribute between dialects, allowing | ||
| custom printing of an attribute by an external dialect. | ||
| }]; | ||
| let methods = [ | ||
| InterfaceMethod<[{ | ||
| Returns the dialect responsible for printing and parsing the attribute | ||
| instance. | ||
| }], | ||
| "Dialect*", "getAliasDialect", (ins), [{}], [{}] | ||
| > | ||
| ]; | ||
| } | ||
|
|
||
| //===----------------------------------------------------------------------===// | ||
| // TypeAsmAliasTypeInterface | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| def TypeAsmAliasTypeInterface : TypeInterface<"TypeAsmAliasTypeInterface"> { | ||
| let cppNamespace = "::mlir"; | ||
| let description = [{ | ||
| This interface allows aliasing a type between dialects, allowing custom | ||
| printing of a type by an external dialect. | ||
| }]; | ||
| let methods = [ | ||
| InterfaceMethod<[{ | ||
| Returns the dialect responsible for printing and parsing the type | ||
| instance. | ||
| }], | ||
| "Dialect*", "getAliasDialect", (ins), [{}], [{}] | ||
| > | ||
| ]; | ||
| } | ||
|
|
||
| #endif // MLIR_IR_ASMINTERFACES_TD |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| //===- LLVMIRToPtrTranslation.h - LLVM IR to Ptr Dialect --------*- C++ -*-===// | ||
| // | ||
| // 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 | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // This provides registration calls for LLVM IR to Ptr dialect translation. | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #ifndef MLIR_TARGET_LLVMIR_DIALECT_PTR_LLVMIRTOPTRTRANSLATION_H | ||
| #define MLIR_TARGET_LLVMIR_DIALECT_PTR_LLVMIRTOPTRTRANSLATION_H | ||
|
|
||
| namespace mlir { | ||
|
|
||
| class DialectRegistry; | ||
| class MLIRContext; | ||
|
|
||
| /// Registers the Ptr dialect and its import from LLVM IR in the given | ||
| /// registry. | ||
| void registerPtrDialectImport(DialectRegistry ®istry); | ||
|
|
||
| /// Registers the Ptr dialect and its import from LLVM IR with the given | ||
| /// context. | ||
| void registerPtrDialectImport(MLIRContext &context); | ||
|
|
||
| } // namespace mlir | ||
|
|
||
| #endif // MLIR_TARGET_LLVMIR_DIALECT_PTR_LLVMIRTOPTRTRANSLATION_H |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| //===- PtrToLLVMIRTranslation.h - Ptr Dialect to LLVM IR --------*- C++ -*-===// | ||
| // | ||
| // 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 | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // This provides registration calls for Ptr dialect to LLVM IR translation. | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #ifndef MLIR_TARGET_LLVMIR_DIALECT_PTR_PTRTOLLVMIRTRANSLATION_H | ||
| #define MLIR_TARGET_LLVMIR_DIALECT_PTR_PTRTOLLVMIRTRANSLATION_H | ||
|
|
||
| namespace mlir { | ||
|
|
||
| class DialectRegistry; | ||
| class MLIRContext; | ||
|
|
||
| /// Register the Ptr dialect and the translation from it to the LLVM IR in | ||
| /// the given registry; | ||
| void registerPtrDialectTranslation(DialectRegistry ®istry); | ||
|
|
||
| /// Register the Ptr dialect and the translation from it in the registry | ||
| /// associated with the given context. | ||
| void registerPtrDialectTranslation(MLIRContext &context); | ||
|
|
||
| } // namespace mlir | ||
|
|
||
| #endif // MLIR_TARGET_LLVMIR_DIALECT_PTR_PTRTOLLVMIRTRANSLATION_H |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| add_subdirectory(IR) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| add_mlir_dialect_library( | ||
| MLIRPtrDialect | ||
| PtrTypes.cpp | ||
| PtrDialect.cpp | ||
| PtrMemorySlot.cpp | ||
| ADDITIONAL_HEADER_DIRS | ||
| ${PROJECT_SOURCE_DIR}/mlir/Dialect/Pointer | ||
| DEPENDS | ||
| MLIRPtrOpsIncGen | ||
| MLIRPtrOpsEnumsGen | ||
| MLIRPtrOpsAttributesIncGen | ||
| MLIRPtrMemorySpaceInterfacesIncGen | ||
| LINK_LIBS | ||
| PUBLIC | ||
| MLIRIR | ||
| MLIRDataLayoutInterfaces | ||
| MLIRMemorySlotInterfaces | ||
| ) |