From e2e6dea9f2043ad2175e499f97a31adea6d3bddd Mon Sep 17 00:00:00 2001 From: Alex Lorenz Date: Thu, 20 Aug 2015 00:20:03 +0000 Subject: [PATCH] MIR Serialization: Use the global value syntax for global value memory operands. This commit modifies the serialization syntax so that the global IR values in machine memory operands use the global value '@' syntax instead of the current '%ir.' syntax. The unnamed global IR values are handled by this commit as well, as the existing global value parsing method can parse the unnamed globals already. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@245527 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/MIRParser/MIParser.cpp | 15 +++++++++---- lib/CodeGen/MIRPrinter.cpp | 5 ++++- .../MIR/AArch64/stack-object-local-offset.mir | 4 ++-- .../MIR/X86/frame-info-stack-references.mir | 2 +- test/CodeGen/MIR/X86/memory-operands.mir | 21 ++++++++++++------- 5 files changed, 32 insertions(+), 15 deletions(-) diff --git a/lib/CodeGen/MIRParser/MIParser.cpp b/lib/CodeGen/MIRParser/MIParser.cpp index 3260249d95b..d706f04eccc 100644 --- a/lib/CodeGen/MIRParser/MIParser.cpp +++ b/lib/CodeGen/MIRParser/MIParser.cpp @@ -1531,9 +1531,6 @@ bool MIParser::parseIRValue(const Value *&V) { switch (Token.kind()) { case MIToken::NamedIRValue: { V = MF.getFunction()->getValueSymbolTable().lookup(Token.stringValue()); - if (!V) - V = MF.getFunction()->getParent()->getValueSymbolTable().lookup( - Token.stringValue()); break; } case MIToken::IRValue: { @@ -1543,6 +1540,14 @@ bool MIParser::parseIRValue(const Value *&V) { V = getIRValue(SlotNumber); break; } + case MIToken::NamedGlobalValue: + case MIToken::GlobalValue: { + GlobalValue *GV = nullptr; + if (parseGlobalValue(GV)) + return true; + V = GV; + break; + } default: llvm_unreachable("The current token should be an IR block reference"); } @@ -1646,7 +1651,9 @@ bool MIParser::parseMachinePointerInfo(MachinePointerInfo &Dest) { Dest = MachinePointerInfo(PSV, Offset); return false; } - if (Token.isNot(MIToken::NamedIRValue) && Token.isNot(MIToken::IRValue)) + if (Token.isNot(MIToken::NamedIRValue) && Token.isNot(MIToken::IRValue) && + Token.isNot(MIToken::GlobalValue) && + Token.isNot(MIToken::NamedGlobalValue)) return error("expected an IR value reference"); const Value *V = nullptr; if (parseIRValue(V)) diff --git a/lib/CodeGen/MIRPrinter.cpp b/lib/CodeGen/MIRPrinter.cpp index 1be845f8b89..4b4d7b4f25c 100644 --- a/lib/CodeGen/MIRPrinter.cpp +++ b/lib/CodeGen/MIRPrinter.cpp @@ -608,7 +608,10 @@ void MIPrinter::printIRBlockReference(const BasicBlock &BB) { } void MIPrinter::printIRValueReference(const Value &V) { - // TODO: Global values should use the '@' syntax. + if (isa(V)) { + V.printAsOperand(OS, /*PrintType=*/false, MST); + return; + } OS << "%ir."; if (V.hasName()) { printLLVMNameWithoutPrefix(OS, V.getName()); diff --git a/test/CodeGen/MIR/AArch64/stack-object-local-offset.mir b/test/CodeGen/MIR/AArch64/stack-object-local-offset.mir index 4b0c4eccf6b..9471516db64 100644 --- a/test/CodeGen/MIR/AArch64/stack-object-local-offset.mir +++ b/test/CodeGen/MIR/AArch64/stack-object-local-offset.mir @@ -32,10 +32,10 @@ stack: body: | bb.0.entry: %0 = ADRP @var - %1 = LDRXui killed %0, @var :: (load 8 from %ir.var) + %1 = LDRXui killed %0, @var :: (load 8 from @var) STRXui killed %1, %stack.0.local_var, 0 :: (store 8 into %ir.local_var) %2 = ADRP @local_addr %3 = ADDXri %stack.0.local_var, 0, 0 - STRXui killed %3, killed %2, @local_addr :: (store 8 into %ir.local_addr) + STRXui killed %3, killed %2, @local_addr :: (store 8 into @local_addr) RET_ReallyLR ... diff --git a/test/CodeGen/MIR/X86/frame-info-stack-references.mir b/test/CodeGen/MIR/X86/frame-info-stack-references.mir index a1f13aff68f..c8fa3bbe226 100644 --- a/test/CodeGen/MIR/X86/frame-info-stack-references.mir +++ b/test/CodeGen/MIR/X86/frame-info-stack-references.mir @@ -57,7 +57,7 @@ body: | frame-setup PUSH64r killed %rbx, implicit-def %rsp, implicit %rsp %rsp = frame-setup SUB64ri8 %rsp, 32, implicit-def dead %eflags - %rbx = LOAD_STACK_GUARD :: (invariant load 8 from %ir.__stack_chk_guard) + %rbx = LOAD_STACK_GUARD :: (invariant load 8 from @__stack_chk_guard) MOV64mr %rsp, 1, _, 24, _, %rbx %rsi = LEA64r %rsp, 1, _, 19, _ MOV64mr %rsp, 1, _, 8, _, %rsi diff --git a/test/CodeGen/MIR/X86/memory-operands.mir b/test/CodeGen/MIR/X86/memory-operands.mir index ba5bcec820e..6621b7e2e75 100644 --- a/test/CodeGen/MIR/X86/memory-operands.mir +++ b/test/CodeGen/MIR/X86/memory-operands.mir @@ -93,11 +93,15 @@ ret i32 %b } + @0 = external global i32 + define i32 @global_value() { entry: %a = load i32, i32* @G %b = add i32 %a, 1 - ret i32 %b + %c = load i32, i32* @0 + %d = add i32 %b, %c + ret i32 %d } define i32 @jumptable_psv(i32 %in) { @@ -358,10 +362,13 @@ tracksRegLiveness: true body: | bb.0.entry: %rax = MOV64rm %rip, 1, _, @G, _ - ; CHECK: name: global_value - ; CHECK: %eax = MOV32rm killed %rax, 1, _, 0, _ :: (load 4 from %ir.G) - %eax = MOV32rm killed %rax, 1, _, 0, _ :: (load 4 from %ir.G) - %eax = INC32r killed %eax, implicit-def dead %eflags + ; CHECK-LABEL: name: global_value + ; CHECK: %eax = MOV32rm killed %rax, 1, _, 0, _, implicit-def %rax :: (load 4 from @G) + ; CHECK: %ecx = MOV32rm killed %rcx, 1, _, 0, _, implicit-def %rcx :: (load 4 from @0) + %eax = MOV32rm killed %rax, 1, _, 0, _, implicit-def %rax :: (load 4 from @G) + %rcx = MOV64rm %rip, 1, _, @0, _ + %ecx = MOV32rm killed %rcx, 1, _, 0, _, implicit-def %rcx :: (load 4 from @0) + %eax = LEA64_32r killed %rax, 1, killed %rcx, 1, _ RETQ %eax ... --- @@ -421,9 +428,9 @@ body: | bb.0.entry: %rax = MOV64rm %rip, 1, _, @a, _ :: (load 8 from got) ; CHECK-LABEL: name: tbaa_metadata - ; CHECK: %eax = MOV32rm killed %rax, 1, _, 0, _, implicit-def %rax :: (load 4 from %ir.a, !tbaa !2) + ; CHECK: %eax = MOV32rm killed %rax, 1, _, 0, _, implicit-def %rax :: (load 4 from @a, !tbaa !2) ; CHECK-NEXT: %eax = MOV32rm killed %rax, 1, _, 0, _ :: (load 4 from %ir.total_len2, !tbaa !6) - %eax = MOV32rm killed %rax, 1, _, 0, _, implicit-def %rax :: (load 4 from %ir.a, !tbaa !2) + %eax = MOV32rm killed %rax, 1, _, 0, _, implicit-def %rax :: (load 4 from @a, !tbaa !2) %eax = MOV32rm killed %rax, 1, _, 0, _ :: (load 4 from %ir.total_len2, !tbaa !6) RETQ %eax ... -- 2.34.1