blob: 13b4f9ab962da451ca1429c4d9d1a5b926152c54 [file] [log] [blame]
Jia Liub22310f2012-02-18 12:03:15 +00001//===-- PPCInstrInfo.cpp - PowerPC Instruction Information ----------------===//
Misha Brukmanb4402432005-04-21 23:30:14 +00002//
Misha Brukman116f9272004-08-17 04:55:41 +00003// The LLVM Compiler Infrastructure
4//
Chris Lattnerf3ebc3f2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Misha Brukmanb4402432005-04-21 23:30:14 +00007//
Misha Brukman116f9272004-08-17 04:55:41 +00008//===----------------------------------------------------------------------===//
9//
10// This file contains the PowerPC implementation of the TargetInstrInfo class.
11//
12//===----------------------------------------------------------------------===//
13
Chris Lattner6f3b9542005-10-14 23:59:06 +000014#include "PPCInstrInfo.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000015#include "MCTargetDesc/PPCPredicates.h"
Evan Chengc5e6d2f2011-07-11 03:57:24 +000016#include "PPC.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000017#include "PPCHazardRecognizers.h"
Owen Andersoneee14602008-01-01 21:11:32 +000018#include "PPCInstrBuilder.h"
Bill Wendling632ea652008-03-03 22:19:16 +000019#include "PPCMachineFunctionInfo.h"
Chris Lattner49cadab2006-06-17 00:01:04 +000020#include "PPCTargetMachine.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000021#include "llvm/ADT/STLExtras.h"
Chandler Carruth8a8cd2b2014-01-07 11:48:04 +000022#include "llvm/ADT/Statistic.h"
Hal Finkel174e5902014-03-25 23:29:21 +000023#include "llvm/CodeGen/LiveIntervalAnalysis.h"
Jakob Stoklund Olesen6353e532010-07-16 18:22:00 +000024#include "llvm/CodeGen/MachineFrameInfo.h"
Hal Finkelb5aa7e52013-04-08 16:24:03 +000025#include "llvm/CodeGen/MachineFunctionPass.h"
Misha Brukman116f9272004-08-17 04:55:41 +000026#include "llvm/CodeGen/MachineInstrBuilder.h"
Jakob Stoklund Olesen6353e532010-07-16 18:22:00 +000027#include "llvm/CodeGen/MachineMemOperand.h"
Jakob Stoklund Olesenddbf7a82010-02-26 21:09:24 +000028#include "llvm/CodeGen/MachineRegisterInfo.h"
Hal Finkel9f9f8922012-04-01 19:22:40 +000029#include "llvm/CodeGen/PseudoSourceValue.h"
Eric Christopher1dcea732014-06-12 21:48:52 +000030#include "llvm/CodeGen/ScheduleDAG.h"
Hal Finkel174e5902014-03-25 23:29:21 +000031#include "llvm/CodeGen/SlotIndexes.h"
Hal Finkel934361a2015-01-14 01:07:51 +000032#include "llvm/CodeGen/StackMaps.h"
Evan Chengc5e6d2f2011-07-11 03:57:24 +000033#include "llvm/MC/MCAsmInfo.h"
Pete Cooper3de83e42015-05-15 21:58:42 +000034#include "llvm/MC/MCInst.h"
Bill Wendling1af20ad2008-03-04 23:13:51 +000035#include "llvm/Support/CommandLine.h"
Hal Finkel174e5902014-03-25 23:29:21 +000036#include "llvm/Support/Debug.h"
Torok Edwinfb8d6d52009-07-08 20:53:28 +000037#include "llvm/Support/ErrorHandling.h"
Evan Cheng2bb40352011-08-24 18:08:43 +000038#include "llvm/Support/TargetRegistry.h"
Torok Edwinfb8d6d52009-07-08 20:53:28 +000039#include "llvm/Support/raw_ostream.h"
Misha Brukman116f9272004-08-17 04:55:41 +000040
Dan Gohman20857192010-04-15 17:20:57 +000041using namespace llvm;
Bill Wendling1af20ad2008-03-04 23:13:51 +000042
Chandler Carruthe96dd892014-04-21 22:55:11 +000043#define DEBUG_TYPE "ppc-instr-info"
44
Chandler Carruthd174b722014-04-22 02:03:14 +000045#define GET_INSTRMAP_INFO
46#define GET_INSTRINFO_CTOR_DTOR
47#include "PPCGenInstrInfo.inc"
48
Hal Finkel821e0012012-06-08 15:38:25 +000049static cl::
Hal Finkelc6b5deb2012-06-08 19:19:53 +000050opt<bool> DisableCTRLoopAnal("disable-ppc-ctrloop-analysis", cl::Hidden,
51 cl::desc("Disable analysis for CTR loops"));
Hal Finkel821e0012012-06-08 15:38:25 +000052
Hal Finkele6322392013-04-19 22:08:38 +000053static cl::opt<bool> DisableCmpOpt("disable-ppc-cmp-opt",
Hal Finkelb12da6b2013-04-18 22:54:25 +000054cl::desc("Disable compare instruction optimization"), cl::Hidden);
55
Hal Finkel9dcb3582014-03-27 22:46:28 +000056static cl::opt<bool> VSXSelfCopyCrash("crash-on-ppc-vsx-self-copy",
57cl::desc("Causes the backend to crash instead of generating a nop VSX copy"),
58cl::Hidden);
59
Hal Finkel8acae522015-07-14 20:02:02 +000060static cl::opt<bool>
61UseOldLatencyCalc("ppc-old-latency-calc", cl::Hidden,
62 cl::desc("Use the old (incorrect) instruction latency calculation"));
63
Juergen Ributzkad12ccbd2013-11-19 00:57:56 +000064// Pin the vtable to this file.
65void PPCInstrInfo::anchor() {}
66
Eric Christopher1dcea732014-06-12 21:48:52 +000067PPCInstrInfo::PPCInstrInfo(PPCSubtarget &STI)
Tim Shen918ed872017-02-10 21:03:24 +000068 : PPCGenInstrInfo(PPC::ADJCALLSTACKDOWN, PPC::ADJCALLSTACKUP,
69 /* CatchRetOpcode */ -1,
70 STI.isPPC64() ? PPC::BLR8 : PPC::BLR),
Eric Christopherea178cf2015-03-12 01:42:51 +000071 Subtarget(STI), RI(STI.getTargetMachine()) {}
Chris Lattner49cadab2006-06-17 00:01:04 +000072
Andrew Trick10ffc2b2010-12-24 05:03:26 +000073/// CreateTargetHazardRecognizer - Return the hazard recognizer to use for
74/// this target when scheduling the DAG.
Eric Christopherf047bfd2014-06-13 22:38:52 +000075ScheduleHazardRecognizer *
76PPCInstrInfo::CreateTargetHazardRecognizer(const TargetSubtargetInfo *STI,
77 const ScheduleDAG *DAG) const {
78 unsigned Directive =
79 static_cast<const PPCSubtarget *>(STI)->getDarwinDirective();
Hal Finkel742b5352012-08-28 16:12:39 +000080 if (Directive == PPC::DIR_440 || Directive == PPC::DIR_A2 ||
81 Directive == PPC::DIR_E500mc || Directive == PPC::DIR_E5500) {
Eric Christopherf047bfd2014-06-13 22:38:52 +000082 const InstrItineraryData *II =
Eric Christopherd9134482014-08-04 21:25:23 +000083 static_cast<const PPCSubtarget *>(STI)->getInstrItineraryData();
Hal Finkel563cc052013-12-02 23:52:46 +000084 return new ScoreboardHazardRecognizer(II, DAG);
Hal Finkel6fa56972011-10-17 04:03:49 +000085 }
Hal Finkel58ca3602011-12-02 04:58:02 +000086
Eric Christopherf047bfd2014-06-13 22:38:52 +000087 return TargetInstrInfo::CreateTargetHazardRecognizer(STI, DAG);
Andrew Trick10ffc2b2010-12-24 05:03:26 +000088}
89
Hal Finkel58ca3602011-12-02 04:58:02 +000090/// CreateTargetPostRAHazardRecognizer - Return the postRA hazard recognizer
91/// to use for this target when scheduling the DAG.
Eric Christophercccae792015-01-30 22:02:31 +000092ScheduleHazardRecognizer *
93PPCInstrInfo::CreateTargetPostRAHazardRecognizer(const InstrItineraryData *II,
94 const ScheduleDAG *DAG) const {
Eric Christopher1dcea732014-06-12 21:48:52 +000095 unsigned Directive =
Eric Christophercccae792015-01-30 22:02:31 +000096 DAG->MF.getSubtarget<PPCSubtarget>().getDarwinDirective();
Hal Finkel58ca3602011-12-02 04:58:02 +000097
Nemanja Ivanovic6e29baf2016-05-09 18:54:58 +000098 // FIXME: Leaving this as-is until we have POWER9 scheduling info
Will Schmidt970ff642014-06-26 13:36:19 +000099 if (Directive == PPC::DIR_PWR7 || Directive == PPC::DIR_PWR8)
Hal Finkelceb1f122013-12-12 00:19:11 +0000100 return new PPCDispatchGroupSBHazardRecognizer(II, DAG);
101
Hal Finkel58ca3602011-12-02 04:58:02 +0000102 // Most subtargets use a PPC970 recognizer.
Hal Finkel742b5352012-08-28 16:12:39 +0000103 if (Directive != PPC::DIR_440 && Directive != PPC::DIR_A2 &&
104 Directive != PPC::DIR_E500mc && Directive != PPC::DIR_E5500) {
Eric Christopher1dcea732014-06-12 21:48:52 +0000105 assert(DAG->TII && "No InstrInfo?");
Hal Finkel58ca3602011-12-02 04:58:02 +0000106
Eric Christopher1dcea732014-06-12 21:48:52 +0000107 return new PPCHazardRecognizer970(*DAG);
Hal Finkel58ca3602011-12-02 04:58:02 +0000108 }
109
Hal Finkel563cc052013-12-02 23:52:46 +0000110 return new ScoreboardHazardRecognizer(II, DAG);
Hal Finkel58ca3602011-12-02 04:58:02 +0000111}
Jakob Stoklund Olesen0f855e42012-06-19 21:14:34 +0000112
Hal Finkel8acae522015-07-14 20:02:02 +0000113unsigned PPCInstrInfo::getInstrLatency(const InstrItineraryData *ItinData,
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +0000114 const MachineInstr &MI,
Hal Finkel8acae522015-07-14 20:02:02 +0000115 unsigned *PredCost) const {
116 if (!ItinData || UseOldLatencyCalc)
117 return PPCGenInstrInfo::getInstrLatency(ItinData, MI, PredCost);
118
119 // The default implementation of getInstrLatency calls getStageLatency, but
120 // getStageLatency does not do the right thing for us. While we have
121 // itinerary, most cores are fully pipelined, and so the itineraries only
122 // express the first part of the pipeline, not every stage. Instead, we need
123 // to use the listed output operand cycle number (using operand 0 here, which
124 // is an output).
125
126 unsigned Latency = 1;
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +0000127 unsigned DefClass = MI.getDesc().getSchedClass();
128 for (unsigned i = 0, e = MI.getNumOperands(); i != e; ++i) {
129 const MachineOperand &MO = MI.getOperand(i);
Hal Finkel8acae522015-07-14 20:02:02 +0000130 if (!MO.isReg() || !MO.isDef() || MO.isImplicit())
131 continue;
132
133 int Cycle = ItinData->getOperandCycle(DefClass, i);
134 if (Cycle < 0)
135 continue;
136
137 Latency = std::max(Latency, (unsigned) Cycle);
138 }
139
140 return Latency;
141}
Hal Finkelceb1f122013-12-12 00:19:11 +0000142
143int PPCInstrInfo::getOperandLatency(const InstrItineraryData *ItinData,
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +0000144 const MachineInstr &DefMI, unsigned DefIdx,
145 const MachineInstr &UseMI,
Hal Finkelceb1f122013-12-12 00:19:11 +0000146 unsigned UseIdx) const {
147 int Latency = PPCGenInstrInfo::getOperandLatency(ItinData, DefMI, DefIdx,
148 UseMI, UseIdx);
149
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +0000150 if (!DefMI.getParent())
Hal Finkel5d36b232015-07-15 08:23:05 +0000151 return Latency;
152
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +0000153 const MachineOperand &DefMO = DefMI.getOperand(DefIdx);
Hal Finkelceb1f122013-12-12 00:19:11 +0000154 unsigned Reg = DefMO.getReg();
155
Hal Finkelceb1f122013-12-12 00:19:11 +0000156 bool IsRegCR;
Andrew Kaylor5c73e1f2015-03-24 23:37:10 +0000157 if (TargetRegisterInfo::isVirtualRegister(Reg)) {
Hal Finkelceb1f122013-12-12 00:19:11 +0000158 const MachineRegisterInfo *MRI =
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +0000159 &DefMI.getParent()->getParent()->getRegInfo();
Hal Finkelceb1f122013-12-12 00:19:11 +0000160 IsRegCR = MRI->getRegClass(Reg)->hasSuperClassEq(&PPC::CRRCRegClass) ||
161 MRI->getRegClass(Reg)->hasSuperClassEq(&PPC::CRBITRCRegClass);
162 } else {
163 IsRegCR = PPC::CRRCRegClass.contains(Reg) ||
164 PPC::CRBITRCRegClass.contains(Reg);
165 }
166
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +0000167 if (UseMI.isBranch() && IsRegCR) {
Hal Finkelceb1f122013-12-12 00:19:11 +0000168 if (Latency < 0)
169 Latency = getInstrLatency(ItinData, DefMI);
170
171 // On some cores, there is an additional delay between writing to a condition
172 // register, and using it from a branch.
Eric Christopher1dcea732014-06-12 21:48:52 +0000173 unsigned Directive = Subtarget.getDarwinDirective();
Hal Finkelceb1f122013-12-12 00:19:11 +0000174 switch (Directive) {
175 default: break;
176 case PPC::DIR_7400:
177 case PPC::DIR_750:
178 case PPC::DIR_970:
179 case PPC::DIR_E5500:
180 case PPC::DIR_PWR4:
181 case PPC::DIR_PWR5:
182 case PPC::DIR_PWR5X:
183 case PPC::DIR_PWR6:
184 case PPC::DIR_PWR6X:
185 case PPC::DIR_PWR7:
Will Schmidt970ff642014-06-26 13:36:19 +0000186 case PPC::DIR_PWR8:
Nemanja Ivanovic6e29baf2016-05-09 18:54:58 +0000187 // FIXME: Is this needed for POWER9?
Hal Finkelceb1f122013-12-12 00:19:11 +0000188 Latency += 2;
189 break;
190 }
191 }
192
193 return Latency;
194}
195
Hal Finkel5d36b232015-07-15 08:23:05 +0000196// This function does not list all associative and commutative operations, but
197// only those worth feeding through the machine combiner in an attempt to
198// reduce the critical path. Mostly, this means floating-point operations,
199// because they have high latencies (compared to other operations, such and
200// and/or, which are also associative and commutative, but have low latencies).
Chad Rosier03a47302015-09-21 15:09:11 +0000201bool PPCInstrInfo::isAssociativeAndCommutative(const MachineInstr &Inst) const {
202 switch (Inst.getOpcode()) {
Hal Finkel5d36b232015-07-15 08:23:05 +0000203 // FP Add:
204 case PPC::FADD:
205 case PPC::FADDS:
206 // FP Multiply:
207 case PPC::FMUL:
208 case PPC::FMULS:
209 // Altivec Add:
210 case PPC::VADDFP:
211 // VSX Add:
212 case PPC::XSADDDP:
213 case PPC::XVADDDP:
214 case PPC::XVADDSP:
215 case PPC::XSADDSP:
216 // VSX Multiply:
217 case PPC::XSMULDP:
218 case PPC::XVMULDP:
219 case PPC::XVMULSP:
220 case PPC::XSMULSP:
221 // QPX Add:
222 case PPC::QVFADD:
223 case PPC::QVFADDS:
224 case PPC::QVFADDSs:
225 // QPX Multiply:
226 case PPC::QVFMUL:
227 case PPC::QVFMULS:
228 case PPC::QVFMULSs:
229 return true;
230 default:
231 return false;
232 }
233}
234
Chad Rosier03a47302015-09-21 15:09:11 +0000235bool PPCInstrInfo::getMachineCombinerPatterns(
236 MachineInstr &Root,
Sanjay Patel387e66e2015-11-05 19:34:57 +0000237 SmallVectorImpl<MachineCombinerPattern> &Patterns) const {
Hal Finkel5d36b232015-07-15 08:23:05 +0000238 // Using the machine combiner in this way is potentially expensive, so
239 // restrict to when aggressive optimizations are desired.
240 if (Subtarget.getTargetMachine().getOptLevel() != CodeGenOpt::Aggressive)
241 return false;
242
243 // FP reassociation is only legal when we don't need strict IEEE semantics.
244 if (!Root.getParent()->getParent()->getTarget().Options.UnsafeFPMath)
245 return false;
246
Chad Rosier03a47302015-09-21 15:09:11 +0000247 return TargetInstrInfo::getMachineCombinerPatterns(Root, Patterns);
Hal Finkel5d36b232015-07-15 08:23:05 +0000248}
249
Jakob Stoklund Olesen0f855e42012-06-19 21:14:34 +0000250// Detect 32 -> 64-bit extensions where we may reuse the low sub-register.
251bool PPCInstrInfo::isCoalescableExtInstr(const MachineInstr &MI,
252 unsigned &SrcReg, unsigned &DstReg,
253 unsigned &SubIdx) const {
254 switch (MI.getOpcode()) {
255 default: return false;
256 case PPC::EXTSW:
257 case PPC::EXTSW_32_64:
258 SrcReg = MI.getOperand(1).getReg();
259 DstReg = MI.getOperand(0).getReg();
260 SubIdx = PPC::sub_32;
261 return true;
262 }
263}
264
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +0000265unsigned PPCInstrInfo::isLoadFromStackSlot(const MachineInstr &MI,
Chris Lattner91400bd2006-03-16 22:24:02 +0000266 int &FrameIndex) const {
Hal Finkel37714b82013-03-27 21:21:15 +0000267 // Note: This list must be kept consistent with LoadRegFromStackSlot.
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +0000268 switch (MI.getOpcode()) {
Chris Lattnerbb53acd2006-02-02 20:12:32 +0000269 default: break;
270 case PPC::LD:
271 case PPC::LWZ:
272 case PPC::LFS:
273 case PPC::LFD:
Hal Finkel37714b82013-03-27 21:21:15 +0000274 case PPC::RESTORE_CR:
Hal Finkel940ab932014-02-28 00:27:01 +0000275 case PPC::RESTORE_CRBIT:
Hal Finkel37714b82013-03-27 21:21:15 +0000276 case PPC::LVX:
Hal Finkel27774d92014-03-13 07:58:58 +0000277 case PPC::LXVD2X:
Nemanja Ivanovic6e7879c2016-09-22 09:52:19 +0000278 case PPC::LXVX:
Hal Finkelc93a9a22015-02-25 01:06:45 +0000279 case PPC::QVLFDX:
280 case PPC::QVLFSXs:
281 case PPC::QVLFDXb:
Hal Finkel37714b82013-03-27 21:21:15 +0000282 case PPC::RESTORE_VRSAVE:
283 // Check for the operands added by addFrameReference (the immediate is the
284 // offset which defaults to 0).
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +0000285 if (MI.getOperand(1).isImm() && !MI.getOperand(1).getImm() &&
286 MI.getOperand(2).isFI()) {
287 FrameIndex = MI.getOperand(2).getIndex();
288 return MI.getOperand(0).getReg();
Chris Lattnerbb53acd2006-02-02 20:12:32 +0000289 }
290 break;
291 }
292 return 0;
Chris Lattnerc327d712006-02-02 20:16:12 +0000293}
Chris Lattnerbb53acd2006-02-02 20:12:32 +0000294
Lei Huang84dbbfd2017-06-21 17:17:56 +0000295// For opcodes with the ReMaterializable flag set, this function is called to
296// verify the instruction is really rematable.
297bool PPCInstrInfo::isReallyTriviallyReMaterializable(const MachineInstr &MI,
298 AliasAnalysis *AA) const {
299 switch (MI.getOpcode()) {
300 default:
301 // This function should only be called for opcodes with the ReMaterializable
302 // flag set.
303 llvm_unreachable("Unknown rematerializable operation!");
304 break;
305 case PPC::LI:
306 case PPC::LI8:
307 case PPC::LIS:
308 case PPC::LIS8:
309 case PPC::QVGPCI:
310 case PPC::ADDIStocHA:
311 case PPC::ADDItocL:
312 case PPC::LOAD_STACK_GUARD:
313 return true;
314 }
315 return false;
316}
317
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +0000318unsigned PPCInstrInfo::isStoreToStackSlot(const MachineInstr &MI,
Chris Lattnerc327d712006-02-02 20:16:12 +0000319 int &FrameIndex) const {
Hal Finkel37714b82013-03-27 21:21:15 +0000320 // Note: This list must be kept consistent with StoreRegToStackSlot.
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +0000321 switch (MI.getOpcode()) {
Chris Lattnerc327d712006-02-02 20:16:12 +0000322 default: break;
Nate Begeman4efb3282006-02-02 21:07:50 +0000323 case PPC::STD:
Chris Lattnerc327d712006-02-02 20:16:12 +0000324 case PPC::STW:
325 case PPC::STFS:
326 case PPC::STFD:
Hal Finkel37714b82013-03-27 21:21:15 +0000327 case PPC::SPILL_CR:
Hal Finkel940ab932014-02-28 00:27:01 +0000328 case PPC::SPILL_CRBIT:
Hal Finkel37714b82013-03-27 21:21:15 +0000329 case PPC::STVX:
Hal Finkel27774d92014-03-13 07:58:58 +0000330 case PPC::STXVD2X:
Nemanja Ivanovic6e7879c2016-09-22 09:52:19 +0000331 case PPC::STXVX:
Hal Finkelc93a9a22015-02-25 01:06:45 +0000332 case PPC::QVSTFDX:
333 case PPC::QVSTFSXs:
334 case PPC::QVSTFDXb:
Hal Finkel37714b82013-03-27 21:21:15 +0000335 case PPC::SPILL_VRSAVE:
336 // Check for the operands added by addFrameReference (the immediate is the
337 // offset which defaults to 0).
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +0000338 if (MI.getOperand(1).isImm() && !MI.getOperand(1).getImm() &&
339 MI.getOperand(2).isFI()) {
340 FrameIndex = MI.getOperand(2).getIndex();
341 return MI.getOperand(0).getReg();
Chris Lattnerc327d712006-02-02 20:16:12 +0000342 }
343 break;
344 }
345 return 0;
346}
Chris Lattnerbb53acd2006-02-02 20:12:32 +0000347
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +0000348MachineInstr *PPCInstrInfo::commuteInstructionImpl(MachineInstr &MI, bool NewMI,
Andrew Kaylor16c4da02015-09-28 20:33:22 +0000349 unsigned OpIdx1,
350 unsigned OpIdx2) const {
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +0000351 MachineFunction &MF = *MI.getParent()->getParent();
Dan Gohman3b460302008-07-07 23:14:23 +0000352
Chris Lattnerc37a2f12005-09-09 18:17:41 +0000353 // Normal instructions can be commuted the obvious way.
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +0000354 if (MI.getOpcode() != PPC::RLWIMI && MI.getOpcode() != PPC::RLWIMIo)
Andrew Kaylor16c4da02015-09-28 20:33:22 +0000355 return TargetInstrInfo::commuteInstructionImpl(MI, NewMI, OpIdx1, OpIdx2);
Hal Finkel4c6658f2014-12-12 23:59:36 +0000356 // Note that RLWIMI can be commuted as a 32-bit instruction, but not as a
357 // 64-bit instruction (so we don't handle PPC::RLWIMI8 here), because
358 // changing the relative order of the mask operands might change what happens
359 // to the high-bits of the mask (and, thus, the result).
Andrew Trickc416ba62010-12-24 04:28:06 +0000360
Chris Lattnerc37a2f12005-09-09 18:17:41 +0000361 // Cannot commute if it has a non-zero rotate count.
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +0000362 if (MI.getOperand(3).getImm() != 0)
Craig Topper062a2ba2014-04-25 05:30:21 +0000363 return nullptr;
Andrew Trickc416ba62010-12-24 04:28:06 +0000364
Chris Lattnerc37a2f12005-09-09 18:17:41 +0000365 // If we have a zero rotate count, we have:
366 // M = mask(MB,ME)
367 // Op0 = (Op1 & ~M) | (Op2 & M)
368 // Change this to:
369 // M = mask((ME+1)&31, (MB-1)&31)
370 // Op0 = (Op2 & ~M) | (Op1 & M)
371
372 // Swap op1/op2
Andrew Kaylor16c4da02015-09-28 20:33:22 +0000373 assert(((OpIdx1 == 1 && OpIdx2 == 2) || (OpIdx1 == 2 && OpIdx2 == 1)) &&
374 "Only the operands 1 and 2 can be swapped in RLSIMI/RLWIMIo.");
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +0000375 unsigned Reg0 = MI.getOperand(0).getReg();
376 unsigned Reg1 = MI.getOperand(1).getReg();
377 unsigned Reg2 = MI.getOperand(2).getReg();
378 unsigned SubReg1 = MI.getOperand(1).getSubReg();
379 unsigned SubReg2 = MI.getOperand(2).getSubReg();
380 bool Reg1IsKill = MI.getOperand(1).isKill();
381 bool Reg2IsKill = MI.getOperand(2).isKill();
Evan Cheng03553bb2008-06-16 07:33:11 +0000382 bool ChangeReg0 = false;
Evan Cheng244183e2008-02-13 02:46:49 +0000383 // If machine instrs are no longer in two-address forms, update
384 // destination register as well.
385 if (Reg0 == Reg1) {
386 // Must be two address instruction!
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +0000387 assert(MI.getDesc().getOperandConstraint(0, MCOI::TIED_TO) &&
Evan Cheng244183e2008-02-13 02:46:49 +0000388 "Expecting a two-address instruction!");
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +0000389 assert(MI.getOperand(0).getSubReg() == SubReg1 && "Tied subreg mismatch");
Evan Cheng244183e2008-02-13 02:46:49 +0000390 Reg2IsKill = false;
Evan Cheng03553bb2008-06-16 07:33:11 +0000391 ChangeReg0 = true;
Evan Cheng244183e2008-02-13 02:46:49 +0000392 }
Evan Cheng03553bb2008-06-16 07:33:11 +0000393
394 // Masks.
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +0000395 unsigned MB = MI.getOperand(4).getImm();
396 unsigned ME = MI.getOperand(5).getImm();
Evan Cheng03553bb2008-06-16 07:33:11 +0000397
Hal Finkelccf92592015-09-06 04:17:30 +0000398 // We can't commute a trivial mask (there is no way to represent an all-zero
399 // mask).
400 if (MB == 0 && ME == 31)
401 return nullptr;
402
Evan Cheng03553bb2008-06-16 07:33:11 +0000403 if (NewMI) {
404 // Create a new instruction.
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +0000405 unsigned Reg0 = ChangeReg0 ? Reg2 : MI.getOperand(0).getReg();
406 bool Reg0IsDead = MI.getOperand(0).isDead();
407 return BuildMI(MF, MI.getDebugLoc(), MI.getDesc())
408 .addReg(Reg0, RegState::Define | getDeadRegState(Reg0IsDead))
409 .addReg(Reg2, getKillRegState(Reg2IsKill))
410 .addReg(Reg1, getKillRegState(Reg1IsKill))
411 .addImm((ME + 1) & 31)
412 .addImm((MB - 1) & 31);
Evan Cheng03553bb2008-06-16 07:33:11 +0000413 }
414
Andrew Tricke3398282013-12-17 04:50:45 +0000415 if (ChangeReg0) {
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +0000416 MI.getOperand(0).setReg(Reg2);
417 MI.getOperand(0).setSubReg(SubReg2);
Andrew Tricke3398282013-12-17 04:50:45 +0000418 }
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +0000419 MI.getOperand(2).setReg(Reg1);
420 MI.getOperand(1).setReg(Reg2);
421 MI.getOperand(2).setSubReg(SubReg1);
422 MI.getOperand(1).setSubReg(SubReg2);
423 MI.getOperand(2).setIsKill(Reg1IsKill);
424 MI.getOperand(1).setIsKill(Reg2IsKill);
Andrew Trickc416ba62010-12-24 04:28:06 +0000425
Chris Lattnerc37a2f12005-09-09 18:17:41 +0000426 // Swap the mask around.
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +0000427 MI.getOperand(4).setImm((ME + 1) & 31);
428 MI.getOperand(5).setImm((MB - 1) & 31);
429 return &MI;
Chris Lattnerc37a2f12005-09-09 18:17:41 +0000430}
Chris Lattnerea79d9fd732006-03-05 23:49:55 +0000431
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +0000432bool PPCInstrInfo::findCommutedOpIndices(MachineInstr &MI, unsigned &SrcOpIdx1,
Hal Finkel6c32ff32014-03-25 19:26:43 +0000433 unsigned &SrcOpIdx2) const {
434 // For VSX A-Type FMA instructions, it is the first two operands that can be
435 // commuted, however, because the non-encoded tied input operand is listed
436 // first, the operands to swap are actually the second and third.
437
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +0000438 int AltOpc = PPC::getAltVSXFMAOpcode(MI.getOpcode());
Hal Finkel6c32ff32014-03-25 19:26:43 +0000439 if (AltOpc == -1)
440 return TargetInstrInfo::findCommutedOpIndices(MI, SrcOpIdx1, SrcOpIdx2);
441
Andrew Kaylor16c4da02015-09-28 20:33:22 +0000442 // The commutable operand indices are 2 and 3. Return them in SrcOpIdx1
443 // and SrcOpIdx2.
444 return fixCommutedOpIndices(SrcOpIdx1, SrcOpIdx2, 2, 3);
Hal Finkel6c32ff32014-03-25 19:26:43 +0000445}
446
Andrew Trickc416ba62010-12-24 04:28:06 +0000447void PPCInstrInfo::insertNoop(MachineBasicBlock &MBB,
Chris Lattnerea79d9fd732006-03-05 23:49:55 +0000448 MachineBasicBlock::iterator MI) const {
Hal Finkelceb1f122013-12-12 00:19:11 +0000449 // This function is used for scheduling, and the nop wanted here is the type
450 // that terminates dispatch groups on the POWER cores.
Eric Christopher1dcea732014-06-12 21:48:52 +0000451 unsigned Directive = Subtarget.getDarwinDirective();
Hal Finkelceb1f122013-12-12 00:19:11 +0000452 unsigned Opcode;
453 switch (Directive) {
454 default: Opcode = PPC::NOP; break;
455 case PPC::DIR_PWR6: Opcode = PPC::NOP_GT_PWR6; break;
456 case PPC::DIR_PWR7: Opcode = PPC::NOP_GT_PWR7; break;
Will Schmidt970ff642014-06-26 13:36:19 +0000457 case PPC::DIR_PWR8: Opcode = PPC::NOP_GT_PWR7; break; /* FIXME: Update when P8 InstrScheduling model is ready */
Nemanja Ivanovic6e29baf2016-05-09 18:54:58 +0000458 // FIXME: Update when POWER9 scheduling model is ready.
459 case PPC::DIR_PWR9: Opcode = PPC::NOP_GT_PWR7; break;
Hal Finkelceb1f122013-12-12 00:19:11 +0000460 }
Chris Lattnera47294ed2006-10-13 21:21:17 +0000461
Hal Finkelceb1f122013-12-12 00:19:11 +0000462 DebugLoc DL;
463 BuildMI(MBB, MI, DL, get(Opcode));
464}
Chris Lattnera47294ed2006-10-13 21:21:17 +0000465
Hans Wennborg9b9a5352017-04-21 21:48:41 +0000466/// Return the noop instruction to use for a noop.
467void PPCInstrInfo::getNoop(MCInst &NopInst) const {
Joerg Sonnenberger7ee0f312014-08-08 19:13:23 +0000468 NopInst.setOpcode(PPC::NOP);
469}
470
Chris Lattnera47294ed2006-10-13 21:21:17 +0000471// Branch analysis.
Hal Finkel96c2d4d2012-06-08 15:38:21 +0000472// Note: If the condition register is set to CTR or CTR8 then this is a
473// BDNZ (imm == 1) or BDZ (imm == 0) branch.
Jacques Pienaar71c30a12016-07-15 14:41:04 +0000474bool PPCInstrInfo::analyzeBranch(MachineBasicBlock &MBB,
475 MachineBasicBlock *&TBB,
Chris Lattnera47294ed2006-10-13 21:21:17 +0000476 MachineBasicBlock *&FBB,
Evan Cheng64dfcac2009-02-09 07:14:22 +0000477 SmallVectorImpl<MachineOperand> &Cond,
478 bool AllowModify) const {
Eric Christopher1dcea732014-06-12 21:48:52 +0000479 bool isPPC64 = Subtarget.isPPC64();
Hal Finkel96c2d4d2012-06-08 15:38:21 +0000480
Chris Lattnera47294ed2006-10-13 21:21:17 +0000481 // If the block has no terminators, it just falls into the block after it.
Benjamin Kramer92861d72015-06-25 13:39:03 +0000482 MachineBasicBlock::iterator I = MBB.getLastNonDebugInstr();
483 if (I == MBB.end())
Dale Johannesen4244d122010-04-02 01:38:09 +0000484 return false;
Benjamin Kramer92861d72015-06-25 13:39:03 +0000485
Duncan P. N. Exon Smith6307eb52016-02-23 02:46:52 +0000486 if (!isUnpredicatedTerminator(*I))
Chris Lattnera47294ed2006-10-13 21:21:17 +0000487 return false;
488
489 // Get the last instruction in the block.
Duncan P. N. Exon Smithe5a22f42016-07-27 13:24:16 +0000490 MachineInstr &LastInst = *I;
Andrew Trickc416ba62010-12-24 04:28:06 +0000491
Chris Lattnera47294ed2006-10-13 21:21:17 +0000492 // If there is only one terminator instruction, process it.
Duncan P. N. Exon Smith6307eb52016-02-23 02:46:52 +0000493 if (I == MBB.begin() || !isUnpredicatedTerminator(*--I)) {
Duncan P. N. Exon Smithe5a22f42016-07-27 13:24:16 +0000494 if (LastInst.getOpcode() == PPC::B) {
495 if (!LastInst.getOperand(0).isMBB())
Evan Cheng8f43afd2009-05-08 23:09:25 +0000496 return true;
Duncan P. N. Exon Smithe5a22f42016-07-27 13:24:16 +0000497 TBB = LastInst.getOperand(0).getMBB();
Chris Lattnera47294ed2006-10-13 21:21:17 +0000498 return false;
Duncan P. N. Exon Smithe5a22f42016-07-27 13:24:16 +0000499 } else if (LastInst.getOpcode() == PPC::BCC) {
500 if (!LastInst.getOperand(2).isMBB())
Evan Cheng8f43afd2009-05-08 23:09:25 +0000501 return true;
Chris Lattnera47294ed2006-10-13 21:21:17 +0000502 // Block ends with fall-through condbranch.
Duncan P. N. Exon Smithe5a22f42016-07-27 13:24:16 +0000503 TBB = LastInst.getOperand(2).getMBB();
504 Cond.push_back(LastInst.getOperand(0));
505 Cond.push_back(LastInst.getOperand(1));
Chris Lattner23f22de2006-10-21 06:03:11 +0000506 return false;
Duncan P. N. Exon Smithe5a22f42016-07-27 13:24:16 +0000507 } else if (LastInst.getOpcode() == PPC::BC) {
508 if (!LastInst.getOperand(1).isMBB())
Hal Finkel940ab932014-02-28 00:27:01 +0000509 return true;
510 // Block ends with fall-through condbranch.
Duncan P. N. Exon Smithe5a22f42016-07-27 13:24:16 +0000511 TBB = LastInst.getOperand(1).getMBB();
Hal Finkel940ab932014-02-28 00:27:01 +0000512 Cond.push_back(MachineOperand::CreateImm(PPC::PRED_BIT_SET));
Duncan P. N. Exon Smithe5a22f42016-07-27 13:24:16 +0000513 Cond.push_back(LastInst.getOperand(0));
Hal Finkel940ab932014-02-28 00:27:01 +0000514 return false;
Duncan P. N. Exon Smithe5a22f42016-07-27 13:24:16 +0000515 } else if (LastInst.getOpcode() == PPC::BCn) {
516 if (!LastInst.getOperand(1).isMBB())
Hal Finkel940ab932014-02-28 00:27:01 +0000517 return true;
518 // Block ends with fall-through condbranch.
Duncan P. N. Exon Smithe5a22f42016-07-27 13:24:16 +0000519 TBB = LastInst.getOperand(1).getMBB();
Hal Finkel940ab932014-02-28 00:27:01 +0000520 Cond.push_back(MachineOperand::CreateImm(PPC::PRED_BIT_UNSET));
Duncan P. N. Exon Smithe5a22f42016-07-27 13:24:16 +0000521 Cond.push_back(LastInst.getOperand(0));
Hal Finkel940ab932014-02-28 00:27:01 +0000522 return false;
Duncan P. N. Exon Smithe5a22f42016-07-27 13:24:16 +0000523 } else if (LastInst.getOpcode() == PPC::BDNZ8 ||
524 LastInst.getOpcode() == PPC::BDNZ) {
525 if (!LastInst.getOperand(0).isMBB())
Hal Finkel96c2d4d2012-06-08 15:38:21 +0000526 return true;
Hal Finkelc6b5deb2012-06-08 19:19:53 +0000527 if (DisableCTRLoopAnal)
Hal Finkel821e0012012-06-08 15:38:25 +0000528 return true;
Duncan P. N. Exon Smithe5a22f42016-07-27 13:24:16 +0000529 TBB = LastInst.getOperand(0).getMBB();
Hal Finkel96c2d4d2012-06-08 15:38:21 +0000530 Cond.push_back(MachineOperand::CreateImm(1));
531 Cond.push_back(MachineOperand::CreateReg(isPPC64 ? PPC::CTR8 : PPC::CTR,
532 true));
533 return false;
Duncan P. N. Exon Smithe5a22f42016-07-27 13:24:16 +0000534 } else if (LastInst.getOpcode() == PPC::BDZ8 ||
535 LastInst.getOpcode() == PPC::BDZ) {
536 if (!LastInst.getOperand(0).isMBB())
Hal Finkel96c2d4d2012-06-08 15:38:21 +0000537 return true;
Hal Finkelc6b5deb2012-06-08 19:19:53 +0000538 if (DisableCTRLoopAnal)
Hal Finkel821e0012012-06-08 15:38:25 +0000539 return true;
Duncan P. N. Exon Smithe5a22f42016-07-27 13:24:16 +0000540 TBB = LastInst.getOperand(0).getMBB();
Hal Finkel96c2d4d2012-06-08 15:38:21 +0000541 Cond.push_back(MachineOperand::CreateImm(0));
542 Cond.push_back(MachineOperand::CreateReg(isPPC64 ? PPC::CTR8 : PPC::CTR,
543 true));
544 return false;
Chris Lattnera47294ed2006-10-13 21:21:17 +0000545 }
Hal Finkel96c2d4d2012-06-08 15:38:21 +0000546
Chris Lattnera47294ed2006-10-13 21:21:17 +0000547 // Otherwise, don't know what this is.
548 return true;
549 }
Andrew Trickc416ba62010-12-24 04:28:06 +0000550
Chris Lattnera47294ed2006-10-13 21:21:17 +0000551 // Get the instruction before it if it's a terminator.
Duncan P. N. Exon Smithe5a22f42016-07-27 13:24:16 +0000552 MachineInstr &SecondLastInst = *I;
Chris Lattnera47294ed2006-10-13 21:21:17 +0000553
554 // If there are three terminators, we don't know what sort of block this is.
Duncan P. N. Exon Smithe5a22f42016-07-27 13:24:16 +0000555 if (I != MBB.begin() && isUnpredicatedTerminator(*--I))
Chris Lattnera47294ed2006-10-13 21:21:17 +0000556 return true;
Andrew Trickc416ba62010-12-24 04:28:06 +0000557
Chris Lattnere0263792006-11-17 22:14:47 +0000558 // If the block ends with PPC::B and PPC:BCC, handle it.
Duncan P. N. Exon Smithe5a22f42016-07-27 13:24:16 +0000559 if (SecondLastInst.getOpcode() == PPC::BCC &&
560 LastInst.getOpcode() == PPC::B) {
561 if (!SecondLastInst.getOperand(2).isMBB() ||
562 !LastInst.getOperand(0).isMBB())
Evan Cheng8f43afd2009-05-08 23:09:25 +0000563 return true;
Duncan P. N. Exon Smithe5a22f42016-07-27 13:24:16 +0000564 TBB = SecondLastInst.getOperand(2).getMBB();
565 Cond.push_back(SecondLastInst.getOperand(0));
566 Cond.push_back(SecondLastInst.getOperand(1));
567 FBB = LastInst.getOperand(0).getMBB();
Chris Lattnera47294ed2006-10-13 21:21:17 +0000568 return false;
Duncan P. N. Exon Smithe5a22f42016-07-27 13:24:16 +0000569 } else if (SecondLastInst.getOpcode() == PPC::BC &&
570 LastInst.getOpcode() == PPC::B) {
571 if (!SecondLastInst.getOperand(1).isMBB() ||
572 !LastInst.getOperand(0).isMBB())
Hal Finkel940ab932014-02-28 00:27:01 +0000573 return true;
Duncan P. N. Exon Smithe5a22f42016-07-27 13:24:16 +0000574 TBB = SecondLastInst.getOperand(1).getMBB();
Hal Finkel940ab932014-02-28 00:27:01 +0000575 Cond.push_back(MachineOperand::CreateImm(PPC::PRED_BIT_SET));
Duncan P. N. Exon Smithe5a22f42016-07-27 13:24:16 +0000576 Cond.push_back(SecondLastInst.getOperand(0));
577 FBB = LastInst.getOperand(0).getMBB();
Hal Finkel940ab932014-02-28 00:27:01 +0000578 return false;
Duncan P. N. Exon Smithe5a22f42016-07-27 13:24:16 +0000579 } else if (SecondLastInst.getOpcode() == PPC::BCn &&
580 LastInst.getOpcode() == PPC::B) {
581 if (!SecondLastInst.getOperand(1).isMBB() ||
582 !LastInst.getOperand(0).isMBB())
Hal Finkel940ab932014-02-28 00:27:01 +0000583 return true;
Duncan P. N. Exon Smithe5a22f42016-07-27 13:24:16 +0000584 TBB = SecondLastInst.getOperand(1).getMBB();
Hal Finkel940ab932014-02-28 00:27:01 +0000585 Cond.push_back(MachineOperand::CreateImm(PPC::PRED_BIT_UNSET));
Duncan P. N. Exon Smithe5a22f42016-07-27 13:24:16 +0000586 Cond.push_back(SecondLastInst.getOperand(0));
587 FBB = LastInst.getOperand(0).getMBB();
Hal Finkel940ab932014-02-28 00:27:01 +0000588 return false;
Duncan P. N. Exon Smithe5a22f42016-07-27 13:24:16 +0000589 } else if ((SecondLastInst.getOpcode() == PPC::BDNZ8 ||
590 SecondLastInst.getOpcode() == PPC::BDNZ) &&
591 LastInst.getOpcode() == PPC::B) {
592 if (!SecondLastInst.getOperand(0).isMBB() ||
593 !LastInst.getOperand(0).isMBB())
Hal Finkel96c2d4d2012-06-08 15:38:21 +0000594 return true;
Hal Finkelc6b5deb2012-06-08 19:19:53 +0000595 if (DisableCTRLoopAnal)
Hal Finkel821e0012012-06-08 15:38:25 +0000596 return true;
Duncan P. N. Exon Smithe5a22f42016-07-27 13:24:16 +0000597 TBB = SecondLastInst.getOperand(0).getMBB();
Hal Finkel96c2d4d2012-06-08 15:38:21 +0000598 Cond.push_back(MachineOperand::CreateImm(1));
599 Cond.push_back(MachineOperand::CreateReg(isPPC64 ? PPC::CTR8 : PPC::CTR,
600 true));
Duncan P. N. Exon Smithe5a22f42016-07-27 13:24:16 +0000601 FBB = LastInst.getOperand(0).getMBB();
Hal Finkel96c2d4d2012-06-08 15:38:21 +0000602 return false;
Duncan P. N. Exon Smithe5a22f42016-07-27 13:24:16 +0000603 } else if ((SecondLastInst.getOpcode() == PPC::BDZ8 ||
604 SecondLastInst.getOpcode() == PPC::BDZ) &&
605 LastInst.getOpcode() == PPC::B) {
606 if (!SecondLastInst.getOperand(0).isMBB() ||
607 !LastInst.getOperand(0).isMBB())
Hal Finkel96c2d4d2012-06-08 15:38:21 +0000608 return true;
Hal Finkelc6b5deb2012-06-08 19:19:53 +0000609 if (DisableCTRLoopAnal)
Hal Finkel821e0012012-06-08 15:38:25 +0000610 return true;
Duncan P. N. Exon Smithe5a22f42016-07-27 13:24:16 +0000611 TBB = SecondLastInst.getOperand(0).getMBB();
Hal Finkel96c2d4d2012-06-08 15:38:21 +0000612 Cond.push_back(MachineOperand::CreateImm(0));
613 Cond.push_back(MachineOperand::CreateReg(isPPC64 ? PPC::CTR8 : PPC::CTR,
614 true));
Duncan P. N. Exon Smithe5a22f42016-07-27 13:24:16 +0000615 FBB = LastInst.getOperand(0).getMBB();
Hal Finkel96c2d4d2012-06-08 15:38:21 +0000616 return false;
Chris Lattnera47294ed2006-10-13 21:21:17 +0000617 }
Andrew Trickc416ba62010-12-24 04:28:06 +0000618
Dale Johannesenc6855462007-06-13 17:59:52 +0000619 // If the block ends with two PPC:Bs, handle it. The second one is not
620 // executed, so remove it.
Duncan P. N. Exon Smithe5a22f42016-07-27 13:24:16 +0000621 if (SecondLastInst.getOpcode() == PPC::B && LastInst.getOpcode() == PPC::B) {
622 if (!SecondLastInst.getOperand(0).isMBB())
Evan Cheng8f43afd2009-05-08 23:09:25 +0000623 return true;
Duncan P. N. Exon Smithe5a22f42016-07-27 13:24:16 +0000624 TBB = SecondLastInst.getOperand(0).getMBB();
Dale Johannesenc6855462007-06-13 17:59:52 +0000625 I = LastInst;
Evan Cheng64dfcac2009-02-09 07:14:22 +0000626 if (AllowModify)
627 I->eraseFromParent();
Dale Johannesenc6855462007-06-13 17:59:52 +0000628 return false;
629 }
630
Chris Lattnera47294ed2006-10-13 21:21:17 +0000631 // Otherwise, can't handle this.
632 return true;
633}
634
Matt Arsenault1b9fc8e2016-09-14 20:43:16 +0000635unsigned PPCInstrInfo::removeBranch(MachineBasicBlock &MBB,
Matt Arsenaulta2b036e2016-09-14 17:23:48 +0000636 int *BytesRemoved) const {
637 assert(!BytesRemoved && "code size not handled");
638
Benjamin Kramer92861d72015-06-25 13:39:03 +0000639 MachineBasicBlock::iterator I = MBB.getLastNonDebugInstr();
640 if (I == MBB.end())
641 return 0;
642
Hal Finkel96c2d4d2012-06-08 15:38:21 +0000643 if (I->getOpcode() != PPC::B && I->getOpcode() != PPC::BCC &&
Hal Finkel940ab932014-02-28 00:27:01 +0000644 I->getOpcode() != PPC::BC && I->getOpcode() != PPC::BCn &&
Hal Finkel96c2d4d2012-06-08 15:38:21 +0000645 I->getOpcode() != PPC::BDNZ8 && I->getOpcode() != PPC::BDNZ &&
646 I->getOpcode() != PPC::BDZ8 && I->getOpcode() != PPC::BDZ)
Evan Cheng99be49d2007-05-18 00:05:48 +0000647 return 0;
Andrew Trickc416ba62010-12-24 04:28:06 +0000648
Chris Lattnera47294ed2006-10-13 21:21:17 +0000649 // Remove the branch.
650 I->eraseFromParent();
Andrew Trickc416ba62010-12-24 04:28:06 +0000651
Chris Lattnera47294ed2006-10-13 21:21:17 +0000652 I = MBB.end();
653
Evan Cheng99be49d2007-05-18 00:05:48 +0000654 if (I == MBB.begin()) return 1;
Chris Lattnera47294ed2006-10-13 21:21:17 +0000655 --I;
Hal Finkel96c2d4d2012-06-08 15:38:21 +0000656 if (I->getOpcode() != PPC::BCC &&
Hal Finkel940ab932014-02-28 00:27:01 +0000657 I->getOpcode() != PPC::BC && I->getOpcode() != PPC::BCn &&
Hal Finkel96c2d4d2012-06-08 15:38:21 +0000658 I->getOpcode() != PPC::BDNZ8 && I->getOpcode() != PPC::BDNZ &&
659 I->getOpcode() != PPC::BDZ8 && I->getOpcode() != PPC::BDZ)
Evan Cheng99be49d2007-05-18 00:05:48 +0000660 return 1;
Andrew Trickc416ba62010-12-24 04:28:06 +0000661
Chris Lattnera47294ed2006-10-13 21:21:17 +0000662 // Remove the branch.
663 I->eraseFromParent();
Evan Cheng99be49d2007-05-18 00:05:48 +0000664 return 2;
Chris Lattnera47294ed2006-10-13 21:21:17 +0000665}
666
Matt Arsenaulte8e0f5c2016-09-14 17:24:15 +0000667unsigned PPCInstrInfo::insertBranch(MachineBasicBlock &MBB,
Benjamin Kramerbdc49562016-06-12 15:39:02 +0000668 MachineBasicBlock *TBB,
669 MachineBasicBlock *FBB,
670 ArrayRef<MachineOperand> Cond,
Matt Arsenaulta2b036e2016-09-14 17:23:48 +0000671 const DebugLoc &DL,
672 int *BytesAdded) const {
Chris Lattnera61f0102006-10-17 18:06:55 +0000673 // Shouldn't be a fall through.
Matt Arsenaulte8e0f5c2016-09-14 17:24:15 +0000674 assert(TBB && "insertBranch must not be told to insert a fallthrough");
Andrew Trickc416ba62010-12-24 04:28:06 +0000675 assert((Cond.size() == 2 || Cond.size() == 0) &&
Chris Lattner94e04442006-10-21 05:36:13 +0000676 "PPC branch conditions have two components!");
Matt Arsenaulta2b036e2016-09-14 17:23:48 +0000677 assert(!BytesAdded && "code size not handled");
Andrew Trickc416ba62010-12-24 04:28:06 +0000678
Eric Christopher1dcea732014-06-12 21:48:52 +0000679 bool isPPC64 = Subtarget.isPPC64();
Hal Finkel96c2d4d2012-06-08 15:38:21 +0000680
Chris Lattner94e04442006-10-21 05:36:13 +0000681 // One-way branch.
Craig Topper062a2ba2014-04-25 05:30:21 +0000682 if (!FBB) {
Chris Lattner94e04442006-10-21 05:36:13 +0000683 if (Cond.empty()) // Unconditional branch
Stuart Hastings0125b642010-06-17 22:43:56 +0000684 BuildMI(&MBB, DL, get(PPC::B)).addMBB(TBB);
Hal Finkel96c2d4d2012-06-08 15:38:21 +0000685 else if (Cond[1].getReg() == PPC::CTR || Cond[1].getReg() == PPC::CTR8)
686 BuildMI(&MBB, DL, get(Cond[0].getImm() ?
687 (isPPC64 ? PPC::BDNZ8 : PPC::BDNZ) :
688 (isPPC64 ? PPC::BDZ8 : PPC::BDZ))).addMBB(TBB);
Hal Finkel940ab932014-02-28 00:27:01 +0000689 else if (Cond[0].getImm() == PPC::PRED_BIT_SET)
Diana Picus116bbab2017-01-13 09:58:52 +0000690 BuildMI(&MBB, DL, get(PPC::BC)).add(Cond[1]).addMBB(TBB);
Hal Finkel940ab932014-02-28 00:27:01 +0000691 else if (Cond[0].getImm() == PPC::PRED_BIT_UNSET)
Diana Picus116bbab2017-01-13 09:58:52 +0000692 BuildMI(&MBB, DL, get(PPC::BCn)).add(Cond[1]).addMBB(TBB);
Chris Lattner94e04442006-10-21 05:36:13 +0000693 else // Conditional branch
Stuart Hastings0125b642010-06-17 22:43:56 +0000694 BuildMI(&MBB, DL, get(PPC::BCC))
Diana Picus116bbab2017-01-13 09:58:52 +0000695 .addImm(Cond[0].getImm())
696 .add(Cond[1])
697 .addMBB(TBB);
Evan Cheng99be49d2007-05-18 00:05:48 +0000698 return 1;
Chris Lattnera61f0102006-10-17 18:06:55 +0000699 }
Andrew Trickc416ba62010-12-24 04:28:06 +0000700
Chris Lattnerd8816602006-10-21 05:42:09 +0000701 // Two-way Conditional Branch.
Hal Finkel96c2d4d2012-06-08 15:38:21 +0000702 if (Cond[1].getReg() == PPC::CTR || Cond[1].getReg() == PPC::CTR8)
703 BuildMI(&MBB, DL, get(Cond[0].getImm() ?
704 (isPPC64 ? PPC::BDNZ8 : PPC::BDNZ) :
705 (isPPC64 ? PPC::BDZ8 : PPC::BDZ))).addMBB(TBB);
Hal Finkel940ab932014-02-28 00:27:01 +0000706 else if (Cond[0].getImm() == PPC::PRED_BIT_SET)
Diana Picus116bbab2017-01-13 09:58:52 +0000707 BuildMI(&MBB, DL, get(PPC::BC)).add(Cond[1]).addMBB(TBB);
Hal Finkel940ab932014-02-28 00:27:01 +0000708 else if (Cond[0].getImm() == PPC::PRED_BIT_UNSET)
Diana Picus116bbab2017-01-13 09:58:52 +0000709 BuildMI(&MBB, DL, get(PPC::BCn)).add(Cond[1]).addMBB(TBB);
Hal Finkel96c2d4d2012-06-08 15:38:21 +0000710 else
711 BuildMI(&MBB, DL, get(PPC::BCC))
Diana Picus116bbab2017-01-13 09:58:52 +0000712 .addImm(Cond[0].getImm())
713 .add(Cond[1])
714 .addMBB(TBB);
Stuart Hastings0125b642010-06-17 22:43:56 +0000715 BuildMI(&MBB, DL, get(PPC::B)).addMBB(FBB);
Evan Cheng99be49d2007-05-18 00:05:48 +0000716 return 2;
Chris Lattnera47294ed2006-10-13 21:21:17 +0000717}
718
Hal Finkeled6a2852013-04-05 23:29:01 +0000719// Select analysis.
720bool PPCInstrInfo::canInsertSelect(const MachineBasicBlock &MBB,
Ahmed Bougachac88bf542015-06-11 19:30:37 +0000721 ArrayRef<MachineOperand> Cond,
Hal Finkeled6a2852013-04-05 23:29:01 +0000722 unsigned TrueReg, unsigned FalseReg,
723 int &CondCycles, int &TrueCycles, int &FalseCycles) const {
Hal Finkeled6a2852013-04-05 23:29:01 +0000724 if (Cond.size() != 2)
725 return false;
726
727 // If this is really a bdnz-like condition, then it cannot be turned into a
728 // select.
729 if (Cond[1].getReg() == PPC::CTR || Cond[1].getReg() == PPC::CTR8)
730 return false;
731
732 // Check register classes.
733 const MachineRegisterInfo &MRI = MBB.getParent()->getRegInfo();
734 const TargetRegisterClass *RC =
735 RI.getCommonSubClass(MRI.getRegClass(TrueReg), MRI.getRegClass(FalseReg));
736 if (!RC)
737 return false;
738
739 // isel is for regular integer GPRs only.
740 if (!PPC::GPRCRegClass.hasSubClassEq(RC) &&
Hal Finkel8e8618a2013-07-15 20:22:58 +0000741 !PPC::GPRC_NOR0RegClass.hasSubClassEq(RC) &&
742 !PPC::G8RCRegClass.hasSubClassEq(RC) &&
743 !PPC::G8RC_NOX0RegClass.hasSubClassEq(RC))
Hal Finkeled6a2852013-04-05 23:29:01 +0000744 return false;
745
746 // FIXME: These numbers are for the A2, how well they work for other cores is
747 // an open question. On the A2, the isel instruction has a 2-cycle latency
748 // but single-cycle throughput. These numbers are used in combination with
749 // the MispredictPenalty setting from the active SchedMachineModel.
750 CondCycles = 1;
751 TrueCycles = 1;
752 FalseCycles = 1;
753
754 return true;
755}
756
757void PPCInstrInfo::insertSelect(MachineBasicBlock &MBB,
Benjamin Kramerbdc49562016-06-12 15:39:02 +0000758 MachineBasicBlock::iterator MI,
759 const DebugLoc &dl, unsigned DestReg,
760 ArrayRef<MachineOperand> Cond, unsigned TrueReg,
761 unsigned FalseReg) const {
Hal Finkeled6a2852013-04-05 23:29:01 +0000762 assert(Cond.size() == 2 &&
763 "PPC branch conditions have two components!");
764
Hal Finkeled6a2852013-04-05 23:29:01 +0000765 // Get the register classes.
766 MachineRegisterInfo &MRI = MBB.getParent()->getRegInfo();
767 const TargetRegisterClass *RC =
768 RI.getCommonSubClass(MRI.getRegClass(TrueReg), MRI.getRegClass(FalseReg));
769 assert(RC && "TrueReg and FalseReg must have overlapping register classes");
Hal Finkel8e8618a2013-07-15 20:22:58 +0000770
771 bool Is64Bit = PPC::G8RCRegClass.hasSubClassEq(RC) ||
772 PPC::G8RC_NOX0RegClass.hasSubClassEq(RC);
773 assert((Is64Bit ||
774 PPC::GPRCRegClass.hasSubClassEq(RC) ||
775 PPC::GPRC_NOR0RegClass.hasSubClassEq(RC)) &&
Hal Finkeled6a2852013-04-05 23:29:01 +0000776 "isel is for regular integer GPRs only");
777
Hal Finkel8e8618a2013-07-15 20:22:58 +0000778 unsigned OpCode = Is64Bit ? PPC::ISEL8 : PPC::ISEL;
Kyle Buttcec40802016-01-12 21:00:43 +0000779 auto SelectPred = static_cast<PPC::Predicate>(Cond[0].getImm());
Hal Finkeled6a2852013-04-05 23:29:01 +0000780
Kyle Butt132bf362016-01-15 19:20:06 +0000781 unsigned SubIdx = 0;
782 bool SwapOps = false;
Hal Finkeled6a2852013-04-05 23:29:01 +0000783 switch (SelectPred) {
Kyle Buttcec40802016-01-12 21:00:43 +0000784 case PPC::PRED_EQ:
785 case PPC::PRED_EQ_MINUS:
786 case PPC::PRED_EQ_PLUS:
787 SubIdx = PPC::sub_eq; SwapOps = false; break;
788 case PPC::PRED_NE:
789 case PPC::PRED_NE_MINUS:
790 case PPC::PRED_NE_PLUS:
791 SubIdx = PPC::sub_eq; SwapOps = true; break;
792 case PPC::PRED_LT:
793 case PPC::PRED_LT_MINUS:
794 case PPC::PRED_LT_PLUS:
795 SubIdx = PPC::sub_lt; SwapOps = false; break;
796 case PPC::PRED_GE:
797 case PPC::PRED_GE_MINUS:
798 case PPC::PRED_GE_PLUS:
799 SubIdx = PPC::sub_lt; SwapOps = true; break;
800 case PPC::PRED_GT:
801 case PPC::PRED_GT_MINUS:
802 case PPC::PRED_GT_PLUS:
803 SubIdx = PPC::sub_gt; SwapOps = false; break;
804 case PPC::PRED_LE:
805 case PPC::PRED_LE_MINUS:
806 case PPC::PRED_LE_PLUS:
807 SubIdx = PPC::sub_gt; SwapOps = true; break;
808 case PPC::PRED_UN:
809 case PPC::PRED_UN_MINUS:
810 case PPC::PRED_UN_PLUS:
811 SubIdx = PPC::sub_un; SwapOps = false; break;
812 case PPC::PRED_NU:
813 case PPC::PRED_NU_MINUS:
814 case PPC::PRED_NU_PLUS:
815 SubIdx = PPC::sub_un; SwapOps = true; break;
Hal Finkel940ab932014-02-28 00:27:01 +0000816 case PPC::PRED_BIT_SET: SubIdx = 0; SwapOps = false; break;
817 case PPC::PRED_BIT_UNSET: SubIdx = 0; SwapOps = true; break;
Hal Finkeled6a2852013-04-05 23:29:01 +0000818 }
819
820 unsigned FirstReg = SwapOps ? FalseReg : TrueReg,
821 SecondReg = SwapOps ? TrueReg : FalseReg;
822
823 // The first input register of isel cannot be r0. If it is a member
824 // of a register class that can be r0, then copy it first (the
825 // register allocator should eliminate the copy).
826 if (MRI.getRegClass(FirstReg)->contains(PPC::R0) ||
827 MRI.getRegClass(FirstReg)->contains(PPC::X0)) {
828 const TargetRegisterClass *FirstRC =
829 MRI.getRegClass(FirstReg)->contains(PPC::X0) ?
830 &PPC::G8RC_NOX0RegClass : &PPC::GPRC_NOR0RegClass;
831 unsigned OldFirstReg = FirstReg;
832 FirstReg = MRI.createVirtualRegister(FirstRC);
833 BuildMI(MBB, MI, dl, get(TargetOpcode::COPY), FirstReg)
834 .addReg(OldFirstReg);
835 }
836
837 BuildMI(MBB, MI, dl, get(OpCode), DestReg)
838 .addReg(FirstReg).addReg(SecondReg)
839 .addReg(Cond[1].getReg(), 0, SubIdx);
840}
841
Kit Barton535e69d2015-03-25 19:36:23 +0000842static unsigned getCRBitValue(unsigned CRBit) {
843 unsigned Ret = 4;
844 if (CRBit == PPC::CR0LT || CRBit == PPC::CR1LT ||
845 CRBit == PPC::CR2LT || CRBit == PPC::CR3LT ||
846 CRBit == PPC::CR4LT || CRBit == PPC::CR5LT ||
847 CRBit == PPC::CR6LT || CRBit == PPC::CR7LT)
848 Ret = 3;
849 if (CRBit == PPC::CR0GT || CRBit == PPC::CR1GT ||
850 CRBit == PPC::CR2GT || CRBit == PPC::CR3GT ||
851 CRBit == PPC::CR4GT || CRBit == PPC::CR5GT ||
852 CRBit == PPC::CR6GT || CRBit == PPC::CR7GT)
853 Ret = 2;
854 if (CRBit == PPC::CR0EQ || CRBit == PPC::CR1EQ ||
855 CRBit == PPC::CR2EQ || CRBit == PPC::CR3EQ ||
856 CRBit == PPC::CR4EQ || CRBit == PPC::CR5EQ ||
857 CRBit == PPC::CR6EQ || CRBit == PPC::CR7EQ)
858 Ret = 1;
859 if (CRBit == PPC::CR0UN || CRBit == PPC::CR1UN ||
860 CRBit == PPC::CR2UN || CRBit == PPC::CR3UN ||
861 CRBit == PPC::CR4UN || CRBit == PPC::CR5UN ||
862 CRBit == PPC::CR6UN || CRBit == PPC::CR7UN)
863 Ret = 0;
864
865 assert(Ret != 4 && "Invalid CR bit register");
866 return Ret;
867}
868
Jakob Stoklund Olesen0d611972010-07-11 07:31:00 +0000869void PPCInstrInfo::copyPhysReg(MachineBasicBlock &MBB,
Benjamin Kramerbdc49562016-06-12 15:39:02 +0000870 MachineBasicBlock::iterator I,
871 const DebugLoc &DL, unsigned DestReg,
872 unsigned SrcReg, bool KillSrc) const {
Hal Finkel27774d92014-03-13 07:58:58 +0000873 // We can end up with self copies and similar things as a result of VSX copy
Hal Finkel9dcb3582014-03-27 22:46:28 +0000874 // legalization. Promote them here.
Hal Finkel27774d92014-03-13 07:58:58 +0000875 const TargetRegisterInfo *TRI = &getRegisterInfo();
876 if (PPC::F8RCRegClass.contains(DestReg) &&
Hal Finkel5cedafb2015-02-16 23:46:30 +0000877 PPC::VSRCRegClass.contains(SrcReg)) {
Hal Finkel27774d92014-03-13 07:58:58 +0000878 unsigned SuperReg =
879 TRI->getMatchingSuperReg(DestReg, PPC::sub_64, &PPC::VSRCRegClass);
880
Hal Finkel9dcb3582014-03-27 22:46:28 +0000881 if (VSXSelfCopyCrash && SrcReg == SuperReg)
882 llvm_unreachable("nop VSX copy");
Hal Finkel27774d92014-03-13 07:58:58 +0000883
884 DestReg = SuperReg;
Hal Finkel27774d92014-03-13 07:58:58 +0000885 } else if (PPC::F8RCRegClass.contains(SrcReg) &&
Hal Finkel5cedafb2015-02-16 23:46:30 +0000886 PPC::VSRCRegClass.contains(DestReg)) {
Hal Finkel27774d92014-03-13 07:58:58 +0000887 unsigned SuperReg =
888 TRI->getMatchingSuperReg(SrcReg, PPC::sub_64, &PPC::VSRCRegClass);
889
Hal Finkel9dcb3582014-03-27 22:46:28 +0000890 if (VSXSelfCopyCrash && DestReg == SuperReg)
891 llvm_unreachable("nop VSX copy");
Hal Finkel27774d92014-03-13 07:58:58 +0000892
893 SrcReg = SuperReg;
Hal Finkel27774d92014-03-13 07:58:58 +0000894 }
895
Kit Barton535e69d2015-03-25 19:36:23 +0000896 // Different class register copy
897 if (PPC::CRBITRCRegClass.contains(SrcReg) &&
898 PPC::GPRCRegClass.contains(DestReg)) {
899 unsigned CRReg = getCRFromCRBit(SrcReg);
Richard Trieu7a083812016-02-18 22:09:30 +0000900 BuildMI(MBB, I, DL, get(PPC::MFOCRF), DestReg).addReg(CRReg);
901 getKillRegState(KillSrc);
Kit Barton535e69d2015-03-25 19:36:23 +0000902 // Rotate the CR bit in the CR fields to be the least significant bit and
903 // then mask with 0x1 (MB = ME = 31).
904 BuildMI(MBB, I, DL, get(PPC::RLWINM), DestReg)
905 .addReg(DestReg, RegState::Kill)
906 .addImm(TRI->getEncodingValue(CRReg) * 4 + (4 - getCRBitValue(SrcReg)))
907 .addImm(31)
908 .addImm(31);
909 return;
910 } else if (PPC::CRRCRegClass.contains(SrcReg) &&
911 PPC::G8RCRegClass.contains(DestReg)) {
Richard Trieu7a083812016-02-18 22:09:30 +0000912 BuildMI(MBB, I, DL, get(PPC::MFOCRF8), DestReg).addReg(SrcReg);
913 getKillRegState(KillSrc);
Kit Barton535e69d2015-03-25 19:36:23 +0000914 return;
915 } else if (PPC::CRRCRegClass.contains(SrcReg) &&
916 PPC::GPRCRegClass.contains(DestReg)) {
Richard Trieu7a083812016-02-18 22:09:30 +0000917 BuildMI(MBB, I, DL, get(PPC::MFOCRF), DestReg).addReg(SrcReg);
918 getKillRegState(KillSrc);
Kit Barton535e69d2015-03-25 19:36:23 +0000919 return;
920 }
921
Jakob Stoklund Olesen0d611972010-07-11 07:31:00 +0000922 unsigned Opc;
923 if (PPC::GPRCRegClass.contains(DestReg, SrcReg))
924 Opc = PPC::OR;
925 else if (PPC::G8RCRegClass.contains(DestReg, SrcReg))
926 Opc = PPC::OR8;
927 else if (PPC::F4RCRegClass.contains(DestReg, SrcReg))
928 Opc = PPC::FMR;
929 else if (PPC::CRRCRegClass.contains(DestReg, SrcReg))
930 Opc = PPC::MCRF;
931 else if (PPC::VRRCRegClass.contains(DestReg, SrcReg))
932 Opc = PPC::VOR;
Hal Finkel27774d92014-03-13 07:58:58 +0000933 else if (PPC::VSRCRegClass.contains(DestReg, SrcReg))
Hal Finkelbbad2332014-03-24 09:36:36 +0000934 // There are two different ways this can be done:
Hal Finkel27774d92014-03-13 07:58:58 +0000935 // 1. xxlor : This has lower latency (on the P7), 2 cycles, but can only
936 // issue in VSU pipeline 0.
937 // 2. xmovdp/xmovsp: This has higher latency (on the P7), 6 cycles, but
938 // can go to either pipeline.
Hal Finkelbbad2332014-03-24 09:36:36 +0000939 // We'll always use xxlor here, because in practically all cases where
940 // copies are generated, they are close enough to some use that the
941 // lower-latency form is preferable.
Hal Finkel27774d92014-03-13 07:58:58 +0000942 Opc = PPC::XXLOR;
Nemanja Ivanovicf3c94b12015-05-07 18:24:05 +0000943 else if (PPC::VSFRCRegClass.contains(DestReg, SrcReg) ||
944 PPC::VSSRCRegClass.contains(DestReg, SrcReg))
Hal Finkel19be5062014-03-29 05:29:01 +0000945 Opc = PPC::XXLORf;
Hal Finkelc93a9a22015-02-25 01:06:45 +0000946 else if (PPC::QFRCRegClass.contains(DestReg, SrcReg))
947 Opc = PPC::QVFMR;
948 else if (PPC::QSRCRegClass.contains(DestReg, SrcReg))
949 Opc = PPC::QVFMRs;
950 else if (PPC::QBRCRegClass.contains(DestReg, SrcReg))
951 Opc = PPC::QVFMRb;
Jakob Stoklund Olesen0d611972010-07-11 07:31:00 +0000952 else if (PPC::CRBITRCRegClass.contains(DestReg, SrcReg))
953 Opc = PPC::CROR;
954 else
955 llvm_unreachable("Impossible reg-to-reg copy");
Owen Anderson7a73ae92007-12-31 06:32:00 +0000956
Evan Cheng6cc775f2011-06-28 19:10:37 +0000957 const MCInstrDesc &MCID = get(Opc);
958 if (MCID.getNumOperands() == 3)
959 BuildMI(MBB, I, DL, MCID, DestReg)
Jakob Stoklund Olesen0d611972010-07-11 07:31:00 +0000960 .addReg(SrcReg).addReg(SrcReg, getKillRegState(KillSrc));
961 else
Evan Cheng6cc775f2011-06-28 19:10:37 +0000962 BuildMI(MBB, I, DL, MCID, DestReg).addReg(SrcReg, getKillRegState(KillSrc));
Owen Anderson7a73ae92007-12-31 06:32:00 +0000963}
964
Hal Finkel8f6834d2011-12-05 17:55:17 +0000965// This function returns true if a CR spill is necessary and false otherwise.
Bill Wendlingc6c48fc2008-03-10 22:49:16 +0000966bool
Dan Gohman3b460302008-07-07 23:14:23 +0000967PPCInstrInfo::StoreRegToStackSlot(MachineFunction &MF,
968 unsigned SrcReg, bool isKill,
Bill Wendlingc6c48fc2008-03-10 22:49:16 +0000969 int FrameIdx,
970 const TargetRegisterClass *RC,
Hal Finkelfcc51d42013-03-17 04:43:44 +0000971 SmallVectorImpl<MachineInstr*> &NewMIs,
Hal Finkelcc1eeda2013-03-23 22:06:03 +0000972 bool &NonRI, bool &SpillsVRS) const{
Hal Finkel37714b82013-03-27 21:21:15 +0000973 // Note: If additional store instructions are added here,
974 // update isStoreToStackSlot.
975
Chris Lattner6f306d72010-04-02 20:16:16 +0000976 DebugLoc DL;
Hal Finkel4e703bc2014-01-28 05:32:58 +0000977 if (PPC::GPRCRegClass.hasSubClassEq(RC) ||
978 PPC::GPRC_NOR0RegClass.hasSubClassEq(RC)) {
Hal Finkel794e05b2013-03-23 17:14:27 +0000979 NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(PPC::STW))
980 .addReg(SrcReg,
981 getKillRegState(isKill)),
982 FrameIdx));
Hal Finkel4e703bc2014-01-28 05:32:58 +0000983 } else if (PPC::G8RCRegClass.hasSubClassEq(RC) ||
984 PPC::G8RC_NOX0RegClass.hasSubClassEq(RC)) {
Hal Finkel794e05b2013-03-23 17:14:27 +0000985 NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(PPC::STD))
986 .addReg(SrcReg,
987 getKillRegState(isKill)),
988 FrameIdx));
Craig Topperabadc662012-04-20 06:31:50 +0000989 } else if (PPC::F8RCRegClass.hasSubClassEq(RC)) {
Dale Johannesen6b8c76a2009-02-12 23:08:38 +0000990 NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(PPC::STFD))
Bill Wendlingf7b83c72009-05-13 21:33:08 +0000991 .addReg(SrcReg,
992 getKillRegState(isKill)),
993 FrameIdx));
Craig Topperabadc662012-04-20 06:31:50 +0000994 } else if (PPC::F4RCRegClass.hasSubClassEq(RC)) {
Dale Johannesen6b8c76a2009-02-12 23:08:38 +0000995 NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(PPC::STFS))
Bill Wendlingf7b83c72009-05-13 21:33:08 +0000996 .addReg(SrcReg,
997 getKillRegState(isKill)),
998 FrameIdx));
Craig Topperabadc662012-04-20 06:31:50 +0000999 } else if (PPC::CRRCRegClass.hasSubClassEq(RC)) {
Hal Finkele154c8f2013-03-12 14:12:16 +00001000 NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(PPC::SPILL_CR))
1001 .addReg(SrcReg,
1002 getKillRegState(isKill)),
1003 FrameIdx));
1004 return true;
Craig Topperabadc662012-04-20 06:31:50 +00001005 } else if (PPC::CRBITRCRegClass.hasSubClassEq(RC)) {
Hal Finkel940ab932014-02-28 00:27:01 +00001006 NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(PPC::SPILL_CRBIT))
1007 .addReg(SrcReg,
1008 getKillRegState(isKill)),
1009 FrameIdx));
1010 return true;
Craig Topperabadc662012-04-20 06:31:50 +00001011 } else if (PPC::VRRCRegClass.hasSubClassEq(RC)) {
Hal Finkelfcc51d42013-03-17 04:43:44 +00001012 NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(PPC::STVX))
1013 .addReg(SrcReg,
1014 getKillRegState(isKill)),
1015 FrameIdx));
1016 NonRI = true;
Hal Finkel27774d92014-03-13 07:58:58 +00001017 } else if (PPC::VSRCRegClass.hasSubClassEq(RC)) {
Nemanja Ivanovic6e7879c2016-09-22 09:52:19 +00001018 unsigned Op = Subtarget.hasP9Vector() ? PPC::STXVX : PPC::STXVD2X;
1019 NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(Op))
Hal Finkel27774d92014-03-13 07:58:58 +00001020 .addReg(SrcReg,
1021 getKillRegState(isKill)),
1022 FrameIdx));
1023 NonRI = true;
Hal Finkel19be5062014-03-29 05:29:01 +00001024 } else if (PPC::VSFRCRegClass.hasSubClassEq(RC)) {
Nemanja Ivanovic6354d232016-10-04 11:25:52 +00001025 unsigned Opc = Subtarget.hasP9Vector() ? PPC::DFSTOREf64 : PPC::STXSDX;
1026 NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(Opc))
Hal Finkel19be5062014-03-29 05:29:01 +00001027 .addReg(SrcReg,
1028 getKillRegState(isKill)),
1029 FrameIdx));
1030 NonRI = true;
Nemanja Ivanovicf3c94b12015-05-07 18:24:05 +00001031 } else if (PPC::VSSRCRegClass.hasSubClassEq(RC)) {
Nemanja Ivanovic6354d232016-10-04 11:25:52 +00001032 unsigned Opc = Subtarget.hasP9Vector() ? PPC::DFSTOREf32 : PPC::STXSSPX;
1033 NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(Opc))
Nemanja Ivanovicf3c94b12015-05-07 18:24:05 +00001034 .addReg(SrcReg,
1035 getKillRegState(isKill)),
1036 FrameIdx));
1037 NonRI = true;
Hal Finkela1431df2013-03-21 19:03:21 +00001038 } else if (PPC::VRSAVERCRegClass.hasSubClassEq(RC)) {
Eric Christopher1dcea732014-06-12 21:48:52 +00001039 assert(Subtarget.isDarwin() &&
Hal Finkela7b06302013-03-27 00:02:20 +00001040 "VRSAVE only needs spill/restore on Darwin");
Hal Finkela1431df2013-03-21 19:03:21 +00001041 NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(PPC::SPILL_VRSAVE))
1042 .addReg(SrcReg,
1043 getKillRegState(isKill)),
1044 FrameIdx));
Hal Finkelcc1eeda2013-03-23 22:06:03 +00001045 SpillsVRS = true;
Hal Finkelc93a9a22015-02-25 01:06:45 +00001046 } else if (PPC::QFRCRegClass.hasSubClassEq(RC)) {
1047 NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(PPC::QVSTFDX))
1048 .addReg(SrcReg,
1049 getKillRegState(isKill)),
1050 FrameIdx));
1051 NonRI = true;
1052 } else if (PPC::QSRCRegClass.hasSubClassEq(RC)) {
1053 NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(PPC::QVSTFSXs))
1054 .addReg(SrcReg,
1055 getKillRegState(isKill)),
1056 FrameIdx));
1057 NonRI = true;
1058 } else if (PPC::QBRCRegClass.hasSubClassEq(RC)) {
1059 NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(PPC::QVSTFDXb))
1060 .addReg(SrcReg,
1061 getKillRegState(isKill)),
1062 FrameIdx));
1063 NonRI = true;
Owen Andersoneee14602008-01-01 21:11:32 +00001064 } else {
Torok Edwinfbcc6632009-07-14 16:55:14 +00001065 llvm_unreachable("Unknown regclass!");
Owen Andersoneee14602008-01-01 21:11:32 +00001066 }
Bill Wendling632ea652008-03-03 22:19:16 +00001067
1068 return false;
Owen Andersoneee14602008-01-01 21:11:32 +00001069}
1070
1071void
1072PPCInstrInfo::storeRegToStackSlot(MachineBasicBlock &MBB,
Bill Wendling632ea652008-03-03 22:19:16 +00001073 MachineBasicBlock::iterator MI,
1074 unsigned SrcReg, bool isKill, int FrameIdx,
Evan Chengefb126a2010-05-06 19:06:44 +00001075 const TargetRegisterClass *RC,
1076 const TargetRegisterInfo *TRI) const {
Dan Gohman3b460302008-07-07 23:14:23 +00001077 MachineFunction &MF = *MBB.getParent();
Owen Andersoneee14602008-01-01 21:11:32 +00001078 SmallVector<MachineInstr*, 4> NewMIs;
Bill Wendling632ea652008-03-03 22:19:16 +00001079
Hal Finkelbb420f12013-03-15 05:06:04 +00001080 PPCFunctionInfo *FuncInfo = MF.getInfo<PPCFunctionInfo>();
1081 FuncInfo->setHasSpills();
1082
Nemanja Ivanovic11049f82016-10-04 06:59:23 +00001083 // We need to avoid a situation in which the value from a VRRC register is
1084 // spilled using an Altivec instruction and reloaded into a VSRC register
1085 // using a VSX instruction. The issue with this is that the VSX
1086 // load/store instructions swap the doublewords in the vector and the Altivec
1087 // ones don't. The register classes on the spill/reload may be different if
1088 // the register is defined using an Altivec instruction and is then used by a
1089 // VSX instruction.
1090 RC = updatedRC(RC);
1091
Hal Finkelcc1eeda2013-03-23 22:06:03 +00001092 bool NonRI = false, SpillsVRS = false;
1093 if (StoreRegToStackSlot(MF, SrcReg, isKill, FrameIdx, RC, NewMIs,
1094 NonRI, SpillsVRS))
Bill Wendling632ea652008-03-03 22:19:16 +00001095 FuncInfo->setSpillsCR();
Bill Wendling632ea652008-03-03 22:19:16 +00001096
Hal Finkelcc1eeda2013-03-23 22:06:03 +00001097 if (SpillsVRS)
1098 FuncInfo->setSpillsVRSAVE();
1099
Hal Finkelfcc51d42013-03-17 04:43:44 +00001100 if (NonRI)
1101 FuncInfo->setHasNonRISpills();
1102
Owen Andersoneee14602008-01-01 21:11:32 +00001103 for (unsigned i = 0, e = NewMIs.size(); i != e; ++i)
1104 MBB.insert(MI, NewMIs[i]);
Jakob Stoklund Olesen6353e532010-07-16 18:22:00 +00001105
Matthias Braun941a7052016-07-28 18:40:00 +00001106 const MachineFrameInfo &MFI = MF.getFrameInfo();
Alex Lorenze40c8a22015-08-11 23:09:45 +00001107 MachineMemOperand *MMO = MF.getMachineMemOperand(
1108 MachinePointerInfo::getFixedStack(MF, FrameIdx),
1109 MachineMemOperand::MOStore, MFI.getObjectSize(FrameIdx),
1110 MFI.getObjectAlignment(FrameIdx));
Jakob Stoklund Olesen6353e532010-07-16 18:22:00 +00001111 NewMIs.back()->addMemOperand(MF, MMO);
Owen Andersoneee14602008-01-01 21:11:32 +00001112}
1113
Benjamin Kramerbdc49562016-06-12 15:39:02 +00001114bool PPCInstrInfo::LoadRegFromStackSlot(MachineFunction &MF, const DebugLoc &DL,
1115 unsigned DestReg, int FrameIdx,
1116 const TargetRegisterClass *RC,
1117 SmallVectorImpl<MachineInstr *> &NewMIs,
1118 bool &NonRI, bool &SpillsVRS) const {
Hal Finkel37714b82013-03-27 21:21:15 +00001119 // Note: If additional load instructions are added here,
1120 // update isLoadFromStackSlot.
1121
Hal Finkel4e703bc2014-01-28 05:32:58 +00001122 if (PPC::GPRCRegClass.hasSubClassEq(RC) ||
1123 PPC::GPRC_NOR0RegClass.hasSubClassEq(RC)) {
Hal Finkel5791f512013-03-27 19:10:40 +00001124 NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(PPC::LWZ),
1125 DestReg), FrameIdx));
Hal Finkel4e703bc2014-01-28 05:32:58 +00001126 } else if (PPC::G8RCRegClass.hasSubClassEq(RC) ||
1127 PPC::G8RC_NOX0RegClass.hasSubClassEq(RC)) {
Hal Finkel5791f512013-03-27 19:10:40 +00001128 NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(PPC::LD), DestReg),
1129 FrameIdx));
Craig Topperabadc662012-04-20 06:31:50 +00001130 } else if (PPC::F8RCRegClass.hasSubClassEq(RC)) {
Bill Wendlingf6d609a2009-02-12 00:02:55 +00001131 NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(PPC::LFD), DestReg),
Owen Andersoneee14602008-01-01 21:11:32 +00001132 FrameIdx));
Craig Topperabadc662012-04-20 06:31:50 +00001133 } else if (PPC::F4RCRegClass.hasSubClassEq(RC)) {
Bill Wendlingf6d609a2009-02-12 00:02:55 +00001134 NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(PPC::LFS), DestReg),
Owen Andersoneee14602008-01-01 21:11:32 +00001135 FrameIdx));
Craig Topperabadc662012-04-20 06:31:50 +00001136 } else if (PPC::CRRCRegClass.hasSubClassEq(RC)) {
Hal Finkele154c8f2013-03-12 14:12:16 +00001137 NewMIs.push_back(addFrameReference(BuildMI(MF, DL,
1138 get(PPC::RESTORE_CR), DestReg),
1139 FrameIdx));
1140 return true;
Craig Topperabadc662012-04-20 06:31:50 +00001141 } else if (PPC::CRBITRCRegClass.hasSubClassEq(RC)) {
Hal Finkel940ab932014-02-28 00:27:01 +00001142 NewMIs.push_back(addFrameReference(BuildMI(MF, DL,
1143 get(PPC::RESTORE_CRBIT), DestReg),
1144 FrameIdx));
1145 return true;
Craig Topperabadc662012-04-20 06:31:50 +00001146 } else if (PPC::VRRCRegClass.hasSubClassEq(RC)) {
Hal Finkelfcc51d42013-03-17 04:43:44 +00001147 NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(PPC::LVX), DestReg),
1148 FrameIdx));
1149 NonRI = true;
Hal Finkel27774d92014-03-13 07:58:58 +00001150 } else if (PPC::VSRCRegClass.hasSubClassEq(RC)) {
Nemanja Ivanovic6e7879c2016-09-22 09:52:19 +00001151 unsigned Op = Subtarget.hasP9Vector() ? PPC::LXVX : PPC::LXVD2X;
1152 NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(Op), DestReg),
Hal Finkel27774d92014-03-13 07:58:58 +00001153 FrameIdx));
1154 NonRI = true;
Hal Finkel19be5062014-03-29 05:29:01 +00001155 } else if (PPC::VSFRCRegClass.hasSubClassEq(RC)) {
Nemanja Ivanovic6354d232016-10-04 11:25:52 +00001156 unsigned Opc = Subtarget.hasP9Vector() ? PPC::DFLOADf64 : PPC::LXSDX;
1157 NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(Opc),
1158 DestReg), FrameIdx));
Hal Finkel19be5062014-03-29 05:29:01 +00001159 NonRI = true;
Nemanja Ivanovicf3c94b12015-05-07 18:24:05 +00001160 } else if (PPC::VSSRCRegClass.hasSubClassEq(RC)) {
Nemanja Ivanovic6354d232016-10-04 11:25:52 +00001161 unsigned Opc = Subtarget.hasP9Vector() ? PPC::DFLOADf32 : PPC::LXSSPX;
1162 NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(Opc),
1163 DestReg), FrameIdx));
Nemanja Ivanovicf3c94b12015-05-07 18:24:05 +00001164 NonRI = true;
Hal Finkela1431df2013-03-21 19:03:21 +00001165 } else if (PPC::VRSAVERCRegClass.hasSubClassEq(RC)) {
Eric Christopher1dcea732014-06-12 21:48:52 +00001166 assert(Subtarget.isDarwin() &&
Hal Finkela7b06302013-03-27 00:02:20 +00001167 "VRSAVE only needs spill/restore on Darwin");
Hal Finkela1431df2013-03-21 19:03:21 +00001168 NewMIs.push_back(addFrameReference(BuildMI(MF, DL,
1169 get(PPC::RESTORE_VRSAVE),
1170 DestReg),
1171 FrameIdx));
Hal Finkelcc1eeda2013-03-23 22:06:03 +00001172 SpillsVRS = true;
Hal Finkelc93a9a22015-02-25 01:06:45 +00001173 } else if (PPC::QFRCRegClass.hasSubClassEq(RC)) {
1174 NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(PPC::QVLFDX), DestReg),
1175 FrameIdx));
1176 NonRI = true;
1177 } else if (PPC::QSRCRegClass.hasSubClassEq(RC)) {
1178 NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(PPC::QVLFSXs), DestReg),
1179 FrameIdx));
1180 NonRI = true;
1181 } else if (PPC::QBRCRegClass.hasSubClassEq(RC)) {
1182 NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(PPC::QVLFDXb), DestReg),
1183 FrameIdx));
1184 NonRI = true;
Owen Andersoneee14602008-01-01 21:11:32 +00001185 } else {
Torok Edwinfbcc6632009-07-14 16:55:14 +00001186 llvm_unreachable("Unknown regclass!");
Owen Andersoneee14602008-01-01 21:11:32 +00001187 }
Hal Finkelbde7f8f2011-12-06 20:55:36 +00001188
1189 return false;
Owen Andersoneee14602008-01-01 21:11:32 +00001190}
1191
1192void
1193PPCInstrInfo::loadRegFromStackSlot(MachineBasicBlock &MBB,
Bill Wendling632ea652008-03-03 22:19:16 +00001194 MachineBasicBlock::iterator MI,
1195 unsigned DestReg, int FrameIdx,
Evan Chengefb126a2010-05-06 19:06:44 +00001196 const TargetRegisterClass *RC,
1197 const TargetRegisterInfo *TRI) const {
Dan Gohman3b460302008-07-07 23:14:23 +00001198 MachineFunction &MF = *MBB.getParent();
Owen Andersoneee14602008-01-01 21:11:32 +00001199 SmallVector<MachineInstr*, 4> NewMIs;
Chris Lattner6f306d72010-04-02 20:16:16 +00001200 DebugLoc DL;
Bill Wendlingf6d609a2009-02-12 00:02:55 +00001201 if (MI != MBB.end()) DL = MI->getDebugLoc();
Hal Finkelfcc51d42013-03-17 04:43:44 +00001202
1203 PPCFunctionInfo *FuncInfo = MF.getInfo<PPCFunctionInfo>();
1204 FuncInfo->setHasSpills();
1205
Nemanja Ivanovic11049f82016-10-04 06:59:23 +00001206 // We need to avoid a situation in which the value from a VRRC register is
1207 // spilled using an Altivec instruction and reloaded into a VSRC register
1208 // using a VSX instruction. The issue with this is that the VSX
1209 // load/store instructions swap the doublewords in the vector and the Altivec
1210 // ones don't. The register classes on the spill/reload may be different if
1211 // the register is defined using an Altivec instruction and is then used by a
1212 // VSX instruction.
1213 if (Subtarget.hasVSX() && RC == &PPC::VRRCRegClass)
1214 RC = &PPC::VSRCRegClass;
1215
Hal Finkelcc1eeda2013-03-23 22:06:03 +00001216 bool NonRI = false, SpillsVRS = false;
1217 if (LoadRegFromStackSlot(MF, DL, DestReg, FrameIdx, RC, NewMIs,
1218 NonRI, SpillsVRS))
Hal Finkelbde7f8f2011-12-06 20:55:36 +00001219 FuncInfo->setSpillsCR();
Hal Finkelfcc51d42013-03-17 04:43:44 +00001220
Hal Finkelcc1eeda2013-03-23 22:06:03 +00001221 if (SpillsVRS)
1222 FuncInfo->setSpillsVRSAVE();
1223
Hal Finkelfcc51d42013-03-17 04:43:44 +00001224 if (NonRI)
1225 FuncInfo->setHasNonRISpills();
1226
Owen Andersoneee14602008-01-01 21:11:32 +00001227 for (unsigned i = 0, e = NewMIs.size(); i != e; ++i)
1228 MBB.insert(MI, NewMIs[i]);
Jakob Stoklund Olesen6353e532010-07-16 18:22:00 +00001229
Matthias Braun941a7052016-07-28 18:40:00 +00001230 const MachineFrameInfo &MFI = MF.getFrameInfo();
Alex Lorenze40c8a22015-08-11 23:09:45 +00001231 MachineMemOperand *MMO = MF.getMachineMemOperand(
1232 MachinePointerInfo::getFixedStack(MF, FrameIdx),
1233 MachineMemOperand::MOLoad, MFI.getObjectSize(FrameIdx),
1234 MFI.getObjectAlignment(FrameIdx));
Jakob Stoklund Olesen6353e532010-07-16 18:22:00 +00001235 NewMIs.back()->addMemOperand(MF, MMO);
Owen Andersoneee14602008-01-01 21:11:32 +00001236}
1237
Chris Lattnera47294ed2006-10-13 21:21:17 +00001238bool PPCInstrInfo::
Matt Arsenault1b9fc8e2016-09-14 20:43:16 +00001239reverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const {
Chris Lattner23f22de2006-10-21 06:03:11 +00001240 assert(Cond.size() == 2 && "Invalid PPC branch opcode!");
Hal Finkel96c2d4d2012-06-08 15:38:21 +00001241 if (Cond[1].getReg() == PPC::CTR8 || Cond[1].getReg() == PPC::CTR)
1242 Cond[0].setImm(Cond[0].getImm() == 0 ? 1 : 0);
1243 else
1244 // Leave the CR# the same, but invert the condition.
1245 Cond[0].setImm(PPC::InvertPredicate((PPC::Predicate)Cond[0].getImm()));
Chris Lattner23f22de2006-10-21 06:03:11 +00001246 return false;
Chris Lattnera47294ed2006-10-13 21:21:17 +00001247}
Nicolas Geoffrayae84bbd2008-04-16 20:10:13 +00001248
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +00001249bool PPCInstrInfo::FoldImmediate(MachineInstr &UseMI, MachineInstr &DefMI,
1250 unsigned Reg, MachineRegisterInfo *MRI) const {
Hal Finkeld61d4f82013-04-06 19:30:30 +00001251 // For some instructions, it is legal to fold ZERO into the RA register field.
1252 // A zero immediate should always be loaded with a single li.
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +00001253 unsigned DefOpc = DefMI.getOpcode();
Hal Finkeld61d4f82013-04-06 19:30:30 +00001254 if (DefOpc != PPC::LI && DefOpc != PPC::LI8)
1255 return false;
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +00001256 if (!DefMI.getOperand(1).isImm())
Hal Finkeld61d4f82013-04-06 19:30:30 +00001257 return false;
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +00001258 if (DefMI.getOperand(1).getImm() != 0)
Hal Finkeld61d4f82013-04-06 19:30:30 +00001259 return false;
1260
1261 // Note that we cannot here invert the arguments of an isel in order to fold
1262 // a ZERO into what is presented as the second argument. All we have here
1263 // is the condition bit, and that might come from a CR-logical bit operation.
1264
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +00001265 const MCInstrDesc &UseMCID = UseMI.getDesc();
Hal Finkeld61d4f82013-04-06 19:30:30 +00001266
1267 // Only fold into real machine instructions.
1268 if (UseMCID.isPseudo())
1269 return false;
1270
1271 unsigned UseIdx;
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +00001272 for (UseIdx = 0; UseIdx < UseMI.getNumOperands(); ++UseIdx)
1273 if (UseMI.getOperand(UseIdx).isReg() &&
1274 UseMI.getOperand(UseIdx).getReg() == Reg)
Hal Finkeld61d4f82013-04-06 19:30:30 +00001275 break;
1276
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +00001277 assert(UseIdx < UseMI.getNumOperands() && "Cannot find Reg in UseMI");
Hal Finkeld61d4f82013-04-06 19:30:30 +00001278 assert(UseIdx < UseMCID.getNumOperands() && "No operand description for Reg");
1279
1280 const MCOperandInfo *UseInfo = &UseMCID.OpInfo[UseIdx];
1281
1282 // We can fold the zero if this register requires a GPRC_NOR0/G8RC_NOX0
1283 // register (which might also be specified as a pointer class kind).
1284 if (UseInfo->isLookupPtrRegClass()) {
1285 if (UseInfo->RegClass /* Kind */ != 1)
1286 return false;
1287 } else {
1288 if (UseInfo->RegClass != PPC::GPRC_NOR0RegClassID &&
1289 UseInfo->RegClass != PPC::G8RC_NOX0RegClassID)
1290 return false;
1291 }
1292
1293 // Make sure this is not tied to an output register (or otherwise
1294 // constrained). This is true for ST?UX registers, for example, which
1295 // are tied to their output registers.
1296 if (UseInfo->Constraints != 0)
1297 return false;
1298
1299 unsigned ZeroReg;
1300 if (UseInfo->isLookupPtrRegClass()) {
Eric Christopher1dcea732014-06-12 21:48:52 +00001301 bool isPPC64 = Subtarget.isPPC64();
Hal Finkeld61d4f82013-04-06 19:30:30 +00001302 ZeroReg = isPPC64 ? PPC::ZERO8 : PPC::ZERO;
1303 } else {
1304 ZeroReg = UseInfo->RegClass == PPC::G8RC_NOX0RegClassID ?
1305 PPC::ZERO8 : PPC::ZERO;
1306 }
1307
1308 bool DeleteDef = MRI->hasOneNonDBGUse(Reg);
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +00001309 UseMI.getOperand(UseIdx).setReg(ZeroReg);
Hal Finkeld61d4f82013-04-06 19:30:30 +00001310
1311 if (DeleteDef)
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +00001312 DefMI.eraseFromParent();
Hal Finkeld61d4f82013-04-06 19:30:30 +00001313
1314 return true;
1315}
1316
Hal Finkel30ae2292013-04-10 18:30:16 +00001317static bool MBBDefinesCTR(MachineBasicBlock &MBB) {
1318 for (MachineBasicBlock::iterator I = MBB.begin(), IE = MBB.end();
1319 I != IE; ++I)
1320 if (I->definesRegister(PPC::CTR) || I->definesRegister(PPC::CTR8))
1321 return true;
1322 return false;
1323}
1324
1325// We should make sure that, if we're going to predicate both sides of a
1326// condition (a diamond), that both sides don't define the counter register. We
1327// can predicate counter-decrement-based branches, but while that predicates
1328// the branching, it does not predicate the counter decrement. If we tried to
1329// merge the triangle into one predicated block, we'd decrement the counter
1330// twice.
1331bool PPCInstrInfo::isProfitableToIfCvt(MachineBasicBlock &TMBB,
1332 unsigned NumT, unsigned ExtraT,
1333 MachineBasicBlock &FMBB,
1334 unsigned NumF, unsigned ExtraF,
Cong Houc536bd92015-09-10 23:10:42 +00001335 BranchProbability Probability) const {
Hal Finkel30ae2292013-04-10 18:30:16 +00001336 return !(MBBDefinesCTR(TMBB) && MBBDefinesCTR(FMBB));
1337}
1338
1339
Duncan P. N. Exon Smith6307eb52016-02-23 02:46:52 +00001340bool PPCInstrInfo::isPredicated(const MachineInstr &MI) const {
Hal Finkelf29285a2013-04-11 01:23:34 +00001341 // The predicated branches are identified by their type, not really by the
1342 // explicit presence of a predicate. Furthermore, some of them can be
1343 // predicated more than once. Because if conversion won't try to predicate
1344 // any instruction which already claims to be predicated (by returning true
1345 // here), always return false. In doing so, we let isPredicable() be the
1346 // final word on whether not the instruction can be (further) predicated.
1347
1348 return false;
Hal Finkel5711eca2013-04-09 22:58:37 +00001349}
1350
Duncan P. N. Exon Smith6307eb52016-02-23 02:46:52 +00001351bool PPCInstrInfo::isUnpredicatedTerminator(const MachineInstr &MI) const {
1352 if (!MI.isTerminator())
Hal Finkel5711eca2013-04-09 22:58:37 +00001353 return false;
1354
1355 // Conditional branch is a special case.
Duncan P. N. Exon Smith6307eb52016-02-23 02:46:52 +00001356 if (MI.isBranch() && !MI.isBarrier())
Hal Finkel5711eca2013-04-09 22:58:37 +00001357 return true;
1358
1359 return !isPredicated(MI);
1360}
1361
Duncan P. N. Exon Smith6307eb52016-02-23 02:46:52 +00001362bool PPCInstrInfo::PredicateInstruction(MachineInstr &MI,
Ahmed Bougachac88bf542015-06-11 19:30:37 +00001363 ArrayRef<MachineOperand> Pred) const {
Duncan P. N. Exon Smith6307eb52016-02-23 02:46:52 +00001364 unsigned OpC = MI.getOpcode();
Hal Finkelf4a22c02015-01-13 17:47:54 +00001365 if (OpC == PPC::BLR || OpC == PPC::BLR8) {
Hal Finkel5711eca2013-04-09 22:58:37 +00001366 if (Pred[1].getReg() == PPC::CTR8 || Pred[1].getReg() == PPC::CTR) {
Eric Christopher1dcea732014-06-12 21:48:52 +00001367 bool isPPC64 = Subtarget.isPPC64();
Duncan P. N. Exon Smith6307eb52016-02-23 02:46:52 +00001368 MI.setDesc(get(Pred[0].getImm() ? (isPPC64 ? PPC::BDNZLR8 : PPC::BDNZLR)
1369 : (isPPC64 ? PPC::BDZLR8 : PPC::BDZLR)));
Hal Finkel940ab932014-02-28 00:27:01 +00001370 } else if (Pred[0].getImm() == PPC::PRED_BIT_SET) {
Duncan P. N. Exon Smith6307eb52016-02-23 02:46:52 +00001371 MI.setDesc(get(PPC::BCLR));
1372 MachineInstrBuilder(*MI.getParent()->getParent(), MI)
1373 .addReg(Pred[1].getReg());
Hal Finkel940ab932014-02-28 00:27:01 +00001374 } else if (Pred[0].getImm() == PPC::PRED_BIT_UNSET) {
Duncan P. N. Exon Smith6307eb52016-02-23 02:46:52 +00001375 MI.setDesc(get(PPC::BCLRn));
1376 MachineInstrBuilder(*MI.getParent()->getParent(), MI)
1377 .addReg(Pred[1].getReg());
Hal Finkel940ab932014-02-28 00:27:01 +00001378 } else {
Duncan P. N. Exon Smith6307eb52016-02-23 02:46:52 +00001379 MI.setDesc(get(PPC::BCCLR));
1380 MachineInstrBuilder(*MI.getParent()->getParent(), MI)
1381 .addImm(Pred[0].getImm())
1382 .addReg(Pred[1].getReg());
Hal Finkel5711eca2013-04-09 22:58:37 +00001383 }
1384
1385 return true;
1386 } else if (OpC == PPC::B) {
1387 if (Pred[1].getReg() == PPC::CTR8 || Pred[1].getReg() == PPC::CTR) {
Eric Christopher1dcea732014-06-12 21:48:52 +00001388 bool isPPC64 = Subtarget.isPPC64();
Duncan P. N. Exon Smith6307eb52016-02-23 02:46:52 +00001389 MI.setDesc(get(Pred[0].getImm() ? (isPPC64 ? PPC::BDNZ8 : PPC::BDNZ)
1390 : (isPPC64 ? PPC::BDZ8 : PPC::BDZ)));
Hal Finkel940ab932014-02-28 00:27:01 +00001391 } else if (Pred[0].getImm() == PPC::PRED_BIT_SET) {
Duncan P. N. Exon Smith6307eb52016-02-23 02:46:52 +00001392 MachineBasicBlock *MBB = MI.getOperand(0).getMBB();
1393 MI.RemoveOperand(0);
Hal Finkel940ab932014-02-28 00:27:01 +00001394
Duncan P. N. Exon Smith6307eb52016-02-23 02:46:52 +00001395 MI.setDesc(get(PPC::BC));
1396 MachineInstrBuilder(*MI.getParent()->getParent(), MI)
1397 .addReg(Pred[1].getReg())
1398 .addMBB(MBB);
Hal Finkel940ab932014-02-28 00:27:01 +00001399 } else if (Pred[0].getImm() == PPC::PRED_BIT_UNSET) {
Duncan P. N. Exon Smith6307eb52016-02-23 02:46:52 +00001400 MachineBasicBlock *MBB = MI.getOperand(0).getMBB();
1401 MI.RemoveOperand(0);
Hal Finkel940ab932014-02-28 00:27:01 +00001402
Duncan P. N. Exon Smith6307eb52016-02-23 02:46:52 +00001403 MI.setDesc(get(PPC::BCn));
1404 MachineInstrBuilder(*MI.getParent()->getParent(), MI)
1405 .addReg(Pred[1].getReg())
1406 .addMBB(MBB);
Hal Finkel5711eca2013-04-09 22:58:37 +00001407 } else {
Duncan P. N. Exon Smith6307eb52016-02-23 02:46:52 +00001408 MachineBasicBlock *MBB = MI.getOperand(0).getMBB();
1409 MI.RemoveOperand(0);
Hal Finkel5711eca2013-04-09 22:58:37 +00001410
Duncan P. N. Exon Smith6307eb52016-02-23 02:46:52 +00001411 MI.setDesc(get(PPC::BCC));
1412 MachineInstrBuilder(*MI.getParent()->getParent(), MI)
1413 .addImm(Pred[0].getImm())
1414 .addReg(Pred[1].getReg())
1415 .addMBB(MBB);
Hal Finkel5711eca2013-04-09 22:58:37 +00001416 }
1417
1418 return true;
Hal Finkel500b0042013-04-10 06:42:34 +00001419 } else if (OpC == PPC::BCTR || OpC == PPC::BCTR8 ||
1420 OpC == PPC::BCTRL || OpC == PPC::BCTRL8) {
1421 if (Pred[1].getReg() == PPC::CTR8 || Pred[1].getReg() == PPC::CTR)
1422 llvm_unreachable("Cannot predicate bctr[l] on the ctr register");
1423
1424 bool setLR = OpC == PPC::BCTRL || OpC == PPC::BCTRL8;
Eric Christopher1dcea732014-06-12 21:48:52 +00001425 bool isPPC64 = Subtarget.isPPC64();
Hal Finkel940ab932014-02-28 00:27:01 +00001426
1427 if (Pred[0].getImm() == PPC::PRED_BIT_SET) {
Duncan P. N. Exon Smith6307eb52016-02-23 02:46:52 +00001428 MI.setDesc(get(isPPC64 ? (setLR ? PPC::BCCTRL8 : PPC::BCCTR8)
1429 : (setLR ? PPC::BCCTRL : PPC::BCCTR)));
1430 MachineInstrBuilder(*MI.getParent()->getParent(), MI)
1431 .addReg(Pred[1].getReg());
Hal Finkel940ab932014-02-28 00:27:01 +00001432 return true;
1433 } else if (Pred[0].getImm() == PPC::PRED_BIT_UNSET) {
Duncan P. N. Exon Smith6307eb52016-02-23 02:46:52 +00001434 MI.setDesc(get(isPPC64 ? (setLR ? PPC::BCCTRL8n : PPC::BCCTR8n)
1435 : (setLR ? PPC::BCCTRLn : PPC::BCCTRn)));
1436 MachineInstrBuilder(*MI.getParent()->getParent(), MI)
1437 .addReg(Pred[1].getReg());
Hal Finkel940ab932014-02-28 00:27:01 +00001438 return true;
1439 }
1440
Duncan P. N. Exon Smith6307eb52016-02-23 02:46:52 +00001441 MI.setDesc(get(isPPC64 ? (setLR ? PPC::BCCCTRL8 : PPC::BCCCTR8)
1442 : (setLR ? PPC::BCCCTRL : PPC::BCCCTR)));
1443 MachineInstrBuilder(*MI.getParent()->getParent(), MI)
1444 .addImm(Pred[0].getImm())
1445 .addReg(Pred[1].getReg());
Hal Finkel500b0042013-04-10 06:42:34 +00001446 return true;
Hal Finkel5711eca2013-04-09 22:58:37 +00001447 }
1448
1449 return false;
1450}
1451
Ahmed Bougachac88bf542015-06-11 19:30:37 +00001452bool PPCInstrInfo::SubsumesPredicate(ArrayRef<MachineOperand> Pred1,
1453 ArrayRef<MachineOperand> Pred2) const {
Hal Finkel5711eca2013-04-09 22:58:37 +00001454 assert(Pred1.size() == 2 && "Invalid PPC first predicate");
1455 assert(Pred2.size() == 2 && "Invalid PPC second predicate");
1456
1457 if (Pred1[1].getReg() == PPC::CTR8 || Pred1[1].getReg() == PPC::CTR)
1458 return false;
1459 if (Pred2[1].getReg() == PPC::CTR8 || Pred2[1].getReg() == PPC::CTR)
1460 return false;
1461
Hal Finkel94a6f382013-12-11 23:12:25 +00001462 // P1 can only subsume P2 if they test the same condition register.
1463 if (Pred1[1].getReg() != Pred2[1].getReg())
1464 return false;
1465
Hal Finkel5711eca2013-04-09 22:58:37 +00001466 PPC::Predicate P1 = (PPC::Predicate) Pred1[0].getImm();
1467 PPC::Predicate P2 = (PPC::Predicate) Pred2[0].getImm();
1468
1469 if (P1 == P2)
1470 return true;
1471
1472 // Does P1 subsume P2, e.g. GE subsumes GT.
1473 if (P1 == PPC::PRED_LE &&
1474 (P2 == PPC::PRED_LT || P2 == PPC::PRED_EQ))
1475 return true;
1476 if (P1 == PPC::PRED_GE &&
1477 (P2 == PPC::PRED_GT || P2 == PPC::PRED_EQ))
1478 return true;
1479
1480 return false;
1481}
1482
Duncan P. N. Exon Smith6307eb52016-02-23 02:46:52 +00001483bool PPCInstrInfo::DefinesPredicate(MachineInstr &MI,
Hal Finkel5711eca2013-04-09 22:58:37 +00001484 std::vector<MachineOperand> &Pred) const {
1485 // Note: At the present time, the contents of Pred from this function is
1486 // unused by IfConversion. This implementation follows ARM by pushing the
1487 // CR-defining operand. Because the 'DZ' and 'DNZ' count as types of
1488 // predicate, instructions defining CTR or CTR8 are also included as
1489 // predicate-defining instructions.
1490
1491 const TargetRegisterClass *RCs[] =
1492 { &PPC::CRRCRegClass, &PPC::CRBITRCRegClass,
1493 &PPC::CTRRCRegClass, &PPC::CTRRC8RegClass };
1494
1495 bool Found = false;
Duncan P. N. Exon Smith6307eb52016-02-23 02:46:52 +00001496 for (unsigned i = 0, e = MI.getNumOperands(); i != e; ++i) {
1497 const MachineOperand &MO = MI.getOperand(i);
Hal Finkelaf822012013-04-10 07:17:47 +00001498 for (unsigned c = 0; c < array_lengthof(RCs) && !Found; ++c) {
Hal Finkel5711eca2013-04-09 22:58:37 +00001499 const TargetRegisterClass *RC = RCs[c];
Hal Finkelaf822012013-04-10 07:17:47 +00001500 if (MO.isReg()) {
1501 if (MO.isDef() && RC->contains(MO.getReg())) {
Hal Finkel5711eca2013-04-09 22:58:37 +00001502 Pred.push_back(MO);
1503 Found = true;
1504 }
Hal Finkelaf822012013-04-10 07:17:47 +00001505 } else if (MO.isRegMask()) {
1506 for (TargetRegisterClass::iterator I = RC->begin(),
1507 IE = RC->end(); I != IE; ++I)
1508 if (MO.clobbersPhysReg(*I)) {
1509 Pred.push_back(MO);
1510 Found = true;
1511 }
Hal Finkel5711eca2013-04-09 22:58:37 +00001512 }
1513 }
1514 }
1515
1516 return Found;
1517}
1518
Krzysztof Parzyszekcc318712017-03-03 18:30:54 +00001519bool PPCInstrInfo::isPredicable(const MachineInstr &MI) const {
Duncan P. N. Exon Smith6307eb52016-02-23 02:46:52 +00001520 unsigned OpC = MI.getOpcode();
Hal Finkel5711eca2013-04-09 22:58:37 +00001521 switch (OpC) {
1522 default:
1523 return false;
1524 case PPC::B:
1525 case PPC::BLR:
Hal Finkelf4a22c02015-01-13 17:47:54 +00001526 case PPC::BLR8:
Hal Finkel500b0042013-04-10 06:42:34 +00001527 case PPC::BCTR:
1528 case PPC::BCTR8:
1529 case PPC::BCTRL:
1530 case PPC::BCTRL8:
Hal Finkel5711eca2013-04-09 22:58:37 +00001531 return true;
1532 }
1533}
1534
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +00001535bool PPCInstrInfo::analyzeCompare(const MachineInstr &MI, unsigned &SrcReg,
1536 unsigned &SrcReg2, int &Mask,
1537 int &Value) const {
1538 unsigned Opc = MI.getOpcode();
Hal Finkel82656cb2013-04-18 22:15:08 +00001539
1540 switch (Opc) {
1541 default: return false;
1542 case PPC::CMPWI:
1543 case PPC::CMPLWI:
1544 case PPC::CMPDI:
1545 case PPC::CMPLDI:
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +00001546 SrcReg = MI.getOperand(1).getReg();
Hal Finkel82656cb2013-04-18 22:15:08 +00001547 SrcReg2 = 0;
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +00001548 Value = MI.getOperand(2).getImm();
Hal Finkel82656cb2013-04-18 22:15:08 +00001549 Mask = 0xFFFF;
1550 return true;
1551 case PPC::CMPW:
1552 case PPC::CMPLW:
1553 case PPC::CMPD:
1554 case PPC::CMPLD:
1555 case PPC::FCMPUS:
1556 case PPC::FCMPUD:
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +00001557 SrcReg = MI.getOperand(1).getReg();
1558 SrcReg2 = MI.getOperand(2).getReg();
Hiroshi Inoue37e63b12017-05-21 06:00:05 +00001559 Value = 0;
1560 Mask = 0;
Hal Finkel82656cb2013-04-18 22:15:08 +00001561 return true;
1562 }
1563}
Hal Finkele6322392013-04-19 22:08:38 +00001564
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +00001565bool PPCInstrInfo::optimizeCompareInstr(MachineInstr &CmpInstr, unsigned SrcReg,
1566 unsigned SrcReg2, int Mask, int Value,
Hal Finkel82656cb2013-04-18 22:15:08 +00001567 const MachineRegisterInfo *MRI) const {
Hal Finkelb12da6b2013-04-18 22:54:25 +00001568 if (DisableCmpOpt)
1569 return false;
1570
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +00001571 int OpC = CmpInstr.getOpcode();
1572 unsigned CRReg = CmpInstr.getOperand(0).getReg();
Hal Finkel08e53ee2013-05-08 12:16:14 +00001573
1574 // FP record forms set CR1 based on the execption status bits, not a
1575 // comparison with zero.
1576 if (OpC == PPC::FCMPUS || OpC == PPC::FCMPUD)
1577 return false;
Hal Finkel82656cb2013-04-18 22:15:08 +00001578
1579 // The record forms set the condition register based on a signed comparison
1580 // with zero (so says the ISA manual). This is not as straightforward as it
1581 // seems, however, because this is always a 64-bit comparison on PPC64, even
1582 // for instructions that are 32-bit in nature (like slw for example).
1583 // So, on PPC32, for unsigned comparisons, we can use the record forms only
1584 // for equality checks (as those don't depend on the sign). On PPC64,
1585 // we are restricted to equality for unsigned 64-bit comparisons and for
1586 // signed 32-bit comparisons the applicability is more restricted.
Eric Christopher1dcea732014-06-12 21:48:52 +00001587 bool isPPC64 = Subtarget.isPPC64();
Hal Finkel82656cb2013-04-18 22:15:08 +00001588 bool is32BitSignedCompare = OpC == PPC::CMPWI || OpC == PPC::CMPW;
1589 bool is32BitUnsignedCompare = OpC == PPC::CMPLWI || OpC == PPC::CMPLW;
1590 bool is64BitUnsignedCompare = OpC == PPC::CMPLDI || OpC == PPC::CMPLD;
1591
1592 // Get the unique definition of SrcReg.
1593 MachineInstr *MI = MRI->getUniqueVRegDef(SrcReg);
1594 if (!MI) return false;
1595 int MIOpC = MI->getOpcode();
1596
1597 bool equalityOnly = false;
1598 bool noSub = false;
1599 if (isPPC64) {
1600 if (is32BitSignedCompare) {
1601 // We can perform this optimization only if MI is sign-extending.
1602 if (MIOpC == PPC::SRAW || MIOpC == PPC::SRAWo ||
1603 MIOpC == PPC::SRAWI || MIOpC == PPC::SRAWIo ||
1604 MIOpC == PPC::EXTSB || MIOpC == PPC::EXTSBo ||
1605 MIOpC == PPC::EXTSH || MIOpC == PPC::EXTSHo ||
1606 MIOpC == PPC::EXTSW || MIOpC == PPC::EXTSWo) {
1607 noSub = true;
1608 } else
1609 return false;
1610 } else if (is32BitUnsignedCompare) {
Kyle Butt61311282016-03-23 19:51:22 +00001611 // 32-bit rotate and mask instructions are zero extending only if MB <= ME
1612 bool isZeroExtendingRotate =
1613 (MIOpC == PPC::RLWINM || MIOpC == PPC::RLWINMo ||
1614 MIOpC == PPC::RLWNM || MIOpC == PPC::RLWNMo)
1615 && MI->getOperand(3).getImm() <= MI->getOperand(4).getImm();
1616
Hal Finkel82656cb2013-04-18 22:15:08 +00001617 // We can perform this optimization, equality only, if MI is
1618 // zero-extending.
Hiroshi Inoue37e63b12017-05-21 06:00:05 +00001619 // FIXME: Other possible target instructions include ANDISo and
1620 // RLWINM aliases, such as ROTRWI, EXTLWI, SLWI and SRWI.
Hal Finkel82656cb2013-04-18 22:15:08 +00001621 if (MIOpC == PPC::CNTLZW || MIOpC == PPC::CNTLZWo ||
1622 MIOpC == PPC::SLW || MIOpC == PPC::SLWo ||
Kyle Butt61311282016-03-23 19:51:22 +00001623 MIOpC == PPC::SRW || MIOpC == PPC::SRWo ||
Hiroshi Inoue37e63b12017-05-21 06:00:05 +00001624 MIOpC == PPC::ANDIo ||
Kyle Butt61311282016-03-23 19:51:22 +00001625 isZeroExtendingRotate) {
Hal Finkel82656cb2013-04-18 22:15:08 +00001626 noSub = true;
1627 equalityOnly = true;
1628 } else
1629 return false;
Hal Finkel08e53ee2013-05-08 12:16:14 +00001630 } else
Hal Finkel82656cb2013-04-18 22:15:08 +00001631 equalityOnly = is64BitUnsignedCompare;
Hal Finkel08e53ee2013-05-08 12:16:14 +00001632 } else
Hal Finkel82656cb2013-04-18 22:15:08 +00001633 equalityOnly = is32BitUnsignedCompare;
1634
1635 if (equalityOnly) {
1636 // We need to check the uses of the condition register in order to reject
1637 // non-equality comparisons.
Owen Anderson16c6bf42014-03-13 23:12:04 +00001638 for (MachineRegisterInfo::use_instr_iterator I =MRI->use_instr_begin(CRReg),
1639 IE = MRI->use_instr_end(); I != IE; ++I) {
Hal Finkel82656cb2013-04-18 22:15:08 +00001640 MachineInstr *UseMI = &*I;
1641 if (UseMI->getOpcode() == PPC::BCC) {
1642 unsigned Pred = UseMI->getOperand(0).getImm();
Hal Finkelc3632452013-05-07 17:49:55 +00001643 if (Pred != PPC::PRED_EQ && Pred != PPC::PRED_NE)
1644 return false;
Hal Finkel82656cb2013-04-18 22:15:08 +00001645 } else if (UseMI->getOpcode() == PPC::ISEL ||
1646 UseMI->getOpcode() == PPC::ISEL8) {
1647 unsigned SubIdx = UseMI->getOperand(3).getSubReg();
Hal Finkelc3632452013-05-07 17:49:55 +00001648 if (SubIdx != PPC::sub_eq)
1649 return false;
Hal Finkel82656cb2013-04-18 22:15:08 +00001650 } else
1651 return false;
1652 }
1653 }
1654
Hal Finkelc3632452013-05-07 17:49:55 +00001655 MachineBasicBlock::iterator I = CmpInstr;
Hal Finkel82656cb2013-04-18 22:15:08 +00001656
1657 // Scan forward to find the first use of the compare.
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +00001658 for (MachineBasicBlock::iterator EL = CmpInstr.getParent()->end(); I != EL;
1659 ++I) {
Hal Finkel82656cb2013-04-18 22:15:08 +00001660 bool FoundUse = false;
Owen Anderson16c6bf42014-03-13 23:12:04 +00001661 for (MachineRegisterInfo::use_instr_iterator J =MRI->use_instr_begin(CRReg),
1662 JE = MRI->use_instr_end(); J != JE; ++J)
Hal Finkel82656cb2013-04-18 22:15:08 +00001663 if (&*J == &*I) {
1664 FoundUse = true;
1665 break;
1666 }
1667
1668 if (FoundUse)
1669 break;
1670 }
1671
Hiroshi Inoue37e63b12017-05-21 06:00:05 +00001672 SmallVector<std::pair<MachineOperand*, PPC::Predicate>, 4> PredsToUpdate;
1673 SmallVector<std::pair<MachineOperand*, unsigned>, 4> SubRegsToUpdate;
1674
Hal Finkel82656cb2013-04-18 22:15:08 +00001675 // There are two possible candidates which can be changed to set CR[01].
1676 // One is MI, the other is a SUB instruction.
1677 // For CMPrr(r1,r2), we are looking for SUB(r1,r2) or SUB(r2,r1).
Craig Topper062a2ba2014-04-25 05:30:21 +00001678 MachineInstr *Sub = nullptr;
Hal Finkel82656cb2013-04-18 22:15:08 +00001679 if (SrcReg2 != 0)
1680 // MI is not a candidate for CMPrr.
Craig Topper062a2ba2014-04-25 05:30:21 +00001681 MI = nullptr;
Hal Finkel82656cb2013-04-18 22:15:08 +00001682 // FIXME: Conservatively refuse to convert an instruction which isn't in the
1683 // same BB as the comparison. This is to allow the check below to avoid calls
1684 // (and other explicit clobbers); instead we should really check for these
1685 // more explicitly (in at least a few predecessors).
Hiroshi Inoue37e63b12017-05-21 06:00:05 +00001686 else if (MI->getParent() != CmpInstr.getParent())
Hal Finkel82656cb2013-04-18 22:15:08 +00001687 return false;
Hiroshi Inoue37e63b12017-05-21 06:00:05 +00001688 else if (Value != 0) {
1689 // The record-form instructions set CR bit based on signed comparison against 0.
1690 // We try to convert a compare against 1 or -1 into a compare against 0.
1691 bool Success = false;
1692 if (!equalityOnly && MRI->hasOneUse(CRReg)) {
1693 MachineInstr *UseMI = &*MRI->use_instr_begin(CRReg);
1694 if (UseMI->getOpcode() == PPC::BCC) {
1695 PPC::Predicate Pred = (PPC::Predicate)UseMI->getOperand(0).getImm();
1696 int16_t Immed = (int16_t)Value;
1697
1698 if (Immed == -1 && Pred == PPC::PRED_GT) {
1699 // We convert "greater than -1" into "greater than or equal to 0",
1700 // since we are assuming signed comparison by !equalityOnly
1701 PredsToUpdate.push_back(std::make_pair(&(UseMI->getOperand(0)),
1702 PPC::PRED_GE));
1703 Success = true;
1704 }
1705 else if (Immed == 1 && Pred == PPC::PRED_LT) {
1706 // We convert "less than 1" into "less than or equal to 0".
1707 PredsToUpdate.push_back(std::make_pair(&(UseMI->getOperand(0)),
1708 PPC::PRED_LE));
1709 Success = true;
1710 }
1711 }
1712 }
1713
1714 // PPC does not have a record-form SUBri.
1715 if (!Success)
1716 return false;
Hal Finkel82656cb2013-04-18 22:15:08 +00001717 }
1718
1719 // Search for Sub.
1720 const TargetRegisterInfo *TRI = &getRegisterInfo();
1721 --I;
Hal Finkelc3632452013-05-07 17:49:55 +00001722
1723 // Get ready to iterate backward from CmpInstr.
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +00001724 MachineBasicBlock::iterator E = MI, B = CmpInstr.getParent()->begin();
Hal Finkelc3632452013-05-07 17:49:55 +00001725
Hal Finkel82656cb2013-04-18 22:15:08 +00001726 for (; I != E && !noSub; --I) {
1727 const MachineInstr &Instr = *I;
1728 unsigned IOpC = Instr.getOpcode();
1729
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +00001730 if (&*I != &CmpInstr && (Instr.modifiesRegister(PPC::CR0, TRI) ||
1731 Instr.readsRegister(PPC::CR0, TRI)))
Hal Finkel82656cb2013-04-18 22:15:08 +00001732 // This instruction modifies or uses the record condition register after
1733 // the one we want to change. While we could do this transformation, it
1734 // would likely not be profitable. This transformation removes one
1735 // instruction, and so even forcing RA to generate one move probably
1736 // makes it unprofitable.
1737 return false;
1738
1739 // Check whether CmpInstr can be made redundant by the current instruction.
1740 if ((OpC == PPC::CMPW || OpC == PPC::CMPLW ||
1741 OpC == PPC::CMPD || OpC == PPC::CMPLD) &&
1742 (IOpC == PPC::SUBF || IOpC == PPC::SUBF8) &&
1743 ((Instr.getOperand(1).getReg() == SrcReg &&
1744 Instr.getOperand(2).getReg() == SrcReg2) ||
1745 (Instr.getOperand(1).getReg() == SrcReg2 &&
1746 Instr.getOperand(2).getReg() == SrcReg))) {
1747 Sub = &*I;
1748 break;
1749 }
1750
Hal Finkel82656cb2013-04-18 22:15:08 +00001751 if (I == B)
1752 // The 'and' is below the comparison instruction.
1753 return false;
1754 }
1755
1756 // Return false if no candidates exist.
1757 if (!MI && !Sub)
1758 return false;
1759
1760 // The single candidate is called MI.
1761 if (!MI) MI = Sub;
1762
1763 int NewOpC = -1;
1764 MIOpC = MI->getOpcode();
1765 if (MIOpC == PPC::ANDIo || MIOpC == PPC::ANDIo8)
1766 NewOpC = MIOpC;
1767 else {
1768 NewOpC = PPC::getRecordFormOpcode(MIOpC);
1769 if (NewOpC == -1 && PPC::getNonRecordFormOpcode(MIOpC) != -1)
1770 NewOpC = MIOpC;
1771 }
1772
1773 // FIXME: On the non-embedded POWER architectures, only some of the record
1774 // forms are fast, and we should use only the fast ones.
1775
1776 // The defining instruction has a record form (or is already a record
1777 // form). It is possible, however, that we'll need to reverse the condition
1778 // code of the users.
1779 if (NewOpC == -1)
1780 return false;
1781
Hal Finkel82656cb2013-04-18 22:15:08 +00001782 // If we have SUB(r1, r2) and CMP(r2, r1), the condition code based on CMP
1783 // needs to be updated to be based on SUB. Push the condition code
1784 // operands to OperandsToUpdate. If it is safe to remove CmpInstr, the
1785 // condition code of these operands will be modified.
Hiroshi Inoue37e63b12017-05-21 06:00:05 +00001786 // Here, Value == 0 means we haven't converted comparison against 1 or -1 to
1787 // comparison against 0, which may modify predicate.
Hal Finkel82656cb2013-04-18 22:15:08 +00001788 bool ShouldSwap = false;
Hiroshi Inoue37e63b12017-05-21 06:00:05 +00001789 if (Sub && Value == 0) {
Hal Finkel82656cb2013-04-18 22:15:08 +00001790 ShouldSwap = SrcReg2 != 0 && Sub->getOperand(1).getReg() == SrcReg2 &&
1791 Sub->getOperand(2).getReg() == SrcReg;
1792
1793 // The operands to subf are the opposite of sub, so only in the fixed-point
1794 // case, invert the order.
Hal Finkel08e53ee2013-05-08 12:16:14 +00001795 ShouldSwap = !ShouldSwap;
Hal Finkel82656cb2013-04-18 22:15:08 +00001796 }
1797
1798 if (ShouldSwap)
Owen Anderson16c6bf42014-03-13 23:12:04 +00001799 for (MachineRegisterInfo::use_instr_iterator
1800 I = MRI->use_instr_begin(CRReg), IE = MRI->use_instr_end();
1801 I != IE; ++I) {
Hal Finkel82656cb2013-04-18 22:15:08 +00001802 MachineInstr *UseMI = &*I;
1803 if (UseMI->getOpcode() == PPC::BCC) {
1804 PPC::Predicate Pred = (PPC::Predicate) UseMI->getOperand(0).getImm();
Hal Finkele6322392013-04-19 22:08:38 +00001805 assert((!equalityOnly ||
1806 Pred == PPC::PRED_EQ || Pred == PPC::PRED_NE) &&
1807 "Invalid predicate for equality-only optimization");
Owen Anderson16c6bf42014-03-13 23:12:04 +00001808 PredsToUpdate.push_back(std::make_pair(&(UseMI->getOperand(0)),
Hal Finkel0f64e212013-04-20 05:16:26 +00001809 PPC::getSwappedPredicate(Pred)));
Hal Finkel82656cb2013-04-18 22:15:08 +00001810 } else if (UseMI->getOpcode() == PPC::ISEL ||
1811 UseMI->getOpcode() == PPC::ISEL8) {
Hal Finkele6322392013-04-19 22:08:38 +00001812 unsigned NewSubReg = UseMI->getOperand(3).getSubReg();
1813 assert((!equalityOnly || NewSubReg == PPC::sub_eq) &&
1814 "Invalid CR bit for equality-only optimization");
1815
1816 if (NewSubReg == PPC::sub_lt)
1817 NewSubReg = PPC::sub_gt;
1818 else if (NewSubReg == PPC::sub_gt)
1819 NewSubReg = PPC::sub_lt;
1820
Owen Anderson16c6bf42014-03-13 23:12:04 +00001821 SubRegsToUpdate.push_back(std::make_pair(&(UseMI->getOperand(3)),
Hal Finkele6322392013-04-19 22:08:38 +00001822 NewSubReg));
Hal Finkel82656cb2013-04-18 22:15:08 +00001823 } else // We need to abort on a user we don't understand.
1824 return false;
1825 }
Hiroshi Inoue37e63b12017-05-21 06:00:05 +00001826 assert(!(Value != 0 && ShouldSwap) &&
1827 "Non-zero immediate support and ShouldSwap"
1828 "may conflict in updating predicate");
Hal Finkel82656cb2013-04-18 22:15:08 +00001829
1830 // Create a new virtual register to hold the value of the CR set by the
1831 // record-form instruction. If the instruction was not previously in
1832 // record form, then set the kill flag on the CR.
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +00001833 CmpInstr.eraseFromParent();
Hal Finkel82656cb2013-04-18 22:15:08 +00001834
1835 MachineBasicBlock::iterator MII = MI;
Benjamin Kramerb6d0bd42014-03-02 12:27:27 +00001836 BuildMI(*MI->getParent(), std::next(MII), MI->getDebugLoc(),
Hal Finkel82656cb2013-04-18 22:15:08 +00001837 get(TargetOpcode::COPY), CRReg)
Hal Finkel08e53ee2013-05-08 12:16:14 +00001838 .addReg(PPC::CR0, MIOpC != NewOpC ? RegState::Kill : 0);
Hal Finkel82656cb2013-04-18 22:15:08 +00001839
Chuang-Yu Cheng94f58e72016-04-12 03:10:52 +00001840 // Even if CR0 register were dead before, it is alive now since the
1841 // instruction we just built uses it.
1842 MI->clearRegisterDeads(PPC::CR0);
1843
Hal Finkel82656cb2013-04-18 22:15:08 +00001844 if (MIOpC != NewOpC) {
1845 // We need to be careful here: we're replacing one instruction with
1846 // another, and we need to make sure that we get all of the right
1847 // implicit uses and defs. On the other hand, the caller may be holding
1848 // an iterator to this instruction, and so we can't delete it (this is
1849 // specifically the case if this is the instruction directly after the
1850 // compare).
1851
1852 const MCInstrDesc &NewDesc = get(NewOpC);
1853 MI->setDesc(NewDesc);
1854
1855 if (NewDesc.ImplicitDefs)
Craig Toppere5e035a32015-12-05 07:13:35 +00001856 for (const MCPhysReg *ImpDefs = NewDesc.getImplicitDefs();
Hal Finkel82656cb2013-04-18 22:15:08 +00001857 *ImpDefs; ++ImpDefs)
1858 if (!MI->definesRegister(*ImpDefs))
1859 MI->addOperand(*MI->getParent()->getParent(),
1860 MachineOperand::CreateReg(*ImpDefs, true, true));
1861 if (NewDesc.ImplicitUses)
Craig Toppere5e035a32015-12-05 07:13:35 +00001862 for (const MCPhysReg *ImpUses = NewDesc.getImplicitUses();
Hal Finkel82656cb2013-04-18 22:15:08 +00001863 *ImpUses; ++ImpUses)
1864 if (!MI->readsRegister(*ImpUses))
1865 MI->addOperand(*MI->getParent()->getParent(),
1866 MachineOperand::CreateReg(*ImpUses, false, true));
1867 }
Keno Fischer55734832016-06-01 20:31:07 +00001868 assert(MI->definesRegister(PPC::CR0) &&
1869 "Record-form instruction does not define cr0?");
Hal Finkel82656cb2013-04-18 22:15:08 +00001870
1871 // Modify the condition code of operands in OperandsToUpdate.
1872 // Since we have SUB(r1, r2) and CMP(r2, r1), the condition code needs to
1873 // be changed from r2 > r1 to r1 < r2, from r2 < r1 to r1 > r2, etc.
Hal Finkele6322392013-04-19 22:08:38 +00001874 for (unsigned i = 0, e = PredsToUpdate.size(); i < e; i++)
1875 PredsToUpdate[i].first->setImm(PredsToUpdate[i].second);
Hal Finkel82656cb2013-04-18 22:15:08 +00001876
Hal Finkele6322392013-04-19 22:08:38 +00001877 for (unsigned i = 0, e = SubRegsToUpdate.size(); i < e; i++)
1878 SubRegsToUpdate[i].first->setSubReg(SubRegsToUpdate[i].second);
Hal Finkel82656cb2013-04-18 22:15:08 +00001879
1880 return true;
1881}
1882
Nicolas Geoffrayae84bbd2008-04-16 20:10:13 +00001883/// GetInstSize - Return the number of bytes of code the specified
1884/// instruction may be. This returns the maximum number of bytes.
1885///
Sjoerd Meijer89217f82016-07-28 16:32:22 +00001886unsigned PPCInstrInfo::getInstSizeInBytes(const MachineInstr &MI) const {
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +00001887 unsigned Opcode = MI.getOpcode();
Hal Finkela7bbaf62014-02-02 06:12:27 +00001888
1889 if (Opcode == PPC::INLINEASM) {
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +00001890 const MachineFunction *MF = MI.getParent()->getParent();
1891 const char *AsmStr = MI.getOperand(0).getSymbolName();
Chris Lattner7b26fce2009-08-22 20:48:53 +00001892 return getInlineAsmLength(AsmStr, *MF->getTarget().getMCAsmInfo());
Hal Finkel934361a2015-01-14 01:07:51 +00001893 } else if (Opcode == TargetOpcode::STACKMAP) {
Philip Reamese83c4b32016-08-23 23:33:29 +00001894 StackMapOpers Opers(&MI);
1895 return Opers.getNumPatchBytes();
Hal Finkel934361a2015-01-14 01:07:51 +00001896 } else if (Opcode == TargetOpcode::PATCHPOINT) {
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +00001897 PatchPointOpers Opers(&MI);
Philip Reamese83c4b32016-08-23 23:33:29 +00001898 return Opers.getNumPatchBytes();
Hal Finkela7bbaf62014-02-02 06:12:27 +00001899 } else {
Eric Christopherf48ef332017-03-27 22:40:51 +00001900 return get(Opcode).getSize();
Nicolas Geoffrayae84bbd2008-04-16 20:10:13 +00001901 }
1902}
Hal Finkelb5aa7e52013-04-08 16:24:03 +00001903
Hal Finkel2d556982015-08-30 07:50:35 +00001904std::pair<unsigned, unsigned>
1905PPCInstrInfo::decomposeMachineOperandsTargetFlags(unsigned TF) const {
1906 const unsigned Mask = PPCII::MO_ACCESS_MASK;
1907 return std::make_pair(TF & Mask, TF & ~Mask);
1908}
1909
1910ArrayRef<std::pair<unsigned, const char *>>
1911PPCInstrInfo::getSerializableDirectMachineOperandTargetFlags() const {
1912 using namespace PPCII;
Hal Finkel982e8d42015-08-30 08:07:29 +00001913 static const std::pair<unsigned, const char *> TargetFlags[] = {
Hal Finkel2d556982015-08-30 07:50:35 +00001914 {MO_LO, "ppc-lo"},
1915 {MO_HA, "ppc-ha"},
1916 {MO_TPREL_LO, "ppc-tprel-lo"},
1917 {MO_TPREL_HA, "ppc-tprel-ha"},
1918 {MO_DTPREL_LO, "ppc-dtprel-lo"},
1919 {MO_TLSLD_LO, "ppc-tlsld-lo"},
1920 {MO_TOC_LO, "ppc-toc-lo"},
1921 {MO_TLS, "ppc-tls"}};
1922 return makeArrayRef(TargetFlags);
1923}
1924
1925ArrayRef<std::pair<unsigned, const char *>>
1926PPCInstrInfo::getSerializableBitmaskMachineOperandTargetFlags() const {
1927 using namespace PPCII;
Hal Finkel982e8d42015-08-30 08:07:29 +00001928 static const std::pair<unsigned, const char *> TargetFlags[] = {
Rafael Espindolaa99ccfc2016-06-29 14:59:50 +00001929 {MO_PLT, "ppc-plt"},
Hal Finkel2d556982015-08-30 07:50:35 +00001930 {MO_PIC_FLAG, "ppc-pic"},
1931 {MO_NLP_FLAG, "ppc-nlp"},
1932 {MO_NLP_HIDDEN_FLAG, "ppc-nlp-hidden"}};
1933 return makeArrayRef(TargetFlags);
1934}
1935
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +00001936bool PPCInstrInfo::expandPostRAPseudo(MachineInstr &MI) const {
Tim Shen3bef27c2017-05-16 20:18:06 +00001937 auto &MBB = *MI.getParent();
1938 auto DL = MI.getDebugLoc();
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +00001939 switch (MI.getOpcode()) {
Tim Shena1d8bc52016-04-19 20:14:52 +00001940 case TargetOpcode::LOAD_STACK_GUARD: {
1941 assert(Subtarget.isTargetLinux() &&
1942 "Only Linux target is expected to contain LOAD_STACK_GUARD");
1943 const int64_t Offset = Subtarget.isPPC64() ? -0x7010 : -0x7008;
1944 const unsigned Reg = Subtarget.isPPC64() ? PPC::X13 : PPC::R2;
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +00001945 MI.setDesc(get(Subtarget.isPPC64() ? PPC::LD : PPC::LWZ));
1946 MachineInstrBuilder(*MI.getParent()->getParent(), MI)
Tim Shena1d8bc52016-04-19 20:14:52 +00001947 .addImm(Offset)
1948 .addReg(Reg);
1949 return true;
1950 }
Nemanja Ivanovic6354d232016-10-04 11:25:52 +00001951 case PPC::DFLOADf32:
1952 case PPC::DFLOADf64:
1953 case PPC::DFSTOREf32:
1954 case PPC::DFSTOREf64: {
1955 assert(Subtarget.hasP9Vector() &&
1956 "Invalid D-Form Pseudo-ops on non-P9 target.");
Hiroshi Inouee3c14eb2017-05-29 07:12:39 +00001957 assert(MI.getOperand(2).isReg() && MI.getOperand(1).isImm() &&
1958 "D-form op must have register and immediate operands");
Nemanja Ivanovic6354d232016-10-04 11:25:52 +00001959 unsigned UpperOpcode, LowerOpcode;
1960 switch (MI.getOpcode()) {
1961 case PPC::DFLOADf32:
1962 UpperOpcode = PPC::LXSSP;
1963 LowerOpcode = PPC::LFS;
1964 break;
1965 case PPC::DFLOADf64:
1966 UpperOpcode = PPC::LXSD;
1967 LowerOpcode = PPC::LFD;
1968 break;
1969 case PPC::DFSTOREf32:
1970 UpperOpcode = PPC::STXSSP;
1971 LowerOpcode = PPC::STFS;
1972 break;
1973 case PPC::DFSTOREf64:
1974 UpperOpcode = PPC::STXSD;
1975 LowerOpcode = PPC::STFD;
1976 break;
1977 }
1978 unsigned TargetReg = MI.getOperand(0).getReg();
1979 unsigned Opcode;
1980 if ((TargetReg >= PPC::F0 && TargetReg <= PPC::F31) ||
1981 (TargetReg >= PPC::VSL0 && TargetReg <= PPC::VSL31))
1982 Opcode = LowerOpcode;
1983 else
1984 Opcode = UpperOpcode;
1985 MI.setDesc(get(Opcode));
1986 return true;
1987 }
Tim Shen3bef27c2017-05-16 20:18:06 +00001988 case PPC::CFENCE8: {
1989 auto Val = MI.getOperand(0).getReg();
Hiroshi Inoue7a08bb12017-06-15 16:51:28 +00001990 BuildMI(MBB, MI, DL, get(PPC::CMPD), PPC::CR7).addReg(Val).addReg(Val);
Tim Shen3bef27c2017-05-16 20:18:06 +00001991 BuildMI(MBB, MI, DL, get(PPC::CTRL_DEP))
1992 .addImm(PPC::PRED_NE_MINUS)
1993 .addReg(PPC::CR7)
1994 .addImm(1);
1995 MI.setDesc(get(PPC::ISYNC));
1996 MI.RemoveOperand(0);
1997 return true;
1998 }
Tim Shena1d8bc52016-04-19 20:14:52 +00001999 }
2000 return false;
2001}
Nemanja Ivanovic11049f82016-10-04 06:59:23 +00002002
2003const TargetRegisterClass *
2004PPCInstrInfo::updatedRC(const TargetRegisterClass *RC) const {
2005 if (Subtarget.hasVSX() && RC == &PPC::VRRCRegClass)
2006 return &PPC::VSRCRegClass;
2007 return RC;
2008}
Nemanja Ivanovice597bd82017-05-31 05:40:25 +00002009
2010int PPCInstrInfo::getRecordFormOpcode(unsigned Opcode) {
2011 return PPC::getRecordFormOpcode(Opcode);
2012}