From 77676424fd391c318bbc5ce53ec8f9feb425e88a Mon Sep 17 00:00:00 2001 From: Alex Lorenz Date: Thu, 20 Aug 2015 00:12:57 +0000 Subject: [PATCH] MIR Serialization: Change syntax for the call entry pseudo source values. The global IR values in machine memory operands should use the global value '@' syntax instead of the current '%ir.' syntax. However, the global value call entry pseudo source values use the global value syntax already. Therefore, the syntax for the call entry pseudo source values has to be changed so that the global values and call entry global value PSVs can be parsed without ambiguities. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@245526 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/MIRParser/MILexer.cpp | 1 + lib/CodeGen/MIRParser/MILexer.h | 1 + lib/CodeGen/MIRParser/MIParser.cpp | 33 +++++++++------ lib/CodeGen/MIRPrinter.cpp | 3 +- ...lobal-value-or-symbol-after-call-entry.mir | 41 +++++++++++++++++++ test/CodeGen/MIR/Mips/memory-operands.mir | 12 +++--- 6 files changed, 71 insertions(+), 20 deletions(-) create mode 100644 test/CodeGen/MIR/Mips/expected-global-value-or-symbol-after-call-entry.mir diff --git a/lib/CodeGen/MIRParser/MILexer.cpp b/lib/CodeGen/MIRParser/MILexer.cpp index 6094ca996bf..8346ff294e4 100644 --- a/lib/CodeGen/MIRParser/MILexer.cpp +++ b/lib/CodeGen/MIRParser/MILexer.cpp @@ -220,6 +220,7 @@ static MIToken::TokenKind getIdentifierKind(StringRef Identifier) { .Case("got", MIToken::kw_got) .Case("jump-table", MIToken::kw_jump_table) .Case("constant-pool", MIToken::kw_constant_pool) + .Case("call-entry", MIToken::kw_call_entry) .Case("liveout", MIToken::kw_liveout) .Case("address-taken", MIToken::kw_address_taken) .Case("landing-pad", MIToken::kw_landing_pad) diff --git a/lib/CodeGen/MIRParser/MILexer.h b/lib/CodeGen/MIRParser/MILexer.h index 17ddc4d5c1a..35c526be812 100644 --- a/lib/CodeGen/MIRParser/MILexer.h +++ b/lib/CodeGen/MIRParser/MILexer.h @@ -81,6 +81,7 @@ struct MIToken { kw_got, kw_jump_table, kw_constant_pool, + kw_call_entry, kw_liveout, kw_address_taken, kw_landing_pad, diff --git a/lib/CodeGen/MIRParser/MIParser.cpp b/lib/CodeGen/MIRParser/MIParser.cpp index 80f6a654b97..3260249d95b 100644 --- a/lib/CodeGen/MIRParser/MIParser.cpp +++ b/lib/CodeGen/MIRParser/MIParser.cpp @@ -1605,18 +1605,27 @@ bool MIParser::parseMemoryPseudoSourceValue(const PseudoSourceValue *&PSV) { // The token was already consumed, so use return here instead of break. return false; } - case MIToken::GlobalValue: - case MIToken::NamedGlobalValue: { - GlobalValue *GV = nullptr; - if (parseGlobalValue(GV)) - return true; - PSV = MF.getPSVManager().getGlobalValueCallEntry(GV); + case MIToken::kw_call_entry: { + lex(); + switch (Token.kind()) { + case MIToken::GlobalValue: + case MIToken::NamedGlobalValue: { + GlobalValue *GV = nullptr; + if (parseGlobalValue(GV)) + return true; + PSV = MF.getPSVManager().getGlobalValueCallEntry(GV); + break; + } + case MIToken::ExternalSymbol: + PSV = MF.getPSVManager().getExternalSymbolCallEntry( + MF.createExternalSymbolName(Token.stringValue())); + break; + default: + return error( + "expected a global value or an external symbol after 'call-entry'"); + } break; } - case MIToken::ExternalSymbol: - PSV = MF.getPSVManager().getExternalSymbolCallEntry( - MF.createExternalSymbolName(Token.stringValue())); - break; default: llvm_unreachable("The current token should be pseudo source value"); } @@ -1627,9 +1636,7 @@ bool MIParser::parseMemoryPseudoSourceValue(const PseudoSourceValue *&PSV) { bool MIParser::parseMachinePointerInfo(MachinePointerInfo &Dest) { if (Token.is(MIToken::kw_constant_pool) || Token.is(MIToken::kw_stack) || Token.is(MIToken::kw_got) || Token.is(MIToken::kw_jump_table) || - Token.is(MIToken::FixedStackObject) || Token.is(MIToken::GlobalValue) || - Token.is(MIToken::NamedGlobalValue) || - Token.is(MIToken::ExternalSymbol)) { + Token.is(MIToken::FixedStackObject) || Token.is(MIToken::kw_call_entry)) { const PseudoSourceValue *PSV = nullptr; if (parseMemoryPseudoSourceValue(PSV)) return true; diff --git a/lib/CodeGen/MIRPrinter.cpp b/lib/CodeGen/MIRPrinter.cpp index 2440a4103d8..1be845f8b89 100644 --- a/lib/CodeGen/MIRPrinter.cpp +++ b/lib/CodeGen/MIRPrinter.cpp @@ -873,11 +873,12 @@ void MIPrinter::print(const MachineMemOperand &Op) { cast(PVal)->getFrameIndex()); break; case PseudoSourceValue::GlobalValueCallEntry: + OS << "call-entry "; cast(PVal)->getValue()->printAsOperand( OS, /*PrintType=*/false, MST); break; case PseudoSourceValue::ExternalSymbolCallEntry: - OS << '$'; + OS << "call-entry $"; printLLVMNameWithoutPrefix( OS, cast(PVal)->getSymbol()); break; diff --git a/test/CodeGen/MIR/Mips/expected-global-value-or-symbol-after-call-entry.mir b/test/CodeGen/MIR/Mips/expected-global-value-or-symbol-after-call-entry.mir new file mode 100644 index 00000000000..4fba28a0f42 --- /dev/null +++ b/test/CodeGen/MIR/Mips/expected-global-value-or-symbol-after-call-entry.mir @@ -0,0 +1,41 @@ +# RUN: not llc -march=mipsel -mcpu=mips16 -relocation-model=pic -start-after branch-folder -stop-after branch-folder -o /dev/null %s 2>&1 | FileCheck %s +--- | + define i32 @test(i32 %a) { + entry: + %call = call i32 @foo(i32 %a) + ret i32 0 + } + + declare i32 @foo(i32) +... +--- +name: test +tracksRegLiveness: true +liveins: + - { reg: '%a0' } +frameInfo: + stackSize: 24 + maxAlignment: 4 + adjustsStack: true + hasCalls: true + maxCallFrameSize: 16 +stack: + - { id: 0, type: spill-slot, offset: -4, size: 4, alignment: 4, + callee-saved-register: '%ra' } +body: | + bb.0.entry: + liveins: %a0, %ra + + Save16 %ra, 24, implicit-def %sp, implicit %sp + %v0, %v1 = GotPrologue16 $_gp_disp, $_gp_disp + %v0 = SllX16 killed %v0, 16 + %v0 = AdduRxRyRz16 killed %v1, killed %v0 + ; CHECK: [[@LINE+1]]:67: expected a global value or an external symbol after 'call-entry' + %v1 = LwRxRyOffMemX16 %v0, @foo, 0 :: (load 4 from call-entry foo) + %t9 = COPY %v1 + %gp = COPY killed %v0 + JumpLinkReg16 killed %v1, csr_o32, implicit-def %ra, implicit killed %t9, implicit %a0, implicit killed %gp, implicit-def %sp, implicit-def dead %v0 + %v0 = LiRxImmX16 0 + %ra = Restore16 24, implicit-def %sp, implicit %sp + RetRA16 implicit %v0 +... diff --git a/test/CodeGen/MIR/Mips/memory-operands.mir b/test/CodeGen/MIR/Mips/memory-operands.mir index 965cda37812..d45b41a9061 100644 --- a/test/CodeGen/MIR/Mips/memory-operands.mir +++ b/test/CodeGen/MIR/Mips/memory-operands.mir @@ -50,8 +50,8 @@ body: | %v0 = SllX16 killed %v0, 16 %v0 = AdduRxRyRz16 killed %v1, killed %v0 ; CHECK-LABEL: name: test - ; CHECK: %v1 = LwRxRyOffMemX16 %v0, @foo, 0 :: (load 4 from @foo) - %v1 = LwRxRyOffMemX16 %v0, @foo, 0 :: (load 4 from @foo) + ; CHECK: %v1 = LwRxRyOffMemX16 %v0, @foo, 0 :: (load 4 from call-entry @foo) + %v1 = LwRxRyOffMemX16 %v0, @foo, 0 :: (load 4 from call-entry @foo) %t9 = COPY %v1 %gp = COPY killed %v0 JumpLinkReg16 killed %v1, csr_o32, implicit-def %ra, implicit killed %t9, implicit %a0, implicit killed %gp, implicit-def %sp, implicit-def dead %v0 @@ -87,13 +87,13 @@ body: | %v0, %v1 = GotPrologue16 $_gp_disp, $_gp_disp %v0 = SllX16 killed %v0, 16 %s0 = AdduRxRyRz16 killed %v1, killed %v0 - %v0 = LwRxRyOffMemX16 %s0, @g, 0 :: (load 4 from @g) + %v0 = LwRxRyOffMemX16 %s0, @g, 0 :: (load 4 from call-entry @g) ; CHECK-LABEL: test2 - ; CHECK: %v1 = LwRxRyOffMemX16 %s0, $__mips16_call_stub_sf_0, 0 :: (load 4 from $__mips16_call_stub_sf_0) - %v1 = LwRxRyOffMemX16 %s0, $__mips16_call_stub_sf_0, 0 :: (load 4 from $__mips16_call_stub_sf_0) + ; CHECK: %v1 = LwRxRyOffMemX16 %s0, $__mips16_call_stub_sf_0, 0 :: (load 4 from call-entry $__mips16_call_stub_sf_0) + %v1 = LwRxRyOffMemX16 %s0, $__mips16_call_stub_sf_0, 0 :: (load 4 from call-entry $__mips16_call_stub_sf_0) %gp = COPY %s0 JumpLinkReg16 killed %v1, csr_o32, implicit-def %ra, implicit %v0, implicit killed %gp, implicit-def %sp, implicit-def %v0 - %v1 = LwRxRyOffMemX16 %s0, @__mips16_ret_sf, 0 :: (load 4 from @__mips16_ret_sf) + %v1 = LwRxRyOffMemX16 %s0, @__mips16_ret_sf, 0 :: (load 4 from call-entry @__mips16_ret_sf) %t9 = COPY %v1 %gp = COPY killed %s0 JumpLinkReg16 killed %v1, csr_mips16rethelper, implicit-def %ra, implicit killed %t9, implicit %v0, implicit killed %gp, implicit-def %sp -- 2.34.1