From b9a7c89d4322b261b65eb96d678a9d38b776cb60 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Gabriel=20Hjort=20=C3=85kerlund?= Date: Mon, 28 Dec 2020 17:41:25 +0100 Subject: [PATCH] [MIRPrinter] Fix incorrect output of unnamed stack names The MIRParser expects unnamed stack entries to have empty names (''). In case of unnamed alloca instructions, the MIRPrinter would output '', which caused the MIRParser to reject the generated code. Reviewed By: arsenm Differential Revision: https://reviews.llvm.org/D93685 --- llvm/lib/CodeGen/MIRPrinter.cpp | 2 +- llvm/test/CodeGen/MIR/AArch64/unnamed-stack.ll | 23 +++++++++++++++++++++++ llvm/test/CodeGen/PowerPC/alloca-crspill.ll | 8 ++++---- 3 files changed, 28 insertions(+), 5 deletions(-) create mode 100644 llvm/test/CodeGen/MIR/AArch64/unnamed-stack.ll diff --git a/llvm/lib/CodeGen/MIRPrinter.cpp b/llvm/lib/CodeGen/MIRPrinter.cpp index 25f7853..eae1740 100644 --- a/llvm/lib/CodeGen/MIRPrinter.cpp +++ b/llvm/lib/CodeGen/MIRPrinter.cpp @@ -415,7 +415,7 @@ void MIRPrinter::convertStackObjects(yaml::MachineFunction &YMF, YamlObject.ID = ID; if (const auto *Alloca = MFI.getObjectAllocation(I)) YamlObject.Name.Value = std::string( - Alloca->hasName() ? Alloca->getName() : ""); + Alloca->hasName() ? Alloca->getName() : ""); YamlObject.Type = MFI.isSpillSlotObjectIndex(I) ? yaml::MachineStackObject::SpillSlot : MFI.isVariableSizedObjectIndex(I) diff --git a/llvm/test/CodeGen/MIR/AArch64/unnamed-stack.ll b/llvm/test/CodeGen/MIR/AArch64/unnamed-stack.ll new file mode 100644 index 0000000..c7e87e3 --- /dev/null +++ b/llvm/test/CodeGen/MIR/AArch64/unnamed-stack.ll @@ -0,0 +1,23 @@ +; RUN: llc -O0 -march aarch64 -global-isel -stop-after=irtranslator -o - %s | llc -x mir -march aarch64 -run-pass=none -o - | FileCheck %s + +define i16 @unnamed_stack() { +entry: + ; CHECK-NAME: unnamed_stack + ; CHECK: stack: + ; CHECK-NEXT: - { id: 0, name: '', + ; CHECK: %0:_(p0) = G_FRAME_INDEX %stack.0 + %0 = alloca i16 + %1 = load i16, i16* %0 + ret i16 %1 +} + +define i16 @named_stack() { +entry: + ; CHECK-NAME: named_stack + ; CHECK: stack: + ; CHECK-NEXT: - { id: 0, name: ptr, + ; CHECK: %0:_(p0) = G_FRAME_INDEX %stack.0.ptr + %ptr = alloca i16 + %0 = load i16, i16* %ptr + ret i16 %0 +} diff --git a/llvm/test/CodeGen/PowerPC/alloca-crspill.ll b/llvm/test/CodeGen/PowerPC/alloca-crspill.ll index f52e305..b71a9ff 100644 --- a/llvm/test/CodeGen/PowerPC/alloca-crspill.ll +++ b/llvm/test/CodeGen/PowerPC/alloca-crspill.ll @@ -49,8 +49,8 @@ declare signext i32 @do_something(double*) ; CHECK64-NEXT: debug-info-variable: '', debug-info-expression: '', debug-info-location: '' } ; CHECK64-NEXT: stack: -; CHECK64-NEXT: - { id: 0, name: '', type: variable-sized, offset: -8, -; CHECK64-NEXT: alignment: 1, stack-id: default, callee-saved-register: '', callee-saved-restored: true, +; CHECK64-NEXT: - { id: 0, name: '', type: variable-sized, offset: -8, alignment: 1, +; CHECK64-NEXT: stack-id: default, callee-saved-register: '', callee-saved-restored: true, ; CHECK64-NEXT: local-offset: 0, debug-info-variable: '', debug-info-expression: '', ; CHECK64-NEXT: debug-info-location: '' } ; CHECK64-NEXT: - { id: 1, name: '', type: default, offset: -16, size: 8, alignment: 8, @@ -68,8 +68,8 @@ declare signext i32 @do_something(double*) ; CHECK32-NEXT: debug-info-variable: '', debug-info-expression: '', debug-info-location: '' } ; CHECK32-NEXT: stack: -; CHECK32-NEXT: - { id: 0, name: '', type: variable-sized, offset: -4, -; CHECK32-NEXT: alignment: 1, stack-id: default, callee-saved-register: '', callee-saved-restored: true, +; CHECK32-NEXT: - { id: 0, name: '', type: variable-sized, offset: -4, alignment: 1, +; CHECK32-NEXT: stack-id: default, callee-saved-register: '', callee-saved-restored: true, ; CHECK32-NEXT: local-offset: 0, debug-info-variable: '', debug-info-expression: '', ; CHECK32-NEXT: debug-info-location: '' } ; CHECK32-NEXT: - { id: 1, name: '', type: default, offset: -8, size: 4, alignment: 4, -- 2.7.4