-
Notifications
You must be signed in to change notification settings - Fork 100
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
[CIR] Introduce a flattening pass #516
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
ce7c238
[CIR] A skeleton for the structured cfg pass
gitoleg 9d4c51d
adds the pass right after the lowering prepare
gitoleg 92b5586
Refactoring And Unifrom flat cir passes
gitoleg 3565272
emit-flat-cir option
gitoleg 058d28d
kind of test fixing
gitoleg 6594249
silly test
gitoleg d2c6640
refactoring
gitoleg d97f9a1
refactoring
gitoleg 3fa07d7
test updated
gitoleg 8bd1e7b
clang-format ...
gitoleg 5d4c149
minor fix
gitoleg 1714c8a
flat cir -> cir flat
gitoleg 399f8bd
StructuredCFG -> FlattenCFG
gitoleg f324404
minor fixes
gitoleg daec97f
minor bug fix
gitoleg 5a876d9
clang-format ...
gitoleg 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 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 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 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 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 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 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 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 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 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 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 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,60 @@ | ||
//====- FlattenCFG.cpp - Flatten CIR CFG ----------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This file implements pass that inlines CIR operations regions into the parent | ||
// function region. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
#include "PassDetail.h" | ||
#include "mlir/Dialect/Func/IR/FuncOps.h" | ||
#include "mlir/IR/PatternMatch.h" | ||
#include "mlir/Support/LogicalResult.h" | ||
#include "mlir/Transforms/DialectConversion.h" | ||
#include "mlir/Transforms/GreedyPatternRewriteDriver.h" | ||
#include "clang/CIR/Dialect/IR/CIRDialect.h" | ||
#include "clang/CIR/Dialect/Passes.h" | ||
|
||
using namespace mlir; | ||
using namespace mlir::cir; | ||
|
||
namespace { | ||
|
||
struct FlattenCFGPass : public FlattenCFGBase<FlattenCFGPass> { | ||
|
||
FlattenCFGPass() = default; | ||
void runOnOperation() override; | ||
}; | ||
|
||
void populateFlattenCFGPatterns(RewritePatternSet &patterns) { | ||
// TODO: add patterns here | ||
} | ||
|
||
void FlattenCFGPass::runOnOperation() { | ||
RewritePatternSet patterns(&getContext()); | ||
populateFlattenCFGPatterns(patterns); | ||
|
||
// Collect operations to apply patterns. | ||
SmallVector<Operation *, 16> ops; | ||
getOperation()->walk<mlir::WalkOrder::PostOrder>([&](Operation *op) { | ||
// TODO: push back operations here | ||
}); | ||
|
||
// Apply patterns. | ||
if (applyOpPatternsAndFold(ops, std::move(patterns)).failed()) | ||
signalPassFailure(); | ||
} | ||
|
||
} // namespace | ||
|
||
namespace mlir { | ||
|
||
std::unique_ptr<Pass> createFlattenCFGPass() { | ||
return std::make_unique<FlattenCFGPass>(); | ||
} | ||
|
||
} // namespace mlir |
This file contains 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 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 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 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 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 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.
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 does
internal
means? I don't understand why this needs to be renamed.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.
internal
here is a hint that this pass can't be run with any CIR input like it was before. Now the pre requirement is our newcir-flatten-cfg
pass. I would deprecatecreateConvertCIRToLLVMPass
of even remove it from the interface, but it;s up to you to decide.And the pass need to be renamed since we register a pipeline in
cir-opt
with the same name - in order to guarantee any cir input is stiil valid as it was earlier - i.e. that first it will be processed bycir-flatten-cfg
pass and then will go to the lowering.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'm down for simplifying and unifying as much as possible, but can you address it in a follow up PR.
Perhaps it should be named
cir-flat-to-llvm
, or something like that.Since it would be wrong to run
cir-flat-to-llvm
without runningcir-flatten-cfg
, we should makecir-flat-to-llvm
pass to requirecir-flatten-cfg
pass to be run before.Seems like all the changes for this comment should be addressed together in another PR.