Skip to content

Commit

Permalink
Only print intermediates when keep_intermediate=True.
Browse files Browse the repository at this point in the history
  • Loading branch information
erick-xanadu committed Sep 19, 2023
1 parent f0dfdbb commit a352ba8
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions mlir/lib/Driver/CompilerDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,11 +226,13 @@ LogicalResult runLLVMPasses(const CompilerOptions &options,
// Optimize the IR!
MPM.run(*llvmModule.get(), MAM);

llvm::raw_string_ostream rawStringOstream{outputs["PreEnzymeOpt"]};
llvmModule->print(rawStringOstream, nullptr);
const std::string &outFile = fs::path("1_PreEnzymeOpt.ll");
if (failed(dumpToFile(options, outFile, outputs["PreEnzymeOpt"]))) {
return failure();
if (options.keepIntermediate) {
llvm::raw_string_ostream rawStringOstream{outputs["PreEnzymeOpt"]};
llvmModule->print(rawStringOstream, nullptr);
const std::string &outFile = fs::path("1_PreEnzymeOpt.ll");
if (failed(dumpToFile(options, outFile, outputs["PreEnzymeOpt"]))) {
return failure();
}
}

return success();
Expand Down Expand Up @@ -270,11 +272,13 @@ LogicalResult runEnzymePasses(const CompilerOptions &options,
// Optimize the IR!
MPM.run(*llvmModule.get(), MAM);

llvm::raw_string_ostream rawStringOstream{outputs["Enzyme"]};
llvmModule->print(rawStringOstream, nullptr);
const std::string &outFile = fs::path("2_Enzyme.ll");
if (failed(dumpToFile(options, outFile, outputs["Enzyme"]))) {
return failure();
if (options.keepIntermediate) {
llvm::raw_string_ostream rawStringOstream{outputs["Enzyme"]};
llvmModule->print(rawStringOstream, nullptr);
const std::string &outFile = fs::path("2_Enzyme.ll");
if (failed(dumpToFile(options, outFile, outputs["Enzyme"]))) {
return failure();
}
}

return success();
Expand Down Expand Up @@ -314,6 +318,10 @@ LogicalResult runLowering(const CompilerOptions &options, MLIRContext *ctx, Modu
size_t pipelineIdx = 0;
auto printHandler =
[&](Pass *pass, CatalystIRPrinterConfig::PrintCallbackFn print) -> LogicalResult {
// Do not print if keepIntermediate is not set.
if (!options.keepIntermediate) {
return success();
}
auto res = pipelineTailMarkers.find(pass);
if (res != pipelineTailMarkers.end()) {
for (const auto &pn : res->second) {
Expand Down

0 comments on commit a352ba8

Please sign in to comment.