Skip to content

Commit c876e84

Browse files
htyulanza
authored andcommitted
[CIR] Enable per-pass IR printing (llvm#234)
Enabling IR printing with --mlir-print-ir-after=passName1, passName2. This requires all CIR passes to be registered at startup time.
1 parent 0bd79e1 commit c876e84

File tree

4 files changed

+8
-3
lines changed

4 files changed

+8
-3
lines changed

clang/lib/CIR/Dialect/Transforms/LifetimeCheck.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1903,15 +1903,13 @@ void LifetimeCheckPass::checkOperation(Operation *op) {
19031903
}
19041904

19051905
void LifetimeCheckPass::runOnOperation() {
1906+
assert(astCtx && "Missing ASTContext, please construct with the right ctor");
19061907
opts.parseOptions(*this);
19071908
Operation *op = getOperation();
19081909
checkOperation(op);
19091910
}
19101911

19111912
std::unique_ptr<Pass> mlir::createLifetimeCheckPass() {
1912-
// FIXME: MLIR requres a default "constructor", but should never
1913-
// be used.
1914-
llvm_unreachable("Check requires clang::ASTContext, use the other ctor");
19151913
return std::make_unique<LifetimeCheckPass>();
19161914
}
19171915

clang/lib/FrontendTool/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ set(deps)
1717
if(CLANG_ENABLE_CIR)
1818
list(APPEND link_libs
1919
clangCIRFrontendAction
20+
MLIRCIRTransforms
2021
MLIRIR
2122
MLIRPass
2223
)

clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include "mlir/IR/AsmState.h"
3737
#include "mlir/IR/MLIRContext.h"
3838
#include "mlir/Pass/PassManager.h"
39+
#include "clang/CIR/Dialect/Passes.h"
3940
#include "clang/CIRFrontendAction/CIRGenAction.h"
4041
#endif
4142

@@ -323,6 +324,7 @@ bool ExecuteCompilerInvocation(CompilerInstance *Clang) {
323324
#endif
324325
#if CLANG_ENABLE_CIR
325326
if (!Clang->getFrontendOpts().MLIRArgs.empty()) {
327+
mlir::registerCIRPasses();
326328
mlir::registerMLIRContextCLOptions();
327329
mlir::registerPassManagerCLOptions();
328330
mlir::registerAsmPrinterCLOptions();

clang/test/CIR/mlirprint.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// RUN: %clang_cc1 -fclangir -emit-cir -mmlir --mlir-print-ir-after-all %s -o %t.cir 2>&1 | FileCheck %s -check-prefix=CIR
22
// RUN: %clang_cc1 -fclangir -emit-llvm -mmlir --mlir-print-ir-after-all -mllvm -print-after-all %s -o %t.ll 2>&1 | FileCheck %s -check-prefix=CIR -check-prefix=LLVM
3+
// RUN: %clang_cc1 -fclangir -emit-cir -mmlir --mlir-print-ir-after=cir-drop-ast %s -o %t.cir 2>&1 | FileCheck %s -check-prefix=CIRPASS
34

45
int foo(void) {
56
int i = 3;
@@ -15,3 +16,6 @@ int foo(void) {
1516
// LLVM: llvm.func @foo() -> i32
1617
// LLVM: IR Dump After
1718
// LLVM: define i32 @foo()
19+
20+
// CIRPASS-NOT: IR Dump After MergeCleanups
21+
// CIRPASS: IR Dump After DropAST

0 commit comments

Comments
 (0)