[llvm] r244803 - MIR Serialization: Serialize the constant pool pseudo source values.

Alex Lorenz via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 12 13:33:26 PDT 2015


Author: arphaman
Date: Wed Aug 12 15:33:26 2015
New Revision: 244803

URL: http://llvm.org/viewvc/llvm-project?rev=244803&view=rev
Log:
MIR Serialization: Serialize the constant pool pseudo source values.

Modified:
    llvm/trunk/lib/CodeGen/MIRParser/MILexer.cpp
    llvm/trunk/lib/CodeGen/MIRParser/MILexer.h
    llvm/trunk/lib/CodeGen/MIRParser/MIParser.cpp
    llvm/trunk/lib/CodeGen/MIRPrinter.cpp
    llvm/trunk/test/CodeGen/MIR/X86/memory-operands.mir

Modified: llvm/trunk/lib/CodeGen/MIRParser/MILexer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MIRParser/MILexer.cpp?rev=244803&r1=244802&r2=244803&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/MIRParser/MILexer.cpp (original)
+++ llvm/trunk/lib/CodeGen/MIRParser/MILexer.cpp Wed Aug 12 15:33:26 2015
@@ -201,6 +201,7 @@ static MIToken::TokenKind getIdentifierK
       .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);
 }

Modified: llvm/trunk/lib/CodeGen/MIRParser/MILexer.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MIRParser/MILexer.h?rev=244803&r1=244802&r2=244803&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/MIRParser/MILexer.h (original)
+++ llvm/trunk/lib/CodeGen/MIRParser/MILexer.h Wed Aug 12 15:33:26 2015
@@ -70,6 +70,7 @@ struct MIToken {
     kw_non_temporal,
     kw_invariant,
     kw_align,
+    kw_constant_pool,
     kw_liveout,
 
     // Identifier tokens

Modified: llvm/trunk/lib/CodeGen/MIRParser/MIParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MIRParser/MIParser.cpp?rev=244803&r1=244802&r2=244803&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/MIRParser/MIParser.cpp (original)
+++ llvm/trunk/lib/CodeGen/MIRParser/MIParser.cpp Wed Aug 12 15:33:26 2015
@@ -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(un
   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
     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
   // 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;
 }
 

Modified: llvm/trunk/lib/CodeGen/MIRPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MIRPrinter.cpp?rev=244803&r1=244802&r2=244803&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/MIRPrinter.cpp (original)
+++ llvm/trunk/lib/CodeGen/MIRPrinter.cpp Wed Aug 12 15:33:26 2015
@@ -704,9 +704,21 @@ void MIPrinter::print(const MachineMemOp
     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 << "<unserializable pseudo value>";
+      break;
+    }
+  }
   printOffset(Op.getOffset());
   if (Op.getBaseAlignment() != Op.getSize())
     OS << ", align " << Op.getBaseAlignment();

Modified: llvm/trunk/test/CodeGen/MIR/X86/memory-operands.mir
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/MIR/X86/memory-operands.mir?rev=244803&r1=244802&r2=244803&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/MIR/X86/memory-operands.mir (original)
+++ llvm/trunk/test/CodeGen/MIR/X86/memory-operands.mir Wed Aug 12 15:33:26 2015
@@ -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'
+...




More information about the llvm-commits mailing list