-
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
[Moore] A new pass to delete local temporary variables. #6990
base: main
Are you sure you want to change the base?
[Moore] A new pass to delete local temporary variables. #6990
Conversation
The further IR details:
To
or
To
The above-mentioned are just one step before generating the Core IR. |
All Build and Tests are passing on my personal computer. It's so strange! |
6a09633
to
f047ad1
Compare
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.
Great to see this take shape!
It would be nice to have a bunch of tests that make sure all the different code paths through the pass' code work as expected. And that also make sure that things which the pass does not yet support (for example, myStruct.myField[42] = x
) either produce an error message or are left in their original state.
Yeah, I'll test more cases to ensure its correction. |
01e0f6b
to
068a28d
Compare
/// Parse specified files that had been translated into Moore dialect IR. After | ||
/// that simplify these files like deleting local variables, and then emit the | ||
/// resulting Moore dialect IR . | ||
static LogicalResult populateMooreTransforms(MLIRContext &context, | ||
ModuleOp module) { | ||
PassManager pm(&context); | ||
pm.addNestedPass<moore::SVModuleOp>(circt::moore::createDeleteLocalVarPass()); | ||
// TODO: like dedup pass. | ||
|
||
if (failed(pm.run(module))) | ||
return failure(); | ||
|
||
return success(); | ||
} | ||
|
||
/// Convert Moore dialect IR into core dialect IR | ||
static LogicalResult populateLowMooreToCore(MLIRContext &context, | ||
ModuleOp module) { | ||
PassManager pm(&context); | ||
pm.addPass(createConvertMooreToCorePass()); | ||
|
||
if (failed(pm.run(module))) | ||
return failure(); | ||
|
||
return success(); | ||
} | ||
|
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's great that you have dedicated populate*
functions to populate the pipeline 🥳
Instead of creating a pass manager in these functions and running it immediately, the populate functions should accept the pass manager as a function argument and then just populate it with passes (that's why the function name starts with "populate"). For example: https://github.com/llvm/circt/blob/main/lib/Firtool/Firtool.cpp#L26-L49
The firtool tool then calls these populate functions to fill in its own pass manager, and then at the very end calls pm.run
to run everything: https://github.com/llvm/circt/blob/main/tools/firtool/firtool.cpp#L377-L481
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 for your detailed explanation!
Later, I'll enumerate some examples about DeleteLocalVarPass
.
068a28d
to
a336f37
Compare
I have an example:
Or
However, these error messages are thrown by |
if (valueSymbols.count(destOp)) { | ||
if (auto srcValue = valueSymbols.lookup(srcOp)) | ||
valueSymbols.insert(destOp, srcValue); | ||
else | ||
valueSymbols.insert(destOp, op.getSrc()); | ||
|
||
isNewValue = true; | ||
} |
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.
I think all you need is an else
branch here that emits an error. Something like "cannot assign this expression". This will make sure that the user sees a proper error for anything that the pass does not yet fully support.
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.
If I don't misunderstand, I need to add an else
branch. Like if(valueSymbols.count(destOp)){...} else{error:...}
. But this will lead to global variables also triggering this error.
By the way, @dtzSiFive has mentioned that MLIR has a mem2reg pass: https://github.com/llvm/llvm-project/blob/main/mlir/lib/Transforms/Mem2Reg.cpp You might be able to rely on that pass to do the heavy lifting for getting rid of local variables. |
I'll try it again. Originally, I attempted to call |
I think the Mem2Reg pass uses op interfaces to find out what certain ops do
and how it has to handle them. You may be able to add those interfaces to
the relevant moore ops to make Mem2Reg able to work with them 🙂
|
That means we need new interfaces for specified operations 🤔 So MooreOpInterface is coming ? |
I think all you need is to add the As far as I can tell, only the MemRef and LLVMIR dialects in MLIR support mem2reg, or at least have a test for it: https://github.com/llvm/llvm-project/blob/main/mlir/test/Dialect/MemRef/mem2reg.mlir. But you may be able to look at the op definitions in the MemRef dialect to see which of the Mem2Reg op interfaces you have to implement. |
Hey, @fabianschuiki! Please review this at your convenience! Thanks in advance!
This PR is about deleting local variables.
For example:
To
Anything about code details could be pointed out.