Skip to content

Commit

Permalink
[CIR] Enable per-pass IR printing (#234)
Browse files Browse the repository at this point in the history
Enabling IR printing with --mlir-print-ir-after=passName1, passName2.
This requires all CIR passes to be registered at startup time.
  • Loading branch information
htyu authored and lanza committed Oct 25, 2023
1 parent eaca774 commit 9155ecc
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 3 deletions.
4 changes: 1 addition & 3 deletions clang/lib/CIR/Dialect/Transforms/LifetimeCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1907,15 +1907,13 @@ void LifetimeCheckPass::checkOperation(Operation *op) {
}

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

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

Expand Down
1 change: 1 addition & 0 deletions clang/lib/FrontendTool/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ set(deps)
if(CLANG_ENABLE_CIR)
list(APPEND link_libs
clangCIRFrontendAction
MLIRCIRTransforms
MLIRIR
MLIRPass
)
Expand Down
2 changes: 2 additions & 0 deletions clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "mlir/IR/AsmState.h"
#include "mlir/IR/MLIRContext.h"
#include "mlir/Pass/PassManager.h"
#include "clang/CIR/Dialect/Passes.h"
#include "clang/CIRFrontendAction/CIRGenAction.h"
#endif

Expand Down Expand Up @@ -317,6 +318,7 @@ bool ExecuteCompilerInvocation(CompilerInstance *Clang) {
#endif
#if CLANG_ENABLE_CIR
if (!Clang->getFrontendOpts().MLIRArgs.empty()) {
mlir::registerCIRPasses();
mlir::registerMLIRContextCLOptions();
mlir::registerPassManagerCLOptions();
mlir::registerAsmPrinterCLOptions();
Expand Down
4 changes: 4 additions & 0 deletions clang/test/CIR/mlirprint.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// RUN: %clang_cc1 -fclangir-enable -emit-cir -mmlir --mlir-print-ir-after-all %s -o %t.cir 2>&1 | FileCheck %s -check-prefix=CIR
// RUN: %clang_cc1 -fclangir-enable -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
// RUN: %clang_cc1 -fclangir-enable -emit-cir -mmlir --mlir-print-ir-after=cir-drop-ast %s -o %t.cir 2>&1 | FileCheck %s -check-prefix=CIRPASS

int foo(void) {
int i = 3;
Expand All @@ -15,3 +16,6 @@ int foo(void) {
// LLVM: llvm.func @foo() -> i32
// LLVM: IR Dump After VerifierPass on [module] ***
// LLVM: define i32 @foo()

// CIRPASS-NOT: IR Dump After MergeCleanups
// CIRPASS: IR Dump After DropAST

0 comments on commit 9155ecc

Please sign in to comment.