-
Notifications
You must be signed in to change notification settings - Fork 15
feat: Implement AffineToNeura pass with loop nest analysis and valid signal optimization #173
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
Merged
guosran
merged 32 commits into
coredac:main
from
guosran:feature/allow-steering-spatial-temporal
Nov 7, 2025
Merged
Changes from 11 commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
e0fdc3f
Support spatial-temporal loop control, and parsing perfect nested loo…
5637cad
Merge origin/main and remove allow-steering-spatial-temporal option
fc3792a
Fix test: check if there exists neura.load_indexed/store_indexed, and…
85a8a28
Fix compilation errors in AffineToNeuraPass
e09519c
Completely rewrite AffineToNeura pass with dataflow-style loop lowering
e57c3e0
Add comprehensive test suite and fix code style
bb4816a
feat(AffineToNeura): Add loop nest analysis and valid signal reuse op…
cb6f657
refactor: Reorganize AffineToNeura tests - split into focused test files
56a16ba
Fixed know error
5a2e111
fix: Pass empty ValueRange to inlineBlockBefore
bb86bdd
fix: Correctly pass loop_index to inlineBlockBefore
53cd897
style: rename LoopInfo fields to snake_case
ce811c0
refactor: remove unused fused operations (CarryInvariantOp, Condition…
c9950fc
refactor: improve test readability
07f83da
test: add example of unsupported case (affine.if)
0357b5c
refactor: remove hard 3D dimension constraint
f83f8ad
docs: add comment explaining AffineApplyOp single-result check
1571c5a
docs: add comprehensive examples for all conversions
f063aec
fix: remove ConstantOp from steering unwrapped operations.
ed2795d
Fix grant_once semantic conflict in loop control
154d3b2
1. Remove indentation in imperfect-ops-after.mlir CHECK lines
7331bf4
fix: update test files to expect constant instead of grant_once
698121c
fix: address reviewer comments on test files
e5d2243
remove: delete unsupported-dynamic-bounds.mlir test file
49cc61a
Remove confusing comments in mapping_util.cpp
bc0695c
Align is_steering_unwrapped_op with InsertDataMovPass behavior
9a59352
fix: correct FileCheck pattern in unsupported-affine-if test
00d6d55
fix: remove is_steering_unwrapped_op per reviewer feedback and fix test
0e22a58
feat: add complete multi-stage lowering demonstration for affine.if
7544c23
test: use deterministic patterns and move CHECK after code
17f512f
test: add visual separators in CHECK patterns
fadb2f0
fix: correct operation names in complex-affine-expressions test
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| //===- LoopNestAnalysis.h - Analyze affine loop nests ----------*- C++ -*-===// | ||
| // | ||
| // Loop nest analysis for affine loops. | ||
| // | ||
| // Features: | ||
| // 1. Build loop hierarchy tree (parent-child relationships, nesting depth) | ||
| // 2. Identify perfect vs imperfect nesting | ||
| // 3. Support valid signal reuse optimization for nested loops | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
| #ifndef CONVERSION_AFFINE_TO_NEURA_LOOP_NEST_ANALYSIS_H | ||
| #define CONVERSION_AFFINE_TO_NEURA_LOOP_NEST_ANALYSIS_H | ||
|
|
||
| #include "mlir/Dialect/Affine/IR/AffineOps.h" | ||
| #include "mlir/Dialect/Func/IR/FuncOps.h" | ||
| #include "mlir/IR/Operation.h" | ||
| #include "llvm/ADT/DenseMap.h" | ||
| #include "llvm/ADT/SmallVector.h" | ||
| #include <memory> | ||
|
|
||
| namespace mlir { | ||
| namespace neura { | ||
|
|
||
| /// Loop information structure - Stores all analysis information for a single loop. | ||
| struct LoopInfo { | ||
| affine::AffineForOp loop; // The loop operation itself. | ||
| LoopInfo *parent = nullptr; // Parent loop (nullptr if top-level). | ||
| llvm::SmallVector<LoopInfo *, 4> children; // Child loops list. | ||
| unsigned depth = 0; // Nesting depth (0=top-level). | ||
| bool isPerfectNest = true; // Whether it is a perfect nest. | ||
|
|
||
| // Operations list for imperfect nesting. | ||
| llvm::SmallVector<Operation *, 4> operationsBeforeChild; // Operations before child loops. | ||
tancheng marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| llvm::SmallVector<Operation *, 4> operationsAfterChild; // Operations after child loops. | ||
|
|
||
| LoopInfo(affine::AffineForOp loop) : loop(loop) {} | ||
| }; | ||
|
|
||
| /// Loop nest analysis class. | ||
| /// | ||
| /// Purpose: Provides loop hierarchy information for AffineToNeura pass to support optimization decisions. | ||
| /// | ||
| /// Usage example: | ||
| /// LoopNestAnalysis analysis(func_op); | ||
| /// analysis.dump(); // Prints analysis results. | ||
| /// LoopInfo *info = analysis.getLoopInfo(loop); | ||
| /// if (info && info->parent) { | ||
| /// // This is a nested loop, can reuse parent's valid signal. | ||
| /// } | ||
| class LoopNestAnalysis { | ||
| public: | ||
| /// Constructor - Performs loop nest analysis on the given function. | ||
| explicit LoopNestAnalysis(func::FuncOp func); | ||
|
|
||
| /// Query interfaces. | ||
| LoopInfo *getLoopInfo(affine::AffineForOp loop) const; // Gets loop information. | ||
| llvm::ArrayRef<LoopInfo *> getTopLevelLoops() const { return topLevelLoops; } // Gets top-level loops. | ||
| llvm::ArrayRef<std::unique_ptr<LoopInfo>> getAllLoops() const { return allLoops; } // Gets all loops. | ||
| bool isPerfectNest(affine::AffineForOp loop) const; // Checks if perfect nest. | ||
| LoopInfo *getParentLoop(affine::AffineForOp loop) const; // Gets parent loop. | ||
| llvm::ArrayRef<LoopInfo *> getChildLoops(affine::AffineForOp loop) const; // Gets child loops. | ||
|
|
||
| /// Debug interface - Prints analysis results. | ||
| void dump() const; | ||
|
|
||
| private: | ||
| /// Internal analysis methods. | ||
| void buildLoopNestTree(func::FuncOp func); // Builds loop hierarchy tree. | ||
| void analyzePerfectNests(); // Analyzes perfect nest characteristics. | ||
|
|
||
| /// Data members. | ||
| llvm::DenseMap<Operation *, LoopInfo *> loopMap; // Loop fast lookup table. | ||
| llvm::SmallVector<std::unique_ptr<LoopInfo>, 8> allLoops; // All loops (owns ownership). | ||
| llvm::SmallVector<LoopInfo *, 4> topLevelLoops; // Top-level loop pointers list. | ||
| }; | ||
|
|
||
| } // namespace neura | ||
| } // namespace mlir | ||
|
|
||
| #endif | ||
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
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
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
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
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.