-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[mlir][emitc] Add op modelling C expressions #71631
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
Merged
Changes from all commits
Commits
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
add_subdirectory(IR) | ||
add_subdirectory(Transforms) |
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,5 @@ | ||
set(LLVM_TARGET_DEFINITIONS Passes.td) | ||
mlir_tablegen(Passes.h.inc -gen-pass-decls -name EmitC) | ||
add_public_tablegen_target(MLIREmitCTransformsIncGen) | ||
|
||
add_mlir_doc(Passes EmitCPasses ./ -gen-pass-doc) |
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,35 @@ | ||
//===- Passes.h - Pass Entrypoints ------------------------------*- C++ -*-===// | ||
// | ||
// 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 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef MLIR_DIALECT_EMITC_TRANSFORMS_PASSES_H_ | ||
#define MLIR_DIALECT_EMITC_TRANSFORMS_PASSES_H_ | ||
|
||
#include "mlir/Pass/Pass.h" | ||
|
||
namespace mlir { | ||
namespace emitc { | ||
|
||
//===----------------------------------------------------------------------===// | ||
// Passes | ||
//===----------------------------------------------------------------------===// | ||
|
||
/// Creates an instance of the C-style expressions forming pass. | ||
std::unique_ptr<Pass> createFormExpressionsPass(); | ||
|
||
//===----------------------------------------------------------------------===// | ||
// Registration | ||
//===----------------------------------------------------------------------===// | ||
|
||
/// Generate the code for registering passes. | ||
#define GEN_PASS_REGISTRATION | ||
#include "mlir/Dialect/EmitC/Transforms/Passes.h.inc" | ||
|
||
} // namespace emitc | ||
} // namespace mlir | ||
|
||
#endif // MLIR_DIALECT_EMITC_TRANSFORMS_PASSES_H_ |
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,24 @@ | ||
//===-- Passes.td - pass definition file -------------------*- tablegen -*-===// | ||
// | ||
// 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 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef MLIR_DIALECT_EMITC_TRANSFORMS_PASSES | ||
#define MLIR_DIALECT_EMITC_TRANSFORMS_PASSES | ||
|
||
include "mlir/Pass/PassBase.td" | ||
|
||
def FormExpressions : Pass<"form-expressions"> { | ||
let summary = "Form C-style expressions from C-operator ops"; | ||
let description = [{ | ||
The pass wraps emitc ops modelling C operators in emitc.expression ops and | ||
then folds single-use expressions into their users where possible. | ||
}]; | ||
let constructor = "mlir::emitc::createFormExpressionsPass()"; | ||
let dependentDialects = ["emitc::EmitCDialect"]; | ||
} | ||
|
||
#endif // MLIR_DIALECT_EMITC_TRANSFORMS_PASSES |
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,34 @@ | ||
//===- Transforms.h - EmitC transformations as patterns --------*- C++ -*-===// | ||
// | ||
// 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 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef MLIR_DIALECT_EMITC_TRANSFORMS_TRANSFORMS_H | ||
#define MLIR_DIALECT_EMITC_TRANSFORMS_TRANSFORMS_H | ||
|
||
#include "mlir/Dialect/EmitC/IR/EmitC.h" | ||
#include "mlir/IR/PatternMatch.h" | ||
|
||
namespace mlir { | ||
namespace emitc { | ||
|
||
//===----------------------------------------------------------------------===// | ||
// Expression transforms | ||
//===----------------------------------------------------------------------===// | ||
|
||
ExpressionOp createExpression(Operation *op, OpBuilder &builder); | ||
|
||
//===----------------------------------------------------------------------===// | ||
// Populate functions | ||
//===----------------------------------------------------------------------===// | ||
|
||
/// Populates `patterns` with expression-related patterns. | ||
void populateExpressionPatterns(RewritePatternSet &patterns); | ||
|
||
} // namespace emitc | ||
} // namespace mlir | ||
|
||
#endif // MLIR_DIALECT_EMITC_TRANSFORMS_TRANSFORMS_H |
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
add_subdirectory(IR) | ||
add_subdirectory(Transforms) |
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,16 @@ | ||
add_mlir_dialect_library(MLIREmitCTransforms | ||
Transforms.cpp | ||
FormExpressions.cpp | ||
|
||
ADDITIONAL_HEADER_DIRS | ||
${MLIR_MAIN_INCLUDE_DIR}/mlir/Dialect/EmitC/Transforms | ||
|
||
DEPENDS | ||
MLIREmitCTransformsIncGen | ||
|
||
LINK_LIBS PUBLIC | ||
MLIRIR | ||
MLIRPass | ||
MLIREmitCDialect | ||
MLIRTransforms | ||
) |
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,60 @@ | ||
//===- FormExpressions.cpp - Form C-style expressions --------*- C++ -*-===// | ||
// | ||
// 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 a pass that forms EmitC operations modeling C operators | ||
// into C-style expressions using the emitc.expression op. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "mlir/Dialect/EmitC/IR/EmitC.h" | ||
#include "mlir/Dialect/EmitC/Transforms/Passes.h" | ||
#include "mlir/Dialect/EmitC/Transforms/Transforms.h" | ||
#include "mlir/Transforms/GreedyPatternRewriteDriver.h" | ||
|
||
namespace mlir { | ||
namespace emitc { | ||
#define GEN_PASS_DEF_FORMEXPRESSIONS | ||
#include "mlir/Dialect/EmitC/Transforms/Passes.h.inc" | ||
} // namespace emitc | ||
} // namespace mlir | ||
|
||
using namespace mlir; | ||
using namespace emitc; | ||
|
||
namespace { | ||
struct FormExpressionsPass | ||
: public emitc::impl::FormExpressionsBase<FormExpressionsPass> { | ||
void runOnOperation() override { | ||
Operation *rootOp = getOperation(); | ||
MLIRContext *context = rootOp->getContext(); | ||
|
||
// Wrap each C operator op with an expression op. | ||
OpBuilder builder(context); | ||
auto matchFun = [&](Operation *op) { | ||
if (emitc::ExpressionOp::isCExpression(*op)) | ||
createExpression(op, builder); | ||
}; | ||
rootOp->walk(matchFun); | ||
|
||
// Fold expressions where possible. | ||
RewritePatternSet patterns(context); | ||
populateExpressionPatterns(patterns); | ||
|
||
if (failed(applyPatternsAndFoldGreedily(rootOp, std::move(patterns)))) | ||
return signalPassFailure(); | ||
} | ||
|
||
void getDependentDialects(DialectRegistry ®istry) const override { | ||
registry.insert<emitc::EmitCDialect>(); | ||
} | ||
}; | ||
} // namespace | ||
|
||
std::unique_ptr<Pass> mlir::emitc::createFormExpressionsPass() { | ||
return std::make_unique<FormExpressionsPass>(); | ||
} |
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.