From: Alex Lorenz Date: Wed, 12 Aug 2015 20:33:26 +0000 (+0000) Subject: MIR Serialization: Serialize the constant pool pseudo source values. X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=91097a3ffa3557600ca39066e4080a31055d0f76;p=platform%2Fupstream%2Fllvm.git MIR Serialization: Serialize the constant pool pseudo source values. llvm-svn: 244803 --- diff --git a/llvm/lib/CodeGen/MIRParser/MILexer.cpp b/llvm/lib/CodeGen/MIRParser/MILexer.cpp index c59d780..c94c398 100644 --- a/llvm/lib/CodeGen/MIRParser/MILexer.cpp +++ b/llvm/lib/CodeGen/MIRParser/MILexer.cpp @@ -201,6 +201,7 @@ static MIToken::TokenKind getIdentifierKind(StringRef Identifier) { .Case("non-temporal", MIToken::kw_non_temporal) .Case("invariant", MIToken::kw_invariant) .Case("align", MIToken::kw_align) + .Case("constant-pool", MIToken::kw_constant_pool) .Case("liveout", MIToken::kw_liveout) .Default(MIToken::Identifier); } diff --git a/llvm/lib/CodeGen/MIRParser/MILexer.h b/llvm/lib/CodeGen/MIRParser/MILexer.h index 831a21b..75cf3f3 100644 --- a/llvm/lib/CodeGen/MIRParser/MILexer.h +++ b/llvm/lib/CodeGen/MIRParser/MILexer.h @@ -70,6 +70,7 @@ struct MIToken { kw_non_temporal, kw_invariant, kw_align, + kw_constant_pool, kw_liveout, // Identifier tokens diff --git a/llvm/lib/CodeGen/MIRParser/MIParser.cpp b/llvm/lib/CodeGen/MIRParser/MIParser.cpp index cfdd588..afa6ffc 100644 --- a/llvm/lib/CodeGen/MIRParser/MIParser.cpp +++ b/llvm/lib/CodeGen/MIRParser/MIParser.cpp @@ -128,6 +128,8 @@ public: bool parseOperandsOffset(MachineOperand &Op); bool parseIRValue(Value *&V); bool parseMemoryOperandFlag(unsigned &Flags); + bool parseMemoryPseudoSourceValue(const PseudoSourceValue *&PSV); + bool parseMachinePointerInfo(MachinePointerInfo &Dest); bool parseMachineMemoryOperand(MachineMemOperand *&Dest); private: @@ -1117,6 +1119,45 @@ bool MIParser::parseMemoryOperandFlag(unsigned &Flags) { return false; } +bool MIParser::parseMemoryPseudoSourceValue(const PseudoSourceValue *&PSV) { + switch (Token.kind()) { + case MIToken::kw_constant_pool: + PSV = MF.getPSVManager().getConstantPool(); + break; + // TODO: Parse the other pseudo source values. + default: + llvm_unreachable("The current token should be pseudo source value"); + } + lex(); + return false; +} + +bool MIParser::parseMachinePointerInfo(MachinePointerInfo &Dest) { + if (Token.is(MIToken::kw_constant_pool)) { + const PseudoSourceValue *PSV = nullptr; + if (parseMemoryPseudoSourceValue(PSV)) + return true; + int64_t Offset = 0; + if (parseOffset(Offset)) + return true; + Dest = MachinePointerInfo(PSV, Offset); + return false; + } + if (Token.isNot(MIToken::NamedIRValue)) + return error("expected an IR value reference"); + Value *V = nullptr; + if (parseIRValue(V)) + return true; + if (!V->getType()->isPointerTy()) + return error("expected a pointer IR value"); + lex(); + int64_t Offset = 0; + if (parseOffset(Offset)) + return true; + Dest = MachinePointerInfo(V, Offset); + return false; +} + bool MIParser::parseMachineMemoryOperand(MachineMemOperand *&Dest) { if (expectAndConsume(MIToken::lparen)) return true; @@ -1146,17 +1187,8 @@ bool MIParser::parseMachineMemoryOperand(MachineMemOperand *&Dest) { return error(Twine("expected '") + Word + "'"); lex(); - // TODO: Parse pseudo source values. - if (Token.isNot(MIToken::NamedIRValue)) - return error("expected an IR value reference"); - Value *V = nullptr; - if (parseIRValue(V)) - return true; - if (!V->getType()->isPointerTy()) - return error("expected a pointer IR value"); - lex(); - int64_t Offset = 0; - if (parseOffset(Offset)) + MachinePointerInfo Ptr = MachinePointerInfo(); + if (parseMachinePointerInfo(Ptr)) return true; unsigned BaseAlignment = Size; if (Token.is(MIToken::comma)) { @@ -1173,9 +1205,7 @@ bool MIParser::parseMachineMemoryOperand(MachineMemOperand *&Dest) { // TODO: Parse the attached metadata nodes. if (expectAndConsume(MIToken::rparen)) return true; - - Dest = MF.getMachineMemOperand(MachinePointerInfo(V, Offset), Flags, Size, - BaseAlignment); + Dest = MF.getMachineMemOperand(Ptr, Flags, Size, BaseAlignment); return false; } diff --git a/llvm/lib/CodeGen/MIRPrinter.cpp b/llvm/lib/CodeGen/MIRPrinter.cpp index 8b54a98..d47ed97 100644 --- a/llvm/lib/CodeGen/MIRPrinter.cpp +++ b/llvm/lib/CodeGen/MIRPrinter.cpp @@ -704,9 +704,21 @@ void MIPrinter::print(const MachineMemOperand &Op) { OS << "store "; } OS << Op.getSize() << (Op.isLoad() ? " from " : " into "); - if (const Value *Val = Op.getValue()) + if (const Value *Val = Op.getValue()) { printIRValueReference(*Val); - // TODO: Print PseudoSourceValue. + } else { + const PseudoSourceValue *PVal = Op.getPseudoValue(); + assert(PVal && "Expected a pseudo source value"); + switch (PVal->kind()) { + case PseudoSourceValue::ConstantPool: + OS << "constant-pool"; + break; + default: + // TODO: Print the other pseudo source values. + OS << ""; + break; + } + } printOffset(Op.getOffset()); if (Op.getBaseAlignment() != Op.getSize()) OS << ", align " << Op.getBaseAlignment(); diff --git a/llvm/test/CodeGen/MIR/X86/memory-operands.mir b/llvm/test/CodeGen/MIR/X86/memory-operands.mir index f061367..f84ebfb 100644 --- a/llvm/test/CodeGen/MIR/X86/memory-operands.mir +++ b/llvm/test/CodeGen/MIR/X86/memory-operands.mir @@ -59,6 +59,12 @@ ret void } + define double @constant_pool_psv(double %a) { + entry: + %b = fadd double %a, 3.250000e+00 + ret double %b + } + ... --- name: test @@ -185,3 +191,23 @@ body: - 'MOVAPSmr killed %rdi, 1, _, 16, _, killed %xmm1 :: (store 16 into %ir.vec + 16, align 32)' - RETQ ... +--- +name: constant_pool_psv +tracksRegLiveness: true +liveins: + - { reg: '%xmm0' } +constants: + - id: 0 + value: 'double 3.250000e+00' +body: + - id: 0 + name: entry + liveins: [ '%xmm0' ] + instructions: +# CHECK: name: constant_pool_psv +# CHECK: %xmm0 = ADDSDrm killed %xmm0, %rip, 1, _, %const.0, _ :: (load 8 from constant-pool) +# CHECK-NEXT: %xmm0 = ADDSDrm killed %xmm0, %rip, 1, _, %const.0, _ :: (load 8 from constant-pool + 8) + - '%xmm0 = ADDSDrm killed %xmm0, %rip, 1, _, %const.0, _ :: (load 8 from constant-pool)' + - '%xmm0 = ADDSDrm killed %xmm0, %rip, 1, _, %const.0, _ :: (load 8 from constant-pool + 8)' + - 'RETQ %xmm0' +...