Include a frame index in the "fixed stack" pseudo source value
instead of using the frame index for the SVOffset, which was
inconsistent.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@53486 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/PseudoSourceValue.cpp b/lib/CodeGen/PseudoSourceValue.cpp
index c62e49a..ea704e6 100644
--- a/lib/CodeGen/PseudoSourceValue.cpp
+++ b/lib/CodeGen/PseudoSourceValue.cpp
@@ -13,28 +13,27 @@
 
 #include "llvm/CodeGen/PseudoSourceValue.h"
 #include "llvm/DerivedTypes.h"
+#include "llvm/Support/Compiler.h"
 #include "llvm/Support/ManagedStatic.h"
+#include <map>
 
 namespace llvm {
-  static ManagedStatic<PseudoSourceValue[5]> PSVs;
+  static ManagedStatic<PseudoSourceValue[4]> PSVs;
 
-  const PseudoSourceValue *PseudoSourceValue::getFixedStack()
-  { return &(*PSVs)[0]; }
   const PseudoSourceValue *PseudoSourceValue::getStack()
-  { return &(*PSVs)[1]; }
+  { return &(*PSVs)[0]; }
   const PseudoSourceValue *PseudoSourceValue::getGOT()
+  { return &(*PSVs)[1]; }
+  const PseudoSourceValue *PseudoSourceValue::getJumpTable()
   { return &(*PSVs)[2]; }
   const PseudoSourceValue *PseudoSourceValue::getConstantPool()
   { return &(*PSVs)[3]; }
-  const PseudoSourceValue *PseudoSourceValue::getJumpTable()
-  { return &(*PSVs)[4]; }
 
   static const char *const PSVNames[] = {
-    "FixedStack",
     "Stack",
     "GOT",
-    "ConstantPool",
     "JumpTable"
+    "ConstantPool"
   };
 
   PseudoSourceValue::PseudoSourceValue() :
@@ -43,4 +42,26 @@
   void PseudoSourceValue::print(std::ostream &OS) const {
     OS << PSVNames[this - *PSVs];
   }
+
+  /// FixedStackPseudoSourceValue - A specialized PseudoSourceValue
+  /// for holding FixedStack values, which must include a frame
+  /// index.
+  class VISIBILITY_HIDDEN FixedStackPseudoSourceValue
+    : public PseudoSourceValue {
+    const int FI;
+  public:
+    explicit FixedStackPseudoSourceValue(int fi) : FI(fi) {}
+    virtual void print(std::ostream &OS) const {
+      OS << "FixedStack" << FI;
+    }
+  };
+
+  static ManagedStatic<std::map<int, const PseudoSourceValue *> > FSValues;
+
+  const PseudoSourceValue *PseudoSourceValue::getFixedStack(int FI) {
+    const PseudoSourceValue *&V = (*FSValues)[FI];
+    if (!V)
+      V = new FixedStackPseudoSourceValue(FI);
+    return V;
+  }
 }
diff --git a/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp b/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
index 4b4c02b..632653b 100644
--- a/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
+++ b/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
@@ -780,13 +780,11 @@
   MVT PtrVT = TLI.getPointerTy();
   SDOperand StackPtr = DAG.CreateStackTemporary(VT);
 
-  FrameIndexSDNode *StackPtrFI = cast<FrameIndexSDNode>(StackPtr.Val);
-  int SPFI = StackPtrFI->getIndex();
+  int SPFI = cast<FrameIndexSDNode>(StackPtr.Val)->getIndex();
 
   // Store the vector.
   SDOperand Ch = DAG.getStore(DAG.getEntryNode(), Tmp1, StackPtr,
-                              PseudoSourceValue::getFixedStack(),
-                              SPFI);
+                              PseudoSourceValue::getFixedStack(SPFI), 0);
 
   // Truncate or zero extend offset to target pointer type.
   unsigned CastOpc = IdxVT.bitsGT(PtrVT) ? ISD::TRUNCATE : ISD::ZERO_EXTEND;
@@ -797,9 +795,10 @@
   SDOperand StackPtr2 = DAG.getNode(ISD::ADD, IdxVT, Tmp3, StackPtr);
   // Store the scalar value.
   Ch = DAG.getTruncStore(Ch, Tmp2, StackPtr2,
-                         PseudoSourceValue::getFixedStack(), SPFI, EltVT);
+                         PseudoSourceValue::getFixedStack(SPFI), 0, EltVT);
   // Load the updated vector.
-  return DAG.getLoad(VT, Ch, StackPtr, PseudoSourceValue::getFixedStack(),SPFI);
+  return DAG.getLoad(VT, Ch, StackPtr,
+                     PseudoSourceValue::getFixedStack(SPFI), 0);
 }
 
 /// LegalizeOp - We know that the specified value has a legal type, and
@@ -4906,12 +4905,12 @@
   
   if (SrcSize > SlotSize)
     Store = DAG.getTruncStore(DAG.getEntryNode(), SrcOp, FIPtr,
-                              PseudoSourceValue::getFixedStack(), SPFI, SlotVT, 
-                              false, SrcAlign);
+                              PseudoSourceValue::getFixedStack(SPFI), 0,
+                              SlotVT, false, SrcAlign);
   else {
     assert(SrcSize == SlotSize && "Invalid store");
     Store = DAG.getStore(DAG.getEntryNode(), SrcOp, FIPtr,
-                         PseudoSourceValue::getFixedStack(), SPFI,
+                         PseudoSourceValue::getFixedStack(SPFI), 0,
                          false, SrcAlign);
   }
   
@@ -4933,9 +4932,9 @@
   int SPFI = StackPtrFI->getIndex();
 
   SDOperand Ch = DAG.getStore(DAG.getEntryNode(), Node->getOperand(0), StackPtr,
-                              PseudoSourceValue::getFixedStack(), SPFI);
+                              PseudoSourceValue::getFixedStack(SPFI), 0);
   return DAG.getLoad(Node->getValueType(0), Ch, StackPtr,
-                     PseudoSourceValue::getFixedStack(), SPFI);
+                     PseudoSourceValue::getFixedStack(SPFI), 0);
 }
 
 
@@ -7017,15 +7016,13 @@
       // Lower to a store/load so that it can be split.
       // FIXME: this could be improved probably.
       SDOperand Ptr = DAG.CreateStackTemporary(InOp.getValueType());
-      FrameIndexSDNode *FI = cast<FrameIndexSDNode>(Ptr.Val);
+      int FI = cast<FrameIndexSDNode>(Ptr.Val)->getIndex();
 
       SDOperand St = DAG.getStore(DAG.getEntryNode(),
                                   InOp, Ptr,
-                                  PseudoSourceValue::getFixedStack(),
-                                  FI->getIndex());
+                                  PseudoSourceValue::getFixedStack(FI), 0);
       InOp = DAG.getLoad(Op.getValueType(), St, Ptr,
-                         PseudoSourceValue::getFixedStack(),
-                         FI->getIndex());
+                         PseudoSourceValue::getFixedStack(FI), 0);
     }
     // Split the vector and convert each of the pieces now.
     SplitVectorOp(InOp, Lo, Hi);
diff --git a/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
index db31538..cc1acf4 100644
--- a/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ b/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -4361,8 +4361,8 @@
   const FrameIndexSDNode *FI = 
   dyn_cast<const FrameIndexSDNode>(getBasePtr().Val);
   if (!getSrcValue() && FI)
-    return MachineMemOperand(PseudoSourceValue::getFixedStack(), Flags,
-                             FI->getIndex(), Size, getAlignment());
+    return MachineMemOperand(PseudoSourceValue::getFixedStack(FI->getIndex()),
+                             Flags, 0, Size, getAlignment());
   else
     return MachineMemOperand(getSrcValue(), Flags, getSrcValueOffset(),
                              Size, getAlignment());