-
Notifications
You must be signed in to change notification settings - Fork 14.5k
[CIR] Upstream the basic structure of LoweringPrepare pass #148545
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] Upstream the basic structure of LoweringPrepare pass #148545
Conversation
@llvm/pr-subscribers-clang Author: Amr Hesham (AmrDeveloper) ChangesUpstream, the basic structure of the LoweringPrepare pass as a prerequisite for other ComplexType PR's Full diff: https://github.com/llvm/llvm-project/pull/148545.diff 5 Files Affected:
diff --git a/clang/include/clang/CIR/Dialect/Passes.h b/clang/include/clang/CIR/Dialect/Passes.h
index dbecf81acf7bb..02210ec0a8336 100644
--- a/clang/include/clang/CIR/Dialect/Passes.h
+++ b/clang/include/clang/CIR/Dialect/Passes.h
@@ -24,6 +24,7 @@ std::unique_ptr<Pass> createCIRCanonicalizePass();
std::unique_ptr<Pass> createCIRFlattenCFGPass();
std::unique_ptr<Pass> createCIRSimplifyPass();
std::unique_ptr<Pass> createHoistAllocasPass();
+std::unique_ptr<Pass> createLoweringPreparePass();
void populateCIRPreLoweringPasses(mlir::OpPassManager &pm);
diff --git a/clang/include/clang/CIR/Dialect/Passes.td b/clang/include/clang/CIR/Dialect/Passes.td
index de775e69f0073..59c06f2e13f22 100644
--- a/clang/include/clang/CIR/Dialect/Passes.td
+++ b/clang/include/clang/CIR/Dialect/Passes.td
@@ -33,14 +33,14 @@ def CIRSimplify : Pass<"cir-simplify"> {
let summary = "Performs CIR simplification and code optimization";
let description = [{
The pass performs semantics-preserving code simplifications and optimizations
- on CIR while maintaining strict program correctness.
-
+ on CIR while maintaining strict program correctness.
+
Unlike the `cir-canonicalize` pass, these transformations may reduce the IR's
structural similarity to the original source code as a trade-off for improved
code quality. This can affect debugging fidelity by altering intermediate
- representations of folded expressions, hoisted operations, and other
+ representations of folded expressions, hoisted operations, and other
optimized constructs.
-
+
Example transformations include ternary expression folding and code hoisting
while preserving program semantics.
}];
@@ -72,4 +72,14 @@ def CIRFlattenCFG : Pass<"cir-flatten-cfg"> {
let dependentDialects = ["cir::CIRDialect"];
}
+def LoweringPrepare : Pass<"cir-lowering-prepare"> {
+ let summary = "Preparation work before lowering to LLVM dialect";
+ let description = [{
+ This pass does preparation work for LLVM lowering. For example, it may
+ expand the global variable initialziation in a more ABI-friendly form.
+ }];
+ let constructor = "mlir::createLoweringPreparePass()";
+ let dependentDialects = ["cir::CIRDialect"];
+}
+
#endif // CLANG_CIR_DIALECT_PASSES_TD
diff --git a/clang/lib/CIR/Dialect/Transforms/CMakeLists.txt b/clang/lib/CIR/Dialect/Transforms/CMakeLists.txt
index 4dece5b57e450..18beca7b9a680 100644
--- a/clang/lib/CIR/Dialect/Transforms/CMakeLists.txt
+++ b/clang/lib/CIR/Dialect/Transforms/CMakeLists.txt
@@ -3,6 +3,7 @@ add_clang_library(MLIRCIRTransforms
CIRSimplify.cpp
FlattenCFG.cpp
HoistAllocas.cpp
+ LoweringPrepare.cpp
DEPENDS
MLIRCIRPassIncGen
diff --git a/clang/lib/CIR/Dialect/Transforms/LoweringPrepare.cpp b/clang/lib/CIR/Dialect/Transforms/LoweringPrepare.cpp
new file mode 100644
index 0000000000000..5493b86a0a321
--- /dev/null
+++ b/clang/lib/CIR/Dialect/Transforms/LoweringPrepare.cpp
@@ -0,0 +1,40 @@
+//===- LoweringPrepare.cpp - pareparation work for LLVM lowering ----------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "PassDetail.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/CIR/Dialect/IR/CIRDialect.h"
+#include "clang/CIR/Dialect/Passes.h"
+
+#include <memory>
+
+using namespace mlir;
+using namespace cir;
+
+namespace {
+struct LoweringPreparePass : public LoweringPrepareBase<LoweringPreparePass> {
+ LoweringPreparePass() = default;
+ void runOnOperation() override;
+
+ void runOnOp(Operation *op);
+};
+
+} // namespace
+
+void LoweringPreparePass::runOnOp(Operation *op) {}
+
+void LoweringPreparePass::runOnOperation() {
+ llvm::SmallVector<Operation *> opsToTransform;
+
+ for (auto *o : opsToTransform)
+ runOnOp(o);
+}
+
+std::unique_ptr<Pass> mlir::createLoweringPreparePass() {
+ return std::make_unique<LoweringPreparePass>();
+}
diff --git a/clang/lib/CIR/Lowering/CIRPasses.cpp b/clang/lib/CIR/Lowering/CIRPasses.cpp
index 7a581939580a9..5607abc98e319 100644
--- a/clang/lib/CIR/Lowering/CIRPasses.cpp
+++ b/clang/lib/CIR/Lowering/CIRPasses.cpp
@@ -31,6 +31,8 @@ mlir::LogicalResult runCIRToCIRPasses(mlir::ModuleOp theModule,
if (enableCIRSimplify)
pm.addPass(mlir::createCIRSimplifyPass());
+ pm.addPass(mlir::createLoweringPreparePass());
+
pm.enableVerifier(enableVerifier);
(void)mlir::applyPassManagerCLOptions(pm);
return pm.run(theModule);
|
@llvm/pr-subscribers-clangir Author: Amr Hesham (AmrDeveloper) ChangesUpstream, the basic structure of the LoweringPrepare pass as a prerequisite for other ComplexType PR's Full diff: https://github.com/llvm/llvm-project/pull/148545.diff 5 Files Affected:
diff --git a/clang/include/clang/CIR/Dialect/Passes.h b/clang/include/clang/CIR/Dialect/Passes.h
index dbecf81acf7bb..02210ec0a8336 100644
--- a/clang/include/clang/CIR/Dialect/Passes.h
+++ b/clang/include/clang/CIR/Dialect/Passes.h
@@ -24,6 +24,7 @@ std::unique_ptr<Pass> createCIRCanonicalizePass();
std::unique_ptr<Pass> createCIRFlattenCFGPass();
std::unique_ptr<Pass> createCIRSimplifyPass();
std::unique_ptr<Pass> createHoistAllocasPass();
+std::unique_ptr<Pass> createLoweringPreparePass();
void populateCIRPreLoweringPasses(mlir::OpPassManager &pm);
diff --git a/clang/include/clang/CIR/Dialect/Passes.td b/clang/include/clang/CIR/Dialect/Passes.td
index de775e69f0073..59c06f2e13f22 100644
--- a/clang/include/clang/CIR/Dialect/Passes.td
+++ b/clang/include/clang/CIR/Dialect/Passes.td
@@ -33,14 +33,14 @@ def CIRSimplify : Pass<"cir-simplify"> {
let summary = "Performs CIR simplification and code optimization";
let description = [{
The pass performs semantics-preserving code simplifications and optimizations
- on CIR while maintaining strict program correctness.
-
+ on CIR while maintaining strict program correctness.
+
Unlike the `cir-canonicalize` pass, these transformations may reduce the IR's
structural similarity to the original source code as a trade-off for improved
code quality. This can affect debugging fidelity by altering intermediate
- representations of folded expressions, hoisted operations, and other
+ representations of folded expressions, hoisted operations, and other
optimized constructs.
-
+
Example transformations include ternary expression folding and code hoisting
while preserving program semantics.
}];
@@ -72,4 +72,14 @@ def CIRFlattenCFG : Pass<"cir-flatten-cfg"> {
let dependentDialects = ["cir::CIRDialect"];
}
+def LoweringPrepare : Pass<"cir-lowering-prepare"> {
+ let summary = "Preparation work before lowering to LLVM dialect";
+ let description = [{
+ This pass does preparation work for LLVM lowering. For example, it may
+ expand the global variable initialziation in a more ABI-friendly form.
+ }];
+ let constructor = "mlir::createLoweringPreparePass()";
+ let dependentDialects = ["cir::CIRDialect"];
+}
+
#endif // CLANG_CIR_DIALECT_PASSES_TD
diff --git a/clang/lib/CIR/Dialect/Transforms/CMakeLists.txt b/clang/lib/CIR/Dialect/Transforms/CMakeLists.txt
index 4dece5b57e450..18beca7b9a680 100644
--- a/clang/lib/CIR/Dialect/Transforms/CMakeLists.txt
+++ b/clang/lib/CIR/Dialect/Transforms/CMakeLists.txt
@@ -3,6 +3,7 @@ add_clang_library(MLIRCIRTransforms
CIRSimplify.cpp
FlattenCFG.cpp
HoistAllocas.cpp
+ LoweringPrepare.cpp
DEPENDS
MLIRCIRPassIncGen
diff --git a/clang/lib/CIR/Dialect/Transforms/LoweringPrepare.cpp b/clang/lib/CIR/Dialect/Transforms/LoweringPrepare.cpp
new file mode 100644
index 0000000000000..5493b86a0a321
--- /dev/null
+++ b/clang/lib/CIR/Dialect/Transforms/LoweringPrepare.cpp
@@ -0,0 +1,40 @@
+//===- LoweringPrepare.cpp - pareparation work for LLVM lowering ----------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "PassDetail.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/CIR/Dialect/IR/CIRDialect.h"
+#include "clang/CIR/Dialect/Passes.h"
+
+#include <memory>
+
+using namespace mlir;
+using namespace cir;
+
+namespace {
+struct LoweringPreparePass : public LoweringPrepareBase<LoweringPreparePass> {
+ LoweringPreparePass() = default;
+ void runOnOperation() override;
+
+ void runOnOp(Operation *op);
+};
+
+} // namespace
+
+void LoweringPreparePass::runOnOp(Operation *op) {}
+
+void LoweringPreparePass::runOnOperation() {
+ llvm::SmallVector<Operation *> opsToTransform;
+
+ for (auto *o : opsToTransform)
+ runOnOp(o);
+}
+
+std::unique_ptr<Pass> mlir::createLoweringPreparePass() {
+ return std::make_unique<LoweringPreparePass>();
+}
diff --git a/clang/lib/CIR/Lowering/CIRPasses.cpp b/clang/lib/CIR/Lowering/CIRPasses.cpp
index 7a581939580a9..5607abc98e319 100644
--- a/clang/lib/CIR/Lowering/CIRPasses.cpp
+++ b/clang/lib/CIR/Lowering/CIRPasses.cpp
@@ -31,6 +31,8 @@ mlir::LogicalResult runCIRToCIRPasses(mlir::ModuleOp theModule,
if (enableCIRSimplify)
pm.addPass(mlir::createCIRSimplifyPass());
+ pm.addPass(mlir::createLoweringPreparePass());
+
pm.enableVerifier(enableVerifier);
(void)mlir::applyPassManagerCLOptions(pm);
return pm.run(theModule);
|
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.
We need to update some of the entries because they are old now, so a few comments on that, otherwise LGTM
let summary = "Preparation work before lowering to LLVM dialect"; | ||
let description = [{ | ||
This pass does preparation work for LLVM lowering. For example, it may | ||
expand the global variable initialziation in a more ABI-friendly form. |
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.
Please make the description a bit more generic (not LLVM specific) since it also covers the core dialect path in the incubator.
@@ -72,4 +72,14 @@ def CIRFlattenCFG : Pass<"cir-flatten-cfg"> { | |||
let dependentDialects = ["cir::CIRDialect"]; | |||
} | |||
|
|||
def LoweringPrepare : Pass<"cir-lowering-prepare"> { | |||
let summary = "Preparation work before lowering to LLVM dialect"; |
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.
Preparation work before lowering to LLVM dialect
-> Lower to more fine-grained CIR operations before lowering to other dialects
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.
lgtm
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/195/builds/11862 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/197/builds/7022 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/18/builds/19024 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/143/builds/9297 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/113/builds/8104 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/153/builds/38150 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/6/builds/10413 Here is the relevant piece of the build log for the reference
|
Upstream, the basic structure of the LoweringPrepare pass as a prerequisite for other ComplexType PR's
#141365