Nate Begeman | 21e463b | 2005-10-16 05:39:50 +0000 | [diff] [blame] | 1 | //===- PPCRegisterInfo.cpp - PowerPC Register Information -------*- C++ -*-===// |
Misha Brukman | b5f662f | 2005-04-21 23:30:14 +0000 | [diff] [blame] | 2 | // |
Misha Brukman | f2ccb77 | 2004-08-17 04:55:41 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file was developed by the LLVM research group and is distributed under |
| 6 | // the University of Illinois Open Source License. See LICENSE.TXT for details. |
Misha Brukman | b5f662f | 2005-04-21 23:30:14 +0000 | [diff] [blame] | 7 | // |
Misha Brukman | f2ccb77 | 2004-08-17 04:55:41 +0000 | [diff] [blame] | 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
Nate Begeman | 21e463b | 2005-10-16 05:39:50 +0000 | [diff] [blame] | 10 | // This file contains the PowerPC implementation of the MRegisterInfo class. |
Misha Brukman | f2ccb77 | 2004-08-17 04:55:41 +0000 | [diff] [blame] | 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #define DEBUG_TYPE "reginfo" |
Chris Lattner | 2668959 | 2005-10-14 23:51:18 +0000 | [diff] [blame] | 15 | #include "PPC.h" |
Chris Lattner | 26bd0d4 | 2005-10-14 23:45:43 +0000 | [diff] [blame] | 16 | #include "PPCInstrBuilder.h" |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 17 | #include "PPCMachineFunctionInfo.h" |
Chris Lattner | 16e71f2 | 2005-10-14 23:59:06 +0000 | [diff] [blame] | 18 | #include "PPCRegisterInfo.h" |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 19 | #include "PPCFrameInfo.h" |
Chris Lattner | 804e067 | 2006-07-11 00:48:23 +0000 | [diff] [blame] | 20 | #include "PPCSubtarget.h" |
Misha Brukman | f2ccb77 | 2004-08-17 04:55:41 +0000 | [diff] [blame] | 21 | #include "llvm/Constants.h" |
| 22 | #include "llvm/Type.h" |
| 23 | #include "llvm/CodeGen/ValueTypes.h" |
| 24 | #include "llvm/CodeGen/MachineInstrBuilder.h" |
Jim Laskey | 4188699 | 2006-04-07 16:34:46 +0000 | [diff] [blame] | 25 | #include "llvm/CodeGen/MachineDebugInfo.h" |
Misha Brukman | f2ccb77 | 2004-08-17 04:55:41 +0000 | [diff] [blame] | 26 | #include "llvm/CodeGen/MachineFunction.h" |
| 27 | #include "llvm/CodeGen/MachineFrameInfo.h" |
Jim Laskey | f1d78e8 | 2006-03-23 18:12:57 +0000 | [diff] [blame] | 28 | #include "llvm/CodeGen/MachineLocation.h" |
Jim Laskey | 4188699 | 2006-04-07 16:34:46 +0000 | [diff] [blame] | 29 | #include "llvm/CodeGen/SelectionDAGNodes.h" |
Misha Brukman | f2ccb77 | 2004-08-17 04:55:41 +0000 | [diff] [blame] | 30 | #include "llvm/Target/TargetFrameInfo.h" |
Chris Lattner | f9568d8 | 2006-04-17 21:48:13 +0000 | [diff] [blame] | 31 | #include "llvm/Target/TargetInstrInfo.h" |
Misha Brukman | f2ccb77 | 2004-08-17 04:55:41 +0000 | [diff] [blame] | 32 | #include "llvm/Target/TargetMachine.h" |
| 33 | #include "llvm/Target/TargetOptions.h" |
Reid Spencer | 551ccae | 2004-09-01 22:55:40 +0000 | [diff] [blame] | 34 | #include "llvm/Support/CommandLine.h" |
| 35 | #include "llvm/Support/Debug.h" |
Nate Begeman | ae232e7 | 2005-11-06 09:00:38 +0000 | [diff] [blame] | 36 | #include "llvm/Support/MathExtras.h" |
Reid Spencer | 551ccae | 2004-09-01 22:55:40 +0000 | [diff] [blame] | 37 | #include "llvm/ADT/STLExtras.h" |
Misha Brukman | f2ccb77 | 2004-08-17 04:55:41 +0000 | [diff] [blame] | 38 | #include <cstdlib> |
Misha Brukman | f2ccb77 | 2004-08-17 04:55:41 +0000 | [diff] [blame] | 39 | using namespace llvm; |
| 40 | |
Chris Lattner | 369503f | 2006-04-17 21:07:20 +0000 | [diff] [blame] | 41 | /// getRegisterNumbering - Given the enum value for some register, e.g. |
| 42 | /// PPC::F14, return the number that it corresponds to (e.g. 14). |
| 43 | unsigned PPCRegisterInfo::getRegisterNumbering(unsigned RegEnum) { |
Chris Lattner | be6a039 | 2006-07-11 20:53:55 +0000 | [diff] [blame] | 44 | using namespace PPC; |
Chris Lattner | 369503f | 2006-04-17 21:07:20 +0000 | [diff] [blame] | 45 | switch (RegEnum) { |
Chris Lattner | be6a039 | 2006-07-11 20:53:55 +0000 | [diff] [blame] | 46 | case R0 : case X0 : case F0 : case V0 : case CR0: return 0; |
| 47 | case R1 : case X1 : case F1 : case V1 : case CR1: return 1; |
| 48 | case R2 : case X2 : case F2 : case V2 : case CR2: return 2; |
| 49 | case R3 : case X3 : case F3 : case V3 : case CR3: return 3; |
| 50 | case R4 : case X4 : case F4 : case V4 : case CR4: return 4; |
| 51 | case R5 : case X5 : case F5 : case V5 : case CR5: return 5; |
| 52 | case R6 : case X6 : case F6 : case V6 : case CR6: return 6; |
| 53 | case R7 : case X7 : case F7 : case V7 : case CR7: return 7; |
| 54 | case R8 : case X8 : case F8 : case V8 : return 8; |
| 55 | case R9 : case X9 : case F9 : case V9 : return 9; |
| 56 | case R10: case X10: case F10: case V10: return 10; |
| 57 | case R11: case X11: case F11: case V11: return 11; |
| 58 | case R12: case X12: case F12: case V12: return 12; |
| 59 | case R13: case X13: case F13: case V13: return 13; |
| 60 | case R14: case X14: case F14: case V14: return 14; |
| 61 | case R15: case X15: case F15: case V15: return 15; |
| 62 | case R16: case X16: case F16: case V16: return 16; |
| 63 | case R17: case X17: case F17: case V17: return 17; |
| 64 | case R18: case X18: case F18: case V18: return 18; |
| 65 | case R19: case X19: case F19: case V19: return 19; |
| 66 | case R20: case X20: case F20: case V20: return 20; |
| 67 | case R21: case X21: case F21: case V21: return 21; |
| 68 | case R22: case X22: case F22: case V22: return 22; |
| 69 | case R23: case X23: case F23: case V23: return 23; |
| 70 | case R24: case X24: case F24: case V24: return 24; |
| 71 | case R25: case X25: case F25: case V25: return 25; |
| 72 | case R26: case X26: case F26: case V26: return 26; |
| 73 | case R27: case X27: case F27: case V27: return 27; |
| 74 | case R28: case X28: case F28: case V28: return 28; |
| 75 | case R29: case X29: case F29: case V29: return 29; |
| 76 | case R30: case X30: case F30: case V30: return 30; |
| 77 | case R31: case X31: case F31: case V31: return 31; |
| 78 | default: |
Bill Wendling | f5da133 | 2006-12-07 22:21:48 +0000 | [diff] [blame] | 79 | cerr << "Unhandled reg in PPCRegisterInfo::getRegisterNumbering!\n"; |
Chris Lattner | be6a039 | 2006-07-11 20:53:55 +0000 | [diff] [blame] | 80 | abort(); |
Chris Lattner | 369503f | 2006-04-17 21:07:20 +0000 | [diff] [blame] | 81 | } |
| 82 | } |
| 83 | |
Evan Cheng | 7ce4578 | 2006-11-13 23:36:35 +0000 | [diff] [blame] | 84 | PPCRegisterInfo::PPCRegisterInfo(const PPCSubtarget &ST, |
| 85 | const TargetInstrInfo &tii) |
Chris Lattner | 804e067 | 2006-07-11 00:48:23 +0000 | [diff] [blame] | 86 | : PPCGenRegisterInfo(PPC::ADJCALLSTACKDOWN, PPC::ADJCALLSTACKUP), |
Evan Cheng | 7ce4578 | 2006-11-13 23:36:35 +0000 | [diff] [blame] | 87 | Subtarget(ST), TII(tii) { |
Misha Brukman | b5f662f | 2005-04-21 23:30:14 +0000 | [diff] [blame] | 88 | ImmToIdxMap[PPC::LD] = PPC::LDX; ImmToIdxMap[PPC::STD] = PPC::STDX; |
Misha Brukman | f2ccb77 | 2004-08-17 04:55:41 +0000 | [diff] [blame] | 89 | ImmToIdxMap[PPC::LBZ] = PPC::LBZX; ImmToIdxMap[PPC::STB] = PPC::STBX; |
| 90 | ImmToIdxMap[PPC::LHZ] = PPC::LHZX; ImmToIdxMap[PPC::LHA] = PPC::LHAX; |
| 91 | ImmToIdxMap[PPC::LWZ] = PPC::LWZX; ImmToIdxMap[PPC::LWA] = PPC::LWAX; |
| 92 | ImmToIdxMap[PPC::LFS] = PPC::LFSX; ImmToIdxMap[PPC::LFD] = PPC::LFDX; |
| 93 | ImmToIdxMap[PPC::STH] = PPC::STHX; ImmToIdxMap[PPC::STW] = PPC::STWX; |
| 94 | ImmToIdxMap[PPC::STFS] = PPC::STFSX; ImmToIdxMap[PPC::STFD] = PPC::STFDX; |
Nate Begeman | 1d9d742 | 2005-10-18 00:28:58 +0000 | [diff] [blame] | 95 | ImmToIdxMap[PPC::ADDI] = PPC::ADD4; |
Chris Lattner | c88fa74 | 2006-12-07 22:15:58 +0000 | [diff] [blame] | 96 | ImmToIdxMap[PPC::ADDI8] = PPC::ADD8; |
Misha Brukman | f2ccb77 | 2004-08-17 04:55:41 +0000 | [diff] [blame] | 97 | } |
| 98 | |
Misha Brukman | b5f662f | 2005-04-21 23:30:14 +0000 | [diff] [blame] | 99 | void |
Nate Begeman | 21e463b | 2005-10-16 05:39:50 +0000 | [diff] [blame] | 100 | PPCRegisterInfo::storeRegToStackSlot(MachineBasicBlock &MBB, |
| 101 | MachineBasicBlock::iterator MI, |
| 102 | unsigned SrcReg, int FrameIdx, |
| 103 | const TargetRegisterClass *RC) const { |
Chris Lattner | 6a5339b | 2006-11-14 18:44:47 +0000 | [diff] [blame] | 104 | if (RC == PPC::GPRCRegisterClass) { |
| 105 | if (SrcReg != PPC::LR) { |
Evan Cheng | c0f64ff | 2006-11-27 23:37:22 +0000 | [diff] [blame] | 106 | addFrameReference(BuildMI(MBB, MI, TII.get(PPC::STW)).addReg(SrcReg), |
| 107 | FrameIdx); |
Chris Lattner | 6a5339b | 2006-11-14 18:44:47 +0000 | [diff] [blame] | 108 | } else { |
| 109 | // FIXME: this spills LR immediately to memory in one step. To do this, |
| 110 | // we use R11, which we know cannot be used in the prolog/epilog. This is |
| 111 | // a hack. |
Evan Cheng | c0f64ff | 2006-11-27 23:37:22 +0000 | [diff] [blame] | 112 | BuildMI(MBB, MI, TII.get(PPC::MFLR), PPC::R11); |
| 113 | addFrameReference(BuildMI(MBB, MI, TII.get(PPC::STW)).addReg(PPC::R11), |
Chris Lattner | 6a5339b | 2006-11-14 18:44:47 +0000 | [diff] [blame] | 114 | FrameIdx); |
| 115 | } |
| 116 | } else if (RC == PPC::G8RCRegisterClass) { |
| 117 | if (SrcReg != PPC::LR8) { |
Evan Cheng | c0f64ff | 2006-11-27 23:37:22 +0000 | [diff] [blame] | 118 | addFrameReference(BuildMI(MBB, MI, TII.get(PPC::STD)).addReg(SrcReg), |
| 119 | FrameIdx); |
Chris Lattner | 6a5339b | 2006-11-14 18:44:47 +0000 | [diff] [blame] | 120 | } else { |
| 121 | // FIXME: this spills LR immediately to memory in one step. To do this, |
| 122 | // we use R11, which we know cannot be used in the prolog/epilog. This is |
| 123 | // a hack. |
Evan Cheng | c0f64ff | 2006-11-27 23:37:22 +0000 | [diff] [blame] | 124 | BuildMI(MBB, MI, TII.get(PPC::MFLR8), PPC::X11); |
| 125 | addFrameReference(BuildMI(MBB, MI, TII.get(PPC::STD)).addReg(PPC::X11), |
Chris Lattner | 6a5339b | 2006-11-14 18:44:47 +0000 | [diff] [blame] | 126 | FrameIdx); |
| 127 | } |
| 128 | } else if (RC == PPC::F8RCRegisterClass) { |
Evan Cheng | c0f64ff | 2006-11-27 23:37:22 +0000 | [diff] [blame] | 129 | addFrameReference(BuildMI(MBB, MI, TII.get(PPC::STFD)).addReg(SrcReg), |
| 130 | FrameIdx); |
Chris Lattner | 6a5339b | 2006-11-14 18:44:47 +0000 | [diff] [blame] | 131 | } else if (RC == PPC::F4RCRegisterClass) { |
Evan Cheng | c0f64ff | 2006-11-27 23:37:22 +0000 | [diff] [blame] | 132 | addFrameReference(BuildMI(MBB, MI, TII.get(PPC::STFS)).addReg(SrcReg), |
| 133 | FrameIdx); |
Nate Begeman | 1d9d742 | 2005-10-18 00:28:58 +0000 | [diff] [blame] | 134 | } else if (RC == PPC::CRRCRegisterClass) { |
Chris Lattner | e67304f | 2006-06-12 23:59:16 +0000 | [diff] [blame] | 135 | // FIXME: We use R0 here, because it isn't available for RA. |
Chris Lattner | b47e089 | 2006-06-12 21:50:57 +0000 | [diff] [blame] | 136 | // We need to store the CR in the low 4-bits of the saved value. First, |
| 137 | // issue a MFCR to save all of the CRBits. |
Evan Cheng | c0f64ff | 2006-11-27 23:37:22 +0000 | [diff] [blame] | 138 | BuildMI(MBB, MI, TII.get(PPC::MFCR), PPC::R0); |
Chris Lattner | b47e089 | 2006-06-12 21:50:57 +0000 | [diff] [blame] | 139 | |
| 140 | // If the saved register wasn't CR0, shift the bits left so that they are in |
| 141 | // CR0's slot. |
| 142 | if (SrcReg != PPC::CR0) { |
| 143 | unsigned ShiftBits = PPCRegisterInfo::getRegisterNumbering(SrcReg)*4; |
Chris Lattner | e67304f | 2006-06-12 23:59:16 +0000 | [diff] [blame] | 144 | // rlwinm r0, r0, ShiftBits, 0, 31. |
Evan Cheng | c0f64ff | 2006-11-27 23:37:22 +0000 | [diff] [blame] | 145 | BuildMI(MBB, MI, TII.get(PPC::RLWINM), PPC::R0) |
Chris Lattner | e67304f | 2006-06-12 23:59:16 +0000 | [diff] [blame] | 146 | .addReg(PPC::R0).addImm(ShiftBits).addImm(0).addImm(31); |
Chris Lattner | b47e089 | 2006-06-12 21:50:57 +0000 | [diff] [blame] | 147 | } |
| 148 | |
Evan Cheng | c0f64ff | 2006-11-27 23:37:22 +0000 | [diff] [blame] | 149 | addFrameReference(BuildMI(MBB, MI, TII.get(PPC::STW)).addReg(PPC::R0), |
| 150 | FrameIdx); |
Chris Lattner | 9c09c9e | 2006-03-16 22:24:02 +0000 | [diff] [blame] | 151 | } else if (RC == PPC::VRRCRegisterClass) { |
| 152 | // We don't have indexed addressing for vector loads. Emit: |
| 153 | // R11 = ADDI FI# |
| 154 | // Dest = LVX R0, R11 |
| 155 | // |
| 156 | // FIXME: We use R0 here, because it isn't available for RA. |
Evan Cheng | c0f64ff | 2006-11-27 23:37:22 +0000 | [diff] [blame] | 157 | addFrameReference(BuildMI(MBB, MI, TII.get(PPC::ADDI), PPC::R0), |
| 158 | FrameIdx, 0, 0); |
| 159 | BuildMI(MBB, MI, TII.get(PPC::STVX)) |
Chris Lattner | 9c09c9e | 2006-03-16 22:24:02 +0000 | [diff] [blame] | 160 | .addReg(SrcReg).addReg(PPC::R0).addReg(PPC::R0); |
Misha Brukman | f2ccb77 | 2004-08-17 04:55:41 +0000 | [diff] [blame] | 161 | } else { |
Chris Lattner | 919c032 | 2005-10-01 01:35:02 +0000 | [diff] [blame] | 162 | assert(0 && "Unknown regclass!"); |
| 163 | abort(); |
Misha Brukman | f2ccb77 | 2004-08-17 04:55:41 +0000 | [diff] [blame] | 164 | } |
| 165 | } |
| 166 | |
| 167 | void |
Nate Begeman | 21e463b | 2005-10-16 05:39:50 +0000 | [diff] [blame] | 168 | PPCRegisterInfo::loadRegFromStackSlot(MachineBasicBlock &MBB, |
Chris Lattner | 6a5339b | 2006-11-14 18:44:47 +0000 | [diff] [blame] | 169 | MachineBasicBlock::iterator MI, |
| 170 | unsigned DestReg, int FrameIdx, |
| 171 | const TargetRegisterClass *RC) const { |
| 172 | if (RC == PPC::GPRCRegisterClass) { |
| 173 | if (DestReg != PPC::LR) { |
Evan Cheng | c0f64ff | 2006-11-27 23:37:22 +0000 | [diff] [blame] | 174 | addFrameReference(BuildMI(MBB, MI, TII.get(PPC::LWZ), DestReg), FrameIdx); |
Chris Lattner | 6a5339b | 2006-11-14 18:44:47 +0000 | [diff] [blame] | 175 | } else { |
Evan Cheng | c0f64ff | 2006-11-27 23:37:22 +0000 | [diff] [blame] | 176 | addFrameReference(BuildMI(MBB, MI, TII.get(PPC::LWZ), PPC::R11),FrameIdx); |
| 177 | BuildMI(MBB, MI, TII.get(PPC::MTLR)).addReg(PPC::R11); |
Chris Lattner | 6a5339b | 2006-11-14 18:44:47 +0000 | [diff] [blame] | 178 | } |
| 179 | } else if (RC == PPC::G8RCRegisterClass) { |
| 180 | if (DestReg != PPC::LR8) { |
Evan Cheng | c0f64ff | 2006-11-27 23:37:22 +0000 | [diff] [blame] | 181 | addFrameReference(BuildMI(MBB, MI, TII.get(PPC::LD), DestReg), FrameIdx); |
Chris Lattner | 6a5339b | 2006-11-14 18:44:47 +0000 | [diff] [blame] | 182 | } else { |
Evan Cheng | c0f64ff | 2006-11-27 23:37:22 +0000 | [diff] [blame] | 183 | addFrameReference(BuildMI(MBB, MI, TII.get(PPC::LD), PPC::R11), FrameIdx); |
| 184 | BuildMI(MBB, MI, TII.get(PPC::MTLR8)).addReg(PPC::R11); |
Chris Lattner | 6a5339b | 2006-11-14 18:44:47 +0000 | [diff] [blame] | 185 | } |
| 186 | } else if (RC == PPC::F8RCRegisterClass) { |
Evan Cheng | c0f64ff | 2006-11-27 23:37:22 +0000 | [diff] [blame] | 187 | addFrameReference(BuildMI(MBB, MI, TII.get(PPC::LFD), DestReg), FrameIdx); |
Chris Lattner | 6a5339b | 2006-11-14 18:44:47 +0000 | [diff] [blame] | 188 | } else if (RC == PPC::F4RCRegisterClass) { |
Evan Cheng | c0f64ff | 2006-11-27 23:37:22 +0000 | [diff] [blame] | 189 | addFrameReference(BuildMI(MBB, MI, TII.get(PPC::LFS), DestReg), FrameIdx); |
Nate Begeman | 1d9d742 | 2005-10-18 00:28:58 +0000 | [diff] [blame] | 190 | } else if (RC == PPC::CRRCRegisterClass) { |
Chris Lattner | e67304f | 2006-06-12 23:59:16 +0000 | [diff] [blame] | 191 | // FIXME: We use R0 here, because it isn't available for RA. |
Evan Cheng | c0f64ff | 2006-11-27 23:37:22 +0000 | [diff] [blame] | 192 | addFrameReference(BuildMI(MBB, MI, TII.get(PPC::LWZ), PPC::R0), FrameIdx); |
Chris Lattner | b47e089 | 2006-06-12 21:50:57 +0000 | [diff] [blame] | 193 | |
| 194 | // If the reloaded register isn't CR0, shift the bits right so that they are |
| 195 | // in the right CR's slot. |
| 196 | if (DestReg != PPC::CR0) { |
| 197 | unsigned ShiftBits = PPCRegisterInfo::getRegisterNumbering(DestReg)*4; |
| 198 | // rlwinm r11, r11, 32-ShiftBits, 0, 31. |
Evan Cheng | c0f64ff | 2006-11-27 23:37:22 +0000 | [diff] [blame] | 199 | BuildMI(MBB, MI, TII.get(PPC::RLWINM), PPC::R0) |
Chris Lattner | e67304f | 2006-06-12 23:59:16 +0000 | [diff] [blame] | 200 | .addReg(PPC::R0).addImm(32-ShiftBits).addImm(0).addImm(31); |
Chris Lattner | b47e089 | 2006-06-12 21:50:57 +0000 | [diff] [blame] | 201 | } |
| 202 | |
Evan Cheng | c0f64ff | 2006-11-27 23:37:22 +0000 | [diff] [blame] | 203 | BuildMI(MBB, MI, TII.get(PPC::MTCRF), DestReg).addReg(PPC::R0); |
Chris Lattner | 9c09c9e | 2006-03-16 22:24:02 +0000 | [diff] [blame] | 204 | } else if (RC == PPC::VRRCRegisterClass) { |
| 205 | // We don't have indexed addressing for vector loads. Emit: |
| 206 | // R11 = ADDI FI# |
| 207 | // Dest = LVX R0, R11 |
| 208 | // |
| 209 | // FIXME: We use R0 here, because it isn't available for RA. |
Evan Cheng | c0f64ff | 2006-11-27 23:37:22 +0000 | [diff] [blame] | 210 | addFrameReference(BuildMI(MBB, MI, TII.get(PPC::ADDI), PPC::R0), |
| 211 | FrameIdx, 0, 0); |
| 212 | BuildMI(MBB, MI, TII.get(PPC::LVX),DestReg).addReg(PPC::R0).addReg(PPC::R0); |
Misha Brukman | f2ccb77 | 2004-08-17 04:55:41 +0000 | [diff] [blame] | 213 | } else { |
Chris Lattner | 919c032 | 2005-10-01 01:35:02 +0000 | [diff] [blame] | 214 | assert(0 && "Unknown regclass!"); |
| 215 | abort(); |
Misha Brukman | f2ccb77 | 2004-08-17 04:55:41 +0000 | [diff] [blame] | 216 | } |
| 217 | } |
| 218 | |
Nate Begeman | 21e463b | 2005-10-16 05:39:50 +0000 | [diff] [blame] | 219 | void PPCRegisterInfo::copyRegToReg(MachineBasicBlock &MBB, |
| 220 | MachineBasicBlock::iterator MI, |
| 221 | unsigned DestReg, unsigned SrcReg, |
| 222 | const TargetRegisterClass *RC) const { |
Nate Begeman | 1d9d742 | 2005-10-18 00:28:58 +0000 | [diff] [blame] | 223 | if (RC == PPC::GPRCRegisterClass) { |
Evan Cheng | c0f64ff | 2006-11-27 23:37:22 +0000 | [diff] [blame] | 224 | BuildMI(MBB, MI, TII.get(PPC::OR), DestReg).addReg(SrcReg).addReg(SrcReg); |
Nate Begeman | 1d9d742 | 2005-10-18 00:28:58 +0000 | [diff] [blame] | 225 | } else if (RC == PPC::G8RCRegisterClass) { |
Evan Cheng | c0f64ff | 2006-11-27 23:37:22 +0000 | [diff] [blame] | 226 | BuildMI(MBB, MI, TII.get(PPC::OR8), DestReg).addReg(SrcReg).addReg(SrcReg); |
Nate Begeman | 1d9d742 | 2005-10-18 00:28:58 +0000 | [diff] [blame] | 227 | } else if (RC == PPC::F4RCRegisterClass) { |
Evan Cheng | c0f64ff | 2006-11-27 23:37:22 +0000 | [diff] [blame] | 228 | BuildMI(MBB, MI, TII.get(PPC::FMRS), DestReg).addReg(SrcReg); |
Nate Begeman | 1d9d742 | 2005-10-18 00:28:58 +0000 | [diff] [blame] | 229 | } else if (RC == PPC::F8RCRegisterClass) { |
Evan Cheng | c0f64ff | 2006-11-27 23:37:22 +0000 | [diff] [blame] | 230 | BuildMI(MBB, MI, TII.get(PPC::FMRD), DestReg).addReg(SrcReg); |
Nate Begeman | 1d9d742 | 2005-10-18 00:28:58 +0000 | [diff] [blame] | 231 | } else if (RC == PPC::CRRCRegisterClass) { |
Evan Cheng | c0f64ff | 2006-11-27 23:37:22 +0000 | [diff] [blame] | 232 | BuildMI(MBB, MI, TII.get(PPC::MCRF), DestReg).addReg(SrcReg); |
Chris Lattner | 335fd3c | 2006-03-16 20:03:58 +0000 | [diff] [blame] | 233 | } else if (RC == PPC::VRRCRegisterClass) { |
Evan Cheng | c0f64ff | 2006-11-27 23:37:22 +0000 | [diff] [blame] | 234 | BuildMI(MBB, MI, TII.get(PPC::VOR), DestReg).addReg(SrcReg).addReg(SrcReg); |
Nate Begeman | 7af0248 | 2005-04-12 07:04:16 +0000 | [diff] [blame] | 235 | } else { |
Bill Wendling | f5da133 | 2006-12-07 22:21:48 +0000 | [diff] [blame] | 236 | cerr << "Attempt to copy register that is not GPR or FPR"; |
Misha Brukman | f2ccb77 | 2004-08-17 04:55:41 +0000 | [diff] [blame] | 237 | abort(); |
| 238 | } |
| 239 | } |
| 240 | |
Evan Cheng | c2b861d | 2007-01-02 21:33:40 +0000 | [diff] [blame^] | 241 | const unsigned* PPCRegisterInfo::getCalleeSavedRegs() const { |
Chris Lattner | 804e067 | 2006-07-11 00:48:23 +0000 | [diff] [blame] | 242 | // 32-bit Darwin calling convention. |
Evan Cheng | c2b861d | 2007-01-02 21:33:40 +0000 | [diff] [blame^] | 243 | static const unsigned Darwin32_CalleeSavedRegs[] = { |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 244 | PPC::R13, PPC::R14, PPC::R15, |
Chris Lattner | 804e067 | 2006-07-11 00:48:23 +0000 | [diff] [blame] | 245 | PPC::R16, PPC::R17, PPC::R18, PPC::R19, |
| 246 | PPC::R20, PPC::R21, PPC::R22, PPC::R23, |
| 247 | PPC::R24, PPC::R25, PPC::R26, PPC::R27, |
| 248 | PPC::R28, PPC::R29, PPC::R30, PPC::R31, |
| 249 | |
| 250 | PPC::F14, PPC::F15, PPC::F16, PPC::F17, |
| 251 | PPC::F18, PPC::F19, PPC::F20, PPC::F21, |
| 252 | PPC::F22, PPC::F23, PPC::F24, PPC::F25, |
| 253 | PPC::F26, PPC::F27, PPC::F28, PPC::F29, |
Evan Cheng | 0f3ac8d | 2006-05-18 00:12:58 +0000 | [diff] [blame] | 254 | PPC::F30, PPC::F31, |
Chris Lattner | 804e067 | 2006-07-11 00:48:23 +0000 | [diff] [blame] | 255 | |
| 256 | PPC::CR2, PPC::CR3, PPC::CR4, |
| 257 | PPC::V20, PPC::V21, PPC::V22, PPC::V23, |
| 258 | PPC::V24, PPC::V25, PPC::V26, PPC::V27, |
| 259 | PPC::V28, PPC::V29, PPC::V30, PPC::V31, |
| 260 | |
| 261 | PPC::LR, 0 |
Evan Cheng | 0f3ac8d | 2006-05-18 00:12:58 +0000 | [diff] [blame] | 262 | }; |
Chris Lattner | 804e067 | 2006-07-11 00:48:23 +0000 | [diff] [blame] | 263 | // 64-bit Darwin calling convention. |
Evan Cheng | c2b861d | 2007-01-02 21:33:40 +0000 | [diff] [blame^] | 264 | static const unsigned Darwin64_CalleeSavedRegs[] = { |
Chris Lattner | bdc571b | 2006-11-20 19:33:51 +0000 | [diff] [blame] | 265 | PPC::X14, PPC::X15, |
Chris Lattner | 804e067 | 2006-07-11 00:48:23 +0000 | [diff] [blame] | 266 | PPC::X16, PPC::X17, PPC::X18, PPC::X19, |
| 267 | PPC::X20, PPC::X21, PPC::X22, PPC::X23, |
| 268 | PPC::X24, PPC::X25, PPC::X26, PPC::X27, |
| 269 | PPC::X28, PPC::X29, PPC::X30, PPC::X31, |
| 270 | |
| 271 | PPC::F14, PPC::F15, PPC::F16, PPC::F17, |
| 272 | PPC::F18, PPC::F19, PPC::F20, PPC::F21, |
| 273 | PPC::F22, PPC::F23, PPC::F24, PPC::F25, |
| 274 | PPC::F26, PPC::F27, PPC::F28, PPC::F29, |
| 275 | PPC::F30, PPC::F31, |
| 276 | |
| 277 | PPC::CR2, PPC::CR3, PPC::CR4, |
| 278 | PPC::V20, PPC::V21, PPC::V22, PPC::V23, |
| 279 | PPC::V24, PPC::V25, PPC::V26, PPC::V27, |
| 280 | PPC::V28, PPC::V29, PPC::V30, PPC::V31, |
| 281 | |
Chris Lattner | 6a5339b | 2006-11-14 18:44:47 +0000 | [diff] [blame] | 282 | PPC::LR8, 0 |
Chris Lattner | 804e067 | 2006-07-11 00:48:23 +0000 | [diff] [blame] | 283 | }; |
| 284 | |
Evan Cheng | c2b861d | 2007-01-02 21:33:40 +0000 | [diff] [blame^] | 285 | return Subtarget.isPPC64() ? Darwin64_CalleeSavedRegs : |
| 286 | Darwin32_CalleeSavedRegs; |
Evan Cheng | 0f3ac8d | 2006-05-18 00:12:58 +0000 | [diff] [blame] | 287 | } |
| 288 | |
| 289 | const TargetRegisterClass* const* |
Evan Cheng | c2b861d | 2007-01-02 21:33:40 +0000 | [diff] [blame^] | 290 | PPCRegisterInfo::getCalleeSavedRegClasses() const { |
Chris Lattner | 804e067 | 2006-07-11 00:48:23 +0000 | [diff] [blame] | 291 | // 32-bit Darwin calling convention. |
Evan Cheng | c2b861d | 2007-01-02 21:33:40 +0000 | [diff] [blame^] | 292 | static const TargetRegisterClass * const Darwin32_CalleeSavedRegClasses[] = { |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 293 | &PPC::GPRCRegClass,&PPC::GPRCRegClass,&PPC::GPRCRegClass, |
Chris Lattner | 804e067 | 2006-07-11 00:48:23 +0000 | [diff] [blame] | 294 | &PPC::GPRCRegClass,&PPC::GPRCRegClass,&PPC::GPRCRegClass,&PPC::GPRCRegClass, |
| 295 | &PPC::GPRCRegClass,&PPC::GPRCRegClass,&PPC::GPRCRegClass,&PPC::GPRCRegClass, |
| 296 | &PPC::GPRCRegClass,&PPC::GPRCRegClass,&PPC::GPRCRegClass,&PPC::GPRCRegClass, |
| 297 | &PPC::GPRCRegClass,&PPC::GPRCRegClass,&PPC::GPRCRegClass,&PPC::GPRCRegClass, |
| 298 | |
| 299 | &PPC::F8RCRegClass,&PPC::F8RCRegClass,&PPC::F8RCRegClass,&PPC::F8RCRegClass, |
| 300 | &PPC::F8RCRegClass,&PPC::F8RCRegClass,&PPC::F8RCRegClass,&PPC::F8RCRegClass, |
| 301 | &PPC::F8RCRegClass,&PPC::F8RCRegClass,&PPC::F8RCRegClass,&PPC::F8RCRegClass, |
| 302 | &PPC::F8RCRegClass,&PPC::F8RCRegClass,&PPC::F8RCRegClass,&PPC::F8RCRegClass, |
| 303 | &PPC::F8RCRegClass,&PPC::F8RCRegClass, |
| 304 | |
| 305 | &PPC::CRRCRegClass,&PPC::CRRCRegClass,&PPC::CRRCRegClass, |
| 306 | |
| 307 | &PPC::VRRCRegClass,&PPC::VRRCRegClass,&PPC::VRRCRegClass,&PPC::VRRCRegClass, |
| 308 | &PPC::VRRCRegClass,&PPC::VRRCRegClass,&PPC::VRRCRegClass,&PPC::VRRCRegClass, |
| 309 | &PPC::VRRCRegClass,&PPC::VRRCRegClass,&PPC::VRRCRegClass,&PPC::VRRCRegClass, |
| 310 | |
| 311 | &PPC::GPRCRegClass, 0 |
Evan Cheng | 0f3ac8d | 2006-05-18 00:12:58 +0000 | [diff] [blame] | 312 | }; |
Chris Lattner | 804e067 | 2006-07-11 00:48:23 +0000 | [diff] [blame] | 313 | |
| 314 | // 64-bit Darwin calling convention. |
Evan Cheng | c2b861d | 2007-01-02 21:33:40 +0000 | [diff] [blame^] | 315 | static const TargetRegisterClass * const Darwin64_CalleeSavedRegClasses[] = { |
Chris Lattner | bdc571b | 2006-11-20 19:33:51 +0000 | [diff] [blame] | 316 | &PPC::G8RCRegClass,&PPC::G8RCRegClass, |
Chris Lattner | 804e067 | 2006-07-11 00:48:23 +0000 | [diff] [blame] | 317 | &PPC::G8RCRegClass,&PPC::G8RCRegClass,&PPC::G8RCRegClass,&PPC::G8RCRegClass, |
| 318 | &PPC::G8RCRegClass,&PPC::G8RCRegClass,&PPC::G8RCRegClass,&PPC::G8RCRegClass, |
| 319 | &PPC::G8RCRegClass,&PPC::G8RCRegClass,&PPC::G8RCRegClass,&PPC::G8RCRegClass, |
| 320 | &PPC::G8RCRegClass,&PPC::G8RCRegClass,&PPC::G8RCRegClass,&PPC::G8RCRegClass, |
| 321 | |
| 322 | &PPC::F8RCRegClass,&PPC::F8RCRegClass,&PPC::F8RCRegClass,&PPC::F8RCRegClass, |
| 323 | &PPC::F8RCRegClass,&PPC::F8RCRegClass,&PPC::F8RCRegClass,&PPC::F8RCRegClass, |
| 324 | &PPC::F8RCRegClass,&PPC::F8RCRegClass,&PPC::F8RCRegClass,&PPC::F8RCRegClass, |
| 325 | &PPC::F8RCRegClass,&PPC::F8RCRegClass,&PPC::F8RCRegClass,&PPC::F8RCRegClass, |
| 326 | &PPC::F8RCRegClass,&PPC::F8RCRegClass, |
| 327 | |
| 328 | &PPC::CRRCRegClass,&PPC::CRRCRegClass,&PPC::CRRCRegClass, |
| 329 | |
| 330 | &PPC::VRRCRegClass,&PPC::VRRCRegClass,&PPC::VRRCRegClass,&PPC::VRRCRegClass, |
| 331 | &PPC::VRRCRegClass,&PPC::VRRCRegClass,&PPC::VRRCRegClass,&PPC::VRRCRegClass, |
| 332 | &PPC::VRRCRegClass,&PPC::VRRCRegClass,&PPC::VRRCRegClass,&PPC::VRRCRegClass, |
| 333 | |
Chris Lattner | 6a5339b | 2006-11-14 18:44:47 +0000 | [diff] [blame] | 334 | &PPC::G8RCRegClass, 0 |
Chris Lattner | 804e067 | 2006-07-11 00:48:23 +0000 | [diff] [blame] | 335 | }; |
| 336 | |
Evan Cheng | c2b861d | 2007-01-02 21:33:40 +0000 | [diff] [blame^] | 337 | return Subtarget.isPPC64() ? Darwin64_CalleeSavedRegClasses : |
| 338 | Darwin32_CalleeSavedRegClasses; |
Evan Cheng | 0f3ac8d | 2006-05-18 00:12:58 +0000 | [diff] [blame] | 339 | } |
| 340 | |
Chris Lattner | f38df04 | 2005-09-09 21:46:49 +0000 | [diff] [blame] | 341 | /// foldMemoryOperand - PowerPC (like most RISC's) can only fold spills into |
| 342 | /// copy instructions, turning them into load/store instructions. |
Nate Begeman | 21e463b | 2005-10-16 05:39:50 +0000 | [diff] [blame] | 343 | MachineInstr *PPCRegisterInfo::foldMemoryOperand(MachineInstr *MI, |
| 344 | unsigned OpNum, |
| 345 | int FrameIndex) const { |
Chris Lattner | f38df04 | 2005-09-09 21:46:49 +0000 | [diff] [blame] | 346 | // Make sure this is a reg-reg copy. Note that we can't handle MCRF, because |
| 347 | // it takes more than one instruction to store it. |
| 348 | unsigned Opc = MI->getOpcode(); |
Evan Cheng | 6ce7dc2 | 2006-11-15 20:58:11 +0000 | [diff] [blame] | 349 | |
| 350 | MachineInstr *NewMI = NULL; |
Chris Lattner | b410dc9 | 2006-06-20 23:18:58 +0000 | [diff] [blame] | 351 | if ((Opc == PPC::OR && |
Chris Lattner | f38df04 | 2005-09-09 21:46:49 +0000 | [diff] [blame] | 352 | MI->getOperand(1).getReg() == MI->getOperand(2).getReg())) { |
| 353 | if (OpNum == 0) { // move -> store |
| 354 | unsigned InReg = MI->getOperand(1).getReg(); |
Evan Cheng | c0f64ff | 2006-11-27 23:37:22 +0000 | [diff] [blame] | 355 | NewMI = addFrameReference(BuildMI(TII.get(PPC::STW)).addReg(InReg), |
| 356 | FrameIndex); |
Chris Lattner | c9fe750 | 2005-09-09 21:59:44 +0000 | [diff] [blame] | 357 | } else { // move -> load |
Chris Lattner | f38df04 | 2005-09-09 21:46:49 +0000 | [diff] [blame] | 358 | unsigned OutReg = MI->getOperand(0).getReg(); |
Evan Cheng | c0f64ff | 2006-11-27 23:37:22 +0000 | [diff] [blame] | 359 | NewMI = addFrameReference(BuildMI(TII.get(PPC::LWZ), OutReg), |
| 360 | FrameIndex); |
Chris Lattner | f38df04 | 2005-09-09 21:46:49 +0000 | [diff] [blame] | 361 | } |
Nate Begeman | 1d9d742 | 2005-10-18 00:28:58 +0000 | [diff] [blame] | 362 | } else if ((Opc == PPC::OR8 && |
| 363 | MI->getOperand(1).getReg() == MI->getOperand(2).getReg())) { |
| 364 | if (OpNum == 0) { // move -> store |
| 365 | unsigned InReg = MI->getOperand(1).getReg(); |
Evan Cheng | c0f64ff | 2006-11-27 23:37:22 +0000 | [diff] [blame] | 366 | NewMI = addFrameReference(BuildMI(TII.get(PPC::STD)).addReg(InReg), |
| 367 | FrameIndex); |
Nate Begeman | 1d9d742 | 2005-10-18 00:28:58 +0000 | [diff] [blame] | 368 | } else { // move -> load |
| 369 | unsigned OutReg = MI->getOperand(0).getReg(); |
Evan Cheng | c0f64ff | 2006-11-27 23:37:22 +0000 | [diff] [blame] | 370 | NewMI = addFrameReference(BuildMI(TII.get(PPC::LD), OutReg), FrameIndex); |
Nate Begeman | 1d9d742 | 2005-10-18 00:28:58 +0000 | [diff] [blame] | 371 | } |
Chris Lattner | 919c032 | 2005-10-01 01:35:02 +0000 | [diff] [blame] | 372 | } else if (Opc == PPC::FMRD) { |
Chris Lattner | c9fe750 | 2005-09-09 21:59:44 +0000 | [diff] [blame] | 373 | if (OpNum == 0) { // move -> store |
| 374 | unsigned InReg = MI->getOperand(1).getReg(); |
Evan Cheng | c0f64ff | 2006-11-27 23:37:22 +0000 | [diff] [blame] | 375 | NewMI = addFrameReference(BuildMI(TII.get(PPC::STFD)).addReg(InReg), |
| 376 | FrameIndex); |
Chris Lattner | c9fe750 | 2005-09-09 21:59:44 +0000 | [diff] [blame] | 377 | } else { // move -> load |
| 378 | unsigned OutReg = MI->getOperand(0).getReg(); |
Evan Cheng | c0f64ff | 2006-11-27 23:37:22 +0000 | [diff] [blame] | 379 | NewMI = addFrameReference(BuildMI(TII.get(PPC::LFD), OutReg), FrameIndex); |
Chris Lattner | c9fe750 | 2005-09-09 21:59:44 +0000 | [diff] [blame] | 380 | } |
Chris Lattner | 919c032 | 2005-10-01 01:35:02 +0000 | [diff] [blame] | 381 | } else if (Opc == PPC::FMRS) { |
| 382 | if (OpNum == 0) { // move -> store |
| 383 | unsigned InReg = MI->getOperand(1).getReg(); |
Evan Cheng | c0f64ff | 2006-11-27 23:37:22 +0000 | [diff] [blame] | 384 | NewMI = addFrameReference(BuildMI(TII.get(PPC::STFS)).addReg(InReg), |
| 385 | FrameIndex); |
Chris Lattner | 919c032 | 2005-10-01 01:35:02 +0000 | [diff] [blame] | 386 | } else { // move -> load |
| 387 | unsigned OutReg = MI->getOperand(0).getReg(); |
Evan Cheng | c0f64ff | 2006-11-27 23:37:22 +0000 | [diff] [blame] | 388 | NewMI = addFrameReference(BuildMI(TII.get(PPC::LFS), OutReg), FrameIndex); |
Chris Lattner | 919c032 | 2005-10-01 01:35:02 +0000 | [diff] [blame] | 389 | } |
Chris Lattner | f38df04 | 2005-09-09 21:46:49 +0000 | [diff] [blame] | 390 | } |
Evan Cheng | 6ce7dc2 | 2006-11-15 20:58:11 +0000 | [diff] [blame] | 391 | |
| 392 | if (NewMI) |
| 393 | NewMI->copyKillDeadInfo(MI); |
| 394 | return NewMI; |
Chris Lattner | f38df04 | 2005-09-09 21:46:49 +0000 | [diff] [blame] | 395 | } |
| 396 | |
Misha Brukman | f2ccb77 | 2004-08-17 04:55:41 +0000 | [diff] [blame] | 397 | //===----------------------------------------------------------------------===// |
| 398 | // Stack Frame Processing methods |
| 399 | //===----------------------------------------------------------------------===// |
| 400 | |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 401 | // needsFP - Return true if the specified function should have a dedicated frame |
Misha Brukman | f2ccb77 | 2004-08-17 04:55:41 +0000 | [diff] [blame] | 402 | // pointer register. This is true if the function has variable sized allocas or |
| 403 | // if frame pointer elimination is disabled. |
| 404 | // |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 405 | static bool needsFP(const MachineFunction &MF) { |
| 406 | const MachineFrameInfo *MFI = MF.getFrameInfo(); |
| 407 | return NoFramePointerElim || MFI->hasVarSizedObjects(); |
| 408 | } |
| 409 | |
| 410 | // hasFP - Return true if the specified function actually has a dedicated frame |
| 411 | // pointer register. This is true if the function needs a frame pointer and has |
| 412 | // a non-zero stack size. |
Chris Lattner | 4f91a4c | 2006-04-03 22:03:29 +0000 | [diff] [blame] | 413 | static bool hasFP(const MachineFunction &MF) { |
| 414 | const MachineFrameInfo *MFI = MF.getFrameInfo(); |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 415 | return MFI->getStackSize() && needsFP(MF); |
Misha Brukman | f2ccb77 | 2004-08-17 04:55:41 +0000 | [diff] [blame] | 416 | } |
| 417 | |
Jim Laskey | 51fe9d9 | 2006-12-06 17:42:06 +0000 | [diff] [blame] | 418 | /// usesLR - Returns if the link registers (LR) has been used in the function. |
| 419 | /// |
| 420 | bool PPCRegisterInfo::usesLR(MachineFunction &MF) const { |
| 421 | const bool *PhysRegsUsed = MF.getUsedPhysregs(); |
| 422 | return PhysRegsUsed[getRARegister()]; |
| 423 | } |
| 424 | |
Nate Begeman | 21e463b | 2005-10-16 05:39:50 +0000 | [diff] [blame] | 425 | void PPCRegisterInfo:: |
Misha Brukman | f2ccb77 | 2004-08-17 04:55:41 +0000 | [diff] [blame] | 426 | eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB, |
| 427 | MachineBasicBlock::iterator I) const { |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 428 | // Simply discard ADJCALLSTACKDOWN, ADJCALLSTACKUP instructions. |
Misha Brukman | f2ccb77 | 2004-08-17 04:55:41 +0000 | [diff] [blame] | 429 | MBB.erase(I); |
| 430 | } |
| 431 | |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 432 | /// LowerDynamicAlloc - Generate the code for allocating an object in the |
| 433 | /// current frame. The sequence of code with be in the general form |
| 434 | /// |
| 435 | /// addi R0, SP, #frameSize ; get the address of the previous frame |
| 436 | /// stwxu R0, SP, Rnegsize ; add and update the SP with the negated size |
| 437 | /// addi Rnew, SP, #maxCalFrameSize ; get the top of the allocation |
| 438 | /// |
| 439 | void PPCRegisterInfo::lowerDynamicAlloc(MachineBasicBlock::iterator II) const { |
| 440 | // Get the instruction. |
| 441 | MachineInstr &MI = *II; |
| 442 | // Get the instruction's basic block. |
| 443 | MachineBasicBlock &MBB = *MI.getParent(); |
| 444 | // Get the basic block's function. |
| 445 | MachineFunction &MF = *MBB.getParent(); |
| 446 | // Get the frame info. |
| 447 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
| 448 | // Determine whether 64-bit pointers are used. |
| 449 | bool LP64 = Subtarget.isPPC64(); |
| 450 | |
| 451 | // Determine the maximum call stack size. maxCallFrameSize may be |
| 452 | // less than the minimum. |
| 453 | unsigned maxCallFrameSize = MFI->getMaxCallFrameSize(); |
| 454 | unsigned getMinCallFrameSize = |
| 455 | PPCFrameInfo::getMinCallFrameSize(LP64); |
| 456 | maxCallFrameSize = std::max(maxCallFrameSize, getMinCallFrameSize); |
| 457 | // Get the total frame size. |
| 458 | unsigned FrameSize = MFI->getStackSize(); |
| 459 | |
| 460 | // Get stack alignments. |
| 461 | unsigned TargetAlign = MF.getTarget().getFrameInfo()->getStackAlignment(); |
| 462 | unsigned MaxAlign = MFI->getMaxAlignment(); |
Jim Laskey | d6fa8c1 | 2006-11-17 18:49:39 +0000 | [diff] [blame] | 463 | assert(MaxAlign <= TargetAlign && |
| 464 | "Dynamic alloca with large aligns not supported"); |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 465 | |
| 466 | // Determine the previous frame's address. If FrameSize can't be |
| 467 | // represented as 16 bits or we need special alignment, then we load the |
| 468 | // previous frame's address from 0(SP). Why not do an addis of the hi? |
| 469 | // Because R0 is our only safe tmp register and addi/addis treat R0 as zero. |
| 470 | // Constructing the constant and adding would take 3 instructions. |
| 471 | // Fortunately, a frame greater than 32K is rare. |
| 472 | if (MaxAlign < TargetAlign && isInt16(FrameSize)) { |
Evan Cheng | c0f64ff | 2006-11-27 23:37:22 +0000 | [diff] [blame] | 473 | BuildMI(MBB, II, TII.get(PPC::ADDI), PPC::R0) |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 474 | .addReg(PPC::R31) |
| 475 | .addImm(FrameSize); |
| 476 | } else if (LP64) { |
Evan Cheng | c0f64ff | 2006-11-27 23:37:22 +0000 | [diff] [blame] | 477 | BuildMI(MBB, II, TII.get(PPC::LD), PPC::X0) |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 478 | .addImm(0) |
| 479 | .addReg(PPC::X1); |
| 480 | } else { |
Evan Cheng | c0f64ff | 2006-11-27 23:37:22 +0000 | [diff] [blame] | 481 | BuildMI(MBB, II, TII.get(PPC::LWZ), PPC::R0) |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 482 | .addImm(0) |
| 483 | .addReg(PPC::R1); |
| 484 | } |
| 485 | |
| 486 | // Grow the stack and update the stack pointer link, then |
| 487 | // determine the address of new allocated space. |
| 488 | if (LP64) { |
Evan Cheng | c0f64ff | 2006-11-27 23:37:22 +0000 | [diff] [blame] | 489 | BuildMI(MBB, II, TII.get(PPC::STDUX)) |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 490 | .addReg(PPC::X0) |
| 491 | .addReg(PPC::X1) |
| 492 | .addReg(MI.getOperand(1).getReg()); |
Evan Cheng | c0f64ff | 2006-11-27 23:37:22 +0000 | [diff] [blame] | 493 | BuildMI(MBB, II, TII.get(PPC::ADDI8), MI.getOperand(0).getReg()) |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 494 | .addReg(PPC::X1) |
| 495 | .addImm(maxCallFrameSize); |
| 496 | } else { |
Evan Cheng | c0f64ff | 2006-11-27 23:37:22 +0000 | [diff] [blame] | 497 | BuildMI(MBB, II, TII.get(PPC::STWUX)) |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 498 | .addReg(PPC::R0) |
| 499 | .addReg(PPC::R1) |
| 500 | .addReg(MI.getOperand(1).getReg()); |
Evan Cheng | c0f64ff | 2006-11-27 23:37:22 +0000 | [diff] [blame] | 501 | BuildMI(MBB, II, TII.get(PPC::ADDI), MI.getOperand(0).getReg()) |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 502 | .addReg(PPC::R1) |
| 503 | .addImm(maxCallFrameSize); |
| 504 | } |
| 505 | |
| 506 | // Discard the DYNALLOC instruction. |
| 507 | MBB.erase(II); |
| 508 | } |
| 509 | |
Misha Brukman | f2ccb77 | 2004-08-17 04:55:41 +0000 | [diff] [blame] | 510 | void |
Nate Begeman | 21e463b | 2005-10-16 05:39:50 +0000 | [diff] [blame] | 511 | PPCRegisterInfo::eliminateFrameIndex(MachineBasicBlock::iterator II) const { |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 512 | // Get the instruction. |
Misha Brukman | f2ccb77 | 2004-08-17 04:55:41 +0000 | [diff] [blame] | 513 | MachineInstr &MI = *II; |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 514 | // Get the instruction's basic block. |
Misha Brukman | f2ccb77 | 2004-08-17 04:55:41 +0000 | [diff] [blame] | 515 | MachineBasicBlock &MBB = *MI.getParent(); |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 516 | // Get the basic block's function. |
Misha Brukman | f2ccb77 | 2004-08-17 04:55:41 +0000 | [diff] [blame] | 517 | MachineFunction &MF = *MBB.getParent(); |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 518 | // Get the frame info. |
| 519 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
Misha Brukman | b5f662f | 2005-04-21 23:30:14 +0000 | [diff] [blame] | 520 | |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 521 | // Find out which operand is the frame index. |
| 522 | unsigned i = 0; |
Misha Brukman | f2ccb77 | 2004-08-17 04:55:41 +0000 | [diff] [blame] | 523 | while (!MI.getOperand(i).isFrameIndex()) { |
| 524 | ++i; |
| 525 | assert(i < MI.getNumOperands() && "Instr doesn't have FrameIndex operand!"); |
| 526 | } |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 527 | // Take into account whether it's an add or mem instruction |
| 528 | unsigned OffIdx = (i == 2) ? 1 : 2; |
| 529 | // Get the frame index. |
Misha Brukman | f2ccb77 | 2004-08-17 04:55:41 +0000 | [diff] [blame] | 530 | int FrameIndex = MI.getOperand(i).getFrameIndex(); |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 531 | |
| 532 | // Get the frame pointer save index. Users of this index are primarily |
| 533 | // DYNALLOC instructions. |
| 534 | PPCFunctionInfo *FI = MF.getInfo<PPCFunctionInfo>(); |
| 535 | int FPSI = FI->getFramePointerSaveIndex(); |
| 536 | // Get the instruction opcode. |
| 537 | unsigned OpC = MI.getOpcode(); |
| 538 | |
| 539 | // Special case for dynamic alloca. |
| 540 | if (FPSI && FrameIndex == FPSI && |
| 541 | (OpC == PPC::DYNALLOC || OpC == PPC::DYNALLOC8)) { |
| 542 | lowerDynamicAlloc(II); |
| 543 | return; |
| 544 | } |
Misha Brukman | f2ccb77 | 2004-08-17 04:55:41 +0000 | [diff] [blame] | 545 | |
| 546 | // Replace the FrameIndex with base register with GPR1 (SP) or GPR31 (FP). |
Chris Lattner | 09e4606 | 2006-09-05 02:31:13 +0000 | [diff] [blame] | 547 | MI.getOperand(i).ChangeToRegister(hasFP(MF) ? PPC::R31 : PPC::R1, false); |
Misha Brukman | f2ccb77 | 2004-08-17 04:55:41 +0000 | [diff] [blame] | 548 | |
Chris Lattner | 7ffa9ab | 2006-06-27 18:55:49 +0000 | [diff] [blame] | 549 | // Figure out if the offset in the instruction is shifted right two bits. This |
| 550 | // is true for instructions like "STD", which the machine implicitly adds two |
| 551 | // low zeros to. |
| 552 | bool isIXAddr = false; |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 553 | switch (OpC) { |
Chris Lattner | 7ffa9ab | 2006-06-27 18:55:49 +0000 | [diff] [blame] | 554 | case PPC::LWA: |
| 555 | case PPC::LD: |
| 556 | case PPC::STD: |
| 557 | case PPC::STD_32: |
| 558 | isIXAddr = true; |
| 559 | break; |
| 560 | } |
| 561 | |
Misha Brukman | f2ccb77 | 2004-08-17 04:55:41 +0000 | [diff] [blame] | 562 | // Now add the frame object offset to the offset from r1. |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 563 | int Offset = MFI->getObjectOffset(FrameIndex); |
Chris Lattner | 7ffa9ab | 2006-06-27 18:55:49 +0000 | [diff] [blame] | 564 | |
| 565 | if (!isIXAddr) |
| 566 | Offset += MI.getOperand(OffIdx).getImmedValue(); |
| 567 | else |
| 568 | Offset += MI.getOperand(OffIdx).getImmedValue() << 2; |
Misha Brukman | f2ccb77 | 2004-08-17 04:55:41 +0000 | [diff] [blame] | 569 | |
| 570 | // If we're not using a Frame Pointer that has been set to the value of the |
| 571 | // SP before having the stack size subtracted from it, then add the stack size |
| 572 | // to Offset to get the correct offset. |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 573 | Offset += MFI->getStackSize(); |
Misha Brukman | b5f662f | 2005-04-21 23:30:14 +0000 | [diff] [blame] | 574 | |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 575 | if (!isInt16(Offset)) { |
Misha Brukman | f2ccb77 | 2004-08-17 04:55:41 +0000 | [diff] [blame] | 576 | // Insert a set of r0 with the full offset value before the ld, st, or add |
Evan Cheng | c0f64ff | 2006-11-27 23:37:22 +0000 | [diff] [blame] | 577 | BuildMI(MBB, II, TII.get(PPC::LIS), PPC::R0).addImm(Offset >> 16); |
| 578 | BuildMI(MBB, II, TII.get(PPC::ORI), PPC::R0).addReg(PPC::R0).addImm(Offset); |
Chris Lattner | c6d48d3 | 2006-01-11 23:07:57 +0000 | [diff] [blame] | 579 | |
Misha Brukman | f2ccb77 | 2004-08-17 04:55:41 +0000 | [diff] [blame] | 580 | // convert into indexed form of the instruction |
| 581 | // sth 0:rA, 1:imm 2:(rB) ==> sthx 0:rA, 2:rB, 1:r0 |
| 582 | // addi 0:rA 1:rB, 2, imm ==> add 0:rA, 1:rB, 2:r0 |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 583 | assert(ImmToIdxMap.count(OpC) && |
Chris Lattner | 1463019 | 2005-09-09 20:51:08 +0000 | [diff] [blame] | 584 | "No indexed form of load or store available!"); |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 585 | unsigned NewOpcode = ImmToIdxMap.find(OpC)->second; |
Evan Cheng | 12a4478 | 2006-11-30 07:12:03 +0000 | [diff] [blame] | 586 | MI.setInstrDescriptor(TII.get(NewOpcode)); |
Chris Lattner | 09e4606 | 2006-09-05 02:31:13 +0000 | [diff] [blame] | 587 | MI.getOperand(1).ChangeToRegister(MI.getOperand(i).getReg(), false); |
| 588 | MI.getOperand(2).ChangeToRegister(PPC::R0, false); |
Misha Brukman | f2ccb77 | 2004-08-17 04:55:41 +0000 | [diff] [blame] | 589 | } else { |
Chris Lattner | 7ffa9ab | 2006-06-27 18:55:49 +0000 | [diff] [blame] | 590 | if (isIXAddr) { |
Chris Lattner | 841d12d | 2005-10-18 16:51:22 +0000 | [diff] [blame] | 591 | assert((Offset & 3) == 0 && "Invalid frame offset!"); |
| 592 | Offset >>= 2; // The actual encoded value has the low two bits zero. |
Chris Lattner | 841d12d | 2005-10-18 16:51:22 +0000 | [diff] [blame] | 593 | } |
Chris Lattner | e53f4a0 | 2006-05-04 17:52:23 +0000 | [diff] [blame] | 594 | MI.getOperand(OffIdx).ChangeToImmediate(Offset); |
Misha Brukman | f2ccb77 | 2004-08-17 04:55:41 +0000 | [diff] [blame] | 595 | } |
| 596 | } |
| 597 | |
Chris Lattner | f7d2372 | 2006-04-17 20:59:25 +0000 | [diff] [blame] | 598 | /// VRRegNo - Map from a numbered VR register to its enum value. |
| 599 | /// |
| 600 | static const unsigned short VRRegNo[] = { |
Chris Lattner | b47e089 | 2006-06-12 21:50:57 +0000 | [diff] [blame] | 601 | PPC::V0 , PPC::V1 , PPC::V2 , PPC::V3 , PPC::V4 , PPC::V5 , PPC::V6 , PPC::V7 , |
| 602 | PPC::V8 , PPC::V9 , PPC::V10, PPC::V11, PPC::V12, PPC::V13, PPC::V14, PPC::V15, |
Chris Lattner | f7d2372 | 2006-04-17 20:59:25 +0000 | [diff] [blame] | 603 | PPC::V16, PPC::V17, PPC::V18, PPC::V19, PPC::V20, PPC::V21, PPC::V22, PPC::V23, |
| 604 | PPC::V24, PPC::V25, PPC::V26, PPC::V27, PPC::V28, PPC::V29, PPC::V30, PPC::V31 |
| 605 | }; |
| 606 | |
Chris Lattner | f9568d8 | 2006-04-17 21:48:13 +0000 | [diff] [blame] | 607 | /// RemoveVRSaveCode - We have found that this function does not need any code |
| 608 | /// to manipulate the VRSAVE register, even though it uses vector registers. |
| 609 | /// This can happen when the only registers used are known to be live in or out |
| 610 | /// of the function. Remove all of the VRSAVE related code from the function. |
| 611 | static void RemoveVRSaveCode(MachineInstr *MI) { |
| 612 | MachineBasicBlock *Entry = MI->getParent(); |
| 613 | MachineFunction *MF = Entry->getParent(); |
| 614 | |
| 615 | // We know that the MTVRSAVE instruction immediately follows MI. Remove it. |
| 616 | MachineBasicBlock::iterator MBBI = MI; |
| 617 | ++MBBI; |
| 618 | assert(MBBI != Entry->end() && MBBI->getOpcode() == PPC::MTVRSAVE); |
| 619 | MBBI->eraseFromParent(); |
| 620 | |
| 621 | bool RemovedAllMTVRSAVEs = true; |
| 622 | // See if we can find and remove the MTVRSAVE instruction from all of the |
| 623 | // epilog blocks. |
| 624 | const TargetInstrInfo &TII = *MF->getTarget().getInstrInfo(); |
| 625 | for (MachineFunction::iterator I = MF->begin(), E = MF->end(); I != E; ++I) { |
| 626 | // If last instruction is a return instruction, add an epilogue |
| 627 | if (!I->empty() && TII.isReturn(I->back().getOpcode())) { |
| 628 | bool FoundIt = false; |
| 629 | for (MBBI = I->end(); MBBI != I->begin(); ) { |
| 630 | --MBBI; |
| 631 | if (MBBI->getOpcode() == PPC::MTVRSAVE) { |
| 632 | MBBI->eraseFromParent(); // remove it. |
| 633 | FoundIt = true; |
| 634 | break; |
| 635 | } |
| 636 | } |
| 637 | RemovedAllMTVRSAVEs &= FoundIt; |
| 638 | } |
| 639 | } |
| 640 | |
| 641 | // If we found and removed all MTVRSAVE instructions, remove the read of |
| 642 | // VRSAVE as well. |
| 643 | if (RemovedAllMTVRSAVEs) { |
| 644 | MBBI = MI; |
| 645 | assert(MBBI != Entry->begin() && "UPDATE_VRSAVE is first instr in block?"); |
| 646 | --MBBI; |
| 647 | assert(MBBI->getOpcode() == PPC::MFVRSAVE && "VRSAVE instrs wandered?"); |
| 648 | MBBI->eraseFromParent(); |
| 649 | } |
| 650 | |
| 651 | // Finally, nuke the UPDATE_VRSAVE. |
| 652 | MI->eraseFromParent(); |
| 653 | } |
| 654 | |
Chris Lattner | 1877ec9 | 2006-03-13 21:52:10 +0000 | [diff] [blame] | 655 | // HandleVRSaveUpdate - MI is the UPDATE_VRSAVE instruction introduced by the |
| 656 | // instruction selector. Based on the vector registers that have been used, |
| 657 | // transform this into the appropriate ORI instruction. |
Evan Cheng | c0f64ff | 2006-11-27 23:37:22 +0000 | [diff] [blame] | 658 | static void HandleVRSaveUpdate(MachineInstr *MI, const bool *UsedRegs, |
| 659 | const TargetInstrInfo &TII) { |
Chris Lattner | 1877ec9 | 2006-03-13 21:52:10 +0000 | [diff] [blame] | 660 | unsigned UsedRegMask = 0; |
Chris Lattner | f7d2372 | 2006-04-17 20:59:25 +0000 | [diff] [blame] | 661 | for (unsigned i = 0; i != 32; ++i) |
| 662 | if (UsedRegs[VRRegNo[i]]) |
| 663 | UsedRegMask |= 1 << (31-i); |
| 664 | |
Chris Lattner | 402504b | 2006-04-17 21:22:06 +0000 | [diff] [blame] | 665 | // Live in and live out values already must be in the mask, so don't bother |
| 666 | // marking them. |
| 667 | MachineFunction *MF = MI->getParent()->getParent(); |
| 668 | for (MachineFunction::livein_iterator I = |
| 669 | MF->livein_begin(), E = MF->livein_end(); I != E; ++I) { |
| 670 | unsigned RegNo = PPCRegisterInfo::getRegisterNumbering(I->first); |
| 671 | if (VRRegNo[RegNo] == I->first) // If this really is a vector reg. |
| 672 | UsedRegMask &= ~(1 << (31-RegNo)); // Doesn't need to be marked. |
| 673 | } |
| 674 | for (MachineFunction::liveout_iterator I = |
| 675 | MF->liveout_begin(), E = MF->liveout_end(); I != E; ++I) { |
| 676 | unsigned RegNo = PPCRegisterInfo::getRegisterNumbering(*I); |
| 677 | if (VRRegNo[RegNo] == *I) // If this really is a vector reg. |
| 678 | UsedRegMask &= ~(1 << (31-RegNo)); // Doesn't need to be marked. |
| 679 | } |
| 680 | |
Chris Lattner | 1877ec9 | 2006-03-13 21:52:10 +0000 | [diff] [blame] | 681 | unsigned SrcReg = MI->getOperand(1).getReg(); |
| 682 | unsigned DstReg = MI->getOperand(0).getReg(); |
| 683 | // If no registers are used, turn this into a copy. |
| 684 | if (UsedRegMask == 0) { |
Chris Lattner | f9568d8 | 2006-04-17 21:48:13 +0000 | [diff] [blame] | 685 | // Remove all VRSAVE code. |
| 686 | RemoveVRSaveCode(MI); |
| 687 | return; |
Chris Lattner | 1877ec9 | 2006-03-13 21:52:10 +0000 | [diff] [blame] | 688 | } else if ((UsedRegMask & 0xFFFF) == UsedRegMask) { |
Evan Cheng | c0f64ff | 2006-11-27 23:37:22 +0000 | [diff] [blame] | 689 | BuildMI(*MI->getParent(), MI, TII.get(PPC::ORI), DstReg) |
Chris Lattner | 1877ec9 | 2006-03-13 21:52:10 +0000 | [diff] [blame] | 690 | .addReg(SrcReg).addImm(UsedRegMask); |
| 691 | } else if ((UsedRegMask & 0xFFFF0000) == UsedRegMask) { |
Evan Cheng | c0f64ff | 2006-11-27 23:37:22 +0000 | [diff] [blame] | 692 | BuildMI(*MI->getParent(), MI, TII.get(PPC::ORIS), DstReg) |
Chris Lattner | 1877ec9 | 2006-03-13 21:52:10 +0000 | [diff] [blame] | 693 | .addReg(SrcReg).addImm(UsedRegMask >> 16); |
| 694 | } else { |
Evan Cheng | c0f64ff | 2006-11-27 23:37:22 +0000 | [diff] [blame] | 695 | BuildMI(*MI->getParent(), MI, TII.get(PPC::ORIS), DstReg) |
Chris Lattner | 1877ec9 | 2006-03-13 21:52:10 +0000 | [diff] [blame] | 696 | .addReg(SrcReg).addImm(UsedRegMask >> 16); |
Evan Cheng | c0f64ff | 2006-11-27 23:37:22 +0000 | [diff] [blame] | 697 | BuildMI(*MI->getParent(), MI, TII.get(PPC::ORI), DstReg) |
Chris Lattner | 1877ec9 | 2006-03-13 21:52:10 +0000 | [diff] [blame] | 698 | .addReg(DstReg).addImm(UsedRegMask & 0xFFFF); |
| 699 | } |
| 700 | |
| 701 | // Remove the old UPDATE_VRSAVE instruction. |
Chris Lattner | f9568d8 | 2006-04-17 21:48:13 +0000 | [diff] [blame] | 702 | MI->eraseFromParent(); |
Chris Lattner | 1877ec9 | 2006-03-13 21:52:10 +0000 | [diff] [blame] | 703 | } |
| 704 | |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 705 | /// determineFrameLayout - Determine the size of the frame and maximum call |
| 706 | /// frame size. |
| 707 | void PPCRegisterInfo::determineFrameLayout(MachineFunction &MF) const { |
| 708 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
| 709 | |
| 710 | // Get the number of bytes to allocate from the FrameInfo |
| 711 | unsigned FrameSize = MFI->getStackSize(); |
| 712 | |
| 713 | // Get the alignments provided by the target, and the maximum alignment |
| 714 | // (if any) of the fixed frame objects. |
| 715 | unsigned TargetAlign = MF.getTarget().getFrameInfo()->getStackAlignment(); |
| 716 | unsigned MaxAlign = MFI->getMaxAlignment(); |
| 717 | unsigned Align = std::max(TargetAlign, MaxAlign); |
| 718 | assert(isPowerOf2_32(Align) && "Alignment is not power of 2"); |
| 719 | unsigned AlignMask = Align - 1; // |
| 720 | |
| 721 | // If we are a leaf function, and use up to 224 bytes of stack space, |
| 722 | // don't have a frame pointer, calls, or dynamic alloca then we do not need |
| 723 | // to adjust the stack pointer (we fit in the Red Zone). |
| 724 | if (FrameSize <= 224 && // Fits in red zone. |
Jim Laskey | 2ff5cdb | 2006-11-17 16:09:31 +0000 | [diff] [blame] | 725 | !MFI->hasVarSizedObjects() && // No dynamic alloca. |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 726 | !MFI->hasCalls() && // No calls. |
| 727 | MaxAlign <= TargetAlign) { // No special alignment. |
| 728 | // No need for frame |
| 729 | MFI->setStackSize(0); |
| 730 | return; |
| 731 | } |
| 732 | |
| 733 | // Get the maximum call frame size of all the calls. |
| 734 | unsigned maxCallFrameSize = MFI->getMaxCallFrameSize(); |
| 735 | |
| 736 | // Maximum call frame needs to be at least big enough for linkage and 8 args. |
| 737 | unsigned minCallFrameSize = |
| 738 | PPCFrameInfo::getMinCallFrameSize(Subtarget.isPPC64()); |
| 739 | maxCallFrameSize = std::max(maxCallFrameSize, minCallFrameSize); |
| 740 | |
| 741 | // If we have dynamic alloca then maxCallFrameSize needs to be aligned so |
| 742 | // that allocations will be aligned. |
| 743 | if (MFI->hasVarSizedObjects()) |
| 744 | maxCallFrameSize = (maxCallFrameSize + AlignMask) & ~AlignMask; |
| 745 | |
| 746 | // Update maximum call frame size. |
| 747 | MFI->setMaxCallFrameSize(maxCallFrameSize); |
| 748 | |
| 749 | // Include call frame size in total. |
| 750 | FrameSize += maxCallFrameSize; |
| 751 | |
| 752 | // Make sure the frame is aligned. |
| 753 | FrameSize = (FrameSize + AlignMask) & ~AlignMask; |
| 754 | |
| 755 | // Update frame info. |
| 756 | MFI->setStackSize(FrameSize); |
| 757 | } |
Misha Brukman | f2ccb77 | 2004-08-17 04:55:41 +0000 | [diff] [blame] | 758 | |
Nate Begeman | 21e463b | 2005-10-16 05:39:50 +0000 | [diff] [blame] | 759 | void PPCRegisterInfo::emitPrologue(MachineFunction &MF) const { |
Misha Brukman | f2ccb77 | 2004-08-17 04:55:41 +0000 | [diff] [blame] | 760 | MachineBasicBlock &MBB = MF.front(); // Prolog goes in entry BB |
| 761 | MachineBasicBlock::iterator MBBI = MBB.begin(); |
| 762 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
Jim Laskey | 4188699 | 2006-04-07 16:34:46 +0000 | [diff] [blame] | 763 | MachineDebugInfo *DebugInfo = MFI->getMachineDebugInfo(); |
Chris Lattner | 4f91a4c | 2006-04-03 22:03:29 +0000 | [diff] [blame] | 764 | |
Chris Lattner | 4f91a4c | 2006-04-03 22:03:29 +0000 | [diff] [blame] | 765 | // Scan the prolog, looking for an UPDATE_VRSAVE instruction. If we find it, |
| 766 | // process it. |
Chris Lattner | 8aa777d | 2006-03-16 21:31:45 +0000 | [diff] [blame] | 767 | for (unsigned i = 0; MBBI != MBB.end(); ++i, ++MBBI) { |
Chris Lattner | 1877ec9 | 2006-03-13 21:52:10 +0000 | [diff] [blame] | 768 | if (MBBI->getOpcode() == PPC::UPDATE_VRSAVE) { |
Evan Cheng | c0f64ff | 2006-11-27 23:37:22 +0000 | [diff] [blame] | 769 | HandleVRSaveUpdate(MBBI, MF.getUsedPhysregs(), TII); |
Chris Lattner | 1877ec9 | 2006-03-13 21:52:10 +0000 | [diff] [blame] | 770 | break; |
| 771 | } |
| 772 | } |
| 773 | |
| 774 | // Move MBBI back to the beginning of the function. |
| 775 | MBBI = MBB.begin(); |
| 776 | |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 777 | // Work out frame sizes. |
| 778 | determineFrameLayout(MF); |
| 779 | unsigned FrameSize = MFI->getStackSize(); |
Nate Begeman | ae232e7 | 2005-11-06 09:00:38 +0000 | [diff] [blame] | 780 | |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 781 | // Skip if a leaf routine. |
| 782 | if (!FrameSize) return; |
| 783 | |
| 784 | int NegFrameSize = -FrameSize; |
Jim Laskey | 51fe9d9 | 2006-12-06 17:42:06 +0000 | [diff] [blame] | 785 | |
| 786 | // Get processor type. |
| 787 | bool IsPPC64 = Subtarget.isPPC64(); |
| 788 | // Check if the link register (LR) has been used. |
| 789 | bool UsesLR = MFI->hasCalls() || usesLR(MF); |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 790 | // Do we have a frame pointer for this function? |
| 791 | bool HasFP = hasFP(MF); |
Jim Laskey | 51fe9d9 | 2006-12-06 17:42:06 +0000 | [diff] [blame] | 792 | |
| 793 | int LROffset = PPCFrameInfo::getReturnSaveOffset(IsPPC64); |
| 794 | int FPOffset = PPCFrameInfo::getFramePointerSaveOffset(IsPPC64); |
| 795 | |
| 796 | if (IsPPC64) { |
| 797 | if (UsesLR) |
| 798 | BuildMI(MBB, MBBI, TII.get(PPC::MFLR8), PPC::X0); |
| 799 | |
| 800 | if (HasFP) |
Evan Cheng | c0f64ff | 2006-11-27 23:37:22 +0000 | [diff] [blame] | 801 | BuildMI(MBB, MBBI, TII.get(PPC::STD)) |
Jim Laskey | 51fe9d9 | 2006-12-06 17:42:06 +0000 | [diff] [blame] | 802 | .addReg(PPC::X31).addImm(FPOffset/4).addReg(PPC::X1); |
| 803 | |
| 804 | if (UsesLR) |
| 805 | BuildMI(MBB, MBBI, TII.get(PPC::STD)) |
| 806 | .addReg(PPC::X0).addImm(LROffset/4).addReg(PPC::X1); |
| 807 | } else { |
| 808 | if (UsesLR) |
| 809 | BuildMI(MBB, MBBI, TII.get(PPC::MFLR), PPC::R0); |
| 810 | |
| 811 | if (HasFP) |
| 812 | BuildMI(MBB, MBBI, TII.get(PPC::STW)) |
| 813 | .addReg(PPC::R31).addImm(FPOffset).addReg(PPC::R1); |
| 814 | |
| 815 | if (UsesLR) |
| 816 | BuildMI(MBB, MBBI, TII.get(PPC::STW)) |
| 817 | .addReg(PPC::R0).addImm(LROffset).addReg(PPC::R1); |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 818 | } |
| 819 | |
| 820 | // Get stack alignments. |
Nate Begeman | ae232e7 | 2005-11-06 09:00:38 +0000 | [diff] [blame] | 821 | unsigned TargetAlign = MF.getTarget().getFrameInfo()->getStackAlignment(); |
| 822 | unsigned MaxAlign = MFI->getMaxAlignment(); |
Misha Brukman | f2ccb77 | 2004-08-17 04:55:41 +0000 | [diff] [blame] | 823 | |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 824 | // Adjust stack pointer: r1 += NegFrameSize. |
Nate Begeman | 030514c | 2006-04-11 19:29:21 +0000 | [diff] [blame] | 825 | // If there is a preferred stack alignment, align R1 now |
Jim Laskey | 51fe9d9 | 2006-12-06 17:42:06 +0000 | [diff] [blame] | 826 | if (!IsPPC64) { |
Chris Lattner | a94a203 | 2006-11-11 19:05:28 +0000 | [diff] [blame] | 827 | // PPC32. |
| 828 | if (MaxAlign > TargetAlign) { |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 829 | assert(isPowerOf2_32(MaxAlign)&&isInt16(MaxAlign)&&"Invalid alignment!"); |
| 830 | assert(isInt16(NegFrameSize) && "Unhandled stack size and alignment!"); |
Evan Cheng | c0f64ff | 2006-11-27 23:37:22 +0000 | [diff] [blame] | 831 | BuildMI(MBB, MBBI, TII.get(PPC::RLWINM), PPC::R0) |
Chris Lattner | a94a203 | 2006-11-11 19:05:28 +0000 | [diff] [blame] | 832 | .addReg(PPC::R1).addImm(0).addImm(32-Log2_32(MaxAlign)).addImm(31); |
Evan Cheng | c0f64ff | 2006-11-27 23:37:22 +0000 | [diff] [blame] | 833 | BuildMI(MBB, MBBI, TII.get(PPC::SUBFIC) ,PPC::R0).addReg(PPC::R0) |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 834 | .addImm(NegFrameSize); |
Evan Cheng | c0f64ff | 2006-11-27 23:37:22 +0000 | [diff] [blame] | 835 | BuildMI(MBB, MBBI, TII.get(PPC::STWUX)) |
Chris Lattner | a94a203 | 2006-11-11 19:05:28 +0000 | [diff] [blame] | 836 | .addReg(PPC::R1).addReg(PPC::R1).addReg(PPC::R0); |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 837 | } else if (isInt16(NegFrameSize)) { |
Evan Cheng | c0f64ff | 2006-11-27 23:37:22 +0000 | [diff] [blame] | 838 | BuildMI(MBB, MBBI, TII.get(PPC::STWU), |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 839 | PPC::R1).addReg(PPC::R1).addImm(NegFrameSize).addReg(PPC::R1); |
Chris Lattner | a94a203 | 2006-11-11 19:05:28 +0000 | [diff] [blame] | 840 | } else { |
Evan Cheng | c0f64ff | 2006-11-27 23:37:22 +0000 | [diff] [blame] | 841 | BuildMI(MBB, MBBI, TII.get(PPC::LIS), PPC::R0).addImm(NegFrameSize >> 16); |
| 842 | BuildMI(MBB, MBBI, TII.get(PPC::ORI), PPC::R0).addReg(PPC::R0) |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 843 | .addImm(NegFrameSize & 0xFFFF); |
Evan Cheng | c0f64ff | 2006-11-27 23:37:22 +0000 | [diff] [blame] | 844 | BuildMI(MBB, MBBI, TII.get(PPC::STWUX)).addReg(PPC::R1).addReg(PPC::R1) |
Chris Lattner | a94a203 | 2006-11-11 19:05:28 +0000 | [diff] [blame] | 845 | .addReg(PPC::R0); |
| 846 | } |
| 847 | } else { // PPC64. |
| 848 | if (MaxAlign > TargetAlign) { |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 849 | assert(isPowerOf2_32(MaxAlign)&&isInt16(MaxAlign)&&"Invalid alignment!"); |
| 850 | assert(isInt16(NegFrameSize) && "Unhandled stack size and alignment!"); |
Evan Cheng | c0f64ff | 2006-11-27 23:37:22 +0000 | [diff] [blame] | 851 | BuildMI(MBB, MBBI, TII.get(PPC::RLDICL), PPC::X0) |
Chris Lattner | a94a203 | 2006-11-11 19:05:28 +0000 | [diff] [blame] | 852 | .addReg(PPC::X1).addImm(0).addImm(64-Log2_32(MaxAlign)); |
Evan Cheng | c0f64ff | 2006-11-27 23:37:22 +0000 | [diff] [blame] | 853 | BuildMI(MBB, MBBI, TII.get(PPC::SUBFIC8), PPC::X0).addReg(PPC::X0) |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 854 | .addImm(NegFrameSize); |
Evan Cheng | c0f64ff | 2006-11-27 23:37:22 +0000 | [diff] [blame] | 855 | BuildMI(MBB, MBBI, TII.get(PPC::STDUX)) |
Chris Lattner | a94a203 | 2006-11-11 19:05:28 +0000 | [diff] [blame] | 856 | .addReg(PPC::X1).addReg(PPC::X1).addReg(PPC::X0); |
Jim Laskey | 2ff5cdb | 2006-11-17 16:09:31 +0000 | [diff] [blame] | 857 | } else if (isInt16(NegFrameSize)) { |
Evan Cheng | c0f64ff | 2006-11-27 23:37:22 +0000 | [diff] [blame] | 858 | BuildMI(MBB, MBBI, TII.get(PPC::STDU), PPC::X1) |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 859 | .addReg(PPC::X1).addImm(NegFrameSize/4).addReg(PPC::X1); |
Chris Lattner | a94a203 | 2006-11-11 19:05:28 +0000 | [diff] [blame] | 860 | } else { |
Evan Cheng | c0f64ff | 2006-11-27 23:37:22 +0000 | [diff] [blame] | 861 | BuildMI(MBB, MBBI, TII.get(PPC::LIS8), PPC::X0).addImm(NegFrameSize >>16); |
| 862 | BuildMI(MBB, MBBI, TII.get(PPC::ORI8), PPC::X0).addReg(PPC::X0) |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 863 | .addImm(NegFrameSize & 0xFFFF); |
Evan Cheng | c0f64ff | 2006-11-27 23:37:22 +0000 | [diff] [blame] | 864 | BuildMI(MBB, MBBI, TII.get(PPC::STDUX)).addReg(PPC::X1).addReg(PPC::X1) |
Chris Lattner | a94a203 | 2006-11-11 19:05:28 +0000 | [diff] [blame] | 865 | .addReg(PPC::X0); |
| 866 | } |
Misha Brukman | f2ccb77 | 2004-08-17 04:55:41 +0000 | [diff] [blame] | 867 | } |
Nate Begeman | ae232e7 | 2005-11-06 09:00:38 +0000 | [diff] [blame] | 868 | |
Jim Laskey | 52fa244 | 2006-04-11 08:11:53 +0000 | [diff] [blame] | 869 | if (DebugInfo && DebugInfo->hasInfo()) { |
Jim Laskey | 4188699 | 2006-04-07 16:34:46 +0000 | [diff] [blame] | 870 | std::vector<MachineMove *> &Moves = DebugInfo->getFrameMoves(); |
| 871 | unsigned LabelID = DebugInfo->NextLabelID(); |
| 872 | |
Jim Laskey | 4c2c903 | 2006-08-25 19:40:59 +0000 | [diff] [blame] | 873 | // Mark effective beginning of when frame pointer becomes valid. |
Evan Cheng | c0f64ff | 2006-11-27 23:37:22 +0000 | [diff] [blame] | 874 | BuildMI(MBB, MBBI, TII.get(PPC::DWARF_LABEL)).addImm(LabelID); |
Jim Laskey | 4c2c903 | 2006-08-25 19:40:59 +0000 | [diff] [blame] | 875 | |
Jim Laskey | ce50a16 | 2006-08-29 16:24:26 +0000 | [diff] [blame] | 876 | // Show update of SP. |
| 877 | MachineLocation SPDst(MachineLocation::VirtualFP); |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 878 | MachineLocation SPSrc(MachineLocation::VirtualFP, NegFrameSize); |
Jim Laskey | ce50a16 | 2006-08-29 16:24:26 +0000 | [diff] [blame] | 879 | Moves.push_back(new MachineMove(LabelID, SPDst, SPSrc)); |
| 880 | |
| 881 | // Add callee saved registers to move list. |
| 882 | const std::vector<CalleeSavedInfo> &CSI = MFI->getCalleeSavedInfo(); |
| 883 | for (unsigned I = 0, E = CSI.size(); I != E; ++I) { |
| 884 | MachineLocation CSDst(MachineLocation::VirtualFP, |
| 885 | MFI->getObjectOffset(CSI[I].getFrameIdx())); |
| 886 | MachineLocation CSSrc(CSI[I].getReg()); |
| 887 | Moves.push_back(new MachineMove(LabelID, CSDst, CSSrc)); |
| 888 | } |
Jim Laskey | 4188699 | 2006-04-07 16:34:46 +0000 | [diff] [blame] | 889 | } |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 890 | |
| 891 | // If there is a frame pointer, copy R1 into R31 |
Chris Lattner | 4f91a4c | 2006-04-03 22:03:29 +0000 | [diff] [blame] | 892 | if (HasFP) { |
Jim Laskey | 51fe9d9 | 2006-12-06 17:42:06 +0000 | [diff] [blame] | 893 | if (!IsPPC64) { |
Evan Cheng | c0f64ff | 2006-11-27 23:37:22 +0000 | [diff] [blame] | 894 | BuildMI(MBB, MBBI, TII.get(PPC::OR), PPC::R31).addReg(PPC::R1) |
| 895 | .addReg(PPC::R1); |
Chris Lattner | a94a203 | 2006-11-11 19:05:28 +0000 | [diff] [blame] | 896 | } else { |
Evan Cheng | c0f64ff | 2006-11-27 23:37:22 +0000 | [diff] [blame] | 897 | BuildMI(MBB, MBBI, TII.get(PPC::OR8), PPC::X31).addReg(PPC::X1) |
| 898 | .addReg(PPC::X1); |
Chris Lattner | a94a203 | 2006-11-11 19:05:28 +0000 | [diff] [blame] | 899 | } |
Misha Brukman | f2ccb77 | 2004-08-17 04:55:41 +0000 | [diff] [blame] | 900 | } |
| 901 | } |
| 902 | |
Nate Begeman | 21e463b | 2005-10-16 05:39:50 +0000 | [diff] [blame] | 903 | void PPCRegisterInfo::emitEpilogue(MachineFunction &MF, |
| 904 | MachineBasicBlock &MBB) const { |
Misha Brukman | f2ccb77 | 2004-08-17 04:55:41 +0000 | [diff] [blame] | 905 | MachineBasicBlock::iterator MBBI = prior(MBB.end()); |
Evan Cheng | 6da8d99 | 2006-01-09 18:28:21 +0000 | [diff] [blame] | 906 | assert(MBBI->getOpcode() == PPC::BLR && |
Misha Brukman | f2ccb77 | 2004-08-17 04:55:41 +0000 | [diff] [blame] | 907 | "Can only insert epilog into returning blocks"); |
Misha Brukman | b5f662f | 2005-04-21 23:30:14 +0000 | [diff] [blame] | 908 | |
Nate Begeman | 030514c | 2006-04-11 19:29:21 +0000 | [diff] [blame] | 909 | // Get alignment info so we know how to restore r1 |
| 910 | const MachineFrameInfo *MFI = MF.getFrameInfo(); |
| 911 | unsigned TargetAlign = MF.getTarget().getFrameInfo()->getStackAlignment(); |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 912 | unsigned MaxAlign = MFI->getMaxAlignment(); |
Nate Begeman | 030514c | 2006-04-11 19:29:21 +0000 | [diff] [blame] | 913 | |
Chris Lattner | 64da172 | 2006-01-11 23:03:54 +0000 | [diff] [blame] | 914 | // Get the number of bytes allocated from the FrameInfo. |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 915 | unsigned FrameSize = MFI->getStackSize(); |
Misha Brukman | f2ccb77 | 2004-08-17 04:55:41 +0000 | [diff] [blame] | 916 | |
Jim Laskey | 51fe9d9 | 2006-12-06 17:42:06 +0000 | [diff] [blame] | 917 | if (!FrameSize) return; |
| 918 | |
| 919 | // Get processor type. |
| 920 | bool IsPPC64 = Subtarget.isPPC64(); |
| 921 | // Check if the link register (LR) has been used. |
| 922 | bool UsesLR = MFI->hasCalls() || usesLR(MF); |
| 923 | // Do we have a frame pointer for this function? |
| 924 | bool HasFP = hasFP(MF); |
| 925 | |
| 926 | // The loaded (or persistent) stack pointer value is offset by the 'stwu' |
| 927 | // on entry to the function. Add this offset back now. |
| 928 | if (!Subtarget.isPPC64()) { |
| 929 | if (isInt16(FrameSize) && TargetAlign >= MaxAlign && |
| 930 | !MFI->hasVarSizedObjects()) { |
| 931 | BuildMI(MBB, MBBI, TII.get(PPC::ADDI), PPC::R1) |
| 932 | .addReg(PPC::R1).addImm(FrameSize); |
Chris Lattner | 64da172 | 2006-01-11 23:03:54 +0000 | [diff] [blame] | 933 | } else { |
Jim Laskey | 51fe9d9 | 2006-12-06 17:42:06 +0000 | [diff] [blame] | 934 | BuildMI(MBB, MBBI, TII.get(PPC::LWZ),PPC::R1).addImm(0).addReg(PPC::R1); |
Chris Lattner | 64da172 | 2006-01-11 23:03:54 +0000 | [diff] [blame] | 935 | } |
Jim Laskey | 51fe9d9 | 2006-12-06 17:42:06 +0000 | [diff] [blame] | 936 | } else { |
| 937 | if (isInt16(FrameSize) && TargetAlign >= MaxAlign && |
| 938 | !MFI->hasVarSizedObjects()) { |
| 939 | BuildMI(MBB, MBBI, TII.get(PPC::ADDI8), PPC::X1) |
| 940 | .addReg(PPC::X1).addImm(FrameSize); |
| 941 | } else { |
| 942 | BuildMI(MBB, MBBI, TII.get(PPC::LD), PPC::X1).addImm(0).addReg(PPC::X1); |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 943 | } |
Jim Laskey | 51fe9d9 | 2006-12-06 17:42:06 +0000 | [diff] [blame] | 944 | } |
| 945 | |
| 946 | int LROffset = PPCFrameInfo::getReturnSaveOffset(IsPPC64); |
| 947 | int FPOffset = PPCFrameInfo::getFramePointerSaveOffset(IsPPC64); |
| 948 | |
| 949 | if (IsPPC64) { |
| 950 | if (UsesLR) |
| 951 | BuildMI(MBB, MBBI, TII.get(PPC::LD), PPC::X0) |
| 952 | .addImm(LROffset/4).addReg(PPC::X1); |
| 953 | |
| 954 | if (HasFP) |
| 955 | BuildMI(MBB, MBBI, TII.get(PPC::LD), PPC::X31) |
| 956 | .addImm(FPOffset/4).addReg(PPC::X1); |
| 957 | |
| 958 | if (UsesLR) |
| 959 | BuildMI(MBB, MBBI, TII.get(PPC::MTLR8)).addReg(PPC::X0); |
| 960 | } else { |
| 961 | if (UsesLR) |
| 962 | BuildMI(MBB, MBBI, TII.get(PPC::LWZ), PPC::R0) |
| 963 | .addImm(LROffset).addReg(PPC::R1); |
| 964 | |
| 965 | if (HasFP) |
| 966 | BuildMI(MBB, MBBI, TII.get(PPC::LWZ), PPC::R31) |
| 967 | .addImm(FPOffset).addReg(PPC::R1); |
| 968 | |
| 969 | if (UsesLR) |
| 970 | BuildMI(MBB, MBBI, TII.get(PPC::MTLR)).addReg(PPC::R0); |
Misha Brukman | f2ccb77 | 2004-08-17 04:55:41 +0000 | [diff] [blame] | 971 | } |
| 972 | } |
| 973 | |
Jim Laskey | 4188699 | 2006-04-07 16:34:46 +0000 | [diff] [blame] | 974 | unsigned PPCRegisterInfo::getRARegister() const { |
Chris Lattner | 6a5339b | 2006-11-14 18:44:47 +0000 | [diff] [blame] | 975 | return !Subtarget.isPPC64() ? PPC::LR : PPC::LR8; |
| 976 | |
Jim Laskey | 4188699 | 2006-04-07 16:34:46 +0000 | [diff] [blame] | 977 | } |
| 978 | |
Jim Laskey | a997918 | 2006-03-28 13:48:33 +0000 | [diff] [blame] | 979 | unsigned PPCRegisterInfo::getFrameRegister(MachineFunction &MF) const { |
Chris Lattner | a94a203 | 2006-11-11 19:05:28 +0000 | [diff] [blame] | 980 | if (!Subtarget.isPPC64()) |
| 981 | return hasFP(MF) ? PPC::R31 : PPC::R1; |
| 982 | else |
| 983 | return hasFP(MF) ? PPC::X31 : PPC::X1; |
Jim Laskey | 4188699 | 2006-04-07 16:34:46 +0000 | [diff] [blame] | 984 | } |
| 985 | |
| 986 | void PPCRegisterInfo::getInitialFrameState(std::vector<MachineMove *> &Moves) |
| 987 | const { |
Jim Laskey | 4c2c903 | 2006-08-25 19:40:59 +0000 | [diff] [blame] | 988 | // Initial state of the frame pointer is R1. |
Jim Laskey | 4188699 | 2006-04-07 16:34:46 +0000 | [diff] [blame] | 989 | MachineLocation Dst(MachineLocation::VirtualFP); |
| 990 | MachineLocation Src(PPC::R1, 0); |
| 991 | Moves.push_back(new MachineMove(0, Dst, Src)); |
Jim Laskey | f1d78e8 | 2006-03-23 18:12:57 +0000 | [diff] [blame] | 992 | } |
| 993 | |
Chris Lattner | 4c7b43b | 2005-10-14 23:37:35 +0000 | [diff] [blame] | 994 | #include "PPCGenRegisterInfo.inc" |
Misha Brukman | f2ccb77 | 2004-08-17 04:55:41 +0000 | [diff] [blame] | 995 | |