Factor out a bit of code that appears in several places into a
authorDan Gohman <gohman@apple.com>
Thu, 23 Apr 2009 23:13:24 +0000 (23:13 +0000)
committerDan Gohman <gohman@apple.com>
Thu, 23 Apr 2009 23:13:24 +0000 (23:13 +0000)
utility function.

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

lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp
lib/CodeGen/SelectionDAG/SelectionDAGBuild.h
lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp

index fd5fcbb1aad18d07fcebeae61c7908d0d89e7d53..3e6da24a4a1a8ed69b2640f96759021b6c5afa9b 100644 (file)
@@ -1020,6 +1020,17 @@ void SelectionDAGLowering::visitRet(ReturnInst &I) {
                           &NewValues[0], NewValues.size()));
 }
 
+/// CopyToExportRegsIfNeeded - If the given value has virtual registers
+/// created for it, emit nodes to copy the value into the virtual
+/// registers.
+void SelectionDAGLowering::CopyToExportRegsIfNeeded(Value *V) {
+  if (!V->use_empty()) {
+    DenseMap<const Value *, unsigned>::iterator VMI = FuncInfo.ValueMap.find(V);
+    if (VMI != FuncInfo.ValueMap.end())
+      CopyValueToVirtualRegister(V, VMI->second);
+  }
+}
+
 /// ExportFromCurrentBlock - If this condition isn't known to be exported from
 /// the current basic block, add it to ValueMap now so that we'll get a
 /// CopyTo/FromReg.
@@ -1572,11 +1583,7 @@ void SelectionDAGLowering::visitInvoke(InvokeInst &I) {
 
   // If the value of the invoke is used outside of its defining block, make it
   // available as a virtual register.
-  if (!I.use_empty()) {
-    DenseMap<const Value*, unsigned>::iterator VMI = FuncInfo.ValueMap.find(&I);
-    if (VMI != FuncInfo.ValueMap.end())
-      CopyValueToVirtualRegister(&I, VMI->second);
-  }
+  CopyToExportRegsIfNeeded(&I);
 
   // Update successor info
   CurMBB->addSuccessor(Return);
@@ -5924,10 +5931,7 @@ LowerArguments(BasicBlock *LLVMBB) {
                                                 SDL->getCurDebugLoc()));
       // If this argument is live outside of the entry block, insert a copy from
       // whereever we got it to the vreg that other BB's will reference it as.
-      DenseMap<const Value*, unsigned>::iterator VMI=FuncInfo->ValueMap.find(AI);
-      if (VMI != FuncInfo->ValueMap.end()) {
-        SDL->CopyValueToVirtualRegister(AI, VMI->second);
-      }
+      SDL->CopyToExportRegsIfNeeded(AI);
     }
     a += NumValues;
   }
index 7a76c5f83d2bba6a5470e6f71929eb2ac492d557..ecac1ae0a2fe00ca72ee5c1c419330c12a1da403 100644 (file)
@@ -422,6 +422,7 @@ public:
                                     MachineBasicBlock *CurBB);
   bool ShouldEmitAsBranches(const std::vector<CaseBlock> &Cases);
   bool isExportableFromCurrentBlock(Value *V, const BasicBlock *FromBB);
+  void CopyToExportRegsIfNeeded(Value *V);
   void ExportFromCurrentBlock(Value *V);
   void LowerCallTo(CallSite CS, SDValue Callee, bool IsTailCall,
                    MachineBasicBlock *LandingPad = NULL);
index 49ff4f2a5d5aa428294e22a92f84dd051ecd1004..2953472da967c6ab9babcb57d660886889a90deb 100644 (file)
@@ -476,11 +476,8 @@ void SelectionDAGISel::SelectBasicBlock(BasicBlock *LLVMBB,
   // Ensure that all instructions which are used outside of their defining
   // blocks are available as virtual registers.  Invoke is handled elsewhere.
   for (BasicBlock::iterator I = Begin; I != End; ++I)
-    if (!I->use_empty() && !isa<PHINode>(I) && !isa<InvokeInst>(I)) {
-      DenseMap<const Value*,unsigned>::iterator VMI =FuncInfo->ValueMap.find(I);
-      if (VMI != FuncInfo->ValueMap.end())
-        SDL->CopyValueToVirtualRegister(I, VMI->second);
-    }
+    if (!isa<PHINode>(I) && !isa<InvokeInst>(I))
+      SDL->CopyToExportRegsIfNeeded(I);
 
   // Handle PHI nodes in successor blocks.
   if (End == LLVMBB->end()) {