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 | // |
Chris Lattner | 4ee451d | 2007-12-29 20:36:04 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // 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 | // |
Dan Gohman | 6f0d024 | 2008-02-10 18:45:23 +0000 | [diff] [blame] | 10 | // This file contains the PowerPC implementation of the TargetRegisterInfo |
| 11 | // class. |
Misha Brukman | f2ccb77 | 2004-08-17 04:55:41 +0000 | [diff] [blame] | 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #define DEBUG_TYPE "reginfo" |
Chris Lattner | 2668959 | 2005-10-14 23:51:18 +0000 | [diff] [blame] | 16 | #include "PPC.h" |
Chris Lattner | 26bd0d4 | 2005-10-14 23:45:43 +0000 | [diff] [blame] | 17 | #include "PPCInstrBuilder.h" |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 18 | #include "PPCMachineFunctionInfo.h" |
Chris Lattner | 16e71f2 | 2005-10-14 23:59:06 +0000 | [diff] [blame] | 19 | #include "PPCRegisterInfo.h" |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 20 | #include "PPCFrameInfo.h" |
Chris Lattner | 804e067 | 2006-07-11 00:48:23 +0000 | [diff] [blame] | 21 | #include "PPCSubtarget.h" |
Misha Brukman | f2ccb77 | 2004-08-17 04:55:41 +0000 | [diff] [blame] | 22 | #include "llvm/Constants.h" |
Dale Johannesen | 1532f3d | 2008-04-02 00:25:04 +0000 | [diff] [blame] | 23 | #include "llvm/Function.h" |
Misha Brukman | f2ccb77 | 2004-08-17 04:55:41 +0000 | [diff] [blame] | 24 | #include "llvm/Type.h" |
| 25 | #include "llvm/CodeGen/ValueTypes.h" |
| 26 | #include "llvm/CodeGen/MachineInstrBuilder.h" |
Jim Laskey | 44c3b9f | 2007-01-26 21:22:28 +0000 | [diff] [blame] | 27 | #include "llvm/CodeGen/MachineModuleInfo.h" |
Misha Brukman | f2ccb77 | 2004-08-17 04:55:41 +0000 | [diff] [blame] | 28 | #include "llvm/CodeGen/MachineFunction.h" |
| 29 | #include "llvm/CodeGen/MachineFrameInfo.h" |
Jim Laskey | f1d78e8 | 2006-03-23 18:12:57 +0000 | [diff] [blame] | 30 | #include "llvm/CodeGen/MachineLocation.h" |
Chris Lattner | 84bc542 | 2007-12-31 04:13:23 +0000 | [diff] [blame] | 31 | #include "llvm/CodeGen/MachineRegisterInfo.h" |
Bill Wendling | 7194aaf | 2008-03-03 22:19:16 +0000 | [diff] [blame] | 32 | #include "llvm/CodeGen/RegisterScavenging.h" |
Jim Laskey | 4188699 | 2006-04-07 16:34:46 +0000 | [diff] [blame] | 33 | #include "llvm/CodeGen/SelectionDAGNodes.h" |
Misha Brukman | f2ccb77 | 2004-08-17 04:55:41 +0000 | [diff] [blame] | 34 | #include "llvm/Target/TargetFrameInfo.h" |
Chris Lattner | f9568d8 | 2006-04-17 21:48:13 +0000 | [diff] [blame] | 35 | #include "llvm/Target/TargetInstrInfo.h" |
Misha Brukman | f2ccb77 | 2004-08-17 04:55:41 +0000 | [diff] [blame] | 36 | #include "llvm/Target/TargetMachine.h" |
| 37 | #include "llvm/Target/TargetOptions.h" |
Reid Spencer | 551ccae | 2004-09-01 22:55:40 +0000 | [diff] [blame] | 38 | #include "llvm/Support/CommandLine.h" |
| 39 | #include "llvm/Support/Debug.h" |
Nate Begeman | ae232e7 | 2005-11-06 09:00:38 +0000 | [diff] [blame] | 40 | #include "llvm/Support/MathExtras.h" |
Evan Cheng | b371f45 | 2007-02-19 21:49:54 +0000 | [diff] [blame] | 41 | #include "llvm/ADT/BitVector.h" |
Reid Spencer | 551ccae | 2004-09-01 22:55:40 +0000 | [diff] [blame] | 42 | #include "llvm/ADT/STLExtras.h" |
Misha Brukman | f2ccb77 | 2004-08-17 04:55:41 +0000 | [diff] [blame] | 43 | #include <cstdlib> |
Misha Brukman | f2ccb77 | 2004-08-17 04:55:41 +0000 | [diff] [blame] | 44 | using namespace llvm; |
| 45 | |
Dale Johannesen | 82e4289 | 2008-03-10 22:59:46 +0000 | [diff] [blame] | 46 | // FIXME This disables some code that aligns the stack to a boundary |
| 47 | // bigger than the default (16 bytes on Darwin) when there is a stack local |
| 48 | // of greater alignment. This does not currently work, because the delta |
| 49 | // between old and new stack pointers is added to offsets that reference |
| 50 | // incoming parameters after the prolog is generated, and the code that |
| 51 | // does that doesn't handle a variable delta. You don't want to do that |
| 52 | // anyway; a better approach is to reserve another register that retains |
| 53 | // to the incoming stack pointer, and reference parameters relative to that. |
| 54 | #define ALIGN_STACK 0 |
| 55 | |
Bill Wendling | 880d0f6 | 2008-03-04 23:13:51 +0000 | [diff] [blame] | 56 | // FIXME (64-bit): Eventually enable by default. |
Bill Wendling | 4a66e9a | 2008-03-10 22:49:16 +0000 | [diff] [blame] | 57 | cl::opt<bool> EnablePPC32RS("enable-ppc32-regscavenger", |
| 58 | cl::init(false), |
| 59 | cl::desc("Enable PPC32 register scavenger"), |
| 60 | cl::Hidden); |
| 61 | cl::opt<bool> EnablePPC64RS("enable-ppc64-regscavenger", |
| 62 | cl::init(false), |
| 63 | cl::desc("Enable PPC64 register scavenger"), |
| 64 | cl::Hidden); |
| 65 | #define EnableRegisterScavenging \ |
| 66 | ((EnablePPC32RS && !Subtarget.isPPC64()) || \ |
| 67 | (EnablePPC64RS && Subtarget.isPPC64())) |
Bill Wendling | 880d0f6 | 2008-03-04 23:13:51 +0000 | [diff] [blame] | 68 | |
Bill Wendling | 7194aaf | 2008-03-03 22:19:16 +0000 | [diff] [blame] | 69 | // FIXME (64-bit): Should be inlined. |
| 70 | bool |
| 71 | PPCRegisterInfo::requiresRegisterScavenging(const MachineFunction &) const { |
Bill Wendling | 4a66e9a | 2008-03-10 22:49:16 +0000 | [diff] [blame] | 72 | return EnableRegisterScavenging; |
Bill Wendling | 7194aaf | 2008-03-03 22:19:16 +0000 | [diff] [blame] | 73 | } |
| 74 | |
Chris Lattner | 369503f | 2006-04-17 21:07:20 +0000 | [diff] [blame] | 75 | /// getRegisterNumbering - Given the enum value for some register, e.g. |
| 76 | /// PPC::F14, return the number that it corresponds to (e.g. 14). |
| 77 | unsigned PPCRegisterInfo::getRegisterNumbering(unsigned RegEnum) { |
Chris Lattner | be6a039 | 2006-07-11 20:53:55 +0000 | [diff] [blame] | 78 | using namespace PPC; |
Chris Lattner | 369503f | 2006-04-17 21:07:20 +0000 | [diff] [blame] | 79 | switch (RegEnum) { |
Chris Lattner | a1998d1 | 2008-02-13 17:24:14 +0000 | [diff] [blame] | 80 | case 0: return 0; |
Nicolas Geoffray | 0404cd9 | 2008-03-10 14:12:10 +0000 | [diff] [blame] | 81 | case R0 : case X0 : case F0 : case V0 : case CR0: case CR0LT: return 0; |
| 82 | case R1 : case X1 : case F1 : case V1 : case CR1: case CR0GT: return 1; |
| 83 | case R2 : case X2 : case F2 : case V2 : case CR2: case CR0EQ: return 2; |
| 84 | case R3 : case X3 : case F3 : case V3 : case CR3: case CR0UN: return 3; |
| 85 | case R4 : case X4 : case F4 : case V4 : case CR4: case CR1LT: return 4; |
| 86 | case R5 : case X5 : case F5 : case V5 : case CR5: case CR1GT: return 5; |
| 87 | case R6 : case X6 : case F6 : case V6 : case CR6: case CR1EQ: return 6; |
| 88 | case R7 : case X7 : case F7 : case V7 : case CR7: case CR1UN: return 7; |
| 89 | case R8 : case X8 : case F8 : case V8 : case CR2LT: return 8; |
| 90 | case R9 : case X9 : case F9 : case V9 : case CR2GT: return 9; |
| 91 | case R10: case X10: case F10: case V10: case CR2EQ: return 10; |
| 92 | case R11: case X11: case F11: case V11: case CR2UN: return 11; |
| 93 | case R12: case X12: case F12: case V12: case CR3LT: return 12; |
| 94 | case R13: case X13: case F13: case V13: case CR3GT: return 13; |
| 95 | case R14: case X14: case F14: case V14: case CR3EQ: return 14; |
| 96 | case R15: case X15: case F15: case V15: case CR3UN: return 15; |
| 97 | case R16: case X16: case F16: case V16: case CR4LT: return 16; |
| 98 | case R17: case X17: case F17: case V17: case CR4GT: return 17; |
| 99 | case R18: case X18: case F18: case V18: case CR4EQ: return 18; |
| 100 | case R19: case X19: case F19: case V19: case CR4UN: return 19; |
| 101 | case R20: case X20: case F20: case V20: case CR5LT: return 20; |
| 102 | case R21: case X21: case F21: case V21: case CR5GT: return 21; |
| 103 | case R22: case X22: case F22: case V22: case CR5EQ: return 22; |
| 104 | case R23: case X23: case F23: case V23: case CR5UN: return 23; |
| 105 | case R24: case X24: case F24: case V24: case CR6LT: return 24; |
| 106 | case R25: case X25: case F25: case V25: case CR6GT: return 25; |
| 107 | case R26: case X26: case F26: case V26: case CR6EQ: return 26; |
| 108 | case R27: case X27: case F27: case V27: case CR6UN: return 27; |
| 109 | case R28: case X28: case F28: case V28: case CR7LT: return 28; |
| 110 | case R29: case X29: case F29: case V29: case CR7GT: return 29; |
| 111 | case R30: case X30: case F30: case V30: case CR7EQ: return 30; |
| 112 | case R31: case X31: case F31: case V31: case CR7UN: return 31; |
Chris Lattner | be6a039 | 2006-07-11 20:53:55 +0000 | [diff] [blame] | 113 | default: |
Bill Wendling | f5da133 | 2006-12-07 22:21:48 +0000 | [diff] [blame] | 114 | cerr << "Unhandled reg in PPCRegisterInfo::getRegisterNumbering!\n"; |
Chris Lattner | be6a039 | 2006-07-11 20:53:55 +0000 | [diff] [blame] | 115 | abort(); |
Chris Lattner | 369503f | 2006-04-17 21:07:20 +0000 | [diff] [blame] | 116 | } |
| 117 | } |
| 118 | |
Evan Cheng | 7ce4578 | 2006-11-13 23:36:35 +0000 | [diff] [blame] | 119 | PPCRegisterInfo::PPCRegisterInfo(const PPCSubtarget &ST, |
| 120 | const TargetInstrInfo &tii) |
Chris Lattner | 804e067 | 2006-07-11 00:48:23 +0000 | [diff] [blame] | 121 | : PPCGenRegisterInfo(PPC::ADJCALLSTACKDOWN, PPC::ADJCALLSTACKUP), |
Evan Cheng | 7ce4578 | 2006-11-13 23:36:35 +0000 | [diff] [blame] | 122 | Subtarget(ST), TII(tii) { |
Misha Brukman | b5f662f | 2005-04-21 23:30:14 +0000 | [diff] [blame] | 123 | ImmToIdxMap[PPC::LD] = PPC::LDX; ImmToIdxMap[PPC::STD] = PPC::STDX; |
Misha Brukman | f2ccb77 | 2004-08-17 04:55:41 +0000 | [diff] [blame] | 124 | ImmToIdxMap[PPC::LBZ] = PPC::LBZX; ImmToIdxMap[PPC::STB] = PPC::STBX; |
| 125 | ImmToIdxMap[PPC::LHZ] = PPC::LHZX; ImmToIdxMap[PPC::LHA] = PPC::LHAX; |
| 126 | ImmToIdxMap[PPC::LWZ] = PPC::LWZX; ImmToIdxMap[PPC::LWA] = PPC::LWAX; |
| 127 | ImmToIdxMap[PPC::LFS] = PPC::LFSX; ImmToIdxMap[PPC::LFD] = PPC::LFDX; |
| 128 | ImmToIdxMap[PPC::STH] = PPC::STHX; ImmToIdxMap[PPC::STW] = PPC::STWX; |
| 129 | ImmToIdxMap[PPC::STFS] = PPC::STFSX; ImmToIdxMap[PPC::STFD] = PPC::STFDX; |
Nate Begeman | 1d9d742 | 2005-10-18 00:28:58 +0000 | [diff] [blame] | 130 | ImmToIdxMap[PPC::ADDI] = PPC::ADD4; |
Bill Wendling | 82d2514 | 2007-09-07 22:01:02 +0000 | [diff] [blame] | 131 | |
| 132 | // 64-bit |
| 133 | ImmToIdxMap[PPC::LHA8] = PPC::LHAX8; ImmToIdxMap[PPC::LBZ8] = PPC::LBZX8; |
| 134 | ImmToIdxMap[PPC::LHZ8] = PPC::LHZX8; ImmToIdxMap[PPC::LWZ8] = PPC::LWZX8; |
| 135 | ImmToIdxMap[PPC::STB8] = PPC::STBX8; ImmToIdxMap[PPC::STH8] = PPC::STHX8; |
| 136 | ImmToIdxMap[PPC::STW8] = PPC::STWX8; ImmToIdxMap[PPC::STDU] = PPC::STDUX; |
| 137 | ImmToIdxMap[PPC::ADDI8] = PPC::ADD8; ImmToIdxMap[PPC::STD_32] = PPC::STDX_32; |
Misha Brukman | f2ccb77 | 2004-08-17 04:55:41 +0000 | [diff] [blame] | 138 | } |
| 139 | |
Evan Cheng | 64d80e3 | 2007-07-19 01:14:50 +0000 | [diff] [blame] | 140 | const unsigned* |
| 141 | PPCRegisterInfo::getCalleeSavedRegs(const MachineFunction *MF) const { |
Chris Lattner | 804e067 | 2006-07-11 00:48:23 +0000 | [diff] [blame] | 142 | // 32-bit Darwin calling convention. |
Nicolas Geoffray | ec58d9f | 2007-04-03 12:35:28 +0000 | [diff] [blame] | 143 | static const unsigned Macho32_CalleeSavedRegs[] = { |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 144 | PPC::R13, PPC::R14, PPC::R15, |
Chris Lattner | 804e067 | 2006-07-11 00:48:23 +0000 | [diff] [blame] | 145 | PPC::R16, PPC::R17, PPC::R18, PPC::R19, |
| 146 | PPC::R20, PPC::R21, PPC::R22, PPC::R23, |
| 147 | PPC::R24, PPC::R25, PPC::R26, PPC::R27, |
| 148 | PPC::R28, PPC::R29, PPC::R30, PPC::R31, |
| 149 | |
| 150 | PPC::F14, PPC::F15, PPC::F16, PPC::F17, |
| 151 | PPC::F18, PPC::F19, PPC::F20, PPC::F21, |
| 152 | PPC::F22, PPC::F23, PPC::F24, PPC::F25, |
| 153 | PPC::F26, PPC::F27, PPC::F28, PPC::F29, |
Evan Cheng | 0f3ac8d | 2006-05-18 00:12:58 +0000 | [diff] [blame] | 154 | PPC::F30, PPC::F31, |
Chris Lattner | 804e067 | 2006-07-11 00:48:23 +0000 | [diff] [blame] | 155 | |
| 156 | PPC::CR2, PPC::CR3, PPC::CR4, |
| 157 | PPC::V20, PPC::V21, PPC::V22, PPC::V23, |
| 158 | PPC::V24, PPC::V25, PPC::V26, PPC::V27, |
| 159 | PPC::V28, PPC::V29, PPC::V30, PPC::V31, |
| 160 | |
Nicolas Geoffray | 0404cd9 | 2008-03-10 14:12:10 +0000 | [diff] [blame] | 161 | PPC::CR2LT, PPC::CR2GT, PPC::CR2EQ, PPC::CR2UN, |
| 162 | PPC::CR3LT, PPC::CR3GT, PPC::CR3EQ, PPC::CR3UN, |
| 163 | PPC::CR4LT, PPC::CR4GT, PPC::CR4EQ, PPC::CR4UN, |
| 164 | |
Chris Lattner | 804e067 | 2006-07-11 00:48:23 +0000 | [diff] [blame] | 165 | PPC::LR, 0 |
Evan Cheng | 0f3ac8d | 2006-05-18 00:12:58 +0000 | [diff] [blame] | 166 | }; |
Chris Lattner | 9f0bc65 | 2007-02-25 05:34:32 +0000 | [diff] [blame] | 167 | |
| 168 | static const unsigned ELF32_CalleeSavedRegs[] = { |
| 169 | PPC::R13, PPC::R14, PPC::R15, |
| 170 | PPC::R16, PPC::R17, PPC::R18, PPC::R19, |
| 171 | PPC::R20, PPC::R21, PPC::R22, PPC::R23, |
| 172 | PPC::R24, PPC::R25, PPC::R26, PPC::R27, |
| 173 | PPC::R28, PPC::R29, PPC::R30, PPC::R31, |
| 174 | |
Nicolas Geoffray | ef3c030 | 2007-04-03 10:27:07 +0000 | [diff] [blame] | 175 | PPC::F9, |
| 176 | PPC::F10, PPC::F11, PPC::F12, PPC::F13, |
Chris Lattner | 9f0bc65 | 2007-02-25 05:34:32 +0000 | [diff] [blame] | 177 | PPC::F14, PPC::F15, PPC::F16, PPC::F17, |
| 178 | PPC::F18, PPC::F19, PPC::F20, PPC::F21, |
| 179 | PPC::F22, PPC::F23, PPC::F24, PPC::F25, |
| 180 | PPC::F26, PPC::F27, PPC::F28, PPC::F29, |
| 181 | PPC::F30, PPC::F31, |
| 182 | |
| 183 | PPC::CR2, PPC::CR3, PPC::CR4, |
| 184 | PPC::V20, PPC::V21, PPC::V22, PPC::V23, |
| 185 | PPC::V24, PPC::V25, PPC::V26, PPC::V27, |
| 186 | PPC::V28, PPC::V29, PPC::V30, PPC::V31, |
| 187 | |
Nicolas Geoffray | 0404cd9 | 2008-03-10 14:12:10 +0000 | [diff] [blame] | 188 | PPC::CR2LT, PPC::CR2GT, PPC::CR2EQ, PPC::CR2UN, |
| 189 | PPC::CR3LT, PPC::CR3GT, PPC::CR3EQ, PPC::CR3UN, |
| 190 | PPC::CR4LT, PPC::CR4GT, PPC::CR4EQ, PPC::CR4UN, |
| 191 | |
Chris Lattner | 9f0bc65 | 2007-02-25 05:34:32 +0000 | [diff] [blame] | 192 | PPC::LR, 0 |
| 193 | }; |
Chris Lattner | 804e067 | 2006-07-11 00:48:23 +0000 | [diff] [blame] | 194 | // 64-bit Darwin calling convention. |
Nicolas Geoffray | ec58d9f | 2007-04-03 12:35:28 +0000 | [diff] [blame] | 195 | static const unsigned Macho64_CalleeSavedRegs[] = { |
Chris Lattner | bdc571b | 2006-11-20 19:33:51 +0000 | [diff] [blame] | 196 | PPC::X14, PPC::X15, |
Chris Lattner | 804e067 | 2006-07-11 00:48:23 +0000 | [diff] [blame] | 197 | PPC::X16, PPC::X17, PPC::X18, PPC::X19, |
| 198 | PPC::X20, PPC::X21, PPC::X22, PPC::X23, |
| 199 | PPC::X24, PPC::X25, PPC::X26, PPC::X27, |
| 200 | PPC::X28, PPC::X29, PPC::X30, PPC::X31, |
| 201 | |
| 202 | PPC::F14, PPC::F15, PPC::F16, PPC::F17, |
| 203 | PPC::F18, PPC::F19, PPC::F20, PPC::F21, |
| 204 | PPC::F22, PPC::F23, PPC::F24, PPC::F25, |
| 205 | PPC::F26, PPC::F27, PPC::F28, PPC::F29, |
| 206 | PPC::F30, PPC::F31, |
| 207 | |
| 208 | PPC::CR2, PPC::CR3, PPC::CR4, |
| 209 | PPC::V20, PPC::V21, PPC::V22, PPC::V23, |
| 210 | PPC::V24, PPC::V25, PPC::V26, PPC::V27, |
| 211 | PPC::V28, PPC::V29, PPC::V30, PPC::V31, |
| 212 | |
Nicolas Geoffray | 0404cd9 | 2008-03-10 14:12:10 +0000 | [diff] [blame] | 213 | PPC::CR2LT, PPC::CR2GT, PPC::CR2EQ, PPC::CR2UN, |
| 214 | PPC::CR3LT, PPC::CR3GT, PPC::CR3EQ, PPC::CR3UN, |
| 215 | PPC::CR4LT, PPC::CR4GT, PPC::CR4EQ, PPC::CR4UN, |
| 216 | |
Chris Lattner | 6a5339b | 2006-11-14 18:44:47 +0000 | [diff] [blame] | 217 | PPC::LR8, 0 |
Chris Lattner | 804e067 | 2006-07-11 00:48:23 +0000 | [diff] [blame] | 218 | }; |
| 219 | |
Chris Lattner | 9f0bc65 | 2007-02-25 05:34:32 +0000 | [diff] [blame] | 220 | if (Subtarget.isMachoABI()) |
Nicolas Geoffray | ec58d9f | 2007-04-03 12:35:28 +0000 | [diff] [blame] | 221 | return Subtarget.isPPC64() ? Macho64_CalleeSavedRegs : |
| 222 | Macho32_CalleeSavedRegs; |
Chris Lattner | 9f0bc65 | 2007-02-25 05:34:32 +0000 | [diff] [blame] | 223 | |
Nicolas Geoffray | ec58d9f | 2007-04-03 12:35:28 +0000 | [diff] [blame] | 224 | // ELF 32. |
| 225 | return ELF32_CalleeSavedRegs; |
Evan Cheng | 0f3ac8d | 2006-05-18 00:12:58 +0000 | [diff] [blame] | 226 | } |
| 227 | |
| 228 | const TargetRegisterClass* const* |
Anton Korobeynikov | 2365f51 | 2007-07-14 14:06:15 +0000 | [diff] [blame] | 229 | PPCRegisterInfo::getCalleeSavedRegClasses(const MachineFunction *MF) const { |
Nicolas Geoffray | ec58d9f | 2007-04-03 12:35:28 +0000 | [diff] [blame] | 230 | // 32-bit Macho calling convention. |
| 231 | static const TargetRegisterClass * const Macho32_CalleeSavedRegClasses[] = { |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 232 | &PPC::GPRCRegClass,&PPC::GPRCRegClass,&PPC::GPRCRegClass, |
Chris Lattner | 804e067 | 2006-07-11 00:48:23 +0000 | [diff] [blame] | 233 | &PPC::GPRCRegClass,&PPC::GPRCRegClass,&PPC::GPRCRegClass,&PPC::GPRCRegClass, |
| 234 | &PPC::GPRCRegClass,&PPC::GPRCRegClass,&PPC::GPRCRegClass,&PPC::GPRCRegClass, |
| 235 | &PPC::GPRCRegClass,&PPC::GPRCRegClass,&PPC::GPRCRegClass,&PPC::GPRCRegClass, |
| 236 | &PPC::GPRCRegClass,&PPC::GPRCRegClass,&PPC::GPRCRegClass,&PPC::GPRCRegClass, |
| 237 | |
| 238 | &PPC::F8RCRegClass,&PPC::F8RCRegClass,&PPC::F8RCRegClass,&PPC::F8RCRegClass, |
| 239 | &PPC::F8RCRegClass,&PPC::F8RCRegClass,&PPC::F8RCRegClass,&PPC::F8RCRegClass, |
| 240 | &PPC::F8RCRegClass,&PPC::F8RCRegClass,&PPC::F8RCRegClass,&PPC::F8RCRegClass, |
| 241 | &PPC::F8RCRegClass,&PPC::F8RCRegClass,&PPC::F8RCRegClass,&PPC::F8RCRegClass, |
| 242 | &PPC::F8RCRegClass,&PPC::F8RCRegClass, |
| 243 | |
| 244 | &PPC::CRRCRegClass,&PPC::CRRCRegClass,&PPC::CRRCRegClass, |
| 245 | |
| 246 | &PPC::VRRCRegClass,&PPC::VRRCRegClass,&PPC::VRRCRegClass,&PPC::VRRCRegClass, |
| 247 | &PPC::VRRCRegClass,&PPC::VRRCRegClass,&PPC::VRRCRegClass,&PPC::VRRCRegClass, |
| 248 | &PPC::VRRCRegClass,&PPC::VRRCRegClass,&PPC::VRRCRegClass,&PPC::VRRCRegClass, |
| 249 | |
Nicolas Geoffray | 0404cd9 | 2008-03-10 14:12:10 +0000 | [diff] [blame] | 250 | &PPC::CRBITRCRegClass,&PPC::CRBITRCRegClass,&PPC::CRBITRCRegClass, |
| 251 | &PPC::CRBITRCRegClass, |
| 252 | &PPC::CRBITRCRegClass,&PPC::CRBITRCRegClass,&PPC::CRBITRCRegClass, |
| 253 | &PPC::CRBITRCRegClass, |
| 254 | &PPC::CRBITRCRegClass,&PPC::CRBITRCRegClass,&PPC::CRBITRCRegClass, |
| 255 | &PPC::CRBITRCRegClass, |
| 256 | |
Chris Lattner | 804e067 | 2006-07-11 00:48:23 +0000 | [diff] [blame] | 257 | &PPC::GPRCRegClass, 0 |
Evan Cheng | 0f3ac8d | 2006-05-18 00:12:58 +0000 | [diff] [blame] | 258 | }; |
Chris Lattner | 804e067 | 2006-07-11 00:48:23 +0000 | [diff] [blame] | 259 | |
Chris Lattner | 9f0bc65 | 2007-02-25 05:34:32 +0000 | [diff] [blame] | 260 | static const TargetRegisterClass * const ELF32_CalleeSavedRegClasses[] = { |
| 261 | &PPC::GPRCRegClass,&PPC::GPRCRegClass,&PPC::GPRCRegClass, |
| 262 | &PPC::GPRCRegClass,&PPC::GPRCRegClass,&PPC::GPRCRegClass,&PPC::GPRCRegClass, |
| 263 | &PPC::GPRCRegClass,&PPC::GPRCRegClass,&PPC::GPRCRegClass,&PPC::GPRCRegClass, |
| 264 | &PPC::GPRCRegClass,&PPC::GPRCRegClass,&PPC::GPRCRegClass,&PPC::GPRCRegClass, |
| 265 | &PPC::GPRCRegClass,&PPC::GPRCRegClass,&PPC::GPRCRegClass,&PPC::GPRCRegClass, |
| 266 | |
Nicolas Geoffray | cfcd8da | 2007-04-03 10:57:49 +0000 | [diff] [blame] | 267 | &PPC::F8RCRegClass, |
| 268 | &PPC::F8RCRegClass,&PPC::F8RCRegClass,&PPC::F8RCRegClass,&PPC::F8RCRegClass, |
Chris Lattner | 9f0bc65 | 2007-02-25 05:34:32 +0000 | [diff] [blame] | 269 | &PPC::F8RCRegClass,&PPC::F8RCRegClass,&PPC::F8RCRegClass,&PPC::F8RCRegClass, |
| 270 | &PPC::F8RCRegClass,&PPC::F8RCRegClass,&PPC::F8RCRegClass,&PPC::F8RCRegClass, |
| 271 | &PPC::F8RCRegClass,&PPC::F8RCRegClass,&PPC::F8RCRegClass,&PPC::F8RCRegClass, |
| 272 | &PPC::F8RCRegClass,&PPC::F8RCRegClass,&PPC::F8RCRegClass,&PPC::F8RCRegClass, |
| 273 | &PPC::F8RCRegClass,&PPC::F8RCRegClass, |
| 274 | |
| 275 | &PPC::CRRCRegClass,&PPC::CRRCRegClass,&PPC::CRRCRegClass, |
| 276 | |
| 277 | &PPC::VRRCRegClass,&PPC::VRRCRegClass,&PPC::VRRCRegClass,&PPC::VRRCRegClass, |
| 278 | &PPC::VRRCRegClass,&PPC::VRRCRegClass,&PPC::VRRCRegClass,&PPC::VRRCRegClass, |
| 279 | &PPC::VRRCRegClass,&PPC::VRRCRegClass,&PPC::VRRCRegClass,&PPC::VRRCRegClass, |
| 280 | |
Nicolas Geoffray | 0404cd9 | 2008-03-10 14:12:10 +0000 | [diff] [blame] | 281 | &PPC::CRBITRCRegClass,&PPC::CRBITRCRegClass,&PPC::CRBITRCRegClass, |
| 282 | &PPC::CRBITRCRegClass, |
| 283 | &PPC::CRBITRCRegClass,&PPC::CRBITRCRegClass,&PPC::CRBITRCRegClass, |
| 284 | &PPC::CRBITRCRegClass, |
| 285 | &PPC::CRBITRCRegClass,&PPC::CRBITRCRegClass,&PPC::CRBITRCRegClass, |
| 286 | &PPC::CRBITRCRegClass, |
| 287 | |
Chris Lattner | 9f0bc65 | 2007-02-25 05:34:32 +0000 | [diff] [blame] | 288 | &PPC::GPRCRegClass, 0 |
| 289 | }; |
| 290 | |
Nicolas Geoffray | ec58d9f | 2007-04-03 12:35:28 +0000 | [diff] [blame] | 291 | // 64-bit Macho calling convention. |
| 292 | static const TargetRegisterClass * const Macho64_CalleeSavedRegClasses[] = { |
Chris Lattner | bdc571b | 2006-11-20 19:33:51 +0000 | [diff] [blame] | 293 | &PPC::G8RCRegClass,&PPC::G8RCRegClass, |
Chris Lattner | 804e067 | 2006-07-11 00:48:23 +0000 | [diff] [blame] | 294 | &PPC::G8RCRegClass,&PPC::G8RCRegClass,&PPC::G8RCRegClass,&PPC::G8RCRegClass, |
| 295 | &PPC::G8RCRegClass,&PPC::G8RCRegClass,&PPC::G8RCRegClass,&PPC::G8RCRegClass, |
| 296 | &PPC::G8RCRegClass,&PPC::G8RCRegClass,&PPC::G8RCRegClass,&PPC::G8RCRegClass, |
| 297 | &PPC::G8RCRegClass,&PPC::G8RCRegClass,&PPC::G8RCRegClass,&PPC::G8RCRegClass, |
| 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 | |
Nicolas Geoffray | 0404cd9 | 2008-03-10 14:12:10 +0000 | [diff] [blame] | 311 | &PPC::CRBITRCRegClass,&PPC::CRBITRCRegClass,&PPC::CRBITRCRegClass, |
| 312 | &PPC::CRBITRCRegClass, |
| 313 | &PPC::CRBITRCRegClass,&PPC::CRBITRCRegClass,&PPC::CRBITRCRegClass, |
| 314 | &PPC::CRBITRCRegClass, |
| 315 | &PPC::CRBITRCRegClass,&PPC::CRBITRCRegClass,&PPC::CRBITRCRegClass, |
| 316 | &PPC::CRBITRCRegClass, |
| 317 | |
Chris Lattner | 6a5339b | 2006-11-14 18:44:47 +0000 | [diff] [blame] | 318 | &PPC::G8RCRegClass, 0 |
Chris Lattner | 804e067 | 2006-07-11 00:48:23 +0000 | [diff] [blame] | 319 | }; |
Chris Lattner | 9f0bc65 | 2007-02-25 05:34:32 +0000 | [diff] [blame] | 320 | |
Chris Lattner | 9f0bc65 | 2007-02-25 05:34:32 +0000 | [diff] [blame] | 321 | if (Subtarget.isMachoABI()) |
Nicolas Geoffray | ec58d9f | 2007-04-03 12:35:28 +0000 | [diff] [blame] | 322 | return Subtarget.isPPC64() ? Macho64_CalleeSavedRegClasses : |
| 323 | Macho32_CalleeSavedRegClasses; |
Chris Lattner | 9f0bc65 | 2007-02-25 05:34:32 +0000 | [diff] [blame] | 324 | |
Nicolas Geoffray | ec58d9f | 2007-04-03 12:35:28 +0000 | [diff] [blame] | 325 | // ELF 32. |
| 326 | return ELF32_CalleeSavedRegClasses; |
Evan Cheng | 0f3ac8d | 2006-05-18 00:12:58 +0000 | [diff] [blame] | 327 | } |
| 328 | |
Evan Cheng | b371f45 | 2007-02-19 21:49:54 +0000 | [diff] [blame] | 329 | // needsFP - Return true if the specified function should have a dedicated frame |
| 330 | // pointer register. This is true if the function has variable sized allocas or |
| 331 | // if frame pointer elimination is disabled. |
| 332 | // |
| 333 | static bool needsFP(const MachineFunction &MF) { |
| 334 | const MachineFrameInfo *MFI = MF.getFrameInfo(); |
| 335 | return NoFramePointerElim || MFI->hasVarSizedObjects(); |
| 336 | } |
| 337 | |
Bill Wendling | 7194aaf | 2008-03-03 22:19:16 +0000 | [diff] [blame] | 338 | static bool spillsCR(const MachineFunction &MF) { |
| 339 | const PPCFunctionInfo *FuncInfo = MF.getInfo<PPCFunctionInfo>(); |
| 340 | return FuncInfo->isCRSpilled(); |
| 341 | } |
| 342 | |
Evan Cheng | b371f45 | 2007-02-19 21:49:54 +0000 | [diff] [blame] | 343 | BitVector PPCRegisterInfo::getReservedRegs(const MachineFunction &MF) const { |
| 344 | BitVector Reserved(getNumRegs()); |
| 345 | Reserved.set(PPC::R0); |
| 346 | Reserved.set(PPC::R1); |
| 347 | Reserved.set(PPC::LR); |
Bill Wendling | 7194aaf | 2008-03-03 22:19:16 +0000 | [diff] [blame] | 348 | Reserved.set(PPC::LR8); |
| 349 | |
Evan Cheng | b371f45 | 2007-02-19 21:49:54 +0000 | [diff] [blame] | 350 | // In Linux, r2 is reserved for the OS. |
| 351 | if (!Subtarget.isDarwin()) |
| 352 | Reserved.set(PPC::R2); |
Bill Wendling | 7194aaf | 2008-03-03 22:19:16 +0000 | [diff] [blame] | 353 | |
| 354 | // On PPC64, r13 is the thread pointer. Never allocate this register. Note |
| 355 | // that this is over conservative, as it also prevents allocation of R31 when |
| 356 | // the FP is not needed. |
Evan Cheng | b371f45 | 2007-02-19 21:49:54 +0000 | [diff] [blame] | 357 | if (Subtarget.isPPC64()) { |
| 358 | Reserved.set(PPC::R13); |
| 359 | Reserved.set(PPC::R31); |
Bill Wendling | 7194aaf | 2008-03-03 22:19:16 +0000 | [diff] [blame] | 360 | |
Bill Wendling | 4a66e9a | 2008-03-10 22:49:16 +0000 | [diff] [blame] | 361 | if (!EnableRegisterScavenging) |
Bill Wendling | 880d0f6 | 2008-03-04 23:13:51 +0000 | [diff] [blame] | 362 | Reserved.set(PPC::R0); // FIXME (64-bit): Remove |
Bill Wendling | 7194aaf | 2008-03-03 22:19:16 +0000 | [diff] [blame] | 363 | |
| 364 | Reserved.set(PPC::X0); |
| 365 | Reserved.set(PPC::X1); |
| 366 | Reserved.set(PPC::X13); |
| 367 | Reserved.set(PPC::X31); |
Evan Cheng | b371f45 | 2007-02-19 21:49:54 +0000 | [diff] [blame] | 368 | } |
Bill Wendling | 7194aaf | 2008-03-03 22:19:16 +0000 | [diff] [blame] | 369 | |
Evan Cheng | b371f45 | 2007-02-19 21:49:54 +0000 | [diff] [blame] | 370 | if (needsFP(MF)) |
| 371 | Reserved.set(PPC::R31); |
Bill Wendling | 7194aaf | 2008-03-03 22:19:16 +0000 | [diff] [blame] | 372 | |
Evan Cheng | b371f45 | 2007-02-19 21:49:54 +0000 | [diff] [blame] | 373 | return Reserved; |
| 374 | } |
| 375 | |
Misha Brukman | f2ccb77 | 2004-08-17 04:55:41 +0000 | [diff] [blame] | 376 | //===----------------------------------------------------------------------===// |
| 377 | // Stack Frame Processing methods |
| 378 | //===----------------------------------------------------------------------===// |
| 379 | |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 380 | // hasFP - Return true if the specified function actually has a dedicated frame |
| 381 | // pointer register. This is true if the function needs a frame pointer and has |
| 382 | // a non-zero stack size. |
Evan Cheng | dc77540 | 2007-01-23 00:57:47 +0000 | [diff] [blame] | 383 | bool PPCRegisterInfo::hasFP(const MachineFunction &MF) const { |
Chris Lattner | 4f91a4c | 2006-04-03 22:03:29 +0000 | [diff] [blame] | 384 | const MachineFrameInfo *MFI = MF.getFrameInfo(); |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 385 | return MFI->getStackSize() && needsFP(MF); |
Misha Brukman | f2ccb77 | 2004-08-17 04:55:41 +0000 | [diff] [blame] | 386 | } |
| 387 | |
Chris Lattner | 73944fb | 2007-12-08 06:39:11 +0000 | [diff] [blame] | 388 | /// MustSaveLR - Return true if this function requires that we save the LR |
Chris Lattner | 3fc027d | 2007-12-08 06:59:59 +0000 | [diff] [blame] | 389 | /// register onto the stack in the prolog and restore it in the epilog of the |
| 390 | /// function. |
Chris Lattner | 73944fb | 2007-12-08 06:39:11 +0000 | [diff] [blame] | 391 | static bool MustSaveLR(const MachineFunction &MF) { |
Chris Lattner | 3fc027d | 2007-12-08 06:59:59 +0000 | [diff] [blame] | 392 | const PPCFunctionInfo *MFI = MF.getInfo<PPCFunctionInfo>(); |
| 393 | |
| 394 | // We need an save/restore of LR if there is any use/def of LR explicitly, or |
| 395 | // if there is some use of the LR stack slot (e.g. for builtin_return_address. |
| 396 | return MFI->usesLR() || MFI->isLRStoreRequired() || |
Chris Lattner | 73944fb | 2007-12-08 06:39:11 +0000 | [diff] [blame] | 397 | // FIXME: Anything that has a call should clobber the LR register, |
| 398 | // isn't this redundant?? |
| 399 | MF.getFrameInfo()->hasCalls(); |
Jim Laskey | 51fe9d9 | 2006-12-06 17:42:06 +0000 | [diff] [blame] | 400 | } |
| 401 | |
Nate Begeman | 21e463b | 2005-10-16 05:39:50 +0000 | [diff] [blame] | 402 | void PPCRegisterInfo:: |
Misha Brukman | f2ccb77 | 2004-08-17 04:55:41 +0000 | [diff] [blame] | 403 | eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB, |
| 404 | MachineBasicBlock::iterator I) const { |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 405 | // Simply discard ADJCALLSTACKDOWN, ADJCALLSTACKUP instructions. |
Misha Brukman | f2ccb77 | 2004-08-17 04:55:41 +0000 | [diff] [blame] | 406 | MBB.erase(I); |
| 407 | } |
| 408 | |
Bill Wendling | 7194aaf | 2008-03-03 22:19:16 +0000 | [diff] [blame] | 409 | /// findScratchRegister - Find a 'free' PPC register. Try for a call-clobbered |
| 410 | /// register first and then a spilled callee-saved register if that fails. |
| 411 | static |
| 412 | unsigned findScratchRegister(MachineBasicBlock::iterator II, RegScavenger *RS, |
| 413 | const TargetRegisterClass *RC, int SPAdj) { |
| 414 | assert(RS && "Register scavenging must be on"); |
| 415 | unsigned Reg = RS->FindUnusedReg(RC, true); |
| 416 | // FIXME: move ARM callee-saved reg scan to target independent code, then |
| 417 | // search for already spilled CS register here. |
| 418 | if (Reg == 0) |
| 419 | Reg = RS->scavengeRegister(RC, II, SPAdj); |
| 420 | return Reg; |
| 421 | } |
| 422 | |
| 423 | /// lowerDynamicAlloc - Generate the code for allocating an object in the |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 424 | /// current frame. The sequence of code with be in the general form |
| 425 | /// |
| 426 | /// addi R0, SP, #frameSize ; get the address of the previous frame |
| 427 | /// stwxu R0, SP, Rnegsize ; add and update the SP with the negated size |
| 428 | /// addi Rnew, SP, #maxCalFrameSize ; get the top of the allocation |
| 429 | /// |
Bill Wendling | 7194aaf | 2008-03-03 22:19:16 +0000 | [diff] [blame] | 430 | void PPCRegisterInfo::lowerDynamicAlloc(MachineBasicBlock::iterator II, |
| 431 | int SPAdj, RegScavenger *RS) const { |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 432 | // Get the instruction. |
| 433 | MachineInstr &MI = *II; |
| 434 | // Get the instruction's basic block. |
| 435 | MachineBasicBlock &MBB = *MI.getParent(); |
| 436 | // Get the basic block's function. |
| 437 | MachineFunction &MF = *MBB.getParent(); |
| 438 | // Get the frame info. |
| 439 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
| 440 | // Determine whether 64-bit pointers are used. |
| 441 | bool LP64 = Subtarget.isPPC64(); |
| 442 | |
Evan Cheng | fab0439 | 2007-01-25 22:48:25 +0000 | [diff] [blame] | 443 | // Get the maximum call stack size. |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 444 | unsigned maxCallFrameSize = MFI->getMaxCallFrameSize(); |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 445 | // Get the total frame size. |
| 446 | unsigned FrameSize = MFI->getStackSize(); |
| 447 | |
| 448 | // Get stack alignments. |
| 449 | unsigned TargetAlign = MF.getTarget().getFrameInfo()->getStackAlignment(); |
| 450 | unsigned MaxAlign = MFI->getMaxAlignment(); |
Jim Laskey | d6fa8c1 | 2006-11-17 18:49:39 +0000 | [diff] [blame] | 451 | assert(MaxAlign <= TargetAlign && |
| 452 | "Dynamic alloca with large aligns not supported"); |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 453 | |
| 454 | // Determine the previous frame's address. If FrameSize can't be |
| 455 | // represented as 16 bits or we need special alignment, then we load the |
| 456 | // previous frame's address from 0(SP). Why not do an addis of the hi? |
| 457 | // Because R0 is our only safe tmp register and addi/addis treat R0 as zero. |
| 458 | // Constructing the constant and adding would take 3 instructions. |
| 459 | // Fortunately, a frame greater than 32K is rare. |
Bill Wendling | 7194aaf | 2008-03-03 22:19:16 +0000 | [diff] [blame] | 460 | const TargetRegisterClass *G8RC = &PPC::G8RCRegClass; |
| 461 | const TargetRegisterClass *GPRC = &PPC::GPRCRegClass; |
| 462 | const TargetRegisterClass *RC = LP64 ? G8RC : GPRC; |
| 463 | |
| 464 | // FIXME (64-bit): Use "findScratchRegister" |
| 465 | unsigned Reg; |
Bill Wendling | 4a66e9a | 2008-03-10 22:49:16 +0000 | [diff] [blame] | 466 | if (EnableRegisterScavenging) |
Bill Wendling | 7194aaf | 2008-03-03 22:19:16 +0000 | [diff] [blame] | 467 | Reg = findScratchRegister(II, RS, RC, SPAdj); |
| 468 | else |
| 469 | Reg = PPC::R0; |
| 470 | |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 471 | if (MaxAlign < TargetAlign && isInt16(FrameSize)) { |
Bill Wendling | 7194aaf | 2008-03-03 22:19:16 +0000 | [diff] [blame] | 472 | BuildMI(MBB, II, TII.get(PPC::ADDI), Reg) |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 473 | .addReg(PPC::R31) |
| 474 | .addImm(FrameSize); |
| 475 | } else if (LP64) { |
Bill Wendling | 4a66e9a | 2008-03-10 22:49:16 +0000 | [diff] [blame] | 476 | if (EnableRegisterScavenging) // FIXME (64-bit): Use "true" part. |
Bill Wendling | 880d0f6 | 2008-03-04 23:13:51 +0000 | [diff] [blame] | 477 | BuildMI(MBB, II, TII.get(PPC::LD), Reg) |
Chris Lattner | 71a2cb2 | 2008-03-20 01:22:40 +0000 | [diff] [blame] | 478 | .addImm(0) |
| 479 | .addReg(PPC::X1); |
Bill Wendling | 880d0f6 | 2008-03-04 23:13:51 +0000 | [diff] [blame] | 480 | else |
| 481 | BuildMI(MBB, II, TII.get(PPC::LD), PPC::X0) |
Chris Lattner | 71a2cb2 | 2008-03-20 01:22:40 +0000 | [diff] [blame] | 482 | .addImm(0) |
| 483 | .addReg(PPC::X1); |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 484 | } else { |
Bill Wendling | 7194aaf | 2008-03-03 22:19:16 +0000 | [diff] [blame] | 485 | BuildMI(MBB, II, TII.get(PPC::LWZ), Reg) |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 486 | .addImm(0) |
| 487 | .addReg(PPC::R1); |
| 488 | } |
| 489 | |
Bill Wendling | 7194aaf | 2008-03-03 22:19:16 +0000 | [diff] [blame] | 490 | // Grow the stack and update the stack pointer link, then determine the |
| 491 | // address of new allocated space. |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 492 | if (LP64) { |
Bill Wendling | 4a66e9a | 2008-03-10 22:49:16 +0000 | [diff] [blame] | 493 | if (EnableRegisterScavenging) // FIXME (64-bit): Use "true" part. |
Bill Wendling | 880d0f6 | 2008-03-04 23:13:51 +0000 | [diff] [blame] | 494 | BuildMI(MBB, II, TII.get(PPC::STDUX)) |
Chris Lattner | 71a2cb2 | 2008-03-20 01:22:40 +0000 | [diff] [blame] | 495 | .addReg(Reg, false, false, true) |
| 496 | .addReg(PPC::X1) |
| 497 | .addReg(MI.getOperand(1).getReg()); |
Bill Wendling | 880d0f6 | 2008-03-04 23:13:51 +0000 | [diff] [blame] | 498 | else |
| 499 | BuildMI(MBB, II, TII.get(PPC::STDUX)) |
Chris Lattner | 71a2cb2 | 2008-03-20 01:22:40 +0000 | [diff] [blame] | 500 | .addReg(PPC::X0, false, false, true) |
| 501 | .addReg(PPC::X1) |
| 502 | .addReg(MI.getOperand(1).getReg()); |
Bill Wendling | 7194aaf | 2008-03-03 22:19:16 +0000 | [diff] [blame] | 503 | |
| 504 | if (!MI.getOperand(1).isKill()) |
| 505 | BuildMI(MBB, II, TII.get(PPC::ADDI8), MI.getOperand(0).getReg()) |
Chris Lattner | 71a2cb2 | 2008-03-20 01:22:40 +0000 | [diff] [blame] | 506 | .addReg(PPC::X1) |
| 507 | .addImm(maxCallFrameSize); |
Bill Wendling | 7194aaf | 2008-03-03 22:19:16 +0000 | [diff] [blame] | 508 | else |
| 509 | // Implicitly kill the register. |
| 510 | BuildMI(MBB, II, TII.get(PPC::ADDI8), MI.getOperand(0).getReg()) |
Chris Lattner | 71a2cb2 | 2008-03-20 01:22:40 +0000 | [diff] [blame] | 511 | .addReg(PPC::X1) |
| 512 | .addImm(maxCallFrameSize) |
| 513 | .addReg(MI.getOperand(1).getReg(), false, true, true); |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 514 | } else { |
Evan Cheng | c0f64ff | 2006-11-27 23:37:22 +0000 | [diff] [blame] | 515 | BuildMI(MBB, II, TII.get(PPC::STWUX)) |
Bill Wendling | 7194aaf | 2008-03-03 22:19:16 +0000 | [diff] [blame] | 516 | .addReg(Reg, false, false, true) |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 517 | .addReg(PPC::R1) |
| 518 | .addReg(MI.getOperand(1).getReg()); |
Bill Wendling | 7194aaf | 2008-03-03 22:19:16 +0000 | [diff] [blame] | 519 | |
| 520 | if (!MI.getOperand(1).isKill()) |
| 521 | BuildMI(MBB, II, TII.get(PPC::ADDI), MI.getOperand(0).getReg()) |
Chris Lattner | 71a2cb2 | 2008-03-20 01:22:40 +0000 | [diff] [blame] | 522 | .addReg(PPC::R1) |
| 523 | .addImm(maxCallFrameSize); |
Bill Wendling | 7194aaf | 2008-03-03 22:19:16 +0000 | [diff] [blame] | 524 | else |
| 525 | // Implicitly kill the register. |
| 526 | BuildMI(MBB, II, TII.get(PPC::ADDI), MI.getOperand(0).getReg()) |
Chris Lattner | 71a2cb2 | 2008-03-20 01:22:40 +0000 | [diff] [blame] | 527 | .addReg(PPC::R1) |
| 528 | .addImm(maxCallFrameSize) |
| 529 | .addReg(MI.getOperand(1).getReg(), false, true, true); |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 530 | } |
| 531 | |
| 532 | // Discard the DYNALLOC instruction. |
| 533 | MBB.erase(II); |
| 534 | } |
| 535 | |
Bill Wendling | 7194aaf | 2008-03-03 22:19:16 +0000 | [diff] [blame] | 536 | /// lowerCRSpilling - Generate the code for spilling a CR register. Instead of |
| 537 | /// reserving a whole register (R0), we scrounge for one here. This generates |
| 538 | /// code like this: |
| 539 | /// |
| 540 | /// mfcr rA ; Move the conditional register into GPR rA. |
| 541 | /// rlwinm rA, rA, SB, 0, 31 ; Shift the bits left so they are in CR0's slot. |
| 542 | /// stw rA, FI ; Store rA to the frame. |
| 543 | /// |
| 544 | void PPCRegisterInfo::lowerCRSpilling(MachineBasicBlock::iterator II, |
| 545 | unsigned FrameIndex, int SPAdj, |
| 546 | RegScavenger *RS) const { |
| 547 | // Get the instruction. |
| 548 | MachineInstr &MI = *II; // ; SPILL_CR <SrcReg>, <offset>, <FI> |
| 549 | // Get the instruction's basic block. |
| 550 | MachineBasicBlock &MBB = *MI.getParent(); |
| 551 | |
| 552 | const TargetRegisterClass *G8RC = &PPC::G8RCRegClass; |
| 553 | const TargetRegisterClass *GPRC = &PPC::GPRCRegClass; |
| 554 | const TargetRegisterClass *RC = Subtarget.isPPC64() ? G8RC : GPRC; |
| 555 | unsigned Reg = findScratchRegister(II, RS, RC, SPAdj); |
| 556 | |
Bill Wendling | 2b5fab6 | 2008-03-04 23:27:33 +0000 | [diff] [blame] | 557 | // We need to store the CR in the low 4-bits of the saved value. First, issue |
| 558 | // an MFCR to save all of the CRBits. Add an implicit kill of the CR. |
Bill Wendling | 7194aaf | 2008-03-03 22:19:16 +0000 | [diff] [blame] | 559 | if (!MI.getOperand(0).isKill()) |
| 560 | BuildMI(MBB, II, TII.get(PPC::MFCR), Reg); |
| 561 | else |
| 562 | // Implicitly kill the CR register. |
| 563 | BuildMI(MBB, II, TII.get(PPC::MFCR), Reg) |
| 564 | .addReg(MI.getOperand(0).getReg(), false, true, true); |
Bill Wendling | 2b5fab6 | 2008-03-04 23:27:33 +0000 | [diff] [blame] | 565 | |
Bill Wendling | 7194aaf | 2008-03-03 22:19:16 +0000 | [diff] [blame] | 566 | // If the saved register wasn't CR0, shift the bits left so that they are in |
| 567 | // CR0's slot. |
| 568 | unsigned SrcReg = MI.getOperand(0).getReg(); |
| 569 | if (SrcReg != PPC::CR0) |
| 570 | // rlwinm rA, rA, ShiftBits, 0, 31. |
| 571 | BuildMI(MBB, II, TII.get(PPC::RLWINM), Reg) |
| 572 | .addReg(Reg, false, false, true) |
| 573 | .addImm(PPCRegisterInfo::getRegisterNumbering(SrcReg) * 4) |
| 574 | .addImm(0) |
| 575 | .addImm(31); |
| 576 | |
| 577 | addFrameReference(BuildMI(MBB, II, TII.get(PPC::STW)) |
| 578 | .addReg(Reg, false, false, MI.getOperand(1).getImm()), |
| 579 | FrameIndex); |
| 580 | |
| 581 | // Discard the pseudo instruction. |
| 582 | MBB.erase(II); |
| 583 | } |
| 584 | |
Evan Cheng | 5e6df46 | 2007-02-28 00:21:17 +0000 | [diff] [blame] | 585 | void PPCRegisterInfo::eliminateFrameIndex(MachineBasicBlock::iterator II, |
Evan Cheng | 97de913 | 2007-05-01 09:13:03 +0000 | [diff] [blame] | 586 | int SPAdj, RegScavenger *RS) const { |
| 587 | assert(SPAdj == 0 && "Unexpected"); |
| 588 | |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 589 | // Get the instruction. |
Misha Brukman | f2ccb77 | 2004-08-17 04:55:41 +0000 | [diff] [blame] | 590 | MachineInstr &MI = *II; |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 591 | // Get the instruction's basic block. |
Misha Brukman | f2ccb77 | 2004-08-17 04:55:41 +0000 | [diff] [blame] | 592 | MachineBasicBlock &MBB = *MI.getParent(); |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 593 | // Get the basic block's function. |
Misha Brukman | f2ccb77 | 2004-08-17 04:55:41 +0000 | [diff] [blame] | 594 | MachineFunction &MF = *MBB.getParent(); |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 595 | // Get the frame info. |
| 596 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
Misha Brukman | b5f662f | 2005-04-21 23:30:14 +0000 | [diff] [blame] | 597 | |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 598 | // Find out which operand is the frame index. |
Chris Lattner | f602a25 | 2007-10-16 18:00:18 +0000 | [diff] [blame] | 599 | unsigned FIOperandNo = 0; |
| 600 | while (!MI.getOperand(FIOperandNo).isFrameIndex()) { |
| 601 | ++FIOperandNo; |
| 602 | assert(FIOperandNo != MI.getNumOperands() && |
| 603 | "Instr doesn't have FrameIndex operand!"); |
Misha Brukman | f2ccb77 | 2004-08-17 04:55:41 +0000 | [diff] [blame] | 604 | } |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 605 | // Take into account whether it's an add or mem instruction |
Chris Lattner | f602a25 | 2007-10-16 18:00:18 +0000 | [diff] [blame] | 606 | unsigned OffsetOperandNo = (FIOperandNo == 2) ? 1 : 2; |
Chris Lattner | 9aa2895 | 2007-02-01 00:39:08 +0000 | [diff] [blame] | 607 | if (MI.getOpcode() == TargetInstrInfo::INLINEASM) |
Chris Lattner | f602a25 | 2007-10-16 18:00:18 +0000 | [diff] [blame] | 608 | OffsetOperandNo = FIOperandNo-1; |
Bill Wendling | 7194aaf | 2008-03-03 22:19:16 +0000 | [diff] [blame] | 609 | |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 610 | // Get the frame index. |
Chris Lattner | 8aa797a | 2007-12-30 23:10:15 +0000 | [diff] [blame] | 611 | int FrameIndex = MI.getOperand(FIOperandNo).getIndex(); |
Bill Wendling | 7194aaf | 2008-03-03 22:19:16 +0000 | [diff] [blame] | 612 | |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 613 | // Get the frame pointer save index. Users of this index are primarily |
| 614 | // DYNALLOC instructions. |
| 615 | PPCFunctionInfo *FI = MF.getInfo<PPCFunctionInfo>(); |
| 616 | int FPSI = FI->getFramePointerSaveIndex(); |
| 617 | // Get the instruction opcode. |
| 618 | unsigned OpC = MI.getOpcode(); |
| 619 | |
| 620 | // Special case for dynamic alloca. |
| 621 | if (FPSI && FrameIndex == FPSI && |
| 622 | (OpC == PPC::DYNALLOC || OpC == PPC::DYNALLOC8)) { |
Bill Wendling | 7194aaf | 2008-03-03 22:19:16 +0000 | [diff] [blame] | 623 | lowerDynamicAlloc(II, SPAdj, RS); |
| 624 | return; |
| 625 | } |
| 626 | |
| 627 | // Special case for pseudo-op SPILL_CR. |
Bill Wendling | 4a66e9a | 2008-03-10 22:49:16 +0000 | [diff] [blame] | 628 | if (EnableRegisterScavenging) // FIXME (64-bit): Enable by default. |
Bill Wendling | 880d0f6 | 2008-03-04 23:13:51 +0000 | [diff] [blame] | 629 | if (OpC == PPC::SPILL_CR) { |
| 630 | lowerCRSpilling(II, FrameIndex, SPAdj, RS); |
| 631 | return; |
| 632 | } |
Misha Brukman | f2ccb77 | 2004-08-17 04:55:41 +0000 | [diff] [blame] | 633 | |
| 634 | // Replace the FrameIndex with base register with GPR1 (SP) or GPR31 (FP). |
Chris Lattner | f602a25 | 2007-10-16 18:00:18 +0000 | [diff] [blame] | 635 | MI.getOperand(FIOperandNo).ChangeToRegister(hasFP(MF) ? PPC::R31 : PPC::R1, |
| 636 | false); |
Misha Brukman | f2ccb77 | 2004-08-17 04:55:41 +0000 | [diff] [blame] | 637 | |
Chris Lattner | 7ffa9ab | 2006-06-27 18:55:49 +0000 | [diff] [blame] | 638 | // Figure out if the offset in the instruction is shifted right two bits. This |
| 639 | // is true for instructions like "STD", which the machine implicitly adds two |
| 640 | // low zeros to. |
| 641 | bool isIXAddr = false; |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 642 | switch (OpC) { |
Chris Lattner | 7ffa9ab | 2006-06-27 18:55:49 +0000 | [diff] [blame] | 643 | case PPC::LWA: |
| 644 | case PPC::LD: |
| 645 | case PPC::STD: |
| 646 | case PPC::STD_32: |
| 647 | isIXAddr = true; |
| 648 | break; |
| 649 | } |
| 650 | |
Misha Brukman | f2ccb77 | 2004-08-17 04:55:41 +0000 | [diff] [blame] | 651 | // Now add the frame object offset to the offset from r1. |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 652 | int Offset = MFI->getObjectOffset(FrameIndex); |
Chris Lattner | 7ffa9ab | 2006-06-27 18:55:49 +0000 | [diff] [blame] | 653 | if (!isIXAddr) |
Chris Lattner | 9a1ceae | 2007-12-30 20:49:49 +0000 | [diff] [blame] | 654 | Offset += MI.getOperand(OffsetOperandNo).getImm(); |
Chris Lattner | 7ffa9ab | 2006-06-27 18:55:49 +0000 | [diff] [blame] | 655 | else |
Chris Lattner | 9a1ceae | 2007-12-30 20:49:49 +0000 | [diff] [blame] | 656 | Offset += MI.getOperand(OffsetOperandNo).getImm() << 2; |
Misha Brukman | f2ccb77 | 2004-08-17 04:55:41 +0000 | [diff] [blame] | 657 | |
| 658 | // If we're not using a Frame Pointer that has been set to the value of the |
| 659 | // SP before having the stack size subtracted from it, then add the stack size |
| 660 | // to Offset to get the correct offset. |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 661 | Offset += MFI->getStackSize(); |
Misha Brukman | b5f662f | 2005-04-21 23:30:14 +0000 | [diff] [blame] | 662 | |
Chris Lattner | 789db09 | 2007-11-27 22:14:42 +0000 | [diff] [blame] | 663 | // If we can, encode the offset directly into the instruction. If this is a |
| 664 | // normal PPC "ri" instruction, any 16-bit value can be safely encoded. If |
| 665 | // this is a PPC64 "ix" instruction, only a 16-bit value with the low two bits |
| 666 | // clear can be encoded. This is extremely uncommon, because normally you |
| 667 | // only "std" to a stack slot that is at least 4-byte aligned, but it can |
| 668 | // happen in invalid code. |
Chris Lattner | d964285 | 2007-12-08 07:04:58 +0000 | [diff] [blame] | 669 | if (isInt16(Offset) && (!isIXAddr || (Offset & 3) == 0)) { |
Chris Lattner | 789db09 | 2007-11-27 22:14:42 +0000 | [diff] [blame] | 670 | if (isIXAddr) |
Chris Lattner | 841d12d | 2005-10-18 16:51:22 +0000 | [diff] [blame] | 671 | Offset >>= 2; // The actual encoded value has the low two bits zero. |
Chris Lattner | f602a25 | 2007-10-16 18:00:18 +0000 | [diff] [blame] | 672 | MI.getOperand(OffsetOperandNo).ChangeToImmediate(Offset); |
Chris Lattner | 789db09 | 2007-11-27 22:14:42 +0000 | [diff] [blame] | 673 | return; |
Misha Brukman | f2ccb77 | 2004-08-17 04:55:41 +0000 | [diff] [blame] | 674 | } |
Bill Wendling | 7194aaf | 2008-03-03 22:19:16 +0000 | [diff] [blame] | 675 | |
| 676 | // The offset doesn't fit into a single register, scavenge one to build the |
| 677 | // offset in. |
| 678 | // FIXME: figure out what SPAdj is doing here. |
| 679 | |
| 680 | // FIXME (64-bit): Use "findScratchRegister". |
| 681 | unsigned SReg; |
Bill Wendling | 4a66e9a | 2008-03-10 22:49:16 +0000 | [diff] [blame] | 682 | if (EnableRegisterScavenging) |
Bill Wendling | 7194aaf | 2008-03-03 22:19:16 +0000 | [diff] [blame] | 683 | SReg = findScratchRegister(II, RS, &PPC::GPRCRegClass, SPAdj); |
| 684 | else |
| 685 | SReg = PPC::R0; |
| 686 | |
| 687 | // Insert a set of rA with the full offset value before the ld, st, or add |
| 688 | BuildMI(MBB, II, TII.get(PPC::LIS), SReg) |
| 689 | .addImm(Offset >> 16); |
| 690 | BuildMI(MBB, II, TII.get(PPC::ORI), SReg) |
| 691 | .addReg(SReg, false, false, true) |
| 692 | .addImm(Offset); |
| 693 | |
| 694 | // Convert into indexed form of the instruction: |
| 695 | // |
| 696 | // sth 0:rA, 1:imm 2:(rB) ==> sthx 0:rA, 2:rB, 1:r0 |
| 697 | // addi 0:rA 1:rB, 2, imm ==> add 0:rA, 1:rB, 2:r0 |
Chris Lattner | 789db09 | 2007-11-27 22:14:42 +0000 | [diff] [blame] | 698 | unsigned OperandBase; |
Bill Wendling | 7194aaf | 2008-03-03 22:19:16 +0000 | [diff] [blame] | 699 | |
Chris Lattner | 789db09 | 2007-11-27 22:14:42 +0000 | [diff] [blame] | 700 | if (OpC != TargetInstrInfo::INLINEASM) { |
| 701 | assert(ImmToIdxMap.count(OpC) && |
| 702 | "No indexed form of load or store available!"); |
| 703 | unsigned NewOpcode = ImmToIdxMap.find(OpC)->second; |
Chris Lattner | 5080f4d | 2008-01-11 18:10:50 +0000 | [diff] [blame] | 704 | MI.setDesc(TII.get(NewOpcode)); |
Chris Lattner | 789db09 | 2007-11-27 22:14:42 +0000 | [diff] [blame] | 705 | OperandBase = 1; |
| 706 | } else { |
| 707 | OperandBase = OffsetOperandNo; |
| 708 | } |
| 709 | |
| 710 | unsigned StackReg = MI.getOperand(FIOperandNo).getReg(); |
| 711 | MI.getOperand(OperandBase).ChangeToRegister(StackReg, false); |
Bill Wendling | 7194aaf | 2008-03-03 22:19:16 +0000 | [diff] [blame] | 712 | MI.getOperand(OperandBase + 1).ChangeToRegister(SReg, false); |
Misha Brukman | f2ccb77 | 2004-08-17 04:55:41 +0000 | [diff] [blame] | 713 | } |
| 714 | |
Chris Lattner | f7d2372 | 2006-04-17 20:59:25 +0000 | [diff] [blame] | 715 | /// VRRegNo - Map from a numbered VR register to its enum value. |
| 716 | /// |
| 717 | static const unsigned short VRRegNo[] = { |
Chris Lattner | b47e089 | 2006-06-12 21:50:57 +0000 | [diff] [blame] | 718 | PPC::V0 , PPC::V1 , PPC::V2 , PPC::V3 , PPC::V4 , PPC::V5 , PPC::V6 , PPC::V7 , |
| 719 | 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] | 720 | PPC::V16, PPC::V17, PPC::V18, PPC::V19, PPC::V20, PPC::V21, PPC::V22, PPC::V23, |
| 721 | PPC::V24, PPC::V25, PPC::V26, PPC::V27, PPC::V28, PPC::V29, PPC::V30, PPC::V31 |
| 722 | }; |
| 723 | |
Chris Lattner | f9568d8 | 2006-04-17 21:48:13 +0000 | [diff] [blame] | 724 | /// RemoveVRSaveCode - We have found that this function does not need any code |
| 725 | /// to manipulate the VRSAVE register, even though it uses vector registers. |
| 726 | /// This can happen when the only registers used are known to be live in or out |
| 727 | /// of the function. Remove all of the VRSAVE related code from the function. |
| 728 | static void RemoveVRSaveCode(MachineInstr *MI) { |
| 729 | MachineBasicBlock *Entry = MI->getParent(); |
| 730 | MachineFunction *MF = Entry->getParent(); |
| 731 | |
| 732 | // We know that the MTVRSAVE instruction immediately follows MI. Remove it. |
| 733 | MachineBasicBlock::iterator MBBI = MI; |
| 734 | ++MBBI; |
| 735 | assert(MBBI != Entry->end() && MBBI->getOpcode() == PPC::MTVRSAVE); |
| 736 | MBBI->eraseFromParent(); |
| 737 | |
| 738 | bool RemovedAllMTVRSAVEs = true; |
| 739 | // See if we can find and remove the MTVRSAVE instruction from all of the |
| 740 | // epilog blocks. |
Chris Lattner | f9568d8 | 2006-04-17 21:48:13 +0000 | [diff] [blame] | 741 | for (MachineFunction::iterator I = MF->begin(), E = MF->end(); I != E; ++I) { |
| 742 | // If last instruction is a return instruction, add an epilogue |
Chris Lattner | 749c6f6 | 2008-01-07 07:27:27 +0000 | [diff] [blame] | 743 | if (!I->empty() && I->back().getDesc().isReturn()) { |
Chris Lattner | f9568d8 | 2006-04-17 21:48:13 +0000 | [diff] [blame] | 744 | bool FoundIt = false; |
| 745 | for (MBBI = I->end(); MBBI != I->begin(); ) { |
| 746 | --MBBI; |
| 747 | if (MBBI->getOpcode() == PPC::MTVRSAVE) { |
| 748 | MBBI->eraseFromParent(); // remove it. |
| 749 | FoundIt = true; |
| 750 | break; |
| 751 | } |
| 752 | } |
| 753 | RemovedAllMTVRSAVEs &= FoundIt; |
| 754 | } |
| 755 | } |
| 756 | |
| 757 | // If we found and removed all MTVRSAVE instructions, remove the read of |
| 758 | // VRSAVE as well. |
| 759 | if (RemovedAllMTVRSAVEs) { |
| 760 | MBBI = MI; |
| 761 | assert(MBBI != Entry->begin() && "UPDATE_VRSAVE is first instr in block?"); |
| 762 | --MBBI; |
| 763 | assert(MBBI->getOpcode() == PPC::MFVRSAVE && "VRSAVE instrs wandered?"); |
| 764 | MBBI->eraseFromParent(); |
| 765 | } |
| 766 | |
| 767 | // Finally, nuke the UPDATE_VRSAVE. |
| 768 | MI->eraseFromParent(); |
| 769 | } |
| 770 | |
Chris Lattner | 1877ec9 | 2006-03-13 21:52:10 +0000 | [diff] [blame] | 771 | // HandleVRSaveUpdate - MI is the UPDATE_VRSAVE instruction introduced by the |
| 772 | // instruction selector. Based on the vector registers that have been used, |
| 773 | // transform this into the appropriate ORI instruction. |
Evan Cheng | 6c087e5 | 2007-04-25 22:13:27 +0000 | [diff] [blame] | 774 | static void HandleVRSaveUpdate(MachineInstr *MI, const TargetInstrInfo &TII) { |
| 775 | MachineFunction *MF = MI->getParent()->getParent(); |
| 776 | |
Chris Lattner | 1877ec9 | 2006-03-13 21:52:10 +0000 | [diff] [blame] | 777 | unsigned UsedRegMask = 0; |
Chris Lattner | f7d2372 | 2006-04-17 20:59:25 +0000 | [diff] [blame] | 778 | for (unsigned i = 0; i != 32; ++i) |
Chris Lattner | 84bc542 | 2007-12-31 04:13:23 +0000 | [diff] [blame] | 779 | if (MF->getRegInfo().isPhysRegUsed(VRRegNo[i])) |
Chris Lattner | f7d2372 | 2006-04-17 20:59:25 +0000 | [diff] [blame] | 780 | UsedRegMask |= 1 << (31-i); |
| 781 | |
Chris Lattner | 402504b | 2006-04-17 21:22:06 +0000 | [diff] [blame] | 782 | // Live in and live out values already must be in the mask, so don't bother |
| 783 | // marking them. |
Chris Lattner | 84bc542 | 2007-12-31 04:13:23 +0000 | [diff] [blame] | 784 | for (MachineRegisterInfo::livein_iterator |
| 785 | I = MF->getRegInfo().livein_begin(), |
| 786 | E = MF->getRegInfo().livein_end(); I != E; ++I) { |
Chris Lattner | 402504b | 2006-04-17 21:22:06 +0000 | [diff] [blame] | 787 | unsigned RegNo = PPCRegisterInfo::getRegisterNumbering(I->first); |
| 788 | if (VRRegNo[RegNo] == I->first) // If this really is a vector reg. |
| 789 | UsedRegMask &= ~(1 << (31-RegNo)); // Doesn't need to be marked. |
| 790 | } |
Chris Lattner | 84bc542 | 2007-12-31 04:13:23 +0000 | [diff] [blame] | 791 | for (MachineRegisterInfo::liveout_iterator |
| 792 | I = MF->getRegInfo().liveout_begin(), |
| 793 | E = MF->getRegInfo().liveout_end(); I != E; ++I) { |
Chris Lattner | 402504b | 2006-04-17 21:22:06 +0000 | [diff] [blame] | 794 | unsigned RegNo = PPCRegisterInfo::getRegisterNumbering(*I); |
| 795 | if (VRRegNo[RegNo] == *I) // If this really is a vector reg. |
| 796 | UsedRegMask &= ~(1 << (31-RegNo)); // Doesn't need to be marked. |
| 797 | } |
| 798 | |
Chris Lattner | 1877ec9 | 2006-03-13 21:52:10 +0000 | [diff] [blame] | 799 | // If no registers are used, turn this into a copy. |
| 800 | if (UsedRegMask == 0) { |
Chris Lattner | f9568d8 | 2006-04-17 21:48:13 +0000 | [diff] [blame] | 801 | // Remove all VRSAVE code. |
| 802 | RemoveVRSaveCode(MI); |
| 803 | return; |
Bill Wendling | 7194aaf | 2008-03-03 22:19:16 +0000 | [diff] [blame] | 804 | } |
| 805 | |
| 806 | unsigned SrcReg = MI->getOperand(1).getReg(); |
| 807 | unsigned DstReg = MI->getOperand(0).getReg(); |
| 808 | |
| 809 | if ((UsedRegMask & 0xFFFF) == UsedRegMask) { |
| 810 | if (DstReg != SrcReg) |
| 811 | BuildMI(*MI->getParent(), MI, TII.get(PPC::ORI), DstReg) |
| 812 | .addReg(SrcReg) |
| 813 | .addImm(UsedRegMask); |
| 814 | else |
| 815 | BuildMI(*MI->getParent(), MI, TII.get(PPC::ORI), DstReg) |
| 816 | .addReg(SrcReg, false, false, true) |
| 817 | .addImm(UsedRegMask); |
Chris Lattner | 1877ec9 | 2006-03-13 21:52:10 +0000 | [diff] [blame] | 818 | } else if ((UsedRegMask & 0xFFFF0000) == UsedRegMask) { |
Bill Wendling | 7194aaf | 2008-03-03 22:19:16 +0000 | [diff] [blame] | 819 | if (DstReg != SrcReg) |
| 820 | BuildMI(*MI->getParent(), MI, TII.get(PPC::ORIS), DstReg) |
| 821 | .addReg(SrcReg) |
| 822 | .addImm(UsedRegMask >> 16); |
| 823 | else |
| 824 | BuildMI(*MI->getParent(), MI, TII.get(PPC::ORIS), DstReg) |
| 825 | .addReg(SrcReg, false, false, true) |
| 826 | .addImm(UsedRegMask >> 16); |
Chris Lattner | 1877ec9 | 2006-03-13 21:52:10 +0000 | [diff] [blame] | 827 | } else { |
Bill Wendling | 7194aaf | 2008-03-03 22:19:16 +0000 | [diff] [blame] | 828 | if (DstReg != SrcReg) |
| 829 | BuildMI(*MI->getParent(), MI, TII.get(PPC::ORIS), DstReg) |
| 830 | .addReg(SrcReg) |
| 831 | .addImm(UsedRegMask >> 16); |
| 832 | else |
| 833 | BuildMI(*MI->getParent(), MI, TII.get(PPC::ORIS), DstReg) |
| 834 | .addReg(SrcReg, false, false, true) |
| 835 | .addImm(UsedRegMask >> 16); |
| 836 | |
Evan Cheng | c0f64ff | 2006-11-27 23:37:22 +0000 | [diff] [blame] | 837 | BuildMI(*MI->getParent(), MI, TII.get(PPC::ORI), DstReg) |
Bill Wendling | 7194aaf | 2008-03-03 22:19:16 +0000 | [diff] [blame] | 838 | .addReg(DstReg, false, false, true) |
| 839 | .addImm(UsedRegMask & 0xFFFF); |
Chris Lattner | 1877ec9 | 2006-03-13 21:52:10 +0000 | [diff] [blame] | 840 | } |
| 841 | |
| 842 | // Remove the old UPDATE_VRSAVE instruction. |
Chris Lattner | f9568d8 | 2006-04-17 21:48:13 +0000 | [diff] [blame] | 843 | MI->eraseFromParent(); |
Chris Lattner | 1877ec9 | 2006-03-13 21:52:10 +0000 | [diff] [blame] | 844 | } |
| 845 | |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 846 | /// determineFrameLayout - Determine the size of the frame and maximum call |
| 847 | /// frame size. |
| 848 | void PPCRegisterInfo::determineFrameLayout(MachineFunction &MF) const { |
| 849 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
| 850 | |
| 851 | // Get the number of bytes to allocate from the FrameInfo |
| 852 | unsigned FrameSize = MFI->getStackSize(); |
| 853 | |
| 854 | // Get the alignments provided by the target, and the maximum alignment |
| 855 | // (if any) of the fixed frame objects. |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 856 | unsigned MaxAlign = MFI->getMaxAlignment(); |
Evan Cheng | 99403b6 | 2007-01-25 22:25:04 +0000 | [diff] [blame] | 857 | unsigned TargetAlign = MF.getTarget().getFrameInfo()->getStackAlignment(); |
| 858 | unsigned AlignMask = TargetAlign - 1; // |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 859 | |
| 860 | // If we are a leaf function, and use up to 224 bytes of stack space, |
| 861 | // don't have a frame pointer, calls, or dynamic alloca then we do not need |
| 862 | // to adjust the stack pointer (we fit in the Red Zone). |
Dale Johannesen | 82e4289 | 2008-03-10 22:59:46 +0000 | [diff] [blame] | 863 | if (FrameSize <= 224 && // Fits in red zone. |
| 864 | !MFI->hasVarSizedObjects() && // No dynamic alloca. |
| 865 | !MFI->hasCalls() && // No calls. |
| 866 | (!ALIGN_STACK || MaxAlign <= TargetAlign)) { // No special alignment. |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 867 | // No need for frame |
| 868 | MFI->setStackSize(0); |
| 869 | return; |
| 870 | } |
| 871 | |
| 872 | // Get the maximum call frame size of all the calls. |
| 873 | unsigned maxCallFrameSize = MFI->getMaxCallFrameSize(); |
| 874 | |
| 875 | // Maximum call frame needs to be at least big enough for linkage and 8 args. |
| 876 | unsigned minCallFrameSize = |
Chris Lattner | 9f0bc65 | 2007-02-25 05:34:32 +0000 | [diff] [blame] | 877 | PPCFrameInfo::getMinCallFrameSize(Subtarget.isPPC64(), |
| 878 | Subtarget.isMachoABI()); |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 879 | maxCallFrameSize = std::max(maxCallFrameSize, minCallFrameSize); |
| 880 | |
| 881 | // If we have dynamic alloca then maxCallFrameSize needs to be aligned so |
| 882 | // that allocations will be aligned. |
| 883 | if (MFI->hasVarSizedObjects()) |
| 884 | maxCallFrameSize = (maxCallFrameSize + AlignMask) & ~AlignMask; |
| 885 | |
| 886 | // Update maximum call frame size. |
| 887 | MFI->setMaxCallFrameSize(maxCallFrameSize); |
| 888 | |
| 889 | // Include call frame size in total. |
| 890 | FrameSize += maxCallFrameSize; |
Chris Lattner | 9f0bc65 | 2007-02-25 05:34:32 +0000 | [diff] [blame] | 891 | |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 892 | // Make sure the frame is aligned. |
| 893 | FrameSize = (FrameSize + AlignMask) & ~AlignMask; |
| 894 | |
| 895 | // Update frame info. |
| 896 | MFI->setStackSize(FrameSize); |
| 897 | } |
Misha Brukman | f2ccb77 | 2004-08-17 04:55:41 +0000 | [diff] [blame] | 898 | |
Bill Wendling | 7194aaf | 2008-03-03 22:19:16 +0000 | [diff] [blame] | 899 | void |
| 900 | PPCRegisterInfo::processFunctionBeforeCalleeSavedScan(MachineFunction &MF, |
| 901 | RegScavenger *RS) const { |
Jim Laskey | d313a9b | 2007-02-27 11:55:45 +0000 | [diff] [blame] | 902 | // Save and clear the LR state. |
| 903 | PPCFunctionInfo *FI = MF.getInfo<PPCFunctionInfo>(); |
| 904 | unsigned LR = getRARegister(); |
Chris Lattner | 84bc542 | 2007-12-31 04:13:23 +0000 | [diff] [blame] | 905 | FI->setUsesLR(MF.getRegInfo().isPhysRegUsed(LR)); |
| 906 | MF.getRegInfo().setPhysRegUnused(LR); |
Nicolas Geoffray | 82d4264 | 2007-03-21 16:44:14 +0000 | [diff] [blame] | 907 | |
| 908 | // Save R31 if necessary |
| 909 | int FPSI = FI->getFramePointerSaveIndex(); |
| 910 | bool IsPPC64 = Subtarget.isPPC64(); |
Nicolas Geoffray | ec58d9f | 2007-04-03 12:35:28 +0000 | [diff] [blame] | 911 | bool IsELF32_ABI = Subtarget.isELF32_ABI(); |
| 912 | bool IsMachoABI = Subtarget.isMachoABI(); |
Bill Wendling | 7194aaf | 2008-03-03 22:19:16 +0000 | [diff] [blame] | 913 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
Nicolas Geoffray | 82d4264 | 2007-03-21 16:44:14 +0000 | [diff] [blame] | 914 | |
| 915 | // If the frame pointer save index hasn't been defined yet. |
Chris Lattner | 84bc542 | 2007-12-31 04:13:23 +0000 | [diff] [blame] | 916 | if (!FPSI && (NoFramePointerElim || MFI->hasVarSizedObjects()) && |
| 917 | IsELF32_ABI) { |
Nicolas Geoffray | 82d4264 | 2007-03-21 16:44:14 +0000 | [diff] [blame] | 918 | // Find out what the fix offset of the frame pointer save area. |
Nicolas Geoffray | ec58d9f | 2007-04-03 12:35:28 +0000 | [diff] [blame] | 919 | int FPOffset = PPCFrameInfo::getFramePointerSaveOffset(IsPPC64, |
| 920 | IsMachoABI); |
Nicolas Geoffray | 82d4264 | 2007-03-21 16:44:14 +0000 | [diff] [blame] | 921 | // Allocate the frame index for frame pointer save area. |
| 922 | FPSI = MF.getFrameInfo()->CreateFixedObject(IsPPC64? 8 : 4, FPOffset); |
| 923 | // Save the result. |
| 924 | FI->setFramePointerSaveIndex(FPSI); |
| 925 | } |
| 926 | |
Bill Wendling | 7194aaf | 2008-03-03 22:19:16 +0000 | [diff] [blame] | 927 | // Reserve a slot closest to SP or frame pointer if we have a dynalloc or |
| 928 | // a large stack, which will require scavenging a register to materialize a |
| 929 | // large offset. |
| 930 | // FIXME: this doesn't actually check stack size, so is a bit pessimistic |
| 931 | // FIXME: doesn't detect whether or not we need to spill vXX, which requires |
| 932 | // r0 for now. |
| 933 | |
Bill Wendling | 4a66e9a | 2008-03-10 22:49:16 +0000 | [diff] [blame] | 934 | if (EnableRegisterScavenging) // FIXME (64-bit): Enable. |
Bill Wendling | 880d0f6 | 2008-03-04 23:13:51 +0000 | [diff] [blame] | 935 | if (needsFP(MF) || spillsCR(MF)) { |
| 936 | const TargetRegisterClass *GPRC = &PPC::GPRCRegClass; |
| 937 | const TargetRegisterClass *G8RC = &PPC::G8RCRegClass; |
| 938 | const TargetRegisterClass *RC = IsPPC64 ? G8RC : GPRC; |
| 939 | RS->setScavengingFrameIndex(MFI->CreateStackObject(RC->getSize(), |
Chris Lattner | 71a2cb2 | 2008-03-20 01:22:40 +0000 | [diff] [blame] | 940 | RC->getAlignment())); |
Bill Wendling | 880d0f6 | 2008-03-04 23:13:51 +0000 | [diff] [blame] | 941 | } |
Jim Laskey | d313a9b | 2007-02-27 11:55:45 +0000 | [diff] [blame] | 942 | } |
| 943 | |
Bill Wendling | 7194aaf | 2008-03-03 22:19:16 +0000 | [diff] [blame] | 944 | void |
| 945 | PPCRegisterInfo::emitPrologue(MachineFunction &MF) const { |
Misha Brukman | f2ccb77 | 2004-08-17 04:55:41 +0000 | [diff] [blame] | 946 | MachineBasicBlock &MBB = MF.front(); // Prolog goes in entry BB |
| 947 | MachineBasicBlock::iterator MBBI = MBB.begin(); |
| 948 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
Jim Laskey | 44c3b9f | 2007-01-26 21:22:28 +0000 | [diff] [blame] | 949 | MachineModuleInfo *MMI = MFI->getMachineModuleInfo(); |
Dale Johannesen | e004062 | 2008-04-02 17:04:45 +0000 | [diff] [blame] | 950 | bool needsFrameMoves = (MMI && MMI->hasDebugInfo()) || |
Dale Johannesen | 4e1b794 | 2008-04-08 00:10:24 +0000 | [diff] [blame^] | 951 | !MF.getFunction()->doesNotThrow() || |
| 952 | !UnwindTablesOptional; |
Chris Lattner | 4f91a4c | 2006-04-03 22:03:29 +0000 | [diff] [blame] | 953 | |
Jim Laskey | 072200c | 2007-01-29 18:51:14 +0000 | [diff] [blame] | 954 | // Prepare for frame info. |
Jim Laskey | 5e73d5b | 2007-01-24 18:45:13 +0000 | [diff] [blame] | 955 | unsigned FrameLabelId = 0; |
Bill Wendling | 7194aaf | 2008-03-03 22:19:16 +0000 | [diff] [blame] | 956 | |
Chris Lattner | 4f91a4c | 2006-04-03 22:03:29 +0000 | [diff] [blame] | 957 | // Scan the prolog, looking for an UPDATE_VRSAVE instruction. If we find it, |
| 958 | // process it. |
Chris Lattner | 8aa777d | 2006-03-16 21:31:45 +0000 | [diff] [blame] | 959 | for (unsigned i = 0; MBBI != MBB.end(); ++i, ++MBBI) { |
Chris Lattner | 1877ec9 | 2006-03-13 21:52:10 +0000 | [diff] [blame] | 960 | if (MBBI->getOpcode() == PPC::UPDATE_VRSAVE) { |
Evan Cheng | 6c087e5 | 2007-04-25 22:13:27 +0000 | [diff] [blame] | 961 | HandleVRSaveUpdate(MBBI, TII); |
Chris Lattner | 1877ec9 | 2006-03-13 21:52:10 +0000 | [diff] [blame] | 962 | break; |
| 963 | } |
| 964 | } |
| 965 | |
| 966 | // Move MBBI back to the beginning of the function. |
| 967 | MBBI = MBB.begin(); |
Bill Wendling | 7194aaf | 2008-03-03 22:19:16 +0000 | [diff] [blame] | 968 | |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 969 | // Work out frame sizes. |
| 970 | determineFrameLayout(MF); |
| 971 | unsigned FrameSize = MFI->getStackSize(); |
Nate Begeman | ae232e7 | 2005-11-06 09:00:38 +0000 | [diff] [blame] | 972 | |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 973 | int NegFrameSize = -FrameSize; |
Jim Laskey | 51fe9d9 | 2006-12-06 17:42:06 +0000 | [diff] [blame] | 974 | |
| 975 | // Get processor type. |
| 976 | bool IsPPC64 = Subtarget.isPPC64(); |
Chris Lattner | 9f0bc65 | 2007-02-25 05:34:32 +0000 | [diff] [blame] | 977 | // Get operating system |
| 978 | bool IsMachoABI = Subtarget.isMachoABI(); |
Jim Laskey | 51fe9d9 | 2006-12-06 17:42:06 +0000 | [diff] [blame] | 979 | // Check if the link register (LR) has been used. |
Chris Lattner | 73944fb | 2007-12-08 06:39:11 +0000 | [diff] [blame] | 980 | bool UsesLR = MustSaveLR(MF); |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 981 | // Do we have a frame pointer for this function? |
Jim Laskey | d313a9b | 2007-02-27 11:55:45 +0000 | [diff] [blame] | 982 | bool HasFP = hasFP(MF) && FrameSize; |
Jim Laskey | 51fe9d9 | 2006-12-06 17:42:06 +0000 | [diff] [blame] | 983 | |
Chris Lattner | 9f0bc65 | 2007-02-25 05:34:32 +0000 | [diff] [blame] | 984 | int LROffset = PPCFrameInfo::getReturnSaveOffset(IsPPC64, IsMachoABI); |
| 985 | int FPOffset = PPCFrameInfo::getFramePointerSaveOffset(IsPPC64, IsMachoABI); |
Bill Wendling | 7194aaf | 2008-03-03 22:19:16 +0000 | [diff] [blame] | 986 | |
Jim Laskey | 51fe9d9 | 2006-12-06 17:42:06 +0000 | [diff] [blame] | 987 | if (IsPPC64) { |
| 988 | if (UsesLR) |
| 989 | BuildMI(MBB, MBBI, TII.get(PPC::MFLR8), PPC::X0); |
| 990 | |
| 991 | if (HasFP) |
Evan Cheng | c0f64ff | 2006-11-27 23:37:22 +0000 | [diff] [blame] | 992 | BuildMI(MBB, MBBI, TII.get(PPC::STD)) |
Bill Wendling | 7194aaf | 2008-03-03 22:19:16 +0000 | [diff] [blame] | 993 | .addReg(PPC::X31) |
| 994 | .addImm(FPOffset/4) |
| 995 | .addReg(PPC::X1); |
Jim Laskey | 51fe9d9 | 2006-12-06 17:42:06 +0000 | [diff] [blame] | 996 | |
| 997 | if (UsesLR) |
| 998 | BuildMI(MBB, MBBI, TII.get(PPC::STD)) |
Bill Wendling | 7194aaf | 2008-03-03 22:19:16 +0000 | [diff] [blame] | 999 | .addReg(PPC::X0) |
| 1000 | .addImm(LROffset / 4) |
| 1001 | .addReg(PPC::X1); |
Jim Laskey | 51fe9d9 | 2006-12-06 17:42:06 +0000 | [diff] [blame] | 1002 | } else { |
| 1003 | if (UsesLR) |
| 1004 | BuildMI(MBB, MBBI, TII.get(PPC::MFLR), PPC::R0); |
| 1005 | |
| 1006 | if (HasFP) |
| 1007 | BuildMI(MBB, MBBI, TII.get(PPC::STW)) |
Bill Wendling | 7194aaf | 2008-03-03 22:19:16 +0000 | [diff] [blame] | 1008 | .addReg(PPC::R31) |
| 1009 | .addImm(FPOffset) |
| 1010 | .addReg(PPC::R1); |
Jim Laskey | 51fe9d9 | 2006-12-06 17:42:06 +0000 | [diff] [blame] | 1011 | |
| 1012 | if (UsesLR) |
| 1013 | BuildMI(MBB, MBBI, TII.get(PPC::STW)) |
Bill Wendling | 7194aaf | 2008-03-03 22:19:16 +0000 | [diff] [blame] | 1014 | .addReg(PPC::R0) |
| 1015 | .addImm(LROffset) |
| 1016 | .addReg(PPC::R1); |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 1017 | } |
| 1018 | |
Jim Laskey | d313a9b | 2007-02-27 11:55:45 +0000 | [diff] [blame] | 1019 | // Skip if a leaf routine. |
| 1020 | if (!FrameSize) return; |
| 1021 | |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 1022 | // Get stack alignments. |
Nate Begeman | ae232e7 | 2005-11-06 09:00:38 +0000 | [diff] [blame] | 1023 | unsigned TargetAlign = MF.getTarget().getFrameInfo()->getStackAlignment(); |
| 1024 | unsigned MaxAlign = MFI->getMaxAlignment(); |
Misha Brukman | f2ccb77 | 2004-08-17 04:55:41 +0000 | [diff] [blame] | 1025 | |
Dale Johannesen | e004062 | 2008-04-02 17:04:45 +0000 | [diff] [blame] | 1026 | if (needsFrameMoves) { |
Jim Laskey | 5e73d5b | 2007-01-24 18:45:13 +0000 | [diff] [blame] | 1027 | // Mark effective beginning of when frame pointer becomes valid. |
Jim Laskey | 44c3b9f | 2007-01-26 21:22:28 +0000 | [diff] [blame] | 1028 | FrameLabelId = MMI->NextLabelID(); |
Evan Cheng | bb81d97 | 2008-01-31 09:59:15 +0000 | [diff] [blame] | 1029 | BuildMI(MBB, MBBI, TII.get(PPC::LABEL)).addImm(FrameLabelId).addImm(0); |
Jim Laskey | 5e73d5b | 2007-01-24 18:45:13 +0000 | [diff] [blame] | 1030 | } |
| 1031 | |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 1032 | // Adjust stack pointer: r1 += NegFrameSize. |
Nate Begeman | 030514c | 2006-04-11 19:29:21 +0000 | [diff] [blame] | 1033 | // If there is a preferred stack alignment, align R1 now |
Jim Laskey | 51fe9d9 | 2006-12-06 17:42:06 +0000 | [diff] [blame] | 1034 | if (!IsPPC64) { |
Chris Lattner | a94a203 | 2006-11-11 19:05:28 +0000 | [diff] [blame] | 1035 | // PPC32. |
Dale Johannesen | 82e4289 | 2008-03-10 22:59:46 +0000 | [diff] [blame] | 1036 | if (ALIGN_STACK && MaxAlign > TargetAlign) { |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 1037 | assert(isPowerOf2_32(MaxAlign)&&isInt16(MaxAlign)&&"Invalid alignment!"); |
| 1038 | assert(isInt16(NegFrameSize) && "Unhandled stack size and alignment!"); |
Bill Wendling | 7194aaf | 2008-03-03 22:19:16 +0000 | [diff] [blame] | 1039 | |
Evan Cheng | c0f64ff | 2006-11-27 23:37:22 +0000 | [diff] [blame] | 1040 | BuildMI(MBB, MBBI, TII.get(PPC::RLWINM), PPC::R0) |
Bill Wendling | 7194aaf | 2008-03-03 22:19:16 +0000 | [diff] [blame] | 1041 | .addReg(PPC::R1) |
| 1042 | .addImm(0) |
| 1043 | .addImm(32 - Log2_32(MaxAlign)) |
| 1044 | .addImm(31); |
| 1045 | BuildMI(MBB, MBBI, TII.get(PPC::SUBFIC) ,PPC::R0) |
| 1046 | .addReg(PPC::R0, false, false, true) |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 1047 | .addImm(NegFrameSize); |
Evan Cheng | c0f64ff | 2006-11-27 23:37:22 +0000 | [diff] [blame] | 1048 | BuildMI(MBB, MBBI, TII.get(PPC::STWUX)) |
Bill Wendling | 7194aaf | 2008-03-03 22:19:16 +0000 | [diff] [blame] | 1049 | .addReg(PPC::R1) |
| 1050 | .addReg(PPC::R1) |
| 1051 | .addReg(PPC::R0); |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 1052 | } else if (isInt16(NegFrameSize)) { |
Bill Wendling | 7194aaf | 2008-03-03 22:19:16 +0000 | [diff] [blame] | 1053 | BuildMI(MBB, MBBI, TII.get(PPC::STWU), PPC::R1) |
| 1054 | .addReg(PPC::R1) |
| 1055 | .addImm(NegFrameSize) |
| 1056 | .addReg(PPC::R1); |
Chris Lattner | a94a203 | 2006-11-11 19:05:28 +0000 | [diff] [blame] | 1057 | } else { |
Bill Wendling | 7194aaf | 2008-03-03 22:19:16 +0000 | [diff] [blame] | 1058 | BuildMI(MBB, MBBI, TII.get(PPC::LIS), PPC::R0) |
| 1059 | .addImm(NegFrameSize >> 16); |
| 1060 | BuildMI(MBB, MBBI, TII.get(PPC::ORI), PPC::R0) |
| 1061 | .addReg(PPC::R0, false, false, true) |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 1062 | .addImm(NegFrameSize & 0xFFFF); |
Bill Wendling | 7194aaf | 2008-03-03 22:19:16 +0000 | [diff] [blame] | 1063 | BuildMI(MBB, MBBI, TII.get(PPC::STWUX)) |
| 1064 | .addReg(PPC::R1) |
| 1065 | .addReg(PPC::R1) |
Chris Lattner | a94a203 | 2006-11-11 19:05:28 +0000 | [diff] [blame] | 1066 | .addReg(PPC::R0); |
| 1067 | } |
| 1068 | } else { // PPC64. |
Dale Johannesen | 82e4289 | 2008-03-10 22:59:46 +0000 | [diff] [blame] | 1069 | if (ALIGN_STACK && MaxAlign > TargetAlign) { |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 1070 | assert(isPowerOf2_32(MaxAlign)&&isInt16(MaxAlign)&&"Invalid alignment!"); |
| 1071 | assert(isInt16(NegFrameSize) && "Unhandled stack size and alignment!"); |
Bill Wendling | 7194aaf | 2008-03-03 22:19:16 +0000 | [diff] [blame] | 1072 | |
Evan Cheng | c0f64ff | 2006-11-27 23:37:22 +0000 | [diff] [blame] | 1073 | BuildMI(MBB, MBBI, TII.get(PPC::RLDICL), PPC::X0) |
Bill Wendling | 7194aaf | 2008-03-03 22:19:16 +0000 | [diff] [blame] | 1074 | .addReg(PPC::X1) |
| 1075 | .addImm(0) |
| 1076 | .addImm(64 - Log2_32(MaxAlign)); |
| 1077 | BuildMI(MBB, MBBI, TII.get(PPC::SUBFIC8), PPC::X0) |
| 1078 | .addReg(PPC::X0) |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 1079 | .addImm(NegFrameSize); |
Evan Cheng | c0f64ff | 2006-11-27 23:37:22 +0000 | [diff] [blame] | 1080 | BuildMI(MBB, MBBI, TII.get(PPC::STDUX)) |
Bill Wendling | 7194aaf | 2008-03-03 22:19:16 +0000 | [diff] [blame] | 1081 | .addReg(PPC::X1) |
| 1082 | .addReg(PPC::X1) |
| 1083 | .addReg(PPC::X0); |
Jim Laskey | 2ff5cdb | 2006-11-17 16:09:31 +0000 | [diff] [blame] | 1084 | } else if (isInt16(NegFrameSize)) { |
Evan Cheng | c0f64ff | 2006-11-27 23:37:22 +0000 | [diff] [blame] | 1085 | BuildMI(MBB, MBBI, TII.get(PPC::STDU), PPC::X1) |
Bill Wendling | 7194aaf | 2008-03-03 22:19:16 +0000 | [diff] [blame] | 1086 | .addReg(PPC::X1) |
| 1087 | .addImm(NegFrameSize / 4) |
| 1088 | .addReg(PPC::X1); |
Chris Lattner | a94a203 | 2006-11-11 19:05:28 +0000 | [diff] [blame] | 1089 | } else { |
Bill Wendling | 7194aaf | 2008-03-03 22:19:16 +0000 | [diff] [blame] | 1090 | BuildMI(MBB, MBBI, TII.get(PPC::LIS8), PPC::X0) |
| 1091 | .addImm(NegFrameSize >> 16); |
| 1092 | BuildMI(MBB, MBBI, TII.get(PPC::ORI8), PPC::X0) |
| 1093 | .addReg(PPC::X0, false, false, true) |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 1094 | .addImm(NegFrameSize & 0xFFFF); |
Bill Wendling | 7194aaf | 2008-03-03 22:19:16 +0000 | [diff] [blame] | 1095 | BuildMI(MBB, MBBI, TII.get(PPC::STDUX)) |
| 1096 | .addReg(PPC::X1) |
| 1097 | .addReg(PPC::X1) |
Chris Lattner | a94a203 | 2006-11-11 19:05:28 +0000 | [diff] [blame] | 1098 | .addReg(PPC::X0); |
| 1099 | } |
Misha Brukman | f2ccb77 | 2004-08-17 04:55:41 +0000 | [diff] [blame] | 1100 | } |
Nate Begeman | ae232e7 | 2005-11-06 09:00:38 +0000 | [diff] [blame] | 1101 | |
Dale Johannesen | e004062 | 2008-04-02 17:04:45 +0000 | [diff] [blame] | 1102 | if (needsFrameMoves) { |
Jim Laskey | 44c3b9f | 2007-01-26 21:22:28 +0000 | [diff] [blame] | 1103 | std::vector<MachineMove> &Moves = MMI->getFrameMoves(); |
Jim Laskey | 4188699 | 2006-04-07 16:34:46 +0000 | [diff] [blame] | 1104 | |
Jim Laskey | 5e73d5b | 2007-01-24 18:45:13 +0000 | [diff] [blame] | 1105 | if (NegFrameSize) { |
| 1106 | // Show update of SP. |
| 1107 | MachineLocation SPDst(MachineLocation::VirtualFP); |
| 1108 | MachineLocation SPSrc(MachineLocation::VirtualFP, NegFrameSize); |
| 1109 | Moves.push_back(MachineMove(FrameLabelId, SPDst, SPSrc)); |
| 1110 | } else { |
| 1111 | MachineLocation SP(IsPPC64 ? PPC::X31 : PPC::R31); |
| 1112 | Moves.push_back(MachineMove(FrameLabelId, SP, SP)); |
| 1113 | } |
Jim Laskey | 4c2c903 | 2006-08-25 19:40:59 +0000 | [diff] [blame] | 1114 | |
Jim Laskey | 5e73d5b | 2007-01-24 18:45:13 +0000 | [diff] [blame] | 1115 | if (HasFP) { |
| 1116 | MachineLocation FPDst(MachineLocation::VirtualFP, FPOffset); |
| 1117 | MachineLocation FPSrc(IsPPC64 ? PPC::X31 : PPC::R31); |
| 1118 | Moves.push_back(MachineMove(FrameLabelId, FPDst, FPSrc)); |
| 1119 | } |
Jim Laskey | ce50a16 | 2006-08-29 16:24:26 +0000 | [diff] [blame] | 1120 | |
| 1121 | // Add callee saved registers to move list. |
| 1122 | const std::vector<CalleeSavedInfo> &CSI = MFI->getCalleeSavedInfo(); |
| 1123 | for (unsigned I = 0, E = CSI.size(); I != E; ++I) { |
Jim Laskey | 5e73d5b | 2007-01-24 18:45:13 +0000 | [diff] [blame] | 1124 | int Offset = MFI->getObjectOffset(CSI[I].getFrameIdx()); |
| 1125 | unsigned Reg = CSI[I].getReg(); |
| 1126 | if (Reg == PPC::LR || Reg == PPC::LR8) continue; |
| 1127 | MachineLocation CSDst(MachineLocation::VirtualFP, Offset); |
| 1128 | MachineLocation CSSrc(Reg); |
| 1129 | Moves.push_back(MachineMove(FrameLabelId, CSDst, CSSrc)); |
Jim Laskey | ce50a16 | 2006-08-29 16:24:26 +0000 | [diff] [blame] | 1130 | } |
Jim Laskey | 5e73d5b | 2007-01-24 18:45:13 +0000 | [diff] [blame] | 1131 | |
Jim Laskey | b82313f | 2007-02-01 16:31:34 +0000 | [diff] [blame] | 1132 | MachineLocation LRDst(MachineLocation::VirtualFP, LROffset); |
| 1133 | MachineLocation LRSrc(IsPPC64 ? PPC::LR8 : PPC::LR); |
| 1134 | Moves.push_back(MachineMove(FrameLabelId, LRDst, LRSrc)); |
| 1135 | |
Jim Laskey | 5e73d5b | 2007-01-24 18:45:13 +0000 | [diff] [blame] | 1136 | // Mark effective beginning of when frame pointer is ready. |
Jim Laskey | 44c3b9f | 2007-01-26 21:22:28 +0000 | [diff] [blame] | 1137 | unsigned ReadyLabelId = MMI->NextLabelID(); |
Evan Cheng | bb81d97 | 2008-01-31 09:59:15 +0000 | [diff] [blame] | 1138 | BuildMI(MBB, MBBI, TII.get(PPC::LABEL)).addImm(ReadyLabelId).addImm(0); |
Jim Laskey | 5e73d5b | 2007-01-24 18:45:13 +0000 | [diff] [blame] | 1139 | |
| 1140 | MachineLocation FPDst(HasFP ? (IsPPC64 ? PPC::X31 : PPC::R31) : |
| 1141 | (IsPPC64 ? PPC::X1 : PPC::R1)); |
| 1142 | MachineLocation FPSrc(MachineLocation::VirtualFP); |
| 1143 | Moves.push_back(MachineMove(ReadyLabelId, FPDst, FPSrc)); |
Jim Laskey | 4188699 | 2006-04-07 16:34:46 +0000 | [diff] [blame] | 1144 | } |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 1145 | |
| 1146 | // If there is a frame pointer, copy R1 into R31 |
Chris Lattner | 4f91a4c | 2006-04-03 22:03:29 +0000 | [diff] [blame] | 1147 | if (HasFP) { |
Jim Laskey | 51fe9d9 | 2006-12-06 17:42:06 +0000 | [diff] [blame] | 1148 | if (!IsPPC64) { |
Bill Wendling | 7194aaf | 2008-03-03 22:19:16 +0000 | [diff] [blame] | 1149 | BuildMI(MBB, MBBI, TII.get(PPC::OR), PPC::R31) |
| 1150 | .addReg(PPC::R1) |
Evan Cheng | c0f64ff | 2006-11-27 23:37:22 +0000 | [diff] [blame] | 1151 | .addReg(PPC::R1); |
Chris Lattner | a94a203 | 2006-11-11 19:05:28 +0000 | [diff] [blame] | 1152 | } else { |
Bill Wendling | 7194aaf | 2008-03-03 22:19:16 +0000 | [diff] [blame] | 1153 | BuildMI(MBB, MBBI, TII.get(PPC::OR8), PPC::X31) |
| 1154 | .addReg(PPC::X1) |
Evan Cheng | c0f64ff | 2006-11-27 23:37:22 +0000 | [diff] [blame] | 1155 | .addReg(PPC::X1); |
Chris Lattner | a94a203 | 2006-11-11 19:05:28 +0000 | [diff] [blame] | 1156 | } |
Misha Brukman | f2ccb77 | 2004-08-17 04:55:41 +0000 | [diff] [blame] | 1157 | } |
| 1158 | } |
| 1159 | |
Nate Begeman | 21e463b | 2005-10-16 05:39:50 +0000 | [diff] [blame] | 1160 | void PPCRegisterInfo::emitEpilogue(MachineFunction &MF, |
| 1161 | MachineBasicBlock &MBB) const { |
Misha Brukman | f2ccb77 | 2004-08-17 04:55:41 +0000 | [diff] [blame] | 1162 | MachineBasicBlock::iterator MBBI = prior(MBB.end()); |
Evan Cheng | 6da8d99 | 2006-01-09 18:28:21 +0000 | [diff] [blame] | 1163 | assert(MBBI->getOpcode() == PPC::BLR && |
Misha Brukman | f2ccb77 | 2004-08-17 04:55:41 +0000 | [diff] [blame] | 1164 | "Can only insert epilog into returning blocks"); |
Misha Brukman | b5f662f | 2005-04-21 23:30:14 +0000 | [diff] [blame] | 1165 | |
Nate Begeman | 030514c | 2006-04-11 19:29:21 +0000 | [diff] [blame] | 1166 | // Get alignment info so we know how to restore r1 |
| 1167 | const MachineFrameInfo *MFI = MF.getFrameInfo(); |
| 1168 | unsigned TargetAlign = MF.getTarget().getFrameInfo()->getStackAlignment(); |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 1169 | unsigned MaxAlign = MFI->getMaxAlignment(); |
Nate Begeman | 030514c | 2006-04-11 19:29:21 +0000 | [diff] [blame] | 1170 | |
Chris Lattner | 64da172 | 2006-01-11 23:03:54 +0000 | [diff] [blame] | 1171 | // Get the number of bytes allocated from the FrameInfo. |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 1172 | unsigned FrameSize = MFI->getStackSize(); |
Misha Brukman | f2ccb77 | 2004-08-17 04:55:41 +0000 | [diff] [blame] | 1173 | |
Jim Laskey | 51fe9d9 | 2006-12-06 17:42:06 +0000 | [diff] [blame] | 1174 | // Get processor type. |
| 1175 | bool IsPPC64 = Subtarget.isPPC64(); |
Chris Lattner | 9f0bc65 | 2007-02-25 05:34:32 +0000 | [diff] [blame] | 1176 | // Get operating system |
| 1177 | bool IsMachoABI = Subtarget.isMachoABI(); |
Jim Laskey | 51fe9d9 | 2006-12-06 17:42:06 +0000 | [diff] [blame] | 1178 | // Check if the link register (LR) has been used. |
Chris Lattner | 73944fb | 2007-12-08 06:39:11 +0000 | [diff] [blame] | 1179 | bool UsesLR = MustSaveLR(MF); |
Jim Laskey | 51fe9d9 | 2006-12-06 17:42:06 +0000 | [diff] [blame] | 1180 | // Do we have a frame pointer for this function? |
Jim Laskey | d313a9b | 2007-02-27 11:55:45 +0000 | [diff] [blame] | 1181 | bool HasFP = hasFP(MF) && FrameSize; |
Chris Lattner | 9f0bc65 | 2007-02-25 05:34:32 +0000 | [diff] [blame] | 1182 | |
| 1183 | int LROffset = PPCFrameInfo::getReturnSaveOffset(IsPPC64, IsMachoABI); |
| 1184 | int FPOffset = PPCFrameInfo::getFramePointerSaveOffset(IsPPC64, IsMachoABI); |
| 1185 | |
Jim Laskey | d313a9b | 2007-02-27 11:55:45 +0000 | [diff] [blame] | 1186 | if (FrameSize) { |
| 1187 | // The loaded (or persistent) stack pointer value is offset by the 'stwu' |
| 1188 | // on entry to the function. Add this offset back now. |
| 1189 | if (!Subtarget.isPPC64()) { |
Dale Johannesen | 82e4289 | 2008-03-10 22:59:46 +0000 | [diff] [blame] | 1190 | if (isInt16(FrameSize) && (!ALIGN_STACK || TargetAlign >= MaxAlign) && |
Jim Laskey | d313a9b | 2007-02-27 11:55:45 +0000 | [diff] [blame] | 1191 | !MFI->hasVarSizedObjects()) { |
| 1192 | BuildMI(MBB, MBBI, TII.get(PPC::ADDI), PPC::R1) |
| 1193 | .addReg(PPC::R1).addImm(FrameSize); |
| 1194 | } else { |
| 1195 | BuildMI(MBB, MBBI, TII.get(PPC::LWZ),PPC::R1).addImm(0).addReg(PPC::R1); |
| 1196 | } |
Chris Lattner | 64da172 | 2006-01-11 23:03:54 +0000 | [diff] [blame] | 1197 | } else { |
Jim Laskey | d313a9b | 2007-02-27 11:55:45 +0000 | [diff] [blame] | 1198 | if (isInt16(FrameSize) && TargetAlign >= MaxAlign && |
| 1199 | !MFI->hasVarSizedObjects()) { |
| 1200 | BuildMI(MBB, MBBI, TII.get(PPC::ADDI8), PPC::X1) |
| 1201 | .addReg(PPC::X1).addImm(FrameSize); |
| 1202 | } else { |
| 1203 | BuildMI(MBB, MBBI, TII.get(PPC::LD), PPC::X1).addImm(0).addReg(PPC::X1); |
| 1204 | } |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 1205 | } |
Jim Laskey | 51fe9d9 | 2006-12-06 17:42:06 +0000 | [diff] [blame] | 1206 | } |
Jim Laskey | 51fe9d9 | 2006-12-06 17:42:06 +0000 | [diff] [blame] | 1207 | |
| 1208 | if (IsPPC64) { |
| 1209 | if (UsesLR) |
| 1210 | BuildMI(MBB, MBBI, TII.get(PPC::LD), PPC::X0) |
| 1211 | .addImm(LROffset/4).addReg(PPC::X1); |
| 1212 | |
| 1213 | if (HasFP) |
| 1214 | BuildMI(MBB, MBBI, TII.get(PPC::LD), PPC::X31) |
| 1215 | .addImm(FPOffset/4).addReg(PPC::X1); |
| 1216 | |
| 1217 | if (UsesLR) |
| 1218 | BuildMI(MBB, MBBI, TII.get(PPC::MTLR8)).addReg(PPC::X0); |
| 1219 | } else { |
| 1220 | if (UsesLR) |
| 1221 | BuildMI(MBB, MBBI, TII.get(PPC::LWZ), PPC::R0) |
| 1222 | .addImm(LROffset).addReg(PPC::R1); |
| 1223 | |
| 1224 | if (HasFP) |
| 1225 | BuildMI(MBB, MBBI, TII.get(PPC::LWZ), PPC::R31) |
| 1226 | .addImm(FPOffset).addReg(PPC::R1); |
| 1227 | |
| 1228 | if (UsesLR) |
| 1229 | BuildMI(MBB, MBBI, TII.get(PPC::MTLR)).addReg(PPC::R0); |
Misha Brukman | f2ccb77 | 2004-08-17 04:55:41 +0000 | [diff] [blame] | 1230 | } |
| 1231 | } |
| 1232 | |
Jim Laskey | 4188699 | 2006-04-07 16:34:46 +0000 | [diff] [blame] | 1233 | unsigned PPCRegisterInfo::getRARegister() const { |
Chris Lattner | 6a5339b | 2006-11-14 18:44:47 +0000 | [diff] [blame] | 1234 | return !Subtarget.isPPC64() ? PPC::LR : PPC::LR8; |
Jim Laskey | 4188699 | 2006-04-07 16:34:46 +0000 | [diff] [blame] | 1235 | } |
| 1236 | |
Jim Laskey | a997918 | 2006-03-28 13:48:33 +0000 | [diff] [blame] | 1237 | unsigned PPCRegisterInfo::getFrameRegister(MachineFunction &MF) const { |
Chris Lattner | a94a203 | 2006-11-11 19:05:28 +0000 | [diff] [blame] | 1238 | if (!Subtarget.isPPC64()) |
| 1239 | return hasFP(MF) ? PPC::R31 : PPC::R1; |
| 1240 | else |
| 1241 | return hasFP(MF) ? PPC::X31 : PPC::X1; |
Jim Laskey | 4188699 | 2006-04-07 16:34:46 +0000 | [diff] [blame] | 1242 | } |
| 1243 | |
Jim Laskey | 5e73d5b | 2007-01-24 18:45:13 +0000 | [diff] [blame] | 1244 | void PPCRegisterInfo::getInitialFrameState(std::vector<MachineMove> &Moves) |
Jim Laskey | 4188699 | 2006-04-07 16:34:46 +0000 | [diff] [blame] | 1245 | const { |
Jim Laskey | 4c2c903 | 2006-08-25 19:40:59 +0000 | [diff] [blame] | 1246 | // Initial state of the frame pointer is R1. |
Jim Laskey | 4188699 | 2006-04-07 16:34:46 +0000 | [diff] [blame] | 1247 | MachineLocation Dst(MachineLocation::VirtualFP); |
| 1248 | MachineLocation Src(PPC::R1, 0); |
Jim Laskey | 5e73d5b | 2007-01-24 18:45:13 +0000 | [diff] [blame] | 1249 | Moves.push_back(MachineMove(0, Dst, Src)); |
Jim Laskey | f1d78e8 | 2006-03-23 18:12:57 +0000 | [diff] [blame] | 1250 | } |
| 1251 | |
Jim Laskey | 62819f3 | 2007-02-21 22:54:50 +0000 | [diff] [blame] | 1252 | unsigned PPCRegisterInfo::getEHExceptionRegister() const { |
| 1253 | return !Subtarget.isPPC64() ? PPC::R3 : PPC::X3; |
| 1254 | } |
| 1255 | |
| 1256 | unsigned PPCRegisterInfo::getEHHandlerRegister() const { |
| 1257 | return !Subtarget.isPPC64() ? PPC::R4 : PPC::X4; |
| 1258 | } |
| 1259 | |
Dale Johannesen | b97aec6 | 2007-11-13 19:13:01 +0000 | [diff] [blame] | 1260 | int PPCRegisterInfo::getDwarfRegNum(unsigned RegNum, bool isEH) const { |
Anton Korobeynikov | 3809fbe | 2007-11-12 23:36:13 +0000 | [diff] [blame] | 1261 | // FIXME: Most probably dwarf numbers differs for Linux and Darwin |
| 1262 | return PPCGenRegisterInfo::getDwarfRegNumFull(RegNum, 0); |
Anton Korobeynikov | f191c80 | 2007-11-11 19:50:10 +0000 | [diff] [blame] | 1263 | } |
| 1264 | |
Chris Lattner | 4c7b43b | 2005-10-14 23:37:35 +0000 | [diff] [blame] | 1265 | #include "PPCGenRegisterInfo.inc" |
Misha Brukman | f2ccb77 | 2004-08-17 04:55:41 +0000 | [diff] [blame] | 1266 | |