[Mlir-commits] [mlir] 61272b5 - [MLIR][LLVM] Print LLVMStructType name using printEscapedString (#139652)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Tue May 13 15:41:54 PDT 2025
Author: Bruno Cardoso Lopes
Date: 2025-05-13T15:41:50-07:00
New Revision: 61272b5a1c6ca9287450705e24509370033f9451
URL: https://github.com/llvm/llvm-project/commit/61272b5a1c6ca9287450705e24509370033f9451
DIFF: https://github.com/llvm/llvm-project/commit/61272b5a1c6ca9287450705e24509370033f9451.diff
LOG: [MLIR][LLVM] Print LLVMStructType name using printEscapedString (#139652)
LLVM struct type names need to be escaped when printed in order to allow
interesting name choices.
Added:
mlir/test/Target/LLVMIR/Import/struct.ll
Modified:
mlir/lib/Dialect/LLVMIR/IR/LLVMTypeSyntax.cpp
mlir/test/Dialect/LLVMIR/roundtrip.mlir
Removed:
################################################################################
diff --git a/mlir/lib/Dialect/LLVMIR/IR/LLVMTypeSyntax.cpp b/mlir/lib/Dialect/LLVMIR/IR/LLVMTypeSyntax.cpp
index 319bb90d9b601..0acd5c7fd80e3 100644
--- a/mlir/lib/Dialect/LLVMIR/IR/LLVMTypeSyntax.cpp
+++ b/mlir/lib/Dialect/LLVMIR/IR/LLVMTypeSyntax.cpp
@@ -11,6 +11,7 @@
#include "mlir/IR/DialectImplementation.h"
#include "llvm/ADT/ScopeExit.h"
#include "llvm/ADT/SetVector.h"
+#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/TypeSwitch.h"
using namespace mlir;
@@ -58,7 +59,9 @@ void LLVMStructType::print(AsmPrinter &printer) const {
if (isIdentified()) {
cyclicPrint = printer.tryStartCyclicPrint(*this);
- printer << '"' << getName() << '"';
+ printer << '"';
+ llvm::printEscapedString(getName(), printer.getStream());
+ printer << '"';
// If we are printing a reference to one of the enclosing structs, just
// print the name and stop to avoid infinitely long output.
if (failed(cyclicPrint)) {
diff --git a/mlir/test/Dialect/LLVMIR/roundtrip.mlir b/mlir/test/Dialect/LLVMIR/roundtrip.mlir
index 2e6acc13d1627..a0273fb1e1bf4 100644
--- a/mlir/test/Dialect/LLVMIR/roundtrip.mlir
+++ b/mlir/test/Dialect/LLVMIR/roundtrip.mlir
@@ -1045,3 +1045,11 @@ llvm.func @llvm.aarch64.neon.st3.v8i8.p0(vector<8xi8>, vector<8xi8>, vector<8xi8
llvm.mlir.global internal thread_local unnamed_addr @myglobal(-1 : i32) {addr_space = 0 : i32, alignment = 4 : i64, dso_local} : i32
// CHECK: llvm.mlir.global internal thread_local unnamed_addr @myglobal(-1 : i32) {addr_space = 0 : i32, alignment = 4 : i64, dso_local} : i32
+
+// CHECK-LABEL: llvm.func @escapedtypename
+llvm.func @escapedtypename() {
+ %0 = llvm.mlir.constant(1 : i32) : i32
+ // CHECK: llvm.alloca %0 x !llvm.struct<"bucket<string, double, '\\b'>::Iterator", (ptr, i64, i64)>
+ %1 = llvm.alloca %0 x !llvm.struct<"bucket<string, double, '\\b'>::Iterator", (ptr, i64, i64)> {alignment = 8 : i64} : (i32) -> !llvm.ptr
+ llvm.return
+}
diff --git a/mlir/test/Target/LLVMIR/Import/struct.ll b/mlir/test/Target/LLVMIR/Import/struct.ll
new file mode 100644
index 0000000000000..dd94035e585f4
--- /dev/null
+++ b/mlir/test/Target/LLVMIR/Import/struct.ll
@@ -0,0 +1,10 @@
+; RUN: mlir-translate -import-llvm -split-input-file %s | FileCheck %s
+
+%"bucket<string, double, '\\b'>::Iterator" = type { ptr, i64, i64 }
+
+; CHECK-LABEL: llvm.func @g
+define void @g() {
+ %item.i = alloca %"bucket<string, double, '\\b'>::Iterator", align 8
+ ; CHECK: llvm.alloca %0 x !llvm.struct<"bucket<string, double, '\\b'>::Iterator", (ptr, i64, i64)> {alignment = 8 : i64} : (i32) -> !llvm.ptr
+ ret void
+}
More information about the Mlir-commits
mailing list