-
Notifications
You must be signed in to change notification settings - Fork 15
Provide predicated data type #23
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
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
8c67e60
[feature] Include predicate operand for each op
tancheng 6979ace
[feature] Transform ctrl to data flow
tancheng baf57aa
[test] Update insert-data-mov
tancheng 13b965f
[test] Update Clang version
tancheng d76f907
[feature] Provide predicatedData and corresponding pass to apply this…
tancheng 5473af9
Merge branch 'main' into ctrl_flow
tancheng 8dc1a35
[fix] Resolve merge conflicts
tancheng 9b94e87
[refactor] Comments
tancheng 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
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
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,104 @@ | ||
| #include "NeuraDialect/NeuraDialect.h" | ||
| #include "NeuraDialect/NeuraOps.h" | ||
| #include "NeuraDialect/NeuraPasses.h" | ||
| #include "mlir/Dialect/Func/IR/FuncOps.h" | ||
| #include "mlir/Dialect/LLVMIR/LLVMDialect.h" | ||
| #include "mlir/IR/PatternMatch.h" | ||
| #include "mlir/Pass/Pass.h" | ||
| #include "mlir/Transforms/GreedyPatternRewriteDriver.h" | ||
|
|
||
| using namespace mlir; | ||
|
|
||
| #define GEN_PASS_DEF_InsertDataMov | ||
| #include "NeuraDialect/NeuraPasses.h.inc" | ||
|
|
||
| namespace { | ||
| struct InsertDataMovForNeuraOps : public RewritePattern { | ||
| InsertDataMovForNeuraOps(MLIRContext *context) | ||
| : RewritePattern(/*matchAnyOpTypeTag=*/MatchAnyOpTypeTag(), /*benefit=*/1, context) {} | ||
|
|
||
| LogicalResult matchAndRewrite(Operation *op, PatternRewriter &rewriter) const override { | ||
| if (op->getDialect()->getNamespace() != "neura" || | ||
| isa<neura::DataMovOp>(op)) { | ||
| return failure(); | ||
| } | ||
|
|
||
| // Skips ops that already being inserted mov on the operands. | ||
| bool allInputsAreMov = llvm::all_of(op->getOperands(), [](Value v) { | ||
| return isa_and_nonnull<neura::DataMovOp>(v.getDefiningOp()); | ||
| }); | ||
| if (allInputsAreMov) { | ||
| return failure(); | ||
| } | ||
|
|
||
| // Makes sure none of the operand has being processed. | ||
| bool hasAnyMovInput = llvm::any_of(op->getOperands(), [](Value v) { | ||
| return isa_and_nonnull<neura::DataMovOp>(v.getDefiningOp()); | ||
| }); | ||
| assert(!hasAnyMovInput && "Unexpected: operand already wrapped in neura.mov"); | ||
|
|
||
| Location loc = op->getLoc(); | ||
|
|
||
| // Wraps operands in mov. | ||
| SmallVector<Value> newOperands; | ||
| for (Value operand : op->getOperands()) { | ||
| auto mov = rewriter.create<neura::DataMovOp>(loc, operand.getType(), operand); | ||
| newOperands.push_back(mov); | ||
| } | ||
|
|
||
| // Clones op with new operands. | ||
| OperationState state(loc, op->getName()); | ||
| state.addOperands(newOperands); | ||
| state.addTypes(op->getResultTypes()); | ||
| state.addAttributes(op->getAttrs()); | ||
|
|
||
| Operation *newOp = rewriter.create(state); | ||
| rewriter.replaceOp(op, newOp->getResults()); | ||
| return success(); | ||
| } | ||
| }; | ||
|
|
||
| struct InsertDataMovPass | ||
| : public PassWrapper<InsertDataMovPass, OperationPass<ModuleOp>> { | ||
| MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(InsertDataMovPass) | ||
|
|
||
| StringRef getArgument() const override { return "insert-data-mov"; } | ||
| StringRef getDescription() const override { | ||
| return "Insert neura.data_mov before all neura dialect operations."; | ||
| } | ||
|
|
||
| void getDependentDialects(DialectRegistry ®istry) const override { | ||
| registry.insert<mlir::neura::NeuraDialect>(); | ||
| } | ||
|
|
||
| void runOnOperation() override { | ||
| RewritePatternSet patterns(&getContext()); | ||
| patterns.add<InsertDataMovForNeuraOps>(&getContext()); | ||
| FrozenRewritePatternSet frozen(std::move(patterns)); | ||
|
|
||
| ModuleOp module_op = getOperation(); | ||
|
|
||
| // Applies to every region inside the module (regardless of func type, | ||
| // e.g., mlir func or llvm func). | ||
| module_op.walk([&](Operation *op) { | ||
| if (!op->getRegions().empty()) { | ||
| for (Region ®ion : op->getRegions()) { | ||
| if (failed(applyPatternsAndFoldGreedily(region, frozen))) { | ||
| signalPassFailure(); | ||
| } | ||
| } | ||
| } | ||
| }); | ||
| } | ||
| }; | ||
| } // namespace | ||
|
|
||
| namespace mlir { | ||
| namespace neura { | ||
|
|
||
| std::unique_ptr<Pass> createInsertDataMovPass() { | ||
| return std::make_unique<InsertDataMovPass>(); | ||
| } | ||
|
|
||
| } // namespace neura | ||
| } // namespace mlir |
Oops, something went wrong.
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.
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.
What is the difference in functionalities between MovOp and DataMovOp
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.
DataMovis for data delivery while I also provideCtrlMov.I initially plan to have both inherited from same base Op, however, failed due to some cmake or tablegen issue. And later I found I need CtrlMov to represent the backward flow. So in the latest commit in this PR, I just give two separate MovOp.