-
Notifications
You must be signed in to change notification settings - Fork 13.7k
[mlir][AsmPrinter] Print op properties directly in generic form #106996
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1809,14 +1809,13 @@ class Op : public OpState, public Traits<ConcreteType>... { | |
|
||
/// Trait to check if printProperties(OpAsmPrinter, T, ArrayRef<StringRef>) | ||
/// exist | ||
template <typename T, typename... Args> | ||
using has_print_properties = | ||
decltype(printProperties(std::declval<OpAsmPrinter &>(), | ||
std::declval<T>(), | ||
std::declval<ArrayRef<StringRef>>())); | ||
template <typename T> | ||
template <typename ConcreteOp, typename Props> | ||
using has_print_properties = decltype(ConcreteOp::printProperties( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. note: this changed from free-standing printProperties to ConcreteOp::printProperties. motivation: Since properties type is strongly coupled to the operation, i think it makes sense to make printProperties a static member function also. This would at least avoid the declaration-issue as one would have method declaration in the body of the Op (e.g. when generating tablegen - inside extraClassDeclarations). |
||
std::declval<OpAsmPrinter &>(), std::declval<Props>(), | ||
std::declval<ArrayRef<StringRef>>())); | ||
template <typename ConcreteOp, typename Props> | ||
using detect_has_print_properties = | ||
llvm::is_detected<has_print_properties, T>; | ||
llvm::is_detected<has_print_properties, ConcreteOp, Props>; | ||
|
||
/// Trait to check if parseProperties(OpAsmParser, T) exist | ||
template <typename T, typename... Args> | ||
|
@@ -1981,16 +1980,16 @@ class Op : public OpState, public Traits<ConcreteType>... { | |
|
||
/// Print the operation properties with names not included within | ||
/// 'elidedProps'. Unless overridden, this method will try to dispatch to a | ||
/// `printProperties` free-function if it exists, and otherwise by converting | ||
/// the properties to an Attribute. | ||
template <typename T> | ||
/// `T::printProperties` if it exists, and otherwise by converting the | ||
/// properties to an Attribute. | ||
template <typename T = ConcreteType> | ||
static void printProperties(MLIRContext *ctx, OpAsmPrinter &p, | ||
const T &properties, | ||
const InferredProperties<T> &properties, | ||
ArrayRef<StringRef> elidedProps = {}) { | ||
if constexpr (detect_has_print_properties<T>::value) | ||
return printProperties(p, properties, elidedProps); | ||
genericPrintProperties( | ||
p, ConcreteType::getPropertiesAsAttr(ctx, properties), elidedProps); | ||
if constexpr (detect_has_print_properties<T, InferredProperties<T>>::value) | ||
return T::printProperties(p, properties, elidedProps); | ||
genericPrintProperties(p, T::getPropertiesAsAttr(ctx, properties), | ||
elidedProps); | ||
} | ||
|
||
/// Parses 'prop-dict' for the operation. Unless overridden, the method will | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -142,6 +142,7 @@ class OperationName { | |
virtual void copyProperties(OpaqueProperties, OpaqueProperties) = 0; | ||
virtual bool compareProperties(OpaqueProperties, OpaqueProperties) = 0; | ||
virtual llvm::hash_code hashProperties(OpaqueProperties) = 0; | ||
virtual void printProperties(Operation *, OpAsmPrinter &) = 0; | ||
}; | ||
|
||
public: | ||
|
@@ -223,6 +224,7 @@ class OperationName { | |
void copyProperties(OpaqueProperties, OpaqueProperties) final; | ||
bool compareProperties(OpaqueProperties, OpaqueProperties) final; | ||
llvm::hash_code hashProperties(OpaqueProperties) final; | ||
void printProperties(Operation *, OpAsmPrinter &) final; | ||
}; | ||
|
||
public: | ||
|
@@ -455,6 +457,10 @@ class OperationName { | |
return getImpl()->hashProperties(properties); | ||
} | ||
|
||
void printOpProperties(Operation *op, OpAsmPrinter &printer) const { | ||
getImpl()->printProperties(op, printer); | ||
} | ||
|
||
/// Return the dialect this operation is registered to if the dialect is | ||
/// loaded in the context, or nullptr if the dialect isn't loaded. | ||
Dialect *getDialect() const { | ||
|
@@ -668,6 +674,13 @@ class RegisteredOperationName : public OperationName { | |
|
||
return {}; | ||
} | ||
void printProperties(Operation *op, OpAsmPrinter &printer) final { | ||
if constexpr (hasProperties) { | ||
auto concreteOp = cast<ConcreteOp>(op); | ||
ConcreteOp::printProperties(concreteOp->getContext(), printer, | ||
concreteOp.getProperties()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. self-review: perhaps I should be explicit here to also pass (e.g. see |
||
} | ||
} | ||
}; | ||
|
||
/// Lookup the registered operation information for the given operation. | ||
|
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.
self-review: