-
Notifications
You must be signed in to change notification settings - Fork 276
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
Conversation
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.
A few minor points but looks pretty good to me!
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.
Thanks a lot for working on this!
|
||
|
||
|
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.
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); |
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.
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?
info.indentLevel + indentExt, info.openParens); | |
info.indentLevel + indentExt, 0); |
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.
Right, I was having some problem wiht parentheses and I was testing what this changed, but forgot to put it back afterwards! thanks
@@ -343,7 +353,42 @@ struct ExpressionVisitor | |||
info.stream << ")"; | |||
|
|||
if (weight != 0) | |||
info.stream << " :weight " << weight << ")"; | |||
info.stream << " :weight " << weight; | |||
if(!patterns.empty()){ |
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.
Forgot to run git-clang-format
?
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.
yes 🤦♀️
for (auto [i, arg] : llvm::enumerate(p.getArguments())) { | ||
info.valueMap.insert(arg, argNames[i].str()); | ||
} |
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.
Nit: loops where the body is just one statement usually omit the curly braces
// CHECK: (let (([[V31:.+]] (=> [[V30:.+]] true))) | ||
// CHECK: [[V31:.+]])) :weight 2 | ||
// CHECK :pattern ( ( let (([[V32:.+]] (= [[V28:.+]] [[V29:.+]]))) | ||
// CHECK: [[V32:.+]])))))) |
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.
same here
newInfo.stream.indent(newInfo.indentLevel); | ||
info.indentLevel + indentExt, info.openParens); | ||
if(weight !=0 || !patterns.empty()) | ||
newInfo.stream.indent(0); |
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.
Can you explain why we want 0 indentation here instead of info.indentLevel
as well?
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.
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).
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.
It is actually correct! I had misunderstood your previous comment, thanks
Value yieldedValue = p.front().getTerminator()->getOperand(0); | ||
|
||
worklist.push_back(yieldedValue); |
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.
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.
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.
Quick questin about this, when (in the tests) I try to add multiple operands I get this error 2 operands present, but expected 1
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.
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:
circt/test/Conversion/SMTToZ3LLVM/smt-to-z3-llvm.mlir
Lines 365 to 378 in 62fbb3a
%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 | |
} |
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.
oh thanks for the reference! There was actually another syntax error I had not considered
llvm
Outdated
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.
Accidental LLVM bump?
6da87b8
to
0824f09
Compare
Sorry @luisacicolini, looks like rebasing with the correct LLVM commit made GitHub think I was the author of the commits on the branch! |
No worries, there's no need to stress. If you need help with something, let me know :) |
@maerhart all fixed now, this currently only supports single patterns, will open a new PR for the multi pattern :) |
Adding multi patterns turned out to require just a few changes compared to this version, so now everything is pushed here :) |
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.
Thanks! This looks really nice already, just one indentation issue and maybe improve the regression tests a little.
// CHECK: :pattern ((let (([[V39:.+]] (= [[V34]] 3))) | ||
// CHECK: [[V39]]) (let (([[V40:.+]] (= [[V35]] 4))) |
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.
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.
newInfo.stream.indent(newInfo.indentLevel); | ||
info.indentLevel + indentExt, info.openParens); | ||
if(weight !=0 || !patterns.empty()) | ||
newInfo.stream.indent(0); |
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.
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).
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.
Awesome, thanks!
This PR addressess issue #6913 to enable the support of attributes in the SMTLIB export pass.