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