[llvm-branch-commits] [llvm-branch] r102557 - in /llvm/branches/Apple/Morbo: include/llvm/CodeGen/MachineRegisterInfo.h lib/CodeGen/MachineRegisterInfo.cpp lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp lib/CodeGen/SelectionDAG/FunctionLoweringInfo.h lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp lib/CodeGen/SelectionDAG/SelectionDAGBuilder.h lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp

Evan Cheng evan.cheng at apple.com
Wed Apr 28 16:23:38 PDT 2010


Author: evancheng
Date: Wed Apr 28 18:23:38 2010
New Revision: 102557

URL: http://llvm.org/viewvc/llvm-project?rev=102557&view=rev
Log:
Merge 102553.

Modified:
    llvm/branches/Apple/Morbo/include/llvm/CodeGen/MachineRegisterInfo.h
    llvm/branches/Apple/Morbo/lib/CodeGen/MachineRegisterInfo.cpp
    llvm/branches/Apple/Morbo/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp
    llvm/branches/Apple/Morbo/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.h
    llvm/branches/Apple/Morbo/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
    llvm/branches/Apple/Morbo/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.h
    llvm/branches/Apple/Morbo/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp

Modified: llvm/branches/Apple/Morbo/include/llvm/CodeGen/MachineRegisterInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Morbo/include/llvm/CodeGen/MachineRegisterInfo.h?rev=102557&r1=102556&r2=102557&view=diff
==============================================================================
--- llvm/branches/Apple/Morbo/include/llvm/CodeGen/MachineRegisterInfo.h (original)
+++ llvm/branches/Apple/Morbo/include/llvm/CodeGen/MachineRegisterInfo.h Wed Apr 28 18:23:38 2010
@@ -271,6 +271,10 @@
     return false;
   }
 
+  /// getLiveInPhysReg - If VReg is a live-in virtual register, return the
+  /// corresponding live-in physical register.
+  unsigned getLiveInPhysReg(unsigned VReg) const;
+
 private:
   void HandleVRegListReallocation();
   

Modified: llvm/branches/Apple/Morbo/lib/CodeGen/MachineRegisterInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Morbo/lib/CodeGen/MachineRegisterInfo.cpp?rev=102557&r1=102556&r2=102557&view=diff
==============================================================================
--- llvm/branches/Apple/Morbo/lib/CodeGen/MachineRegisterInfo.cpp (original)
+++ llvm/branches/Apple/Morbo/lib/CodeGen/MachineRegisterInfo.cpp Wed Apr 28 18:23:38 2010
@@ -136,3 +136,12 @@
     I.getOperand().getParent()->dump();
 }
 #endif
+
+/// getLiveInPhysReg - If VReg is a live-in virtual register, return the
+/// corresponding live-in physical register.
+unsigned MachineRegisterInfo::getLiveInPhysReg(unsigned VReg) const {
+  for (livein_iterator I = livein_begin(), E = livein_end(); I != E; ++I)
+    if (I->second == VReg)
+      return I->first;
+  return 0;
+}

Modified: llvm/branches/Apple/Morbo/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Morbo/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp?rev=102557&r1=102556&r2=102557&view=diff
==============================================================================
--- llvm/branches/Apple/Morbo/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp (original)
+++ llvm/branches/Apple/Morbo/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp Wed Apr 28 18:23:38 2010
@@ -246,6 +246,7 @@
   CatchInfoFound.clear();
 #endif
   LiveOutRegInfo.clear();
+  ArgDbgValues.clear();
 }
 
 unsigned FunctionLoweringInfo::MakeReg(EVT VT) {

Modified: llvm/branches/Apple/Morbo/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Morbo/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.h?rev=102557&r1=102556&r2=102557&view=diff
==============================================================================
--- llvm/branches/Apple/Morbo/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.h (original)
+++ llvm/branches/Apple/Morbo/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.h Wed Apr 28 18:23:38 2010
@@ -33,6 +33,7 @@
 class Instruction;
 class MachineBasicBlock;
 class MachineFunction;
+class MachineInstr;
 class MachineModuleInfo;
 class MachineRegisterInfo;
 class TargetLowering;
@@ -77,6 +78,8 @@
   /// anywhere in the function.
   DenseMap<const AllocaInst*, int> StaticAllocaMap;
 
+  SmallVector<MachineInstr*, 8> ArgDbgValues;
+
 #ifndef NDEBUG
   SmallSet<Instruction*, 8> CatchInfoLost;
   SmallSet<Instruction*, 8> CatchInfoFound;

Modified: llvm/branches/Apple/Morbo/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Morbo/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp?rev=102557&r1=102556&r2=102557&view=diff
==============================================================================
--- llvm/branches/Apple/Morbo/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp (original)
+++ llvm/branches/Apple/Morbo/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp Wed Apr 28 18:23:38 2010
@@ -3696,6 +3696,41 @@
   return DAG.getNode(ISD::FPOWI, DL, LHS.getValueType(), LHS, RHS);
 }
 
+/// EmitFuncArgumentDbgValue - If the DbgValueInst is a dbg_value of a function
+/// argument, create the corresponding DBG_VALUE machine instruction for it now.
+/// At the end of instruction selection, they will be inserted to the entry BB.
+void
+SelectionDAGBuilder::EmitFuncArgumentDbgValue(const DbgValueInst &DI,
+                                              const Value *V, MDNode *Variable,
+                                              uint64_t Offset, SDValue &N) {
+  if (!isa<Argument>(V))
+    return;
+
+  MachineFunction &MF = DAG.getMachineFunction();
+  MachineBasicBlock *MBB = FuncInfo.MBBMap[DI.getParent()];
+  if (MBB != &MF.front())
+    return;
+
+  unsigned Reg = 0;
+  if (N.getOpcode() == ISD::CopyFromReg) {
+    Reg = cast<RegisterSDNode>(N.getOperand(1))->getReg();
+    if (TargetRegisterInfo::isVirtualRegister(Reg)) {
+      MachineRegisterInfo &RegInfo = MF.getRegInfo();
+      unsigned PR = RegInfo.getLiveInPhysReg(Reg);
+      if (PR)
+        Reg = PR;
+    }
+  }
+
+  if (!Reg)
+    Reg = FuncInfo.ValueMap[V];
+
+  const TargetInstrInfo *TII = DAG.getTarget().getInstrInfo();
+  MachineInstrBuilder MIB = BuildMI(MF, getCurDebugLoc(),
+                                    TII->get(TargetOpcode::DBG_VALUE))
+    .addReg(Reg).addImm(Offset).addMetadata(Variable);
+  FuncInfo.ArgDbgValues.push_back(&*MIB);
+}
 
 /// visitIntrinsicCall - Lower the call to the specified intrinsic function.  If
 /// we want to emit this as a call to a named external function, return the name
@@ -3885,6 +3920,7 @@
     } else {
       SDValue &N = NodeMap[V];
       if (N.getNode()) {
+        EmitFuncArgumentDbgValue(DI, V, Variable, Offset, N);
         SDV = DAG.getDbgValue(Variable, N.getNode(),
                               N.getResNo(), Offset, dl, SDNodeOrder);
         DAG.AddDbgValue(SDV, N.getNode(), false);

Modified: llvm/branches/Apple/Morbo/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Morbo/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.h?rev=102557&r1=102556&r2=102557&view=diff
==============================================================================
--- llvm/branches/Apple/Morbo/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.h (original)
+++ llvm/branches/Apple/Morbo/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.h Wed Apr 28 18:23:38 2010
@@ -36,6 +36,7 @@
 class BitCastInst;
 class BranchInst;
 class CallInst;
+class DbgValueInst;
 class ExtractElementInst;
 class ExtractValueInst;
 class FCmpInst;
@@ -59,6 +60,7 @@
 class MachineFunction;
 class MachineInstr;
 class MachineRegisterInfo;
+class MDNode;
 class PHINode;
 class PtrToIntInst;
 class ReturnInst;
@@ -493,6 +495,14 @@
   
   const char *implVisitBinaryAtomic(CallInst& I, ISD::NodeType Op);
   const char *implVisitAluOverflow(CallInst &I, ISD::NodeType Op);
+
+   /// EmitFuncArgumentDbgValue - If the DbgValueInst is a dbg_value of a
+   /// function argument, create the corresponding DBG_VALUE machine instruction
+   /// for it now. At the end of instruction selection, they will be inserted to
+   /// the entry BB.
+   void EmitFuncArgumentDbgValue(const DbgValueInst &DI,
+                                 const Value *V, MDNode *Variable,
+                                 uint64_t Offset, SDValue &N);
 };
 
 } // end namespace llvm

Modified: llvm/branches/Apple/Morbo/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Morbo/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp?rev=102557&r1=102556&r2=102557&view=diff
==============================================================================
--- llvm/branches/Apple/Morbo/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp (original)
+++ llvm/branches/Apple/Morbo/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp Wed Apr 28 18:23:38 2010
@@ -241,30 +241,6 @@
   }
 }
 
-/// InsertLiveInDbgValue - Insert a DBG_VALUE instruction for each live-in
-/// register that has a corresponding source information metadata. e.g.
-/// function parameters.
-static void InsertLiveInDbgValue(MachineBasicBlock *MBB,
-                                 MachineBasicBlock::iterator InsertPos,
-                                 unsigned LiveInReg, unsigned VirtReg,
-                                 const MachineRegisterInfo &MRI,
-                                 const TargetInstrInfo &TII) {
-  for (MachineRegisterInfo::use_iterator UI = MRI.use_begin(VirtReg),
-         UE = MRI.use_end(); UI != UE; ++UI) {
-    MachineInstr *UseMI = &*UI;
-    if (!UseMI->isDebugValue() || UseMI->getParent() != MBB)
-      continue;
-    // Found local dbg_value. FIXME: Verify it's not possible to have multiple
-    // dbg_value's which reference the vr in the same mbb.
-    uint64_t Offset = UseMI->getOperand(1).getImm();
-    const MDNode *MDPtr = UseMI->getOperand(2).getMetadata();    
-    BuildMI(*MBB, InsertPos, InsertPos->getDebugLoc(),
-            TII.get(TargetOpcode::DBG_VALUE))
-      .addReg(LiveInReg).addImm(Offset).addMetadata(MDPtr);
-    return;
-  }
-}
-
 /// EmitLiveInCopies - If this is the first basic block in the function,
 /// and if it has live ins that need to be copied into vregs, emit the
 /// copies into the block.
@@ -282,8 +258,6 @@
         const TargetRegisterClass *RC = MRI.getRegClass(LI->second);
         EmitLiveInCopy(EntryMBB, InsertPos, LI->second, LI->first,
                        RC, CopyRegMap, MRI, TRI, TII);
-        InsertLiveInDbgValue(EntryMBB, InsertPos,
-                             LI->first, LI->second, MRI, TII);
       }
   } else {
     // Emit the copies into the top of the block.
@@ -295,8 +269,6 @@
                                         LI->second, LI->first, RC, RC);
         assert(Emitted && "Unable to issue a live-in copy instruction!\n");
         (void) Emitted;
-        InsertLiveInDbgValue(EntryMBB, EntryMBB->begin(),
-                             LI->first, LI->second, MRI, TII);
       }
   }
 }
@@ -374,7 +346,8 @@
   // If the first basic block in the function has live ins that need to be
   // copied into vregs, emit the copies into the top of the block before
   // emitting the code for the block.
-  EmitLiveInCopies(MF->begin(), *RegInfo, TRI, TII);
+  MachineBasicBlock *EntryMBB = MF->begin();
+  EmitLiveInCopies(EntryMBB, *RegInfo, TRI, TII);
 
   // Add function live-ins to entry block live-in set.
   for (MachineRegisterInfo::livein_iterator I = RegInfo->livein_begin(),
@@ -386,6 +359,19 @@
          "Not all catch info was assigned to a landing pad!");
 #endif
 
+  // Insert DBG_VALUE instructions for function arguments to the entry block.
+  for (unsigned i = 0, e = FuncInfo->ArgDbgValues.size(); i != e; ++i) {
+    MachineInstr *MI = FuncInfo->ArgDbgValues[e-i-1];
+    unsigned Reg = MI->getOperand(0).getReg();
+    if (TargetRegisterInfo::isPhysicalRegister(Reg))
+      EntryMBB->insert(EntryMBB->begin(), MI);
+    else {
+      MachineInstr *Def = RegInfo->getVRegDef(Reg);
+      MachineBasicBlock::iterator InsertPos = Def;
+      EntryMBB->insert(llvm::next(InsertPos), MI);
+    }
+  }
+
   FuncInfo->clear();
 
   return true;





More information about the llvm-branch-commits mailing list