Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions mlir/lib/Pass/IRPrinting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "mlir/IR/SymbolTable.h"
#include "mlir/Pass/PassManager.h"
#include "mlir/Support/FileUtilities.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/FormatVariadic.h"
Expand Down Expand Up @@ -210,22 +211,26 @@ struct BasicIRPrinterConfig : public PassManager::IRPrinterConfig {
/// `op` first, `op` last). This information is used to construct the directory
/// tree for the `FileTreeIRPrinterConfig` below.
/// The counter for `op` will be incremented by this call.
static std::pair<SmallVector<std::pair<std::string, StringRef>>, std::string>
static std::pair<SmallVector<std::pair<std::string, std::string>>, std::string>
getOpAndSymbolNames(Operation *op, StringRef passName,
llvm::DenseMap<Operation *, unsigned> &counters) {
SmallVector<std::pair<std::string, StringRef>> pathElements;
SmallVector<std::pair<std::string, std::string>> pathElements;
SmallVector<unsigned> countPrefix;

Operation *iter = op;
++counters.try_emplace(op, -1).first->second;
while (iter) {
countPrefix.push_back(counters[iter]);
StringAttr symbolName =
StringAttr symbolNameAttr =
iter->getAttrOfType<StringAttr>(SymbolTable::getSymbolAttrName());
std::string symbolName =
symbolNameAttr ? symbolNameAttr.str() : "no-symbol-name";
llvm::replace(symbolName, '/', '_');
llvm::replace(symbolName, '\\', '_');

std::string opName =
llvm::join(llvm::split(iter->getName().getStringRef().str(), '.'), "_");
pathElements.emplace_back(opName, symbolName ? symbolName.strref()
: "no-symbol-name");
pathElements.emplace_back(std::move(opName), std::move(symbolName));
iter = iter->getParentOp();
}
// Return in the order of top level (module) down to `op`.
Expand Down
10 changes: 8 additions & 2 deletions mlir/test/Pass/ir-printing-file-tree.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
// RUN: -mlir-print-ir-after-all
// RUN: test -f %t/builtin_module_outer/0_canonicalize.mlir
// RUN: test -f %t/builtin_module_outer/1_canonicalize.mlir
// RUN: test -f %t/builtin_module_outer/func_func_symA/1_0_cse.mlir
// RUN: test -f %t/builtin_module_outer/func_func_sym_A/1_0_cse.mlir
// RUN: test -f %t/builtin_module_outer/func_func_sym_backslash/1_0_cse.mlir
// RUN: test -f %t/builtin_module_outer/builtin_module_inner/1_0_canonicalize.mlir
// RUN: test -f %t/builtin_module_outer/builtin_module_inner/func_func_symB/1_0_0_cse.mlir
// RUN: test -f %t/builtin_module_outer/builtin_module_inner/func_func_symB/1_0_1_canonicalize.mlir
Expand All @@ -26,7 +27,10 @@

builtin.module @outer {

func.func @symA() {
func.func @"sym/A"() {
return
}
func.func @"sym\\backslash"() {
return
}

Expand All @@ -38,4 +42,6 @@ builtin.module @outer {
return
}
}


}