-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[mlir][Ptr] Init the Ptr dialect with the !ptr.ptr
type.
#86860
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c0a51c0
[mlir][Ptr] Init the Ptr dialect with the `!ptr.ptr` type.
fabianmcg f2ffe70
add layout test, address reviewer comments and fix a bug in layout me…
fabianmcg 108501e
Addressed reviewer comments
fabianmcg 4a42c68
address reviewer comments
fabianmcg 57f4945
update PtrType description with mention of nullptr
fabianmcg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
add_subdirectory(IR) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
add_mlir_dialect(PtrOps ptr) | ||
add_mlir_doc(PtrOps PtrOps Dialects/ -gen-op-doc) | ||
|
||
set(LLVM_TARGET_DEFINITIONS PtrOps.td) | ||
mlir_tablegen(PtrOpsAttrs.h.inc -gen-attrdef-decls -attrdefs-dialect=ptr) | ||
mlir_tablegen(PtrOpsAttrs.cpp.inc -gen-attrdef-defs -attrdefs-dialect=ptr) | ||
add_public_tablegen_target(MLIRPtrOpsAttributesIncGen) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
//===-- 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; | ||
} | ||
|
||
//===----------------------------------------------------------------------===// | ||
// 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<size = 64, abi = 64, preferred = 128, index = 64> | ||
``` | ||
}]; | ||
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<uint32_t>::max(); | ||
}]; | ||
let genVerifyDecl = 1; | ||
} | ||
|
||
#endif // PTR_ATTRDEFS |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
//===- PtrAttrs.h - Pointer dialect attributes ------------------*- 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 declares the Ptr dialect attributes. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef MLIR_DIALECT_PTR_IR_PTRATTRS_H | ||
#define MLIR_DIALECT_PTR_IR_PTRATTRS_H | ||
|
||
#include "mlir/IR/OpImplementation.h" | ||
|
||
#define GET_ATTRDEF_CLASSES | ||
#include "mlir/Dialect/Ptr/IR/PtrOpsAttrs.h.inc" | ||
|
||
#endif // MLIR_DIALECT_PTR_IR_PTRATTRS_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
//===- PtrDialect.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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
//===- 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 = 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"]> | ||
]> { | ||
let summary = "pointer type"; | ||
let description = [{ | ||
The `ptr` type is an opaque pointer type. This type typically represents a | ||
handle to an object in memory or target-dependent values like `nullptr`. | ||
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">:$memorySpace), [{ | ||
return $_get($_ctxt, memorySpace); | ||
}]> | ||
]; | ||
let skipDefaultBuilders = 1; | ||
} | ||
|
||
//===----------------------------------------------------------------------===// | ||
// Base address operation definition. | ||
//===----------------------------------------------------------------------===// | ||
|
||
class Pointer_Op<string mnemonic, list<Trait> traits = []> : | ||
Op<Ptr_Dialect, mnemonic, traits>; | ||
|
||
#endif // PTR_DIALECT |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
//===- PtrDialect.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_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/PtrTypes.h" | ||
#include "mlir/IR/OpDefinition.h" | ||
|
||
#define GET_OP_CLASSES | ||
#include "mlir/Dialect/Ptr/IR/PtrOps.h.inc" | ||
|
||
#endif // MLIR_DIALECT_PTR_IR_PTROPS_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
//===- PtrOps.td - Pointer dialect ops ---------------------*- tablegen -*-===// | ||
// | ||
// This file is licensed under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://ptr.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef PTR_OPS | ||
#define PTR_OPS | ||
|
||
include "mlir/Dialect/Ptr/IR/PtrDialect.td" | ||
include "mlir/Dialect/Ptr/IR/PtrAttrDefs.td" | ||
include "mlir/IR/OpAsmInterface.td" | ||
|
||
#endif // PTR_OPS |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
//===- PtrTypes.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/IR/Types.h" | ||
#include "mlir/Interfaces/DataLayoutInterfaces.h" | ||
|
||
#define GET_TYPEDEF_CLASSES | ||
#include "mlir/Dialect/Ptr/IR/PtrOpsTypes.h.inc" | ||
|
||
#endif // MLIR_DIALECT_PTR_IR_PTRTYPES_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
add_subdirectory(IR) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
add_mlir_dialect_library( | ||
MLIRPtrDialect | ||
PtrAttrs.cpp | ||
PtrTypes.cpp | ||
PtrDialect.cpp | ||
|
||
DEPENDS | ||
fabianmcg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
MLIRPtrOpsAttributesIncGen | ||
MLIRPtrOpsIncGen | ||
|
||
LINK_LIBS | ||
PUBLIC | ||
MLIRIR | ||
MLIRDataLayoutInterfaces | ||
MLIRMemorySlotInterfaces | ||
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
//===- PtrAttrs.cpp - Pointer dialect attributes ----------------*- 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 attributes. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "mlir/Dialect/Ptr/IR/PtrAttrs.h" | ||
#include "llvm/ADT/TypeSwitch.h" | ||
|
||
using namespace mlir; | ||
using namespace mlir::ptr; | ||
|
||
constexpr const static unsigned kBitsInByte = 8; | ||
|
||
//===----------------------------------------------------------------------===// | ||
// SpecAttr | ||
//===----------------------------------------------------------------------===// | ||
|
||
LogicalResult SpecAttr::verify(function_ref<InFlightDiagnostic()> emitError, | ||
uint32_t size, uint32_t abi, uint32_t preferred, | ||
uint32_t index) { | ||
if (size % kBitsInByte != 0) | ||
return emitError() << "size entry must be divisible by 8"; | ||
if (abi % kBitsInByte != 0) | ||
return emitError() << "abi entry must be divisible by 8"; | ||
if (preferred % kBitsInByte != 0) | ||
return emitError() << "preferred entry must be divisible by 8"; | ||
if (index != kOptionalSpecValue && index % kBitsInByte != 0) | ||
return emitError() << "index entry must be divisible by 8"; | ||
if (abi > preferred) | ||
return emitError() << "preferred alignment is expected to be at least " | ||
"as large as ABI alignment"; | ||
return success(); | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably should be added later, with tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can remove it, however, there's already a first test on
types.mlir
checkingmemref<!ptr.ptr>
is valid.