aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMisha Brukman <brukman+llvm@gmail.com>2002-12-04 19:22:53 +0000
committerMisha Brukman <brukman+llvm@gmail.com>2002-12-04 19:22:53 +0000
commit0d2cf3a533572ee2f4a08f997499d18e41a37176 (patch)
tree91f68dc5690eb2b432e47ff11ad300215b65392d
parenta17a2ac727dec57f08ff2c651fbdf3d780c5ef27 (diff)
Adjust the stack pointer after a function call, proportional to the number of
arguments pushed onto the stack. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@4922 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Target/X86/InstSelectSimple.cpp9
-rw-r--r--lib/Target/X86/X86ISelSimple.cpp9
2 files changed, 18 insertions, 0 deletions
diff --git a/lib/Target/X86/InstSelectSimple.cpp b/lib/Target/X86/InstSelectSimple.cpp
index 65bfb1c7ed..55bf65b2f5 100644
--- a/lib/Target/X86/InstSelectSimple.cpp
+++ b/lib/Target/X86/InstSelectSimple.cpp
@@ -393,6 +393,9 @@ ISel::visitBranchInst (BranchInst & BI)
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 @@ ISel::visitCallInst (CallInst & CI)
// 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 @@ ISel::visitCallInst (CallInst & CI)
}
// 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...
diff --git a/lib/Target/X86/X86ISelSimple.cpp b/lib/Target/X86/X86ISelSimple.cpp
index 65bfb1c7ed..55bf65b2f5 100644
--- a/lib/Target/X86/X86ISelSimple.cpp
+++ b/lib/Target/X86/X86ISelSimple.cpp
@@ -393,6 +393,9 @@ ISel::visitBranchInst (BranchInst & BI)
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 @@ ISel::visitCallInst (CallInst & CI)
// 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 @@ ISel::visitCallInst (CallInst & CI)
}
// 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...