Jia Liu | b22310f | 2012-02-18 12:03:15 +0000 | [diff] [blame] | 1 | //===-- PPCInstrInfo.cpp - PowerPC Instruction Information ----------------===// |
Misha Brukman | b440243 | 2005-04-21 23:30:14 +0000 | [diff] [blame] | 2 | // |
Misha Brukman | 116f927 | 2004-08-17 04:55:41 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | f3ebc3f | 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 | b440243 | 2005-04-21 23:30:14 +0000 | [diff] [blame] | 7 | // |
Misha Brukman | 116f927 | 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 | 6f3b954 | 2005-10-14 23:59:06 +0000 | [diff] [blame] | 14 | #include "PPCInstrInfo.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 15 | #include "MCTargetDesc/PPCPredicates.h" |
Evan Cheng | c5e6d2f | 2011-07-11 03:57:24 +0000 | [diff] [blame] | 16 | #include "PPC.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 17 | #include "PPCHazardRecognizers.h" |
Owen Anderson | eee1460 | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 18 | #include "PPCInstrBuilder.h" |
Bill Wendling | 632ea65 | 2008-03-03 22:19:16 +0000 | [diff] [blame] | 19 | #include "PPCMachineFunctionInfo.h" |
Chris Lattner | 49cadab | 2006-06-17 00:01:04 +0000 | [diff] [blame] | 20 | #include "PPCTargetMachine.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 21 | #include "llvm/ADT/STLExtras.h" |
Chandler Carruth | 8a8cd2b | 2014-01-07 11:48:04 +0000 | [diff] [blame] | 22 | #include "llvm/ADT/Statistic.h" |
Hal Finkel | 174e590 | 2014-03-25 23:29:21 +0000 | [diff] [blame] | 23 | #include "llvm/CodeGen/LiveIntervalAnalysis.h" |
Jakob Stoklund Olesen | 6353e53 | 2010-07-16 18:22:00 +0000 | [diff] [blame] | 24 | #include "llvm/CodeGen/MachineFrameInfo.h" |
Hal Finkel | b5aa7e5 | 2013-04-08 16:24:03 +0000 | [diff] [blame] | 25 | #include "llvm/CodeGen/MachineFunctionPass.h" |
Misha Brukman | 116f927 | 2004-08-17 04:55:41 +0000 | [diff] [blame] | 26 | #include "llvm/CodeGen/MachineInstrBuilder.h" |
Jakob Stoklund Olesen | 6353e53 | 2010-07-16 18:22:00 +0000 | [diff] [blame] | 27 | #include "llvm/CodeGen/MachineMemOperand.h" |
Jakob Stoklund Olesen | ddbf7a8 | 2010-02-26 21:09:24 +0000 | [diff] [blame] | 28 | #include "llvm/CodeGen/MachineRegisterInfo.h" |
Hal Finkel | 9f9f892 | 2012-04-01 19:22:40 +0000 | [diff] [blame] | 29 | #include "llvm/CodeGen/PseudoSourceValue.h" |
Eric Christopher | 1dcea73 | 2014-06-12 21:48:52 +0000 | [diff] [blame] | 30 | #include "llvm/CodeGen/ScheduleDAG.h" |
Hal Finkel | 174e590 | 2014-03-25 23:29:21 +0000 | [diff] [blame] | 31 | #include "llvm/CodeGen/SlotIndexes.h" |
Hal Finkel | 934361a | 2015-01-14 01:07:51 +0000 | [diff] [blame] | 32 | #include "llvm/CodeGen/StackMaps.h" |
Evan Cheng | c5e6d2f | 2011-07-11 03:57:24 +0000 | [diff] [blame] | 33 | #include "llvm/MC/MCAsmInfo.h" |
Pete Cooper | 3de83e4 | 2015-05-15 21:58:42 +0000 | [diff] [blame] | 34 | #include "llvm/MC/MCInst.h" |
Bill Wendling | 1af20ad | 2008-03-04 23:13:51 +0000 | [diff] [blame] | 35 | #include "llvm/Support/CommandLine.h" |
Hal Finkel | 174e590 | 2014-03-25 23:29:21 +0000 | [diff] [blame] | 36 | #include "llvm/Support/Debug.h" |
Torok Edwin | fb8d6d5 | 2009-07-08 20:53:28 +0000 | [diff] [blame] | 37 | #include "llvm/Support/ErrorHandling.h" |
Evan Cheng | 2bb4035 | 2011-08-24 18:08:43 +0000 | [diff] [blame] | 38 | #include "llvm/Support/TargetRegistry.h" |
Torok Edwin | fb8d6d5 | 2009-07-08 20:53:28 +0000 | [diff] [blame] | 39 | #include "llvm/Support/raw_ostream.h" |
Misha Brukman | 116f927 | 2004-08-17 04:55:41 +0000 | [diff] [blame] | 40 | |
Dan Gohman | 2085719 | 2010-04-15 17:20:57 +0000 | [diff] [blame] | 41 | using namespace llvm; |
Bill Wendling | 1af20ad | 2008-03-04 23:13:51 +0000 | [diff] [blame] | 42 | |
Chandler Carruth | e96dd89 | 2014-04-21 22:55:11 +0000 | [diff] [blame] | 43 | #define DEBUG_TYPE "ppc-instr-info" |
| 44 | |
Chandler Carruth | d174b72 | 2014-04-22 02:03:14 +0000 | [diff] [blame] | 45 | #define GET_INSTRMAP_INFO |
| 46 | #define GET_INSTRINFO_CTOR_DTOR |
| 47 | #include "PPCGenInstrInfo.inc" |
| 48 | |
Hal Finkel | 821e001 | 2012-06-08 15:38:25 +0000 | [diff] [blame] | 49 | static cl:: |
Hal Finkel | c6b5deb | 2012-06-08 19:19:53 +0000 | [diff] [blame] | 50 | opt<bool> DisableCTRLoopAnal("disable-ppc-ctrloop-analysis", cl::Hidden, |
| 51 | cl::desc("Disable analysis for CTR loops")); |
Hal Finkel | 821e001 | 2012-06-08 15:38:25 +0000 | [diff] [blame] | 52 | |
Hal Finkel | e632239 | 2013-04-19 22:08:38 +0000 | [diff] [blame] | 53 | static cl::opt<bool> DisableCmpOpt("disable-ppc-cmp-opt", |
Hal Finkel | b12da6b | 2013-04-18 22:54:25 +0000 | [diff] [blame] | 54 | cl::desc("Disable compare instruction optimization"), cl::Hidden); |
| 55 | |
Hal Finkel | 9dcb358 | 2014-03-27 22:46:28 +0000 | [diff] [blame] | 56 | static cl::opt<bool> VSXSelfCopyCrash("crash-on-ppc-vsx-self-copy", |
| 57 | cl::desc("Causes the backend to crash instead of generating a nop VSX copy"), |
| 58 | cl::Hidden); |
| 59 | |
Hal Finkel | 8acae52 | 2015-07-14 20:02:02 +0000 | [diff] [blame] | 60 | static cl::opt<bool> |
| 61 | UseOldLatencyCalc("ppc-old-latency-calc", cl::Hidden, |
| 62 | cl::desc("Use the old (incorrect) instruction latency calculation")); |
| 63 | |
Juergen Ributzka | d12ccbd | 2013-11-19 00:57:56 +0000 | [diff] [blame] | 64 | // Pin the vtable to this file. |
| 65 | void PPCInstrInfo::anchor() {} |
| 66 | |
Eric Christopher | 1dcea73 | 2014-06-12 21:48:52 +0000 | [diff] [blame] | 67 | PPCInstrInfo::PPCInstrInfo(PPCSubtarget &STI) |
| 68 | : PPCGenInstrInfo(PPC::ADJCALLSTACKDOWN, PPC::ADJCALLSTACKUP), |
Eric Christopher | ea178cf | 2015-03-12 01:42:51 +0000 | [diff] [blame] | 69 | Subtarget(STI), RI(STI.getTargetMachine()) {} |
Chris Lattner | 49cadab | 2006-06-17 00:01:04 +0000 | [diff] [blame] | 70 | |
Andrew Trick | 10ffc2b | 2010-12-24 05:03:26 +0000 | [diff] [blame] | 71 | /// CreateTargetHazardRecognizer - Return the hazard recognizer to use for |
| 72 | /// this target when scheduling the DAG. |
Eric Christopher | f047bfd | 2014-06-13 22:38:52 +0000 | [diff] [blame] | 73 | ScheduleHazardRecognizer * |
| 74 | PPCInstrInfo::CreateTargetHazardRecognizer(const TargetSubtargetInfo *STI, |
| 75 | const ScheduleDAG *DAG) const { |
| 76 | unsigned Directive = |
| 77 | static_cast<const PPCSubtarget *>(STI)->getDarwinDirective(); |
Hal Finkel | 742b535 | 2012-08-28 16:12:39 +0000 | [diff] [blame] | 78 | if (Directive == PPC::DIR_440 || Directive == PPC::DIR_A2 || |
| 79 | Directive == PPC::DIR_E500mc || Directive == PPC::DIR_E5500) { |
Eric Christopher | f047bfd | 2014-06-13 22:38:52 +0000 | [diff] [blame] | 80 | const InstrItineraryData *II = |
Eric Christopher | d913448 | 2014-08-04 21:25:23 +0000 | [diff] [blame] | 81 | static_cast<const PPCSubtarget *>(STI)->getInstrItineraryData(); |
Hal Finkel | 563cc05 | 2013-12-02 23:52:46 +0000 | [diff] [blame] | 82 | return new ScoreboardHazardRecognizer(II, DAG); |
Hal Finkel | 6fa5697 | 2011-10-17 04:03:49 +0000 | [diff] [blame] | 83 | } |
Hal Finkel | 58ca360 | 2011-12-02 04:58:02 +0000 | [diff] [blame] | 84 | |
Eric Christopher | f047bfd | 2014-06-13 22:38:52 +0000 | [diff] [blame] | 85 | return TargetInstrInfo::CreateTargetHazardRecognizer(STI, DAG); |
Andrew Trick | 10ffc2b | 2010-12-24 05:03:26 +0000 | [diff] [blame] | 86 | } |
| 87 | |
Hal Finkel | 58ca360 | 2011-12-02 04:58:02 +0000 | [diff] [blame] | 88 | /// CreateTargetPostRAHazardRecognizer - Return the postRA hazard recognizer |
| 89 | /// to use for this target when scheduling the DAG. |
Eric Christopher | cccae79 | 2015-01-30 22:02:31 +0000 | [diff] [blame] | 90 | ScheduleHazardRecognizer * |
| 91 | PPCInstrInfo::CreateTargetPostRAHazardRecognizer(const InstrItineraryData *II, |
| 92 | const ScheduleDAG *DAG) const { |
Eric Christopher | 1dcea73 | 2014-06-12 21:48:52 +0000 | [diff] [blame] | 93 | unsigned Directive = |
Eric Christopher | cccae79 | 2015-01-30 22:02:31 +0000 | [diff] [blame] | 94 | DAG->MF.getSubtarget<PPCSubtarget>().getDarwinDirective(); |
Hal Finkel | 58ca360 | 2011-12-02 04:58:02 +0000 | [diff] [blame] | 95 | |
Will Schmidt | 970ff64 | 2014-06-26 13:36:19 +0000 | [diff] [blame] | 96 | if (Directive == PPC::DIR_PWR7 || Directive == PPC::DIR_PWR8) |
Hal Finkel | ceb1f12 | 2013-12-12 00:19:11 +0000 | [diff] [blame] | 97 | return new PPCDispatchGroupSBHazardRecognizer(II, DAG); |
| 98 | |
Hal Finkel | 58ca360 | 2011-12-02 04:58:02 +0000 | [diff] [blame] | 99 | // Most subtargets use a PPC970 recognizer. |
Hal Finkel | 742b535 | 2012-08-28 16:12:39 +0000 | [diff] [blame] | 100 | if (Directive != PPC::DIR_440 && Directive != PPC::DIR_A2 && |
| 101 | Directive != PPC::DIR_E500mc && Directive != PPC::DIR_E5500) { |
Eric Christopher | 1dcea73 | 2014-06-12 21:48:52 +0000 | [diff] [blame] | 102 | assert(DAG->TII && "No InstrInfo?"); |
Hal Finkel | 58ca360 | 2011-12-02 04:58:02 +0000 | [diff] [blame] | 103 | |
Eric Christopher | 1dcea73 | 2014-06-12 21:48:52 +0000 | [diff] [blame] | 104 | return new PPCHazardRecognizer970(*DAG); |
Hal Finkel | 58ca360 | 2011-12-02 04:58:02 +0000 | [diff] [blame] | 105 | } |
| 106 | |
Hal Finkel | 563cc05 | 2013-12-02 23:52:46 +0000 | [diff] [blame] | 107 | return new ScoreboardHazardRecognizer(II, DAG); |
Hal Finkel | 58ca360 | 2011-12-02 04:58:02 +0000 | [diff] [blame] | 108 | } |
Jakob Stoklund Olesen | 0f855e4 | 2012-06-19 21:14:34 +0000 | [diff] [blame] | 109 | |
Hal Finkel | 8acae52 | 2015-07-14 20:02:02 +0000 | [diff] [blame] | 110 | unsigned PPCInstrInfo::getInstrLatency(const InstrItineraryData *ItinData, |
| 111 | const MachineInstr *MI, |
| 112 | unsigned *PredCost) const { |
| 113 | if (!ItinData || UseOldLatencyCalc) |
| 114 | return PPCGenInstrInfo::getInstrLatency(ItinData, MI, PredCost); |
| 115 | |
| 116 | // The default implementation of getInstrLatency calls getStageLatency, but |
| 117 | // getStageLatency does not do the right thing for us. While we have |
| 118 | // itinerary, most cores are fully pipelined, and so the itineraries only |
| 119 | // express the first part of the pipeline, not every stage. Instead, we need |
| 120 | // to use the listed output operand cycle number (using operand 0 here, which |
| 121 | // is an output). |
| 122 | |
| 123 | unsigned Latency = 1; |
| 124 | unsigned DefClass = MI->getDesc().getSchedClass(); |
| 125 | for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) { |
| 126 | const MachineOperand &MO = MI->getOperand(i); |
| 127 | if (!MO.isReg() || !MO.isDef() || MO.isImplicit()) |
| 128 | continue; |
| 129 | |
| 130 | int Cycle = ItinData->getOperandCycle(DefClass, i); |
| 131 | if (Cycle < 0) |
| 132 | continue; |
| 133 | |
| 134 | Latency = std::max(Latency, (unsigned) Cycle); |
| 135 | } |
| 136 | |
| 137 | return Latency; |
| 138 | } |
Hal Finkel | ceb1f12 | 2013-12-12 00:19:11 +0000 | [diff] [blame] | 139 | |
| 140 | int PPCInstrInfo::getOperandLatency(const InstrItineraryData *ItinData, |
| 141 | const MachineInstr *DefMI, unsigned DefIdx, |
| 142 | const MachineInstr *UseMI, |
| 143 | unsigned UseIdx) const { |
| 144 | int Latency = PPCGenInstrInfo::getOperandLatency(ItinData, DefMI, DefIdx, |
| 145 | UseMI, UseIdx); |
| 146 | |
Hal Finkel | 5d36b23 | 2015-07-15 08:23:05 +0000 | [diff] [blame^] | 147 | if (!DefMI->getParent()) |
| 148 | return Latency; |
| 149 | |
Hal Finkel | ceb1f12 | 2013-12-12 00:19:11 +0000 | [diff] [blame] | 150 | const MachineOperand &DefMO = DefMI->getOperand(DefIdx); |
| 151 | unsigned Reg = DefMO.getReg(); |
| 152 | |
Hal Finkel | ceb1f12 | 2013-12-12 00:19:11 +0000 | [diff] [blame] | 153 | bool IsRegCR; |
Andrew Kaylor | 5c73e1f | 2015-03-24 23:37:10 +0000 | [diff] [blame] | 154 | if (TargetRegisterInfo::isVirtualRegister(Reg)) { |
Hal Finkel | ceb1f12 | 2013-12-12 00:19:11 +0000 | [diff] [blame] | 155 | const MachineRegisterInfo *MRI = |
| 156 | &DefMI->getParent()->getParent()->getRegInfo(); |
| 157 | IsRegCR = MRI->getRegClass(Reg)->hasSuperClassEq(&PPC::CRRCRegClass) || |
| 158 | MRI->getRegClass(Reg)->hasSuperClassEq(&PPC::CRBITRCRegClass); |
| 159 | } else { |
| 160 | IsRegCR = PPC::CRRCRegClass.contains(Reg) || |
| 161 | PPC::CRBITRCRegClass.contains(Reg); |
| 162 | } |
| 163 | |
| 164 | if (UseMI->isBranch() && IsRegCR) { |
| 165 | if (Latency < 0) |
| 166 | Latency = getInstrLatency(ItinData, DefMI); |
| 167 | |
| 168 | // On some cores, there is an additional delay between writing to a condition |
| 169 | // register, and using it from a branch. |
Eric Christopher | 1dcea73 | 2014-06-12 21:48:52 +0000 | [diff] [blame] | 170 | unsigned Directive = Subtarget.getDarwinDirective(); |
Hal Finkel | ceb1f12 | 2013-12-12 00:19:11 +0000 | [diff] [blame] | 171 | switch (Directive) { |
| 172 | default: break; |
| 173 | case PPC::DIR_7400: |
| 174 | case PPC::DIR_750: |
| 175 | case PPC::DIR_970: |
| 176 | case PPC::DIR_E5500: |
| 177 | case PPC::DIR_PWR4: |
| 178 | case PPC::DIR_PWR5: |
| 179 | case PPC::DIR_PWR5X: |
| 180 | case PPC::DIR_PWR6: |
| 181 | case PPC::DIR_PWR6X: |
| 182 | case PPC::DIR_PWR7: |
Will Schmidt | 970ff64 | 2014-06-26 13:36:19 +0000 | [diff] [blame] | 183 | case PPC::DIR_PWR8: |
Hal Finkel | ceb1f12 | 2013-12-12 00:19:11 +0000 | [diff] [blame] | 184 | Latency += 2; |
| 185 | break; |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | return Latency; |
| 190 | } |
| 191 | |
Hal Finkel | 5d36b23 | 2015-07-15 08:23:05 +0000 | [diff] [blame^] | 192 | static bool hasVirtualRegDefsInBasicBlock(const MachineInstr &Inst, |
| 193 | const MachineBasicBlock *MBB) { |
| 194 | const MachineOperand &Op1 = Inst.getOperand(1); |
| 195 | const MachineOperand &Op2 = Inst.getOperand(2); |
| 196 | const MachineRegisterInfo &MRI = MBB->getParent()->getRegInfo(); |
| 197 | |
| 198 | // We need virtual register definitions. |
| 199 | MachineInstr *MI1 = nullptr; |
| 200 | MachineInstr *MI2 = nullptr; |
| 201 | if (Op1.isReg() && TargetRegisterInfo::isVirtualRegister(Op1.getReg())) |
| 202 | MI1 = MRI.getUniqueVRegDef(Op1.getReg()); |
| 203 | if (Op2.isReg() && TargetRegisterInfo::isVirtualRegister(Op2.getReg())) |
| 204 | MI2 = MRI.getUniqueVRegDef(Op2.getReg()); |
| 205 | |
| 206 | // And they need to be in the trace (otherwise, they won't have a depth). |
| 207 | if (MI1 && MI2 && MI1->getParent() == MBB && MI2->getParent() == MBB) |
| 208 | return true; |
| 209 | |
| 210 | return false; |
| 211 | } |
| 212 | |
| 213 | static bool hasReassocSibling(const MachineInstr &Inst, bool &Commuted) { |
| 214 | const MachineBasicBlock *MBB = Inst.getParent(); |
| 215 | const MachineRegisterInfo &MRI = MBB->getParent()->getRegInfo(); |
| 216 | MachineInstr *MI1 = MRI.getUniqueVRegDef(Inst.getOperand(1).getReg()); |
| 217 | MachineInstr *MI2 = MRI.getUniqueVRegDef(Inst.getOperand(2).getReg()); |
| 218 | unsigned AssocOpcode = Inst.getOpcode(); |
| 219 | |
| 220 | // If only one operand has the same opcode and it's the second source operand, |
| 221 | // the operands must be commuted. |
| 222 | Commuted = MI1->getOpcode() != AssocOpcode && MI2->getOpcode() == AssocOpcode; |
| 223 | if (Commuted) |
| 224 | std::swap(MI1, MI2); |
| 225 | |
| 226 | // 1. The previous instruction must be the same type as Inst. |
| 227 | // 2. The previous instruction must have virtual register definitions for its |
| 228 | // operands in the same basic block as Inst. |
| 229 | // 3. The previous instruction's result must only be used by Inst. |
| 230 | if (MI1->getOpcode() == AssocOpcode && |
| 231 | hasVirtualRegDefsInBasicBlock(*MI1, MBB) && |
| 232 | MRI.hasOneNonDBGUse(MI1->getOperand(0).getReg())) |
| 233 | return true; |
| 234 | |
| 235 | return false; |
| 236 | } |
| 237 | |
| 238 | // This function does not list all associative and commutative operations, but |
| 239 | // only those worth feeding through the machine combiner in an attempt to |
| 240 | // reduce the critical path. Mostly, this means floating-point operations, |
| 241 | // because they have high latencies (compared to other operations, such and |
| 242 | // and/or, which are also associative and commutative, but have low latencies). |
| 243 | // |
| 244 | // The concept is that these operations can benefit from this kind of |
| 245 | // transformation: |
| 246 | // |
| 247 | // A = ? op ? |
| 248 | // B = A op X |
| 249 | // C = B op Y |
| 250 | // --> |
| 251 | // A = ? op ? |
| 252 | // B = X op Y |
| 253 | // C = A op B |
| 254 | // |
| 255 | // breaking the dependency between A and B, allowing them to be executed in |
| 256 | // parallel (or back-to-back in a pipeline) instead of depending on each other. |
| 257 | static bool isAssociativeAndCommutative(unsigned Opcode) { |
| 258 | switch (Opcode) { |
| 259 | // FP Add: |
| 260 | case PPC::FADD: |
| 261 | case PPC::FADDS: |
| 262 | // FP Multiply: |
| 263 | case PPC::FMUL: |
| 264 | case PPC::FMULS: |
| 265 | // Altivec Add: |
| 266 | case PPC::VADDFP: |
| 267 | // VSX Add: |
| 268 | case PPC::XSADDDP: |
| 269 | case PPC::XVADDDP: |
| 270 | case PPC::XVADDSP: |
| 271 | case PPC::XSADDSP: |
| 272 | // VSX Multiply: |
| 273 | case PPC::XSMULDP: |
| 274 | case PPC::XVMULDP: |
| 275 | case PPC::XVMULSP: |
| 276 | case PPC::XSMULSP: |
| 277 | // QPX Add: |
| 278 | case PPC::QVFADD: |
| 279 | case PPC::QVFADDS: |
| 280 | case PPC::QVFADDSs: |
| 281 | // QPX Multiply: |
| 282 | case PPC::QVFMUL: |
| 283 | case PPC::QVFMULS: |
| 284 | case PPC::QVFMULSs: |
| 285 | return true; |
| 286 | default: |
| 287 | return false; |
| 288 | } |
| 289 | } |
| 290 | |
| 291 | /// Return true if the input instruction is part of a chain of dependent ops |
| 292 | /// that are suitable for reassociation, otherwise return false. |
| 293 | /// If the instruction's operands must be commuted to have a previous |
| 294 | /// instruction of the same type define the first source operand, Commuted will |
| 295 | /// be set to true. |
| 296 | static bool isReassocCandidate(const MachineInstr &Inst, bool &Commuted) { |
| 297 | // 1. The operation must be associative and commutative. |
| 298 | // 2. The instruction must have virtual register definitions for its |
| 299 | // operands in the same basic block. |
| 300 | // 3. The instruction must have a reassociable sibling. |
| 301 | if (isAssociativeAndCommutative(Inst.getOpcode()) && |
| 302 | hasVirtualRegDefsInBasicBlock(Inst, Inst.getParent()) && |
| 303 | hasReassocSibling(Inst, Commuted)) |
| 304 | return true; |
| 305 | |
| 306 | return false; |
| 307 | } |
| 308 | |
| 309 | bool PPCInstrInfo::getMachineCombinerPatterns(MachineInstr &Root, |
| 310 | SmallVectorImpl<MachineCombinerPattern::MC_PATTERN> &Patterns) const { |
| 311 | // Using the machine combiner in this way is potentially expensive, so |
| 312 | // restrict to when aggressive optimizations are desired. |
| 313 | if (Subtarget.getTargetMachine().getOptLevel() != CodeGenOpt::Aggressive) |
| 314 | return false; |
| 315 | |
| 316 | // FP reassociation is only legal when we don't need strict IEEE semantics. |
| 317 | if (!Root.getParent()->getParent()->getTarget().Options.UnsafeFPMath) |
| 318 | return false; |
| 319 | |
| 320 | // Look for this reassociation pattern: |
| 321 | // B = A op X (Prev) |
| 322 | // C = B op Y (Root) |
| 323 | |
| 324 | // FIXME: We should also match FMA operations here, where we consider the |
| 325 | // 'part' of the FMA, either the addition or the multiplication, paired with |
| 326 | // an actual addition or multiplication. |
| 327 | |
| 328 | bool Commute; |
| 329 | if (isReassocCandidate(Root, Commute)) { |
| 330 | // We found a sequence of instructions that may be suitable for a |
| 331 | // reassociation of operands to increase ILP. Specify each commutation |
| 332 | // possibility for the Prev instruction in the sequence and let the |
| 333 | // machine combiner decide if changing the operands is worthwhile. |
| 334 | if (Commute) { |
| 335 | Patterns.push_back(MachineCombinerPattern::MC_REASSOC_AX_YB); |
| 336 | Patterns.push_back(MachineCombinerPattern::MC_REASSOC_XA_YB); |
| 337 | } else { |
| 338 | Patterns.push_back(MachineCombinerPattern::MC_REASSOC_AX_BY); |
| 339 | Patterns.push_back(MachineCombinerPattern::MC_REASSOC_XA_BY); |
| 340 | } |
| 341 | return true; |
| 342 | } |
| 343 | |
| 344 | return false; |
| 345 | } |
| 346 | |
| 347 | /// Attempt the following reassociation to reduce critical path length: |
| 348 | /// B = A op X (Prev) |
| 349 | /// C = B op Y (Root) |
| 350 | /// ===> |
| 351 | /// B = X op Y |
| 352 | /// C = A op B |
| 353 | static void reassociateOps(MachineInstr &Root, MachineInstr &Prev, |
| 354 | MachineCombinerPattern::MC_PATTERN Pattern, |
| 355 | SmallVectorImpl<MachineInstr *> &InsInstrs, |
| 356 | SmallVectorImpl<MachineInstr *> &DelInstrs, |
| 357 | DenseMap<unsigned, unsigned> &InstrIdxForVirtReg) { |
| 358 | MachineFunction *MF = Root.getParent()->getParent(); |
| 359 | MachineRegisterInfo &MRI = MF->getRegInfo(); |
| 360 | const TargetInstrInfo *TII = MF->getSubtarget().getInstrInfo(); |
| 361 | const TargetRegisterInfo *TRI = MF->getSubtarget().getRegisterInfo(); |
| 362 | const TargetRegisterClass *RC = Root.getRegClassConstraint(0, TII, TRI); |
| 363 | |
| 364 | // This array encodes the operand index for each parameter because the |
| 365 | // operands may be commuted. Each row corresponds to a pattern value, |
| 366 | // and each column specifies the index of A, B, X, Y. |
| 367 | unsigned OpIdx[4][4] = { |
| 368 | { 1, 1, 2, 2 }, |
| 369 | { 1, 2, 2, 1 }, |
| 370 | { 2, 1, 1, 2 }, |
| 371 | { 2, 2, 1, 1 } |
| 372 | }; |
| 373 | |
| 374 | MachineOperand &OpA = Prev.getOperand(OpIdx[Pattern][0]); |
| 375 | MachineOperand &OpB = Root.getOperand(OpIdx[Pattern][1]); |
| 376 | MachineOperand &OpX = Prev.getOperand(OpIdx[Pattern][2]); |
| 377 | MachineOperand &OpY = Root.getOperand(OpIdx[Pattern][3]); |
| 378 | MachineOperand &OpC = Root.getOperand(0); |
| 379 | |
| 380 | unsigned RegA = OpA.getReg(); |
| 381 | unsigned RegB = OpB.getReg(); |
| 382 | unsigned RegX = OpX.getReg(); |
| 383 | unsigned RegY = OpY.getReg(); |
| 384 | unsigned RegC = OpC.getReg(); |
| 385 | |
| 386 | if (TargetRegisterInfo::isVirtualRegister(RegA)) |
| 387 | MRI.constrainRegClass(RegA, RC); |
| 388 | if (TargetRegisterInfo::isVirtualRegister(RegB)) |
| 389 | MRI.constrainRegClass(RegB, RC); |
| 390 | if (TargetRegisterInfo::isVirtualRegister(RegX)) |
| 391 | MRI.constrainRegClass(RegX, RC); |
| 392 | if (TargetRegisterInfo::isVirtualRegister(RegY)) |
| 393 | MRI.constrainRegClass(RegY, RC); |
| 394 | if (TargetRegisterInfo::isVirtualRegister(RegC)) |
| 395 | MRI.constrainRegClass(RegC, RC); |
| 396 | |
| 397 | // Create a new virtual register for the result of (X op Y) instead of |
| 398 | // recycling RegB because the MachineCombiner's computation of the critical |
| 399 | // path requires a new register definition rather than an existing one. |
| 400 | unsigned NewVR = MRI.createVirtualRegister(RC); |
| 401 | InstrIdxForVirtReg.insert(std::make_pair(NewVR, 0)); |
| 402 | |
| 403 | unsigned Opcode = Root.getOpcode(); |
| 404 | bool KillA = OpA.isKill(); |
| 405 | bool KillX = OpX.isKill(); |
| 406 | bool KillY = OpY.isKill(); |
| 407 | |
| 408 | // Create new instructions for insertion. |
| 409 | MachineInstrBuilder MIB1 = |
| 410 | BuildMI(*MF, Prev.getDebugLoc(), TII->get(Opcode), NewVR) |
| 411 | .addReg(RegX, getKillRegState(KillX)) |
| 412 | .addReg(RegY, getKillRegState(KillY)); |
| 413 | InsInstrs.push_back(MIB1); |
| 414 | |
| 415 | MachineInstrBuilder MIB2 = |
| 416 | BuildMI(*MF, Root.getDebugLoc(), TII->get(Opcode), RegC) |
| 417 | .addReg(RegA, getKillRegState(KillA)) |
| 418 | .addReg(NewVR, getKillRegState(true)); |
| 419 | InsInstrs.push_back(MIB2); |
| 420 | |
| 421 | // Record old instructions for deletion. |
| 422 | DelInstrs.push_back(&Prev); |
| 423 | DelInstrs.push_back(&Root); |
| 424 | } |
| 425 | |
| 426 | void PPCInstrInfo::genAlternativeCodeSequence( |
| 427 | MachineInstr &Root, |
| 428 | MachineCombinerPattern::MC_PATTERN Pattern, |
| 429 | SmallVectorImpl<MachineInstr *> &InsInstrs, |
| 430 | SmallVectorImpl<MachineInstr *> &DelInstrs, |
| 431 | DenseMap<unsigned, unsigned> &InstIdxForVirtReg) const { |
| 432 | MachineRegisterInfo &MRI = Root.getParent()->getParent()->getRegInfo(); |
| 433 | |
| 434 | // Select the previous instruction in the sequence based on the input pattern. |
| 435 | MachineInstr *Prev = nullptr; |
| 436 | switch (Pattern) { |
| 437 | case MachineCombinerPattern::MC_REASSOC_AX_BY: |
| 438 | case MachineCombinerPattern::MC_REASSOC_XA_BY: |
| 439 | Prev = MRI.getUniqueVRegDef(Root.getOperand(1).getReg()); |
| 440 | break; |
| 441 | case MachineCombinerPattern::MC_REASSOC_AX_YB: |
| 442 | case MachineCombinerPattern::MC_REASSOC_XA_YB: |
| 443 | Prev = MRI.getUniqueVRegDef(Root.getOperand(2).getReg()); |
| 444 | } |
| 445 | assert(Prev && "Unknown pattern for machine combiner"); |
| 446 | |
| 447 | reassociateOps(Root, *Prev, Pattern, InsInstrs, DelInstrs, InstIdxForVirtReg); |
| 448 | return; |
| 449 | } |
| 450 | |
Jakob Stoklund Olesen | 0f855e4 | 2012-06-19 21:14:34 +0000 | [diff] [blame] | 451 | // Detect 32 -> 64-bit extensions where we may reuse the low sub-register. |
| 452 | bool PPCInstrInfo::isCoalescableExtInstr(const MachineInstr &MI, |
| 453 | unsigned &SrcReg, unsigned &DstReg, |
| 454 | unsigned &SubIdx) const { |
| 455 | switch (MI.getOpcode()) { |
| 456 | default: return false; |
| 457 | case PPC::EXTSW: |
| 458 | case PPC::EXTSW_32_64: |
| 459 | SrcReg = MI.getOperand(1).getReg(); |
| 460 | DstReg = MI.getOperand(0).getReg(); |
| 461 | SubIdx = PPC::sub_32; |
| 462 | return true; |
| 463 | } |
| 464 | } |
| 465 | |
Andrew Trick | c416ba6 | 2010-12-24 04:28:06 +0000 | [diff] [blame] | 466 | unsigned PPCInstrInfo::isLoadFromStackSlot(const MachineInstr *MI, |
Chris Lattner | 91400bd | 2006-03-16 22:24:02 +0000 | [diff] [blame] | 467 | int &FrameIndex) const { |
Hal Finkel | 37714b8 | 2013-03-27 21:21:15 +0000 | [diff] [blame] | 468 | // Note: This list must be kept consistent with LoadRegFromStackSlot. |
Chris Lattner | bb53acd | 2006-02-02 20:12:32 +0000 | [diff] [blame] | 469 | switch (MI->getOpcode()) { |
| 470 | default: break; |
| 471 | case PPC::LD: |
| 472 | case PPC::LWZ: |
| 473 | case PPC::LFS: |
| 474 | case PPC::LFD: |
Hal Finkel | 37714b8 | 2013-03-27 21:21:15 +0000 | [diff] [blame] | 475 | case PPC::RESTORE_CR: |
Hal Finkel | 940ab93 | 2014-02-28 00:27:01 +0000 | [diff] [blame] | 476 | case PPC::RESTORE_CRBIT: |
Hal Finkel | 37714b8 | 2013-03-27 21:21:15 +0000 | [diff] [blame] | 477 | case PPC::LVX: |
Hal Finkel | 27774d9 | 2014-03-13 07:58:58 +0000 | [diff] [blame] | 478 | case PPC::LXVD2X: |
Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 479 | case PPC::QVLFDX: |
| 480 | case PPC::QVLFSXs: |
| 481 | case PPC::QVLFDXb: |
Hal Finkel | 37714b8 | 2013-03-27 21:21:15 +0000 | [diff] [blame] | 482 | case PPC::RESTORE_VRSAVE: |
| 483 | // Check for the operands added by addFrameReference (the immediate is the |
| 484 | // offset which defaults to 0). |
Dan Gohman | 0d1e9a8 | 2008-10-03 15:45:36 +0000 | [diff] [blame] | 485 | if (MI->getOperand(1).isImm() && !MI->getOperand(1).getImm() && |
| 486 | MI->getOperand(2).isFI()) { |
Chris Lattner | a5bb370 | 2007-12-30 23:10:15 +0000 | [diff] [blame] | 487 | FrameIndex = MI->getOperand(2).getIndex(); |
Chris Lattner | bb53acd | 2006-02-02 20:12:32 +0000 | [diff] [blame] | 488 | return MI->getOperand(0).getReg(); |
| 489 | } |
| 490 | break; |
| 491 | } |
| 492 | return 0; |
Chris Lattner | c327d71 | 2006-02-02 20:16:12 +0000 | [diff] [blame] | 493 | } |
Chris Lattner | bb53acd | 2006-02-02 20:12:32 +0000 | [diff] [blame] | 494 | |
Andrew Trick | c416ba6 | 2010-12-24 04:28:06 +0000 | [diff] [blame] | 495 | unsigned PPCInstrInfo::isStoreToStackSlot(const MachineInstr *MI, |
Chris Lattner | c327d71 | 2006-02-02 20:16:12 +0000 | [diff] [blame] | 496 | int &FrameIndex) const { |
Hal Finkel | 37714b8 | 2013-03-27 21:21:15 +0000 | [diff] [blame] | 497 | // Note: This list must be kept consistent with StoreRegToStackSlot. |
Chris Lattner | c327d71 | 2006-02-02 20:16:12 +0000 | [diff] [blame] | 498 | switch (MI->getOpcode()) { |
| 499 | default: break; |
Nate Begeman | 4efb328 | 2006-02-02 21:07:50 +0000 | [diff] [blame] | 500 | case PPC::STD: |
Chris Lattner | c327d71 | 2006-02-02 20:16:12 +0000 | [diff] [blame] | 501 | case PPC::STW: |
| 502 | case PPC::STFS: |
| 503 | case PPC::STFD: |
Hal Finkel | 37714b8 | 2013-03-27 21:21:15 +0000 | [diff] [blame] | 504 | case PPC::SPILL_CR: |
Hal Finkel | 940ab93 | 2014-02-28 00:27:01 +0000 | [diff] [blame] | 505 | case PPC::SPILL_CRBIT: |
Hal Finkel | 37714b8 | 2013-03-27 21:21:15 +0000 | [diff] [blame] | 506 | case PPC::STVX: |
Hal Finkel | 27774d9 | 2014-03-13 07:58:58 +0000 | [diff] [blame] | 507 | case PPC::STXVD2X: |
Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 508 | case PPC::QVSTFDX: |
| 509 | case PPC::QVSTFSXs: |
| 510 | case PPC::QVSTFDXb: |
Hal Finkel | 37714b8 | 2013-03-27 21:21:15 +0000 | [diff] [blame] | 511 | case PPC::SPILL_VRSAVE: |
| 512 | // Check for the operands added by addFrameReference (the immediate is the |
| 513 | // offset which defaults to 0). |
Dan Gohman | 0d1e9a8 | 2008-10-03 15:45:36 +0000 | [diff] [blame] | 514 | if (MI->getOperand(1).isImm() && !MI->getOperand(1).getImm() && |
| 515 | MI->getOperand(2).isFI()) { |
Chris Lattner | a5bb370 | 2007-12-30 23:10:15 +0000 | [diff] [blame] | 516 | FrameIndex = MI->getOperand(2).getIndex(); |
Chris Lattner | c327d71 | 2006-02-02 20:16:12 +0000 | [diff] [blame] | 517 | return MI->getOperand(0).getReg(); |
| 518 | } |
| 519 | break; |
| 520 | } |
| 521 | return 0; |
| 522 | } |
Chris Lattner | bb53acd | 2006-02-02 20:12:32 +0000 | [diff] [blame] | 523 | |
Chris Lattner | c37a2f1 | 2005-09-09 18:17:41 +0000 | [diff] [blame] | 524 | // commuteInstruction - We can commute rlwimi instructions, but only if the |
| 525 | // rotate amt is zero. We also have to munge the immediates a bit. |
Evan Cheng | 03553bb | 2008-06-16 07:33:11 +0000 | [diff] [blame] | 526 | MachineInstr * |
| 527 | PPCInstrInfo::commuteInstruction(MachineInstr *MI, bool NewMI) const { |
Dan Gohman | 3b46030 | 2008-07-07 23:14:23 +0000 | [diff] [blame] | 528 | MachineFunction &MF = *MI->getParent()->getParent(); |
| 529 | |
Chris Lattner | c37a2f1 | 2005-09-09 18:17:41 +0000 | [diff] [blame] | 530 | // Normal instructions can be commuted the obvious way. |
Hal Finkel | 654d43b | 2013-04-12 02:18:09 +0000 | [diff] [blame] | 531 | if (MI->getOpcode() != PPC::RLWIMI && |
Hal Finkel | 4c6658f | 2014-12-12 23:59:36 +0000 | [diff] [blame] | 532 | MI->getOpcode() != PPC::RLWIMIo) |
Jakob Stoklund Olesen | 9de596e | 2012-11-28 02:35:17 +0000 | [diff] [blame] | 533 | return TargetInstrInfo::commuteInstruction(MI, NewMI); |
Hal Finkel | 4c6658f | 2014-12-12 23:59:36 +0000 | [diff] [blame] | 534 | // Note that RLWIMI can be commuted as a 32-bit instruction, but not as a |
| 535 | // 64-bit instruction (so we don't handle PPC::RLWIMI8 here), because |
| 536 | // changing the relative order of the mask operands might change what happens |
| 537 | // to the high-bits of the mask (and, thus, the result). |
Andrew Trick | c416ba6 | 2010-12-24 04:28:06 +0000 | [diff] [blame] | 538 | |
Chris Lattner | c37a2f1 | 2005-09-09 18:17:41 +0000 | [diff] [blame] | 539 | // Cannot commute if it has a non-zero rotate count. |
Chris Lattner | 5c46378 | 2007-12-30 20:49:49 +0000 | [diff] [blame] | 540 | if (MI->getOperand(3).getImm() != 0) |
Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 541 | return nullptr; |
Andrew Trick | c416ba6 | 2010-12-24 04:28:06 +0000 | [diff] [blame] | 542 | |
Chris Lattner | c37a2f1 | 2005-09-09 18:17:41 +0000 | [diff] [blame] | 543 | // If we have a zero rotate count, we have: |
| 544 | // M = mask(MB,ME) |
| 545 | // Op0 = (Op1 & ~M) | (Op2 & M) |
| 546 | // Change this to: |
| 547 | // M = mask((ME+1)&31, (MB-1)&31) |
| 548 | // Op0 = (Op2 & ~M) | (Op1 & M) |
| 549 | |
| 550 | // Swap op1/op2 |
Evan Cheng | 244183e | 2008-02-13 02:46:49 +0000 | [diff] [blame] | 551 | unsigned Reg0 = MI->getOperand(0).getReg(); |
Chris Lattner | c37a2f1 | 2005-09-09 18:17:41 +0000 | [diff] [blame] | 552 | unsigned Reg1 = MI->getOperand(1).getReg(); |
| 553 | unsigned Reg2 = MI->getOperand(2).getReg(); |
Andrew Trick | e339828 | 2013-12-17 04:50:45 +0000 | [diff] [blame] | 554 | unsigned SubReg1 = MI->getOperand(1).getSubReg(); |
| 555 | unsigned SubReg2 = MI->getOperand(2).getSubReg(); |
Evan Cheng | dc2c874 | 2006-11-15 20:58:11 +0000 | [diff] [blame] | 556 | bool Reg1IsKill = MI->getOperand(1).isKill(); |
| 557 | bool Reg2IsKill = MI->getOperand(2).isKill(); |
Evan Cheng | 03553bb | 2008-06-16 07:33:11 +0000 | [diff] [blame] | 558 | bool ChangeReg0 = false; |
Evan Cheng | 244183e | 2008-02-13 02:46:49 +0000 | [diff] [blame] | 559 | // If machine instrs are no longer in two-address forms, update |
| 560 | // destination register as well. |
| 561 | if (Reg0 == Reg1) { |
| 562 | // Must be two address instruction! |
Evan Cheng | 6cc775f | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 563 | assert(MI->getDesc().getOperandConstraint(0, MCOI::TIED_TO) && |
Evan Cheng | 244183e | 2008-02-13 02:46:49 +0000 | [diff] [blame] | 564 | "Expecting a two-address instruction!"); |
Andrew Trick | e339828 | 2013-12-17 04:50:45 +0000 | [diff] [blame] | 565 | assert(MI->getOperand(0).getSubReg() == SubReg1 && "Tied subreg mismatch"); |
Evan Cheng | 244183e | 2008-02-13 02:46:49 +0000 | [diff] [blame] | 566 | Reg2IsKill = false; |
Evan Cheng | 03553bb | 2008-06-16 07:33:11 +0000 | [diff] [blame] | 567 | ChangeReg0 = true; |
Evan Cheng | 244183e | 2008-02-13 02:46:49 +0000 | [diff] [blame] | 568 | } |
Evan Cheng | 03553bb | 2008-06-16 07:33:11 +0000 | [diff] [blame] | 569 | |
| 570 | // Masks. |
| 571 | unsigned MB = MI->getOperand(4).getImm(); |
| 572 | unsigned ME = MI->getOperand(5).getImm(); |
| 573 | |
| 574 | if (NewMI) { |
| 575 | // Create a new instruction. |
| 576 | unsigned Reg0 = ChangeReg0 ? Reg2 : MI->getOperand(0).getReg(); |
| 577 | bool Reg0IsDead = MI->getOperand(0).isDead(); |
Bill Wendling | f6d609a | 2009-02-12 00:02:55 +0000 | [diff] [blame] | 578 | return BuildMI(MF, MI->getDebugLoc(), MI->getDesc()) |
Bill Wendling | f7b83c7 | 2009-05-13 21:33:08 +0000 | [diff] [blame] | 579 | .addReg(Reg0, RegState::Define | getDeadRegState(Reg0IsDead)) |
| 580 | .addReg(Reg2, getKillRegState(Reg2IsKill)) |
| 581 | .addReg(Reg1, getKillRegState(Reg1IsKill)) |
Evan Cheng | 03553bb | 2008-06-16 07:33:11 +0000 | [diff] [blame] | 582 | .addImm((ME+1) & 31) |
| 583 | .addImm((MB-1) & 31); |
| 584 | } |
| 585 | |
Andrew Trick | e339828 | 2013-12-17 04:50:45 +0000 | [diff] [blame] | 586 | if (ChangeReg0) { |
Evan Cheng | 03553bb | 2008-06-16 07:33:11 +0000 | [diff] [blame] | 587 | MI->getOperand(0).setReg(Reg2); |
Andrew Trick | e339828 | 2013-12-17 04:50:45 +0000 | [diff] [blame] | 588 | MI->getOperand(0).setSubReg(SubReg2); |
| 589 | } |
Chris Lattner | 10d6341 | 2006-05-04 17:52:23 +0000 | [diff] [blame] | 590 | MI->getOperand(2).setReg(Reg1); |
| 591 | MI->getOperand(1).setReg(Reg2); |
Andrew Trick | e339828 | 2013-12-17 04:50:45 +0000 | [diff] [blame] | 592 | MI->getOperand(2).setSubReg(SubReg1); |
| 593 | MI->getOperand(1).setSubReg(SubReg2); |
Chris Lattner | 6005589 | 2007-12-30 21:56:09 +0000 | [diff] [blame] | 594 | MI->getOperand(2).setIsKill(Reg1IsKill); |
| 595 | MI->getOperand(1).setIsKill(Reg2IsKill); |
Andrew Trick | c416ba6 | 2010-12-24 04:28:06 +0000 | [diff] [blame] | 596 | |
Chris Lattner | c37a2f1 | 2005-09-09 18:17:41 +0000 | [diff] [blame] | 597 | // Swap the mask around. |
Chris Lattner | 5c46378 | 2007-12-30 20:49:49 +0000 | [diff] [blame] | 598 | MI->getOperand(4).setImm((ME+1) & 31); |
| 599 | MI->getOperand(5).setImm((MB-1) & 31); |
Chris Lattner | c37a2f1 | 2005-09-09 18:17:41 +0000 | [diff] [blame] | 600 | return MI; |
| 601 | } |
Chris Lattner | ea79d9fd73 | 2006-03-05 23:49:55 +0000 | [diff] [blame] | 602 | |
Hal Finkel | 6c32ff3 | 2014-03-25 19:26:43 +0000 | [diff] [blame] | 603 | bool PPCInstrInfo::findCommutedOpIndices(MachineInstr *MI, unsigned &SrcOpIdx1, |
| 604 | unsigned &SrcOpIdx2) const { |
| 605 | // For VSX A-Type FMA instructions, it is the first two operands that can be |
| 606 | // commuted, however, because the non-encoded tied input operand is listed |
| 607 | // first, the operands to swap are actually the second and third. |
| 608 | |
| 609 | int AltOpc = PPC::getAltVSXFMAOpcode(MI->getOpcode()); |
| 610 | if (AltOpc == -1) |
| 611 | return TargetInstrInfo::findCommutedOpIndices(MI, SrcOpIdx1, SrcOpIdx2); |
| 612 | |
| 613 | SrcOpIdx1 = 2; |
| 614 | SrcOpIdx2 = 3; |
| 615 | return true; |
| 616 | } |
| 617 | |
Andrew Trick | c416ba6 | 2010-12-24 04:28:06 +0000 | [diff] [blame] | 618 | void PPCInstrInfo::insertNoop(MachineBasicBlock &MBB, |
Chris Lattner | ea79d9fd73 | 2006-03-05 23:49:55 +0000 | [diff] [blame] | 619 | MachineBasicBlock::iterator MI) const { |
Hal Finkel | ceb1f12 | 2013-12-12 00:19:11 +0000 | [diff] [blame] | 620 | // This function is used for scheduling, and the nop wanted here is the type |
| 621 | // that terminates dispatch groups on the POWER cores. |
Eric Christopher | 1dcea73 | 2014-06-12 21:48:52 +0000 | [diff] [blame] | 622 | unsigned Directive = Subtarget.getDarwinDirective(); |
Hal Finkel | ceb1f12 | 2013-12-12 00:19:11 +0000 | [diff] [blame] | 623 | unsigned Opcode; |
| 624 | switch (Directive) { |
| 625 | default: Opcode = PPC::NOP; break; |
| 626 | case PPC::DIR_PWR6: Opcode = PPC::NOP_GT_PWR6; break; |
| 627 | case PPC::DIR_PWR7: Opcode = PPC::NOP_GT_PWR7; break; |
Will Schmidt | 970ff64 | 2014-06-26 13:36:19 +0000 | [diff] [blame] | 628 | case PPC::DIR_PWR8: Opcode = PPC::NOP_GT_PWR7; break; /* FIXME: Update when P8 InstrScheduling model is ready */ |
Hal Finkel | ceb1f12 | 2013-12-12 00:19:11 +0000 | [diff] [blame] | 629 | } |
Chris Lattner | a47294ed | 2006-10-13 21:21:17 +0000 | [diff] [blame] | 630 | |
Hal Finkel | ceb1f12 | 2013-12-12 00:19:11 +0000 | [diff] [blame] | 631 | DebugLoc DL; |
| 632 | BuildMI(MBB, MI, DL, get(Opcode)); |
| 633 | } |
Chris Lattner | a47294ed | 2006-10-13 21:21:17 +0000 | [diff] [blame] | 634 | |
Joerg Sonnenberger | 7ee0f31 | 2014-08-08 19:13:23 +0000 | [diff] [blame] | 635 | /// getNoopForMachoTarget - Return the noop instruction to use for a noop. |
| 636 | void PPCInstrInfo::getNoopForMachoTarget(MCInst &NopInst) const { |
| 637 | NopInst.setOpcode(PPC::NOP); |
| 638 | } |
| 639 | |
Chris Lattner | a47294ed | 2006-10-13 21:21:17 +0000 | [diff] [blame] | 640 | // Branch analysis. |
Hal Finkel | 96c2d4d | 2012-06-08 15:38:21 +0000 | [diff] [blame] | 641 | // Note: If the condition register is set to CTR or CTR8 then this is a |
| 642 | // BDNZ (imm == 1) or BDZ (imm == 0) branch. |
Chris Lattner | a47294ed | 2006-10-13 21:21:17 +0000 | [diff] [blame] | 643 | bool PPCInstrInfo::AnalyzeBranch(MachineBasicBlock &MBB,MachineBasicBlock *&TBB, |
| 644 | MachineBasicBlock *&FBB, |
Evan Cheng | 64dfcac | 2009-02-09 07:14:22 +0000 | [diff] [blame] | 645 | SmallVectorImpl<MachineOperand> &Cond, |
| 646 | bool AllowModify) const { |
Eric Christopher | 1dcea73 | 2014-06-12 21:48:52 +0000 | [diff] [blame] | 647 | bool isPPC64 = Subtarget.isPPC64(); |
Hal Finkel | 96c2d4d | 2012-06-08 15:38:21 +0000 | [diff] [blame] | 648 | |
Chris Lattner | a47294ed | 2006-10-13 21:21:17 +0000 | [diff] [blame] | 649 | // If the block has no terminators, it just falls into the block after it. |
Benjamin Kramer | 92861d7 | 2015-06-25 13:39:03 +0000 | [diff] [blame] | 650 | MachineBasicBlock::iterator I = MBB.getLastNonDebugInstr(); |
| 651 | if (I == MBB.end()) |
Dale Johannesen | 4244d12 | 2010-04-02 01:38:09 +0000 | [diff] [blame] | 652 | return false; |
Benjamin Kramer | 92861d7 | 2015-06-25 13:39:03 +0000 | [diff] [blame] | 653 | |
Dale Johannesen | 4244d12 | 2010-04-02 01:38:09 +0000 | [diff] [blame] | 654 | if (!isUnpredicatedTerminator(I)) |
Chris Lattner | a47294ed | 2006-10-13 21:21:17 +0000 | [diff] [blame] | 655 | return false; |
| 656 | |
| 657 | // Get the last instruction in the block. |
| 658 | MachineInstr *LastInst = I; |
Andrew Trick | c416ba6 | 2010-12-24 04:28:06 +0000 | [diff] [blame] | 659 | |
Chris Lattner | a47294ed | 2006-10-13 21:21:17 +0000 | [diff] [blame] | 660 | // If there is only one terminator instruction, process it. |
Evan Cheng | 5514bbe | 2007-06-08 21:59:56 +0000 | [diff] [blame] | 661 | if (I == MBB.begin() || !isUnpredicatedTerminator(--I)) { |
Chris Lattner | a47294ed | 2006-10-13 21:21:17 +0000 | [diff] [blame] | 662 | if (LastInst->getOpcode() == PPC::B) { |
Evan Cheng | 8f43afd | 2009-05-08 23:09:25 +0000 | [diff] [blame] | 663 | if (!LastInst->getOperand(0).isMBB()) |
| 664 | return true; |
Chris Lattner | a5bb370 | 2007-12-30 23:10:15 +0000 | [diff] [blame] | 665 | TBB = LastInst->getOperand(0).getMBB(); |
Chris Lattner | a47294ed | 2006-10-13 21:21:17 +0000 | [diff] [blame] | 666 | return false; |
Chris Lattner | e026379 | 2006-11-17 22:14:47 +0000 | [diff] [blame] | 667 | } else if (LastInst->getOpcode() == PPC::BCC) { |
Evan Cheng | 8f43afd | 2009-05-08 23:09:25 +0000 | [diff] [blame] | 668 | if (!LastInst->getOperand(2).isMBB()) |
| 669 | return true; |
Chris Lattner | a47294ed | 2006-10-13 21:21:17 +0000 | [diff] [blame] | 670 | // Block ends with fall-through condbranch. |
Chris Lattner | a5bb370 | 2007-12-30 23:10:15 +0000 | [diff] [blame] | 671 | TBB = LastInst->getOperand(2).getMBB(); |
Chris Lattner | a47294ed | 2006-10-13 21:21:17 +0000 | [diff] [blame] | 672 | Cond.push_back(LastInst->getOperand(0)); |
| 673 | Cond.push_back(LastInst->getOperand(1)); |
Chris Lattner | 23f22de | 2006-10-21 06:03:11 +0000 | [diff] [blame] | 674 | return false; |
Hal Finkel | 940ab93 | 2014-02-28 00:27:01 +0000 | [diff] [blame] | 675 | } else if (LastInst->getOpcode() == PPC::BC) { |
| 676 | if (!LastInst->getOperand(1).isMBB()) |
| 677 | return true; |
| 678 | // Block ends with fall-through condbranch. |
| 679 | TBB = LastInst->getOperand(1).getMBB(); |
| 680 | Cond.push_back(MachineOperand::CreateImm(PPC::PRED_BIT_SET)); |
| 681 | Cond.push_back(LastInst->getOperand(0)); |
| 682 | return false; |
| 683 | } else if (LastInst->getOpcode() == PPC::BCn) { |
| 684 | if (!LastInst->getOperand(1).isMBB()) |
| 685 | return true; |
| 686 | // Block ends with fall-through condbranch. |
| 687 | TBB = LastInst->getOperand(1).getMBB(); |
| 688 | Cond.push_back(MachineOperand::CreateImm(PPC::PRED_BIT_UNSET)); |
| 689 | Cond.push_back(LastInst->getOperand(0)); |
| 690 | return false; |
Hal Finkel | 96c2d4d | 2012-06-08 15:38:21 +0000 | [diff] [blame] | 691 | } else if (LastInst->getOpcode() == PPC::BDNZ8 || |
| 692 | LastInst->getOpcode() == PPC::BDNZ) { |
| 693 | if (!LastInst->getOperand(0).isMBB()) |
| 694 | return true; |
Hal Finkel | c6b5deb | 2012-06-08 19:19:53 +0000 | [diff] [blame] | 695 | if (DisableCTRLoopAnal) |
Hal Finkel | 821e001 | 2012-06-08 15:38:25 +0000 | [diff] [blame] | 696 | return true; |
Hal Finkel | 96c2d4d | 2012-06-08 15:38:21 +0000 | [diff] [blame] | 697 | TBB = LastInst->getOperand(0).getMBB(); |
| 698 | Cond.push_back(MachineOperand::CreateImm(1)); |
| 699 | Cond.push_back(MachineOperand::CreateReg(isPPC64 ? PPC::CTR8 : PPC::CTR, |
| 700 | true)); |
| 701 | return false; |
| 702 | } else if (LastInst->getOpcode() == PPC::BDZ8 || |
| 703 | LastInst->getOpcode() == PPC::BDZ) { |
| 704 | if (!LastInst->getOperand(0).isMBB()) |
| 705 | return true; |
Hal Finkel | c6b5deb | 2012-06-08 19:19:53 +0000 | [diff] [blame] | 706 | if (DisableCTRLoopAnal) |
Hal Finkel | 821e001 | 2012-06-08 15:38:25 +0000 | [diff] [blame] | 707 | return true; |
Hal Finkel | 96c2d4d | 2012-06-08 15:38:21 +0000 | [diff] [blame] | 708 | TBB = LastInst->getOperand(0).getMBB(); |
| 709 | Cond.push_back(MachineOperand::CreateImm(0)); |
| 710 | Cond.push_back(MachineOperand::CreateReg(isPPC64 ? PPC::CTR8 : PPC::CTR, |
| 711 | true)); |
| 712 | return false; |
Chris Lattner | a47294ed | 2006-10-13 21:21:17 +0000 | [diff] [blame] | 713 | } |
Hal Finkel | 96c2d4d | 2012-06-08 15:38:21 +0000 | [diff] [blame] | 714 | |
Chris Lattner | a47294ed | 2006-10-13 21:21:17 +0000 | [diff] [blame] | 715 | // Otherwise, don't know what this is. |
| 716 | return true; |
| 717 | } |
Andrew Trick | c416ba6 | 2010-12-24 04:28:06 +0000 | [diff] [blame] | 718 | |
Chris Lattner | a47294ed | 2006-10-13 21:21:17 +0000 | [diff] [blame] | 719 | // Get the instruction before it if it's a terminator. |
| 720 | MachineInstr *SecondLastInst = I; |
| 721 | |
| 722 | // If there are three terminators, we don't know what sort of block this is. |
| 723 | if (SecondLastInst && I != MBB.begin() && |
Evan Cheng | 5514bbe | 2007-06-08 21:59:56 +0000 | [diff] [blame] | 724 | isUnpredicatedTerminator(--I)) |
Chris Lattner | a47294ed | 2006-10-13 21:21:17 +0000 | [diff] [blame] | 725 | return true; |
Andrew Trick | c416ba6 | 2010-12-24 04:28:06 +0000 | [diff] [blame] | 726 | |
Chris Lattner | e026379 | 2006-11-17 22:14:47 +0000 | [diff] [blame] | 727 | // If the block ends with PPC::B and PPC:BCC, handle it. |
Andrew Trick | c416ba6 | 2010-12-24 04:28:06 +0000 | [diff] [blame] | 728 | if (SecondLastInst->getOpcode() == PPC::BCC && |
Chris Lattner | a47294ed | 2006-10-13 21:21:17 +0000 | [diff] [blame] | 729 | LastInst->getOpcode() == PPC::B) { |
Evan Cheng | 8f43afd | 2009-05-08 23:09:25 +0000 | [diff] [blame] | 730 | if (!SecondLastInst->getOperand(2).isMBB() || |
| 731 | !LastInst->getOperand(0).isMBB()) |
| 732 | return true; |
Chris Lattner | a5bb370 | 2007-12-30 23:10:15 +0000 | [diff] [blame] | 733 | TBB = SecondLastInst->getOperand(2).getMBB(); |
Chris Lattner | a47294ed | 2006-10-13 21:21:17 +0000 | [diff] [blame] | 734 | Cond.push_back(SecondLastInst->getOperand(0)); |
| 735 | Cond.push_back(SecondLastInst->getOperand(1)); |
Chris Lattner | a5bb370 | 2007-12-30 23:10:15 +0000 | [diff] [blame] | 736 | FBB = LastInst->getOperand(0).getMBB(); |
Chris Lattner | a47294ed | 2006-10-13 21:21:17 +0000 | [diff] [blame] | 737 | return false; |
Hal Finkel | 940ab93 | 2014-02-28 00:27:01 +0000 | [diff] [blame] | 738 | } else if (SecondLastInst->getOpcode() == PPC::BC && |
| 739 | LastInst->getOpcode() == PPC::B) { |
| 740 | if (!SecondLastInst->getOperand(1).isMBB() || |
| 741 | !LastInst->getOperand(0).isMBB()) |
| 742 | return true; |
| 743 | TBB = SecondLastInst->getOperand(1).getMBB(); |
| 744 | Cond.push_back(MachineOperand::CreateImm(PPC::PRED_BIT_SET)); |
| 745 | Cond.push_back(SecondLastInst->getOperand(0)); |
| 746 | FBB = LastInst->getOperand(0).getMBB(); |
| 747 | return false; |
| 748 | } else if (SecondLastInst->getOpcode() == PPC::BCn && |
| 749 | LastInst->getOpcode() == PPC::B) { |
| 750 | if (!SecondLastInst->getOperand(1).isMBB() || |
| 751 | !LastInst->getOperand(0).isMBB()) |
| 752 | return true; |
| 753 | TBB = SecondLastInst->getOperand(1).getMBB(); |
| 754 | Cond.push_back(MachineOperand::CreateImm(PPC::PRED_BIT_UNSET)); |
| 755 | Cond.push_back(SecondLastInst->getOperand(0)); |
| 756 | FBB = LastInst->getOperand(0).getMBB(); |
| 757 | return false; |
Hal Finkel | 96c2d4d | 2012-06-08 15:38:21 +0000 | [diff] [blame] | 758 | } else if ((SecondLastInst->getOpcode() == PPC::BDNZ8 || |
| 759 | SecondLastInst->getOpcode() == PPC::BDNZ) && |
| 760 | LastInst->getOpcode() == PPC::B) { |
| 761 | if (!SecondLastInst->getOperand(0).isMBB() || |
| 762 | !LastInst->getOperand(0).isMBB()) |
| 763 | return true; |
Hal Finkel | c6b5deb | 2012-06-08 19:19:53 +0000 | [diff] [blame] | 764 | if (DisableCTRLoopAnal) |
Hal Finkel | 821e001 | 2012-06-08 15:38:25 +0000 | [diff] [blame] | 765 | return true; |
Hal Finkel | 96c2d4d | 2012-06-08 15:38:21 +0000 | [diff] [blame] | 766 | TBB = SecondLastInst->getOperand(0).getMBB(); |
| 767 | Cond.push_back(MachineOperand::CreateImm(1)); |
| 768 | Cond.push_back(MachineOperand::CreateReg(isPPC64 ? PPC::CTR8 : PPC::CTR, |
| 769 | true)); |
| 770 | FBB = LastInst->getOperand(0).getMBB(); |
| 771 | return false; |
| 772 | } else if ((SecondLastInst->getOpcode() == PPC::BDZ8 || |
| 773 | SecondLastInst->getOpcode() == PPC::BDZ) && |
| 774 | LastInst->getOpcode() == PPC::B) { |
| 775 | if (!SecondLastInst->getOperand(0).isMBB() || |
| 776 | !LastInst->getOperand(0).isMBB()) |
| 777 | return true; |
Hal Finkel | c6b5deb | 2012-06-08 19:19:53 +0000 | [diff] [blame] | 778 | if (DisableCTRLoopAnal) |
Hal Finkel | 821e001 | 2012-06-08 15:38:25 +0000 | [diff] [blame] | 779 | return true; |
Hal Finkel | 96c2d4d | 2012-06-08 15:38:21 +0000 | [diff] [blame] | 780 | TBB = SecondLastInst->getOperand(0).getMBB(); |
| 781 | Cond.push_back(MachineOperand::CreateImm(0)); |
| 782 | Cond.push_back(MachineOperand::CreateReg(isPPC64 ? PPC::CTR8 : PPC::CTR, |
| 783 | true)); |
| 784 | FBB = LastInst->getOperand(0).getMBB(); |
| 785 | return false; |
Chris Lattner | a47294ed | 2006-10-13 21:21:17 +0000 | [diff] [blame] | 786 | } |
Andrew Trick | c416ba6 | 2010-12-24 04:28:06 +0000 | [diff] [blame] | 787 | |
Dale Johannesen | c685546 | 2007-06-13 17:59:52 +0000 | [diff] [blame] | 788 | // If the block ends with two PPC:Bs, handle it. The second one is not |
| 789 | // executed, so remove it. |
Andrew Trick | c416ba6 | 2010-12-24 04:28:06 +0000 | [diff] [blame] | 790 | if (SecondLastInst->getOpcode() == PPC::B && |
Dale Johannesen | c685546 | 2007-06-13 17:59:52 +0000 | [diff] [blame] | 791 | LastInst->getOpcode() == PPC::B) { |
Evan Cheng | 8f43afd | 2009-05-08 23:09:25 +0000 | [diff] [blame] | 792 | if (!SecondLastInst->getOperand(0).isMBB()) |
| 793 | return true; |
Chris Lattner | a5bb370 | 2007-12-30 23:10:15 +0000 | [diff] [blame] | 794 | TBB = SecondLastInst->getOperand(0).getMBB(); |
Dale Johannesen | c685546 | 2007-06-13 17:59:52 +0000 | [diff] [blame] | 795 | I = LastInst; |
Evan Cheng | 64dfcac | 2009-02-09 07:14:22 +0000 | [diff] [blame] | 796 | if (AllowModify) |
| 797 | I->eraseFromParent(); |
Dale Johannesen | c685546 | 2007-06-13 17:59:52 +0000 | [diff] [blame] | 798 | return false; |
| 799 | } |
| 800 | |
Chris Lattner | a47294ed | 2006-10-13 21:21:17 +0000 | [diff] [blame] | 801 | // Otherwise, can't handle this. |
| 802 | return true; |
| 803 | } |
| 804 | |
Evan Cheng | 99be49d | 2007-05-18 00:05:48 +0000 | [diff] [blame] | 805 | unsigned PPCInstrInfo::RemoveBranch(MachineBasicBlock &MBB) const { |
Benjamin Kramer | 92861d7 | 2015-06-25 13:39:03 +0000 | [diff] [blame] | 806 | MachineBasicBlock::iterator I = MBB.getLastNonDebugInstr(); |
| 807 | if (I == MBB.end()) |
| 808 | return 0; |
| 809 | |
Hal Finkel | 96c2d4d | 2012-06-08 15:38:21 +0000 | [diff] [blame] | 810 | if (I->getOpcode() != PPC::B && I->getOpcode() != PPC::BCC && |
Hal Finkel | 940ab93 | 2014-02-28 00:27:01 +0000 | [diff] [blame] | 811 | I->getOpcode() != PPC::BC && I->getOpcode() != PPC::BCn && |
Hal Finkel | 96c2d4d | 2012-06-08 15:38:21 +0000 | [diff] [blame] | 812 | I->getOpcode() != PPC::BDNZ8 && I->getOpcode() != PPC::BDNZ && |
| 813 | I->getOpcode() != PPC::BDZ8 && I->getOpcode() != PPC::BDZ) |
Evan Cheng | 99be49d | 2007-05-18 00:05:48 +0000 | [diff] [blame] | 814 | return 0; |
Andrew Trick | c416ba6 | 2010-12-24 04:28:06 +0000 | [diff] [blame] | 815 | |
Chris Lattner | a47294ed | 2006-10-13 21:21:17 +0000 | [diff] [blame] | 816 | // Remove the branch. |
| 817 | I->eraseFromParent(); |
Andrew Trick | c416ba6 | 2010-12-24 04:28:06 +0000 | [diff] [blame] | 818 | |
Chris Lattner | a47294ed | 2006-10-13 21:21:17 +0000 | [diff] [blame] | 819 | I = MBB.end(); |
| 820 | |
Evan Cheng | 99be49d | 2007-05-18 00:05:48 +0000 | [diff] [blame] | 821 | if (I == MBB.begin()) return 1; |
Chris Lattner | a47294ed | 2006-10-13 21:21:17 +0000 | [diff] [blame] | 822 | --I; |
Hal Finkel | 96c2d4d | 2012-06-08 15:38:21 +0000 | [diff] [blame] | 823 | if (I->getOpcode() != PPC::BCC && |
Hal Finkel | 940ab93 | 2014-02-28 00:27:01 +0000 | [diff] [blame] | 824 | I->getOpcode() != PPC::BC && I->getOpcode() != PPC::BCn && |
Hal Finkel | 96c2d4d | 2012-06-08 15:38:21 +0000 | [diff] [blame] | 825 | I->getOpcode() != PPC::BDNZ8 && I->getOpcode() != PPC::BDNZ && |
| 826 | I->getOpcode() != PPC::BDZ8 && I->getOpcode() != PPC::BDZ) |
Evan Cheng | 99be49d | 2007-05-18 00:05:48 +0000 | [diff] [blame] | 827 | return 1; |
Andrew Trick | c416ba6 | 2010-12-24 04:28:06 +0000 | [diff] [blame] | 828 | |
Chris Lattner | a47294ed | 2006-10-13 21:21:17 +0000 | [diff] [blame] | 829 | // Remove the branch. |
| 830 | I->eraseFromParent(); |
Evan Cheng | 99be49d | 2007-05-18 00:05:48 +0000 | [diff] [blame] | 831 | return 2; |
Chris Lattner | a47294ed | 2006-10-13 21:21:17 +0000 | [diff] [blame] | 832 | } |
| 833 | |
Evan Cheng | 99be49d | 2007-05-18 00:05:48 +0000 | [diff] [blame] | 834 | unsigned |
| 835 | PPCInstrInfo::InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB, |
| 836 | MachineBasicBlock *FBB, |
Ahmed Bougacha | c88bf54 | 2015-06-11 19:30:37 +0000 | [diff] [blame] | 837 | ArrayRef<MachineOperand> Cond, |
Stuart Hastings | 0125b64 | 2010-06-17 22:43:56 +0000 | [diff] [blame] | 838 | DebugLoc DL) const { |
Chris Lattner | a61f010 | 2006-10-17 18:06:55 +0000 | [diff] [blame] | 839 | // Shouldn't be a fall through. |
| 840 | assert(TBB && "InsertBranch must not be told to insert a fallthrough"); |
Andrew Trick | c416ba6 | 2010-12-24 04:28:06 +0000 | [diff] [blame] | 841 | assert((Cond.size() == 2 || Cond.size() == 0) && |
Chris Lattner | 94e0444 | 2006-10-21 05:36:13 +0000 | [diff] [blame] | 842 | "PPC branch conditions have two components!"); |
Andrew Trick | c416ba6 | 2010-12-24 04:28:06 +0000 | [diff] [blame] | 843 | |
Eric Christopher | 1dcea73 | 2014-06-12 21:48:52 +0000 | [diff] [blame] | 844 | bool isPPC64 = Subtarget.isPPC64(); |
Hal Finkel | 96c2d4d | 2012-06-08 15:38:21 +0000 | [diff] [blame] | 845 | |
Chris Lattner | 94e0444 | 2006-10-21 05:36:13 +0000 | [diff] [blame] | 846 | // One-way branch. |
Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 847 | if (!FBB) { |
Chris Lattner | 94e0444 | 2006-10-21 05:36:13 +0000 | [diff] [blame] | 848 | if (Cond.empty()) // Unconditional branch |
Stuart Hastings | 0125b64 | 2010-06-17 22:43:56 +0000 | [diff] [blame] | 849 | BuildMI(&MBB, DL, get(PPC::B)).addMBB(TBB); |
Hal Finkel | 96c2d4d | 2012-06-08 15:38:21 +0000 | [diff] [blame] | 850 | else if (Cond[1].getReg() == PPC::CTR || Cond[1].getReg() == PPC::CTR8) |
| 851 | BuildMI(&MBB, DL, get(Cond[0].getImm() ? |
| 852 | (isPPC64 ? PPC::BDNZ8 : PPC::BDNZ) : |
| 853 | (isPPC64 ? PPC::BDZ8 : PPC::BDZ))).addMBB(TBB); |
Hal Finkel | 940ab93 | 2014-02-28 00:27:01 +0000 | [diff] [blame] | 854 | else if (Cond[0].getImm() == PPC::PRED_BIT_SET) |
| 855 | BuildMI(&MBB, DL, get(PPC::BC)).addOperand(Cond[1]).addMBB(TBB); |
| 856 | else if (Cond[0].getImm() == PPC::PRED_BIT_UNSET) |
| 857 | BuildMI(&MBB, DL, get(PPC::BCn)).addOperand(Cond[1]).addMBB(TBB); |
Chris Lattner | 94e0444 | 2006-10-21 05:36:13 +0000 | [diff] [blame] | 858 | else // Conditional branch |
Stuart Hastings | 0125b64 | 2010-06-17 22:43:56 +0000 | [diff] [blame] | 859 | BuildMI(&MBB, DL, get(PPC::BCC)) |
Hal Finkel | 940ab93 | 2014-02-28 00:27:01 +0000 | [diff] [blame] | 860 | .addImm(Cond[0].getImm()).addOperand(Cond[1]).addMBB(TBB); |
Evan Cheng | 99be49d | 2007-05-18 00:05:48 +0000 | [diff] [blame] | 861 | return 1; |
Chris Lattner | a61f010 | 2006-10-17 18:06:55 +0000 | [diff] [blame] | 862 | } |
Andrew Trick | c416ba6 | 2010-12-24 04:28:06 +0000 | [diff] [blame] | 863 | |
Chris Lattner | d881660 | 2006-10-21 05:42:09 +0000 | [diff] [blame] | 864 | // Two-way Conditional Branch. |
Hal Finkel | 96c2d4d | 2012-06-08 15:38:21 +0000 | [diff] [blame] | 865 | if (Cond[1].getReg() == PPC::CTR || Cond[1].getReg() == PPC::CTR8) |
| 866 | BuildMI(&MBB, DL, get(Cond[0].getImm() ? |
| 867 | (isPPC64 ? PPC::BDNZ8 : PPC::BDNZ) : |
| 868 | (isPPC64 ? PPC::BDZ8 : PPC::BDZ))).addMBB(TBB); |
Hal Finkel | 940ab93 | 2014-02-28 00:27:01 +0000 | [diff] [blame] | 869 | else if (Cond[0].getImm() == PPC::PRED_BIT_SET) |
| 870 | BuildMI(&MBB, DL, get(PPC::BC)).addOperand(Cond[1]).addMBB(TBB); |
| 871 | else if (Cond[0].getImm() == PPC::PRED_BIT_UNSET) |
| 872 | BuildMI(&MBB, DL, get(PPC::BCn)).addOperand(Cond[1]).addMBB(TBB); |
Hal Finkel | 96c2d4d | 2012-06-08 15:38:21 +0000 | [diff] [blame] | 873 | else |
| 874 | BuildMI(&MBB, DL, get(PPC::BCC)) |
Hal Finkel | 940ab93 | 2014-02-28 00:27:01 +0000 | [diff] [blame] | 875 | .addImm(Cond[0].getImm()).addOperand(Cond[1]).addMBB(TBB); |
Stuart Hastings | 0125b64 | 2010-06-17 22:43:56 +0000 | [diff] [blame] | 876 | BuildMI(&MBB, DL, get(PPC::B)).addMBB(FBB); |
Evan Cheng | 99be49d | 2007-05-18 00:05:48 +0000 | [diff] [blame] | 877 | return 2; |
Chris Lattner | a47294ed | 2006-10-13 21:21:17 +0000 | [diff] [blame] | 878 | } |
| 879 | |
Hal Finkel | ed6a285 | 2013-04-05 23:29:01 +0000 | [diff] [blame] | 880 | // Select analysis. |
| 881 | bool PPCInstrInfo::canInsertSelect(const MachineBasicBlock &MBB, |
Ahmed Bougacha | c88bf54 | 2015-06-11 19:30:37 +0000 | [diff] [blame] | 882 | ArrayRef<MachineOperand> Cond, |
Hal Finkel | ed6a285 | 2013-04-05 23:29:01 +0000 | [diff] [blame] | 883 | unsigned TrueReg, unsigned FalseReg, |
| 884 | int &CondCycles, int &TrueCycles, int &FalseCycles) const { |
Eric Christopher | 1dcea73 | 2014-06-12 21:48:52 +0000 | [diff] [blame] | 885 | if (!Subtarget.hasISEL()) |
Hal Finkel | ed6a285 | 2013-04-05 23:29:01 +0000 | [diff] [blame] | 886 | return false; |
| 887 | |
| 888 | if (Cond.size() != 2) |
| 889 | return false; |
| 890 | |
| 891 | // If this is really a bdnz-like condition, then it cannot be turned into a |
| 892 | // select. |
| 893 | if (Cond[1].getReg() == PPC::CTR || Cond[1].getReg() == PPC::CTR8) |
| 894 | return false; |
| 895 | |
| 896 | // Check register classes. |
| 897 | const MachineRegisterInfo &MRI = MBB.getParent()->getRegInfo(); |
| 898 | const TargetRegisterClass *RC = |
| 899 | RI.getCommonSubClass(MRI.getRegClass(TrueReg), MRI.getRegClass(FalseReg)); |
| 900 | if (!RC) |
| 901 | return false; |
| 902 | |
| 903 | // isel is for regular integer GPRs only. |
| 904 | if (!PPC::GPRCRegClass.hasSubClassEq(RC) && |
Hal Finkel | 8e8618a | 2013-07-15 20:22:58 +0000 | [diff] [blame] | 905 | !PPC::GPRC_NOR0RegClass.hasSubClassEq(RC) && |
| 906 | !PPC::G8RCRegClass.hasSubClassEq(RC) && |
| 907 | !PPC::G8RC_NOX0RegClass.hasSubClassEq(RC)) |
Hal Finkel | ed6a285 | 2013-04-05 23:29:01 +0000 | [diff] [blame] | 908 | return false; |
| 909 | |
| 910 | // FIXME: These numbers are for the A2, how well they work for other cores is |
| 911 | // an open question. On the A2, the isel instruction has a 2-cycle latency |
| 912 | // but single-cycle throughput. These numbers are used in combination with |
| 913 | // the MispredictPenalty setting from the active SchedMachineModel. |
| 914 | CondCycles = 1; |
| 915 | TrueCycles = 1; |
| 916 | FalseCycles = 1; |
| 917 | |
| 918 | return true; |
| 919 | } |
| 920 | |
| 921 | void PPCInstrInfo::insertSelect(MachineBasicBlock &MBB, |
| 922 | MachineBasicBlock::iterator MI, DebugLoc dl, |
Ahmed Bougacha | c88bf54 | 2015-06-11 19:30:37 +0000 | [diff] [blame] | 923 | unsigned DestReg, ArrayRef<MachineOperand> Cond, |
Hal Finkel | ed6a285 | 2013-04-05 23:29:01 +0000 | [diff] [blame] | 924 | unsigned TrueReg, unsigned FalseReg) const { |
| 925 | assert(Cond.size() == 2 && |
| 926 | "PPC branch conditions have two components!"); |
| 927 | |
Eric Christopher | 1dcea73 | 2014-06-12 21:48:52 +0000 | [diff] [blame] | 928 | assert(Subtarget.hasISEL() && |
Hal Finkel | ed6a285 | 2013-04-05 23:29:01 +0000 | [diff] [blame] | 929 | "Cannot insert select on target without ISEL support"); |
| 930 | |
| 931 | // Get the register classes. |
| 932 | MachineRegisterInfo &MRI = MBB.getParent()->getRegInfo(); |
| 933 | const TargetRegisterClass *RC = |
| 934 | RI.getCommonSubClass(MRI.getRegClass(TrueReg), MRI.getRegClass(FalseReg)); |
| 935 | assert(RC && "TrueReg and FalseReg must have overlapping register classes"); |
Hal Finkel | 8e8618a | 2013-07-15 20:22:58 +0000 | [diff] [blame] | 936 | |
| 937 | bool Is64Bit = PPC::G8RCRegClass.hasSubClassEq(RC) || |
| 938 | PPC::G8RC_NOX0RegClass.hasSubClassEq(RC); |
| 939 | assert((Is64Bit || |
| 940 | PPC::GPRCRegClass.hasSubClassEq(RC) || |
| 941 | PPC::GPRC_NOR0RegClass.hasSubClassEq(RC)) && |
Hal Finkel | ed6a285 | 2013-04-05 23:29:01 +0000 | [diff] [blame] | 942 | "isel is for regular integer GPRs only"); |
| 943 | |
Hal Finkel | 8e8618a | 2013-07-15 20:22:58 +0000 | [diff] [blame] | 944 | unsigned OpCode = Is64Bit ? PPC::ISEL8 : PPC::ISEL; |
Hal Finkel | ed6a285 | 2013-04-05 23:29:01 +0000 | [diff] [blame] | 945 | unsigned SelectPred = Cond[0].getImm(); |
| 946 | |
| 947 | unsigned SubIdx; |
| 948 | bool SwapOps; |
| 949 | switch (SelectPred) { |
| 950 | default: llvm_unreachable("invalid predicate for isel"); |
| 951 | case PPC::PRED_EQ: SubIdx = PPC::sub_eq; SwapOps = false; break; |
| 952 | case PPC::PRED_NE: SubIdx = PPC::sub_eq; SwapOps = true; break; |
| 953 | case PPC::PRED_LT: SubIdx = PPC::sub_lt; SwapOps = false; break; |
| 954 | case PPC::PRED_GE: SubIdx = PPC::sub_lt; SwapOps = true; break; |
| 955 | case PPC::PRED_GT: SubIdx = PPC::sub_gt; SwapOps = false; break; |
| 956 | case PPC::PRED_LE: SubIdx = PPC::sub_gt; SwapOps = true; break; |
| 957 | case PPC::PRED_UN: SubIdx = PPC::sub_un; SwapOps = false; break; |
| 958 | case PPC::PRED_NU: SubIdx = PPC::sub_un; SwapOps = true; break; |
Hal Finkel | 940ab93 | 2014-02-28 00:27:01 +0000 | [diff] [blame] | 959 | case PPC::PRED_BIT_SET: SubIdx = 0; SwapOps = false; break; |
| 960 | case PPC::PRED_BIT_UNSET: SubIdx = 0; SwapOps = true; break; |
Hal Finkel | ed6a285 | 2013-04-05 23:29:01 +0000 | [diff] [blame] | 961 | } |
| 962 | |
| 963 | unsigned FirstReg = SwapOps ? FalseReg : TrueReg, |
| 964 | SecondReg = SwapOps ? TrueReg : FalseReg; |
| 965 | |
| 966 | // The first input register of isel cannot be r0. If it is a member |
| 967 | // of a register class that can be r0, then copy it first (the |
| 968 | // register allocator should eliminate the copy). |
| 969 | if (MRI.getRegClass(FirstReg)->contains(PPC::R0) || |
| 970 | MRI.getRegClass(FirstReg)->contains(PPC::X0)) { |
| 971 | const TargetRegisterClass *FirstRC = |
| 972 | MRI.getRegClass(FirstReg)->contains(PPC::X0) ? |
| 973 | &PPC::G8RC_NOX0RegClass : &PPC::GPRC_NOR0RegClass; |
| 974 | unsigned OldFirstReg = FirstReg; |
| 975 | FirstReg = MRI.createVirtualRegister(FirstRC); |
| 976 | BuildMI(MBB, MI, dl, get(TargetOpcode::COPY), FirstReg) |
| 977 | .addReg(OldFirstReg); |
| 978 | } |
| 979 | |
| 980 | BuildMI(MBB, MI, dl, get(OpCode), DestReg) |
| 981 | .addReg(FirstReg).addReg(SecondReg) |
| 982 | .addReg(Cond[1].getReg(), 0, SubIdx); |
| 983 | } |
| 984 | |
Kit Barton | 535e69d | 2015-03-25 19:36:23 +0000 | [diff] [blame] | 985 | static unsigned getCRBitValue(unsigned CRBit) { |
| 986 | unsigned Ret = 4; |
| 987 | if (CRBit == PPC::CR0LT || CRBit == PPC::CR1LT || |
| 988 | CRBit == PPC::CR2LT || CRBit == PPC::CR3LT || |
| 989 | CRBit == PPC::CR4LT || CRBit == PPC::CR5LT || |
| 990 | CRBit == PPC::CR6LT || CRBit == PPC::CR7LT) |
| 991 | Ret = 3; |
| 992 | if (CRBit == PPC::CR0GT || CRBit == PPC::CR1GT || |
| 993 | CRBit == PPC::CR2GT || CRBit == PPC::CR3GT || |
| 994 | CRBit == PPC::CR4GT || CRBit == PPC::CR5GT || |
| 995 | CRBit == PPC::CR6GT || CRBit == PPC::CR7GT) |
| 996 | Ret = 2; |
| 997 | if (CRBit == PPC::CR0EQ || CRBit == PPC::CR1EQ || |
| 998 | CRBit == PPC::CR2EQ || CRBit == PPC::CR3EQ || |
| 999 | CRBit == PPC::CR4EQ || CRBit == PPC::CR5EQ || |
| 1000 | CRBit == PPC::CR6EQ || CRBit == PPC::CR7EQ) |
| 1001 | Ret = 1; |
| 1002 | if (CRBit == PPC::CR0UN || CRBit == PPC::CR1UN || |
| 1003 | CRBit == PPC::CR2UN || CRBit == PPC::CR3UN || |
| 1004 | CRBit == PPC::CR4UN || CRBit == PPC::CR5UN || |
| 1005 | CRBit == PPC::CR6UN || CRBit == PPC::CR7UN) |
| 1006 | Ret = 0; |
| 1007 | |
| 1008 | assert(Ret != 4 && "Invalid CR bit register"); |
| 1009 | return Ret; |
| 1010 | } |
| 1011 | |
Jakob Stoklund Olesen | 0d61197 | 2010-07-11 07:31:00 +0000 | [diff] [blame] | 1012 | void PPCInstrInfo::copyPhysReg(MachineBasicBlock &MBB, |
| 1013 | MachineBasicBlock::iterator I, DebugLoc DL, |
| 1014 | unsigned DestReg, unsigned SrcReg, |
| 1015 | bool KillSrc) const { |
Hal Finkel | 27774d9 | 2014-03-13 07:58:58 +0000 | [diff] [blame] | 1016 | // We can end up with self copies and similar things as a result of VSX copy |
Hal Finkel | 9dcb358 | 2014-03-27 22:46:28 +0000 | [diff] [blame] | 1017 | // legalization. Promote them here. |
Hal Finkel | 27774d9 | 2014-03-13 07:58:58 +0000 | [diff] [blame] | 1018 | const TargetRegisterInfo *TRI = &getRegisterInfo(); |
| 1019 | if (PPC::F8RCRegClass.contains(DestReg) && |
Hal Finkel | 5cedafb | 2015-02-16 23:46:30 +0000 | [diff] [blame] | 1020 | PPC::VSRCRegClass.contains(SrcReg)) { |
Hal Finkel | 27774d9 | 2014-03-13 07:58:58 +0000 | [diff] [blame] | 1021 | unsigned SuperReg = |
| 1022 | TRI->getMatchingSuperReg(DestReg, PPC::sub_64, &PPC::VSRCRegClass); |
| 1023 | |
Hal Finkel | 9dcb358 | 2014-03-27 22:46:28 +0000 | [diff] [blame] | 1024 | if (VSXSelfCopyCrash && SrcReg == SuperReg) |
| 1025 | llvm_unreachable("nop VSX copy"); |
Hal Finkel | 27774d9 | 2014-03-13 07:58:58 +0000 | [diff] [blame] | 1026 | |
| 1027 | DestReg = SuperReg; |
| 1028 | } else if (PPC::VRRCRegClass.contains(DestReg) && |
Hal Finkel | 5cedafb | 2015-02-16 23:46:30 +0000 | [diff] [blame] | 1029 | PPC::VSRCRegClass.contains(SrcReg)) { |
Hal Finkel | 27774d9 | 2014-03-13 07:58:58 +0000 | [diff] [blame] | 1030 | unsigned SuperReg = |
| 1031 | TRI->getMatchingSuperReg(DestReg, PPC::sub_128, &PPC::VSRCRegClass); |
| 1032 | |
Hal Finkel | 9dcb358 | 2014-03-27 22:46:28 +0000 | [diff] [blame] | 1033 | if (VSXSelfCopyCrash && SrcReg == SuperReg) |
| 1034 | llvm_unreachable("nop VSX copy"); |
Hal Finkel | 27774d9 | 2014-03-13 07:58:58 +0000 | [diff] [blame] | 1035 | |
| 1036 | DestReg = SuperReg; |
| 1037 | } else if (PPC::F8RCRegClass.contains(SrcReg) && |
Hal Finkel | 5cedafb | 2015-02-16 23:46:30 +0000 | [diff] [blame] | 1038 | PPC::VSRCRegClass.contains(DestReg)) { |
Hal Finkel | 27774d9 | 2014-03-13 07:58:58 +0000 | [diff] [blame] | 1039 | unsigned SuperReg = |
| 1040 | TRI->getMatchingSuperReg(SrcReg, PPC::sub_64, &PPC::VSRCRegClass); |
| 1041 | |
Hal Finkel | 9dcb358 | 2014-03-27 22:46:28 +0000 | [diff] [blame] | 1042 | if (VSXSelfCopyCrash && DestReg == SuperReg) |
| 1043 | llvm_unreachable("nop VSX copy"); |
Hal Finkel | 27774d9 | 2014-03-13 07:58:58 +0000 | [diff] [blame] | 1044 | |
| 1045 | SrcReg = SuperReg; |
| 1046 | } else if (PPC::VRRCRegClass.contains(SrcReg) && |
Hal Finkel | 5cedafb | 2015-02-16 23:46:30 +0000 | [diff] [blame] | 1047 | PPC::VSRCRegClass.contains(DestReg)) { |
Hal Finkel | 27774d9 | 2014-03-13 07:58:58 +0000 | [diff] [blame] | 1048 | unsigned SuperReg = |
| 1049 | TRI->getMatchingSuperReg(SrcReg, PPC::sub_128, &PPC::VSRCRegClass); |
| 1050 | |
Hal Finkel | 9dcb358 | 2014-03-27 22:46:28 +0000 | [diff] [blame] | 1051 | if (VSXSelfCopyCrash && DestReg == SuperReg) |
| 1052 | llvm_unreachable("nop VSX copy"); |
Hal Finkel | 27774d9 | 2014-03-13 07:58:58 +0000 | [diff] [blame] | 1053 | |
| 1054 | SrcReg = SuperReg; |
| 1055 | } |
| 1056 | |
Kit Barton | 535e69d | 2015-03-25 19:36:23 +0000 | [diff] [blame] | 1057 | // Different class register copy |
| 1058 | if (PPC::CRBITRCRegClass.contains(SrcReg) && |
| 1059 | PPC::GPRCRegClass.contains(DestReg)) { |
| 1060 | unsigned CRReg = getCRFromCRBit(SrcReg); |
| 1061 | BuildMI(MBB, I, DL, get(PPC::MFOCRF), DestReg) |
| 1062 | .addReg(CRReg), getKillRegState(KillSrc); |
| 1063 | // Rotate the CR bit in the CR fields to be the least significant bit and |
| 1064 | // then mask with 0x1 (MB = ME = 31). |
| 1065 | BuildMI(MBB, I, DL, get(PPC::RLWINM), DestReg) |
| 1066 | .addReg(DestReg, RegState::Kill) |
| 1067 | .addImm(TRI->getEncodingValue(CRReg) * 4 + (4 - getCRBitValue(SrcReg))) |
| 1068 | .addImm(31) |
| 1069 | .addImm(31); |
| 1070 | return; |
| 1071 | } else if (PPC::CRRCRegClass.contains(SrcReg) && |
| 1072 | PPC::G8RCRegClass.contains(DestReg)) { |
| 1073 | BuildMI(MBB, I, DL, get(PPC::MFOCRF8), DestReg) |
| 1074 | .addReg(SrcReg), getKillRegState(KillSrc); |
| 1075 | return; |
| 1076 | } else if (PPC::CRRCRegClass.contains(SrcReg) && |
| 1077 | PPC::GPRCRegClass.contains(DestReg)) { |
| 1078 | BuildMI(MBB, I, DL, get(PPC::MFOCRF), DestReg) |
| 1079 | .addReg(SrcReg), getKillRegState(KillSrc); |
| 1080 | return; |
| 1081 | } |
| 1082 | |
Jakob Stoklund Olesen | 0d61197 | 2010-07-11 07:31:00 +0000 | [diff] [blame] | 1083 | unsigned Opc; |
| 1084 | if (PPC::GPRCRegClass.contains(DestReg, SrcReg)) |
| 1085 | Opc = PPC::OR; |
| 1086 | else if (PPC::G8RCRegClass.contains(DestReg, SrcReg)) |
| 1087 | Opc = PPC::OR8; |
| 1088 | else if (PPC::F4RCRegClass.contains(DestReg, SrcReg)) |
| 1089 | Opc = PPC::FMR; |
| 1090 | else if (PPC::CRRCRegClass.contains(DestReg, SrcReg)) |
| 1091 | Opc = PPC::MCRF; |
| 1092 | else if (PPC::VRRCRegClass.contains(DestReg, SrcReg)) |
| 1093 | Opc = PPC::VOR; |
Hal Finkel | 27774d9 | 2014-03-13 07:58:58 +0000 | [diff] [blame] | 1094 | else if (PPC::VSRCRegClass.contains(DestReg, SrcReg)) |
Hal Finkel | bbad233 | 2014-03-24 09:36:36 +0000 | [diff] [blame] | 1095 | // There are two different ways this can be done: |
Hal Finkel | 27774d9 | 2014-03-13 07:58:58 +0000 | [diff] [blame] | 1096 | // 1. xxlor : This has lower latency (on the P7), 2 cycles, but can only |
| 1097 | // issue in VSU pipeline 0. |
| 1098 | // 2. xmovdp/xmovsp: This has higher latency (on the P7), 6 cycles, but |
| 1099 | // can go to either pipeline. |
Hal Finkel | bbad233 | 2014-03-24 09:36:36 +0000 | [diff] [blame] | 1100 | // We'll always use xxlor here, because in practically all cases where |
| 1101 | // copies are generated, they are close enough to some use that the |
| 1102 | // lower-latency form is preferable. |
Hal Finkel | 27774d9 | 2014-03-13 07:58:58 +0000 | [diff] [blame] | 1103 | Opc = PPC::XXLOR; |
Nemanja Ivanovic | f3c94b1 | 2015-05-07 18:24:05 +0000 | [diff] [blame] | 1104 | else if (PPC::VSFRCRegClass.contains(DestReg, SrcReg) || |
| 1105 | PPC::VSSRCRegClass.contains(DestReg, SrcReg)) |
Hal Finkel | 19be506 | 2014-03-29 05:29:01 +0000 | [diff] [blame] | 1106 | Opc = PPC::XXLORf; |
Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 1107 | else if (PPC::QFRCRegClass.contains(DestReg, SrcReg)) |
| 1108 | Opc = PPC::QVFMR; |
| 1109 | else if (PPC::QSRCRegClass.contains(DestReg, SrcReg)) |
| 1110 | Opc = PPC::QVFMRs; |
| 1111 | else if (PPC::QBRCRegClass.contains(DestReg, SrcReg)) |
| 1112 | Opc = PPC::QVFMRb; |
Jakob Stoklund Olesen | 0d61197 | 2010-07-11 07:31:00 +0000 | [diff] [blame] | 1113 | else if (PPC::CRBITRCRegClass.contains(DestReg, SrcReg)) |
| 1114 | Opc = PPC::CROR; |
| 1115 | else |
| 1116 | llvm_unreachable("Impossible reg-to-reg copy"); |
Owen Anderson | 7a73ae9 | 2007-12-31 06:32:00 +0000 | [diff] [blame] | 1117 | |
Evan Cheng | 6cc775f | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 1118 | const MCInstrDesc &MCID = get(Opc); |
| 1119 | if (MCID.getNumOperands() == 3) |
| 1120 | BuildMI(MBB, I, DL, MCID, DestReg) |
Jakob Stoklund Olesen | 0d61197 | 2010-07-11 07:31:00 +0000 | [diff] [blame] | 1121 | .addReg(SrcReg).addReg(SrcReg, getKillRegState(KillSrc)); |
| 1122 | else |
Evan Cheng | 6cc775f | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 1123 | BuildMI(MBB, I, DL, MCID, DestReg).addReg(SrcReg, getKillRegState(KillSrc)); |
Owen Anderson | 7a73ae9 | 2007-12-31 06:32:00 +0000 | [diff] [blame] | 1124 | } |
| 1125 | |
Hal Finkel | 8f6834d | 2011-12-05 17:55:17 +0000 | [diff] [blame] | 1126 | // This function returns true if a CR spill is necessary and false otherwise. |
Bill Wendling | c6c48fc | 2008-03-10 22:49:16 +0000 | [diff] [blame] | 1127 | bool |
Dan Gohman | 3b46030 | 2008-07-07 23:14:23 +0000 | [diff] [blame] | 1128 | PPCInstrInfo::StoreRegToStackSlot(MachineFunction &MF, |
| 1129 | unsigned SrcReg, bool isKill, |
Bill Wendling | c6c48fc | 2008-03-10 22:49:16 +0000 | [diff] [blame] | 1130 | int FrameIdx, |
| 1131 | const TargetRegisterClass *RC, |
Hal Finkel | fcc51d4 | 2013-03-17 04:43:44 +0000 | [diff] [blame] | 1132 | SmallVectorImpl<MachineInstr*> &NewMIs, |
Hal Finkel | cc1eeda | 2013-03-23 22:06:03 +0000 | [diff] [blame] | 1133 | bool &NonRI, bool &SpillsVRS) const{ |
Hal Finkel | 37714b8 | 2013-03-27 21:21:15 +0000 | [diff] [blame] | 1134 | // Note: If additional store instructions are added here, |
| 1135 | // update isStoreToStackSlot. |
| 1136 | |
Chris Lattner | 6f306d7 | 2010-04-02 20:16:16 +0000 | [diff] [blame] | 1137 | DebugLoc DL; |
Hal Finkel | 4e703bc | 2014-01-28 05:32:58 +0000 | [diff] [blame] | 1138 | if (PPC::GPRCRegClass.hasSubClassEq(RC) || |
| 1139 | PPC::GPRC_NOR0RegClass.hasSubClassEq(RC)) { |
Hal Finkel | 794e05b | 2013-03-23 17:14:27 +0000 | [diff] [blame] | 1140 | NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(PPC::STW)) |
| 1141 | .addReg(SrcReg, |
| 1142 | getKillRegState(isKill)), |
| 1143 | FrameIdx)); |
Hal Finkel | 4e703bc | 2014-01-28 05:32:58 +0000 | [diff] [blame] | 1144 | } else if (PPC::G8RCRegClass.hasSubClassEq(RC) || |
| 1145 | PPC::G8RC_NOX0RegClass.hasSubClassEq(RC)) { |
Hal Finkel | 794e05b | 2013-03-23 17:14:27 +0000 | [diff] [blame] | 1146 | NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(PPC::STD)) |
| 1147 | .addReg(SrcReg, |
| 1148 | getKillRegState(isKill)), |
| 1149 | FrameIdx)); |
Craig Topper | abadc66 | 2012-04-20 06:31:50 +0000 | [diff] [blame] | 1150 | } else if (PPC::F8RCRegClass.hasSubClassEq(RC)) { |
Dale Johannesen | 6b8c76a | 2009-02-12 23:08:38 +0000 | [diff] [blame] | 1151 | NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(PPC::STFD)) |
Bill Wendling | f7b83c7 | 2009-05-13 21:33:08 +0000 | [diff] [blame] | 1152 | .addReg(SrcReg, |
| 1153 | getKillRegState(isKill)), |
| 1154 | FrameIdx)); |
Craig Topper | abadc66 | 2012-04-20 06:31:50 +0000 | [diff] [blame] | 1155 | } else if (PPC::F4RCRegClass.hasSubClassEq(RC)) { |
Dale Johannesen | 6b8c76a | 2009-02-12 23:08:38 +0000 | [diff] [blame] | 1156 | NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(PPC::STFS)) |
Bill Wendling | f7b83c7 | 2009-05-13 21:33:08 +0000 | [diff] [blame] | 1157 | .addReg(SrcReg, |
| 1158 | getKillRegState(isKill)), |
| 1159 | FrameIdx)); |
Craig Topper | abadc66 | 2012-04-20 06:31:50 +0000 | [diff] [blame] | 1160 | } else if (PPC::CRRCRegClass.hasSubClassEq(RC)) { |
Hal Finkel | e154c8f | 2013-03-12 14:12:16 +0000 | [diff] [blame] | 1161 | NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(PPC::SPILL_CR)) |
| 1162 | .addReg(SrcReg, |
| 1163 | getKillRegState(isKill)), |
| 1164 | FrameIdx)); |
| 1165 | return true; |
Craig Topper | abadc66 | 2012-04-20 06:31:50 +0000 | [diff] [blame] | 1166 | } else if (PPC::CRBITRCRegClass.hasSubClassEq(RC)) { |
Hal Finkel | 940ab93 | 2014-02-28 00:27:01 +0000 | [diff] [blame] | 1167 | NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(PPC::SPILL_CRBIT)) |
| 1168 | .addReg(SrcReg, |
| 1169 | getKillRegState(isKill)), |
| 1170 | FrameIdx)); |
| 1171 | return true; |
Craig Topper | abadc66 | 2012-04-20 06:31:50 +0000 | [diff] [blame] | 1172 | } else if (PPC::VRRCRegClass.hasSubClassEq(RC)) { |
Hal Finkel | fcc51d4 | 2013-03-17 04:43:44 +0000 | [diff] [blame] | 1173 | NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(PPC::STVX)) |
| 1174 | .addReg(SrcReg, |
| 1175 | getKillRegState(isKill)), |
| 1176 | FrameIdx)); |
| 1177 | NonRI = true; |
Hal Finkel | 27774d9 | 2014-03-13 07:58:58 +0000 | [diff] [blame] | 1178 | } else if (PPC::VSRCRegClass.hasSubClassEq(RC)) { |
| 1179 | NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(PPC::STXVD2X)) |
| 1180 | .addReg(SrcReg, |
| 1181 | getKillRegState(isKill)), |
| 1182 | FrameIdx)); |
| 1183 | NonRI = true; |
Hal Finkel | 19be506 | 2014-03-29 05:29:01 +0000 | [diff] [blame] | 1184 | } else if (PPC::VSFRCRegClass.hasSubClassEq(RC)) { |
| 1185 | NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(PPC::STXSDX)) |
| 1186 | .addReg(SrcReg, |
| 1187 | getKillRegState(isKill)), |
| 1188 | FrameIdx)); |
| 1189 | NonRI = true; |
Nemanja Ivanovic | f3c94b1 | 2015-05-07 18:24:05 +0000 | [diff] [blame] | 1190 | } else if (PPC::VSSRCRegClass.hasSubClassEq(RC)) { |
| 1191 | NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(PPC::STXSSPX)) |
| 1192 | .addReg(SrcReg, |
| 1193 | getKillRegState(isKill)), |
| 1194 | FrameIdx)); |
| 1195 | NonRI = true; |
Hal Finkel | a1431df | 2013-03-21 19:03:21 +0000 | [diff] [blame] | 1196 | } else if (PPC::VRSAVERCRegClass.hasSubClassEq(RC)) { |
Eric Christopher | 1dcea73 | 2014-06-12 21:48:52 +0000 | [diff] [blame] | 1197 | assert(Subtarget.isDarwin() && |
Hal Finkel | a7b0630 | 2013-03-27 00:02:20 +0000 | [diff] [blame] | 1198 | "VRSAVE only needs spill/restore on Darwin"); |
Hal Finkel | a1431df | 2013-03-21 19:03:21 +0000 | [diff] [blame] | 1199 | NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(PPC::SPILL_VRSAVE)) |
| 1200 | .addReg(SrcReg, |
| 1201 | getKillRegState(isKill)), |
| 1202 | FrameIdx)); |
Hal Finkel | cc1eeda | 2013-03-23 22:06:03 +0000 | [diff] [blame] | 1203 | SpillsVRS = true; |
Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 1204 | } else if (PPC::QFRCRegClass.hasSubClassEq(RC)) { |
| 1205 | NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(PPC::QVSTFDX)) |
| 1206 | .addReg(SrcReg, |
| 1207 | getKillRegState(isKill)), |
| 1208 | FrameIdx)); |
| 1209 | NonRI = true; |
| 1210 | } else if (PPC::QSRCRegClass.hasSubClassEq(RC)) { |
| 1211 | NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(PPC::QVSTFSXs)) |
| 1212 | .addReg(SrcReg, |
| 1213 | getKillRegState(isKill)), |
| 1214 | FrameIdx)); |
| 1215 | NonRI = true; |
| 1216 | } else if (PPC::QBRCRegClass.hasSubClassEq(RC)) { |
| 1217 | NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(PPC::QVSTFDXb)) |
| 1218 | .addReg(SrcReg, |
| 1219 | getKillRegState(isKill)), |
| 1220 | FrameIdx)); |
| 1221 | NonRI = true; |
Owen Anderson | eee1460 | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 1222 | } else { |
Torok Edwin | fbcc663 | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 1223 | llvm_unreachable("Unknown regclass!"); |
Owen Anderson | eee1460 | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 1224 | } |
Bill Wendling | 632ea65 | 2008-03-03 22:19:16 +0000 | [diff] [blame] | 1225 | |
| 1226 | return false; |
Owen Anderson | eee1460 | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 1227 | } |
| 1228 | |
| 1229 | void |
| 1230 | PPCInstrInfo::storeRegToStackSlot(MachineBasicBlock &MBB, |
Bill Wendling | 632ea65 | 2008-03-03 22:19:16 +0000 | [diff] [blame] | 1231 | MachineBasicBlock::iterator MI, |
| 1232 | unsigned SrcReg, bool isKill, int FrameIdx, |
Evan Cheng | efb126a | 2010-05-06 19:06:44 +0000 | [diff] [blame] | 1233 | const TargetRegisterClass *RC, |
| 1234 | const TargetRegisterInfo *TRI) const { |
Dan Gohman | 3b46030 | 2008-07-07 23:14:23 +0000 | [diff] [blame] | 1235 | MachineFunction &MF = *MBB.getParent(); |
Owen Anderson | eee1460 | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 1236 | SmallVector<MachineInstr*, 4> NewMIs; |
Bill Wendling | 632ea65 | 2008-03-03 22:19:16 +0000 | [diff] [blame] | 1237 | |
Hal Finkel | bb420f1 | 2013-03-15 05:06:04 +0000 | [diff] [blame] | 1238 | PPCFunctionInfo *FuncInfo = MF.getInfo<PPCFunctionInfo>(); |
| 1239 | FuncInfo->setHasSpills(); |
| 1240 | |
Hal Finkel | cc1eeda | 2013-03-23 22:06:03 +0000 | [diff] [blame] | 1241 | bool NonRI = false, SpillsVRS = false; |
| 1242 | if (StoreRegToStackSlot(MF, SrcReg, isKill, FrameIdx, RC, NewMIs, |
| 1243 | NonRI, SpillsVRS)) |
Bill Wendling | 632ea65 | 2008-03-03 22:19:16 +0000 | [diff] [blame] | 1244 | FuncInfo->setSpillsCR(); |
Bill Wendling | 632ea65 | 2008-03-03 22:19:16 +0000 | [diff] [blame] | 1245 | |
Hal Finkel | cc1eeda | 2013-03-23 22:06:03 +0000 | [diff] [blame] | 1246 | if (SpillsVRS) |
| 1247 | FuncInfo->setSpillsVRSAVE(); |
| 1248 | |
Hal Finkel | fcc51d4 | 2013-03-17 04:43:44 +0000 | [diff] [blame] | 1249 | if (NonRI) |
| 1250 | FuncInfo->setHasNonRISpills(); |
| 1251 | |
Owen Anderson | eee1460 | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 1252 | for (unsigned i = 0, e = NewMIs.size(); i != e; ++i) |
| 1253 | MBB.insert(MI, NewMIs[i]); |
Jakob Stoklund Olesen | 6353e53 | 2010-07-16 18:22:00 +0000 | [diff] [blame] | 1254 | |
| 1255 | const MachineFrameInfo &MFI = *MF.getFrameInfo(); |
| 1256 | MachineMemOperand *MMO = |
Jay Foad | 465101b | 2011-11-15 07:34:52 +0000 | [diff] [blame] | 1257 | MF.getMachineMemOperand(MachinePointerInfo::getFixedStack(FrameIdx), |
Chris Lattner | e3d864b | 2010-09-21 04:39:43 +0000 | [diff] [blame] | 1258 | MachineMemOperand::MOStore, |
Jakob Stoklund Olesen | 6353e53 | 2010-07-16 18:22:00 +0000 | [diff] [blame] | 1259 | MFI.getObjectSize(FrameIdx), |
| 1260 | MFI.getObjectAlignment(FrameIdx)); |
| 1261 | NewMIs.back()->addMemOperand(MF, MMO); |
Owen Anderson | eee1460 | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 1262 | } |
| 1263 | |
Hal Finkel | bde7f8f | 2011-12-06 20:55:36 +0000 | [diff] [blame] | 1264 | bool |
Bill Wendling | f6d609a | 2009-02-12 00:02:55 +0000 | [diff] [blame] | 1265 | PPCInstrInfo::LoadRegFromStackSlot(MachineFunction &MF, DebugLoc DL, |
Dan Gohman | 3b46030 | 2008-07-07 23:14:23 +0000 | [diff] [blame] | 1266 | unsigned DestReg, int FrameIdx, |
Bill Wendling | c6c48fc | 2008-03-10 22:49:16 +0000 | [diff] [blame] | 1267 | const TargetRegisterClass *RC, |
Hal Finkel | fcc51d4 | 2013-03-17 04:43:44 +0000 | [diff] [blame] | 1268 | SmallVectorImpl<MachineInstr*> &NewMIs, |
Hal Finkel | cc1eeda | 2013-03-23 22:06:03 +0000 | [diff] [blame] | 1269 | bool &NonRI, bool &SpillsVRS) const{ |
Hal Finkel | 37714b8 | 2013-03-27 21:21:15 +0000 | [diff] [blame] | 1270 | // Note: If additional load instructions are added here, |
| 1271 | // update isLoadFromStackSlot. |
| 1272 | |
Hal Finkel | 4e703bc | 2014-01-28 05:32:58 +0000 | [diff] [blame] | 1273 | if (PPC::GPRCRegClass.hasSubClassEq(RC) || |
| 1274 | PPC::GPRC_NOR0RegClass.hasSubClassEq(RC)) { |
Hal Finkel | 5791f51 | 2013-03-27 19:10:40 +0000 | [diff] [blame] | 1275 | NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(PPC::LWZ), |
| 1276 | DestReg), FrameIdx)); |
Hal Finkel | 4e703bc | 2014-01-28 05:32:58 +0000 | [diff] [blame] | 1277 | } else if (PPC::G8RCRegClass.hasSubClassEq(RC) || |
| 1278 | PPC::G8RC_NOX0RegClass.hasSubClassEq(RC)) { |
Hal Finkel | 5791f51 | 2013-03-27 19:10:40 +0000 | [diff] [blame] | 1279 | NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(PPC::LD), DestReg), |
| 1280 | FrameIdx)); |
Craig Topper | abadc66 | 2012-04-20 06:31:50 +0000 | [diff] [blame] | 1281 | } else if (PPC::F8RCRegClass.hasSubClassEq(RC)) { |
Bill Wendling | f6d609a | 2009-02-12 00:02:55 +0000 | [diff] [blame] | 1282 | NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(PPC::LFD), DestReg), |
Owen Anderson | eee1460 | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 1283 | FrameIdx)); |
Craig Topper | abadc66 | 2012-04-20 06:31:50 +0000 | [diff] [blame] | 1284 | } else if (PPC::F4RCRegClass.hasSubClassEq(RC)) { |
Bill Wendling | f6d609a | 2009-02-12 00:02:55 +0000 | [diff] [blame] | 1285 | NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(PPC::LFS), DestReg), |
Owen Anderson | eee1460 | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 1286 | FrameIdx)); |
Craig Topper | abadc66 | 2012-04-20 06:31:50 +0000 | [diff] [blame] | 1287 | } else if (PPC::CRRCRegClass.hasSubClassEq(RC)) { |
Hal Finkel | e154c8f | 2013-03-12 14:12:16 +0000 | [diff] [blame] | 1288 | NewMIs.push_back(addFrameReference(BuildMI(MF, DL, |
| 1289 | get(PPC::RESTORE_CR), DestReg), |
| 1290 | FrameIdx)); |
| 1291 | return true; |
Craig Topper | abadc66 | 2012-04-20 06:31:50 +0000 | [diff] [blame] | 1292 | } else if (PPC::CRBITRCRegClass.hasSubClassEq(RC)) { |
Hal Finkel | 940ab93 | 2014-02-28 00:27:01 +0000 | [diff] [blame] | 1293 | NewMIs.push_back(addFrameReference(BuildMI(MF, DL, |
| 1294 | get(PPC::RESTORE_CRBIT), DestReg), |
| 1295 | FrameIdx)); |
| 1296 | return true; |
Craig Topper | abadc66 | 2012-04-20 06:31:50 +0000 | [diff] [blame] | 1297 | } else if (PPC::VRRCRegClass.hasSubClassEq(RC)) { |
Hal Finkel | fcc51d4 | 2013-03-17 04:43:44 +0000 | [diff] [blame] | 1298 | NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(PPC::LVX), DestReg), |
| 1299 | FrameIdx)); |
| 1300 | NonRI = true; |
Hal Finkel | 27774d9 | 2014-03-13 07:58:58 +0000 | [diff] [blame] | 1301 | } else if (PPC::VSRCRegClass.hasSubClassEq(RC)) { |
| 1302 | NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(PPC::LXVD2X), DestReg), |
| 1303 | FrameIdx)); |
| 1304 | NonRI = true; |
Hal Finkel | 19be506 | 2014-03-29 05:29:01 +0000 | [diff] [blame] | 1305 | } else if (PPC::VSFRCRegClass.hasSubClassEq(RC)) { |
| 1306 | NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(PPC::LXSDX), DestReg), |
| 1307 | FrameIdx)); |
| 1308 | NonRI = true; |
Nemanja Ivanovic | f3c94b1 | 2015-05-07 18:24:05 +0000 | [diff] [blame] | 1309 | } else if (PPC::VSSRCRegClass.hasSubClassEq(RC)) { |
| 1310 | NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(PPC::LXSSPX), DestReg), |
| 1311 | FrameIdx)); |
| 1312 | NonRI = true; |
Hal Finkel | a1431df | 2013-03-21 19:03:21 +0000 | [diff] [blame] | 1313 | } else if (PPC::VRSAVERCRegClass.hasSubClassEq(RC)) { |
Eric Christopher | 1dcea73 | 2014-06-12 21:48:52 +0000 | [diff] [blame] | 1314 | assert(Subtarget.isDarwin() && |
Hal Finkel | a7b0630 | 2013-03-27 00:02:20 +0000 | [diff] [blame] | 1315 | "VRSAVE only needs spill/restore on Darwin"); |
Hal Finkel | a1431df | 2013-03-21 19:03:21 +0000 | [diff] [blame] | 1316 | NewMIs.push_back(addFrameReference(BuildMI(MF, DL, |
| 1317 | get(PPC::RESTORE_VRSAVE), |
| 1318 | DestReg), |
| 1319 | FrameIdx)); |
Hal Finkel | cc1eeda | 2013-03-23 22:06:03 +0000 | [diff] [blame] | 1320 | SpillsVRS = true; |
Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 1321 | } else if (PPC::QFRCRegClass.hasSubClassEq(RC)) { |
| 1322 | NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(PPC::QVLFDX), DestReg), |
| 1323 | FrameIdx)); |
| 1324 | NonRI = true; |
| 1325 | } else if (PPC::QSRCRegClass.hasSubClassEq(RC)) { |
| 1326 | NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(PPC::QVLFSXs), DestReg), |
| 1327 | FrameIdx)); |
| 1328 | NonRI = true; |
| 1329 | } else if (PPC::QBRCRegClass.hasSubClassEq(RC)) { |
| 1330 | NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(PPC::QVLFDXb), DestReg), |
| 1331 | FrameIdx)); |
| 1332 | NonRI = true; |
Owen Anderson | eee1460 | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 1333 | } else { |
Torok Edwin | fbcc663 | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 1334 | llvm_unreachable("Unknown regclass!"); |
Owen Anderson | eee1460 | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 1335 | } |
Hal Finkel | bde7f8f | 2011-12-06 20:55:36 +0000 | [diff] [blame] | 1336 | |
| 1337 | return false; |
Owen Anderson | eee1460 | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 1338 | } |
| 1339 | |
| 1340 | void |
| 1341 | PPCInstrInfo::loadRegFromStackSlot(MachineBasicBlock &MBB, |
Bill Wendling | 632ea65 | 2008-03-03 22:19:16 +0000 | [diff] [blame] | 1342 | MachineBasicBlock::iterator MI, |
| 1343 | unsigned DestReg, int FrameIdx, |
Evan Cheng | efb126a | 2010-05-06 19:06:44 +0000 | [diff] [blame] | 1344 | const TargetRegisterClass *RC, |
| 1345 | const TargetRegisterInfo *TRI) const { |
Dan Gohman | 3b46030 | 2008-07-07 23:14:23 +0000 | [diff] [blame] | 1346 | MachineFunction &MF = *MBB.getParent(); |
Owen Anderson | eee1460 | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 1347 | SmallVector<MachineInstr*, 4> NewMIs; |
Chris Lattner | 6f306d7 | 2010-04-02 20:16:16 +0000 | [diff] [blame] | 1348 | DebugLoc DL; |
Bill Wendling | f6d609a | 2009-02-12 00:02:55 +0000 | [diff] [blame] | 1349 | if (MI != MBB.end()) DL = MI->getDebugLoc(); |
Hal Finkel | fcc51d4 | 2013-03-17 04:43:44 +0000 | [diff] [blame] | 1350 | |
| 1351 | PPCFunctionInfo *FuncInfo = MF.getInfo<PPCFunctionInfo>(); |
| 1352 | FuncInfo->setHasSpills(); |
| 1353 | |
Hal Finkel | cc1eeda | 2013-03-23 22:06:03 +0000 | [diff] [blame] | 1354 | bool NonRI = false, SpillsVRS = false; |
| 1355 | if (LoadRegFromStackSlot(MF, DL, DestReg, FrameIdx, RC, NewMIs, |
| 1356 | NonRI, SpillsVRS)) |
Hal Finkel | bde7f8f | 2011-12-06 20:55:36 +0000 | [diff] [blame] | 1357 | FuncInfo->setSpillsCR(); |
Hal Finkel | fcc51d4 | 2013-03-17 04:43:44 +0000 | [diff] [blame] | 1358 | |
Hal Finkel | cc1eeda | 2013-03-23 22:06:03 +0000 | [diff] [blame] | 1359 | if (SpillsVRS) |
| 1360 | FuncInfo->setSpillsVRSAVE(); |
| 1361 | |
Hal Finkel | fcc51d4 | 2013-03-17 04:43:44 +0000 | [diff] [blame] | 1362 | if (NonRI) |
| 1363 | FuncInfo->setHasNonRISpills(); |
| 1364 | |
Owen Anderson | eee1460 | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 1365 | for (unsigned i = 0, e = NewMIs.size(); i != e; ++i) |
| 1366 | MBB.insert(MI, NewMIs[i]); |
Jakob Stoklund Olesen | 6353e53 | 2010-07-16 18:22:00 +0000 | [diff] [blame] | 1367 | |
| 1368 | const MachineFrameInfo &MFI = *MF.getFrameInfo(); |
| 1369 | MachineMemOperand *MMO = |
Jay Foad | 465101b | 2011-11-15 07:34:52 +0000 | [diff] [blame] | 1370 | MF.getMachineMemOperand(MachinePointerInfo::getFixedStack(FrameIdx), |
Chris Lattner | e3d864b | 2010-09-21 04:39:43 +0000 | [diff] [blame] | 1371 | MachineMemOperand::MOLoad, |
Jakob Stoklund Olesen | 6353e53 | 2010-07-16 18:22:00 +0000 | [diff] [blame] | 1372 | MFI.getObjectSize(FrameIdx), |
| 1373 | MFI.getObjectAlignment(FrameIdx)); |
| 1374 | NewMIs.back()->addMemOperand(MF, MMO); |
Owen Anderson | eee1460 | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 1375 | } |
| 1376 | |
Chris Lattner | a47294ed | 2006-10-13 21:21:17 +0000 | [diff] [blame] | 1377 | bool PPCInstrInfo:: |
Owen Anderson | 4f6bf04 | 2008-08-14 22:49:33 +0000 | [diff] [blame] | 1378 | ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const { |
Chris Lattner | 23f22de | 2006-10-21 06:03:11 +0000 | [diff] [blame] | 1379 | assert(Cond.size() == 2 && "Invalid PPC branch opcode!"); |
Hal Finkel | 96c2d4d | 2012-06-08 15:38:21 +0000 | [diff] [blame] | 1380 | if (Cond[1].getReg() == PPC::CTR8 || Cond[1].getReg() == PPC::CTR) |
| 1381 | Cond[0].setImm(Cond[0].getImm() == 0 ? 1 : 0); |
| 1382 | else |
| 1383 | // Leave the CR# the same, but invert the condition. |
| 1384 | Cond[0].setImm(PPC::InvertPredicate((PPC::Predicate)Cond[0].getImm())); |
Chris Lattner | 23f22de | 2006-10-21 06:03:11 +0000 | [diff] [blame] | 1385 | return false; |
Chris Lattner | a47294ed | 2006-10-13 21:21:17 +0000 | [diff] [blame] | 1386 | } |
Nicolas Geoffray | ae84bbd | 2008-04-16 20:10:13 +0000 | [diff] [blame] | 1387 | |
Hal Finkel | d61d4f8 | 2013-04-06 19:30:30 +0000 | [diff] [blame] | 1388 | bool PPCInstrInfo::FoldImmediate(MachineInstr *UseMI, MachineInstr *DefMI, |
| 1389 | unsigned Reg, MachineRegisterInfo *MRI) const { |
| 1390 | // For some instructions, it is legal to fold ZERO into the RA register field. |
| 1391 | // A zero immediate should always be loaded with a single li. |
| 1392 | unsigned DefOpc = DefMI->getOpcode(); |
| 1393 | if (DefOpc != PPC::LI && DefOpc != PPC::LI8) |
| 1394 | return false; |
| 1395 | if (!DefMI->getOperand(1).isImm()) |
| 1396 | return false; |
| 1397 | if (DefMI->getOperand(1).getImm() != 0) |
| 1398 | return false; |
| 1399 | |
| 1400 | // Note that we cannot here invert the arguments of an isel in order to fold |
| 1401 | // a ZERO into what is presented as the second argument. All we have here |
| 1402 | // is the condition bit, and that might come from a CR-logical bit operation. |
| 1403 | |
| 1404 | const MCInstrDesc &UseMCID = UseMI->getDesc(); |
| 1405 | |
| 1406 | // Only fold into real machine instructions. |
| 1407 | if (UseMCID.isPseudo()) |
| 1408 | return false; |
| 1409 | |
| 1410 | unsigned UseIdx; |
| 1411 | for (UseIdx = 0; UseIdx < UseMI->getNumOperands(); ++UseIdx) |
| 1412 | if (UseMI->getOperand(UseIdx).isReg() && |
| 1413 | UseMI->getOperand(UseIdx).getReg() == Reg) |
| 1414 | break; |
| 1415 | |
| 1416 | assert(UseIdx < UseMI->getNumOperands() && "Cannot find Reg in UseMI"); |
| 1417 | assert(UseIdx < UseMCID.getNumOperands() && "No operand description for Reg"); |
| 1418 | |
| 1419 | const MCOperandInfo *UseInfo = &UseMCID.OpInfo[UseIdx]; |
| 1420 | |
| 1421 | // We can fold the zero if this register requires a GPRC_NOR0/G8RC_NOX0 |
| 1422 | // register (which might also be specified as a pointer class kind). |
| 1423 | if (UseInfo->isLookupPtrRegClass()) { |
| 1424 | if (UseInfo->RegClass /* Kind */ != 1) |
| 1425 | return false; |
| 1426 | } else { |
| 1427 | if (UseInfo->RegClass != PPC::GPRC_NOR0RegClassID && |
| 1428 | UseInfo->RegClass != PPC::G8RC_NOX0RegClassID) |
| 1429 | return false; |
| 1430 | } |
| 1431 | |
| 1432 | // Make sure this is not tied to an output register (or otherwise |
| 1433 | // constrained). This is true for ST?UX registers, for example, which |
| 1434 | // are tied to their output registers. |
| 1435 | if (UseInfo->Constraints != 0) |
| 1436 | return false; |
| 1437 | |
| 1438 | unsigned ZeroReg; |
| 1439 | if (UseInfo->isLookupPtrRegClass()) { |
Eric Christopher | 1dcea73 | 2014-06-12 21:48:52 +0000 | [diff] [blame] | 1440 | bool isPPC64 = Subtarget.isPPC64(); |
Hal Finkel | d61d4f8 | 2013-04-06 19:30:30 +0000 | [diff] [blame] | 1441 | ZeroReg = isPPC64 ? PPC::ZERO8 : PPC::ZERO; |
| 1442 | } else { |
| 1443 | ZeroReg = UseInfo->RegClass == PPC::G8RC_NOX0RegClassID ? |
| 1444 | PPC::ZERO8 : PPC::ZERO; |
| 1445 | } |
| 1446 | |
| 1447 | bool DeleteDef = MRI->hasOneNonDBGUse(Reg); |
| 1448 | UseMI->getOperand(UseIdx).setReg(ZeroReg); |
| 1449 | |
| 1450 | if (DeleteDef) |
| 1451 | DefMI->eraseFromParent(); |
| 1452 | |
| 1453 | return true; |
| 1454 | } |
| 1455 | |
Hal Finkel | 30ae229 | 2013-04-10 18:30:16 +0000 | [diff] [blame] | 1456 | static bool MBBDefinesCTR(MachineBasicBlock &MBB) { |
| 1457 | for (MachineBasicBlock::iterator I = MBB.begin(), IE = MBB.end(); |
| 1458 | I != IE; ++I) |
| 1459 | if (I->definesRegister(PPC::CTR) || I->definesRegister(PPC::CTR8)) |
| 1460 | return true; |
| 1461 | return false; |
| 1462 | } |
| 1463 | |
| 1464 | // We should make sure that, if we're going to predicate both sides of a |
| 1465 | // condition (a diamond), that both sides don't define the counter register. We |
| 1466 | // can predicate counter-decrement-based branches, but while that predicates |
| 1467 | // the branching, it does not predicate the counter decrement. If we tried to |
| 1468 | // merge the triangle into one predicated block, we'd decrement the counter |
| 1469 | // twice. |
| 1470 | bool PPCInstrInfo::isProfitableToIfCvt(MachineBasicBlock &TMBB, |
| 1471 | unsigned NumT, unsigned ExtraT, |
| 1472 | MachineBasicBlock &FMBB, |
| 1473 | unsigned NumF, unsigned ExtraF, |
| 1474 | const BranchProbability &Probability) const { |
| 1475 | return !(MBBDefinesCTR(TMBB) && MBBDefinesCTR(FMBB)); |
| 1476 | } |
| 1477 | |
| 1478 | |
Hal Finkel | 5711eca | 2013-04-09 22:58:37 +0000 | [diff] [blame] | 1479 | bool PPCInstrInfo::isPredicated(const MachineInstr *MI) const { |
Hal Finkel | f29285a | 2013-04-11 01:23:34 +0000 | [diff] [blame] | 1480 | // The predicated branches are identified by their type, not really by the |
| 1481 | // explicit presence of a predicate. Furthermore, some of them can be |
| 1482 | // predicated more than once. Because if conversion won't try to predicate |
| 1483 | // any instruction which already claims to be predicated (by returning true |
| 1484 | // here), always return false. In doing so, we let isPredicable() be the |
| 1485 | // final word on whether not the instruction can be (further) predicated. |
| 1486 | |
| 1487 | return false; |
Hal Finkel | 5711eca | 2013-04-09 22:58:37 +0000 | [diff] [blame] | 1488 | } |
| 1489 | |
| 1490 | bool PPCInstrInfo::isUnpredicatedTerminator(const MachineInstr *MI) const { |
| 1491 | if (!MI->isTerminator()) |
| 1492 | return false; |
| 1493 | |
| 1494 | // Conditional branch is a special case. |
| 1495 | if (MI->isBranch() && !MI->isBarrier()) |
| 1496 | return true; |
| 1497 | |
| 1498 | return !isPredicated(MI); |
| 1499 | } |
| 1500 | |
Ahmed Bougacha | c88bf54 | 2015-06-11 19:30:37 +0000 | [diff] [blame] | 1501 | bool PPCInstrInfo::PredicateInstruction(MachineInstr *MI, |
| 1502 | ArrayRef<MachineOperand> Pred) const { |
Hal Finkel | 5711eca | 2013-04-09 22:58:37 +0000 | [diff] [blame] | 1503 | unsigned OpC = MI->getOpcode(); |
Hal Finkel | f4a22c0 | 2015-01-13 17:47:54 +0000 | [diff] [blame] | 1504 | if (OpC == PPC::BLR || OpC == PPC::BLR8) { |
Hal Finkel | 5711eca | 2013-04-09 22:58:37 +0000 | [diff] [blame] | 1505 | if (Pred[1].getReg() == PPC::CTR8 || Pred[1].getReg() == PPC::CTR) { |
Eric Christopher | 1dcea73 | 2014-06-12 21:48:52 +0000 | [diff] [blame] | 1506 | bool isPPC64 = Subtarget.isPPC64(); |
Hal Finkel | 5711eca | 2013-04-09 22:58:37 +0000 | [diff] [blame] | 1507 | MI->setDesc(get(Pred[0].getImm() ? |
| 1508 | (isPPC64 ? PPC::BDNZLR8 : PPC::BDNZLR) : |
| 1509 | (isPPC64 ? PPC::BDZLR8 : PPC::BDZLR))); |
Hal Finkel | 940ab93 | 2014-02-28 00:27:01 +0000 | [diff] [blame] | 1510 | } else if (Pred[0].getImm() == PPC::PRED_BIT_SET) { |
Hal Finkel | 5711eca | 2013-04-09 22:58:37 +0000 | [diff] [blame] | 1511 | MI->setDesc(get(PPC::BCLR)); |
| 1512 | MachineInstrBuilder(*MI->getParent()->getParent(), MI) |
Hal Finkel | 940ab93 | 2014-02-28 00:27:01 +0000 | [diff] [blame] | 1513 | .addReg(Pred[1].getReg()); |
| 1514 | } else if (Pred[0].getImm() == PPC::PRED_BIT_UNSET) { |
| 1515 | MI->setDesc(get(PPC::BCLRn)); |
| 1516 | MachineInstrBuilder(*MI->getParent()->getParent(), MI) |
| 1517 | .addReg(Pred[1].getReg()); |
| 1518 | } else { |
| 1519 | MI->setDesc(get(PPC::BCCLR)); |
| 1520 | MachineInstrBuilder(*MI->getParent()->getParent(), MI) |
Hal Finkel | 5711eca | 2013-04-09 22:58:37 +0000 | [diff] [blame] | 1521 | .addImm(Pred[0].getImm()) |
| 1522 | .addReg(Pred[1].getReg()); |
| 1523 | } |
| 1524 | |
| 1525 | return true; |
| 1526 | } else if (OpC == PPC::B) { |
| 1527 | if (Pred[1].getReg() == PPC::CTR8 || Pred[1].getReg() == PPC::CTR) { |
Eric Christopher | 1dcea73 | 2014-06-12 21:48:52 +0000 | [diff] [blame] | 1528 | bool isPPC64 = Subtarget.isPPC64(); |
Hal Finkel | 5711eca | 2013-04-09 22:58:37 +0000 | [diff] [blame] | 1529 | MI->setDesc(get(Pred[0].getImm() ? |
| 1530 | (isPPC64 ? PPC::BDNZ8 : PPC::BDNZ) : |
| 1531 | (isPPC64 ? PPC::BDZ8 : PPC::BDZ))); |
Hal Finkel | 940ab93 | 2014-02-28 00:27:01 +0000 | [diff] [blame] | 1532 | } else if (Pred[0].getImm() == PPC::PRED_BIT_SET) { |
| 1533 | MachineBasicBlock *MBB = MI->getOperand(0).getMBB(); |
| 1534 | MI->RemoveOperand(0); |
| 1535 | |
| 1536 | MI->setDesc(get(PPC::BC)); |
| 1537 | MachineInstrBuilder(*MI->getParent()->getParent(), MI) |
| 1538 | .addReg(Pred[1].getReg()) |
| 1539 | .addMBB(MBB); |
| 1540 | } else if (Pred[0].getImm() == PPC::PRED_BIT_UNSET) { |
| 1541 | MachineBasicBlock *MBB = MI->getOperand(0).getMBB(); |
| 1542 | MI->RemoveOperand(0); |
| 1543 | |
| 1544 | MI->setDesc(get(PPC::BCn)); |
| 1545 | MachineInstrBuilder(*MI->getParent()->getParent(), MI) |
| 1546 | .addReg(Pred[1].getReg()) |
| 1547 | .addMBB(MBB); |
Hal Finkel | 5711eca | 2013-04-09 22:58:37 +0000 | [diff] [blame] | 1548 | } else { |
| 1549 | MachineBasicBlock *MBB = MI->getOperand(0).getMBB(); |
| 1550 | MI->RemoveOperand(0); |
| 1551 | |
| 1552 | MI->setDesc(get(PPC::BCC)); |
| 1553 | MachineInstrBuilder(*MI->getParent()->getParent(), MI) |
| 1554 | .addImm(Pred[0].getImm()) |
| 1555 | .addReg(Pred[1].getReg()) |
| 1556 | .addMBB(MBB); |
| 1557 | } |
| 1558 | |
| 1559 | return true; |
Hal Finkel | 500b004 | 2013-04-10 06:42:34 +0000 | [diff] [blame] | 1560 | } else if (OpC == PPC::BCTR || OpC == PPC::BCTR8 || |
| 1561 | OpC == PPC::BCTRL || OpC == PPC::BCTRL8) { |
| 1562 | if (Pred[1].getReg() == PPC::CTR8 || Pred[1].getReg() == PPC::CTR) |
| 1563 | llvm_unreachable("Cannot predicate bctr[l] on the ctr register"); |
| 1564 | |
| 1565 | bool setLR = OpC == PPC::BCTRL || OpC == PPC::BCTRL8; |
Eric Christopher | 1dcea73 | 2014-06-12 21:48:52 +0000 | [diff] [blame] | 1566 | bool isPPC64 = Subtarget.isPPC64(); |
Hal Finkel | 940ab93 | 2014-02-28 00:27:01 +0000 | [diff] [blame] | 1567 | |
| 1568 | if (Pred[0].getImm() == PPC::PRED_BIT_SET) { |
| 1569 | MI->setDesc(get(isPPC64 ? (setLR ? PPC::BCCTRL8 : PPC::BCCTR8) : |
| 1570 | (setLR ? PPC::BCCTRL : PPC::BCCTR))); |
| 1571 | MachineInstrBuilder(*MI->getParent()->getParent(), MI) |
| 1572 | .addReg(Pred[1].getReg()); |
| 1573 | return true; |
| 1574 | } else if (Pred[0].getImm() == PPC::PRED_BIT_UNSET) { |
| 1575 | MI->setDesc(get(isPPC64 ? (setLR ? PPC::BCCTRL8n : PPC::BCCTR8n) : |
| 1576 | (setLR ? PPC::BCCTRLn : PPC::BCCTRn))); |
| 1577 | MachineInstrBuilder(*MI->getParent()->getParent(), MI) |
| 1578 | .addReg(Pred[1].getReg()); |
| 1579 | return true; |
| 1580 | } |
| 1581 | |
| 1582 | MI->setDesc(get(isPPC64 ? (setLR ? PPC::BCCCTRL8 : PPC::BCCCTR8) : |
| 1583 | (setLR ? PPC::BCCCTRL : PPC::BCCCTR))); |
Hal Finkel | 500b004 | 2013-04-10 06:42:34 +0000 | [diff] [blame] | 1584 | MachineInstrBuilder(*MI->getParent()->getParent(), MI) |
| 1585 | .addImm(Pred[0].getImm()) |
| 1586 | .addReg(Pred[1].getReg()); |
| 1587 | return true; |
Hal Finkel | 5711eca | 2013-04-09 22:58:37 +0000 | [diff] [blame] | 1588 | } |
| 1589 | |
| 1590 | return false; |
| 1591 | } |
| 1592 | |
Ahmed Bougacha | c88bf54 | 2015-06-11 19:30:37 +0000 | [diff] [blame] | 1593 | bool PPCInstrInfo::SubsumesPredicate(ArrayRef<MachineOperand> Pred1, |
| 1594 | ArrayRef<MachineOperand> Pred2) const { |
Hal Finkel | 5711eca | 2013-04-09 22:58:37 +0000 | [diff] [blame] | 1595 | assert(Pred1.size() == 2 && "Invalid PPC first predicate"); |
| 1596 | assert(Pred2.size() == 2 && "Invalid PPC second predicate"); |
| 1597 | |
| 1598 | if (Pred1[1].getReg() == PPC::CTR8 || Pred1[1].getReg() == PPC::CTR) |
| 1599 | return false; |
| 1600 | if (Pred2[1].getReg() == PPC::CTR8 || Pred2[1].getReg() == PPC::CTR) |
| 1601 | return false; |
| 1602 | |
Hal Finkel | 94a6f38 | 2013-12-11 23:12:25 +0000 | [diff] [blame] | 1603 | // P1 can only subsume P2 if they test the same condition register. |
| 1604 | if (Pred1[1].getReg() != Pred2[1].getReg()) |
| 1605 | return false; |
| 1606 | |
Hal Finkel | 5711eca | 2013-04-09 22:58:37 +0000 | [diff] [blame] | 1607 | PPC::Predicate P1 = (PPC::Predicate) Pred1[0].getImm(); |
| 1608 | PPC::Predicate P2 = (PPC::Predicate) Pred2[0].getImm(); |
| 1609 | |
| 1610 | if (P1 == P2) |
| 1611 | return true; |
| 1612 | |
| 1613 | // Does P1 subsume P2, e.g. GE subsumes GT. |
| 1614 | if (P1 == PPC::PRED_LE && |
| 1615 | (P2 == PPC::PRED_LT || P2 == PPC::PRED_EQ)) |
| 1616 | return true; |
| 1617 | if (P1 == PPC::PRED_GE && |
| 1618 | (P2 == PPC::PRED_GT || P2 == PPC::PRED_EQ)) |
| 1619 | return true; |
| 1620 | |
| 1621 | return false; |
| 1622 | } |
| 1623 | |
| 1624 | bool PPCInstrInfo::DefinesPredicate(MachineInstr *MI, |
| 1625 | std::vector<MachineOperand> &Pred) const { |
| 1626 | // Note: At the present time, the contents of Pred from this function is |
| 1627 | // unused by IfConversion. This implementation follows ARM by pushing the |
| 1628 | // CR-defining operand. Because the 'DZ' and 'DNZ' count as types of |
| 1629 | // predicate, instructions defining CTR or CTR8 are also included as |
| 1630 | // predicate-defining instructions. |
| 1631 | |
| 1632 | const TargetRegisterClass *RCs[] = |
| 1633 | { &PPC::CRRCRegClass, &PPC::CRBITRCRegClass, |
| 1634 | &PPC::CTRRCRegClass, &PPC::CTRRC8RegClass }; |
| 1635 | |
| 1636 | bool Found = false; |
| 1637 | for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) { |
| 1638 | const MachineOperand &MO = MI->getOperand(i); |
Hal Finkel | af82201 | 2013-04-10 07:17:47 +0000 | [diff] [blame] | 1639 | for (unsigned c = 0; c < array_lengthof(RCs) && !Found; ++c) { |
Hal Finkel | 5711eca | 2013-04-09 22:58:37 +0000 | [diff] [blame] | 1640 | const TargetRegisterClass *RC = RCs[c]; |
Hal Finkel | af82201 | 2013-04-10 07:17:47 +0000 | [diff] [blame] | 1641 | if (MO.isReg()) { |
| 1642 | if (MO.isDef() && RC->contains(MO.getReg())) { |
Hal Finkel | 5711eca | 2013-04-09 22:58:37 +0000 | [diff] [blame] | 1643 | Pred.push_back(MO); |
| 1644 | Found = true; |
| 1645 | } |
Hal Finkel | af82201 | 2013-04-10 07:17:47 +0000 | [diff] [blame] | 1646 | } else if (MO.isRegMask()) { |
| 1647 | for (TargetRegisterClass::iterator I = RC->begin(), |
| 1648 | IE = RC->end(); I != IE; ++I) |
| 1649 | if (MO.clobbersPhysReg(*I)) { |
| 1650 | Pred.push_back(MO); |
| 1651 | Found = true; |
| 1652 | } |
Hal Finkel | 5711eca | 2013-04-09 22:58:37 +0000 | [diff] [blame] | 1653 | } |
| 1654 | } |
| 1655 | } |
| 1656 | |
| 1657 | return Found; |
| 1658 | } |
| 1659 | |
| 1660 | bool PPCInstrInfo::isPredicable(MachineInstr *MI) const { |
| 1661 | unsigned OpC = MI->getOpcode(); |
| 1662 | switch (OpC) { |
| 1663 | default: |
| 1664 | return false; |
| 1665 | case PPC::B: |
| 1666 | case PPC::BLR: |
Hal Finkel | f4a22c0 | 2015-01-13 17:47:54 +0000 | [diff] [blame] | 1667 | case PPC::BLR8: |
Hal Finkel | 500b004 | 2013-04-10 06:42:34 +0000 | [diff] [blame] | 1668 | case PPC::BCTR: |
| 1669 | case PPC::BCTR8: |
| 1670 | case PPC::BCTRL: |
| 1671 | case PPC::BCTRL8: |
Hal Finkel | 5711eca | 2013-04-09 22:58:37 +0000 | [diff] [blame] | 1672 | return true; |
| 1673 | } |
| 1674 | } |
| 1675 | |
Hal Finkel | 82656cb | 2013-04-18 22:15:08 +0000 | [diff] [blame] | 1676 | bool PPCInstrInfo::analyzeCompare(const MachineInstr *MI, |
| 1677 | unsigned &SrcReg, unsigned &SrcReg2, |
| 1678 | int &Mask, int &Value) const { |
| 1679 | unsigned Opc = MI->getOpcode(); |
| 1680 | |
| 1681 | switch (Opc) { |
| 1682 | default: return false; |
| 1683 | case PPC::CMPWI: |
| 1684 | case PPC::CMPLWI: |
| 1685 | case PPC::CMPDI: |
| 1686 | case PPC::CMPLDI: |
| 1687 | SrcReg = MI->getOperand(1).getReg(); |
| 1688 | SrcReg2 = 0; |
| 1689 | Value = MI->getOperand(2).getImm(); |
| 1690 | Mask = 0xFFFF; |
| 1691 | return true; |
| 1692 | case PPC::CMPW: |
| 1693 | case PPC::CMPLW: |
| 1694 | case PPC::CMPD: |
| 1695 | case PPC::CMPLD: |
| 1696 | case PPC::FCMPUS: |
| 1697 | case PPC::FCMPUD: |
| 1698 | SrcReg = MI->getOperand(1).getReg(); |
| 1699 | SrcReg2 = MI->getOperand(2).getReg(); |
| 1700 | return true; |
| 1701 | } |
| 1702 | } |
Hal Finkel | e632239 | 2013-04-19 22:08:38 +0000 | [diff] [blame] | 1703 | |
Hal Finkel | 82656cb | 2013-04-18 22:15:08 +0000 | [diff] [blame] | 1704 | bool PPCInstrInfo::optimizeCompareInstr(MachineInstr *CmpInstr, |
| 1705 | unsigned SrcReg, unsigned SrcReg2, |
| 1706 | int Mask, int Value, |
| 1707 | const MachineRegisterInfo *MRI) const { |
Hal Finkel | b12da6b | 2013-04-18 22:54:25 +0000 | [diff] [blame] | 1708 | if (DisableCmpOpt) |
| 1709 | return false; |
| 1710 | |
Hal Finkel | 82656cb | 2013-04-18 22:15:08 +0000 | [diff] [blame] | 1711 | int OpC = CmpInstr->getOpcode(); |
| 1712 | unsigned CRReg = CmpInstr->getOperand(0).getReg(); |
Hal Finkel | 08e53ee | 2013-05-08 12:16:14 +0000 | [diff] [blame] | 1713 | |
| 1714 | // FP record forms set CR1 based on the execption status bits, not a |
| 1715 | // comparison with zero. |
| 1716 | if (OpC == PPC::FCMPUS || OpC == PPC::FCMPUD) |
| 1717 | return false; |
Hal Finkel | 82656cb | 2013-04-18 22:15:08 +0000 | [diff] [blame] | 1718 | |
| 1719 | // The record forms set the condition register based on a signed comparison |
| 1720 | // with zero (so says the ISA manual). This is not as straightforward as it |
| 1721 | // seems, however, because this is always a 64-bit comparison on PPC64, even |
| 1722 | // for instructions that are 32-bit in nature (like slw for example). |
| 1723 | // So, on PPC32, for unsigned comparisons, we can use the record forms only |
| 1724 | // for equality checks (as those don't depend on the sign). On PPC64, |
| 1725 | // we are restricted to equality for unsigned 64-bit comparisons and for |
| 1726 | // signed 32-bit comparisons the applicability is more restricted. |
Eric Christopher | 1dcea73 | 2014-06-12 21:48:52 +0000 | [diff] [blame] | 1727 | bool isPPC64 = Subtarget.isPPC64(); |
Hal Finkel | 82656cb | 2013-04-18 22:15:08 +0000 | [diff] [blame] | 1728 | bool is32BitSignedCompare = OpC == PPC::CMPWI || OpC == PPC::CMPW; |
| 1729 | bool is32BitUnsignedCompare = OpC == PPC::CMPLWI || OpC == PPC::CMPLW; |
| 1730 | bool is64BitUnsignedCompare = OpC == PPC::CMPLDI || OpC == PPC::CMPLD; |
| 1731 | |
| 1732 | // Get the unique definition of SrcReg. |
| 1733 | MachineInstr *MI = MRI->getUniqueVRegDef(SrcReg); |
| 1734 | if (!MI) return false; |
| 1735 | int MIOpC = MI->getOpcode(); |
| 1736 | |
| 1737 | bool equalityOnly = false; |
| 1738 | bool noSub = false; |
| 1739 | if (isPPC64) { |
| 1740 | if (is32BitSignedCompare) { |
| 1741 | // We can perform this optimization only if MI is sign-extending. |
| 1742 | if (MIOpC == PPC::SRAW || MIOpC == PPC::SRAWo || |
| 1743 | MIOpC == PPC::SRAWI || MIOpC == PPC::SRAWIo || |
| 1744 | MIOpC == PPC::EXTSB || MIOpC == PPC::EXTSBo || |
| 1745 | MIOpC == PPC::EXTSH || MIOpC == PPC::EXTSHo || |
| 1746 | MIOpC == PPC::EXTSW || MIOpC == PPC::EXTSWo) { |
| 1747 | noSub = true; |
| 1748 | } else |
| 1749 | return false; |
| 1750 | } else if (is32BitUnsignedCompare) { |
| 1751 | // We can perform this optimization, equality only, if MI is |
| 1752 | // zero-extending. |
| 1753 | if (MIOpC == PPC::CNTLZW || MIOpC == PPC::CNTLZWo || |
| 1754 | MIOpC == PPC::SLW || MIOpC == PPC::SLWo || |
| 1755 | MIOpC == PPC::SRW || MIOpC == PPC::SRWo) { |
| 1756 | noSub = true; |
| 1757 | equalityOnly = true; |
| 1758 | } else |
| 1759 | return false; |
Hal Finkel | 08e53ee | 2013-05-08 12:16:14 +0000 | [diff] [blame] | 1760 | } else |
Hal Finkel | 82656cb | 2013-04-18 22:15:08 +0000 | [diff] [blame] | 1761 | equalityOnly = is64BitUnsignedCompare; |
Hal Finkel | 08e53ee | 2013-05-08 12:16:14 +0000 | [diff] [blame] | 1762 | } else |
Hal Finkel | 82656cb | 2013-04-18 22:15:08 +0000 | [diff] [blame] | 1763 | equalityOnly = is32BitUnsignedCompare; |
| 1764 | |
| 1765 | if (equalityOnly) { |
| 1766 | // We need to check the uses of the condition register in order to reject |
| 1767 | // non-equality comparisons. |
Owen Anderson | 16c6bf4 | 2014-03-13 23:12:04 +0000 | [diff] [blame] | 1768 | for (MachineRegisterInfo::use_instr_iterator I =MRI->use_instr_begin(CRReg), |
| 1769 | IE = MRI->use_instr_end(); I != IE; ++I) { |
Hal Finkel | 82656cb | 2013-04-18 22:15:08 +0000 | [diff] [blame] | 1770 | MachineInstr *UseMI = &*I; |
| 1771 | if (UseMI->getOpcode() == PPC::BCC) { |
| 1772 | unsigned Pred = UseMI->getOperand(0).getImm(); |
Hal Finkel | c363245 | 2013-05-07 17:49:55 +0000 | [diff] [blame] | 1773 | if (Pred != PPC::PRED_EQ && Pred != PPC::PRED_NE) |
| 1774 | return false; |
Hal Finkel | 82656cb | 2013-04-18 22:15:08 +0000 | [diff] [blame] | 1775 | } else if (UseMI->getOpcode() == PPC::ISEL || |
| 1776 | UseMI->getOpcode() == PPC::ISEL8) { |
| 1777 | unsigned SubIdx = UseMI->getOperand(3).getSubReg(); |
Hal Finkel | c363245 | 2013-05-07 17:49:55 +0000 | [diff] [blame] | 1778 | if (SubIdx != PPC::sub_eq) |
| 1779 | return false; |
Hal Finkel | 82656cb | 2013-04-18 22:15:08 +0000 | [diff] [blame] | 1780 | } else |
| 1781 | return false; |
| 1782 | } |
| 1783 | } |
| 1784 | |
Hal Finkel | c363245 | 2013-05-07 17:49:55 +0000 | [diff] [blame] | 1785 | MachineBasicBlock::iterator I = CmpInstr; |
Hal Finkel | 82656cb | 2013-04-18 22:15:08 +0000 | [diff] [blame] | 1786 | |
| 1787 | // Scan forward to find the first use of the compare. |
| 1788 | for (MachineBasicBlock::iterator EL = CmpInstr->getParent()->end(); |
| 1789 | I != EL; ++I) { |
| 1790 | bool FoundUse = false; |
Owen Anderson | 16c6bf4 | 2014-03-13 23:12:04 +0000 | [diff] [blame] | 1791 | for (MachineRegisterInfo::use_instr_iterator J =MRI->use_instr_begin(CRReg), |
| 1792 | JE = MRI->use_instr_end(); J != JE; ++J) |
Hal Finkel | 82656cb | 2013-04-18 22:15:08 +0000 | [diff] [blame] | 1793 | if (&*J == &*I) { |
| 1794 | FoundUse = true; |
| 1795 | break; |
| 1796 | } |
| 1797 | |
| 1798 | if (FoundUse) |
| 1799 | break; |
| 1800 | } |
| 1801 | |
Hal Finkel | 82656cb | 2013-04-18 22:15:08 +0000 | [diff] [blame] | 1802 | // There are two possible candidates which can be changed to set CR[01]. |
| 1803 | // One is MI, the other is a SUB instruction. |
| 1804 | // For CMPrr(r1,r2), we are looking for SUB(r1,r2) or SUB(r2,r1). |
Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 1805 | MachineInstr *Sub = nullptr; |
Hal Finkel | 82656cb | 2013-04-18 22:15:08 +0000 | [diff] [blame] | 1806 | if (SrcReg2 != 0) |
| 1807 | // MI is not a candidate for CMPrr. |
Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 1808 | MI = nullptr; |
Hal Finkel | 82656cb | 2013-04-18 22:15:08 +0000 | [diff] [blame] | 1809 | // FIXME: Conservatively refuse to convert an instruction which isn't in the |
| 1810 | // same BB as the comparison. This is to allow the check below to avoid calls |
| 1811 | // (and other explicit clobbers); instead we should really check for these |
| 1812 | // more explicitly (in at least a few predecessors). |
| 1813 | else if (MI->getParent() != CmpInstr->getParent() || Value != 0) { |
| 1814 | // PPC does not have a record-form SUBri. |
| 1815 | return false; |
| 1816 | } |
| 1817 | |
| 1818 | // Search for Sub. |
| 1819 | const TargetRegisterInfo *TRI = &getRegisterInfo(); |
| 1820 | --I; |
Hal Finkel | c363245 | 2013-05-07 17:49:55 +0000 | [diff] [blame] | 1821 | |
| 1822 | // Get ready to iterate backward from CmpInstr. |
| 1823 | MachineBasicBlock::iterator E = MI, |
| 1824 | B = CmpInstr->getParent()->begin(); |
| 1825 | |
Hal Finkel | 82656cb | 2013-04-18 22:15:08 +0000 | [diff] [blame] | 1826 | for (; I != E && !noSub; --I) { |
| 1827 | const MachineInstr &Instr = *I; |
| 1828 | unsigned IOpC = Instr.getOpcode(); |
| 1829 | |
| 1830 | if (&*I != CmpInstr && ( |
Hal Finkel | 08e53ee | 2013-05-08 12:16:14 +0000 | [diff] [blame] | 1831 | Instr.modifiesRegister(PPC::CR0, TRI) || |
| 1832 | Instr.readsRegister(PPC::CR0, TRI))) |
Hal Finkel | 82656cb | 2013-04-18 22:15:08 +0000 | [diff] [blame] | 1833 | // This instruction modifies or uses the record condition register after |
| 1834 | // the one we want to change. While we could do this transformation, it |
| 1835 | // would likely not be profitable. This transformation removes one |
| 1836 | // instruction, and so even forcing RA to generate one move probably |
| 1837 | // makes it unprofitable. |
| 1838 | return false; |
| 1839 | |
| 1840 | // Check whether CmpInstr can be made redundant by the current instruction. |
| 1841 | if ((OpC == PPC::CMPW || OpC == PPC::CMPLW || |
| 1842 | OpC == PPC::CMPD || OpC == PPC::CMPLD) && |
| 1843 | (IOpC == PPC::SUBF || IOpC == PPC::SUBF8) && |
| 1844 | ((Instr.getOperand(1).getReg() == SrcReg && |
| 1845 | Instr.getOperand(2).getReg() == SrcReg2) || |
| 1846 | (Instr.getOperand(1).getReg() == SrcReg2 && |
| 1847 | Instr.getOperand(2).getReg() == SrcReg))) { |
| 1848 | Sub = &*I; |
| 1849 | break; |
| 1850 | } |
| 1851 | |
Hal Finkel | 82656cb | 2013-04-18 22:15:08 +0000 | [diff] [blame] | 1852 | if (I == B) |
| 1853 | // The 'and' is below the comparison instruction. |
| 1854 | return false; |
| 1855 | } |
| 1856 | |
| 1857 | // Return false if no candidates exist. |
| 1858 | if (!MI && !Sub) |
| 1859 | return false; |
| 1860 | |
| 1861 | // The single candidate is called MI. |
| 1862 | if (!MI) MI = Sub; |
| 1863 | |
| 1864 | int NewOpC = -1; |
| 1865 | MIOpC = MI->getOpcode(); |
| 1866 | if (MIOpC == PPC::ANDIo || MIOpC == PPC::ANDIo8) |
| 1867 | NewOpC = MIOpC; |
| 1868 | else { |
| 1869 | NewOpC = PPC::getRecordFormOpcode(MIOpC); |
| 1870 | if (NewOpC == -1 && PPC::getNonRecordFormOpcode(MIOpC) != -1) |
| 1871 | NewOpC = MIOpC; |
| 1872 | } |
| 1873 | |
| 1874 | // FIXME: On the non-embedded POWER architectures, only some of the record |
| 1875 | // forms are fast, and we should use only the fast ones. |
| 1876 | |
| 1877 | // The defining instruction has a record form (or is already a record |
| 1878 | // form). It is possible, however, that we'll need to reverse the condition |
| 1879 | // code of the users. |
| 1880 | if (NewOpC == -1) |
| 1881 | return false; |
| 1882 | |
Hal Finkel | e632239 | 2013-04-19 22:08:38 +0000 | [diff] [blame] | 1883 | SmallVector<std::pair<MachineOperand*, PPC::Predicate>, 4> PredsToUpdate; |
| 1884 | SmallVector<std::pair<MachineOperand*, unsigned>, 4> SubRegsToUpdate; |
Hal Finkel | 82656cb | 2013-04-18 22:15:08 +0000 | [diff] [blame] | 1885 | |
| 1886 | // If we have SUB(r1, r2) and CMP(r2, r1), the condition code based on CMP |
| 1887 | // needs to be updated to be based on SUB. Push the condition code |
| 1888 | // operands to OperandsToUpdate. If it is safe to remove CmpInstr, the |
| 1889 | // condition code of these operands will be modified. |
| 1890 | bool ShouldSwap = false; |
| 1891 | if (Sub) { |
| 1892 | ShouldSwap = SrcReg2 != 0 && Sub->getOperand(1).getReg() == SrcReg2 && |
| 1893 | Sub->getOperand(2).getReg() == SrcReg; |
| 1894 | |
| 1895 | // The operands to subf are the opposite of sub, so only in the fixed-point |
| 1896 | // case, invert the order. |
Hal Finkel | 08e53ee | 2013-05-08 12:16:14 +0000 | [diff] [blame] | 1897 | ShouldSwap = !ShouldSwap; |
Hal Finkel | 82656cb | 2013-04-18 22:15:08 +0000 | [diff] [blame] | 1898 | } |
| 1899 | |
| 1900 | if (ShouldSwap) |
Owen Anderson | 16c6bf4 | 2014-03-13 23:12:04 +0000 | [diff] [blame] | 1901 | for (MachineRegisterInfo::use_instr_iterator |
| 1902 | I = MRI->use_instr_begin(CRReg), IE = MRI->use_instr_end(); |
| 1903 | I != IE; ++I) { |
Hal Finkel | 82656cb | 2013-04-18 22:15:08 +0000 | [diff] [blame] | 1904 | MachineInstr *UseMI = &*I; |
| 1905 | if (UseMI->getOpcode() == PPC::BCC) { |
| 1906 | PPC::Predicate Pred = (PPC::Predicate) UseMI->getOperand(0).getImm(); |
Hal Finkel | e632239 | 2013-04-19 22:08:38 +0000 | [diff] [blame] | 1907 | assert((!equalityOnly || |
| 1908 | Pred == PPC::PRED_EQ || Pred == PPC::PRED_NE) && |
| 1909 | "Invalid predicate for equality-only optimization"); |
Owen Anderson | 16c6bf4 | 2014-03-13 23:12:04 +0000 | [diff] [blame] | 1910 | PredsToUpdate.push_back(std::make_pair(&(UseMI->getOperand(0)), |
Hal Finkel | 0f64e21 | 2013-04-20 05:16:26 +0000 | [diff] [blame] | 1911 | PPC::getSwappedPredicate(Pred))); |
Hal Finkel | 82656cb | 2013-04-18 22:15:08 +0000 | [diff] [blame] | 1912 | } else if (UseMI->getOpcode() == PPC::ISEL || |
| 1913 | UseMI->getOpcode() == PPC::ISEL8) { |
Hal Finkel | e632239 | 2013-04-19 22:08:38 +0000 | [diff] [blame] | 1914 | unsigned NewSubReg = UseMI->getOperand(3).getSubReg(); |
| 1915 | assert((!equalityOnly || NewSubReg == PPC::sub_eq) && |
| 1916 | "Invalid CR bit for equality-only optimization"); |
| 1917 | |
| 1918 | if (NewSubReg == PPC::sub_lt) |
| 1919 | NewSubReg = PPC::sub_gt; |
| 1920 | else if (NewSubReg == PPC::sub_gt) |
| 1921 | NewSubReg = PPC::sub_lt; |
| 1922 | |
Owen Anderson | 16c6bf4 | 2014-03-13 23:12:04 +0000 | [diff] [blame] | 1923 | SubRegsToUpdate.push_back(std::make_pair(&(UseMI->getOperand(3)), |
Hal Finkel | e632239 | 2013-04-19 22:08:38 +0000 | [diff] [blame] | 1924 | NewSubReg)); |
Hal Finkel | 82656cb | 2013-04-18 22:15:08 +0000 | [diff] [blame] | 1925 | } else // We need to abort on a user we don't understand. |
| 1926 | return false; |
| 1927 | } |
| 1928 | |
| 1929 | // Create a new virtual register to hold the value of the CR set by the |
| 1930 | // record-form instruction. If the instruction was not previously in |
| 1931 | // record form, then set the kill flag on the CR. |
| 1932 | CmpInstr->eraseFromParent(); |
| 1933 | |
| 1934 | MachineBasicBlock::iterator MII = MI; |
Benjamin Kramer | b6d0bd4 | 2014-03-02 12:27:27 +0000 | [diff] [blame] | 1935 | BuildMI(*MI->getParent(), std::next(MII), MI->getDebugLoc(), |
Hal Finkel | 82656cb | 2013-04-18 22:15:08 +0000 | [diff] [blame] | 1936 | get(TargetOpcode::COPY), CRReg) |
Hal Finkel | 08e53ee | 2013-05-08 12:16:14 +0000 | [diff] [blame] | 1937 | .addReg(PPC::CR0, MIOpC != NewOpC ? RegState::Kill : 0); |
Hal Finkel | 82656cb | 2013-04-18 22:15:08 +0000 | [diff] [blame] | 1938 | |
| 1939 | if (MIOpC != NewOpC) { |
| 1940 | // We need to be careful here: we're replacing one instruction with |
| 1941 | // another, and we need to make sure that we get all of the right |
| 1942 | // implicit uses and defs. On the other hand, the caller may be holding |
| 1943 | // an iterator to this instruction, and so we can't delete it (this is |
| 1944 | // specifically the case if this is the instruction directly after the |
| 1945 | // compare). |
| 1946 | |
| 1947 | const MCInstrDesc &NewDesc = get(NewOpC); |
| 1948 | MI->setDesc(NewDesc); |
| 1949 | |
| 1950 | if (NewDesc.ImplicitDefs) |
| 1951 | for (const uint16_t *ImpDefs = NewDesc.getImplicitDefs(); |
| 1952 | *ImpDefs; ++ImpDefs) |
| 1953 | if (!MI->definesRegister(*ImpDefs)) |
| 1954 | MI->addOperand(*MI->getParent()->getParent(), |
| 1955 | MachineOperand::CreateReg(*ImpDefs, true, true)); |
| 1956 | if (NewDesc.ImplicitUses) |
| 1957 | for (const uint16_t *ImpUses = NewDesc.getImplicitUses(); |
| 1958 | *ImpUses; ++ImpUses) |
| 1959 | if (!MI->readsRegister(*ImpUses)) |
| 1960 | MI->addOperand(*MI->getParent()->getParent(), |
| 1961 | MachineOperand::CreateReg(*ImpUses, false, true)); |
| 1962 | } |
| 1963 | |
| 1964 | // Modify the condition code of operands in OperandsToUpdate. |
| 1965 | // Since we have SUB(r1, r2) and CMP(r2, r1), the condition code needs to |
| 1966 | // be changed from r2 > r1 to r1 < r2, from r2 < r1 to r1 > r2, etc. |
Hal Finkel | e632239 | 2013-04-19 22:08:38 +0000 | [diff] [blame] | 1967 | for (unsigned i = 0, e = PredsToUpdate.size(); i < e; i++) |
| 1968 | PredsToUpdate[i].first->setImm(PredsToUpdate[i].second); |
Hal Finkel | 82656cb | 2013-04-18 22:15:08 +0000 | [diff] [blame] | 1969 | |
Hal Finkel | e632239 | 2013-04-19 22:08:38 +0000 | [diff] [blame] | 1970 | for (unsigned i = 0, e = SubRegsToUpdate.size(); i < e; i++) |
| 1971 | SubRegsToUpdate[i].first->setSubReg(SubRegsToUpdate[i].second); |
Hal Finkel | 82656cb | 2013-04-18 22:15:08 +0000 | [diff] [blame] | 1972 | |
| 1973 | return true; |
| 1974 | } |
| 1975 | |
Nicolas Geoffray | ae84bbd | 2008-04-16 20:10:13 +0000 | [diff] [blame] | 1976 | /// GetInstSize - Return the number of bytes of code the specified |
| 1977 | /// instruction may be. This returns the maximum number of bytes. |
| 1978 | /// |
| 1979 | unsigned PPCInstrInfo::GetInstSizeInBytes(const MachineInstr *MI) const { |
Hal Finkel | a7bbaf6 | 2014-02-02 06:12:27 +0000 | [diff] [blame] | 1980 | unsigned Opcode = MI->getOpcode(); |
| 1981 | |
| 1982 | if (Opcode == PPC::INLINEASM) { |
Nicolas Geoffray | ae84bbd | 2008-04-16 20:10:13 +0000 | [diff] [blame] | 1983 | const MachineFunction *MF = MI->getParent()->getParent(); |
| 1984 | const char *AsmStr = MI->getOperand(0).getSymbolName(); |
Chris Lattner | 7b26fce | 2009-08-22 20:48:53 +0000 | [diff] [blame] | 1985 | return getInlineAsmLength(AsmStr, *MF->getTarget().getMCAsmInfo()); |
Hal Finkel | 934361a | 2015-01-14 01:07:51 +0000 | [diff] [blame] | 1986 | } else if (Opcode == TargetOpcode::STACKMAP) { |
| 1987 | return MI->getOperand(1).getImm(); |
| 1988 | } else if (Opcode == TargetOpcode::PATCHPOINT) { |
| 1989 | PatchPointOpers Opers(MI); |
| 1990 | return Opers.getMetaOper(PatchPointOpers::NBytesPos).getImm(); |
Hal Finkel | a7bbaf6 | 2014-02-02 06:12:27 +0000 | [diff] [blame] | 1991 | } else { |
| 1992 | const MCInstrDesc &Desc = get(Opcode); |
| 1993 | return Desc.getSize(); |
Nicolas Geoffray | ae84bbd | 2008-04-16 20:10:13 +0000 | [diff] [blame] | 1994 | } |
| 1995 | } |
Hal Finkel | b5aa7e5 | 2013-04-08 16:24:03 +0000 | [diff] [blame] | 1996 | |