Skip to content

Conversation

@martin-luecke
Copy link

@martin-luecke martin-luecke commented Jun 21, 2023

This PR introduces support for negation of constraints.

Previously, this could only be handled by creating an additional native call, e.g.

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 !. e.g.

Constraint simpleConstraint(op: Op);

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

This pattern only matches if the constraint simpleConstraint is true for root and false for inputOp.

This required the following changes:
PDLL:

  • make lexer aware of ! tokens
  • support parsing ! as prefix for native constraints (only!)
  • extend CallExpr with support for isNegated

PDL & PDLInterp Dialects

  • adding an attribute isNegated with default value false to the operations pdl.apply_native_constraint and pdl_interp.apply_constraint
  • make PDLToPDLInterpPass aware of this attribute

ByteCode:

  • add isNegated to the generated bytecode
  • When interpreting pdl_interp.apply_constraint branch depending on isNegated

This work is to be upstreamed to llvm-project

@martin-luecke martin-luecke marked this pull request as ready for review June 22, 2023 08:58
@martin-luecke martin-luecke requested review from ljfitz and ttjost June 22, 2023 08:59
Copy link

@ttjost ttjost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you just add a test (failure maybe?) for the rewrite section?

@martin-luecke martin-luecke force-pushed the martin.FXML-2302.PDLL_constraint_negation branch from 4444648 to 3ec1761 Compare June 23, 2023 14:43
@martin-luecke
Copy link
Author

Thank you for the review!
I added the test 👍

@martin-luecke martin-luecke requested a review from ttjost June 23, 2023 14:45
Copy link

@ttjost ttjost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! Thanks for adding the test and making the necessary changes.

Copy link
Collaborator

@ljfitz ljfitz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Martin - looks like a useful addition and clearly coded.

@martin-luecke martin-luecke merged commit 13e7391 into feature/fused-ops Jun 26, 2023
@martin-luecke martin-luecke deleted the martin.FXML-2302.PDLL_constraint_negation branch June 26, 2023 08:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants