[llvm-commits] CVS: llvm/lib/Target/X86/X86ISelPattern.cpp X86ISelSimple.cpp X86RegisterInfo.cpp
Chris Lattner
lattner at cs.uiuc.edu
Fri May 13 14:44:18 PDT 2005
Changes in directory llvm/lib/Target/X86:
X86ISelPattern.cpp updated: 1.127 -> 1.128
X86ISelSimple.cpp updated: 1.317 -> 1.318
X86RegisterInfo.cpp updated: 1.101 -> 1.102
---
Log message:
switch to having the callee pop stack operands for fastcc. This is currently buggy
do not use
---
Diffs of the changes: (+43 -16)
X86ISelPattern.cpp | 33 +++++++++++++++++++++++----------
X86ISelSimple.cpp | 2 +-
X86RegisterInfo.cpp | 24 +++++++++++++++++++-----
3 files changed, 43 insertions(+), 16 deletions(-)
Index: llvm/lib/Target/X86/X86ISelPattern.cpp
diff -u llvm/lib/Target/X86/X86ISelPattern.cpp:1.127 llvm/lib/Target/X86/X86ISelPattern.cpp:1.128
--- llvm/lib/Target/X86/X86ISelPattern.cpp:1.127 Fri May 13 15:29:13 2005
+++ llvm/lib/Target/X86/X86ISelPattern.cpp Fri May 13 16:44:04 2005
@@ -109,6 +109,11 @@
addLegalFPImmediate(-1.0); // FLD1/FCHS
}
+ // Return the number of bytes that a function should pop when it returns (in
+ // addition to the space used by the return address).
+ //
+ unsigned getBytesToPopOnReturn() const { return BytesToPopOnReturn; }
+
/// LowerArguments - This hook must be implemented to indicate how we should
/// lower the arguments for the specified function, into the specified DAG.
virtual std::vector<SDOperand>
@@ -228,7 +233,8 @@
// the start of the first vararg value... for expansion of llvm.va_start.
if (F.isVarArg())
VarArgsFrameIndex = MFI->CreateFixedObject(1, ArgOffset);
- ReturnAddrIndex = 0; // No return address slot generated yet.
+ ReturnAddrIndex = 0; // No return address slot generated yet.
+ BytesToPopOnReturn = 0; // Callee pops nothing.
// Finally, inform the code generator which regs we return values in.
switch (getValueType(F.getReturnType())) {
@@ -527,11 +533,9 @@
ArgOffset += ArgIncrement; // Move on to the next argument.
}
- // If the function takes variable number of arguments, make a frame index for
- // the start of the first vararg value... for expansion of llvm.va_start.
- if (F.isVarArg())
- VarArgsFrameIndex = MFI->CreateFixedObject(1, ArgOffset);
- ReturnAddrIndex = 0; // No return address slot generated yet.
+ VarArgsFrameIndex = 0xAAAAAAA; // fastcc functions can't have varargs.
+ ReturnAddrIndex = 0; // No return address slot generated yet.
+ BytesToPopOnReturn = ArgOffset; // Callee pops all stack arguments.
// Finally, inform the code generator which regs we return values in.
switch (getValueType(F.getReturnType())) {
@@ -3518,7 +3522,10 @@
Select(N.getOperand(0));
break;
}
- BuildMI(BB, X86::RET, 0); // Just emit a 'ret' instruction
+ if (X86Lowering.getBytesToPopOnReturn() == 0)
+ BuildMI(BB, X86::RET, 0); // Just emit a 'ret' instruction
+ else
+ BuildMI(BB, X86::RETI, 1).addImm(X86Lowering.getBytesToPopOnReturn());
return;
case ISD::BR: {
Select(N.getOperand(0));
@@ -3721,13 +3728,19 @@
return;
}
case ISD::CALLSEQ_START:
+ Select(N.getOperand(0));
+ // Stack amount
+ Tmp1 = cast<ConstantSDNode>(N.getOperand(1))->getValue();
+ BuildMI(BB, X86::ADJCALLSTACKDOWN, 1).addImm(Tmp1);
+ return;
case ISD::CALLSEQ_END:
Select(N.getOperand(0));
+ // Stack amount
Tmp1 = cast<ConstantSDNode>(N.getOperand(1))->getValue();
- Opc = N.getOpcode() == ISD::CALLSEQ_START ? X86::ADJCALLSTACKDOWN :
- X86::ADJCALLSTACKUP;
- BuildMI(BB, Opc, 1).addImm(Tmp1);
+ // Amount the callee added to the stack pointer.
+ Tmp2 = cast<ConstantSDNode>(N.getOperand(2))->getValue();
+ BuildMI(BB, X86::ADJCALLSTACKUP, 2).addImm(Tmp1).addImm(Tmp2);
return;
case ISD::MEMSET: {
Select(N.getOperand(0)); // Select the chain.
Index: llvm/lib/Target/X86/X86ISelSimple.cpp
diff -u llvm/lib/Target/X86/X86ISelSimple.cpp:1.317 llvm/lib/Target/X86/X86ISelSimple.cpp:1.318
--- llvm/lib/Target/X86/X86ISelSimple.cpp:1.317 Mon May 9 16:06:04 2005
+++ llvm/lib/Target/X86/X86ISelSimple.cpp Fri May 13 16:44:04 2005
@@ -1695,7 +1695,7 @@
BB->push_back(CallMI);
- BuildMI(BB, X86::ADJCALLSTACKUP, 1).addImm(NumBytes);
+ BuildMI(BB, X86::ADJCALLSTACKUP, 2).addImm(NumBytes).addImm(0);
// If there is a return value, scavenge the result from the location the call
// leaves it in...
Index: llvm/lib/Target/X86/X86RegisterInfo.cpp
diff -u llvm/lib/Target/X86/X86RegisterInfo.cpp:1.101 llvm/lib/Target/X86/X86RegisterInfo.cpp:1.102
--- llvm/lib/Target/X86/X86RegisterInfo.cpp:1.101 Fri May 13 15:46:35 2005
+++ llvm/lib/Target/X86/X86RegisterInfo.cpp Fri May 13 16:44:04 2005
@@ -375,17 +375,31 @@
unsigned Align = MF.getTarget().getFrameInfo()->getStackAlignment();
Amount = (Amount+Align-1)/Align*Align;
- MachineInstr *New;
+ MachineInstr *New = 0;
if (Old->getOpcode() == X86::ADJCALLSTACKDOWN) {
New=BuildMI(X86::SUB32ri, 1, X86::ESP, MachineOperand::UseAndDef)
.addZImm(Amount);
} else {
assert(Old->getOpcode() == X86::ADJCALLSTACKUP);
- New=BuildMI(X86::ADD32ri, 1, X86::ESP, MachineOperand::UseAndDef)
- .addZImm(Amount);
+ // factor out the amount the callee already popped.
+ unsigned CalleeAmt = Old->getOperand(1).getImmedValue();
+ Amount -= CalleeAmt;
+ if (Amount)
+ New = BuildMI(X86::ADD32ri, 1, X86::ESP,
+ MachineOperand::UseAndDef).addZImm(Amount);
}
// Replace the pseudo instruction with a new instruction...
+ if (New) MBB.insert(I, New);
+ }
+ } else if (I->getOpcode() == X86::ADJCALLSTACKUP) {
+ // If we are performing frame pointer elimination and if the callee pops
+ // something off the stack pointer, add it back. We do this until we have
+ // more advanced stack pointer tracking ability.
+ if (unsigned CalleeAmt = I->getOperand(1).getImmedValue()) {
+ MachineInstr *New =
+ BuildMI(X86::SUB32ri, 1, X86::ESP,
+ MachineOperand::UseAndDef).addZImm(CalleeAmt);
MBB.insert(I, New);
}
}
@@ -513,8 +527,8 @@
unsigned NumBytes = MFI->getStackSize();
if (NumBytes) { // adjust stack pointer back: ESP += numbytes
- MI =BuildMI(X86::ADD32ri, 1, X86::ESP, MachineOperand::UseAndDef)
- .addZImm(NumBytes);
+ MI = BuildMI(X86::ADD32ri, 1, X86::ESP, MachineOperand::UseAndDef)
+ .addZImm(NumBytes);
MBB.insert(MBBI, MI);
}
}
More information about the llvm-commits
mailing list