[llvm-commits] CVS: llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp

Duncan Sands baldrick at free.fr
Tue Jun 12 22:51:53 PDT 2007



Changes in directory llvm/lib/CodeGen/SelectionDAG:

SelectionDAGISel.cpp updated: 1.458 -> 1.459
---
Log message:

The fix that was applied for PR1224: http://llvm.org/PR1224  stops the compiler
crashing but breaks exception handling.  The problem
described in PR1224: http://llvm.org/PR1224  is that invoke is a terminator that
can produce a value.  The value may be needed in other
blocks.  The code that writes to registers values needed
in other blocks runs before terminators are lowered (in
this case invoke) so asserted because the value was not
yet available.  The fix that was applied was to do invoke
lowering earlier, before writing values to registers.

The problem this causes is that the code to copy values
to registers can be output after the invoke call.  If
an exception is raised and control is passed to the
landing pad then this copy-code will never execute.  If
the value is needed in some code path reached via the
landing pad then that code will get something bogus.

So revert the original fix and simply skip invoke values
in the general copying to registers code.  Instead copy
the invoke value to a register in the invoke lowering code.


---
Diffs of the changes:  (+25 -33)

 SelectionDAGISel.cpp |   58 +++++++++++++++++++++------------------------------
 1 files changed, 25 insertions(+), 33 deletions(-)


Index: llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
diff -u llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:1.458 llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:1.459
--- llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:1.458	Thu Jun  7 16:07:15 2007
+++ llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp	Wed Jun 13 00:51:31 2007
@@ -566,7 +566,6 @@
   
   // These all get lowered before this pass.
   void visitInvoke(InvokeInst &I);
-  void visitInvoke(InvokeInst &I, bool AsTerminator);
   void visitUnwind(UnwindInst &I);
 
   void visitScalarBinary(User &I, unsigned OpCode);
@@ -1332,29 +1331,31 @@
 }
 
 void SelectionDAGLowering::visitInvoke(InvokeInst &I) {
-  assert(0 && "Should never be visited directly");
-}
-void SelectionDAGLowering::visitInvoke(InvokeInst &I, bool AsTerminator) {
   // Retrieve successors.
   MachineBasicBlock *Return = FuncInfo.MBBMap[I.getSuccessor(0)];
+  MachineBasicBlock *LandingPad = FuncInfo.MBBMap[I.getSuccessor(1)];
 
-  if (!AsTerminator) {
-    MachineBasicBlock *LandingPad = FuncInfo.MBBMap[I.getSuccessor(1)];
-
-    LowerCallTo(I, I.getCalledValue()->getType(),
-                I.getCallingConv(),
-                false,
-                getValue(I.getOperand(0)),
-                3, LandingPad);
-
-    // Update successor info
-    CurMBB->addSuccessor(Return);
-    CurMBB->addSuccessor(LandingPad);
-  } else {
-    // Drop into normal successor.
-    DAG.setRoot(DAG.getNode(ISD::BR, MVT::Other, getRoot(), 
-                            DAG.getBasicBlock(Return)));
+  LowerCallTo(I, I.getCalledValue()->getType(),
+              I.getCallingConv(),
+              false,
+              getValue(I.getOperand(0)),
+              3, LandingPad);
+
+  // 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())
+      DAG.setRoot(CopyValueToVirtualRegister(&I, VMI->second));
   }
+
+  // Drop into normal successor.
+  DAG.setRoot(DAG.getNode(ISD::BR, MVT::Other, getRoot(),
+                          DAG.getBasicBlock(Return)));
+
+  // Update successor info
+  CurMBB->addSuccessor(Return);
+  CurMBB->addSuccessor(LandingPad);
 }
 
 void SelectionDAGLowering::visitUnwind(UnwindInst &I) {
@@ -4546,15 +4547,11 @@
   for (BasicBlock::iterator I = LLVMBB->begin(), E = --LLVMBB->end();
        I != E; ++I)
     SDL.visit(*I);
-    
-  // Lower call part of invoke.
-  InvokeInst *Invoke = dyn_cast<InvokeInst>(LLVMBB->getTerminator());
-  if (Invoke) SDL.visitInvoke(*Invoke, false);
-  
+
   // Ensure that all instructions which are used outside of their defining
-  // blocks are available as virtual registers.
+  // blocks are available as virtual registers.  Invoke is handled elsewhere.
   for (BasicBlock::iterator I = LLVMBB->begin(), E = LLVMBB->end(); I != E;++I)
-    if (!I->use_empty() && !isa<PHINode>(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())
         UnorderedChains.push_back(
@@ -4662,12 +4659,7 @@
   }
 
   // Lower the terminator after the copies are emitted.
-  if (Invoke) {
-    // Just the branch part of invoke.
-    SDL.visitInvoke(*Invoke, true);
-  } else {
-    SDL.visit(*LLVMBB->getTerminator());
-  }
+  SDL.visit(*LLVMBB->getTerminator());
 
   // Copy over any CaseBlock records that may now exist due to SwitchInst
   // lowering, as well as any jump table information.






More information about the llvm-commits mailing list