From 78f9b57b68c6892df22d9e5e22c13294212deb24 Mon Sep 17 00:00:00 2001 From: Alex Lorenz Date: Fri, 14 Aug 2015 21:08:30 +0000 Subject: [PATCH] MIR Serialization: Serialize the global value call entry pseudo source values. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@245097 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/CodeGen/PseudoSourceValue.h | 4 ++ lib/CodeGen/MIRParser/MIParser.cpp | 11 +++++- lib/CodeGen/MIRPrinter.cpp | 4 ++ test/CodeGen/MIR/Mips/lit.local.cfg | 2 + test/CodeGen/MIR/Mips/memory-operands.mir | 47 +++++++++++++++++++++++ 5 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 test/CodeGen/MIR/Mips/lit.local.cfg create mode 100644 test/CodeGen/MIR/Mips/memory-operands.mir diff --git a/include/llvm/CodeGen/PseudoSourceValue.h b/include/llvm/CodeGen/PseudoSourceValue.h index 5f6afe918c8..e6b95235e41 100644 --- a/include/llvm/CodeGen/PseudoSourceValue.h +++ b/include/llvm/CodeGen/PseudoSourceValue.h @@ -118,6 +118,10 @@ class GlobalValuePseudoSourceValue : public CallEntryPseudoSourceValue { public: GlobalValuePseudoSourceValue(const GlobalValue *GV); + static inline bool classof(const PseudoSourceValue *V) { + return V->kind() == GlobalValueCallEntry; + } + const GlobalValue *getValue() const { return GV; } }; diff --git a/lib/CodeGen/MIRParser/MIParser.cpp b/lib/CodeGen/MIRParser/MIParser.cpp index 7984116efcb..31046b91cf8 100644 --- a/lib/CodeGen/MIRParser/MIParser.cpp +++ b/lib/CodeGen/MIRParser/MIParser.cpp @@ -1437,6 +1437,14 @@ 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); + break; + } // TODO: Parse the other pseudo source values. default: llvm_unreachable("The current token should be pseudo source value"); @@ -1448,7 +1456,8 @@ 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::FixedStackObject) || Token.is(MIToken::GlobalValue) || + Token.is(MIToken::NamedGlobalValue)) { const PseudoSourceValue *PSV = nullptr; if (parseMemoryPseudoSourceValue(PSV)) return true; diff --git a/lib/CodeGen/MIRPrinter.cpp b/lib/CodeGen/MIRPrinter.cpp index 957cb20eace..7e546eb845f 100644 --- a/lib/CodeGen/MIRPrinter.cpp +++ b/lib/CodeGen/MIRPrinter.cpp @@ -763,6 +763,10 @@ void MIPrinter::print(const MachineMemOperand &Op) { printStackObjectReference( cast(PVal)->getFrameIndex()); break; + case PseudoSourceValue::GlobalValueCallEntry: + cast(PVal)->getValue()->printAsOperand( + OS, /*PrintType=*/false, MST); + break; default: // TODO: Print the other pseudo source values. OS << ""; diff --git a/test/CodeGen/MIR/Mips/lit.local.cfg b/test/CodeGen/MIR/Mips/lit.local.cfg new file mode 100644 index 00000000000..7d12f7a9c56 --- /dev/null +++ b/test/CodeGen/MIR/Mips/lit.local.cfg @@ -0,0 +1,2 @@ +if not 'Mips' in config.root.targets: + config.unsupported = True diff --git a/test/CodeGen/MIR/Mips/memory-operands.mir b/test/CodeGen/MIR/Mips/memory-operands.mir new file mode 100644 index 00000000000..9086ac1ff5d --- /dev/null +++ b/test/CodeGen/MIR/Mips/memory-operands.mir @@ -0,0 +1,47 @@ +# RUN: llc -march=mipsel -mcpu=mips16 -relocation-model=pic -start-after branch-folder -stop-after branch-folder -o /dev/null %s | FileCheck %s +# This test ensures that the MIR parser parses the call entry pseudo source +# values in memory operands correctly. + +--- | + 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 + CFI_INSTRUCTION .cfi_def_cfa_offset 24 + CFI_INSTRUCTION .cfi_offset %ra_64, -4 + %v0, %v1 = GotPrologue16 $_gp_disp, $_gp_disp + %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) + %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 +... -- 2.34.1