Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ struct I64Attr : IntegerAttr {
[[nodiscard]] auto getValue() const -> int64_t {
return IntegerAttr::getValue().getSExtValue();
}

[[nodiscard]] static auto getFromOpaquePointer(const void* ptr) -> I64Attr {
return I64Attr(reinterpret_cast<const mlir::AttributeStorage*>(ptr));
}
};

/// Named constraint for an attribute that stores a resource kind.
Expand Down Expand Up @@ -99,6 +103,11 @@ struct ResourceSpecAttr : Attribute {
: Attribute(static_cast<Attribute>(attr).getImpl()) {}
/*implicit*/ ResourceSpecAttr(FlatSymbolRefAttr attr)
: Attribute(static_cast<Attribute>(attr).getImpl()) {}

[[nodiscard]] static auto getFromOpaquePointer(const void* ptr)
-> ResourceSpecAttr {
return ResourceSpecAttr(reinterpret_cast<const ImplType*>(ptr));
}
};

/// Named constraint for an attribute that stores a directed adjacency matrix.
Expand Down Expand Up @@ -141,6 +150,11 @@ struct AdjacencyMatrixAttr : ElementsAttr {
[[nodiscard]] auto getDim() const -> int64_t {
return getShapedType().getDimSize(0);
}

[[nodiscard]] static auto getFromOpaquePointer(const void* ptr)
-> AdjacencyMatrixAttr {
return AdjacencyMatrixAttr(reinterpret_cast<const ImplType*>(ptr));
}
};

} // namespace mlir::ktdf_arch
Expand All @@ -154,6 +168,15 @@ struct llvm::PointerLikeTypeTraits<mlir::ktdf_arch::KindAttr>
}
};

template <>
struct llvm::PointerLikeTypeTraits<mlir::ktdf_arch::ResourceSpecAttr>
: PointerLikeTypeTraits<mlir::Attribute> {
[[nodiscard]] static auto getFromVoidPointer(void* ptr)
-> mlir::ktdf_arch::ResourceSpecAttr {
return mlir::ktdf_arch::ResourceSpecAttr::getFromOpaquePointer(ptr);
}
};

/// Auto-generated includes.
#define GET_ATTRDEF_CLASSES
#include "dataflow-scheduler/Dialect/KTDFArch/KTDFArchAttributes.h.inc" // IWYU pragma: export
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,15 +209,15 @@ def KTDFArch_Mappable : OpInterface<"Mappable"> {

let methods = [
InterfaceMethod<[{
Gets the attribute that indicates the resource mapping.
Gets the resource mapping as an attribute.
}],
"MapsToAttr", "getMapsTo", (ins),
"",
[{
return mlir::ktdf_arch::getProperty<MapsToAttr>($_op);
}]>,
InterfaceMethod<[{
Tries to set the attribute that indicates the resource mapping.
Tries to set the resource mapping from an attribute.
}],
"LogicalResult", "setMapsTo", (ins "MapsToAttr":$maps_to),
"",
Expand All @@ -226,7 +226,7 @@ def KTDFArch_Mappable : OpInterface<"Mappable"> {
return llvm::success();
}]>,
InterfaceMethod<[{
Removes the attribute that indicates the resource mapping.
Removes the resource mapping as an attribute.
}],
"MapsToAttr", "removeMapsTo", (ins),
"",
Expand All @@ -250,6 +250,22 @@ def KTDFArch_Mappable : OpInterface<"Mappable"> {
/// Gets the implementation for @p op , or the default.
[[nodiscard]] static auto getInterfaceFor(Operation* op) -> Concept*;

/// Gets the resource mapping of @p op , if it has any.
[[nodiscard]] static auto getMapsTo(Operation* op) -> MapsToAttr;

/// Tries to set the resource mapping of @p op.
static auto setMapsTo(Operation* op, MapsToAttr maps_to) -> LogicalResult;

/// Tries to remove the resource mapping of @p op.
static auto removeMapsTo(Operation* op) -> MapsToAttr;

/// Verifies the mapping of @p op to @p resources .
static auto verifyMapping(Operation* op, ArrayRef<Resource> resources) -> LogicalResult;

/// Gets the resource mapping of @p op , or inherits from a parent.
///
/// See getOrInheritMapsTo() for more information.
[[nodiscard]] static auto getOrInheritMapsTo(Operation* op) -> std::pair<Mappable, MapsToAttr>;
/// Gets the resource mapping of this op, or inherits it from a parent.
///
/// Walks the IR upwards from @p mappable , returning the value of the first
Expand Down
42 changes: 42 additions & 0 deletions lib/Dialect/KTDFArch/KTDFArchOpInterfaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,48 @@ auto Mappable::getInterfaceFor(Operation* op) -> Concept* {
return &default_mappable;
}

auto Mappable::getMapsTo(Operation* op) -> MapsToAttr {
if (auto mappable = llvm::dyn_cast<Mappable>(op); mappable) {
return mappable.getMapsTo();
}

return nullptr;
}

auto Mappable::setMapsTo(Operation* op, MapsToAttr maps_to) -> LogicalResult {
if (auto mappable = llvm::dyn_cast<Mappable>(op); mappable) {
return mappable.setMapsTo(maps_to);
}

return failure();
}

auto Mappable::removeMapsTo(Operation* op) -> MapsToAttr {
if (auto mappable = llvm::dyn_cast<Mappable>(op); mappable) {
return mappable.removeMapsTo();
}

return nullptr;
}

auto Mappable::verifyMapping(Operation* op, ArrayRef<Resource> resources)
-> LogicalResult {
if (auto mappable = llvm::dyn_cast<Mappable>(op); mappable) {
return mappable.verifyMapping(resources);
}

return success();
}

auto Mappable::getOrInheritMapsTo(Operation* op)
-> std::pair<Mappable, MapsToAttr> {
if (auto mappable = dyn_cast<Mappable>(op); mappable) {
return mappable.getOrInheritMapsTo();
}

return {nullptr, nullptr};
}

auto Mappable::getOrInheritMapsTo() -> std::pair<Mappable, MapsToAttr> {
for (auto self = *this; self; self = self->getParentOfType<Mappable>()) {
if (const auto mapping = self.getMapsTo(); mapping) {
Expand Down
Loading