-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[mlir][Ptr] Add the MemorySpaceAttrInterface
interface and dependencies.
#86870
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
4 commits
Select commit
Hold shift + click to select a range
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,32 @@ | ||
//===-- MemorySpaceInterfaces.h - ptr memory space 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 the ptr dialect memory space interfaces. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef MLIR_DIALECT_PTR_IR_MEMORYSPACEINTERFACES_H | ||
#define MLIR_DIALECT_PTR_IR_MEMORYSPACEINTERFACES_H | ||
|
||
#include "mlir/IR/Attributes.h" | ||
#include "mlir/IR/BuiltinAttributes.h" | ||
#include "mlir/IR/OpDefinition.h" | ||
|
||
namespace mlir { | ||
class Operation; | ||
namespace ptr { | ||
enum class AtomicBinOp : uint64_t; | ||
enum class AtomicOrdering : uint64_t; | ||
} // namespace ptr | ||
} // namespace mlir | ||
|
||
#include "mlir/Dialect/Ptr/IR/MemorySpaceAttrInterfaces.h.inc" | ||
|
||
#include "mlir/Dialect/Ptr/IR/MemorySpaceInterfaces.h.inc" | ||
|
||
#endif // MLIR_DIALECT_PTR_IR_MEMORYSPACEINTERFACES_H |
117 changes: 117 additions & 0 deletions
117
mlir/include/mlir/Dialect/Ptr/IR/MemorySpaceInterfaces.td
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,117 @@ | ||
//===-- MemorySpaceInterfaces.td - Memory space interfaces ----------------===// | ||
// | ||
// 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 memory space attribute interfaces. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef PTR_MEMORYSPACEINTERFACES | ||
#define PTR_MEMORYSPACEINTERFACES | ||
|
||
include "mlir/IR/AttrTypeBase.td" | ||
include "mlir/IR/OpBase.td" | ||
|
||
//===----------------------------------------------------------------------===// | ||
// Memory space attribute interface. | ||
//===----------------------------------------------------------------------===// | ||
|
||
def MemorySpaceAttrInterface : AttrInterface<"MemorySpaceAttrInterface"> { | ||
let description = [{ | ||
This interface defines a common API for interacting with the memory model of | ||
a memory space and the operations in the pointer dialect. | ||
|
||
Furthermore, this interface allows concepts such as read-only memory to be | ||
adequately modeled and enforced. | ||
}]; | ||
let cppNamespace = "::mlir::ptr"; | ||
let methods = [ | ||
InterfaceMethod< | ||
/*desc=*/ [{ | ||
This method checks if it's valid to load a value from the memory space | ||
with a specific type, alignment, and atomic ordering. | ||
If `emitError` is non-null then the method is allowed to emit errors. | ||
}], | ||
/*returnType=*/ "::mlir::LogicalResult", | ||
/*methodName=*/ "isValidLoad", | ||
/*args=*/ (ins "::mlir::Type":$type, | ||
"::mlir::ptr::AtomicOrdering":$ordering, | ||
"::mlir::IntegerAttr":$alignment, | ||
"::llvm::function_ref<::mlir::InFlightDiagnostic()>":$emitError) | ||
>, | ||
InterfaceMethod< | ||
/*desc=*/ [{ | ||
This method checks if it's valid to store a value in the memory space | ||
with a specific type, alignment, and atomic ordering. | ||
If `emitError` is non-null then the method is allowed to emit errors. | ||
}], | ||
/*returnType=*/ "::mlir::LogicalResult", | ||
/*methodName=*/ "isValidStore", | ||
/*args=*/ (ins "::mlir::Type":$type, | ||
"::mlir::ptr::AtomicOrdering":$ordering, | ||
"::mlir::IntegerAttr":$alignment, | ||
"::llvm::function_ref<::mlir::InFlightDiagnostic()>":$emitError) | ||
>, | ||
InterfaceMethod< | ||
/*desc=*/ [{ | ||
This method checks if it's valid to perform an atomic operation in the | ||
memory space with a specific type, alignment, and atomic ordering. | ||
If `emitError` is non-null then the method is allowed to emit errors. | ||
}], | ||
/*returnType=*/ "::mlir::LogicalResult", | ||
/*methodName=*/ "isValidAtomicOp", | ||
/*args=*/ (ins "::mlir::ptr::AtomicBinOp":$op, | ||
"::mlir::Type":$type, | ||
"::mlir::ptr::AtomicOrdering":$ordering, | ||
"::mlir::IntegerAttr":$alignment, | ||
"::llvm::function_ref<::mlir::InFlightDiagnostic()>":$emitError) | ||
>, | ||
InterfaceMethod< | ||
/*desc=*/ [{ | ||
This method checks if it's valid to perform an atomic exchange operation | ||
in the memory space with a specific type, alignment, and atomic | ||
orderings. | ||
If `emitError` is non-null then the method is allowed to emit errors. | ||
}], | ||
/*returnType=*/ "::mlir::LogicalResult", | ||
/*methodName=*/ "isValidAtomicXchg", | ||
/*args=*/ (ins "::mlir::Type":$type, | ||
"::mlir::ptr::AtomicOrdering":$successOrdering, | ||
"::mlir::ptr::AtomicOrdering":$failureOrdering, | ||
"::mlir::IntegerAttr":$alignment, | ||
"::llvm::function_ref<::mlir::InFlightDiagnostic()>":$emitError) | ||
>, | ||
InterfaceMethod< | ||
/*desc=*/ [{ | ||
This method checks if it's valid to perform an `addrspacecast` op | ||
in the memory space. | ||
If `emitError` is non-null then the method is allowed to emit errors. | ||
}], | ||
/*returnType=*/ "::mlir::LogicalResult", | ||
/*methodName=*/ "isValidAddrSpaceCast", | ||
/*args=*/ (ins "::mlir::Type":$tgt, | ||
"::mlir::Type":$src, | ||
"::llvm::function_ref<::mlir::InFlightDiagnostic()>":$emitError) | ||
>, | ||
InterfaceMethod< | ||
/*desc=*/ [{ | ||
This method checks if it's valid to perform a `ptrtoint` or `inttoptr` | ||
op in the memory space. | ||
The first type is expected to be integer-like, while the second must be a | ||
ptr-like type. | ||
If `emitError` is non-null then the method is allowed to emit errors. | ||
}], | ||
/*returnType=*/ "::mlir::LogicalResult", | ||
/*methodName=*/ "isValidPtrIntCast", | ||
/*args=*/ (ins "::mlir::Type":$intLikeTy, | ||
"::mlir::Type":$ptrLikeTy, | ||
"::llvm::function_ref<::mlir::InFlightDiagnostic()>":$emitError) | ||
>, | ||
]; | ||
} | ||
|
||
#endif // PTR_MEMORYSPACEINTERFACES |
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,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 |
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
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
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.
@fabianmcg : nitpicking here but methods that starts with
is
are predicates and should returnbool
:LogicalResult
is a about method that can fail instead. Can you update?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 update. But these methods can emit an error, remember they get a
::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError
parameter.Admittedly, I would prefer these methods to return something like a
SuccesOrDiagnostic
, so users can have more control on how to handle the result. Or to decouple the diagnostic from the validity method.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.
FailureOr<bool>
?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.
That's a good immediate option, I'll change to that. But I think we are missing something similar to
llvm::Expected
, like:Which would allow users to decide how to handle the diagnostic.
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 think we're trying to be more efficient by avoiding formatting a diagnostic when the user does not want it.
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.
On success we shouldn't format a diagnostic, but I'm still not convinced about the approach.
I'll change to
FailureOr<bool>
, I'll revisit if I have a better idea.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'm talking about the failing case where the user of the API would just discard the diagnostic.
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 just remembered the
emitError
is always optional and the user of the API can opt to pass a default constructed object, in which case the method cannot produce errors. Therefore, it already handles the case of discarding the diagnostic in a efficient manner.I'll switch to
FailureOr<bool>
.