- Move TargetLowering::EmitTargetCodeForFrameDebugValue to TargetInstrInfo and rename...
authorEvan Cheng <evan.cheng@apple.com>
Mon, 26 Apr 2010 07:38:55 +0000 (07:38 +0000)
committerEvan Cheng <evan.cheng@apple.com>
Mon, 26 Apr 2010 07:38:55 +0000 (07:38 +0000)
- Teach spiller to modify DBG_VALUE instructions to reference spill slots.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@102323 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Target/TargetInstrInfo.h
include/llvm/Target/TargetLowering.h
lib/CodeGen/LiveIntervalAnalysis.cpp
lib/CodeGen/SelectionDAG/InstrEmitter.cpp
lib/CodeGen/SelectionDAG/InstrEmitter.h
lib/CodeGen/SelectionDAG/ScheduleDAGSDNodes.cpp
lib/Target/X86/X86ISelLowering.cpp
lib/Target/X86/X86ISelLowering.h
lib/Target/X86/X86InstrInfo.cpp
lib/Target/X86/X86InstrInfo.h

index 959f55219ed7e59513db4e5d3b2d2df9517cca27..db1a15b534c602ad07aa0c8ff60309ce85b4d6a7 100644 (file)
@@ -23,6 +23,7 @@ class CalleeSavedInfo;
 class LiveVariables;
 class MCAsmInfo;
 class MachineMemOperand;
+class MDNode;
 class SDNode;
 class SelectionDAG;
 class TargetRegisterClass;
@@ -361,6 +362,19 @@ public:
     return false;
   }
   
+  /// emitFrameIndexDebugValue - Emit a target-dependent form of
+  /// DBG_VALUE encoding the address of a frame index.  Addresses would
+  /// normally be lowered the same way as other addresses on the target,
+  /// e.g. in load instructions.  For targets that do not support this
+  /// the debug info is simply lost.
+  virtual MachineInstr *emitFrameIndexDebugValue(MachineFunction &MF,
+                                                 unsigned FrameIx,
+                                                 uint64_t Offset,
+                                                 const MDNode *MDPtr,
+                                                 DebugLoc dl) const {
+    return 0;
+  }
+
   /// foldMemoryOperand - Attempt to fold a load or store of the specified stack
   /// slot into the specified machine instruction for the specified operand(s).
   /// If this is possible, a new instruction is returned with the specified
index 2c77331533a388383ab27202f6b4a30d5b3f932c..58037dded131ea23a83ec911e5a36a8e004d50b8 100644 (file)
@@ -1255,16 +1255,6 @@ public:
     return SDValue();
   }
 
-  /// EmitTargetCodeForFrameDebugValue - Emit a target-dependent form of
-  /// DBG_VALUE encoding the address of a frame index.  Addresses would
-  /// normally be lowered the same way as other addresses on the target,
-  /// e.g. in load instructions.  For targets that do not support this
-  /// the debug info is simply lost.
-  virtual void
-  EmitTargetCodeForFrameDebugValue(MachineBasicBlock* BB, unsigned FrameIx,
-                                   uint64_t Offset, MDNode *MDPtr,
-                                   DebugLoc dl) const {}
-
   /// LowerOperationWrapper - This callback is invoked by the type legalizer
   /// to legalize nodes with an illegal operand type but legal result types.
   /// It replaces the LowerOperation callback in the type Legalizer.
index 1f00ccbbb01b877947e2b09f063fbcdf4b9df96f..9e6c70db403b8f55c21031503fd35cb28ff51331 100644 (file)
@@ -1296,9 +1296,23 @@ rewriteInstructionsForSpills(const LiveInterval &li, bool TrySplit,
     MachineOperand &O = ri.getOperand();
     ++ri;
     if (MI->isDebugValue()) {
-      // Remove debug info for now.
-      O.setReg(0U);
-      DEBUG(dbgs() << "Removing debug info due to spill:" << "\t" << *MI);
+      // Modify DBG_VALUE now that the value is in a spill slot.
+      uint64_t Offset = MI->getOperand(1).getImm();
+      const MDNode *MDPtr = MI->getOperand(2).getMetadata();
+      DebugLoc DL = MI->getDebugLoc();
+      MachineInstr *NewDV = tii_->emitFrameIndexDebugValue(*mf_, Slot, Offset,
+                                                           MDPtr, DL);
+      if (NewDV) {
+        DEBUG(dbgs() << "Modifying debug info due to spill:" << "\t" << *MI);
+        ReplaceMachineInstrInMaps(MI, NewDV);
+        MachineBasicBlock *MBB = MI->getParent();
+        MBB->insert(MBB->erase(MI), NewDV);
+      } else {
+        DEBUG(dbgs() << "Removing debug info due to spill:" << "\t" << *MI);
+        RemoveMachineInstrFromMaps(MI);
+        vrm.RemoveMachineInstrFromMaps(MI);
+        MI->eraseFromParent();
+      }
       continue;
     }
     assert(!O.isImplicit() && "Spilling register that's used as implicit use?");
index ff77d82cc9434afc10c1088ee2a3d773158ef5d5..1afca3debf8858c58361bce81568631c9a6a70d7 100644 (file)
@@ -507,7 +507,6 @@ InstrEmitter::EmitCopyToRegClassNode(SDNode *Node,
 /// EmitDbgValue - Generate machine instruction for a dbg_value node.
 ///
 MachineInstr *InstrEmitter::EmitDbgValue(SDDbgValue *SD,
-                                         MachineBasicBlock *InsertBB,
                                          DenseMap<SDValue, unsigned> &VRBaseMap,
                          DenseMap<MachineBasicBlock*, MachineBasicBlock*> *EM) {
   uint64_t Offset = SD->getOffset();
@@ -518,8 +517,7 @@ MachineInstr *InstrEmitter::EmitDbgValue(SDDbgValue *SD,
     // Stack address; this needs to be lowered in target-dependent fashion.
     // EmitTargetCodeForFrameDebugValue is responsible for allocation.
     unsigned FrameIx = SD->getFrameIx();
-    TLI->EmitTargetCodeForFrameDebugValue(InsertBB, FrameIx, Offset, MDPtr, DL);
-    return 0;
+    return TII->emitFrameIndexDebugValue(*MF, FrameIx, Offset, MDPtr, DL);
   }
   // Otherwise, we're going to create an instruction here.
   const TargetInstrDesc &II = TII->get(TargetOpcode::DBG_VALUE);
index baabb7554b60b30a5061fb276e9e402c0d9d886b..f8fd6ef8b8b5180310fb672ffc38565d28127622 100644 (file)
@@ -103,7 +103,6 @@ public:
   /// EmitDbgValue - Generate machine instruction for a dbg_value node.
   ///
   MachineInstr *EmitDbgValue(SDDbgValue *SD,
-                          MachineBasicBlock *InsertBB,
                           DenseMap<SDValue, unsigned> &VRBaseMap,
                           DenseMap<MachineBasicBlock*, MachineBasicBlock*> *EM);
 
index 50defc8187cc4980ceb1da8d04106d012d542477..a4cadc3d5ccffeef2c7ec94b4471aa8e22c7dad2 100644 (file)
@@ -449,9 +449,11 @@ static void ProcessSourceNode(SDNode *N, SelectionDAG *DAG,
       continue;
     unsigned DVOrder = DVs[i]->getOrder();
     if (DVOrder == ++Order) {
-      MachineInstr *DbgMI = Emitter.EmitDbgValue(DVs[i], BB, VRBaseMap, EM);
-      Orders.push_back(std::make_pair(DVOrder, DbgMI));
-      BB->insert(InsertPos, DbgMI);
+      MachineInstr *DbgMI = Emitter.EmitDbgValue(DVs[i], VRBaseMap, EM);
+      if (DbgMI) {
+        Orders.push_back(std::make_pair(DVOrder, DbgMI));
+        BB->insert(InsertPos, DbgMI);
+      }
       DVs[i]->setIsInvalidated();
     }
   }
@@ -540,13 +542,15 @@ EmitSchedule(DenseMap<MachineBasicBlock*, MachineBasicBlock*> *EM) {
 #endif
         if ((*DI)->isInvalidated())
           continue;
-        MachineInstr *DbgMI = Emitter.EmitDbgValue(*DI, MIBB, VRBaseMap, EM);
-        if (!LastOrder)
-          // Insert to start of the BB (after PHIs).
-          BB->insert(BBBegin, DbgMI);
-        else {
-          MachineBasicBlock::iterator Pos = MI;
-          MIBB->insert(llvm::next(Pos), DbgMI);
+        MachineInstr *DbgMI = Emitter.EmitDbgValue(*DI, VRBaseMap, EM);
+        if (DbgMI) {
+          if (!LastOrder)
+            // Insert to start of the BB (after PHIs).
+            BB->insert(BBBegin, DbgMI);
+          else {
+            MachineBasicBlock::iterator Pos = MI;
+            MIBB->insert(llvm::next(Pos), DbgMI);
+          }
         }
       }
       LastOrder = Order;
@@ -558,8 +562,9 @@ EmitSchedule(DenseMap<MachineBasicBlock*, MachineBasicBlock*> *EM) {
       MachineBasicBlock *InsertBB = Emitter.getBlock();
       MachineBasicBlock::iterator Pos= Emitter.getBlock()->getFirstTerminator();
       if (!(*DI)->isInvalidated()) {
-        MachineInstr *DbgMI= Emitter.EmitDbgValue(*DI, InsertBB, VRBaseMap, EM);
-        InsertBB->insert(Pos, DbgMI);
+        MachineInstr *DbgMI= Emitter.EmitDbgValue(*DI, VRBaseMap, EM);
+        if (DbgMI)
+          InsertBB->insert(Pos, DbgMI);
       }
       ++DI;
     }
index 6a14fda5b4d43f95ff35199c1172c45678afa364..fc20d43274cf24547e6d84ad14b06122eec1d415 100644 (file)
@@ -8622,19 +8622,6 @@ X86TargetLowering::EmitLoweredMingwAlloca(MachineInstr *MI,
   return BB;
 }
 
-void
-X86TargetLowering::EmitTargetCodeForFrameDebugValue(MachineBasicBlock* BB,
-                                      unsigned FrameIx, uint64_t Offset,
-                                      MDNode *MDPtr, DebugLoc DL) const {
-  // Target dependent DBG_VALUE.  Only the frame index case is done here.
-  const TargetInstrInfo *TII = getTargetMachine().getInstrInfo();
-  X86AddressMode AM;
-  AM.BaseType = X86AddressMode::FrameIndexBase;
-  AM.Base.FrameIndex = FrameIx;
-  addFullAddress(BuildMI(BB, DL, TII->get(X86::DBG_VALUE)), AM).
-    addImm(Offset).addMetadata(MDPtr);
-}
-
 MachineBasicBlock *
 X86TargetLowering::EmitInstrWithCustomInserter(MachineInstr *MI,
                                                MachineBasicBlock *BB,
index 79cd08bdc7918fc725b000a637f87c232e067f13..7996184f33f309066f49a137e92f76e4259e0237 100644 (file)
@@ -453,11 +453,6 @@ namespace llvm {
     /// and some i16 instructions are slow.
     virtual bool IsDesirableToPromoteOp(SDValue Op, EVT &PVT) const;
 
-    virtual void
-    EmitTargetCodeForFrameDebugValue(MachineBasicBlock* BB,
-                                     unsigned FrameIx, uint64_t Offset,
-                                     MDNode *MDPtr, DebugLoc DL) const;
-
     virtual MachineBasicBlock *EmitInstrWithCustomInserter(MachineInstr *MI,
                                                          MachineBasicBlock *MBB,
                     DenseMap<MachineBasicBlock*, MachineBasicBlock*> *EM) const;
index 1192a471bd724914f1f87d8729009b00fe593727..ebcd8cc535c006367597f90498b5239b9bb926ba 100644 (file)
@@ -2319,6 +2319,20 @@ bool X86InstrInfo::restoreCalleeSavedRegisters(MachineBasicBlock &MBB,
   return true;
 }
 
+MachineInstr*
+X86InstrInfo::emitFrameIndexDebugValue(MachineFunction &MF,
+                                       unsigned FrameIx, uint64_t Offset,
+                                       const MDNode *MDPtr,
+                                       DebugLoc DL) const {
+  // Target dependent DBG_VALUE.  Only the frame index case is done here.
+  X86AddressMode AM;
+  AM.BaseType = X86AddressMode::FrameIndexBase;
+  AM.Base.FrameIndex = FrameIx;
+  MachineInstrBuilder MIB = BuildMI(MF, DL, get(X86::DBG_VALUE));
+  addFullAddress(MIB, AM).addImm(Offset).addMetadata(MDPtr);
+  return &*MIB;
+}
+
 static MachineInstr *FuseTwoAddrInst(MachineFunction &MF, unsigned Opcode,
                                      const SmallVectorImpl<MachineOperand> &MOs,
                                      MachineInstr *MI,
index f0bdd06cce88212baa01661bdc514cca0e320ff8..3626f96b6aa77c37786c0e04f7de8f691e8a07d7 100644 (file)
@@ -623,6 +623,12 @@ public:
                                            MachineBasicBlock::iterator MI,
                                  const std::vector<CalleeSavedInfo> &CSI) const;
   
+  virtual
+  MachineInstr *emitFrameIndexDebugValue(MachineFunction &MF,
+                                         unsigned FrameIx, uint64_t Offset,
+                                         const MDNode *MDPtr,
+                                         DebugLoc DL) const;
+
   /// foldMemoryOperand - If this target supports it, fold a load or store of
   /// the specified stack slot into the specified machine instruction for the
   /// specified operand(s).  If this is possible, the target should perform the