forked from llvm/clangir
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Add new operations: `GotoOp` and `LabelOp` and inserts them in the codegen - Adds a pass that replaces `goto` operations with branches to the corresponded blocks (and erases `LabelOp` from CIR) - Update verifiers and tests
- Loading branch information
Showing
16 changed files
with
488 additions
and
77 deletions.
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,54 @@ | ||
#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 GotoSolverPass : public GotoSolverBase<GotoSolverPass> { | ||
|
||
GotoSolverPass() = default; | ||
void runOnOperation() override; | ||
}; | ||
|
||
static void process(mlir::cir::FuncOp func) { | ||
|
||
mlir::OpBuilder rewriter(func.getContext()); | ||
std::map<std::string, Block *> labels; | ||
std::vector<mlir::cir::GotoOp> gotos; | ||
|
||
func.getBody().walk([&](mlir::Operation *op) { | ||
if (auto lab = dyn_cast<mlir::cir::LabelOp>(op)) { | ||
labels.emplace(lab.getLabel().str(), lab->getBlock()); | ||
lab.erase(); | ||
} else if (auto goTo = dyn_cast<mlir::cir::GotoOp>(op)) { | ||
gotos.push_back(goTo); | ||
} | ||
}); | ||
|
||
for (auto goTo : gotos) { | ||
mlir::OpBuilder::InsertionGuard guard(rewriter); | ||
rewriter.setInsertionPoint(goTo); | ||
auto dest = labels[goTo.getLabel().str()]; | ||
rewriter.create<mlir::cir::BrOp>(goTo.getLoc(), dest); | ||
goTo.erase(); | ||
} | ||
} | ||
|
||
void GotoSolverPass::runOnOperation() { | ||
SmallVector<Operation *, 16> ops; | ||
getOperation()->walk([&](mlir::cir::FuncOp op) { process(op); }); | ||
} | ||
|
||
} // namespace | ||
|
||
std::unique_ptr<Pass> mlir::createGotoSolverPass() { | ||
return std::make_unique<GotoSolverPass>(); | ||
} |
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.