#include "PassDetail.h"
#include "mlir/IR/SymbolTable.h"
#include "mlir/Pass/PassManager.h"
#include "mlir/Support/FileUtilities.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/FormatVariadic.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/ToolOutputFile.h"
usingnamespacemlir;
usingnamespacemlir::detail;
namespace {
class IRPrinterInstrumentation : public PassInstrumentation { … };
}
static void printIR(Operation *op, bool printModuleScope, raw_ostream &out,
OpPrintingFlags flags) { … }
void IRPrinterInstrumentation::runBeforePass(Pass *pass, Operation *op) { … }
void IRPrinterInstrumentation::runAfterPass(Pass *pass, Operation *op) { … }
void IRPrinterInstrumentation::runAfterPassFailed(Pass *pass, Operation *op) { … }
PassManager::IRPrinterConfig::IRPrinterConfig(bool printModuleScope,
bool printAfterOnlyOnChange,
bool printAfterOnlyOnFailure,
OpPrintingFlags opPrintingFlags)
: … { … }
PassManager::IRPrinterConfig::~IRPrinterConfig() = default;
void PassManager::IRPrinterConfig::printBeforeIfEnabled(
Pass *pass, Operation *operation, PrintCallbackFn printCallback) { … }
void PassManager::IRPrinterConfig::printAfterIfEnabled(
Pass *pass, Operation *operation, PrintCallbackFn printCallback) { … }
namespace {
struct BasicIRPrinterConfig : public PassManager::IRPrinterConfig { … };
}
static std::pair<SmallVector<std::pair<std::string, StringRef>>, std::string>
getOpAndSymbolNames(Operation *op, StringRef passName,
llvm::DenseMap<Operation *, unsigned> &counters) { … }
static LogicalResult createDirectoryOrPrintErr(llvm::StringRef dirPath) { … }
static std::unique_ptr<llvm::ToolOutputFile>
createTreePrinterOutputPath(Operation *op, llvm::StringRef passArgument,
llvm::StringRef rootDir,
llvm::DenseMap<Operation *, unsigned> &counters) { … }
namespace {
struct FileTreeIRPrinterConfig : public PassManager::IRPrinterConfig { … };
}
void PassManager::enableIRPrinting(std::unique_ptr<IRPrinterConfig> config) { … }
void PassManager::enableIRPrinting(
std::function<bool(Pass *, Operation *)> shouldPrintBeforePass,
std::function<bool(Pass *, Operation *)> shouldPrintAfterPass,
bool printModuleScope, bool printAfterOnlyOnChange,
bool printAfterOnlyOnFailure, raw_ostream &out,
OpPrintingFlags opPrintingFlags) { … }
void PassManager::enableIRPrintingToFileTree(
std::function<bool(Pass *, Operation *)> shouldPrintBeforePass,
std::function<bool(Pass *, Operation *)> shouldPrintAfterPass,
bool printModuleScope, bool printAfterOnlyOnChange,
bool printAfterOnlyOnFailure, StringRef printTreeDir,
OpPrintingFlags opPrintingFlags) { … }