[llvm-commits] CVS: llvm/lib/Target/X86/X86ISelPattern.cpp

Chris Lattner lattner at cs.uiuc.edu
Fri May 13 15:14:05 PDT 2005



Changes in directory llvm/lib/Target/X86:

X86ISelPattern.cpp updated: 1.130 -> 1.131
---
Log message:

Fix the problems with callee popped argument lists


---
Diffs of the changes:  (+37 -1)

 X86ISelPattern.cpp |   38 +++++++++++++++++++++++++++++++++++++-
 1 files changed, 37 insertions(+), 1 deletion(-)


Index: llvm/lib/Target/X86/X86ISelPattern.cpp
diff -u llvm/lib/Target/X86/X86ISelPattern.cpp:1.130 llvm/lib/Target/X86/X86ISelPattern.cpp:1.131
--- llvm/lib/Target/X86/X86ISelPattern.cpp:1.130	Fri May 13 16:50:27 2005
+++ llvm/lib/Target/X86/X86ISelPattern.cpp	Fri May 13 17:13:49 2005
@@ -3746,7 +3746,43 @@
 
     // Amount the callee added to the stack pointer.
     Tmp2 = cast<ConstantSDNode>(N.getOperand(2))->getValue();
-    BuildMI(BB, X86::ADJCALLSTACKUP, 2).addImm(Tmp1).addImm(Tmp2);
+
+    // This hackery is due to the fact that we don't want to emit this code:
+    //   call foo
+    //   mov vreg, EAX
+    //   adjcallstackup 
+    //
+    // Because if foo is a fastcc call and if vreg gets spilled, we might end up
+    // with this:
+    //   call foo
+    //   mov [ESP+offset], EAX     ;; Offset doesn't consider the 12!
+    //   sub ESP, 12
+    //
+    // To avoid this, we force the adjcallstackup instruction before the 0, 1 or
+    // 2 moves that occur after the call.  The correct way to fix this is to use
+    // target-specific DAG nodes in the call sequence. FIXME!
+    //
+    if (EnableFastCC) {
+      // This code should be safe.  Be defensive for LLVM 1.5 release though.
+      assert(!BB->empty());
+      MachineBasicBlock::iterator PrevI = --BB->end();
+      if (PrevI->getOpcode() == X86::CALLpcrel32 ||
+          PrevI->getOpcode() == X86::CALL32r)
+        ++PrevI;
+      else if (PrevI != BB->begin() &&
+               ((--PrevI)->getOpcode() == X86::CALLpcrel32 ||
+                PrevI->getOpcode() == X86::CALL32r))
+        ++PrevI;
+      else if (PrevI != BB->begin() &&
+               ((--PrevI)->getOpcode() == X86::CALLpcrel32 ||
+                PrevI->getOpcode() == X86::CALL32r))
+        ++PrevI;
+      else
+        PrevI = BB->end();
+      BuildMI(*BB, PrevI, X86::ADJCALLSTACKUP, 2).addImm(Tmp1).addImm(Tmp2);
+    } else {
+      BuildMI(*BB, PrevI, X86::ADJCALLSTACKUP, 2).addImm(Tmp1).addImm(Tmp2);
+    }
     return;
   case ISD::MEMSET: {
     Select(N.getOperand(0));  // Select the chain.






More information about the llvm-commits mailing list