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

Misha Brukman brukman at cs.uiuc.edu
Wed Dec 4 13:24:01 PST 2002


Changes in directory llvm/lib/Target/X86:

InstSelectSimple.cpp updated: 1.49 -> 1.50

---
Log message:

Adjust the stack pointer after a function call, proportional to the number of
arguments pushed onto the stack.


---
Diffs of the changes:

Index: llvm/lib/Target/X86/InstSelectSimple.cpp
diff -u llvm/lib/Target/X86/InstSelectSimple.cpp:1.49 llvm/lib/Target/X86/InstSelectSimple.cpp:1.50
--- llvm/lib/Target/X86/InstSelectSimple.cpp:1.49	Wed Dec  4 11:18:30 2002
+++ llvm/lib/Target/X86/InstSelectSimple.cpp	Wed Dec  4 13:22:53 2002
@@ -393,6 +393,9 @@
 void
 ISel::visitCallInst (CallInst & CI)
 {
+  // keep a counter of how many bytes we pushed on the stack
+  unsigned bytesPushed = 0;
+
   // Push the arguments on the stack in reverse order, as specified by
   // the ABI.
   for (unsigned i = CI.getNumOperands()-1; i >= 1; --i)
@@ -406,11 +409,13 @@
 	  // then push EAX.
 	  promote32 (X86::EAX, v);
 	  BuildMI (BB, X86::PUSHr32, 1).addReg (X86::EAX);
+          bytesPushed += 4;
 	  break;
 	case cInt:
 	case cFloat: {
           unsigned Reg = getReg(v);
           BuildMI (BB, X86::PUSHr32, 1).addReg(Reg);
+          bytesPushed += 4;
 	  break;
         }
 	default:
@@ -421,6 +426,10 @@
     }
   // Emit a CALL instruction with PC-relative displacement.
   BuildMI (BB, X86::CALLpcrel32, 1).addPCDisp (CI.getCalledValue ());
+
+  // Adjust the stack by `bytesPushed' amount if non-zero
+  if (bytesPushed > 0)
+    BuildMI (BB, X86::ADDri32, 2).addReg(X86::ESP).addZImm(bytesPushed);
 }
 
 /// visitSimpleBinary - Implement simple binary operators for integral types...





More information about the llvm-commits mailing list