[llvm-commits] CVS: llvm/lib/Target/PowerPC/PPCMachineFunctionInfo.h PPCRegisterInfo.cpp PPCRegisterInfo.h
Jim Laskey
jlaskey at apple.com
Tue Feb 27 03:56:01 PST 2007
Changes in directory llvm/lib/Target/PowerPC:
PPCMachineFunctionInfo.h updated: 1.4 -> 1.5
PPCRegisterInfo.cpp updated: 1.113 -> 1.114
PPCRegisterInfo.h updated: 1.30 -> 1.31
---
Log message:
Duplicate use of LR, take 2.
---
Diffs of the changes: (+42 -26)
PPCMachineFunctionInfo.h | 7 +++++
PPCRegisterInfo.cpp | 60 ++++++++++++++++++++++++++---------------------
PPCRegisterInfo.h | 1
3 files changed, 42 insertions(+), 26 deletions(-)
Index: llvm/lib/Target/PowerPC/PPCMachineFunctionInfo.h
diff -u llvm/lib/Target/PowerPC/PPCMachineFunctionInfo.h:1.4 llvm/lib/Target/PowerPC/PPCMachineFunctionInfo.h:1.5
--- llvm/lib/Target/PowerPC/PPCMachineFunctionInfo.h:1.4 Mon Feb 26 20:55:29 2007
+++ llvm/lib/Target/PowerPC/PPCMachineFunctionInfo.h Tue Feb 27 05:55:44 2007
@@ -26,6 +26,10 @@
/// stored. Also used as an anchor for instructions that need to be altered
/// when using frame pointers (dyna_add, dyna_sub.)
int FramePointerSaveIndex;
+
+ /// UsesLR - Indicates whether LR is used in the current function.
+ ///
+ bool UsesLR;
public:
PPCFunctionInfo(MachineFunction& MF)
@@ -34,6 +38,9 @@
int getFramePointerSaveIndex() const { return FramePointerSaveIndex; }
void setFramePointerSaveIndex(int Idx) { FramePointerSaveIndex = Idx; }
+
+ void setUsesLR(bool U) { UsesLR = U; }
+ bool usesLR() { return UsesLR; }
};
Index: llvm/lib/Target/PowerPC/PPCRegisterInfo.cpp
diff -u llvm/lib/Target/PowerPC/PPCRegisterInfo.cpp:1.113 llvm/lib/Target/PowerPC/PPCRegisterInfo.cpp:1.114
--- llvm/lib/Target/PowerPC/PPCRegisterInfo.cpp:1.113 Mon Feb 26 20:55:29 2007
+++ llvm/lib/Target/PowerPC/PPCRegisterInfo.cpp Tue Feb 27 05:55:45 2007
@@ -538,8 +538,8 @@
/// usesLR - Returns if the link registers (LR) has been used in the function.
///
bool PPCRegisterInfo::usesLR(MachineFunction &MF) const {
- const bool *PhysRegsUsed = MF.getUsedPhysregs();
- return PhysRegsUsed[getRARegister()];
+ PPCFunctionInfo *FI = MF.getInfo<PPCFunctionInfo>();
+ return FI->usesLR();
}
void PPCRegisterInfo::
@@ -874,6 +874,15 @@
MFI->setStackSize(FrameSize);
}
+void PPCRegisterInfo::processFunctionBeforeCalleeSavedScan(MachineFunction &MF)
+ const {
+ // Save and clear the LR state.
+ PPCFunctionInfo *FI = MF.getInfo<PPCFunctionInfo>();
+ unsigned LR = getRARegister();
+ FI->setUsesLR(MF.isPhysRegUsed(LR));
+ MF.changePhyRegUsed(LR, false);
+}
+
void PPCRegisterInfo::emitPrologue(MachineFunction &MF) const {
MachineBasicBlock &MBB = MF.front(); // Prolog goes in entry BB
MachineBasicBlock::iterator MBBI = MBB.begin();
@@ -899,9 +908,6 @@
determineFrameLayout(MF);
unsigned FrameSize = MFI->getStackSize();
- // Skip if a leaf routine.
- if (!FrameSize) return;
-
int NegFrameSize = -FrameSize;
// Get processor type.
@@ -911,7 +917,7 @@
// Check if the link register (LR) has been used.
bool UsesLR = MFI->hasCalls() || usesLR(MF);
// Do we have a frame pointer for this function?
- bool HasFP = hasFP(MF);
+ bool HasFP = hasFP(MF) && FrameSize;
int LROffset = PPCFrameInfo::getReturnSaveOffset(IsPPC64, IsMachoABI);
int FPOffset = PPCFrameInfo::getFramePointerSaveOffset(IsPPC64, IsMachoABI);
@@ -940,6 +946,9 @@
.addReg(PPC::R0).addImm(LROffset).addReg(PPC::R1);
}
+ // Skip if a leaf routine.
+ if (!FrameSize) return;
+
// Get stack alignments.
unsigned TargetAlign = MF.getTarget().getFrameInfo()->getStackAlignment();
unsigned MaxAlign = MFI->getMaxAlignment();
@@ -1065,8 +1074,6 @@
// Get the number of bytes allocated from the FrameInfo.
unsigned FrameSize = MFI->getStackSize();
- if (!FrameSize) return;
-
// Get processor type.
bool IsPPC64 = Subtarget.isPPC64();
// Get operating system
@@ -1074,31 +1081,32 @@
// Check if the link register (LR) has been used.
bool UsesLR = MFI->hasCalls() || usesLR(MF);
// Do we have a frame pointer for this function?
- bool HasFP = hasFP(MF);
+ bool HasFP = hasFP(MF) && FrameSize;
int LROffset = PPCFrameInfo::getReturnSaveOffset(IsPPC64, IsMachoABI);
int FPOffset = PPCFrameInfo::getFramePointerSaveOffset(IsPPC64, IsMachoABI);
- // The loaded (or persistent) stack pointer value is offset by the 'stwu'
- // on entry to the function. Add this offset back now.
- if (!Subtarget.isPPC64()) {
- if (isInt16(FrameSize) && TargetAlign >= MaxAlign &&
- !MFI->hasVarSizedObjects()) {
- BuildMI(MBB, MBBI, TII.get(PPC::ADDI), PPC::R1)
- .addReg(PPC::R1).addImm(FrameSize);
- } else {
- BuildMI(MBB, MBBI, TII.get(PPC::LWZ),PPC::R1).addImm(0).addReg(PPC::R1);
- }
- } else {
- if (isInt16(FrameSize) && TargetAlign >= MaxAlign &&
- !MFI->hasVarSizedObjects()) {
- BuildMI(MBB, MBBI, TII.get(PPC::ADDI8), PPC::X1)
- .addReg(PPC::X1).addImm(FrameSize);
+ if (FrameSize) {
+ // The loaded (or persistent) stack pointer value is offset by the 'stwu'
+ // on entry to the function. Add this offset back now.
+ if (!Subtarget.isPPC64()) {
+ if (isInt16(FrameSize) && TargetAlign >= MaxAlign &&
+ !MFI->hasVarSizedObjects()) {
+ BuildMI(MBB, MBBI, TII.get(PPC::ADDI), PPC::R1)
+ .addReg(PPC::R1).addImm(FrameSize);
+ } else {
+ BuildMI(MBB, MBBI, TII.get(PPC::LWZ),PPC::R1).addImm(0).addReg(PPC::R1);
+ }
} else {
- BuildMI(MBB, MBBI, TII.get(PPC::LD), PPC::X1).addImm(0).addReg(PPC::X1);
+ if (isInt16(FrameSize) && TargetAlign >= MaxAlign &&
+ !MFI->hasVarSizedObjects()) {
+ BuildMI(MBB, MBBI, TII.get(PPC::ADDI8), PPC::X1)
+ .addReg(PPC::X1).addImm(FrameSize);
+ } else {
+ BuildMI(MBB, MBBI, TII.get(PPC::LD), PPC::X1).addImm(0).addReg(PPC::X1);
+ }
}
}
-
if (IsPPC64) {
if (UsesLR)
Index: llvm/lib/Target/PowerPC/PPCRegisterInfo.h
diff -u llvm/lib/Target/PowerPC/PPCRegisterInfo.h:1.30 llvm/lib/Target/PowerPC/PPCRegisterInfo.h:1.31
--- llvm/lib/Target/PowerPC/PPCRegisterInfo.h:1.30 Mon Feb 26 20:55:29 2007
+++ llvm/lib/Target/PowerPC/PPCRegisterInfo.h Tue Feb 27 05:55:45 2007
@@ -82,6 +82,7 @@
/// frame size.
void determineFrameLayout(MachineFunction &MF) const;
+ void processFunctionBeforeCalleeSavedScan(MachineFunction &MF) const;
void emitPrologue(MachineFunction &MF) const;
void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const;
More information about the llvm-commits
mailing list