Skip to content
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

[SMT] Added support for :pattern attribute #6976

Merged
merged 23 commits into from
May 28, 2024

Conversation

luisacicolini
Copy link
Contributor

This PR addressess issue #6913 to enable the support of attributes in the SMTLIB export pass.

Copy link
Contributor

@TaoBi22 TaoBi22 left a comment

Choose a reason for hiding this comment

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

A few minor points but looks pretty good to me!

integration_test/Target/ExportSMTLIB/attributes.mlir Outdated Show resolved Hide resolved
lib/Target/ExportSMTLIB/ExportSMTLIB.cpp Outdated Show resolved Hide resolved
lib/Target/ExportSMTLIB/ExportSMTLIB.cpp Outdated Show resolved Hide resolved
lib/Target/ExportSMTLIB/ExportSMTLIB.cpp Outdated Show resolved Hide resolved
lib/Target/ExportSMTLIB/ExportSMTLIB.cpp Outdated Show resolved Hide resolved
test.smt Outdated Show resolved Hide resolved
test_export.mlir Outdated Show resolved Hide resolved
lib/Target/ExportSMTLIB/ExportSMTLIB.cpp Outdated Show resolved Hide resolved
Copy link
Member

@maerhart maerhart left a comment

Choose a reason for hiding this comment

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

Thanks a lot for working on this!

Comment on lines 327 to 329



Copy link
Member

Choose a reason for hiding this comment

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

Nit: unnecessarily big whitespace

@@ -332,8 +339,11 @@ struct ExpressionVisitor
worklist.push_back(yieldedValue);
unsigned indentExt = operatorString.size() + 2;
VisitorInfo newInfo(info.stream, info.valueMap,
info.indentLevel + indentExt, 0);
newInfo.stream.indent(newInfo.indentLevel);
info.indentLevel + indentExt, info.openParens);
Copy link
Member

Choose a reason for hiding this comment

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

Why would we want to pass on the number of open parens to the body region? Wouldn't it close the scopes of let expressions that might still be used at a later point?

Suggested change
info.indentLevel + indentExt, info.openParens);
info.indentLevel + indentExt, 0);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, I was having some problem wiht parentheses and I was testing what this changed, but forgot to put it back afterwards! thanks

lib/Target/ExportSMTLIB/ExportSMTLIB.cpp Show resolved Hide resolved
@@ -343,7 +353,42 @@ struct ExpressionVisitor
info.stream << ")";

if (weight != 0)
info.stream << " :weight " << weight << ")";
info.stream << " :weight " << weight;
if(!patterns.empty()){
Copy link
Member

Choose a reason for hiding this comment

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

Forgot to run git-clang-format?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes 🤦‍♀️

Comment on lines 362 to 364
for (auto [i, arg] : llvm::enumerate(p.getArguments())) {
info.valueMap.insert(arg, argNames[i].str());
}
Copy link
Member

Choose a reason for hiding this comment

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

Nit: loops where the body is just one statement usually omit the curly braces

Comment on lines 77 to 80
// CHECK: (let (([[V31:.+]] (=> [[V30:.+]] true)))
// CHECK: [[V31:.+]])) :weight 2
// CHECK :pattern ( ( let (([[V32:.+]] (= [[V28:.+]] [[V29:.+]])))
// CHECK: [[V32:.+]]))))))
Copy link
Member

Choose a reason for hiding this comment

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

same here

test/Target/ExportSMTLIB/attributes.mlir Show resolved Hide resolved
newInfo.stream.indent(newInfo.indentLevel);
info.indentLevel + indentExt, info.openParens);
if(weight !=0 || !patterns.empty())
newInfo.stream.indent(0);
Copy link
Member

Choose a reason for hiding this comment

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

Can you explain why we want 0 indentation here instead of info.indentLevel as well?

Copy link
Member

Choose a reason for hiding this comment

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

Why is the replaced newInfo.stream.indent(newInfo.indentLevel); not the right thing to do here (assuming we move the ( ! printing just after this line).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is actually correct! I had misunderstood your previous comment, thanks

Comment on lines 367 to 369
Value yieldedValue = p.front().getTerminator()->getOperand(0);

worklist.push_back(yieldedValue);
Copy link
Member

Choose a reason for hiding this comment

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

The smt.yield operation can have more than one operand in pattern regions, but only one in the body region. So, there should probably another loop here iterating over all operands.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Quick questin about this, when (in the tests) I try to add multiple operands I get this error 2 operands present, but expected 1

Copy link
Member

Choose a reason for hiding this comment

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

That's interesting. Are you sure you have added it to the yield in the pattern region and not to the body? For me it worked in this regression test:

%58 = smt.forall {
^bb0(%arg2: !smt.int, %arg3: !smt.int):
%59 = smt.eq %arg2, %arg3 : !smt.int
smt.yield %59 : !smt.bool
} patterns {
^bb0(%arg2: !smt.int, %arg3: !smt.int):
%59 = smt.int.add %arg2, %arg3
smt.yield %59 : !smt.int
}, {
^bb0(%arg2: !smt.int, %arg3: !smt.int):
%59 = smt.int.add %arg2, %arg3
%60 = smt.int.sub %arg2, %arg3
smt.yield %59, %60 : !smt.int, !smt.int
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh thanks for the reference! There was actually another syntax error I had not considered

llvm Outdated
Copy link
Member

Choose a reason for hiding this comment

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

Accidental LLVM bump?

luisacicolini and others added 10 commits May 5, 2024 20:18
Co-authored-by: Bea Healy <57840981+TaoBi22@users.noreply.github.com>
Co-authored-by: Bea Healy <57840981+TaoBi22@users.noreply.github.com>
Co-authored-by: Bea Healy <57840981+TaoBi22@users.noreply.github.com>
This reverts commit 70f2a62.
This reverts commit 70f2a62.
@TaoBi22
Copy link
Contributor

TaoBi22 commented May 5, 2024

Sorry @luisacicolini, looks like rebasing with the correct LLVM commit made GitHub think I was the author of the commits on the branch!

@luisacicolini
Copy link
Contributor Author

No worries @TaoBi22 and thanks a lot for your help! Sorry for the delay in working on your commits @maerhart, had some issues with llvm and struggled a bit, luckily @TaoBi22 came to rescue. Getting everything done asap :)

@maerhart
Copy link
Member

maerhart commented May 6, 2024

No worries, there's no need to stress. If you need help with something, let me know :)

@luisacicolini
Copy link
Contributor Author

luisacicolini commented May 14, 2024

@maerhart all fixed now, this currently only supports single patterns, will open a new PR for the multi pattern :)
[EDIT: it actually required fewer changes than I thought, so everything is here now]

%t Outdated Show resolved Hide resolved
lib/Target/ExportSMTLIB/ExportSMTLIB.cpp Outdated Show resolved Hide resolved
lib/Target/ExportSMTLIB/ExportSMTLIB.cpp Outdated Show resolved Hide resolved
@luisacicolini
Copy link
Contributor Author

Adding multi patterns turned out to require just a few changes compared to this version, so now everything is pushed here :)

Copy link
Member

@maerhart maerhart left a comment

Choose a reason for hiding this comment

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

Thanks! This looks really nice already, just one indentation issue and maybe improve the regression tests a little.

lib/Target/ExportSMTLIB/ExportSMTLIB.cpp Outdated Show resolved Hide resolved
test/Target/ExportSMTLIB/attributes.mlir Show resolved Hide resolved
Comment on lines +99 to +100
// CHECK: :pattern ((let (([[V39:.+]] (= [[V34]] 3)))
// CHECK: [[V39]]) (let (([[V40:.+]] (= [[V35]] 4)))
Copy link
Member

Choose a reason for hiding this comment

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

It might be a good idea to add {{$}} at the end of a line to check that there aren't any extra closing parentheses since we had issues with that before.

lib/Target/ExportSMTLIB/ExportSMTLIB.cpp Outdated Show resolved Hide resolved
newInfo.stream.indent(newInfo.indentLevel);
info.indentLevel + indentExt, info.openParens);
if(weight !=0 || !patterns.empty())
newInfo.stream.indent(0);
Copy link
Member

Choose a reason for hiding this comment

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

Why is the replaced newInfo.stream.indent(newInfo.indentLevel); not the right thing to do here (assuming we move the ( ! printing just after this line).

Copy link
Member

@maerhart maerhart left a comment

Choose a reason for hiding this comment

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

Awesome, thanks!

@maerhart maerhart merged commit fa0e614 into llvm:main May 28, 2024
4 checks passed
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.

None yet

3 participants