Skip to content

Commit d681e79

Browse files
author
git apple-llvm automerger
committed
Merge commit '132f7867ff8f' from llvm.org/main into next
2 parents c447b22 + 132f786 commit d681e79

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

mlir/lib/Pass/IRPrinting.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "mlir/IR/SymbolTable.h"
1111
#include "mlir/Pass/PassManager.h"
1212
#include "mlir/Support/FileUtilities.h"
13+
#include "llvm/ADT/STLExtras.h"
1314
#include "llvm/ADT/StringExtras.h"
1415
#include "llvm/Support/FileSystem.h"
1516
#include "llvm/Support/FormatVariadic.h"
@@ -210,22 +211,26 @@ struct BasicIRPrinterConfig : public PassManager::IRPrinterConfig {
210211
/// `op` first, `op` last). This information is used to construct the directory
211212
/// tree for the `FileTreeIRPrinterConfig` below.
212213
/// The counter for `op` will be incremented by this call.
213-
static std::pair<SmallVector<std::pair<std::string, StringRef>>, std::string>
214+
static std::pair<SmallVector<std::pair<std::string, std::string>>, std::string>
214215
getOpAndSymbolNames(Operation *op, StringRef passName,
215216
llvm::DenseMap<Operation *, unsigned> &counters) {
216-
SmallVector<std::pair<std::string, StringRef>> pathElements;
217+
SmallVector<std::pair<std::string, std::string>> pathElements;
217218
SmallVector<unsigned> countPrefix;
218219

219220
Operation *iter = op;
220221
++counters.try_emplace(op, -1).first->second;
221222
while (iter) {
222223
countPrefix.push_back(counters[iter]);
223-
StringAttr symbolName =
224+
StringAttr symbolNameAttr =
224225
iter->getAttrOfType<StringAttr>(SymbolTable::getSymbolAttrName());
226+
std::string symbolName =
227+
symbolNameAttr ? symbolNameAttr.str() : "no-symbol-name";
228+
llvm::replace(symbolName, '/', '_');
229+
llvm::replace(symbolName, '\\', '_');
230+
225231
std::string opName =
226232
llvm::join(llvm::split(iter->getName().getStringRef().str(), '.'), "_");
227-
pathElements.emplace_back(opName, symbolName ? symbolName.strref()
228-
: "no-symbol-name");
233+
pathElements.emplace_back(std::move(opName), std::move(symbolName));
229234
iter = iter->getParentOp();
230235
}
231236
// Return in the order of top level (module) down to `op`.

mlir/test/Pass/ir-printing-file-tree.mlir

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
// RUN: -mlir-print-ir-after-all
1616
// RUN: test -f %t/builtin_module_outer/0_canonicalize.mlir
1717
// RUN: test -f %t/builtin_module_outer/1_canonicalize.mlir
18-
// RUN: test -f %t/builtin_module_outer/func_func_symA/1_0_cse.mlir
18+
// RUN: test -f %t/builtin_module_outer/func_func_sym_A/1_0_cse.mlir
19+
// RUN: test -f %t/builtin_module_outer/func_func_sym_backslash/1_0_cse.mlir
1920
// RUN: test -f %t/builtin_module_outer/builtin_module_inner/1_0_canonicalize.mlir
2021
// RUN: test -f %t/builtin_module_outer/builtin_module_inner/func_func_symB/1_0_0_cse.mlir
2122
// RUN: test -f %t/builtin_module_outer/builtin_module_inner/func_func_symB/1_0_1_canonicalize.mlir
@@ -26,7 +27,10 @@
2627

2728
builtin.module @outer {
2829

29-
func.func @symA() {
30+
func.func @"sym/A"() {
31+
return
32+
}
33+
func.func @"sym\\backslash"() {
3034
return
3135
}
3236

@@ -38,4 +42,6 @@ builtin.module @outer {
3842
return
3943
}
4044
}
45+
46+
4147
}

0 commit comments

Comments
 (0)