mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-15 20:29:48 +00:00
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
This commit is contained in:
parent
a17a2ac727
commit
0d2cf3a533
@ -393,6 +393,9 @@ ISel::visitBranchInst (BranchInst & BI)
|
|||||||
void
|
void
|
||||||
ISel::visitCallInst (CallInst & CI)
|
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
|
// Push the arguments on the stack in reverse order, as specified by
|
||||||
// the ABI.
|
// the ABI.
|
||||||
for (unsigned i = CI.getNumOperands()-1; i >= 1; --i)
|
for (unsigned i = CI.getNumOperands()-1; i >= 1; --i)
|
||||||
@ -406,11 +409,13 @@ ISel::visitCallInst (CallInst & CI)
|
|||||||
// then push EAX.
|
// then push EAX.
|
||||||
promote32 (X86::EAX, v);
|
promote32 (X86::EAX, v);
|
||||||
BuildMI (BB, X86::PUSHr32, 1).addReg (X86::EAX);
|
BuildMI (BB, X86::PUSHr32, 1).addReg (X86::EAX);
|
||||||
|
bytesPushed += 4;
|
||||||
break;
|
break;
|
||||||
case cInt:
|
case cInt:
|
||||||
case cFloat: {
|
case cFloat: {
|
||||||
unsigned Reg = getReg(v);
|
unsigned Reg = getReg(v);
|
||||||
BuildMI (BB, X86::PUSHr32, 1).addReg(Reg);
|
BuildMI (BB, X86::PUSHr32, 1).addReg(Reg);
|
||||||
|
bytesPushed += 4;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
@ -421,6 +426,10 @@ ISel::visitCallInst (CallInst & CI)
|
|||||||
}
|
}
|
||||||
// Emit a CALL instruction with PC-relative displacement.
|
// Emit a CALL instruction with PC-relative displacement.
|
||||||
BuildMI (BB, X86::CALLpcrel32, 1).addPCDisp (CI.getCalledValue ());
|
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...
|
/// visitSimpleBinary - Implement simple binary operators for integral types...
|
||||||
|
@ -393,6 +393,9 @@ ISel::visitBranchInst (BranchInst & BI)
|
|||||||
void
|
void
|
||||||
ISel::visitCallInst (CallInst & CI)
|
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
|
// Push the arguments on the stack in reverse order, as specified by
|
||||||
// the ABI.
|
// the ABI.
|
||||||
for (unsigned i = CI.getNumOperands()-1; i >= 1; --i)
|
for (unsigned i = CI.getNumOperands()-1; i >= 1; --i)
|
||||||
@ -406,11 +409,13 @@ ISel::visitCallInst (CallInst & CI)
|
|||||||
// then push EAX.
|
// then push EAX.
|
||||||
promote32 (X86::EAX, v);
|
promote32 (X86::EAX, v);
|
||||||
BuildMI (BB, X86::PUSHr32, 1).addReg (X86::EAX);
|
BuildMI (BB, X86::PUSHr32, 1).addReg (X86::EAX);
|
||||||
|
bytesPushed += 4;
|
||||||
break;
|
break;
|
||||||
case cInt:
|
case cInt:
|
||||||
case cFloat: {
|
case cFloat: {
|
||||||
unsigned Reg = getReg(v);
|
unsigned Reg = getReg(v);
|
||||||
BuildMI (BB, X86::PUSHr32, 1).addReg(Reg);
|
BuildMI (BB, X86::PUSHr32, 1).addReg(Reg);
|
||||||
|
bytesPushed += 4;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
@ -421,6 +426,10 @@ ISel::visitCallInst (CallInst & CI)
|
|||||||
}
|
}
|
||||||
// Emit a CALL instruction with PC-relative displacement.
|
// Emit a CALL instruction with PC-relative displacement.
|
||||||
BuildMI (BB, X86::CALLpcrel32, 1).addPCDisp (CI.getCalledValue ());
|
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...
|
/// visitSimpleBinary - Implement simple binary operators for integral types...
|
||||||
|
Loading…
Reference in New Issue
Block a user