Only fixed stack objects and spill slots should be get FixedStack PseudoSourceValue.
authorEvan Cheng <evan.cheng@apple.com>
Sun, 18 Oct 2009 06:27:36 +0000 (06:27 +0000)
committerEvan Cheng <evan.cheng@apple.com>
Sun, 18 Oct 2009 06:27:36 +0000 (06:27 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@84411 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
lib/CodeGen/SelectionDAG/LegalizeTypesGeneric.cpp
lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp
lib/CodeGen/SelectionDAG/SelectionDAG.cpp
lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp
lib/CodeGen/StackSlotColoring.cpp
lib/CodeGen/TargetInstrInfoImpl.cpp
lib/Target/PowerPC/PPCISelLowering.cpp
lib/Target/X86/X86ISelLowering.cpp

index 7138dd254698f39b1bc56a106629b072150d8c72..0adffbb463be9c6081ad5ce36c6c6891d768ac46 100644 (file)
@@ -639,11 +639,9 @@ PerformInsertVectorEltInMemory(SDValue Vec, SDValue Val, SDValue Idx,
   EVT PtrVT = TLI.getPointerTy();
   SDValue StackPtr = DAG.CreateStackTemporary(VT);
 
-  int SPFI = cast<FrameIndexSDNode>(StackPtr.getNode())->getIndex();
-
   // Store the vector.
   SDValue Ch = DAG.getStore(DAG.getEntryNode(), dl, Tmp1, StackPtr,
-                            PseudoSourceValue::getFixedStack(SPFI), 0);
+                            PseudoSourceValue::getStack(), 0);
 
   // Truncate or zero extend offset to target pointer type.
   unsigned CastOpc = IdxVT.bitsGT(PtrVT) ? ISD::TRUNCATE : ISD::ZERO_EXTEND;
@@ -654,10 +652,10 @@ PerformInsertVectorEltInMemory(SDValue Vec, SDValue Val, SDValue Idx,
   SDValue StackPtr2 = DAG.getNode(ISD::ADD, dl, IdxVT, Tmp3, StackPtr);
   // Store the scalar value.
   Ch = DAG.getTruncStore(Ch, dl, Tmp2, StackPtr2,
-                         PseudoSourceValue::getFixedStack(SPFI), 0, EltVT);
+                         PseudoSourceValue::getStack(), 0, EltVT);
   // Load the updated vector.
   return DAG.getLoad(VT, dl, Ch, StackPtr,
-                     PseudoSourceValue::getFixedStack(SPFI), 0);
+                     PseudoSourceValue::getStack(), 0);
 }
 
 
@@ -1517,8 +1515,7 @@ SDValue SelectionDAGLegalize::ExpandVectorBuildThroughStack(SDNode* Node) {
   EVT OpVT = Node->getOperand(0).getValueType();
   DebugLoc dl = Node->getDebugLoc();
   SDValue FIPtr = DAG.CreateStackTemporary(VT);
-  int FI = cast<FrameIndexSDNode>(FIPtr.getNode())->getIndex();
-  const Value *SV = PseudoSourceValue::getFixedStack(FI);
+  const Value *SV = PseudoSourceValue::getStack();
 
   // Emit a store of each element to the stack slot.
   SmallVector<SDValue, 8> Stores;
@@ -1712,20 +1709,17 @@ SDValue SelectionDAGLegalize::EmitStackConvert(SDValue SrcOp,
                                               getTypeForEVT(*DAG.getContext()));
   SDValue FIPtr = DAG.CreateStackTemporary(SlotVT, SrcAlign);
 
-  FrameIndexSDNode *StackPtrFI = cast<FrameIndexSDNode>(FIPtr);
-  int SPFI = StackPtrFI->getIndex();
-  const Value *SV = PseudoSourceValue::getFixedStack(SPFI);
-
   unsigned SrcSize = SrcOp.getValueType().getSizeInBits();
   unsigned SlotSize = SlotVT.getSizeInBits();
   unsigned DestSize = DestVT.getSizeInBits();
   unsigned DestAlign =
-    TLI.getTargetData()->getPrefTypeAlignment(DestVT.getTypeForEVT(*DAG.getContext()));
+    TLI.getTargetData()->getPrefTypeAlignment(DestVT.
+                                              getTypeForEVT(*DAG.getContext()));
 
   // Emit a store to the stack slot.  Use a truncstore if the input value is
   // later than DestVT.
   SDValue Store;
-
+  const Value *SV = PseudoSourceValue::getStack();
   if (SrcSize > SlotSize)
     Store = DAG.getTruncStore(DAG.getEntryNode(), dl, SrcOp, FIPtr,
                               SV, 0, SlotVT, false, SrcAlign);
@@ -1750,15 +1744,12 @@ SDValue SelectionDAGLegalize::ExpandSCALAR_TO_VECTOR(SDNode *Node) {
   // then load the whole vector back out.
   SDValue StackPtr = DAG.CreateStackTemporary(Node->getValueType(0));
 
-  FrameIndexSDNode *StackPtrFI = cast<FrameIndexSDNode>(StackPtr);
-  int SPFI = StackPtrFI->getIndex();
-
   SDValue Ch = DAG.getTruncStore(DAG.getEntryNode(), dl, Node->getOperand(0),
                                  StackPtr,
-                                 PseudoSourceValue::getFixedStack(SPFI), 0,
+                                 PseudoSourceValue::getStack(), 0,
                                  Node->getValueType(0).getVectorElementType());
   return DAG.getLoad(Node->getValueType(0), dl, Ch, StackPtr,
-                     PseudoSourceValue::getFixedStack(SPFI), 0);
+                     PseudoSourceValue::getStack(), 0);
 }
 
 
index dbd3e39b54262752af3cce681851211cab4a3366..29f1a2dc3ad5aa126a56a2f6ceb589b602dd6e1e 100644 (file)
@@ -118,8 +118,7 @@ void DAGTypeLegalizer::ExpandRes_BIT_CONVERT(SDNode *N, SDValue &Lo,
     TLI.getTargetData()->getPrefTypeAlignment(NOutVT.
                                               getTypeForEVT(*DAG.getContext()));
   SDValue StackPtr = DAG.CreateStackTemporary(InVT, Alignment);
-  int SPFI = cast<FrameIndexSDNode>(StackPtr.getNode())->getIndex();
-  const Value *SV = PseudoSourceValue::getFixedStack(SPFI);
+  const Value *SV = PseudoSourceValue::getStack();
 
   // Emit a store to the stack slot.
   SDValue Store = DAG.getStore(DAG.getEntryNode(), dl, InOp, StackPtr, SV, 0);
index 75e12395d8bd037278cf854d3efafa3c2d9834ba..1964f641ca801050f4777a8fc0bdaff98c83c9b5 100644 (file)
@@ -1057,8 +1057,7 @@ SDValue DAGTypeLegalizer::SplitVecOp_EXTRACT_VECTOR_ELT(SDNode *N) {
   EVT EltVT = VecVT.getVectorElementType();
   DebugLoc dl = N->getDebugLoc();
   SDValue StackPtr = DAG.CreateStackTemporary(VecVT);
-  int SPFI = cast<FrameIndexSDNode>(StackPtr.getNode())->getIndex();
-  const Value *SV = PseudoSourceValue::getFixedStack(SPFI);
+  const Value *SV = PseudoSourceValue::getStack();
   SDValue Store = DAG.getStore(DAG.getEntryNode(), dl, Vec, StackPtr, SV, 0);
 
   // Load back the required element.
index 8bd0370cc60a0acacd09299c77ec9fd463f67b70..cd7e1fd5f25a5e8b5437f85f8764183adcf72d86 100644 (file)
@@ -3507,16 +3507,22 @@ SDValue SelectionDAG::getAtomic(unsigned Opcode, DebugLoc dl, EVT MemVT,
                                 SDValue Ptr, SDValue Cmp,
                                 SDValue Swp, const Value* PtrVal,
                                 unsigned Alignment) {
+  MachineFunction &MF = getMachineFunction();
+  MachineFrameInfo *FrameInfo = MF.getFrameInfo();
+
   if (Alignment == 0)  // Ensure that codegen never sees alignment 0
     Alignment = getEVTAlignment(MemVT);
 
   // Check if the memory reference references a frame index
   if (!PtrVal)
     if (const FrameIndexSDNode *FI =
-          dyn_cast<const FrameIndexSDNode>(Ptr.getNode()))
-      PtrVal = PseudoSourceValue::getFixedStack(FI->getIndex());
+        dyn_cast<const FrameIndexSDNode>(Ptr.getNode())) {
+      if (FrameInfo->isFixedObjectIndex(FI->getIndex()))
+        PtrVal = PseudoSourceValue::getFixedStack(FI->getIndex());
+      else
+        PtrVal = PseudoSourceValue::getStack();
+    }
 
-  MachineFunction &MF = getMachineFunction();
   unsigned Flags = MachineMemOperand::MOLoad | MachineMemOperand::MOStore;
 
   // For now, atomics are considered to be volatile always.
@@ -3560,16 +3566,21 @@ SDValue SelectionDAG::getAtomic(unsigned Opcode, DebugLoc dl, EVT MemVT,
                                 SDValue Ptr, SDValue Val,
                                 const Value* PtrVal,
                                 unsigned Alignment) {
+  MachineFunction &MF = getMachineFunction();
+  MachineFrameInfo *FrameInfo = MF.getFrameInfo();
+
   if (Alignment == 0)  // Ensure that codegen never sees alignment 0
     Alignment = getEVTAlignment(MemVT);
 
   // Check if the memory reference references a frame index
   if (!PtrVal)
     if (const FrameIndexSDNode *FI =
-          dyn_cast<const FrameIndexSDNode>(Ptr.getNode()))
-      PtrVal = PseudoSourceValue::getFixedStack(FI->getIndex());
+        dyn_cast<const FrameIndexSDNode>(Ptr.getNode()))
+      if (FrameInfo->isFixedObjectIndex(FI->getIndex()))
+        PtrVal = PseudoSourceValue::getFixedStack(FI->getIndex());
+      else
+        PtrVal = PseudoSourceValue::getStack();
 
-  MachineFunction &MF = getMachineFunction();
   unsigned Flags = MachineMemOperand::MOLoad | MachineMemOperand::MOStore;
 
   // For now, atomics are considered to be volatile always.
@@ -3707,16 +3718,21 @@ SelectionDAG::getLoad(ISD::MemIndexedMode AM, DebugLoc dl,
                       SDValue Ptr, SDValue Offset,
                       const Value *SV, int SVOffset, EVT MemVT,
                       bool isVolatile, unsigned Alignment) {
+  MachineFunction &MF = getMachineFunction();
+  MachineFrameInfo *FrameInfo = MF.getFrameInfo();
+
   if (Alignment == 0)  // Ensure that codegen never sees alignment 0
     Alignment = getEVTAlignment(VT);
 
   // Check if the memory reference references a frame index
   if (!SV)
     if (const FrameIndexSDNode *FI =
-          dyn_cast<const FrameIndexSDNode>(Ptr.getNode()))
-      SV = PseudoSourceValue::getFixedStack(FI->getIndex());
+        dyn_cast<const FrameIndexSDNode>(Ptr.getNode()))
+      if (FrameInfo->isFixedObjectIndex(FI->getIndex()))
+        SV = PseudoSourceValue::getFixedStack(FI->getIndex());
+      else
+        SV = PseudoSourceValue::getStack();
 
-  MachineFunction &MF = getMachineFunction();
   unsigned Flags = MachineMemOperand::MOLoad;
   if (isVolatile)
     Flags |= MachineMemOperand::MOVolatile;
@@ -3806,16 +3822,21 @@ SelectionDAG::getIndexedLoad(SDValue OrigLoad, DebugLoc dl, SDValue Base,
 SDValue SelectionDAG::getStore(SDValue Chain, DebugLoc dl, SDValue Val,
                                SDValue Ptr, const Value *SV, int SVOffset,
                                bool isVolatile, unsigned Alignment) {
+  MachineFunction &MF = getMachineFunction();
+  MachineFrameInfo *FrameInfo = MF.getFrameInfo();
+
   if (Alignment == 0)  // Ensure that codegen never sees alignment 0
     Alignment = getEVTAlignment(Val.getValueType());
 
   // Check if the memory reference references a frame index
   if (!SV)
     if (const FrameIndexSDNode *FI =
-          dyn_cast<const FrameIndexSDNode>(Ptr.getNode()))
-      SV = PseudoSourceValue::getFixedStack(FI->getIndex());
+        dyn_cast<const FrameIndexSDNode>(Ptr.getNode()))
+      if (FrameInfo->isFixedObjectIndex(FI->getIndex()))
+        SV = PseudoSourceValue::getFixedStack(FI->getIndex());
+      else
+        SV = PseudoSourceValue::getStack();
 
-  MachineFunction &MF = getMachineFunction();
   unsigned Flags = MachineMemOperand::MOStore;
   if (isVolatile)
     Flags |= MachineMemOperand::MOVolatile;
@@ -3852,16 +3873,21 @@ SDValue SelectionDAG::getTruncStore(SDValue Chain, DebugLoc dl, SDValue Val,
                                     SDValue Ptr, const Value *SV,
                                     int SVOffset, EVT SVT,
                                     bool isVolatile, unsigned Alignment) {
+  MachineFunction &MF = getMachineFunction();
+  MachineFrameInfo *FrameInfo = MF.getFrameInfo();
+
   if (Alignment == 0)  // Ensure that codegen never sees alignment 0
     Alignment = getEVTAlignment(SVT);
 
   // Check if the memory reference references a frame index
   if (!SV)
     if (const FrameIndexSDNode *FI =
-          dyn_cast<const FrameIndexSDNode>(Ptr.getNode()))
-      SV = PseudoSourceValue::getFixedStack(FI->getIndex());
+        dyn_cast<const FrameIndexSDNode>(Ptr.getNode()))
+      if (FrameInfo->isFixedObjectIndex(FI->getIndex()))
+        SV = PseudoSourceValue::getFixedStack(FI->getIndex());
+      else
+        SV = PseudoSourceValue::getStack();
 
-  MachineFunction &MF = getMachineFunction();
   unsigned Flags = MachineMemOperand::MOStore;
   if (isVolatile)
     Flags |= MachineMemOperand::MOVolatile;
index adcc5322721731184c357e74d7fd75b1dd596585..9c22202eb97b90d96c49d7be7edc2dde10d8d0af 100644 (file)
@@ -4196,9 +4196,11 @@ SelectionDAGLowering::visitIntrinsicCall(CallInst &I, unsigned Intrinsic) {
     SDValue FIN = DAG.getFrameIndex(FI, PtrTy);
 
     // Store the stack protector onto the stack.
+    const Value *SV = MFI->isFixedObjectIndex(FI)
+      ? PseudoSourceValue::getFixedStack(FI)
+      : PseudoSourceValue::getStack();
     SDValue Result = DAG.getStore(getRoot(), getCurDebugLoc(), Src, FIN,
-                                  PseudoSourceValue::getFixedStack(FI),
-                                  0, true);
+                                  SV, 0, true);
     setValue(&I, Result);
     DAG.setRoot(Result);
     return 0;
index fad0808c8931c73d95543c6b3b9c76413c7b86b5..62b2c49943329e9b45e335b8a04c5667e9e89259 100644 (file)
@@ -466,8 +466,10 @@ void StackSlotColoring::RewriteInstruction(MachineInstr *MI, int OldFI,
   // Update the memory references. This changes the MachineMemOperands
   // directly. They may be in use by multiple instructions, however all
   // instructions using OldFI are being rewritten to use NewFI.
-  const Value *OldSV = PseudoSourceValue::getFixedStack(OldFI);
-  const Value *NewSV = PseudoSourceValue::getFixedStack(NewFI);
+  const Value *OldSV = MFI->isFixedObjectIndex(OldFI)
+    ? PseudoSourceValue::getFixedStack(OldFI) : PseudoSourceValue::getStack();
+  const Value *NewSV = MFI->isFixedObjectIndex(NewFI)
+    ? PseudoSourceValue::getFixedStack(NewFI) : PseudoSourceValue::getStack();
   for (MachineInstr::mmo_iterator I = MI->memoperands_begin(),
        E = MI->memoperands_end(); I != E; ++I)
     if ((*I)->getValue() == OldSV)
index c646869e8a735ec30f16123cc187bdbf3f374184..0a925f16f07ecc16c5b67f89df8621a6be7fffef 100644 (file)
@@ -186,8 +186,11 @@ TargetInstrInfo::foldMemoryOperand(MachineFunction &MF,
          "Folded a use to a non-load!");
   const MachineFrameInfo &MFI = *MF.getFrameInfo();
   assert(MFI.getObjectOffset(FrameIndex) != -1);
+  const Value *SV = MFI.isFixedObjectIndex(FrameIndex)
+    ? PseudoSourceValue::getFixedStack(FrameIndex)
+    : PseudoSourceValue::getStack();
   MachineMemOperand *MMO =
-    MF.getMachineMemOperand(PseudoSourceValue::getFixedStack(FrameIndex),
+    MF.getMachineMemOperand(SV,
                             Flags, /*Offset=*/0,
                             MFI.getObjectSize(FrameIndex),
                             MFI.getObjectAlignment(FrameIndex));
index 3920b3815098dd211d286cb0df80f3e275f559f2..2c11636388658bb7dc65a9923b1ec0aa442c2038 100644 (file)
@@ -2225,7 +2225,7 @@ struct TailCallArgumentInfo {
 /// StoreTailCallArgumentsToStackSlot - Stores arguments to their stack slot.
 static void
 StoreTailCallArgumentsToStackSlot(SelectionDAG &DAG,
-                                           SDValue Chain,
+                                  SDValue Chain,
                    const SmallVector<TailCallArgumentInfo, 8> &TailCallArgs,
                    SmallVector<SDValue, 8> &MemOpChains,
                    DebugLoc dl) {
@@ -3388,7 +3388,7 @@ SDValue PPCTargetLowering::LowerSINT_TO_FP(SDValue Op, SelectionDAG &DAG) {
 
   // STD the extended value into the stack slot.
   MachineMemOperand *MMO =
-    MF.getMachineMemOperand(PseudoSourceValue::getFixedStack(FrameIdx),
+    MF.getMachineMemOperand(PseudoSourceValue::getStack(),
                             MachineMemOperand::MOStore, 0, 8, 8);
   SDValue Ops[] = { DAG.getEntryNode(), Ext64, FIdx };
   SDValue Store =
index fadc81839491cf5a8d117a21a0efc4097569f4f1..05442124ad9ddcd38413255c99989393eb59b354 100644 (file)
@@ -1562,7 +1562,7 @@ X86TargetLowering::LowerFormalArguments(SDValue Chain,
         SDValue Val = DAG.getCopyFromReg(Chain, dl, VReg, MVT::i64);
         SDValue Store =
           DAG.getStore(Val.getValue(1), dl, Val, FIN,
-                       PseudoSourceValue::getFixedStack(RegSaveFrameIndex),
+                       PseudoSourceValue::getStack(),
                        Offset);
         MemOps.push_back(Store);
         Offset += 8;
@@ -1765,9 +1765,8 @@ X86TargetLowering::LowerCall(SDValue Chain, SDValue Callee,
     case CCValAssign::Indirect: {
       // Store the argument.
       SDValue SpillSlot = DAG.CreateStackTemporary(VA.getValVT());
-      int FI = cast<FrameIndexSDNode>(SpillSlot)->getIndex();
       Chain = DAG.getStore(Chain, dl, Arg, SpillSlot,
-                           PseudoSourceValue::getFixedStack(FI), 0);
+                           PseudoSourceValue::getStack(), 0);
       Arg = SpillSlot;
       break;
     }
@@ -4868,7 +4867,7 @@ SDValue X86TargetLowering::LowerSINT_TO_FP(SDValue Op, SelectionDAG &DAG) {
   SDValue StackSlot = DAG.getFrameIndex(SSFI, getPointerTy());
   SDValue Chain = DAG.getStore(DAG.getEntryNode(), dl, Op.getOperand(0),
                                StackSlot,
-                               PseudoSourceValue::getFixedStack(SSFI), 0);
+                               PseudoSourceValue::getStack(), 0);
   return BuildFILD(Op, SrcVT, Chain, StackSlot, DAG);
 }
 
@@ -4909,7 +4908,7 @@ SDValue X86TargetLowering::BuildFILD(SDValue Op, EVT SrcVT, SDValue Chain,
     Ops.push_back(InFlag);
     Chain = DAG.getNode(X86ISD::FST, dl, Tys, &Ops[0], Ops.size());
     Result = DAG.getLoad(Op.getValueType(), dl, Chain, StackSlot,
-                         PseudoSourceValue::getFixedStack(SSFI), 0);
+                         PseudoSourceValue::getStack(), 0);
   }
 
   return Result;
@@ -5124,7 +5123,7 @@ FP_TO_INTHelper(SDValue Op, SelectionDAG &DAG, bool IsSigned) {
   if (isScalarFPTypeInSSEReg(Op.getOperand(0).getValueType())) {
     assert(DstTy == MVT::i64 && "Invalid FP_TO_SINT to lower!");
     Chain = DAG.getStore(Chain, dl, Value, StackSlot,
-                         PseudoSourceValue::getFixedStack(SSFI), 0);
+                         PseudoSourceValue::getStack(), 0);
     SDVTList Tys = DAG.getVTList(Op.getOperand(0).getValueType(), MVT::Other);
     SDValue Ops[] = {
       Chain, StackSlot, DAG.getValueType(Op.getOperand(0).getValueType())
@@ -7719,6 +7718,7 @@ X86TargetLowering::EmitVAStartSaveXMMRegsWithCustomInserter(
   // stores were performed.
   const BasicBlock *LLVM_BB = MBB->getBasicBlock();
   MachineFunction *F = MBB->getParent();
+  MachineFrameInfo *MFI = F->getFrameInfo();
   MachineFunction::iterator MBBIter = MBB;
   ++MBBIter;
   MachineBasicBlock *XMMSaveMBB = F->CreateMachineBasicBlock(LLVM_BB);
@@ -7750,13 +7750,14 @@ X86TargetLowering::EmitVAStartSaveXMMRegsWithCustomInserter(
   }
 
   // In the XMM save block, save all the XMM argument registers.
+  const Value *SV = MFI->isFixedObjectIndex(RegSaveFrameIndex)
+    ? PseudoSourceValue::getFixedStack(RegSaveFrameIndex)
+    : PseudoSourceValue::getStack();
   for (int i = 3, e = MI->getNumOperands(); i != e; ++i) {
     int64_t Offset = (i - 3) * 16 + VarArgsFPOffset;
     MachineMemOperand *MMO =
-      F->getMachineMemOperand(
-        PseudoSourceValue::getFixedStack(RegSaveFrameIndex),
-        MachineMemOperand::MOStore, Offset,
-        /*Size=*/16, /*Align=*/16);
+      F->getMachineMemOperand(SV, MachineMemOperand::MOStore, Offset,
+                              /*Size=*/16, /*Align=*/16);
     BuildMI(XMMSaveMBB, DL, TII->get(X86::MOVAPSmr))
       .addFrameIndex(RegSaveFrameIndex)
       .addImm(/*Scale=*/1)