Jia Liu | 31d157a | 2012-02-18 12:03:15 +0000 | [diff] [blame^] | 1 | //===-- PPCInstrInfo.cpp - PowerPC Instruction Information ----------------===// |
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 | // |
| 10 | // This file contains the PowerPC implementation of the TargetInstrInfo class. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Chris Lattner | 16e71f2 | 2005-10-14 23:59:06 +0000 | [diff] [blame] | 14 | #include "PPCInstrInfo.h" |
Evan Cheng | 59ee62d | 2011-07-11 03:57:24 +0000 | [diff] [blame] | 15 | #include "PPC.h" |
Owen Anderson | f6372aa | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 16 | #include "PPCInstrBuilder.h" |
Bill Wendling | 7194aaf | 2008-03-03 22:19:16 +0000 | [diff] [blame] | 17 | #include "PPCMachineFunctionInfo.h" |
Chris Lattner | b1d26f6 | 2006-06-17 00:01:04 +0000 | [diff] [blame] | 18 | #include "PPCTargetMachine.h" |
Andrew Trick | 2da8bc8 | 2010-12-24 05:03:26 +0000 | [diff] [blame] | 19 | #include "PPCHazardRecognizers.h" |
Evan Cheng | 94b9550 | 2011-07-26 00:24:13 +0000 | [diff] [blame] | 20 | #include "MCTargetDesc/PPCPredicates.h" |
Jakob Stoklund Olesen | 7a79fcb | 2010-07-16 18:22:00 +0000 | [diff] [blame] | 21 | #include "llvm/CodeGen/MachineFrameInfo.h" |
Misha Brukman | f2ccb77 | 2004-08-17 04:55:41 +0000 | [diff] [blame] | 22 | #include "llvm/CodeGen/MachineInstrBuilder.h" |
Jakob Stoklund Olesen | 7a79fcb | 2010-07-16 18:22:00 +0000 | [diff] [blame] | 23 | #include "llvm/CodeGen/MachineMemOperand.h" |
Jakob Stoklund Olesen | 2432966 | 2010-02-26 21:09:24 +0000 | [diff] [blame] | 24 | #include "llvm/CodeGen/MachineRegisterInfo.h" |
Evan Cheng | 59ee62d | 2011-07-11 03:57:24 +0000 | [diff] [blame] | 25 | #include "llvm/MC/MCAsmInfo.h" |
Bill Wendling | 880d0f6 | 2008-03-04 23:13:51 +0000 | [diff] [blame] | 26 | #include "llvm/Support/CommandLine.h" |
Torok Edwin | dac237e | 2009-07-08 20:53:28 +0000 | [diff] [blame] | 27 | #include "llvm/Support/ErrorHandling.h" |
Evan Cheng | 3e74d6f | 2011-08-24 18:08:43 +0000 | [diff] [blame] | 28 | #include "llvm/Support/TargetRegistry.h" |
Torok Edwin | dac237e | 2009-07-08 20:53:28 +0000 | [diff] [blame] | 29 | #include "llvm/Support/raw_ostream.h" |
Evan Cheng | 59ee62d | 2011-07-11 03:57:24 +0000 | [diff] [blame] | 30 | #include "llvm/ADT/STLExtras.h" |
Misha Brukman | f2ccb77 | 2004-08-17 04:55:41 +0000 | [diff] [blame] | 31 | |
Evan Cheng | 4db3cff | 2011-07-01 17:57:27 +0000 | [diff] [blame] | 32 | #define GET_INSTRINFO_CTOR |
Evan Cheng | 22fee2d | 2011-06-28 20:07:07 +0000 | [diff] [blame] | 33 | #include "PPCGenInstrInfo.inc" |
| 34 | |
Dan Gohman | 82bcd23 | 2010-04-15 17:20:57 +0000 | [diff] [blame] | 35 | namespace llvm { |
Hal Finkel | 3fd0018 | 2011-12-05 17:55:17 +0000 | [diff] [blame] | 36 | extern cl::opt<bool> DisablePPC32RS; |
| 37 | extern cl::opt<bool> DisablePPC64RS; |
Dan Gohman | 82bcd23 | 2010-04-15 17:20:57 +0000 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | using namespace llvm; |
Bill Wendling | 880d0f6 | 2008-03-04 23:13:51 +0000 | [diff] [blame] | 41 | |
Chris Lattner | b1d26f6 | 2006-06-17 00:01:04 +0000 | [diff] [blame] | 42 | PPCInstrInfo::PPCInstrInfo(PPCTargetMachine &tm) |
Evan Cheng | 4db3cff | 2011-07-01 17:57:27 +0000 | [diff] [blame] | 43 | : PPCGenInstrInfo(PPC::ADJCALLSTACKDOWN, PPC::ADJCALLSTACKUP), |
Evan Cheng | d5b03f2 | 2011-06-28 21:14:33 +0000 | [diff] [blame] | 44 | TM(tm), RI(*TM.getSubtargetImpl(), *this) {} |
Chris Lattner | b1d26f6 | 2006-06-17 00:01:04 +0000 | [diff] [blame] | 45 | |
Andrew Trick | 2da8bc8 | 2010-12-24 05:03:26 +0000 | [diff] [blame] | 46 | /// CreateTargetHazardRecognizer - Return the hazard recognizer to use for |
| 47 | /// this target when scheduling the DAG. |
| 48 | ScheduleHazardRecognizer *PPCInstrInfo::CreateTargetHazardRecognizer( |
| 49 | const TargetMachine *TM, |
| 50 | const ScheduleDAG *DAG) const { |
Hal Finkel | c6d08f1 | 2011-10-17 04:03:49 +0000 | [diff] [blame] | 51 | unsigned Directive = TM->getSubtarget<PPCSubtarget>().getDarwinDirective(); |
| 52 | if (Directive == PPC::DIR_440) { |
Hal Finkel | 768c65f | 2011-11-22 16:21:04 +0000 | [diff] [blame] | 53 | const InstrItineraryData *II = TM->getInstrItineraryData(); |
| 54 | return new PPCHazardRecognizer440(II, DAG); |
Hal Finkel | c6d08f1 | 2011-10-17 04:03:49 +0000 | [diff] [blame] | 55 | } |
Hal Finkel | 64c34e2 | 2011-12-02 04:58:02 +0000 | [diff] [blame] | 56 | |
| 57 | return TargetInstrInfoImpl::CreateTargetHazardRecognizer(TM, DAG); |
Andrew Trick | 2da8bc8 | 2010-12-24 05:03:26 +0000 | [diff] [blame] | 58 | } |
| 59 | |
Hal Finkel | 64c34e2 | 2011-12-02 04:58:02 +0000 | [diff] [blame] | 60 | /// CreateTargetPostRAHazardRecognizer - Return the postRA hazard recognizer |
| 61 | /// to use for this target when scheduling the DAG. |
| 62 | ScheduleHazardRecognizer *PPCInstrInfo::CreateTargetPostRAHazardRecognizer( |
| 63 | const InstrItineraryData *II, |
| 64 | const ScheduleDAG *DAG) const { |
| 65 | unsigned Directive = TM.getSubtarget<PPCSubtarget>().getDarwinDirective(); |
| 66 | |
| 67 | // Most subtargets use a PPC970 recognizer. |
| 68 | if (Directive != PPC::DIR_440) { |
| 69 | const TargetInstrInfo *TII = TM.getInstrInfo(); |
| 70 | assert(TII && "No InstrInfo?"); |
| 71 | |
| 72 | return new PPCHazardRecognizer970(*TII); |
| 73 | } |
| 74 | |
| 75 | return TargetInstrInfoImpl::CreateTargetPostRAHazardRecognizer(II, DAG); |
| 76 | } |
Andrew Trick | 6e8f4c4 | 2010-12-24 04:28:06 +0000 | [diff] [blame] | 77 | unsigned PPCInstrInfo::isLoadFromStackSlot(const MachineInstr *MI, |
Chris Lattner | 9c09c9e | 2006-03-16 22:24:02 +0000 | [diff] [blame] | 78 | int &FrameIndex) const { |
Chris Lattner | 4083960 | 2006-02-02 20:12:32 +0000 | [diff] [blame] | 79 | switch (MI->getOpcode()) { |
| 80 | default: break; |
| 81 | case PPC::LD: |
| 82 | case PPC::LWZ: |
| 83 | case PPC::LFS: |
| 84 | case PPC::LFD: |
Dan Gohman | d735b80 | 2008-10-03 15:45:36 +0000 | [diff] [blame] | 85 | if (MI->getOperand(1).isImm() && !MI->getOperand(1).getImm() && |
| 86 | MI->getOperand(2).isFI()) { |
Chris Lattner | 8aa797a | 2007-12-30 23:10:15 +0000 | [diff] [blame] | 87 | FrameIndex = MI->getOperand(2).getIndex(); |
Chris Lattner | 4083960 | 2006-02-02 20:12:32 +0000 | [diff] [blame] | 88 | return MI->getOperand(0).getReg(); |
| 89 | } |
| 90 | break; |
| 91 | } |
| 92 | return 0; |
Chris Lattner | 6524287 | 2006-02-02 20:16:12 +0000 | [diff] [blame] | 93 | } |
Chris Lattner | 4083960 | 2006-02-02 20:12:32 +0000 | [diff] [blame] | 94 | |
Andrew Trick | 6e8f4c4 | 2010-12-24 04:28:06 +0000 | [diff] [blame] | 95 | unsigned PPCInstrInfo::isStoreToStackSlot(const MachineInstr *MI, |
Chris Lattner | 6524287 | 2006-02-02 20:16:12 +0000 | [diff] [blame] | 96 | int &FrameIndex) const { |
| 97 | switch (MI->getOpcode()) { |
| 98 | default: break; |
Nate Begeman | 3b478b3 | 2006-02-02 21:07:50 +0000 | [diff] [blame] | 99 | case PPC::STD: |
Chris Lattner | 6524287 | 2006-02-02 20:16:12 +0000 | [diff] [blame] | 100 | case PPC::STW: |
| 101 | case PPC::STFS: |
| 102 | case PPC::STFD: |
Dan Gohman | d735b80 | 2008-10-03 15:45:36 +0000 | [diff] [blame] | 103 | if (MI->getOperand(1).isImm() && !MI->getOperand(1).getImm() && |
| 104 | MI->getOperand(2).isFI()) { |
Chris Lattner | 8aa797a | 2007-12-30 23:10:15 +0000 | [diff] [blame] | 105 | FrameIndex = MI->getOperand(2).getIndex(); |
Chris Lattner | 6524287 | 2006-02-02 20:16:12 +0000 | [diff] [blame] | 106 | return MI->getOperand(0).getReg(); |
| 107 | } |
| 108 | break; |
| 109 | } |
| 110 | return 0; |
| 111 | } |
Chris Lattner | 4083960 | 2006-02-02 20:12:32 +0000 | [diff] [blame] | 112 | |
Chris Lattner | 043870d | 2005-09-09 18:17:41 +0000 | [diff] [blame] | 113 | // commuteInstruction - We can commute rlwimi instructions, but only if the |
| 114 | // rotate amt is zero. We also have to munge the immediates a bit. |
Evan Cheng | 58dcb0e | 2008-06-16 07:33:11 +0000 | [diff] [blame] | 115 | MachineInstr * |
| 116 | PPCInstrInfo::commuteInstruction(MachineInstr *MI, bool NewMI) const { |
Dan Gohman | 8e5f2c6 | 2008-07-07 23:14:23 +0000 | [diff] [blame] | 117 | MachineFunction &MF = *MI->getParent()->getParent(); |
| 118 | |
Chris Lattner | 043870d | 2005-09-09 18:17:41 +0000 | [diff] [blame] | 119 | // Normal instructions can be commuted the obvious way. |
| 120 | if (MI->getOpcode() != PPC::RLWIMI) |
Evan Cheng | 58dcb0e | 2008-06-16 07:33:11 +0000 | [diff] [blame] | 121 | return TargetInstrInfoImpl::commuteInstruction(MI, NewMI); |
Andrew Trick | 6e8f4c4 | 2010-12-24 04:28:06 +0000 | [diff] [blame] | 122 | |
Chris Lattner | 043870d | 2005-09-09 18:17:41 +0000 | [diff] [blame] | 123 | // Cannot commute if it has a non-zero rotate count. |
Chris Lattner | 9a1ceae | 2007-12-30 20:49:49 +0000 | [diff] [blame] | 124 | if (MI->getOperand(3).getImm() != 0) |
Chris Lattner | 043870d | 2005-09-09 18:17:41 +0000 | [diff] [blame] | 125 | return 0; |
Andrew Trick | 6e8f4c4 | 2010-12-24 04:28:06 +0000 | [diff] [blame] | 126 | |
Chris Lattner | 043870d | 2005-09-09 18:17:41 +0000 | [diff] [blame] | 127 | // If we have a zero rotate count, we have: |
| 128 | // M = mask(MB,ME) |
| 129 | // Op0 = (Op1 & ~M) | (Op2 & M) |
| 130 | // Change this to: |
| 131 | // M = mask((ME+1)&31, (MB-1)&31) |
| 132 | // Op0 = (Op2 & ~M) | (Op1 & M) |
| 133 | |
| 134 | // Swap op1/op2 |
Evan Cheng | a4d16a1 | 2008-02-13 02:46:49 +0000 | [diff] [blame] | 135 | unsigned Reg0 = MI->getOperand(0).getReg(); |
Chris Lattner | 043870d | 2005-09-09 18:17:41 +0000 | [diff] [blame] | 136 | unsigned Reg1 = MI->getOperand(1).getReg(); |
| 137 | unsigned Reg2 = MI->getOperand(2).getReg(); |
Evan Cheng | 6ce7dc2 | 2006-11-15 20:58:11 +0000 | [diff] [blame] | 138 | bool Reg1IsKill = MI->getOperand(1).isKill(); |
| 139 | bool Reg2IsKill = MI->getOperand(2).isKill(); |
Evan Cheng | 58dcb0e | 2008-06-16 07:33:11 +0000 | [diff] [blame] | 140 | bool ChangeReg0 = false; |
Evan Cheng | a4d16a1 | 2008-02-13 02:46:49 +0000 | [diff] [blame] | 141 | // If machine instrs are no longer in two-address forms, update |
| 142 | // destination register as well. |
| 143 | if (Reg0 == Reg1) { |
| 144 | // Must be two address instruction! |
Evan Cheng | e837dea | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 145 | assert(MI->getDesc().getOperandConstraint(0, MCOI::TIED_TO) && |
Evan Cheng | a4d16a1 | 2008-02-13 02:46:49 +0000 | [diff] [blame] | 146 | "Expecting a two-address instruction!"); |
Evan Cheng | a4d16a1 | 2008-02-13 02:46:49 +0000 | [diff] [blame] | 147 | Reg2IsKill = false; |
Evan Cheng | 58dcb0e | 2008-06-16 07:33:11 +0000 | [diff] [blame] | 148 | ChangeReg0 = true; |
Evan Cheng | a4d16a1 | 2008-02-13 02:46:49 +0000 | [diff] [blame] | 149 | } |
Evan Cheng | 58dcb0e | 2008-06-16 07:33:11 +0000 | [diff] [blame] | 150 | |
| 151 | // Masks. |
| 152 | unsigned MB = MI->getOperand(4).getImm(); |
| 153 | unsigned ME = MI->getOperand(5).getImm(); |
| 154 | |
| 155 | if (NewMI) { |
| 156 | // Create a new instruction. |
| 157 | unsigned Reg0 = ChangeReg0 ? Reg2 : MI->getOperand(0).getReg(); |
| 158 | bool Reg0IsDead = MI->getOperand(0).isDead(); |
Bill Wendling | d1c321a | 2009-02-12 00:02:55 +0000 | [diff] [blame] | 159 | return BuildMI(MF, MI->getDebugLoc(), MI->getDesc()) |
Bill Wendling | 587daed | 2009-05-13 21:33:08 +0000 | [diff] [blame] | 160 | .addReg(Reg0, RegState::Define | getDeadRegState(Reg0IsDead)) |
| 161 | .addReg(Reg2, getKillRegState(Reg2IsKill)) |
| 162 | .addReg(Reg1, getKillRegState(Reg1IsKill)) |
Evan Cheng | 58dcb0e | 2008-06-16 07:33:11 +0000 | [diff] [blame] | 163 | .addImm((ME+1) & 31) |
| 164 | .addImm((MB-1) & 31); |
| 165 | } |
| 166 | |
| 167 | if (ChangeReg0) |
| 168 | MI->getOperand(0).setReg(Reg2); |
Chris Lattner | e53f4a0 | 2006-05-04 17:52:23 +0000 | [diff] [blame] | 169 | MI->getOperand(2).setReg(Reg1); |
| 170 | MI->getOperand(1).setReg(Reg2); |
Chris Lattner | f738230 | 2007-12-30 21:56:09 +0000 | [diff] [blame] | 171 | MI->getOperand(2).setIsKill(Reg1IsKill); |
| 172 | MI->getOperand(1).setIsKill(Reg2IsKill); |
Andrew Trick | 6e8f4c4 | 2010-12-24 04:28:06 +0000 | [diff] [blame] | 173 | |
Chris Lattner | 043870d | 2005-09-09 18:17:41 +0000 | [diff] [blame] | 174 | // Swap the mask around. |
Chris Lattner | 9a1ceae | 2007-12-30 20:49:49 +0000 | [diff] [blame] | 175 | MI->getOperand(4).setImm((ME+1) & 31); |
| 176 | MI->getOperand(5).setImm((MB-1) & 31); |
Chris Lattner | 043870d | 2005-09-09 18:17:41 +0000 | [diff] [blame] | 177 | return MI; |
| 178 | } |
Chris Lattner | bbf1c72 | 2006-03-05 23:49:55 +0000 | [diff] [blame] | 179 | |
Andrew Trick | 6e8f4c4 | 2010-12-24 04:28:06 +0000 | [diff] [blame] | 180 | void PPCInstrInfo::insertNoop(MachineBasicBlock &MBB, |
Chris Lattner | bbf1c72 | 2006-03-05 23:49:55 +0000 | [diff] [blame] | 181 | MachineBasicBlock::iterator MI) const { |
Chris Lattner | c7f3ace | 2010-04-02 20:16:16 +0000 | [diff] [blame] | 182 | DebugLoc DL; |
Bill Wendling | d1c321a | 2009-02-12 00:02:55 +0000 | [diff] [blame] | 183 | BuildMI(MBB, MI, DL, get(PPC::NOP)); |
Chris Lattner | bbf1c72 | 2006-03-05 23:49:55 +0000 | [diff] [blame] | 184 | } |
Chris Lattner | c50e2bc | 2006-10-13 21:21:17 +0000 | [diff] [blame] | 185 | |
| 186 | |
| 187 | // Branch analysis. |
| 188 | bool PPCInstrInfo::AnalyzeBranch(MachineBasicBlock &MBB,MachineBasicBlock *&TBB, |
| 189 | MachineBasicBlock *&FBB, |
Evan Cheng | dc54d31 | 2009-02-09 07:14:22 +0000 | [diff] [blame] | 190 | SmallVectorImpl<MachineOperand> &Cond, |
| 191 | bool AllowModify) const { |
Chris Lattner | c50e2bc | 2006-10-13 21:21:17 +0000 | [diff] [blame] | 192 | // If the block has no terminators, it just falls into the block after it. |
| 193 | MachineBasicBlock::iterator I = MBB.end(); |
Dale Johannesen | 93d6a7e | 2010-04-02 01:38:09 +0000 | [diff] [blame] | 194 | if (I == MBB.begin()) |
| 195 | return false; |
| 196 | --I; |
| 197 | while (I->isDebugValue()) { |
| 198 | if (I == MBB.begin()) |
| 199 | return false; |
| 200 | --I; |
| 201 | } |
| 202 | if (!isUnpredicatedTerminator(I)) |
Chris Lattner | c50e2bc | 2006-10-13 21:21:17 +0000 | [diff] [blame] | 203 | return false; |
| 204 | |
| 205 | // Get the last instruction in the block. |
| 206 | MachineInstr *LastInst = I; |
Andrew Trick | 6e8f4c4 | 2010-12-24 04:28:06 +0000 | [diff] [blame] | 207 | |
Chris Lattner | c50e2bc | 2006-10-13 21:21:17 +0000 | [diff] [blame] | 208 | // If there is only one terminator instruction, process it. |
Evan Cheng | bfd2ec4 | 2007-06-08 21:59:56 +0000 | [diff] [blame] | 209 | if (I == MBB.begin() || !isUnpredicatedTerminator(--I)) { |
Chris Lattner | c50e2bc | 2006-10-13 21:21:17 +0000 | [diff] [blame] | 210 | if (LastInst->getOpcode() == PPC::B) { |
Evan Cheng | 82ae933 | 2009-05-08 23:09:25 +0000 | [diff] [blame] | 211 | if (!LastInst->getOperand(0).isMBB()) |
| 212 | return true; |
Chris Lattner | 8aa797a | 2007-12-30 23:10:15 +0000 | [diff] [blame] | 213 | TBB = LastInst->getOperand(0).getMBB(); |
Chris Lattner | c50e2bc | 2006-10-13 21:21:17 +0000 | [diff] [blame] | 214 | return false; |
Chris Lattner | 289c2d5 | 2006-11-17 22:14:47 +0000 | [diff] [blame] | 215 | } else if (LastInst->getOpcode() == PPC::BCC) { |
Evan Cheng | 82ae933 | 2009-05-08 23:09:25 +0000 | [diff] [blame] | 216 | if (!LastInst->getOperand(2).isMBB()) |
| 217 | return true; |
Chris Lattner | c50e2bc | 2006-10-13 21:21:17 +0000 | [diff] [blame] | 218 | // Block ends with fall-through condbranch. |
Chris Lattner | 8aa797a | 2007-12-30 23:10:15 +0000 | [diff] [blame] | 219 | TBB = LastInst->getOperand(2).getMBB(); |
Chris Lattner | c50e2bc | 2006-10-13 21:21:17 +0000 | [diff] [blame] | 220 | Cond.push_back(LastInst->getOperand(0)); |
| 221 | Cond.push_back(LastInst->getOperand(1)); |
Chris Lattner | 7c4fe25 | 2006-10-21 06:03:11 +0000 | [diff] [blame] | 222 | return false; |
Chris Lattner | c50e2bc | 2006-10-13 21:21:17 +0000 | [diff] [blame] | 223 | } |
| 224 | // Otherwise, don't know what this is. |
| 225 | return true; |
| 226 | } |
Andrew Trick | 6e8f4c4 | 2010-12-24 04:28:06 +0000 | [diff] [blame] | 227 | |
Chris Lattner | c50e2bc | 2006-10-13 21:21:17 +0000 | [diff] [blame] | 228 | // Get the instruction before it if it's a terminator. |
| 229 | MachineInstr *SecondLastInst = I; |
| 230 | |
| 231 | // If there are three terminators, we don't know what sort of block this is. |
| 232 | if (SecondLastInst && I != MBB.begin() && |
Evan Cheng | bfd2ec4 | 2007-06-08 21:59:56 +0000 | [diff] [blame] | 233 | isUnpredicatedTerminator(--I)) |
Chris Lattner | c50e2bc | 2006-10-13 21:21:17 +0000 | [diff] [blame] | 234 | return true; |
Andrew Trick | 6e8f4c4 | 2010-12-24 04:28:06 +0000 | [diff] [blame] | 235 | |
Chris Lattner | 289c2d5 | 2006-11-17 22:14:47 +0000 | [diff] [blame] | 236 | // If the block ends with PPC::B and PPC:BCC, handle it. |
Andrew Trick | 6e8f4c4 | 2010-12-24 04:28:06 +0000 | [diff] [blame] | 237 | if (SecondLastInst->getOpcode() == PPC::BCC && |
Chris Lattner | c50e2bc | 2006-10-13 21:21:17 +0000 | [diff] [blame] | 238 | LastInst->getOpcode() == PPC::B) { |
Evan Cheng | 82ae933 | 2009-05-08 23:09:25 +0000 | [diff] [blame] | 239 | if (!SecondLastInst->getOperand(2).isMBB() || |
| 240 | !LastInst->getOperand(0).isMBB()) |
| 241 | return true; |
Chris Lattner | 8aa797a | 2007-12-30 23:10:15 +0000 | [diff] [blame] | 242 | TBB = SecondLastInst->getOperand(2).getMBB(); |
Chris Lattner | c50e2bc | 2006-10-13 21:21:17 +0000 | [diff] [blame] | 243 | Cond.push_back(SecondLastInst->getOperand(0)); |
| 244 | Cond.push_back(SecondLastInst->getOperand(1)); |
Chris Lattner | 8aa797a | 2007-12-30 23:10:15 +0000 | [diff] [blame] | 245 | FBB = LastInst->getOperand(0).getMBB(); |
Chris Lattner | c50e2bc | 2006-10-13 21:21:17 +0000 | [diff] [blame] | 246 | return false; |
| 247 | } |
Andrew Trick | 6e8f4c4 | 2010-12-24 04:28:06 +0000 | [diff] [blame] | 248 | |
Dale Johannesen | 13e8b51 | 2007-06-13 17:59:52 +0000 | [diff] [blame] | 249 | // If the block ends with two PPC:Bs, handle it. The second one is not |
| 250 | // executed, so remove it. |
Andrew Trick | 6e8f4c4 | 2010-12-24 04:28:06 +0000 | [diff] [blame] | 251 | if (SecondLastInst->getOpcode() == PPC::B && |
Dale Johannesen | 13e8b51 | 2007-06-13 17:59:52 +0000 | [diff] [blame] | 252 | LastInst->getOpcode() == PPC::B) { |
Evan Cheng | 82ae933 | 2009-05-08 23:09:25 +0000 | [diff] [blame] | 253 | if (!SecondLastInst->getOperand(0).isMBB()) |
| 254 | return true; |
Chris Lattner | 8aa797a | 2007-12-30 23:10:15 +0000 | [diff] [blame] | 255 | TBB = SecondLastInst->getOperand(0).getMBB(); |
Dale Johannesen | 13e8b51 | 2007-06-13 17:59:52 +0000 | [diff] [blame] | 256 | I = LastInst; |
Evan Cheng | dc54d31 | 2009-02-09 07:14:22 +0000 | [diff] [blame] | 257 | if (AllowModify) |
| 258 | I->eraseFromParent(); |
Dale Johannesen | 13e8b51 | 2007-06-13 17:59:52 +0000 | [diff] [blame] | 259 | return false; |
| 260 | } |
| 261 | |
Chris Lattner | c50e2bc | 2006-10-13 21:21:17 +0000 | [diff] [blame] | 262 | // Otherwise, can't handle this. |
| 263 | return true; |
| 264 | } |
| 265 | |
Evan Cheng | b5cdaa2 | 2007-05-18 00:05:48 +0000 | [diff] [blame] | 266 | unsigned PPCInstrInfo::RemoveBranch(MachineBasicBlock &MBB) const { |
Chris Lattner | c50e2bc | 2006-10-13 21:21:17 +0000 | [diff] [blame] | 267 | MachineBasicBlock::iterator I = MBB.end(); |
Evan Cheng | b5cdaa2 | 2007-05-18 00:05:48 +0000 | [diff] [blame] | 268 | if (I == MBB.begin()) return 0; |
Chris Lattner | c50e2bc | 2006-10-13 21:21:17 +0000 | [diff] [blame] | 269 | --I; |
Dale Johannesen | 93d6a7e | 2010-04-02 01:38:09 +0000 | [diff] [blame] | 270 | while (I->isDebugValue()) { |
| 271 | if (I == MBB.begin()) |
| 272 | return 0; |
| 273 | --I; |
| 274 | } |
Chris Lattner | 289c2d5 | 2006-11-17 22:14:47 +0000 | [diff] [blame] | 275 | if (I->getOpcode() != PPC::B && I->getOpcode() != PPC::BCC) |
Evan Cheng | b5cdaa2 | 2007-05-18 00:05:48 +0000 | [diff] [blame] | 276 | return 0; |
Andrew Trick | 6e8f4c4 | 2010-12-24 04:28:06 +0000 | [diff] [blame] | 277 | |
Chris Lattner | c50e2bc | 2006-10-13 21:21:17 +0000 | [diff] [blame] | 278 | // Remove the branch. |
| 279 | I->eraseFromParent(); |
Andrew Trick | 6e8f4c4 | 2010-12-24 04:28:06 +0000 | [diff] [blame] | 280 | |
Chris Lattner | c50e2bc | 2006-10-13 21:21:17 +0000 | [diff] [blame] | 281 | I = MBB.end(); |
| 282 | |
Evan Cheng | b5cdaa2 | 2007-05-18 00:05:48 +0000 | [diff] [blame] | 283 | if (I == MBB.begin()) return 1; |
Chris Lattner | c50e2bc | 2006-10-13 21:21:17 +0000 | [diff] [blame] | 284 | --I; |
Chris Lattner | 289c2d5 | 2006-11-17 22:14:47 +0000 | [diff] [blame] | 285 | if (I->getOpcode() != PPC::BCC) |
Evan Cheng | b5cdaa2 | 2007-05-18 00:05:48 +0000 | [diff] [blame] | 286 | return 1; |
Andrew Trick | 6e8f4c4 | 2010-12-24 04:28:06 +0000 | [diff] [blame] | 287 | |
Chris Lattner | c50e2bc | 2006-10-13 21:21:17 +0000 | [diff] [blame] | 288 | // Remove the branch. |
| 289 | I->eraseFromParent(); |
Evan Cheng | b5cdaa2 | 2007-05-18 00:05:48 +0000 | [diff] [blame] | 290 | return 2; |
Chris Lattner | c50e2bc | 2006-10-13 21:21:17 +0000 | [diff] [blame] | 291 | } |
| 292 | |
Evan Cheng | b5cdaa2 | 2007-05-18 00:05:48 +0000 | [diff] [blame] | 293 | unsigned |
| 294 | PPCInstrInfo::InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB, |
| 295 | MachineBasicBlock *FBB, |
Stuart Hastings | 3bf9125 | 2010-06-17 22:43:56 +0000 | [diff] [blame] | 296 | const SmallVectorImpl<MachineOperand> &Cond, |
| 297 | DebugLoc DL) const { |
Chris Lattner | 2dc7723 | 2006-10-17 18:06:55 +0000 | [diff] [blame] | 298 | // Shouldn't be a fall through. |
| 299 | assert(TBB && "InsertBranch must not be told to insert a fallthrough"); |
Andrew Trick | 6e8f4c4 | 2010-12-24 04:28:06 +0000 | [diff] [blame] | 300 | assert((Cond.size() == 2 || Cond.size() == 0) && |
Chris Lattner | 5410806 | 2006-10-21 05:36:13 +0000 | [diff] [blame] | 301 | "PPC branch conditions have two components!"); |
Andrew Trick | 6e8f4c4 | 2010-12-24 04:28:06 +0000 | [diff] [blame] | 302 | |
Chris Lattner | 5410806 | 2006-10-21 05:36:13 +0000 | [diff] [blame] | 303 | // One-way branch. |
Chris Lattner | 2dc7723 | 2006-10-17 18:06:55 +0000 | [diff] [blame] | 304 | if (FBB == 0) { |
Chris Lattner | 5410806 | 2006-10-21 05:36:13 +0000 | [diff] [blame] | 305 | if (Cond.empty()) // Unconditional branch |
Stuart Hastings | 3bf9125 | 2010-06-17 22:43:56 +0000 | [diff] [blame] | 306 | BuildMI(&MBB, DL, get(PPC::B)).addMBB(TBB); |
Chris Lattner | 5410806 | 2006-10-21 05:36:13 +0000 | [diff] [blame] | 307 | else // Conditional branch |
Stuart Hastings | 3bf9125 | 2010-06-17 22:43:56 +0000 | [diff] [blame] | 308 | BuildMI(&MBB, DL, get(PPC::BCC)) |
Chris Lattner | 18258c6 | 2006-11-17 22:37:34 +0000 | [diff] [blame] | 309 | .addImm(Cond[0].getImm()).addReg(Cond[1].getReg()).addMBB(TBB); |
Evan Cheng | b5cdaa2 | 2007-05-18 00:05:48 +0000 | [diff] [blame] | 310 | return 1; |
Chris Lattner | 2dc7723 | 2006-10-17 18:06:55 +0000 | [diff] [blame] | 311 | } |
Andrew Trick | 6e8f4c4 | 2010-12-24 04:28:06 +0000 | [diff] [blame] | 312 | |
Chris Lattner | 879d09c | 2006-10-21 05:42:09 +0000 | [diff] [blame] | 313 | // Two-way Conditional Branch. |
Stuart Hastings | 3bf9125 | 2010-06-17 22:43:56 +0000 | [diff] [blame] | 314 | BuildMI(&MBB, DL, get(PPC::BCC)) |
Chris Lattner | 18258c6 | 2006-11-17 22:37:34 +0000 | [diff] [blame] | 315 | .addImm(Cond[0].getImm()).addReg(Cond[1].getReg()).addMBB(TBB); |
Stuart Hastings | 3bf9125 | 2010-06-17 22:43:56 +0000 | [diff] [blame] | 316 | BuildMI(&MBB, DL, get(PPC::B)).addMBB(FBB); |
Evan Cheng | b5cdaa2 | 2007-05-18 00:05:48 +0000 | [diff] [blame] | 317 | return 2; |
Chris Lattner | c50e2bc | 2006-10-13 21:21:17 +0000 | [diff] [blame] | 318 | } |
| 319 | |
Jakob Stoklund Olesen | 27689b0 | 2010-07-11 07:31:00 +0000 | [diff] [blame] | 320 | void PPCInstrInfo::copyPhysReg(MachineBasicBlock &MBB, |
| 321 | MachineBasicBlock::iterator I, DebugLoc DL, |
| 322 | unsigned DestReg, unsigned SrcReg, |
| 323 | bool KillSrc) const { |
| 324 | unsigned Opc; |
| 325 | if (PPC::GPRCRegClass.contains(DestReg, SrcReg)) |
| 326 | Opc = PPC::OR; |
| 327 | else if (PPC::G8RCRegClass.contains(DestReg, SrcReg)) |
| 328 | Opc = PPC::OR8; |
| 329 | else if (PPC::F4RCRegClass.contains(DestReg, SrcReg)) |
| 330 | Opc = PPC::FMR; |
| 331 | else if (PPC::CRRCRegClass.contains(DestReg, SrcReg)) |
| 332 | Opc = PPC::MCRF; |
| 333 | else if (PPC::VRRCRegClass.contains(DestReg, SrcReg)) |
| 334 | Opc = PPC::VOR; |
| 335 | else if (PPC::CRBITRCRegClass.contains(DestReg, SrcReg)) |
| 336 | Opc = PPC::CROR; |
| 337 | else |
| 338 | llvm_unreachable("Impossible reg-to-reg copy"); |
Owen Anderson | d10fd97 | 2007-12-31 06:32:00 +0000 | [diff] [blame] | 339 | |
Evan Cheng | e837dea | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 340 | const MCInstrDesc &MCID = get(Opc); |
| 341 | if (MCID.getNumOperands() == 3) |
| 342 | BuildMI(MBB, I, DL, MCID, DestReg) |
Jakob Stoklund Olesen | 27689b0 | 2010-07-11 07:31:00 +0000 | [diff] [blame] | 343 | .addReg(SrcReg).addReg(SrcReg, getKillRegState(KillSrc)); |
| 344 | else |
Evan Cheng | e837dea | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 345 | BuildMI(MBB, I, DL, MCID, DestReg).addReg(SrcReg, getKillRegState(KillSrc)); |
Owen Anderson | d10fd97 | 2007-12-31 06:32:00 +0000 | [diff] [blame] | 346 | } |
| 347 | |
Hal Finkel | 3fd0018 | 2011-12-05 17:55:17 +0000 | [diff] [blame] | 348 | // This function returns true if a CR spill is necessary and false otherwise. |
Bill Wendling | 4a66e9a | 2008-03-10 22:49:16 +0000 | [diff] [blame] | 349 | bool |
Dan Gohman | 8e5f2c6 | 2008-07-07 23:14:23 +0000 | [diff] [blame] | 350 | PPCInstrInfo::StoreRegToStackSlot(MachineFunction &MF, |
| 351 | unsigned SrcReg, bool isKill, |
Bill Wendling | 4a66e9a | 2008-03-10 22:49:16 +0000 | [diff] [blame] | 352 | int FrameIdx, |
| 353 | const TargetRegisterClass *RC, |
| 354 | SmallVectorImpl<MachineInstr*> &NewMIs) const{ |
Chris Lattner | c7f3ace | 2010-04-02 20:16:16 +0000 | [diff] [blame] | 355 | DebugLoc DL; |
Jakob Stoklund Olesen | 01faf43 | 2011-10-04 15:28:47 +0000 | [diff] [blame] | 356 | if (PPC::GPRCRegisterClass->hasSubClassEq(RC)) { |
Owen Anderson | f6372aa | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 357 | if (SrcReg != PPC::LR) { |
Dale Johannesen | 21b5541 | 2009-02-12 23:08:38 +0000 | [diff] [blame] | 358 | NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(PPC::STW)) |
Bill Wendling | 587daed | 2009-05-13 21:33:08 +0000 | [diff] [blame] | 359 | .addReg(SrcReg, |
| 360 | getKillRegState(isKill)), |
Bill Wendling | 4a66e9a | 2008-03-10 22:49:16 +0000 | [diff] [blame] | 361 | FrameIdx)); |
Owen Anderson | f6372aa | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 362 | } else { |
| 363 | // FIXME: this spills LR immediately to memory in one step. To do this, |
| 364 | // we use R11, which we know cannot be used in the prolog/epilog. This is |
| 365 | // a hack. |
Dale Johannesen | 21b5541 | 2009-02-12 23:08:38 +0000 | [diff] [blame] | 366 | NewMIs.push_back(BuildMI(MF, DL, get(PPC::MFLR), PPC::R11)); |
| 367 | NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(PPC::STW)) |
Bill Wendling | 587daed | 2009-05-13 21:33:08 +0000 | [diff] [blame] | 368 | .addReg(PPC::R11, |
| 369 | getKillRegState(isKill)), |
Bill Wendling | 4a66e9a | 2008-03-10 22:49:16 +0000 | [diff] [blame] | 370 | FrameIdx)); |
Owen Anderson | f6372aa | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 371 | } |
Jakob Stoklund Olesen | 01faf43 | 2011-10-04 15:28:47 +0000 | [diff] [blame] | 372 | } else if (PPC::G8RCRegisterClass->hasSubClassEq(RC)) { |
Owen Anderson | f6372aa | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 373 | if (SrcReg != PPC::LR8) { |
Dale Johannesen | 21b5541 | 2009-02-12 23:08:38 +0000 | [diff] [blame] | 374 | NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(PPC::STD)) |
Bill Wendling | 587daed | 2009-05-13 21:33:08 +0000 | [diff] [blame] | 375 | .addReg(SrcReg, |
| 376 | getKillRegState(isKill)), |
| 377 | FrameIdx)); |
Owen Anderson | f6372aa | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 378 | } else { |
| 379 | // FIXME: this spills LR immediately to memory in one step. To do this, |
Hal Finkel | 7ad6b7d | 2011-12-07 06:32:37 +0000 | [diff] [blame] | 380 | // we use X11, which we know cannot be used in the prolog/epilog. This is |
Owen Anderson | f6372aa | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 381 | // a hack. |
Dale Johannesen | 21b5541 | 2009-02-12 23:08:38 +0000 | [diff] [blame] | 382 | NewMIs.push_back(BuildMI(MF, DL, get(PPC::MFLR8), PPC::X11)); |
| 383 | NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(PPC::STD)) |
Bill Wendling | 587daed | 2009-05-13 21:33:08 +0000 | [diff] [blame] | 384 | .addReg(PPC::X11, |
| 385 | getKillRegState(isKill)), |
| 386 | FrameIdx)); |
Owen Anderson | f6372aa | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 387 | } |
Jakob Stoklund Olesen | 01faf43 | 2011-10-04 15:28:47 +0000 | [diff] [blame] | 388 | } else if (PPC::F8RCRegisterClass->hasSubClassEq(RC)) { |
Dale Johannesen | 21b5541 | 2009-02-12 23:08:38 +0000 | [diff] [blame] | 389 | NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(PPC::STFD)) |
Bill Wendling | 587daed | 2009-05-13 21:33:08 +0000 | [diff] [blame] | 390 | .addReg(SrcReg, |
| 391 | getKillRegState(isKill)), |
| 392 | FrameIdx)); |
Jakob Stoklund Olesen | 01faf43 | 2011-10-04 15:28:47 +0000 | [diff] [blame] | 393 | } else if (PPC::F4RCRegisterClass->hasSubClassEq(RC)) { |
Dale Johannesen | 21b5541 | 2009-02-12 23:08:38 +0000 | [diff] [blame] | 394 | NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(PPC::STFS)) |
Bill Wendling | 587daed | 2009-05-13 21:33:08 +0000 | [diff] [blame] | 395 | .addReg(SrcReg, |
| 396 | getKillRegState(isKill)), |
| 397 | FrameIdx)); |
Jakob Stoklund Olesen | 01faf43 | 2011-10-04 15:28:47 +0000 | [diff] [blame] | 398 | } else if (PPC::CRRCRegisterClass->hasSubClassEq(RC)) { |
Hal Finkel | 3fd0018 | 2011-12-05 17:55:17 +0000 | [diff] [blame] | 399 | if ((!DisablePPC32RS && !TM.getSubtargetImpl()->isPPC64()) || |
| 400 | (!DisablePPC64RS && TM.getSubtargetImpl()->isPPC64())) { |
Dale Johannesen | 21b5541 | 2009-02-12 23:08:38 +0000 | [diff] [blame] | 401 | NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(PPC::SPILL_CR)) |
Bill Wendling | 587daed | 2009-05-13 21:33:08 +0000 | [diff] [blame] | 402 | .addReg(SrcReg, |
| 403 | getKillRegState(isKill)), |
Chris Lattner | 71a2cb2 | 2008-03-20 01:22:40 +0000 | [diff] [blame] | 404 | FrameIdx)); |
Bill Wendling | 7194aaf | 2008-03-03 22:19:16 +0000 | [diff] [blame] | 405 | return true; |
| 406 | } else { |
Dale Johannesen | c12da8d | 2010-02-12 21:35:34 +0000 | [diff] [blame] | 407 | // FIXME: We need a scatch reg here. The trouble with using R0 is that |
| 408 | // it's possible for the stack frame to be so big the save location is |
| 409 | // out of range of immediate offsets, necessitating another register. |
| 410 | // We hack this on Darwin by reserving R2. It's probably broken on Linux |
| 411 | // at the moment. |
| 412 | |
Hal Finkel | 234bb38 | 2011-12-07 06:34:06 +0000 | [diff] [blame] | 413 | bool is64Bit = TM.getSubtargetImpl()->isPPC64(); |
Dale Johannesen | c12da8d | 2010-02-12 21:35:34 +0000 | [diff] [blame] | 414 | // We need to store the CR in the low 4-bits of the saved value. First, |
| 415 | // issue a MFCR to save all of the CRBits. |
Andrew Trick | 6e8f4c4 | 2010-12-24 04:28:06 +0000 | [diff] [blame] | 416 | unsigned ScratchReg = TM.getSubtargetImpl()->isDarwinABI() ? |
Hal Finkel | 234bb38 | 2011-12-07 06:34:06 +0000 | [diff] [blame] | 417 | (is64Bit ? PPC::X2 : PPC::R2) : |
| 418 | (is64Bit ? PPC::X0 : PPC::R0); |
| 419 | NewMIs.push_back(BuildMI(MF, DL, get(is64Bit ? PPC::MFCR8pseud : |
| 420 | PPC::MFCRpseud), ScratchReg) |
Dale Johannesen | 5f07d52 | 2010-05-20 17:48:26 +0000 | [diff] [blame] | 421 | .addReg(SrcReg, getKillRegState(isKill))); |
Andrew Trick | 6e8f4c4 | 2010-12-24 04:28:06 +0000 | [diff] [blame] | 422 | |
Bill Wendling | 7194aaf | 2008-03-03 22:19:16 +0000 | [diff] [blame] | 423 | // If the saved register wasn't CR0, shift the bits left so that they are |
| 424 | // in CR0's slot. |
| 425 | if (SrcReg != PPC::CR0) { |
Evan Cheng | 966aeb5 | 2011-07-25 19:53:23 +0000 | [diff] [blame] | 426 | unsigned ShiftBits = getPPCRegisterNumbering(SrcReg)*4; |
Dale Johannesen | c12da8d | 2010-02-12 21:35:34 +0000 | [diff] [blame] | 427 | // rlwinm scratch, scratch, ShiftBits, 0, 31. |
Hal Finkel | 234bb38 | 2011-12-07 06:34:06 +0000 | [diff] [blame] | 428 | NewMIs.push_back(BuildMI(MF, DL, get(is64Bit ? PPC::RLWINM8 : |
| 429 | PPC::RLWINM), ScratchReg) |
Dale Johannesen | c12da8d | 2010-02-12 21:35:34 +0000 | [diff] [blame] | 430 | .addReg(ScratchReg).addImm(ShiftBits) |
| 431 | .addImm(0).addImm(31)); |
Bill Wendling | 7194aaf | 2008-03-03 22:19:16 +0000 | [diff] [blame] | 432 | } |
Andrew Trick | 6e8f4c4 | 2010-12-24 04:28:06 +0000 | [diff] [blame] | 433 | |
Hal Finkel | 234bb38 | 2011-12-07 06:34:06 +0000 | [diff] [blame] | 434 | NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(is64Bit ? |
| 435 | PPC::STW8 : PPC::STW)) |
Dale Johannesen | c12da8d | 2010-02-12 21:35:34 +0000 | [diff] [blame] | 436 | .addReg(ScratchReg, |
Bill Wendling | 587daed | 2009-05-13 21:33:08 +0000 | [diff] [blame] | 437 | getKillRegState(isKill)), |
Bill Wendling | 7194aaf | 2008-03-03 22:19:16 +0000 | [diff] [blame] | 438 | FrameIdx)); |
Owen Anderson | f6372aa | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 439 | } |
Jakob Stoklund Olesen | 01faf43 | 2011-10-04 15:28:47 +0000 | [diff] [blame] | 440 | } else if (PPC::CRBITRCRegisterClass->hasSubClassEq(RC)) { |
Nicolas Geoffray | 0404cd9 | 2008-03-10 14:12:10 +0000 | [diff] [blame] | 441 | // FIXME: We use CRi here because there is no mtcrf on a bit. Since the |
| 442 | // backend currently only uses CR1EQ as an individual bit, this should |
| 443 | // not cause any bug. If we need other uses of CR bits, the following |
| 444 | // code may be invalid. |
Nicolas Geoffray | 9348c69 | 2008-03-10 17:46:45 +0000 | [diff] [blame] | 445 | unsigned Reg = 0; |
Tilmann Scheller | 6a3a1ba | 2009-07-03 06:47:55 +0000 | [diff] [blame] | 446 | if (SrcReg == PPC::CR0LT || SrcReg == PPC::CR0GT || |
| 447 | SrcReg == PPC::CR0EQ || SrcReg == PPC::CR0UN) |
Nicolas Geoffray | 9348c69 | 2008-03-10 17:46:45 +0000 | [diff] [blame] | 448 | Reg = PPC::CR0; |
Tilmann Scheller | 6a3a1ba | 2009-07-03 06:47:55 +0000 | [diff] [blame] | 449 | else if (SrcReg == PPC::CR1LT || SrcReg == PPC::CR1GT || |
| 450 | SrcReg == PPC::CR1EQ || SrcReg == PPC::CR1UN) |
Nicolas Geoffray | 9348c69 | 2008-03-10 17:46:45 +0000 | [diff] [blame] | 451 | Reg = PPC::CR1; |
Tilmann Scheller | 6a3a1ba | 2009-07-03 06:47:55 +0000 | [diff] [blame] | 452 | else if (SrcReg == PPC::CR2LT || SrcReg == PPC::CR2GT || |
| 453 | SrcReg == PPC::CR2EQ || SrcReg == PPC::CR2UN) |
Nicolas Geoffray | 9348c69 | 2008-03-10 17:46:45 +0000 | [diff] [blame] | 454 | Reg = PPC::CR2; |
Tilmann Scheller | 6a3a1ba | 2009-07-03 06:47:55 +0000 | [diff] [blame] | 455 | else if (SrcReg == PPC::CR3LT || SrcReg == PPC::CR3GT || |
| 456 | SrcReg == PPC::CR3EQ || SrcReg == PPC::CR3UN) |
Nicolas Geoffray | 9348c69 | 2008-03-10 17:46:45 +0000 | [diff] [blame] | 457 | Reg = PPC::CR3; |
Tilmann Scheller | 6a3a1ba | 2009-07-03 06:47:55 +0000 | [diff] [blame] | 458 | else if (SrcReg == PPC::CR4LT || SrcReg == PPC::CR4GT || |
| 459 | SrcReg == PPC::CR4EQ || SrcReg == PPC::CR4UN) |
Nicolas Geoffray | 9348c69 | 2008-03-10 17:46:45 +0000 | [diff] [blame] | 460 | Reg = PPC::CR4; |
Tilmann Scheller | 6a3a1ba | 2009-07-03 06:47:55 +0000 | [diff] [blame] | 461 | else if (SrcReg == PPC::CR5LT || SrcReg == PPC::CR5GT || |
| 462 | SrcReg == PPC::CR5EQ || SrcReg == PPC::CR5UN) |
Nicolas Geoffray | 9348c69 | 2008-03-10 17:46:45 +0000 | [diff] [blame] | 463 | Reg = PPC::CR5; |
Tilmann Scheller | 6a3a1ba | 2009-07-03 06:47:55 +0000 | [diff] [blame] | 464 | else if (SrcReg == PPC::CR6LT || SrcReg == PPC::CR6GT || |
| 465 | SrcReg == PPC::CR6EQ || SrcReg == PPC::CR6UN) |
Nicolas Geoffray | 9348c69 | 2008-03-10 17:46:45 +0000 | [diff] [blame] | 466 | Reg = PPC::CR6; |
Tilmann Scheller | 6a3a1ba | 2009-07-03 06:47:55 +0000 | [diff] [blame] | 467 | else if (SrcReg == PPC::CR7LT || SrcReg == PPC::CR7GT || |
| 468 | SrcReg == PPC::CR7EQ || SrcReg == PPC::CR7UN) |
Nicolas Geoffray | 9348c69 | 2008-03-10 17:46:45 +0000 | [diff] [blame] | 469 | Reg = PPC::CR7; |
| 470 | |
Andrew Trick | 6e8f4c4 | 2010-12-24 04:28:06 +0000 | [diff] [blame] | 471 | return StoreRegToStackSlot(MF, Reg, isKill, FrameIdx, |
Nicolas Geoffray | 9348c69 | 2008-03-10 17:46:45 +0000 | [diff] [blame] | 472 | PPC::CRRCRegisterClass, NewMIs); |
| 473 | |
Jakob Stoklund Olesen | 01faf43 | 2011-10-04 15:28:47 +0000 | [diff] [blame] | 474 | } else if (PPC::VRRCRegisterClass->hasSubClassEq(RC)) { |
Owen Anderson | f6372aa | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 475 | // We don't have indexed addressing for vector loads. Emit: |
| 476 | // R0 = ADDI FI# |
| 477 | // STVX VAL, 0, R0 |
Andrew Trick | 6e8f4c4 | 2010-12-24 04:28:06 +0000 | [diff] [blame] | 478 | // |
Owen Anderson | f6372aa | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 479 | // FIXME: We use R0 here, because it isn't available for RA. |
Dale Johannesen | 21b5541 | 2009-02-12 23:08:38 +0000 | [diff] [blame] | 480 | NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(PPC::ADDI), PPC::R0), |
Owen Anderson | f6372aa | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 481 | FrameIdx, 0, 0)); |
Dale Johannesen | 21b5541 | 2009-02-12 23:08:38 +0000 | [diff] [blame] | 482 | NewMIs.push_back(BuildMI(MF, DL, get(PPC::STVX)) |
Bill Wendling | 587daed | 2009-05-13 21:33:08 +0000 | [diff] [blame] | 483 | .addReg(SrcReg, getKillRegState(isKill)) |
| 484 | .addReg(PPC::R0) |
| 485 | .addReg(PPC::R0)); |
Owen Anderson | f6372aa | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 486 | } else { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 487 | llvm_unreachable("Unknown regclass!"); |
Owen Anderson | f6372aa | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 488 | } |
Bill Wendling | 7194aaf | 2008-03-03 22:19:16 +0000 | [diff] [blame] | 489 | |
| 490 | return false; |
Owen Anderson | f6372aa | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 491 | } |
| 492 | |
| 493 | void |
| 494 | PPCInstrInfo::storeRegToStackSlot(MachineBasicBlock &MBB, |
Bill Wendling | 7194aaf | 2008-03-03 22:19:16 +0000 | [diff] [blame] | 495 | MachineBasicBlock::iterator MI, |
| 496 | unsigned SrcReg, bool isKill, int FrameIdx, |
Evan Cheng | 746ad69 | 2010-05-06 19:06:44 +0000 | [diff] [blame] | 497 | const TargetRegisterClass *RC, |
| 498 | const TargetRegisterInfo *TRI) const { |
Dan Gohman | 8e5f2c6 | 2008-07-07 23:14:23 +0000 | [diff] [blame] | 499 | MachineFunction &MF = *MBB.getParent(); |
Owen Anderson | f6372aa | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 500 | SmallVector<MachineInstr*, 4> NewMIs; |
Bill Wendling | 7194aaf | 2008-03-03 22:19:16 +0000 | [diff] [blame] | 501 | |
Dan Gohman | 8e5f2c6 | 2008-07-07 23:14:23 +0000 | [diff] [blame] | 502 | if (StoreRegToStackSlot(MF, SrcReg, isKill, FrameIdx, RC, NewMIs)) { |
| 503 | PPCFunctionInfo *FuncInfo = MF.getInfo<PPCFunctionInfo>(); |
Bill Wendling | 7194aaf | 2008-03-03 22:19:16 +0000 | [diff] [blame] | 504 | FuncInfo->setSpillsCR(); |
| 505 | } |
| 506 | |
Owen Anderson | f6372aa | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 507 | for (unsigned i = 0, e = NewMIs.size(); i != e; ++i) |
| 508 | MBB.insert(MI, NewMIs[i]); |
Jakob Stoklund Olesen | 7a79fcb | 2010-07-16 18:22:00 +0000 | [diff] [blame] | 509 | |
| 510 | const MachineFrameInfo &MFI = *MF.getFrameInfo(); |
| 511 | MachineMemOperand *MMO = |
Jay Foad | 978e0df | 2011-11-15 07:34:52 +0000 | [diff] [blame] | 512 | MF.getMachineMemOperand(MachinePointerInfo::getFixedStack(FrameIdx), |
Chris Lattner | 59db549 | 2010-09-21 04:39:43 +0000 | [diff] [blame] | 513 | MachineMemOperand::MOStore, |
Jakob Stoklund Olesen | 7a79fcb | 2010-07-16 18:22:00 +0000 | [diff] [blame] | 514 | MFI.getObjectSize(FrameIdx), |
| 515 | MFI.getObjectAlignment(FrameIdx)); |
| 516 | NewMIs.back()->addMemOperand(MF, MMO); |
Owen Anderson | f6372aa | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 517 | } |
| 518 | |
Hal Finkel | d21e930 | 2011-12-06 20:55:36 +0000 | [diff] [blame] | 519 | bool |
Bill Wendling | d1c321a | 2009-02-12 00:02:55 +0000 | [diff] [blame] | 520 | PPCInstrInfo::LoadRegFromStackSlot(MachineFunction &MF, DebugLoc DL, |
Dan Gohman | 8e5f2c6 | 2008-07-07 23:14:23 +0000 | [diff] [blame] | 521 | unsigned DestReg, int FrameIdx, |
Bill Wendling | 4a66e9a | 2008-03-10 22:49:16 +0000 | [diff] [blame] | 522 | const TargetRegisterClass *RC, |
| 523 | SmallVectorImpl<MachineInstr*> &NewMIs)const{ |
Jakob Stoklund Olesen | 01faf43 | 2011-10-04 15:28:47 +0000 | [diff] [blame] | 524 | if (PPC::GPRCRegisterClass->hasSubClassEq(RC)) { |
Owen Anderson | f6372aa | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 525 | if (DestReg != PPC::LR) { |
Bill Wendling | d1c321a | 2009-02-12 00:02:55 +0000 | [diff] [blame] | 526 | NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(PPC::LWZ), |
| 527 | DestReg), FrameIdx)); |
Owen Anderson | f6372aa | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 528 | } else { |
Bill Wendling | d1c321a | 2009-02-12 00:02:55 +0000 | [diff] [blame] | 529 | NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(PPC::LWZ), |
| 530 | PPC::R11), FrameIdx)); |
| 531 | NewMIs.push_back(BuildMI(MF, DL, get(PPC::MTLR)).addReg(PPC::R11)); |
Owen Anderson | f6372aa | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 532 | } |
Jakob Stoklund Olesen | 01faf43 | 2011-10-04 15:28:47 +0000 | [diff] [blame] | 533 | } else if (PPC::G8RCRegisterClass->hasSubClassEq(RC)) { |
Owen Anderson | f6372aa | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 534 | if (DestReg != PPC::LR8) { |
Bill Wendling | d1c321a | 2009-02-12 00:02:55 +0000 | [diff] [blame] | 535 | NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(PPC::LD), DestReg), |
Owen Anderson | f6372aa | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 536 | FrameIdx)); |
| 537 | } else { |
Bill Wendling | d1c321a | 2009-02-12 00:02:55 +0000 | [diff] [blame] | 538 | NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(PPC::LD), |
Hal Finkel | 7ad6b7d | 2011-12-07 06:32:37 +0000 | [diff] [blame] | 539 | PPC::X11), FrameIdx)); |
| 540 | NewMIs.push_back(BuildMI(MF, DL, get(PPC::MTLR8)).addReg(PPC::X11)); |
Owen Anderson | f6372aa | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 541 | } |
Jakob Stoklund Olesen | 01faf43 | 2011-10-04 15:28:47 +0000 | [diff] [blame] | 542 | } else if (PPC::F8RCRegisterClass->hasSubClassEq(RC)) { |
Bill Wendling | d1c321a | 2009-02-12 00:02:55 +0000 | [diff] [blame] | 543 | NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(PPC::LFD), DestReg), |
Owen Anderson | f6372aa | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 544 | FrameIdx)); |
Jakob Stoklund Olesen | 01faf43 | 2011-10-04 15:28:47 +0000 | [diff] [blame] | 545 | } else if (PPC::F4RCRegisterClass->hasSubClassEq(RC)) { |
Bill Wendling | d1c321a | 2009-02-12 00:02:55 +0000 | [diff] [blame] | 546 | NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(PPC::LFS), DestReg), |
Owen Anderson | f6372aa | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 547 | FrameIdx)); |
Jakob Stoklund Olesen | 01faf43 | 2011-10-04 15:28:47 +0000 | [diff] [blame] | 548 | } else if (PPC::CRRCRegisterClass->hasSubClassEq(RC)) { |
Hal Finkel | d21e930 | 2011-12-06 20:55:36 +0000 | [diff] [blame] | 549 | if ((!DisablePPC32RS && !TM.getSubtargetImpl()->isPPC64()) || |
| 550 | (!DisablePPC64RS && TM.getSubtargetImpl()->isPPC64())) { |
| 551 | NewMIs.push_back(addFrameReference(BuildMI(MF, DL, |
| 552 | get(PPC::RESTORE_CR), DestReg) |
| 553 | , FrameIdx)); |
| 554 | return true; |
| 555 | } else { |
| 556 | // FIXME: We need a scatch reg here. The trouble with using R0 is that |
| 557 | // it's possible for the stack frame to be so big the save location is |
| 558 | // out of range of immediate offsets, necessitating another register. |
| 559 | // We hack this on Darwin by reserving R2. It's probably broken on Linux |
| 560 | // at the moment. |
| 561 | unsigned ScratchReg = TM.getSubtargetImpl()->isDarwinABI() ? |
| 562 | PPC::R2 : PPC::R0; |
| 563 | NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(PPC::LWZ), |
| 564 | ScratchReg), FrameIdx)); |
| 565 | |
| 566 | // If the reloaded register isn't CR0, shift the bits right so that they are |
| 567 | // in the right CR's slot. |
| 568 | if (DestReg != PPC::CR0) { |
| 569 | unsigned ShiftBits = getPPCRegisterNumbering(DestReg)*4; |
| 570 | // rlwinm r11, r11, 32-ShiftBits, 0, 31. |
| 571 | NewMIs.push_back(BuildMI(MF, DL, get(PPC::RLWINM), ScratchReg) |
| 572 | .addReg(ScratchReg).addImm(32-ShiftBits).addImm(0) |
| 573 | .addImm(31)); |
| 574 | } |
| 575 | |
Hal Finkel | 234bb38 | 2011-12-07 06:34:06 +0000 | [diff] [blame] | 576 | NewMIs.push_back(BuildMI(MF, DL, get(TM.getSubtargetImpl()->isPPC64() ? |
| 577 | PPC::MTCRF8 : PPC::MTCRF), DestReg) |
Hal Finkel | d21e930 | 2011-12-06 20:55:36 +0000 | [diff] [blame] | 578 | .addReg(ScratchReg)); |
Owen Anderson | f6372aa | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 579 | } |
Jakob Stoklund Olesen | 01faf43 | 2011-10-04 15:28:47 +0000 | [diff] [blame] | 580 | } else if (PPC::CRBITRCRegisterClass->hasSubClassEq(RC)) { |
Andrew Trick | 6e8f4c4 | 2010-12-24 04:28:06 +0000 | [diff] [blame] | 581 | |
Nicolas Geoffray | 9348c69 | 2008-03-10 17:46:45 +0000 | [diff] [blame] | 582 | unsigned Reg = 0; |
Tilmann Scheller | 6a3a1ba | 2009-07-03 06:47:55 +0000 | [diff] [blame] | 583 | if (DestReg == PPC::CR0LT || DestReg == PPC::CR0GT || |
| 584 | DestReg == PPC::CR0EQ || DestReg == PPC::CR0UN) |
Nicolas Geoffray | 9348c69 | 2008-03-10 17:46:45 +0000 | [diff] [blame] | 585 | Reg = PPC::CR0; |
Tilmann Scheller | 6a3a1ba | 2009-07-03 06:47:55 +0000 | [diff] [blame] | 586 | else if (DestReg == PPC::CR1LT || DestReg == PPC::CR1GT || |
| 587 | DestReg == PPC::CR1EQ || DestReg == PPC::CR1UN) |
Nicolas Geoffray | 9348c69 | 2008-03-10 17:46:45 +0000 | [diff] [blame] | 588 | Reg = PPC::CR1; |
Tilmann Scheller | 6a3a1ba | 2009-07-03 06:47:55 +0000 | [diff] [blame] | 589 | else if (DestReg == PPC::CR2LT || DestReg == PPC::CR2GT || |
| 590 | DestReg == PPC::CR2EQ || DestReg == PPC::CR2UN) |
Nicolas Geoffray | 9348c69 | 2008-03-10 17:46:45 +0000 | [diff] [blame] | 591 | Reg = PPC::CR2; |
Tilmann Scheller | 6a3a1ba | 2009-07-03 06:47:55 +0000 | [diff] [blame] | 592 | else if (DestReg == PPC::CR3LT || DestReg == PPC::CR3GT || |
| 593 | DestReg == PPC::CR3EQ || DestReg == PPC::CR3UN) |
Nicolas Geoffray | 9348c69 | 2008-03-10 17:46:45 +0000 | [diff] [blame] | 594 | Reg = PPC::CR3; |
Tilmann Scheller | 6a3a1ba | 2009-07-03 06:47:55 +0000 | [diff] [blame] | 595 | else if (DestReg == PPC::CR4LT || DestReg == PPC::CR4GT || |
| 596 | DestReg == PPC::CR4EQ || DestReg == PPC::CR4UN) |
Nicolas Geoffray | 9348c69 | 2008-03-10 17:46:45 +0000 | [diff] [blame] | 597 | Reg = PPC::CR4; |
Tilmann Scheller | 6a3a1ba | 2009-07-03 06:47:55 +0000 | [diff] [blame] | 598 | else if (DestReg == PPC::CR5LT || DestReg == PPC::CR5GT || |
| 599 | DestReg == PPC::CR5EQ || DestReg == PPC::CR5UN) |
Nicolas Geoffray | 9348c69 | 2008-03-10 17:46:45 +0000 | [diff] [blame] | 600 | Reg = PPC::CR5; |
Tilmann Scheller | 6a3a1ba | 2009-07-03 06:47:55 +0000 | [diff] [blame] | 601 | else if (DestReg == PPC::CR6LT || DestReg == PPC::CR6GT || |
| 602 | DestReg == PPC::CR6EQ || DestReg == PPC::CR6UN) |
Nicolas Geoffray | 9348c69 | 2008-03-10 17:46:45 +0000 | [diff] [blame] | 603 | Reg = PPC::CR6; |
Tilmann Scheller | 6a3a1ba | 2009-07-03 06:47:55 +0000 | [diff] [blame] | 604 | else if (DestReg == PPC::CR7LT || DestReg == PPC::CR7GT || |
| 605 | DestReg == PPC::CR7EQ || DestReg == PPC::CR7UN) |
Nicolas Geoffray | 9348c69 | 2008-03-10 17:46:45 +0000 | [diff] [blame] | 606 | Reg = PPC::CR7; |
| 607 | |
Andrew Trick | 6e8f4c4 | 2010-12-24 04:28:06 +0000 | [diff] [blame] | 608 | return LoadRegFromStackSlot(MF, DL, Reg, FrameIdx, |
Nicolas Geoffray | 9348c69 | 2008-03-10 17:46:45 +0000 | [diff] [blame] | 609 | PPC::CRRCRegisterClass, NewMIs); |
| 610 | |
Jakob Stoklund Olesen | 01faf43 | 2011-10-04 15:28:47 +0000 | [diff] [blame] | 611 | } else if (PPC::VRRCRegisterClass->hasSubClassEq(RC)) { |
Owen Anderson | f6372aa | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 612 | // We don't have indexed addressing for vector loads. Emit: |
| 613 | // R0 = ADDI FI# |
| 614 | // Dest = LVX 0, R0 |
Andrew Trick | 6e8f4c4 | 2010-12-24 04:28:06 +0000 | [diff] [blame] | 615 | // |
Owen Anderson | f6372aa | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 616 | // FIXME: We use R0 here, because it isn't available for RA. |
Bill Wendling | d1c321a | 2009-02-12 00:02:55 +0000 | [diff] [blame] | 617 | NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(PPC::ADDI), PPC::R0), |
Owen Anderson | f6372aa | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 618 | FrameIdx, 0, 0)); |
Bill Wendling | d1c321a | 2009-02-12 00:02:55 +0000 | [diff] [blame] | 619 | NewMIs.push_back(BuildMI(MF, DL, get(PPC::LVX),DestReg).addReg(PPC::R0) |
Owen Anderson | f6372aa | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 620 | .addReg(PPC::R0)); |
| 621 | } else { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 622 | llvm_unreachable("Unknown regclass!"); |
Owen Anderson | f6372aa | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 623 | } |
Hal Finkel | d21e930 | 2011-12-06 20:55:36 +0000 | [diff] [blame] | 624 | |
| 625 | return false; |
Owen Anderson | f6372aa | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 626 | } |
| 627 | |
| 628 | void |
| 629 | PPCInstrInfo::loadRegFromStackSlot(MachineBasicBlock &MBB, |
Bill Wendling | 7194aaf | 2008-03-03 22:19:16 +0000 | [diff] [blame] | 630 | MachineBasicBlock::iterator MI, |
| 631 | unsigned DestReg, int FrameIdx, |
Evan Cheng | 746ad69 | 2010-05-06 19:06:44 +0000 | [diff] [blame] | 632 | const TargetRegisterClass *RC, |
| 633 | const TargetRegisterInfo *TRI) const { |
Dan Gohman | 8e5f2c6 | 2008-07-07 23:14:23 +0000 | [diff] [blame] | 634 | MachineFunction &MF = *MBB.getParent(); |
Owen Anderson | f6372aa | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 635 | SmallVector<MachineInstr*, 4> NewMIs; |
Chris Lattner | c7f3ace | 2010-04-02 20:16:16 +0000 | [diff] [blame] | 636 | DebugLoc DL; |
Bill Wendling | d1c321a | 2009-02-12 00:02:55 +0000 | [diff] [blame] | 637 | if (MI != MBB.end()) DL = MI->getDebugLoc(); |
Hal Finkel | d21e930 | 2011-12-06 20:55:36 +0000 | [diff] [blame] | 638 | if (LoadRegFromStackSlot(MF, DL, DestReg, FrameIdx, RC, NewMIs)) { |
| 639 | PPCFunctionInfo *FuncInfo = MF.getInfo<PPCFunctionInfo>(); |
| 640 | FuncInfo->setSpillsCR(); |
| 641 | } |
Owen Anderson | f6372aa | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 642 | for (unsigned i = 0, e = NewMIs.size(); i != e; ++i) |
| 643 | MBB.insert(MI, NewMIs[i]); |
Jakob Stoklund Olesen | 7a79fcb | 2010-07-16 18:22:00 +0000 | [diff] [blame] | 644 | |
| 645 | const MachineFrameInfo &MFI = *MF.getFrameInfo(); |
| 646 | MachineMemOperand *MMO = |
Jay Foad | 978e0df | 2011-11-15 07:34:52 +0000 | [diff] [blame] | 647 | MF.getMachineMemOperand(MachinePointerInfo::getFixedStack(FrameIdx), |
Chris Lattner | 59db549 | 2010-09-21 04:39:43 +0000 | [diff] [blame] | 648 | MachineMemOperand::MOLoad, |
Jakob Stoklund Olesen | 7a79fcb | 2010-07-16 18:22:00 +0000 | [diff] [blame] | 649 | MFI.getObjectSize(FrameIdx), |
| 650 | MFI.getObjectAlignment(FrameIdx)); |
| 651 | NewMIs.back()->addMemOperand(MF, MMO); |
Owen Anderson | f6372aa | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 652 | } |
| 653 | |
Evan Cheng | 0965217 | 2010-04-26 07:39:36 +0000 | [diff] [blame] | 654 | MachineInstr* |
| 655 | PPCInstrInfo::emitFrameIndexDebugValue(MachineFunction &MF, |
Evan Cheng | 8601a3d | 2010-04-29 01:13:30 +0000 | [diff] [blame] | 656 | int FrameIx, uint64_t Offset, |
Evan Cheng | 0965217 | 2010-04-26 07:39:36 +0000 | [diff] [blame] | 657 | const MDNode *MDPtr, |
| 658 | DebugLoc DL) const { |
| 659 | MachineInstrBuilder MIB = BuildMI(MF, DL, get(PPC::DBG_VALUE)); |
| 660 | addFrameReference(MIB, FrameIx, 0, false).addImm(Offset).addMetadata(MDPtr); |
| 661 | return &*MIB; |
| 662 | } |
| 663 | |
Chris Lattner | c50e2bc | 2006-10-13 21:21:17 +0000 | [diff] [blame] | 664 | bool PPCInstrInfo:: |
Owen Anderson | 44eb65c | 2008-08-14 22:49:33 +0000 | [diff] [blame] | 665 | ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const { |
Chris Lattner | 7c4fe25 | 2006-10-21 06:03:11 +0000 | [diff] [blame] | 666 | assert(Cond.size() == 2 && "Invalid PPC branch opcode!"); |
| 667 | // Leave the CR# the same, but invert the condition. |
Chris Lattner | 18258c6 | 2006-11-17 22:37:34 +0000 | [diff] [blame] | 668 | Cond[0].setImm(PPC::InvertPredicate((PPC::Predicate)Cond[0].getImm())); |
Chris Lattner | 7c4fe25 | 2006-10-21 06:03:11 +0000 | [diff] [blame] | 669 | return false; |
Chris Lattner | c50e2bc | 2006-10-13 21:21:17 +0000 | [diff] [blame] | 670 | } |
Nicolas Geoffray | 52e724a | 2008-04-16 20:10:13 +0000 | [diff] [blame] | 671 | |
| 672 | /// GetInstSize - Return the number of bytes of code the specified |
| 673 | /// instruction may be. This returns the maximum number of bytes. |
| 674 | /// |
| 675 | unsigned PPCInstrInfo::GetInstSizeInBytes(const MachineInstr *MI) const { |
| 676 | switch (MI->getOpcode()) { |
| 677 | case PPC::INLINEASM: { // Inline Asm: Variable size. |
| 678 | const MachineFunction *MF = MI->getParent()->getParent(); |
| 679 | const char *AsmStr = MI->getOperand(0).getSymbolName(); |
Chris Lattner | af76e59 | 2009-08-22 20:48:53 +0000 | [diff] [blame] | 680 | return getInlineAsmLength(AsmStr, *MF->getTarget().getMCAsmInfo()); |
Nicolas Geoffray | 52e724a | 2008-04-16 20:10:13 +0000 | [diff] [blame] | 681 | } |
Bill Wendling | 7431bea | 2010-07-16 22:20:36 +0000 | [diff] [blame] | 682 | case PPC::PROLOG_LABEL: |
Dan Gohman | 4406604 | 2008-07-01 00:05:16 +0000 | [diff] [blame] | 683 | case PPC::EH_LABEL: |
| 684 | case PPC::GC_LABEL: |
Dale Johannesen | 375be77 | 2010-04-07 19:51:44 +0000 | [diff] [blame] | 685 | case PPC::DBG_VALUE: |
Nicolas Geoffray | 52e724a | 2008-04-16 20:10:13 +0000 | [diff] [blame] | 686 | return 0; |
Nicolas Geoffray | 52e724a | 2008-04-16 20:10:13 +0000 | [diff] [blame] | 687 | default: |
| 688 | return 4; // PowerPC instructions are all 4 bytes |
| 689 | } |
| 690 | } |