Refactor FoldConstantPass with generic framework#176
Merged
n0thingNoob merged 12 commits intocoredac:mainfrom Oct 25, 2025
Merged
Refactor FoldConstantPass with generic framework#176n0thingNoob merged 12 commits intocoredac:mainfrom
n0thingNoob merged 12 commits intocoredac:mainfrom
Conversation
tancheng
reviewed
Oct 24, 2025
lib/NeuraDialect/Transforms/Optimizations/HwAgnosticOpt/FoldConstantPass.cpp
Outdated
Show resolved
Hide resolved
lib/NeuraDialect/Transforms/Optimizations/HwAgnosticOpt/FoldConstantPass.cpp
Outdated
Show resolved
Hide resolved
lib/NeuraDialect/Transforms/Optimizations/HwAgnosticOpt/FoldConstantPass.cpp
Outdated
Show resolved
Hide resolved
lib/NeuraDialect/Transforms/Optimizations/HwAgnosticOpt/FoldConstantPass.cpp
Outdated
Show resolved
Hide resolved
lib/NeuraDialect/Transforms/Optimizations/HwAgnosticOpt/FoldConstantPass.cpp
Outdated
Show resolved
Hide resolved
lib/NeuraDialect/Transforms/Optimizations/HwAgnosticOpt/FoldConstantPass.cpp
Show resolved
Hide resolved
Collaborator
Author
PR Summary1. FoldConstantPass.cppGeneric Framework: Introduced Four Special Cases:
2. TransformCtrlToDataFlowPass.cppRPO Optimization: Implemented reverse post-order traversal when flattening blocks to maintain SSA dominance (definitions before uses). |
tancheng
approved these changes
Oct 25, 2025
lib/NeuraDialect/Transforms/Optimizations/HwAgnosticOpt/FoldConstantPass.cpp
Show resolved
Hide resolved
lib/NeuraDialect/Transforms/Optimizations/HwAgnosticOpt/FoldConstantPass.cpp
Outdated
Show resolved
Hide resolved
lib/NeuraDialect/Transforms/Optimizations/HwAgnosticOpt/FoldConstantPass.cpp
Outdated
Show resolved
Hide resolved
lib/NeuraDialect/Transforms/Optimizations/HwAgnosticOpt/FoldConstantPass.cpp
Outdated
Show resolved
Hide resolved
lib/NeuraDialect/Transforms/Optimizations/HwAgnosticOpt/FoldConstantPass.cpp
Outdated
Show resolved
Hide resolved
tancheng
reviewed
Oct 25, 2025
Contributor
|
Excellent work @YanzhouTang~! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The current
--fold-constantpass has a limitation: it can only fold right operand constants for non-commutative operations (such asfsub,fdiv,sub,div), and cannot fold left operand constants.Since our hardware supports folding any operand (left, right, or multiple operands), we should enhance the pass to support arbitrary operand constant folding.
Solution
This PR refactors the
FoldConstantPasswith a generic framework that supports folding constants from any operand position.The pass scans operands from right to left to determine which constants to fold.
When an operand is a constant, it is removed from the operand list and stored as an attribute instead.
Special case: If all operands are constants, the leftmost operand is preserved (since MLIR requires operations to have at least one operand).