Page MenuHomePhabricator

Please use GitHub pull requests for new patches. Avoid migrating existing patches. Phabricator shutdown timeline

[MLIR][PDL] Add PDLL support for negated native constraints
ClosedPublic

Authored by martin-luecke on Jun 28 2023, 4:33 AM.

Details

Summary

This commit enables the expression of negated native constraints in PDLL:

If a constraint is prefixed with "not" it is parsed as a negated constraint and hence the attribute isNegated of the emitted pdl.apply_native_constraint operation is set to true.
In first instance this is only supported for the calling of external native C++ constraints and generation of PDL patterns.

Previously, negating a native constraint would have been handled by creating an additional native call, e.g.

PDLL
Constraint checkA(input: Attr);
Constarint checkNotA(input: Attr);

or by including an explicit additional operand for negation, e.g.
Constraint checkA(input: Attr, negated: Attr);

With this a constraint can simply be negated by prefixing it with not. e.g.

PDLL
Constraint simpleConstraint(op: Op);

Pattern example {
    let inputOp = op<test.bar>() ->(type: Type);
    let root = op<test.foo>(inputOp.0) -> ();
    not simpleConstraint(inputOp);
    simpleConstraint(root);
    erase root;
}

Depends on D153871

Diff Detail

Event Timeline

martin-luecke created this revision.Jun 28 2023, 4:33 AM
Herald added a project: Restricted Project. · View Herald Transcript
martin-luecke requested review of this revision.Jun 28 2023, 4:33 AM
Mogball accepted this revision.Jun 29 2023, 9:45 AM

LGTM but please wait for @rriddle to review

mlir/lib/Tools/PDLL/CodeGen/MLIRGen.cpp
592

can you guard this on std::is_same_v<PDLOpT, ApplyConstantOp> and then use setIsNegated function directly?

mlir/test/mlir-pdll/Parser/expr.pdll
63

I feel like not TestConstraint is a more intuitive syntax here

This revision is now accepted and ready to land.Jun 29 2023, 9:45 AM
martin-luecke marked an inline comment as done.

Address comments:

  • setting attribute directly rather than through the general interface
  • syntax for negation changed from ! to not
martin-luecke edited the summary of this revision. (Show Details)Sep 1 2023, 3:56 AM
martin-luecke marked an inline comment as done.