-
Notifications
You must be signed in to change notification settings - Fork 14.8k
[mlir] Allow using non-attribute properties in declarative rewrite patterns #143071
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
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 |
---|---|---|
|
@@ -400,6 +400,21 @@ class ConfinedProperty<Property p, Pred pred, string newSummary = ""> | |
: ConfinedProp<p, pred, newSummary>, | ||
Deprecated<"moved to shorter name ConfinedProp">; | ||
|
||
/// Defines a constant value of type `prop` to be used in pattern matching. | ||
/// When used as a constraint, forms a matcher that tests that the property is | ||
/// equal to the given value (and matches any other constraints on the property). | ||
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. And this uses/requires that the interface type has an equality operation. Does this also work in templated cases? 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. Docs updated |
||
/// The constant value is given as a string and should be of the _interface_ type | ||
/// of the attribute. | ||
/// | ||
/// This requires that the given property's inference type be comparable to the | ||
/// given value with `==`, and does require specify a concrete property type. | ||
class ConstantProp<Property prop, string val> | ||
: ConfinedProp<prop, | ||
CPred<"$_self == " # val>, | ||
"constant '" # prop.summary # "': " # val> { | ||
string value = val; | ||
} | ||
|
||
//===----------------------------------------------------------------------===// | ||
// Primitive property combinators | ||
//===----------------------------------------------------------------------===// | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -73,12 +73,23 @@ class DagLeaf { | |
// specifies an attribute constraint. | ||
bool isAttrMatcher() const; | ||
|
||
// Returns true if this DAG leaf is matching a property. That is, it | ||
// specifies a property constraint. | ||
bool isPropMatcher() const; | ||
|
||
// Returns true if this DAG leaf is describing a property. That is, it | ||
// is a subclass of `Property` in tablegen. | ||
bool isPropDefinition() const; | ||
|
||
// Returns true if this DAG leaf is wrapping native code call. | ||
bool isNativeCodeCall() const; | ||
|
||
// Returns true if this DAG leaf is specifying a constant attribute. | ||
bool isConstantAttr() const; | ||
|
||
// Returns true if this DAG leaf is specifying a constant property. | ||
bool isConstantProp() const; | ||
|
||
// Returns true if this DAG leaf is specifying an enum case. | ||
bool isEnumCase() const; | ||
|
||
|
@@ -88,9 +99,19 @@ class DagLeaf { | |
// Returns this DAG leaf as a constraint. Asserts if fails. | ||
Constraint getAsConstraint() const; | ||
|
||
// Returns this DAG leaf as a property constraint. Asserts if fails. This | ||
// allows access to the interface type. | ||
PropConstraint getAsPropConstraint() const; | ||
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. Why does properties need to be treated specially compared to other constraints? 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. They've got an interface type attached |
||
|
||
// Returns this DAG leaf as a property definition. Asserts if fails. | ||
Property getAsProperty() const; | ||
|
||
// Returns this DAG leaf as an constant attribute. Asserts if fails. | ||
ConstantAttr getAsConstantAttr() const; | ||
|
||
// Returns this DAG leaf as an constant property. Asserts if fails. | ||
ConstantProp getAsConstantProp() const; | ||
|
||
// Returns this DAG leaf as an enum case. | ||
// Precondition: isEnumCase() | ||
EnumCase getAsEnumCase() const; | ||
|
@@ -279,6 +300,10 @@ class SymbolInfoMap { | |
// the DAG of the operation, `operandIndexOrNumValues` specifies the | ||
// operand index, and `variadicSubIndex` must be set to `std::nullopt`. | ||
// | ||
// * Properties not associated with an operation (e.g. as arguments to | ||
// native code) have their corresponding PropConstraint stored in the | ||
// `dag` field. This constraint is only used when | ||
// | ||
// * If a symbol is defined in a `variadic` DAG, `dag` specifies the DAG | ||
// of the parent operation, `operandIndexOrNumValues` specifies the | ||
// declared operand index of the variadic operand in the parent | ||
|
@@ -364,12 +389,20 @@ class SymbolInfoMap { | |
|
||
// What kind of entity this symbol represents: | ||
krzysz00 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// * Attr: op attribute | ||
// * Prop: op property | ||
// * Operand: op operand | ||
// * Result: op result | ||
// * Value: a value not attached to an op (e.g., from NativeCodeCall) | ||
// * MultipleValues: a pack of values not attached to an op (e.g., from | ||
// NativeCodeCall). This kind supports indexing. | ||
enum class Kind : uint8_t { Attr, Operand, Result, Value, MultipleValues }; | ||
enum class Kind : uint8_t { | ||
Attr, | ||
Prop, | ||
Operand, | ||
Result, | ||
Value, | ||
MultipleValues | ||
}; | ||
|
||
// Creates a SymbolInfo instance. `dagAndConstant` is only used for `Attr` | ||
// and `Operand` so should be std::nullopt for `Result` and `Value` kind. | ||
|
@@ -384,6 +417,15 @@ class SymbolInfoMap { | |
static SymbolInfo getAttr() { | ||
return SymbolInfo(nullptr, Kind::Attr, std::nullopt); | ||
} | ||
static SymbolInfo getProp(const Operator *op, int index) { | ||
return SymbolInfo(op, Kind::Prop, | ||
DagAndConstant(nullptr, index, std::nullopt)); | ||
} | ||
static SymbolInfo getProp(const PropConstraint *constraint) { | ||
// -1 for anthe `operandIndexOrNumValues` is a sentinel value. | ||
return SymbolInfo(nullptr, Kind::Prop, | ||
DagAndConstant(constraint, -1, std::nullopt)); | ||
} | ||
static SymbolInfo | ||
getOperand(DagNode node, const Operator *op, int operandIndex, | ||
std::optional<int> variadicSubIndex = std::nullopt) { | ||
|
@@ -488,6 +530,10 @@ class SymbolInfoMap { | |
// is already bound. | ||
bool bindAttr(StringRef symbol); | ||
|
||
// Registers the given `symbol` as bound to a property that satisfies the | ||
// given `constraint`. `constraint` must name a concrete interface type. | ||
bool bindProp(StringRef symbol, const PropConstraint &constraint); | ||
|
||
// Returns true if the given `symbol` is bound. | ||
bool contains(StringRef symbol) const; | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.