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