blob: 561099b24be8f80cb0041a3e373e47d33a16add4 [file] [log] [blame]
Nate Begeman21e463b2005-10-16 05:39:50 +00001//===-- PPCISelDAGToDAG.cpp - PPC --pattern matching inst selector --------===//
Chris Lattnera5a91b12005-08-17 19:33:03 +00002//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Chris Lattnera5a91b12005-08-17 19:33:03 +00007//
8//===----------------------------------------------------------------------===//
9//
Nate Begeman21e463b2005-10-16 05:39:50 +000010// This file defines a pattern matching instruction selector for PowerPC,
Chris Lattnera5a91b12005-08-17 19:33:03 +000011// converting from a legalized dag to a PPC dag.
12//
13//===----------------------------------------------------------------------===//
14
Chris Lattner95b2c7d2006-12-19 22:59:26 +000015#define DEBUG_TYPE "ppc-codegen"
Chris Lattner26689592005-10-14 23:51:18 +000016#include "PPC.h"
Evan Cheng94b95502011-07-26 00:24:13 +000017#include "MCTargetDesc/PPCPredicates.h"
Chandler Carruthd04a8d42012-12-03 16:50:05 +000018#include "PPCTargetMachine.h"
Chris Lattner4416f1a2005-08-19 22:38:53 +000019#include "llvm/CodeGen/MachineFunction.h"
Chandler Carruthd04a8d42012-12-03 16:50:05 +000020#include "llvm/CodeGen/MachineInstrBuilder.h"
Chris Lattner84bc5422007-12-31 04:13:23 +000021#include "llvm/CodeGen/MachineRegisterInfo.h"
Chris Lattnera5a91b12005-08-17 19:33:03 +000022#include "llvm/CodeGen/SelectionDAG.h"
23#include "llvm/CodeGen/SelectionDAGISel.h"
Chandler Carruth0b8c9a82013-01-02 11:36:10 +000024#include "llvm/IR/Constants.h"
25#include "llvm/IR/Function.h"
Chandler Carruth90230c82013-01-19 08:03:47 +000026#include "llvm/IR/GlobalAlias.h"
Chandler Carruth0b8c9a82013-01-02 11:36:10 +000027#include "llvm/IR/GlobalValue.h"
28#include "llvm/IR/GlobalVariable.h"
29#include "llvm/IR/Intrinsics.h"
Chris Lattnera5a91b12005-08-17 19:33:03 +000030#include "llvm/Support/Debug.h"
Torok Edwindac237e2009-07-08 20:53:28 +000031#include "llvm/Support/ErrorHandling.h"
Chandler Carruthd04a8d42012-12-03 16:50:05 +000032#include "llvm/Support/MathExtras.h"
Torok Edwindac237e2009-07-08 20:53:28 +000033#include "llvm/Support/raw_ostream.h"
Chandler Carruthd04a8d42012-12-03 16:50:05 +000034#include "llvm/Target/TargetOptions.h"
Chris Lattnera5a91b12005-08-17 19:33:03 +000035using namespace llvm;
36
Krzysztof Parzyszek96848df2013-02-13 17:40:07 +000037namespace llvm {
38 void initializePPCDAGToDAGISelPass(PassRegistry&);
39}
40
Chris Lattnera5a91b12005-08-17 19:33:03 +000041namespace {
Chris Lattnera5a91b12005-08-17 19:33:03 +000042 //===--------------------------------------------------------------------===//
Nate Begeman1d9d7422005-10-18 00:28:58 +000043 /// PPCDAGToDAGISel - PPC specific code to select PPC machine
Chris Lattnera5a91b12005-08-17 19:33:03 +000044 /// instructions for SelectionDAG operations.
45 ///
Nick Lewycky6726b6d2009-10-25 06:33:48 +000046 class PPCDAGToDAGISel : public SelectionDAGISel {
Dan Gohmand858e902010-04-17 15:26:15 +000047 const PPCTargetMachine &TM;
48 const PPCTargetLowering &PPCLowering;
Evan Cheng152b7e12007-10-23 06:42:42 +000049 const PPCSubtarget &PPCSubTarget;
Chris Lattner4416f1a2005-08-19 22:38:53 +000050 unsigned GlobalBaseReg;
Chris Lattnera5a91b12005-08-17 19:33:03 +000051 public:
Dan Gohman1002c022008-07-07 18:00:37 +000052 explicit PPCDAGToDAGISel(PPCTargetMachine &tm)
Dan Gohman79ce2762009-01-15 19:20:50 +000053 : SelectionDAGISel(tm), TM(tm),
Evan Cheng152b7e12007-10-23 06:42:42 +000054 PPCLowering(*TM.getTargetLowering()),
Krzysztof Parzyszek96848df2013-02-13 17:40:07 +000055 PPCSubTarget(*TM.getSubtargetImpl()) {
56 initializePPCDAGToDAGISelPass(*PassRegistry::getPassRegistry());
57 }
Andrew Trick6e8f4c42010-12-24 04:28:06 +000058
Dan Gohmanad2afc22009-07-31 18:16:33 +000059 virtual bool runOnMachineFunction(MachineFunction &MF) {
Chris Lattner4416f1a2005-08-19 22:38:53 +000060 // Make sure we re-emit a set of the global base reg if necessary
61 GlobalBaseReg = 0;
Dan Gohmanad2afc22009-07-31 18:16:33 +000062 SelectionDAGISel::runOnMachineFunction(MF);
Andrew Trick6e8f4c42010-12-24 04:28:06 +000063
Bill Schmidta5d0ab52012-10-10 20:54:15 +000064 if (!PPCSubTarget.isSVR4ABI())
65 InsertVRSaveCode(MF);
66
Chris Lattner4bb18952006-03-16 18:25:23 +000067 return true;
Chris Lattner4416f1a2005-08-19 22:38:53 +000068 }
Andrew Trick6e8f4c42010-12-24 04:28:06 +000069
Bill Schmidt42102112013-02-21 00:38:25 +000070 virtual void PostprocessISelDAG();
71
Chris Lattnera5a91b12005-08-17 19:33:03 +000072 /// getI32Imm - Return a target constant with the specified value, of type
73 /// i32.
Dan Gohman475871a2008-07-27 21:46:04 +000074 inline SDValue getI32Imm(unsigned Imm) {
Owen Anderson825b72b2009-08-11 20:47:22 +000075 return CurDAG->getTargetConstant(Imm, MVT::i32);
Chris Lattnera5a91b12005-08-17 19:33:03 +000076 }
Chris Lattner4416f1a2005-08-19 22:38:53 +000077
Chris Lattnerc08f9022006-06-27 00:04:13 +000078 /// getI64Imm - Return a target constant with the specified value, of type
79 /// i64.
Dan Gohman475871a2008-07-27 21:46:04 +000080 inline SDValue getI64Imm(uint64_t Imm) {
Owen Anderson825b72b2009-08-11 20:47:22 +000081 return CurDAG->getTargetConstant(Imm, MVT::i64);
Chris Lattnerc08f9022006-06-27 00:04:13 +000082 }
Andrew Trick6e8f4c42010-12-24 04:28:06 +000083
Chris Lattnerc08f9022006-06-27 00:04:13 +000084 /// getSmallIPtrImm - Return a target constant of pointer type.
Dan Gohman475871a2008-07-27 21:46:04 +000085 inline SDValue getSmallIPtrImm(unsigned Imm) {
Chris Lattnerc08f9022006-06-27 00:04:13 +000086 return CurDAG->getTargetConstant(Imm, PPCLowering.getPointerTy());
87 }
Andrew Trick6e8f4c42010-12-24 04:28:06 +000088
Sylvestre Ledru94c22712012-09-27 10:14:43 +000089 /// isRunOfOnes - Returns true iff Val consists of one contiguous run of 1s
Nate Begemanf42f1332006-09-22 05:01:56 +000090 /// with any number of 0s on either side. The 1s are allowed to wrap from
91 /// LSB to MSB, so 0x000FFF0, 0x0000FFFF, and 0xFF0000FF are all runs.
92 /// 0x0F0F0000 is not, since all 1s are not contiguous.
93 static bool isRunOfOnes(unsigned Val, unsigned &MB, unsigned &ME);
94
95
96 /// isRotateAndMask - Returns true if Mask and Shift can be folded into a
97 /// rotate and mask opcode and mask operation.
Dale Johannesenb60d5192009-11-24 01:09:07 +000098 static bool isRotateAndMask(SDNode *N, unsigned Mask, bool isShiftMask,
Nate Begemanf42f1332006-09-22 05:01:56 +000099 unsigned &SH, unsigned &MB, unsigned &ME);
Andrew Trick6e8f4c42010-12-24 04:28:06 +0000100
Chris Lattner4416f1a2005-08-19 22:38:53 +0000101 /// getGlobalBaseReg - insert code into the entry mbb to materialize the PIC
102 /// base register. Return the virtual register that holds this value.
Evan Cheng9ade2182006-08-26 05:34:46 +0000103 SDNode *getGlobalBaseReg();
Andrew Trick6e8f4c42010-12-24 04:28:06 +0000104
Chris Lattnera5a91b12005-08-17 19:33:03 +0000105 // Select - Convert the specified operand from a target-independent to a
106 // target-specific node if it hasn't already been changed.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000107 SDNode *Select(SDNode *N);
Andrew Trick6e8f4c42010-12-24 04:28:06 +0000108
Nate Begeman02b88a42005-08-19 00:38:14 +0000109 SDNode *SelectBitfieldInsert(SDNode *N);
110
Chris Lattner2fbb4572005-08-21 18:50:37 +0000111 /// SelectCC - Select a comparison of the specified values with the
112 /// specified condition code, returning the CR# of the expression.
Dale Johannesenf5f5dce2009-02-06 19:16:40 +0000113 SDValue SelectCC(SDValue LHS, SDValue RHS, ISD::CondCode CC, DebugLoc dl);
Chris Lattner2fbb4572005-08-21 18:50:37 +0000114
Nate Begeman7fd1edd2005-12-19 23:25:09 +0000115 /// SelectAddrImm - Returns true if the address N can be represented by
116 /// a base register plus a signed 16-bit displacement [r+imm].
Chris Lattner52a261b2010-09-21 20:31:19 +0000117 bool SelectAddrImm(SDValue N, SDValue &Disp,
Dan Gohman475871a2008-07-27 21:46:04 +0000118 SDValue &Base) {
Chris Lattnerfc5b1ab2006-11-08 02:15:41 +0000119 return PPCLowering.SelectAddressRegImm(N, Disp, Base, *CurDAG);
120 }
Andrew Trick6e8f4c42010-12-24 04:28:06 +0000121
Chris Lattner74531e42006-11-16 00:41:37 +0000122 /// SelectAddrImmOffs - Return true if the operand is valid for a preinc
123 /// immediate field. Because preinc imms have already been validated, just
124 /// accept it.
Chris Lattner52a261b2010-09-21 20:31:19 +0000125 bool SelectAddrImmOffs(SDValue N, SDValue &Out) const {
Hal Finkel2bbc9192012-06-21 20:10:48 +0000126 if (isa<ConstantSDNode>(N) || N.getOpcode() == PPCISD::Lo ||
127 N.getOpcode() == ISD::TargetGlobalAddress) {
Hal Finkelac81cc32012-06-19 02:34:32 +0000128 Out = N;
129 return true;
130 }
131
132 return false;
133 }
134
135 /// SelectAddrIdxOffs - Return true if the operand is valid for a preinc
136 /// index field. Because preinc imms have already been validated, just
137 /// accept it.
138 bool SelectAddrIdxOffs(SDValue N, SDValue &Out) const {
Hal Finkel2bbc9192012-06-21 20:10:48 +0000139 if (isa<ConstantSDNode>(N) || N.getOpcode() == PPCISD::Lo ||
140 N.getOpcode() == ISD::TargetGlobalAddress)
141 return false;
142
Chris Lattner74531e42006-11-16 00:41:37 +0000143 Out = N;
144 return true;
145 }
Andrew Trick6e8f4c42010-12-24 04:28:06 +0000146
Nate Begeman7fd1edd2005-12-19 23:25:09 +0000147 /// SelectAddrIdx - Given the specified addressed, check to see if it can be
148 /// represented as an indexed [r+r] operation. Returns false if it can
149 /// be represented by [r+imm], which are preferred.
Chris Lattner52a261b2010-09-21 20:31:19 +0000150 bool SelectAddrIdx(SDValue N, SDValue &Base, SDValue &Index) {
Chris Lattnerfc5b1ab2006-11-08 02:15:41 +0000151 return PPCLowering.SelectAddressRegReg(N, Base, Index, *CurDAG);
152 }
Andrew Trick6e8f4c42010-12-24 04:28:06 +0000153
Nate Begeman7fd1edd2005-12-19 23:25:09 +0000154 /// SelectAddrIdxOnly - Given the specified addressed, force it to be
155 /// represented as an indexed [r+r] operation.
Chris Lattner52a261b2010-09-21 20:31:19 +0000156 bool SelectAddrIdxOnly(SDValue N, SDValue &Base, SDValue &Index) {
Chris Lattnerfc5b1ab2006-11-08 02:15:41 +0000157 return PPCLowering.SelectAddressRegRegOnly(N, Base, Index, *CurDAG);
158 }
Chris Lattner9944b762005-08-21 22:31:09 +0000159
Chris Lattnere5ba5802006-03-22 05:26:03 +0000160 /// SelectAddrImmShift - Returns true if the address N can be represented by
161 /// a base register plus a signed 14-bit displacement [r+imm*4]. Suitable
162 /// for use by STD and friends.
Chris Lattner52a261b2010-09-21 20:31:19 +0000163 bool SelectAddrImmShift(SDValue N, SDValue &Disp, SDValue &Base) {
Chris Lattnerfc5b1ab2006-11-08 02:15:41 +0000164 return PPCLowering.SelectAddressRegImmShift(N, Disp, Base, *CurDAG);
165 }
Andrew Trick6e8f4c42010-12-24 04:28:06 +0000166
Chris Lattnere5d88612006-02-24 02:13:12 +0000167 /// SelectInlineAsmMemoryOperand - Implement addressing mode selection for
Dale Johannesen5cfd4dd2009-08-18 00:18:39 +0000168 /// inline asm expressions. It is always correct to compute the value into
169 /// a register. The case of adding a (possibly relocatable) constant to a
170 /// register can be improved, but it is wrong to substitute Reg+Reg for
171 /// Reg in an asm, because the load or store opcode would have to change.
172 virtual bool SelectInlineAsmMemoryOperand(const SDValue &Op,
Chris Lattnere5d88612006-02-24 02:13:12 +0000173 char ConstraintCode,
Dan Gohmanf350b272008-08-23 02:25:05 +0000174 std::vector<SDValue> &OutOps) {
Dale Johannesen5cfd4dd2009-08-18 00:18:39 +0000175 OutOps.push_back(Op);
Chris Lattnere5d88612006-02-24 02:13:12 +0000176 return false;
177 }
Andrew Trick6e8f4c42010-12-24 04:28:06 +0000178
Dan Gohmanad2afc22009-07-31 18:16:33 +0000179 void InsertVRSaveCode(MachineFunction &MF);
Chris Lattner4bb18952006-03-16 18:25:23 +0000180
Chris Lattnera5a91b12005-08-17 19:33:03 +0000181 virtual const char *getPassName() const {
182 return "PowerPC DAG->DAG Pattern Instruction Selection";
Andrew Trick6e8f4c42010-12-24 04:28:06 +0000183 }
184
Chris Lattneraf165382005-09-13 22:03:06 +0000185// Include the pieces autogenerated from the target description.
Chris Lattner4c7b43b2005-10-14 23:37:35 +0000186#include "PPCGenDAGISel.inc"
Andrew Trick6e8f4c42010-12-24 04:28:06 +0000187
Chris Lattnerbd937b92005-10-06 18:45:51 +0000188private:
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000189 SDNode *SelectSETCC(SDNode *N);
Chris Lattnera5a91b12005-08-17 19:33:03 +0000190 };
191}
192
Chris Lattner4bb18952006-03-16 18:25:23 +0000193/// InsertVRSaveCode - Once the entire function has been instruction selected,
194/// all virtual registers are created and all machine instructions are built,
195/// check to see if we need to save/restore VRSAVE. If so, do it.
Dan Gohmanad2afc22009-07-31 18:16:33 +0000196void PPCDAGToDAGISel::InsertVRSaveCode(MachineFunction &Fn) {
Chris Lattner1877ec92006-03-13 21:52:10 +0000197 // Check to see if this function uses vector registers, which means we have to
Andrew Trick6e8f4c42010-12-24 04:28:06 +0000198 // save and restore the VRSAVE register and update it with the regs we use.
Chris Lattner1877ec92006-03-13 21:52:10 +0000199 //
Dan Gohmanf451cb82010-02-10 16:03:48 +0000200 // In this case, there will be virtual registers of vector type created
Chris Lattner1877ec92006-03-13 21:52:10 +0000201 // by the scheduler. Detect them now.
Chris Lattner1877ec92006-03-13 21:52:10 +0000202 bool HasVectorVReg = false;
Jakob Stoklund Olesenb2581352011-01-08 23:11:11 +0000203 for (unsigned i = 0, e = RegInfo->getNumVirtRegs(); i != e; ++i) {
204 unsigned Reg = TargetRegisterInfo::index2VirtReg(i);
205 if (RegInfo->getRegClass(Reg) == &PPC::VRRCRegClass) {
Chris Lattner1877ec92006-03-13 21:52:10 +0000206 HasVectorVReg = true;
207 break;
208 }
Jakob Stoklund Olesenb2581352011-01-08 23:11:11 +0000209 }
Chris Lattner4bb18952006-03-16 18:25:23 +0000210 if (!HasVectorVReg) return; // nothing to do.
Andrew Trick6e8f4c42010-12-24 04:28:06 +0000211
Chris Lattner1877ec92006-03-13 21:52:10 +0000212 // If we have a vector register, we want to emit code into the entry and exit
213 // blocks to save and restore the VRSAVE register. We do this here (instead
214 // of marking all vector instructions as clobbering VRSAVE) for two reasons:
215 //
216 // 1. This (trivially) reduces the load on the register allocator, by not
217 // having to represent the live range of the VRSAVE register.
218 // 2. This (more significantly) allows us to create a temporary virtual
219 // register to hold the saved VRSAVE value, allowing this temporary to be
220 // register allocated, instead of forcing it to be spilled to the stack.
Chris Lattner4bb18952006-03-16 18:25:23 +0000221
222 // Create two vregs - one to hold the VRSAVE register that is live-in to the
223 // function and one for the value after having bits or'd into it.
Chris Lattner84bc5422007-12-31 04:13:23 +0000224 unsigned InVRSAVE = RegInfo->createVirtualRegister(&PPC::GPRCRegClass);
225 unsigned UpdatedVRSAVE = RegInfo->createVirtualRegister(&PPC::GPRCRegClass);
Andrew Trick6e8f4c42010-12-24 04:28:06 +0000226
Evan Chengc0f64ff2006-11-27 23:37:22 +0000227 const TargetInstrInfo &TII = *TM.getInstrInfo();
Chris Lattner4bb18952006-03-16 18:25:23 +0000228 MachineBasicBlock &EntryBB = *Fn.begin();
Chris Lattnerc7f3ace2010-04-02 20:16:16 +0000229 DebugLoc dl;
Chris Lattner4bb18952006-03-16 18:25:23 +0000230 // Emit the following code into the entry block:
231 // InVRSAVE = MFVRSAVE
232 // UpdatedVRSAVE = UPDATE_VRSAVE InVRSAVE
233 // MTVRSAVE UpdatedVRSAVE
234 MachineBasicBlock::iterator IP = EntryBB.begin(); // Insert Point
Dale Johannesen536a2f12009-02-13 02:27:39 +0000235 BuildMI(EntryBB, IP, dl, TII.get(PPC::MFVRSAVE), InVRSAVE);
236 BuildMI(EntryBB, IP, dl, TII.get(PPC::UPDATE_VRSAVE),
Chris Lattner69244302008-01-07 01:56:04 +0000237 UpdatedVRSAVE).addReg(InVRSAVE);
Dale Johannesen536a2f12009-02-13 02:27:39 +0000238 BuildMI(EntryBB, IP, dl, TII.get(PPC::MTVRSAVE)).addReg(UpdatedVRSAVE);
Andrew Trick6e8f4c42010-12-24 04:28:06 +0000239
Chris Lattner4bb18952006-03-16 18:25:23 +0000240 // Find all return blocks, outputting a restore in each epilog.
Chris Lattner4bb18952006-03-16 18:25:23 +0000241 for (MachineFunction::iterator BB = Fn.begin(), E = Fn.end(); BB != E; ++BB) {
Evan Cheng5a96b3d2011-12-07 07:15:52 +0000242 if (!BB->empty() && BB->back().isReturn()) {
Chris Lattner4bb18952006-03-16 18:25:23 +0000243 IP = BB->end(); --IP;
Andrew Trick6e8f4c42010-12-24 04:28:06 +0000244
Chris Lattner4bb18952006-03-16 18:25:23 +0000245 // Skip over all terminator instructions, which are part of the return
246 // sequence.
247 MachineBasicBlock::iterator I2 = IP;
Evan Cheng5a96b3d2011-12-07 07:15:52 +0000248 while (I2 != BB->begin() && (--I2)->isTerminator())
Chris Lattner4bb18952006-03-16 18:25:23 +0000249 IP = I2;
Andrew Trick6e8f4c42010-12-24 04:28:06 +0000250
Chris Lattner4bb18952006-03-16 18:25:23 +0000251 // Emit: MTVRSAVE InVRSave
Dale Johannesen536a2f12009-02-13 02:27:39 +0000252 BuildMI(*BB, IP, dl, TII.get(PPC::MTVRSAVE)).addReg(InVRSAVE);
Andrew Trick6e8f4c42010-12-24 04:28:06 +0000253 }
Chris Lattner1877ec92006-03-13 21:52:10 +0000254 }
Chris Lattnerbd937b92005-10-06 18:45:51 +0000255}
Chris Lattner6cd40d52005-09-03 01:17:22 +0000256
Chris Lattner4bb18952006-03-16 18:25:23 +0000257
Chris Lattner4416f1a2005-08-19 22:38:53 +0000258/// getGlobalBaseReg - Output the instructions required to put the
259/// base address to use for accessing globals into a register.
260///
Evan Cheng9ade2182006-08-26 05:34:46 +0000261SDNode *PPCDAGToDAGISel::getGlobalBaseReg() {
Chris Lattner4416f1a2005-08-19 22:38:53 +0000262 if (!GlobalBaseReg) {
Evan Chengc0f64ff2006-11-27 23:37:22 +0000263 const TargetInstrInfo &TII = *TM.getInstrInfo();
Chris Lattner4416f1a2005-08-19 22:38:53 +0000264 // Insert the set of GlobalBaseReg into the first MBB of the function
Dan Gohmanbd51c672009-08-15 02:07:36 +0000265 MachineBasicBlock &FirstMBB = MF->front();
Chris Lattner4416f1a2005-08-19 22:38:53 +0000266 MachineBasicBlock::iterator MBBI = FirstMBB.begin();
Chris Lattnerc7f3ace2010-04-02 20:16:16 +0000267 DebugLoc dl;
Chris Lattnerc08f9022006-06-27 00:04:13 +0000268
Owen Anderson825b72b2009-08-11 20:47:22 +0000269 if (PPCLowering.getPointerTy() == MVT::i32) {
Craig Topperc9099502012-04-20 06:31:50 +0000270 GlobalBaseReg = RegInfo->createVirtualRegister(&PPC::GPRCRegClass);
Cameron Zwarich0113e4e2011-05-19 02:56:28 +0000271 BuildMI(FirstMBB, MBBI, dl, TII.get(PPC::MovePCtoLR));
Dale Johannesen536a2f12009-02-13 02:27:39 +0000272 BuildMI(FirstMBB, MBBI, dl, TII.get(PPC::MFLR), GlobalBaseReg);
Chris Lattnerd1043422006-11-14 18:43:11 +0000273 } else {
Craig Topperc9099502012-04-20 06:31:50 +0000274 GlobalBaseReg = RegInfo->createVirtualRegister(&PPC::G8RCRegClass);
Cameron Zwarich0113e4e2011-05-19 02:56:28 +0000275 BuildMI(FirstMBB, MBBI, dl, TII.get(PPC::MovePCtoLR8));
Dale Johannesen536a2f12009-02-13 02:27:39 +0000276 BuildMI(FirstMBB, MBBI, dl, TII.get(PPC::MFLR8), GlobalBaseReg);
Chris Lattnerd1043422006-11-14 18:43:11 +0000277 }
Chris Lattner4416f1a2005-08-19 22:38:53 +0000278 }
Gabor Greif93c53e52008-08-31 15:37:04 +0000279 return CurDAG->getRegister(GlobalBaseReg,
280 PPCLowering.getPointerTy()).getNode();
Chris Lattnerc08f9022006-06-27 00:04:13 +0000281}
282
283/// isIntS16Immediate - This method tests to see if the node is either a 32-bit
284/// or 64-bit immediate, and if the value can be accurately represented as a
285/// sign extension from a 16-bit value. If so, this returns true and the
286/// immediate.
287static bool isIntS16Immediate(SDNode *N, short &Imm) {
288 if (N->getOpcode() != ISD::Constant)
289 return false;
290
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000291 Imm = (short)cast<ConstantSDNode>(N)->getZExtValue();
Owen Anderson825b72b2009-08-11 20:47:22 +0000292 if (N->getValueType(0) == MVT::i32)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000293 return Imm == (int32_t)cast<ConstantSDNode>(N)->getZExtValue();
Chris Lattnerc08f9022006-06-27 00:04:13 +0000294 else
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000295 return Imm == (int64_t)cast<ConstantSDNode>(N)->getZExtValue();
Chris Lattnerc08f9022006-06-27 00:04:13 +0000296}
297
Dan Gohman475871a2008-07-27 21:46:04 +0000298static bool isIntS16Immediate(SDValue Op, short &Imm) {
Gabor Greifba36cb52008-08-28 21:40:38 +0000299 return isIntS16Immediate(Op.getNode(), Imm);
Chris Lattner4416f1a2005-08-19 22:38:53 +0000300}
301
302
Chris Lattnerc08f9022006-06-27 00:04:13 +0000303/// isInt32Immediate - This method tests to see if the node is a 32-bit constant
304/// operand. If so Imm will receive the 32-bit value.
305static bool isInt32Immediate(SDNode *N, unsigned &Imm) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000306 if (N->getOpcode() == ISD::Constant && N->getValueType(0) == MVT::i32) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000307 Imm = cast<ConstantSDNode>(N)->getZExtValue();
Nate Begeman0f3257a2005-08-18 05:00:13 +0000308 return true;
309 }
310 return false;
311}
312
Chris Lattnerc08f9022006-06-27 00:04:13 +0000313/// isInt64Immediate - This method tests to see if the node is a 64-bit constant
314/// operand. If so Imm will receive the 64-bit value.
315static bool isInt64Immediate(SDNode *N, uint64_t &Imm) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000316 if (N->getOpcode() == ISD::Constant && N->getValueType(0) == MVT::i64) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000317 Imm = cast<ConstantSDNode>(N)->getZExtValue();
Chris Lattnerc08f9022006-06-27 00:04:13 +0000318 return true;
319 }
320 return false;
321}
322
323// isInt32Immediate - This method tests to see if a constant operand.
324// If so Imm will receive the 32 bit value.
Dan Gohman475871a2008-07-27 21:46:04 +0000325static bool isInt32Immediate(SDValue N, unsigned &Imm) {
Gabor Greifba36cb52008-08-28 21:40:38 +0000326 return isInt32Immediate(N.getNode(), Imm);
Chris Lattnerc08f9022006-06-27 00:04:13 +0000327}
328
329
330// isOpcWithIntImmediate - This method tests to see if the node is a specific
331// opcode and that it has a immediate integer right operand.
332// If so Imm will receive the 32 bit value.
333static bool isOpcWithIntImmediate(SDNode *N, unsigned Opc, unsigned& Imm) {
Gabor Greif93c53e52008-08-31 15:37:04 +0000334 return N->getOpcode() == Opc
335 && isInt32Immediate(N->getOperand(1).getNode(), Imm);
Chris Lattnerc08f9022006-06-27 00:04:13 +0000336}
337
Nate Begemanf42f1332006-09-22 05:01:56 +0000338bool PPCDAGToDAGISel::isRunOfOnes(unsigned Val, unsigned &MB, unsigned &ME) {
Nate Begemancffc32b2005-08-18 07:30:46 +0000339 if (isShiftedMask_32(Val)) {
340 // look for the first non-zero bit
341 MB = CountLeadingZeros_32(Val);
342 // look for the first zero bit after the run of ones
343 ME = CountLeadingZeros_32((Val - 1) ^ Val);
344 return true;
Chris Lattner2fe76e52005-08-25 04:47:18 +0000345 } else {
346 Val = ~Val; // invert mask
347 if (isShiftedMask_32(Val)) {
348 // effectively look for the first zero bit
349 ME = CountLeadingZeros_32(Val) - 1;
350 // effectively look for the first one bit after the run of zeros
351 MB = CountLeadingZeros_32((Val - 1) ^ Val) + 1;
352 return true;
353 }
Nate Begemancffc32b2005-08-18 07:30:46 +0000354 }
355 // no run present
356 return false;
357}
358
Andrew Trick6e8f4c42010-12-24 04:28:06 +0000359bool PPCDAGToDAGISel::isRotateAndMask(SDNode *N, unsigned Mask,
360 bool isShiftMask, unsigned &SH,
Nate Begemanf42f1332006-09-22 05:01:56 +0000361 unsigned &MB, unsigned &ME) {
Nate Begemanda32c9e2005-10-19 00:05:37 +0000362 // Don't even go down this path for i64, since different logic will be
363 // necessary for rldicl/rldicr/rldimi.
Owen Anderson825b72b2009-08-11 20:47:22 +0000364 if (N->getValueType(0) != MVT::i32)
Nate Begemanda32c9e2005-10-19 00:05:37 +0000365 return false;
366
Nate Begemancffc32b2005-08-18 07:30:46 +0000367 unsigned Shift = 32;
368 unsigned Indeterminant = ~0; // bit mask marking indeterminant results
369 unsigned Opcode = N->getOpcode();
Chris Lattner15055732005-08-30 00:59:16 +0000370 if (N->getNumOperands() != 2 ||
Gabor Greifba36cb52008-08-28 21:40:38 +0000371 !isInt32Immediate(N->getOperand(1).getNode(), Shift) || (Shift > 31))
Nate Begemancffc32b2005-08-18 07:30:46 +0000372 return false;
Andrew Trick6e8f4c42010-12-24 04:28:06 +0000373
Nate Begemancffc32b2005-08-18 07:30:46 +0000374 if (Opcode == ISD::SHL) {
375 // apply shift left to mask if it comes first
Dale Johannesenb60d5192009-11-24 01:09:07 +0000376 if (isShiftMask) Mask = Mask << Shift;
Nate Begemancffc32b2005-08-18 07:30:46 +0000377 // determine which bits are made indeterminant by shift
378 Indeterminant = ~(0xFFFFFFFFu << Shift);
Andrew Trick6e8f4c42010-12-24 04:28:06 +0000379 } else if (Opcode == ISD::SRL) {
Nate Begemancffc32b2005-08-18 07:30:46 +0000380 // apply shift right to mask if it comes first
Dale Johannesenb60d5192009-11-24 01:09:07 +0000381 if (isShiftMask) Mask = Mask >> Shift;
Nate Begemancffc32b2005-08-18 07:30:46 +0000382 // determine which bits are made indeterminant by shift
383 Indeterminant = ~(0xFFFFFFFFu >> Shift);
384 // adjust for the left rotate
385 Shift = 32 - Shift;
Nate Begemanf42f1332006-09-22 05:01:56 +0000386 } else if (Opcode == ISD::ROTL) {
387 Indeterminant = 0;
Nate Begemancffc32b2005-08-18 07:30:46 +0000388 } else {
389 return false;
390 }
Andrew Trick6e8f4c42010-12-24 04:28:06 +0000391
Nate Begemancffc32b2005-08-18 07:30:46 +0000392 // if the mask doesn't intersect any Indeterminant bits
393 if (Mask && !(Mask & Indeterminant)) {
Chris Lattner0949ed52006-05-12 16:29:37 +0000394 SH = Shift & 31;
Nate Begemancffc32b2005-08-18 07:30:46 +0000395 // make sure the mask is still a mask (wrap arounds may not be)
396 return isRunOfOnes(Mask, MB, ME);
397 }
398 return false;
399}
400
Nate Begeman02b88a42005-08-19 00:38:14 +0000401/// SelectBitfieldInsert - turn an or of two masked values into
402/// the rotate left word immediate then mask insert (rlwimi) instruction.
Nate Begeman1d9d7422005-10-18 00:28:58 +0000403SDNode *PPCDAGToDAGISel::SelectBitfieldInsert(SDNode *N) {
Dan Gohman475871a2008-07-27 21:46:04 +0000404 SDValue Op0 = N->getOperand(0);
405 SDValue Op1 = N->getOperand(1);
Dale Johannesened2eee62009-02-06 01:31:28 +0000406 DebugLoc dl = N->getDebugLoc();
Andrew Trick6e8f4c42010-12-24 04:28:06 +0000407
Dan Gohmanb3564aa2008-02-27 01:23:58 +0000408 APInt LKZ, LKO, RKZ, RKO;
Rafael Espindola26c8dcc2012-04-04 12:51:34 +0000409 CurDAG->ComputeMaskedBits(Op0, LKZ, LKO);
410 CurDAG->ComputeMaskedBits(Op1, RKZ, RKO);
Andrew Trick6e8f4c42010-12-24 04:28:06 +0000411
Dan Gohmanb3564aa2008-02-27 01:23:58 +0000412 unsigned TargetMask = LKZ.getZExtValue();
413 unsigned InsertMask = RKZ.getZExtValue();
Andrew Trick6e8f4c42010-12-24 04:28:06 +0000414
Nate Begeman4667f2c2006-05-08 17:38:32 +0000415 if ((TargetMask | InsertMask) == 0xFFFFFFFF) {
416 unsigned Op0Opc = Op0.getOpcode();
417 unsigned Op1Opc = Op1.getOpcode();
418 unsigned Value, SH = 0;
419 TargetMask = ~TargetMask;
420 InsertMask = ~InsertMask;
Nate Begeman77f361f2006-05-07 00:23:38 +0000421
Nate Begeman4667f2c2006-05-08 17:38:32 +0000422 // If the LHS has a foldable shift and the RHS does not, then swap it to the
423 // RHS so that we can fold the shift into the insert.
Nate Begeman77f361f2006-05-07 00:23:38 +0000424 if (Op0Opc == ISD::AND && Op1Opc == ISD::AND) {
425 if (Op0.getOperand(0).getOpcode() == ISD::SHL ||
426 Op0.getOperand(0).getOpcode() == ISD::SRL) {
427 if (Op1.getOperand(0).getOpcode() != ISD::SHL &&
428 Op1.getOperand(0).getOpcode() != ISD::SRL) {
429 std::swap(Op0, Op1);
430 std::swap(Op0Opc, Op1Opc);
Nate Begeman4667f2c2006-05-08 17:38:32 +0000431 std::swap(TargetMask, InsertMask);
Nate Begeman77f361f2006-05-07 00:23:38 +0000432 }
Nate Begeman02b88a42005-08-19 00:38:14 +0000433 }
Nate Begeman4667f2c2006-05-08 17:38:32 +0000434 } else if (Op0Opc == ISD::SHL || Op0Opc == ISD::SRL) {
435 if (Op1Opc == ISD::AND && Op1.getOperand(0).getOpcode() != ISD::SHL &&
436 Op1.getOperand(0).getOpcode() != ISD::SRL) {
437 std::swap(Op0, Op1);
438 std::swap(Op0Opc, Op1Opc);
439 std::swap(TargetMask, InsertMask);
440 }
Nate Begeman02b88a42005-08-19 00:38:14 +0000441 }
Andrew Trick6e8f4c42010-12-24 04:28:06 +0000442
Nate Begeman77f361f2006-05-07 00:23:38 +0000443 unsigned MB, ME;
Chris Lattner0949ed52006-05-12 16:29:37 +0000444 if (InsertMask && isRunOfOnes(InsertMask, MB, ME)) {
Dale Johannesen5ca12462009-11-20 22:16:40 +0000445 SDValue Tmp1, Tmp2;
Nate Begeman77f361f2006-05-07 00:23:38 +0000446
447 if ((Op1Opc == ISD::SHL || Op1Opc == ISD::SRL) &&
Chris Lattnerc08f9022006-06-27 00:04:13 +0000448 isInt32Immediate(Op1.getOperand(1), Value)) {
Nate Begeman77f361f2006-05-07 00:23:38 +0000449 Op1 = Op1.getOperand(0);
450 SH = (Op1Opc == ISD::SHL) ? Value : 32 - Value;
451 }
452 if (Op1Opc == ISD::AND) {
453 unsigned SHOpc = Op1.getOperand(0).getOpcode();
454 if ((SHOpc == ISD::SHL || SHOpc == ISD::SRL) &&
Chris Lattnerc08f9022006-06-27 00:04:13 +0000455 isInt32Immediate(Op1.getOperand(0).getOperand(1), Value)) {
Nate Begeman77f361f2006-05-07 00:23:38 +0000456 Op1 = Op1.getOperand(0).getOperand(0);
457 SH = (SHOpc == ISD::SHL) ? Value : 32 - Value;
458 } else {
459 Op1 = Op1.getOperand(0);
460 }
461 }
Dale Johannesen5ca12462009-11-20 22:16:40 +0000462
Chris Lattner0949ed52006-05-12 16:29:37 +0000463 SH &= 31;
Dale Johannesen5ca12462009-11-20 22:16:40 +0000464 SDValue Ops[] = { Op0, Op1, getI32Imm(SH), getI32Imm(MB),
Evan Cheng0b828e02006-08-27 08:14:06 +0000465 getI32Imm(ME) };
Dan Gohman602b0c82009-09-25 18:54:59 +0000466 return CurDAG->getMachineNode(PPC::RLWIMI, dl, MVT::i32, Ops, 5);
Nate Begeman02b88a42005-08-19 00:38:14 +0000467 }
Nate Begeman02b88a42005-08-19 00:38:14 +0000468 }
469 return 0;
470}
471
Chris Lattner2fbb4572005-08-21 18:50:37 +0000472/// SelectCC - Select a comparison of the specified values with the specified
473/// condition code, returning the CR# of the expression.
Dan Gohman475871a2008-07-27 21:46:04 +0000474SDValue PPCDAGToDAGISel::SelectCC(SDValue LHS, SDValue RHS,
Dale Johannesenf5f5dce2009-02-06 19:16:40 +0000475 ISD::CondCode CC, DebugLoc dl) {
Chris Lattner2fbb4572005-08-21 18:50:37 +0000476 // Always select the LHS.
Chris Lattnerc08f9022006-06-27 00:04:13 +0000477 unsigned Opc;
Andrew Trick6e8f4c42010-12-24 04:28:06 +0000478
Owen Anderson825b72b2009-08-11 20:47:22 +0000479 if (LHS.getValueType() == MVT::i32) {
Chris Lattner529c2332006-06-27 00:10:13 +0000480 unsigned Imm;
Chris Lattner3836dbd2006-09-20 04:25:47 +0000481 if (CC == ISD::SETEQ || CC == ISD::SETNE) {
482 if (isInt32Immediate(RHS, Imm)) {
483 // SETEQ/SETNE comparison with 16-bit immediate, fold it.
Benjamin Kramer34247a02010-03-29 21:13:41 +0000484 if (isUInt<16>(Imm))
Dan Gohman602b0c82009-09-25 18:54:59 +0000485 return SDValue(CurDAG->getMachineNode(PPC::CMPLWI, dl, MVT::i32, LHS,
486 getI32Imm(Imm & 0xFFFF)), 0);
Chris Lattner3836dbd2006-09-20 04:25:47 +0000487 // If this is a 16-bit signed immediate, fold it.
Benjamin Kramer34247a02010-03-29 21:13:41 +0000488 if (isInt<16>((int)Imm))
Dan Gohman602b0c82009-09-25 18:54:59 +0000489 return SDValue(CurDAG->getMachineNode(PPC::CMPWI, dl, MVT::i32, LHS,
490 getI32Imm(Imm & 0xFFFF)), 0);
Andrew Trick6e8f4c42010-12-24 04:28:06 +0000491
Chris Lattner3836dbd2006-09-20 04:25:47 +0000492 // For non-equality comparisons, the default code would materialize the
493 // constant, then compare against it, like this:
494 // lis r2, 4660
Andrew Trick6e8f4c42010-12-24 04:28:06 +0000495 // ori r2, r2, 22136
Chris Lattner3836dbd2006-09-20 04:25:47 +0000496 // cmpw cr0, r3, r2
497 // Since we are just comparing for equality, we can emit this instead:
498 // xoris r0,r3,0x1234
499 // cmplwi cr0,r0,0x5678
500 // beq cr0,L6
Dan Gohman602b0c82009-09-25 18:54:59 +0000501 SDValue Xor(CurDAG->getMachineNode(PPC::XORIS, dl, MVT::i32, LHS,
502 getI32Imm(Imm >> 16)), 0);
503 return SDValue(CurDAG->getMachineNode(PPC::CMPLWI, dl, MVT::i32, Xor,
504 getI32Imm(Imm & 0xFFFF)), 0);
Chris Lattner3836dbd2006-09-20 04:25:47 +0000505 }
506 Opc = PPC::CMPLW;
507 } else if (ISD::isUnsignedIntSetCC(CC)) {
Benjamin Kramer34247a02010-03-29 21:13:41 +0000508 if (isInt32Immediate(RHS, Imm) && isUInt<16>(Imm))
Dan Gohman602b0c82009-09-25 18:54:59 +0000509 return SDValue(CurDAG->getMachineNode(PPC::CMPLWI, dl, MVT::i32, LHS,
510 getI32Imm(Imm & 0xFFFF)), 0);
Chris Lattnerc08f9022006-06-27 00:04:13 +0000511 Opc = PPC::CMPLW;
512 } else {
513 short SImm;
514 if (isIntS16Immediate(RHS, SImm))
Dan Gohman602b0c82009-09-25 18:54:59 +0000515 return SDValue(CurDAG->getMachineNode(PPC::CMPWI, dl, MVT::i32, LHS,
516 getI32Imm((int)SImm & 0xFFFF)),
Chris Lattnerc08f9022006-06-27 00:04:13 +0000517 0);
518 Opc = PPC::CMPW;
519 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000520 } else if (LHS.getValueType() == MVT::i64) {
Chris Lattnerc08f9022006-06-27 00:04:13 +0000521 uint64_t Imm;
Chris Lattner71176242006-09-20 04:33:27 +0000522 if (CC == ISD::SETEQ || CC == ISD::SETNE) {
Gabor Greifba36cb52008-08-28 21:40:38 +0000523 if (isInt64Immediate(RHS.getNode(), Imm)) {
Chris Lattner71176242006-09-20 04:33:27 +0000524 // SETEQ/SETNE comparison with 16-bit immediate, fold it.
Benjamin Kramer34247a02010-03-29 21:13:41 +0000525 if (isUInt<16>(Imm))
Dan Gohman602b0c82009-09-25 18:54:59 +0000526 return SDValue(CurDAG->getMachineNode(PPC::CMPLDI, dl, MVT::i64, LHS,
527 getI32Imm(Imm & 0xFFFF)), 0);
Chris Lattner71176242006-09-20 04:33:27 +0000528 // If this is a 16-bit signed immediate, fold it.
Benjamin Kramer34247a02010-03-29 21:13:41 +0000529 if (isInt<16>(Imm))
Dan Gohman602b0c82009-09-25 18:54:59 +0000530 return SDValue(CurDAG->getMachineNode(PPC::CMPDI, dl, MVT::i64, LHS,
531 getI32Imm(Imm & 0xFFFF)), 0);
Andrew Trick6e8f4c42010-12-24 04:28:06 +0000532
Chris Lattner71176242006-09-20 04:33:27 +0000533 // For non-equality comparisons, the default code would materialize the
534 // constant, then compare against it, like this:
535 // lis r2, 4660
Andrew Trick6e8f4c42010-12-24 04:28:06 +0000536 // ori r2, r2, 22136
Chris Lattner71176242006-09-20 04:33:27 +0000537 // cmpd cr0, r3, r2
538 // Since we are just comparing for equality, we can emit this instead:
539 // xoris r0,r3,0x1234
540 // cmpldi cr0,r0,0x5678
541 // beq cr0,L6
Benjamin Kramer34247a02010-03-29 21:13:41 +0000542 if (isUInt<32>(Imm)) {
Dan Gohman602b0c82009-09-25 18:54:59 +0000543 SDValue Xor(CurDAG->getMachineNode(PPC::XORIS8, dl, MVT::i64, LHS,
544 getI64Imm(Imm >> 16)), 0);
545 return SDValue(CurDAG->getMachineNode(PPC::CMPLDI, dl, MVT::i64, Xor,
546 getI64Imm(Imm & 0xFFFF)), 0);
Chris Lattner71176242006-09-20 04:33:27 +0000547 }
548 }
549 Opc = PPC::CMPLD;
550 } else if (ISD::isUnsignedIntSetCC(CC)) {
Benjamin Kramer34247a02010-03-29 21:13:41 +0000551 if (isInt64Immediate(RHS.getNode(), Imm) && isUInt<16>(Imm))
Dan Gohman602b0c82009-09-25 18:54:59 +0000552 return SDValue(CurDAG->getMachineNode(PPC::CMPLDI, dl, MVT::i64, LHS,
553 getI64Imm(Imm & 0xFFFF)), 0);
Chris Lattnerc08f9022006-06-27 00:04:13 +0000554 Opc = PPC::CMPLD;
555 } else {
556 short SImm;
557 if (isIntS16Immediate(RHS, SImm))
Dan Gohman602b0c82009-09-25 18:54:59 +0000558 return SDValue(CurDAG->getMachineNode(PPC::CMPDI, dl, MVT::i64, LHS,
559 getI64Imm(SImm & 0xFFFF)),
Chris Lattnerc08f9022006-06-27 00:04:13 +0000560 0);
561 Opc = PPC::CMPD;
562 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000563 } else if (LHS.getValueType() == MVT::f32) {
Chris Lattnerc08f9022006-06-27 00:04:13 +0000564 Opc = PPC::FCMPUS;
Chris Lattner2fbb4572005-08-21 18:50:37 +0000565 } else {
Owen Anderson825b72b2009-08-11 20:47:22 +0000566 assert(LHS.getValueType() == MVT::f64 && "Unknown vt!");
Chris Lattnerc08f9022006-06-27 00:04:13 +0000567 Opc = PPC::FCMPUD;
Chris Lattner2fbb4572005-08-21 18:50:37 +0000568 }
Dan Gohman602b0c82009-09-25 18:54:59 +0000569 return SDValue(CurDAG->getMachineNode(Opc, dl, MVT::i32, LHS, RHS), 0);
Chris Lattner2fbb4572005-08-21 18:50:37 +0000570}
571
Chris Lattnerdf4ed632006-11-17 22:10:59 +0000572static PPC::Predicate getPredicateForSetCC(ISD::CondCode CC) {
Chris Lattner2fbb4572005-08-21 18:50:37 +0000573 switch (CC) {
Chris Lattner5d634ce2006-05-25 16:54:16 +0000574 case ISD::SETUEQ:
Dale Johannesen53e4e442008-11-07 22:54:33 +0000575 case ISD::SETONE:
576 case ISD::SETOLE:
577 case ISD::SETOGE:
Torok Edwinc23197a2009-07-14 16:55:14 +0000578 llvm_unreachable("Should be lowered by legalize!");
579 default: llvm_unreachable("Unknown condition!");
Dale Johannesen53e4e442008-11-07 22:54:33 +0000580 case ISD::SETOEQ:
Chris Lattnerdf4ed632006-11-17 22:10:59 +0000581 case ISD::SETEQ: return PPC::PRED_EQ;
Chris Lattner5d634ce2006-05-25 16:54:16 +0000582 case ISD::SETUNE:
Chris Lattnerdf4ed632006-11-17 22:10:59 +0000583 case ISD::SETNE: return PPC::PRED_NE;
Dale Johannesen53e4e442008-11-07 22:54:33 +0000584 case ISD::SETOLT:
Chris Lattnerdf4ed632006-11-17 22:10:59 +0000585 case ISD::SETLT: return PPC::PRED_LT;
Chris Lattner2fbb4572005-08-21 18:50:37 +0000586 case ISD::SETULE:
Chris Lattnerdf4ed632006-11-17 22:10:59 +0000587 case ISD::SETLE: return PPC::PRED_LE;
Dale Johannesen53e4e442008-11-07 22:54:33 +0000588 case ISD::SETOGT:
Chris Lattnerdf4ed632006-11-17 22:10:59 +0000589 case ISD::SETGT: return PPC::PRED_GT;
Chris Lattner2fbb4572005-08-21 18:50:37 +0000590 case ISD::SETUGE:
Chris Lattnerdf4ed632006-11-17 22:10:59 +0000591 case ISD::SETGE: return PPC::PRED_GE;
Chris Lattnerdf4ed632006-11-17 22:10:59 +0000592 case ISD::SETO: return PPC::PRED_NU;
593 case ISD::SETUO: return PPC::PRED_UN;
Dale Johannesen53e4e442008-11-07 22:54:33 +0000594 // These two are invalid for floating point. Assume we have int.
595 case ISD::SETULT: return PPC::PRED_LT;
596 case ISD::SETUGT: return PPC::PRED_GT;
Chris Lattner2fbb4572005-08-21 18:50:37 +0000597 }
Chris Lattner2fbb4572005-08-21 18:50:37 +0000598}
599
Chris Lattner64906a02005-08-25 20:08:18 +0000600/// getCRIdxForSetCC - Return the index of the condition register field
601/// associated with the SetCC condition, and whether or not the field is
602/// treated as inverted. That is, lt = 0; ge = 0 inverted.
Chris Lattnerfe39edd2008-01-08 06:46:30 +0000603///
604/// If this returns with Other != -1, then the returned comparison is an or of
605/// two simpler comparisons. In this case, Invert is guaranteed to be false.
606static unsigned getCRIdxForSetCC(ISD::CondCode CC, bool &Invert, int &Other) {
607 Invert = false;
608 Other = -1;
Chris Lattner64906a02005-08-25 20:08:18 +0000609 switch (CC) {
Torok Edwinc23197a2009-07-14 16:55:14 +0000610 default: llvm_unreachable("Unknown condition!");
Chris Lattnerfe39edd2008-01-08 06:46:30 +0000611 case ISD::SETOLT:
612 case ISD::SETLT: return 0; // Bit #0 = SETOLT
613 case ISD::SETOGT:
614 case ISD::SETGT: return 1; // Bit #1 = SETOGT
615 case ISD::SETOEQ:
616 case ISD::SETEQ: return 2; // Bit #2 = SETOEQ
617 case ISD::SETUO: return 3; // Bit #3 = SETUO
Chris Lattner64906a02005-08-25 20:08:18 +0000618 case ISD::SETUGE:
Chris Lattnerfe39edd2008-01-08 06:46:30 +0000619 case ISD::SETGE: Invert = true; return 0; // !Bit #0 = SETUGE
Chris Lattner64906a02005-08-25 20:08:18 +0000620 case ISD::SETULE:
Chris Lattnerfe39edd2008-01-08 06:46:30 +0000621 case ISD::SETLE: Invert = true; return 1; // !Bit #1 = SETULE
Chris Lattner8e2a04e2006-05-25 18:06:16 +0000622 case ISD::SETUNE:
Chris Lattnerfe39edd2008-01-08 06:46:30 +0000623 case ISD::SETNE: Invert = true; return 2; // !Bit #2 = SETUNE
624 case ISD::SETO: Invert = true; return 3; // !Bit #3 = SETO
Andrew Trick6e8f4c42010-12-24 04:28:06 +0000625 case ISD::SETUEQ:
626 case ISD::SETOGE:
627 case ISD::SETOLE:
Dale Johannesen53e4e442008-11-07 22:54:33 +0000628 case ISD::SETONE:
Torok Edwinc23197a2009-07-14 16:55:14 +0000629 llvm_unreachable("Invalid branch code: should be expanded by legalize");
Dale Johannesen53e4e442008-11-07 22:54:33 +0000630 // These are invalid for floating point. Assume integer.
631 case ISD::SETULT: return 0;
632 case ISD::SETUGT: return 1;
Chris Lattner64906a02005-08-25 20:08:18 +0000633 }
Chris Lattner64906a02005-08-25 20:08:18 +0000634}
Chris Lattner9944b762005-08-21 22:31:09 +0000635
Adhemerval Zanella5f41fd62012-10-30 13:50:19 +0000636// getVCmpInst: return the vector compare instruction for the specified
637// vector type and condition code. Since this is for altivec specific code,
638// only support the altivec types (v16i8, v8i16, v4i32, and v4f32).
639static unsigned int getVCmpInst(MVT::SimpleValueType VecVT, ISD::CondCode CC) {
640 switch (CC) {
641 case ISD::SETEQ:
642 case ISD::SETUEQ:
643 case ISD::SETNE:
644 case ISD::SETUNE:
645 if (VecVT == MVT::v16i8)
646 return PPC::VCMPEQUB;
647 else if (VecVT == MVT::v8i16)
648 return PPC::VCMPEQUH;
649 else if (VecVT == MVT::v4i32)
650 return PPC::VCMPEQUW;
651 // v4f32 != v4f32 could be translate to unordered not equal
652 else if (VecVT == MVT::v4f32)
653 return PPC::VCMPEQFP;
654 break;
655 case ISD::SETLT:
656 case ISD::SETGT:
657 case ISD::SETLE:
658 case ISD::SETGE:
659 if (VecVT == MVT::v16i8)
660 return PPC::VCMPGTSB;
661 else if (VecVT == MVT::v8i16)
662 return PPC::VCMPGTSH;
663 else if (VecVT == MVT::v4i32)
664 return PPC::VCMPGTSW;
665 else if (VecVT == MVT::v4f32)
666 return PPC::VCMPGTFP;
667 break;
668 case ISD::SETULT:
669 case ISD::SETUGT:
670 case ISD::SETUGE:
671 case ISD::SETULE:
672 if (VecVT == MVT::v16i8)
673 return PPC::VCMPGTUB;
674 else if (VecVT == MVT::v8i16)
675 return PPC::VCMPGTUH;
676 else if (VecVT == MVT::v4i32)
677 return PPC::VCMPGTUW;
678 break;
679 case ISD::SETOEQ:
680 if (VecVT == MVT::v4f32)
681 return PPC::VCMPEQFP;
682 break;
683 case ISD::SETOLT:
684 case ISD::SETOGT:
685 case ISD::SETOLE:
686 if (VecVT == MVT::v4f32)
687 return PPC::VCMPGTFP;
688 break;
689 case ISD::SETOGE:
690 if (VecVT == MVT::v4f32)
691 return PPC::VCMPGEFP;
692 break;
693 default:
694 break;
695 }
696 llvm_unreachable("Invalid integer vector compare condition");
697}
698
699// getVCmpEQInst: return the equal compare instruction for the specified vector
700// type. Since this is for altivec specific code, only support the altivec
701// types (v16i8, v8i16, v4i32, and v4f32).
702static unsigned int getVCmpEQInst(MVT::SimpleValueType VecVT) {
703 switch (VecVT) {
704 case MVT::v16i8:
705 return PPC::VCMPEQUB;
706 case MVT::v8i16:
707 return PPC::VCMPEQUH;
708 case MVT::v4i32:
709 return PPC::VCMPEQUW;
710 case MVT::v4f32:
711 return PPC::VCMPEQFP;
712 default:
713 llvm_unreachable("Invalid integer vector compare condition");
714 }
715}
716
717
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000718SDNode *PPCDAGToDAGISel::SelectSETCC(SDNode *N) {
Dale Johannesena05dca42009-02-04 23:02:30 +0000719 DebugLoc dl = N->getDebugLoc();
Chris Lattner222adac2005-10-06 19:03:35 +0000720 unsigned Imm;
721 ISD::CondCode CC = cast<CondCodeSDNode>(N->getOperand(2))->get();
Roman Divacky8e9d6722011-06-20 15:28:39 +0000722 EVT PtrVT = CurDAG->getTargetLoweringInfo().getPointerTy();
723 bool isPPC64 = (PtrVT == MVT::i64);
724
Chris Lattnerc08f9022006-06-27 00:04:13 +0000725 if (isInt32Immediate(N->getOperand(1), Imm)) {
Chris Lattner222adac2005-10-06 19:03:35 +0000726 // We can codegen setcc op, imm very efficiently compared to a brcond.
727 // Check for those cases here.
728 // setcc op, 0
729 if (Imm == 0) {
Dan Gohman475871a2008-07-27 21:46:04 +0000730 SDValue Op = N->getOperand(0);
Chris Lattner222adac2005-10-06 19:03:35 +0000731 switch (CC) {
Chris Lattnerdabb8292005-10-21 21:17:10 +0000732 default: break;
Evan Cheng0b828e02006-08-27 08:14:06 +0000733 case ISD::SETEQ: {
Dan Gohman602b0c82009-09-25 18:54:59 +0000734 Op = SDValue(CurDAG->getMachineNode(PPC::CNTLZW, dl, MVT::i32, Op), 0);
Dan Gohman475871a2008-07-27 21:46:04 +0000735 SDValue Ops[] = { Op, getI32Imm(27), getI32Imm(5), getI32Imm(31) };
Owen Anderson825b72b2009-08-11 20:47:22 +0000736 return CurDAG->SelectNodeTo(N, PPC::RLWINM, MVT::i32, Ops, 4);
Evan Cheng0b828e02006-08-27 08:14:06 +0000737 }
Chris Lattnerdabb8292005-10-21 21:17:10 +0000738 case ISD::SETNE: {
Roman Divacky8e9d6722011-06-20 15:28:39 +0000739 if (isPPC64) break;
Dan Gohman475871a2008-07-27 21:46:04 +0000740 SDValue AD =
Chris Lattnerf1b4eaf2010-12-21 02:38:05 +0000741 SDValue(CurDAG->getMachineNode(PPC::ADDIC, dl, MVT::i32, MVT::Glue,
Dan Gohman602b0c82009-09-25 18:54:59 +0000742 Op, getI32Imm(~0U)), 0);
Andrew Trick6e8f4c42010-12-24 04:28:06 +0000743 return CurDAG->SelectNodeTo(N, PPC::SUBFE, MVT::i32, AD, Op,
Evan Cheng95514ba2006-08-26 08:00:10 +0000744 AD.getValue(1));
Chris Lattner222adac2005-10-06 19:03:35 +0000745 }
Evan Cheng0b828e02006-08-27 08:14:06 +0000746 case ISD::SETLT: {
Dan Gohman475871a2008-07-27 21:46:04 +0000747 SDValue Ops[] = { Op, getI32Imm(1), getI32Imm(31), getI32Imm(31) };
Owen Anderson825b72b2009-08-11 20:47:22 +0000748 return CurDAG->SelectNodeTo(N, PPC::RLWINM, MVT::i32, Ops, 4);
Evan Cheng0b828e02006-08-27 08:14:06 +0000749 }
Chris Lattnerdabb8292005-10-21 21:17:10 +0000750 case ISD::SETGT: {
Dan Gohman475871a2008-07-27 21:46:04 +0000751 SDValue T =
Dan Gohman602b0c82009-09-25 18:54:59 +0000752 SDValue(CurDAG->getMachineNode(PPC::NEG, dl, MVT::i32, Op), 0);
753 T = SDValue(CurDAG->getMachineNode(PPC::ANDC, dl, MVT::i32, T, Op), 0);
Dan Gohman475871a2008-07-27 21:46:04 +0000754 SDValue Ops[] = { T, getI32Imm(1), getI32Imm(31), getI32Imm(31) };
Owen Anderson825b72b2009-08-11 20:47:22 +0000755 return CurDAG->SelectNodeTo(N, PPC::RLWINM, MVT::i32, Ops, 4);
Chris Lattnerdabb8292005-10-21 21:17:10 +0000756 }
757 }
Chris Lattner222adac2005-10-06 19:03:35 +0000758 } else if (Imm == ~0U) { // setcc op, -1
Dan Gohman475871a2008-07-27 21:46:04 +0000759 SDValue Op = N->getOperand(0);
Chris Lattner222adac2005-10-06 19:03:35 +0000760 switch (CC) {
Chris Lattnerdabb8292005-10-21 21:17:10 +0000761 default: break;
762 case ISD::SETEQ:
Roman Divacky8e9d6722011-06-20 15:28:39 +0000763 if (isPPC64) break;
Chris Lattnerf1b4eaf2010-12-21 02:38:05 +0000764 Op = SDValue(CurDAG->getMachineNode(PPC::ADDIC, dl, MVT::i32, MVT::Glue,
Dan Gohman602b0c82009-09-25 18:54:59 +0000765 Op, getI32Imm(1)), 0);
Andrew Trick6e8f4c42010-12-24 04:28:06 +0000766 return CurDAG->SelectNodeTo(N, PPC::ADDZE, MVT::i32,
767 SDValue(CurDAG->getMachineNode(PPC::LI, dl,
Dan Gohman602b0c82009-09-25 18:54:59 +0000768 MVT::i32,
769 getI32Imm(0)), 0),
Dale Johannesena05dca42009-02-04 23:02:30 +0000770 Op.getValue(1));
Chris Lattnerdabb8292005-10-21 21:17:10 +0000771 case ISD::SETNE: {
Roman Divacky8e9d6722011-06-20 15:28:39 +0000772 if (isPPC64) break;
Dan Gohman602b0c82009-09-25 18:54:59 +0000773 Op = SDValue(CurDAG->getMachineNode(PPC::NOR, dl, MVT::i32, Op, Op), 0);
Chris Lattnerf1b4eaf2010-12-21 02:38:05 +0000774 SDNode *AD = CurDAG->getMachineNode(PPC::ADDIC, dl, MVT::i32, MVT::Glue,
Dan Gohman602b0c82009-09-25 18:54:59 +0000775 Op, getI32Imm(~0U));
Owen Anderson825b72b2009-08-11 20:47:22 +0000776 return CurDAG->SelectNodeTo(N, PPC::SUBFE, MVT::i32, SDValue(AD, 0),
Dan Gohman475871a2008-07-27 21:46:04 +0000777 Op, SDValue(AD, 1));
Chris Lattner222adac2005-10-06 19:03:35 +0000778 }
Chris Lattnerdabb8292005-10-21 21:17:10 +0000779 case ISD::SETLT: {
Dan Gohman602b0c82009-09-25 18:54:59 +0000780 SDValue AD = SDValue(CurDAG->getMachineNode(PPC::ADDI, dl, MVT::i32, Op,
781 getI32Imm(1)), 0);
782 SDValue AN = SDValue(CurDAG->getMachineNode(PPC::AND, dl, MVT::i32, AD,
783 Op), 0);
Dan Gohman475871a2008-07-27 21:46:04 +0000784 SDValue Ops[] = { AN, getI32Imm(1), getI32Imm(31), getI32Imm(31) };
Owen Anderson825b72b2009-08-11 20:47:22 +0000785 return CurDAG->SelectNodeTo(N, PPC::RLWINM, MVT::i32, Ops, 4);
Chris Lattnerdabb8292005-10-21 21:17:10 +0000786 }
Evan Cheng0b828e02006-08-27 08:14:06 +0000787 case ISD::SETGT: {
Dan Gohman475871a2008-07-27 21:46:04 +0000788 SDValue Ops[] = { Op, getI32Imm(1), getI32Imm(31), getI32Imm(31) };
Andrew Trick6e8f4c42010-12-24 04:28:06 +0000789 Op = SDValue(CurDAG->getMachineNode(PPC::RLWINM, dl, MVT::i32, Ops, 4),
Dale Johannesena05dca42009-02-04 23:02:30 +0000790 0);
Andrew Trick6e8f4c42010-12-24 04:28:06 +0000791 return CurDAG->SelectNodeTo(N, PPC::XORI, MVT::i32, Op,
Evan Cheng95514ba2006-08-26 08:00:10 +0000792 getI32Imm(1));
Chris Lattnerdabb8292005-10-21 21:17:10 +0000793 }
Evan Cheng0b828e02006-08-27 08:14:06 +0000794 }
Chris Lattner222adac2005-10-06 19:03:35 +0000795 }
796 }
Andrew Trick6e8f4c42010-12-24 04:28:06 +0000797
Adhemerval Zanella1c7d69b2012-10-08 18:59:53 +0000798 SDValue LHS = N->getOperand(0);
799 SDValue RHS = N->getOperand(1);
800
Adhemerval Zanella5f41fd62012-10-30 13:50:19 +0000801 // Altivec Vector compare instructions do not set any CR register by default and
802 // vector compare operations return the same type as the operands.
Adhemerval Zanella1c7d69b2012-10-08 18:59:53 +0000803 if (LHS.getValueType().isVector()) {
Adhemerval Zanella5f41fd62012-10-30 13:50:19 +0000804 EVT VecVT = LHS.getValueType();
805 MVT::SimpleValueType VT = VecVT.getSimpleVT().SimpleTy;
806 unsigned int VCmpInst = getVCmpInst(VT, CC);
807
808 switch (CC) {
809 case ISD::SETEQ:
810 case ISD::SETOEQ:
811 case ISD::SETUEQ:
812 return CurDAG->SelectNodeTo(N, VCmpInst, VecVT, LHS, RHS);
813 case ISD::SETNE:
814 case ISD::SETONE:
815 case ISD::SETUNE: {
816 SDValue VCmp(CurDAG->getMachineNode(VCmpInst, dl, VecVT, LHS, RHS), 0);
817 return CurDAG->SelectNodeTo(N, PPC::VNOR, VecVT, VCmp, VCmp);
818 }
819 case ISD::SETLT:
820 case ISD::SETOLT:
821 case ISD::SETULT:
822 return CurDAG->SelectNodeTo(N, VCmpInst, VecVT, RHS, LHS);
823 case ISD::SETGT:
824 case ISD::SETOGT:
825 case ISD::SETUGT:
826 return CurDAG->SelectNodeTo(N, VCmpInst, VecVT, LHS, RHS);
827 case ISD::SETGE:
828 case ISD::SETOGE:
829 case ISD::SETUGE: {
830 // Small optimization: Altivec provides a 'Vector Compare Greater Than
831 // or Equal To' instruction (vcmpgefp), so in this case there is no
832 // need for extra logic for the equal compare.
833 if (VecVT.getSimpleVT().isFloatingPoint()) {
834 return CurDAG->SelectNodeTo(N, VCmpInst, VecVT, LHS, RHS);
835 } else {
836 SDValue VCmpGT(CurDAG->getMachineNode(VCmpInst, dl, VecVT, LHS, RHS), 0);
837 unsigned int VCmpEQInst = getVCmpEQInst(VT);
838 SDValue VCmpEQ(CurDAG->getMachineNode(VCmpEQInst, dl, VecVT, LHS, RHS), 0);
839 return CurDAG->SelectNodeTo(N, PPC::VOR, VecVT, VCmpGT, VCmpEQ);
840 }
841 }
842 case ISD::SETLE:
843 case ISD::SETOLE:
844 case ISD::SETULE: {
845 SDValue VCmpLE(CurDAG->getMachineNode(VCmpInst, dl, VecVT, RHS, LHS), 0);
846 unsigned int VCmpEQInst = getVCmpEQInst(VT);
847 SDValue VCmpEQ(CurDAG->getMachineNode(VCmpEQInst, dl, VecVT, LHS, RHS), 0);
848 return CurDAG->SelectNodeTo(N, PPC::VOR, VecVT, VCmpLE, VCmpEQ);
849 }
850 default:
851 llvm_unreachable("Invalid vector compare type: should be expanded by legalize");
852 }
Adhemerval Zanella1c7d69b2012-10-08 18:59:53 +0000853 }
854
Chris Lattner222adac2005-10-06 19:03:35 +0000855 bool Inv;
Chris Lattnerfe39edd2008-01-08 06:46:30 +0000856 int OtherCondIdx;
857 unsigned Idx = getCRIdxForSetCC(CC, Inv, OtherCondIdx);
Adhemerval Zanella1c7d69b2012-10-08 18:59:53 +0000858 SDValue CCReg = SelectCC(LHS, RHS, CC, dl);
Dan Gohman475871a2008-07-27 21:46:04 +0000859 SDValue IntCR;
Andrew Trick6e8f4c42010-12-24 04:28:06 +0000860
Chris Lattner222adac2005-10-06 19:03:35 +0000861 // Force the ccreg into CR7.
Owen Anderson825b72b2009-08-11 20:47:22 +0000862 SDValue CR7Reg = CurDAG->getRegister(PPC::CR7, MVT::i32);
Andrew Trick6e8f4c42010-12-24 04:28:06 +0000863
Dan Gohman475871a2008-07-27 21:46:04 +0000864 SDValue InFlag(0, 0); // Null incoming flag value.
Andrew Trick6e8f4c42010-12-24 04:28:06 +0000865 CCReg = CurDAG->getCopyToReg(CurDAG->getEntryNode(), dl, CR7Reg, CCReg,
Chris Lattnerdb1cb2b2005-12-01 03:50:19 +0000866 InFlag).getValue(1);
Andrew Trick6e8f4c42010-12-24 04:28:06 +0000867
Hal Finkelbd5cafd2012-06-11 19:57:01 +0000868 if (PPCSubTarget.hasMFOCRF() && OtherCondIdx == -1)
Dan Gohman602b0c82009-09-25 18:54:59 +0000869 IntCR = SDValue(CurDAG->getMachineNode(PPC::MFOCRF, dl, MVT::i32, CR7Reg,
870 CCReg), 0);
Adhemerval Zanella1c7d69b2012-10-08 18:59:53 +0000871 else
Dale Johannesen5f07d522010-05-20 17:48:26 +0000872 IntCR = SDValue(CurDAG->getMachineNode(PPC::MFCRpseud, dl, MVT::i32,
873 CR7Reg, CCReg), 0);
Andrew Trick6e8f4c42010-12-24 04:28:06 +0000874
Dan Gohman475871a2008-07-27 21:46:04 +0000875 SDValue Ops[] = { IntCR, getI32Imm((32-(3-Idx)) & 31),
Evan Cheng0b828e02006-08-27 08:14:06 +0000876 getI32Imm(31), getI32Imm(31) };
Chris Lattnerfe39edd2008-01-08 06:46:30 +0000877 if (OtherCondIdx == -1 && !Inv)
Owen Anderson825b72b2009-08-11 20:47:22 +0000878 return CurDAG->SelectNodeTo(N, PPC::RLWINM, MVT::i32, Ops, 4);
Chris Lattnerfe39edd2008-01-08 06:46:30 +0000879
880 // Get the specified bit.
Dan Gohman475871a2008-07-27 21:46:04 +0000881 SDValue Tmp =
Dan Gohman602b0c82009-09-25 18:54:59 +0000882 SDValue(CurDAG->getMachineNode(PPC::RLWINM, dl, MVT::i32, Ops, 4), 0);
Chris Lattnerfe39edd2008-01-08 06:46:30 +0000883 if (Inv) {
884 assert(OtherCondIdx == -1 && "Can't have split plus negation");
Owen Anderson825b72b2009-08-11 20:47:22 +0000885 return CurDAG->SelectNodeTo(N, PPC::XORI, MVT::i32, Tmp, getI32Imm(1));
Chris Lattner222adac2005-10-06 19:03:35 +0000886 }
Chris Lattnerfe39edd2008-01-08 06:46:30 +0000887
888 // Otherwise, we have to turn an operation like SETONE -> SETOLT | SETOGT.
889 // We already got the bit for the first part of the comparison (e.g. SETULE).
890
891 // Get the other bit of the comparison.
892 Ops[1] = getI32Imm((32-(3-OtherCondIdx)) & 31);
Andrew Trick6e8f4c42010-12-24 04:28:06 +0000893 SDValue OtherCond =
Dan Gohman602b0c82009-09-25 18:54:59 +0000894 SDValue(CurDAG->getMachineNode(PPC::RLWINM, dl, MVT::i32, Ops, 4), 0);
Chris Lattnerfe39edd2008-01-08 06:46:30 +0000895
Owen Anderson825b72b2009-08-11 20:47:22 +0000896 return CurDAG->SelectNodeTo(N, PPC::OR, MVT::i32, Tmp, OtherCond);
Chris Lattner222adac2005-10-06 19:03:35 +0000897}
Chris Lattner2b63e4c2005-10-06 18:56:10 +0000898
Chris Lattner6a16f6a2005-10-06 19:07:45 +0000899
Chris Lattnera5a91b12005-08-17 19:33:03 +0000900// Select - Convert the specified operand from a target-independent to a
901// target-specific node if it hasn't already been changed.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000902SDNode *PPCDAGToDAGISel::Select(SDNode *N) {
903 DebugLoc dl = N->getDebugLoc();
Dan Gohmane8be6c62008-07-17 19:10:17 +0000904 if (N->isMachineOpcode())
Evan Cheng64a752f2006-08-11 09:08:15 +0000905 return NULL; // Already selected.
Chris Lattnerd3d2cf52005-09-29 00:59:32 +0000906
Chris Lattnera5a91b12005-08-17 19:33:03 +0000907 switch (N->getOpcode()) {
Chris Lattner19c09072005-09-07 23:45:15 +0000908 default: break;
Andrew Trick6e8f4c42010-12-24 04:28:06 +0000909
Jim Laskey78f97f32006-12-12 13:23:43 +0000910 case ISD::Constant: {
Owen Anderson825b72b2009-08-11 20:47:22 +0000911 if (N->getValueType(0) == MVT::i64) {
Jim Laskey78f97f32006-12-12 13:23:43 +0000912 // Get 64 bit value.
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000913 int64_t Imm = cast<ConstantSDNode>(N)->getZExtValue();
Jim Laskey78f97f32006-12-12 13:23:43 +0000914 // Assume no remaining bits.
915 unsigned Remainder = 0;
916 // Assume no shift required.
917 unsigned Shift = 0;
Andrew Trick6e8f4c42010-12-24 04:28:06 +0000918
Jim Laskey78f97f32006-12-12 13:23:43 +0000919 // If it can't be represented as a 32 bit value.
Benjamin Kramer34247a02010-03-29 21:13:41 +0000920 if (!isInt<32>(Imm)) {
Jim Laskey78f97f32006-12-12 13:23:43 +0000921 Shift = CountTrailingZeros_64(Imm);
922 int64_t ImmSh = static_cast<uint64_t>(Imm) >> Shift;
Andrew Trick6e8f4c42010-12-24 04:28:06 +0000923
Jim Laskey78f97f32006-12-12 13:23:43 +0000924 // If the shifted value fits 32 bits.
Benjamin Kramer34247a02010-03-29 21:13:41 +0000925 if (isInt<32>(ImmSh)) {
Jim Laskey78f97f32006-12-12 13:23:43 +0000926 // Go with the shifted value.
927 Imm = ImmSh;
928 } else {
929 // Still stuck with a 64 bit value.
930 Remainder = Imm;
931 Shift = 32;
932 Imm >>= 32;
933 }
934 }
Andrew Trick6e8f4c42010-12-24 04:28:06 +0000935
Jim Laskey78f97f32006-12-12 13:23:43 +0000936 // Intermediate operand.
937 SDNode *Result;
938
939 // Handle first 32 bits.
940 unsigned Lo = Imm & 0xFFFF;
941 unsigned Hi = (Imm >> 16) & 0xFFFF;
Andrew Trick6e8f4c42010-12-24 04:28:06 +0000942
Jim Laskey78f97f32006-12-12 13:23:43 +0000943 // Simple value.
Benjamin Kramer34247a02010-03-29 21:13:41 +0000944 if (isInt<16>(Imm)) {
Jim Laskey78f97f32006-12-12 13:23:43 +0000945 // Just the Lo bits.
Dan Gohman602b0c82009-09-25 18:54:59 +0000946 Result = CurDAG->getMachineNode(PPC::LI8, dl, MVT::i64, getI32Imm(Lo));
Jim Laskey78f97f32006-12-12 13:23:43 +0000947 } else if (Lo) {
948 // Handle the Hi bits.
949 unsigned OpC = Hi ? PPC::LIS8 : PPC::LI8;
Dan Gohman602b0c82009-09-25 18:54:59 +0000950 Result = CurDAG->getMachineNode(OpC, dl, MVT::i64, getI32Imm(Hi));
Jim Laskey78f97f32006-12-12 13:23:43 +0000951 // And Lo bits.
Dan Gohman602b0c82009-09-25 18:54:59 +0000952 Result = CurDAG->getMachineNode(PPC::ORI8, dl, MVT::i64,
953 SDValue(Result, 0), getI32Imm(Lo));
Jim Laskey78f97f32006-12-12 13:23:43 +0000954 } else {
955 // Just the Hi bits.
Dan Gohman602b0c82009-09-25 18:54:59 +0000956 Result = CurDAG->getMachineNode(PPC::LIS8, dl, MVT::i64, getI32Imm(Hi));
Jim Laskey78f97f32006-12-12 13:23:43 +0000957 }
Andrew Trick6e8f4c42010-12-24 04:28:06 +0000958
Jim Laskey78f97f32006-12-12 13:23:43 +0000959 // If no shift, we're done.
960 if (!Shift) return Result;
961
962 // Shift for next step if the upper 32-bits were not zero.
963 if (Imm) {
Dan Gohman602b0c82009-09-25 18:54:59 +0000964 Result = CurDAG->getMachineNode(PPC::RLDICR, dl, MVT::i64,
965 SDValue(Result, 0),
966 getI32Imm(Shift),
967 getI32Imm(63 - Shift));
Jim Laskey78f97f32006-12-12 13:23:43 +0000968 }
969
970 // Add in the last bits as required.
971 if ((Hi = (Remainder >> 16) & 0xFFFF)) {
Dan Gohman602b0c82009-09-25 18:54:59 +0000972 Result = CurDAG->getMachineNode(PPC::ORIS8, dl, MVT::i64,
973 SDValue(Result, 0), getI32Imm(Hi));
Andrew Trick6e8f4c42010-12-24 04:28:06 +0000974 }
Jim Laskey78f97f32006-12-12 13:23:43 +0000975 if ((Lo = Remainder & 0xFFFF)) {
Dan Gohman602b0c82009-09-25 18:54:59 +0000976 Result = CurDAG->getMachineNode(PPC::ORI8, dl, MVT::i64,
977 SDValue(Result, 0), getI32Imm(Lo));
Jim Laskey78f97f32006-12-12 13:23:43 +0000978 }
Andrew Trick6e8f4c42010-12-24 04:28:06 +0000979
Jim Laskey78f97f32006-12-12 13:23:43 +0000980 return Result;
981 }
982 break;
983 }
Andrew Trick6e8f4c42010-12-24 04:28:06 +0000984
Evan Cheng34167212006-02-09 00:37:58 +0000985 case ISD::SETCC:
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000986 return SelectSETCC(N);
Evan Cheng34167212006-02-09 00:37:58 +0000987 case PPCISD::GlobalBaseReg:
Evan Cheng9ade2182006-08-26 05:34:46 +0000988 return getGlobalBaseReg();
Andrew Trick6e8f4c42010-12-24 04:28:06 +0000989
Chris Lattnere28e40a2005-08-25 00:45:43 +0000990 case ISD::FrameIndex: {
991 int FI = cast<FrameIndexSDNode>(N)->getIndex();
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000992 SDValue TFI = CurDAG->getTargetFrameIndex(FI, N->getValueType(0));
993 unsigned Opc = N->getValueType(0) == MVT::i32 ? PPC::ADDI : PPC::ADDI8;
Chris Lattnerccbe2ec2006-08-15 23:48:22 +0000994 if (N->hasOneUse())
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000995 return CurDAG->SelectNodeTo(N, Opc, N->getValueType(0), TFI,
Evan Cheng95514ba2006-08-26 08:00:10 +0000996 getSmallIPtrImm(0));
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000997 return CurDAG->getMachineNode(Opc, dl, N->getValueType(0), TFI,
Dan Gohman602b0c82009-09-25 18:54:59 +0000998 getSmallIPtrImm(0));
Chris Lattnere28e40a2005-08-25 00:45:43 +0000999 }
Chris Lattner6d92cad2006-03-26 10:06:40 +00001000
1001 case PPCISD::MFCR: {
Dan Gohman475871a2008-07-27 21:46:04 +00001002 SDValue InFlag = N->getOperand(1);
Chris Lattner6d92cad2006-03-26 10:06:40 +00001003 // Use MFOCRF if supported.
Hal Finkelbd5cafd2012-06-11 19:57:01 +00001004 if (PPCSubTarget.hasMFOCRF())
Dan Gohman602b0c82009-09-25 18:54:59 +00001005 return CurDAG->getMachineNode(PPC::MFOCRF, dl, MVT::i32,
1006 N->getOperand(0), InFlag);
Chris Lattner6d92cad2006-03-26 10:06:40 +00001007 else
Dale Johannesen5f07d522010-05-20 17:48:26 +00001008 return CurDAG->getMachineNode(PPC::MFCRpseud, dl, MVT::i32,
1009 N->getOperand(0), InFlag);
Chris Lattner6d92cad2006-03-26 10:06:40 +00001010 }
Andrew Trick6e8f4c42010-12-24 04:28:06 +00001011
Chris Lattner88add102005-09-28 22:50:24 +00001012 case ISD::SDIV: {
Nate Begeman405e3ec2005-10-21 00:02:42 +00001013 // FIXME: since this depends on the setting of the carry flag from the srawi
1014 // we should really be making notes about that for the scheduler.
Andrew Trick6e8f4c42010-12-24 04:28:06 +00001015 // FIXME: It sure would be nice if we could cheaply recognize the
Nate Begeman405e3ec2005-10-21 00:02:42 +00001016 // srl/add/sra pattern the dag combiner will generate for this as
1017 // sra/addze rather than having to handle sdiv ourselves. oh well.
Chris Lattner8784a232005-08-25 17:50:06 +00001018 unsigned Imm;
Chris Lattnerc08f9022006-06-27 00:04:13 +00001019 if (isInt32Immediate(N->getOperand(1), Imm)) {
Dan Gohman475871a2008-07-27 21:46:04 +00001020 SDValue N0 = N->getOperand(0);
Chris Lattner8784a232005-08-25 17:50:06 +00001021 if ((signed)Imm > 0 && isPowerOf2_32(Imm)) {
Evan Cheng7e9b26f2006-02-09 07:17:49 +00001022 SDNode *Op =
Chris Lattnerf1b4eaf2010-12-21 02:38:05 +00001023 CurDAG->getMachineNode(PPC::SRAWI, dl, MVT::i32, MVT::Glue,
Dan Gohman602b0c82009-09-25 18:54:59 +00001024 N0, getI32Imm(Log2_32(Imm)));
Andrew Trick6e8f4c42010-12-24 04:28:06 +00001025 return CurDAG->SelectNodeTo(N, PPC::ADDZE, MVT::i32,
Dan Gohman475871a2008-07-27 21:46:04 +00001026 SDValue(Op, 0), SDValue(Op, 1));
Chris Lattner8784a232005-08-25 17:50:06 +00001027 } else if ((signed)Imm < 0 && isPowerOf2_32(-Imm)) {
Evan Cheng7e9b26f2006-02-09 07:17:49 +00001028 SDNode *Op =
Chris Lattnerf1b4eaf2010-12-21 02:38:05 +00001029 CurDAG->getMachineNode(PPC::SRAWI, dl, MVT::i32, MVT::Glue,
Dan Gohman602b0c82009-09-25 18:54:59 +00001030 N0, getI32Imm(Log2_32(-Imm)));
Dan Gohman475871a2008-07-27 21:46:04 +00001031 SDValue PT =
Dan Gohman602b0c82009-09-25 18:54:59 +00001032 SDValue(CurDAG->getMachineNode(PPC::ADDZE, dl, MVT::i32,
1033 SDValue(Op, 0), SDValue(Op, 1)),
Evan Cheng7e9b26f2006-02-09 07:17:49 +00001034 0);
Owen Anderson825b72b2009-08-11 20:47:22 +00001035 return CurDAG->SelectNodeTo(N, PPC::NEG, MVT::i32, PT);
Chris Lattner8784a232005-08-25 17:50:06 +00001036 }
1037 }
Andrew Trick6e8f4c42010-12-24 04:28:06 +00001038
Chris Lattner237733e2005-09-29 23:33:31 +00001039 // Other cases are autogenerated.
1040 break;
Chris Lattner047b9522005-08-25 22:04:30 +00001041 }
Andrew Trick6e8f4c42010-12-24 04:28:06 +00001042
Chris Lattner4eab7142006-11-10 02:08:47 +00001043 case ISD::LOAD: {
1044 // Handle preincrement loads.
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001045 LoadSDNode *LD = cast<LoadSDNode>(N);
Owen Andersone50ed302009-08-10 22:56:29 +00001046 EVT LoadedVT = LD->getMemoryVT();
Andrew Trick6e8f4c42010-12-24 04:28:06 +00001047
Chris Lattner4eab7142006-11-10 02:08:47 +00001048 // Normal loads are handled by code generated from the .td file.
1049 if (LD->getAddressingMode() != ISD::PRE_INC)
1050 break;
Andrew Trick6e8f4c42010-12-24 04:28:06 +00001051
Dan Gohman475871a2008-07-27 21:46:04 +00001052 SDValue Offset = LD->getOffset();
Chris Lattner5b3bbc72006-11-11 04:53:30 +00001053 if (isa<ConstantSDNode>(Offset) ||
1054 Offset.getOpcode() == ISD::TargetGlobalAddress) {
Andrew Trick6e8f4c42010-12-24 04:28:06 +00001055
Chris Lattner0851b4f2006-11-15 19:55:13 +00001056 unsigned Opcode;
1057 bool isSExt = LD->getExtensionType() == ISD::SEXTLOAD;
Owen Anderson825b72b2009-08-11 20:47:22 +00001058 if (LD->getValueType(0) != MVT::i64) {
Chris Lattner0851b4f2006-11-15 19:55:13 +00001059 // Handle PPC32 integer and normal FP loads.
Owen Anderson825b72b2009-08-11 20:47:22 +00001060 assert((!isSExt || LoadedVT == MVT::i16) && "Invalid sext update load");
1061 switch (LoadedVT.getSimpleVT().SimpleTy) {
Torok Edwinc23197a2009-07-14 16:55:14 +00001062 default: llvm_unreachable("Invalid PPC load type!");
Owen Anderson825b72b2009-08-11 20:47:22 +00001063 case MVT::f64: Opcode = PPC::LFDU; break;
1064 case MVT::f32: Opcode = PPC::LFSU; break;
1065 case MVT::i32: Opcode = PPC::LWZU; break;
1066 case MVT::i16: Opcode = isSExt ? PPC::LHAU : PPC::LHZU; break;
1067 case MVT::i1:
1068 case MVT::i8: Opcode = PPC::LBZU; break;
Chris Lattner0851b4f2006-11-15 19:55:13 +00001069 }
1070 } else {
Owen Anderson825b72b2009-08-11 20:47:22 +00001071 assert(LD->getValueType(0) == MVT::i64 && "Unknown load result type!");
1072 assert((!isSExt || LoadedVT == MVT::i16) && "Invalid sext update load");
1073 switch (LoadedVT.getSimpleVT().SimpleTy) {
Torok Edwinc23197a2009-07-14 16:55:14 +00001074 default: llvm_unreachable("Invalid PPC load type!");
Owen Anderson825b72b2009-08-11 20:47:22 +00001075 case MVT::i64: Opcode = PPC::LDU; break;
1076 case MVT::i32: Opcode = PPC::LWZU8; break;
1077 case MVT::i16: Opcode = isSExt ? PPC::LHAU8 : PPC::LHZU8; break;
1078 case MVT::i1:
1079 case MVT::i8: Opcode = PPC::LBZU8; break;
Chris Lattner0851b4f2006-11-15 19:55:13 +00001080 }
1081 }
Andrew Trick6e8f4c42010-12-24 04:28:06 +00001082
Dan Gohman475871a2008-07-27 21:46:04 +00001083 SDValue Chain = LD->getChain();
1084 SDValue Base = LD->getBasePtr();
Dan Gohman475871a2008-07-27 21:46:04 +00001085 SDValue Ops[] = { Offset, Base, Chain };
Dan Gohman602b0c82009-09-25 18:54:59 +00001086 return CurDAG->getMachineNode(Opcode, dl, LD->getValueType(0),
1087 PPCLowering.getPointerTy(),
1088 MVT::Other, Ops, 3);
Chris Lattner4eab7142006-11-10 02:08:47 +00001089 } else {
Hal Finkel0fcdd8b2012-06-20 15:43:03 +00001090 unsigned Opcode;
1091 bool isSExt = LD->getExtensionType() == ISD::SEXTLOAD;
1092 if (LD->getValueType(0) != MVT::i64) {
1093 // Handle PPC32 integer and normal FP loads.
1094 assert((!isSExt || LoadedVT == MVT::i16) && "Invalid sext update load");
1095 switch (LoadedVT.getSimpleVT().SimpleTy) {
1096 default: llvm_unreachable("Invalid PPC load type!");
1097 case MVT::f64: Opcode = PPC::LFDUX; break;
1098 case MVT::f32: Opcode = PPC::LFSUX; break;
1099 case MVT::i32: Opcode = PPC::LWZUX; break;
1100 case MVT::i16: Opcode = isSExt ? PPC::LHAUX : PPC::LHZUX; break;
1101 case MVT::i1:
1102 case MVT::i8: Opcode = PPC::LBZUX; break;
1103 }
1104 } else {
1105 assert(LD->getValueType(0) == MVT::i64 && "Unknown load result type!");
1106 assert((!isSExt || LoadedVT == MVT::i16 || LoadedVT == MVT::i32) &&
1107 "Invalid sext update load");
1108 switch (LoadedVT.getSimpleVT().SimpleTy) {
1109 default: llvm_unreachable("Invalid PPC load type!");
1110 case MVT::i64: Opcode = PPC::LDUX; break;
1111 case MVT::i32: Opcode = isSExt ? PPC::LWAUX : PPC::LWZUX8; break;
1112 case MVT::i16: Opcode = isSExt ? PPC::LHAUX8 : PPC::LHZUX8; break;
1113 case MVT::i1:
1114 case MVT::i8: Opcode = PPC::LBZUX8; break;
1115 }
1116 }
1117
1118 SDValue Chain = LD->getChain();
1119 SDValue Base = LD->getBasePtr();
1120 SDValue Ops[] = { Offset, Base, Chain };
1121 return CurDAG->getMachineNode(Opcode, dl, LD->getValueType(0),
1122 PPCLowering.getPointerTy(),
1123 MVT::Other, Ops, 3);
Chris Lattner4eab7142006-11-10 02:08:47 +00001124 }
1125 }
Andrew Trick6e8f4c42010-12-24 04:28:06 +00001126
Nate Begemancffc32b2005-08-18 07:30:46 +00001127 case ISD::AND: {
Nate Begemanf42f1332006-09-22 05:01:56 +00001128 unsigned Imm, Imm2, SH, MB, ME;
Hal Finkel97d047d2012-08-28 02:10:15 +00001129 uint64_t Imm64;
Nate Begemanf42f1332006-09-22 05:01:56 +00001130
Nate Begemancffc32b2005-08-18 07:30:46 +00001131 // If this is an and of a value rotated between 0 and 31 bits and then and'd
1132 // with a mask, emit rlwinm
Chris Lattnerc08f9022006-06-27 00:04:13 +00001133 if (isInt32Immediate(N->getOperand(1), Imm) &&
Gabor Greifba36cb52008-08-28 21:40:38 +00001134 isRotateAndMask(N->getOperand(0).getNode(), Imm, false, SH, MB, ME)) {
Dan Gohman475871a2008-07-27 21:46:04 +00001135 SDValue Val = N->getOperand(0).getOperand(0);
Dan Gohman475871a2008-07-27 21:46:04 +00001136 SDValue Ops[] = { Val, getI32Imm(SH), getI32Imm(MB), getI32Imm(ME) };
Owen Anderson825b72b2009-08-11 20:47:22 +00001137 return CurDAG->SelectNodeTo(N, PPC::RLWINM, MVT::i32, Ops, 4);
Nate Begemancffc32b2005-08-18 07:30:46 +00001138 }
Nate Begemanf42f1332006-09-22 05:01:56 +00001139 // If this is just a masked value where the input is not handled above, and
1140 // is not a rotate-left (handled by a pattern in the .td file), emit rlwinm
1141 if (isInt32Immediate(N->getOperand(1), Imm) &&
Andrew Trick6e8f4c42010-12-24 04:28:06 +00001142 isRunOfOnes(Imm, MB, ME) &&
Nate Begemanf42f1332006-09-22 05:01:56 +00001143 N->getOperand(0).getOpcode() != ISD::ROTL) {
Dan Gohman475871a2008-07-27 21:46:04 +00001144 SDValue Val = N->getOperand(0);
Dan Gohman475871a2008-07-27 21:46:04 +00001145 SDValue Ops[] = { Val, getI32Imm(0), getI32Imm(MB), getI32Imm(ME) };
Owen Anderson825b72b2009-08-11 20:47:22 +00001146 return CurDAG->SelectNodeTo(N, PPC::RLWINM, MVT::i32, Ops, 4);
Nate Begemanf42f1332006-09-22 05:01:56 +00001147 }
Hal Finkel97d047d2012-08-28 02:10:15 +00001148 // If this is a 64-bit zero-extension mask, emit rldicl.
1149 if (isInt64Immediate(N->getOperand(1).getNode(), Imm64) &&
1150 isMask_64(Imm64)) {
1151 SDValue Val = N->getOperand(0);
1152 MB = 64 - CountTrailingOnes_64(Imm64);
1153 SDValue Ops[] = { Val, getI32Imm(0), getI32Imm(MB) };
1154 return CurDAG->SelectNodeTo(N, PPC::RLDICL, MVT::i64, Ops, 3);
1155 }
Nate Begemanf42f1332006-09-22 05:01:56 +00001156 // AND X, 0 -> 0, not "rlwinm 32".
1157 if (isInt32Immediate(N->getOperand(1), Imm) && (Imm == 0)) {
Dan Gohman475871a2008-07-27 21:46:04 +00001158 ReplaceUses(SDValue(N, 0), N->getOperand(1));
Nate Begemanf42f1332006-09-22 05:01:56 +00001159 return NULL;
1160 }
Nate Begeman50fb3c42005-12-24 01:00:15 +00001161 // ISD::OR doesn't get all the bitfield insertion fun.
1162 // (and (or x, c1), c2) where isRunOfOnes(~(c1^c2)) is a bitfield insert
Andrew Trick6e8f4c42010-12-24 04:28:06 +00001163 if (isInt32Immediate(N->getOperand(1), Imm) &&
Nate Begeman50fb3c42005-12-24 01:00:15 +00001164 N->getOperand(0).getOpcode() == ISD::OR &&
Chris Lattnerc08f9022006-06-27 00:04:13 +00001165 isInt32Immediate(N->getOperand(0).getOperand(1), Imm2)) {
Chris Lattnerc9a5ef52006-01-05 18:32:49 +00001166 unsigned MB, ME;
Nate Begeman50fb3c42005-12-24 01:00:15 +00001167 Imm = ~(Imm^Imm2);
1168 if (isRunOfOnes(Imm, MB, ME)) {
Dan Gohman475871a2008-07-27 21:46:04 +00001169 SDValue Ops[] = { N->getOperand(0).getOperand(0),
Evan Cheng0b828e02006-08-27 08:14:06 +00001170 N->getOperand(0).getOperand(1),
1171 getI32Imm(0), getI32Imm(MB),getI32Imm(ME) };
Dan Gohman602b0c82009-09-25 18:54:59 +00001172 return CurDAG->getMachineNode(PPC::RLWIMI, dl, MVT::i32, Ops, 5);
Nate Begeman50fb3c42005-12-24 01:00:15 +00001173 }
1174 }
Andrew Trick6e8f4c42010-12-24 04:28:06 +00001175
Chris Lattner237733e2005-09-29 23:33:31 +00001176 // Other cases are autogenerated.
1177 break;
Nate Begemancffc32b2005-08-18 07:30:46 +00001178 }
Nate Begeman02b88a42005-08-19 00:38:14 +00001179 case ISD::OR:
Owen Anderson825b72b2009-08-11 20:47:22 +00001180 if (N->getValueType(0) == MVT::i32)
Chris Lattnerccbe2ec2006-08-15 23:48:22 +00001181 if (SDNode *I = SelectBitfieldInsert(N))
1182 return I;
Andrew Trick6e8f4c42010-12-24 04:28:06 +00001183
Chris Lattner237733e2005-09-29 23:33:31 +00001184 // Other cases are autogenerated.
1185 break;
Nate Begemanc15ed442005-08-18 23:38:00 +00001186 case ISD::SHL: {
1187 unsigned Imm, SH, MB, ME;
Gabor Greifba36cb52008-08-28 21:40:38 +00001188 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::AND, Imm) &&
Nate Begeman2d5aff72005-10-19 18:42:01 +00001189 isRotateAndMask(N, Imm, true, SH, MB, ME)) {
Dan Gohman475871a2008-07-27 21:46:04 +00001190 SDValue Ops[] = { N->getOperand(0).getOperand(0),
Evan Cheng0b828e02006-08-27 08:14:06 +00001191 getI32Imm(SH), getI32Imm(MB), getI32Imm(ME) };
Owen Anderson825b72b2009-08-11 20:47:22 +00001192 return CurDAG->SelectNodeTo(N, PPC::RLWINM, MVT::i32, Ops, 4);
Nate Begeman8d948322005-10-19 01:12:32 +00001193 }
Andrew Trick6e8f4c42010-12-24 04:28:06 +00001194
Nate Begeman2d5aff72005-10-19 18:42:01 +00001195 // Other cases are autogenerated.
1196 break;
Nate Begemanc15ed442005-08-18 23:38:00 +00001197 }
1198 case ISD::SRL: {
1199 unsigned Imm, SH, MB, ME;
Gabor Greifba36cb52008-08-28 21:40:38 +00001200 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::AND, Imm) &&
Andrew Trick6e8f4c42010-12-24 04:28:06 +00001201 isRotateAndMask(N, Imm, true, SH, MB, ME)) {
Dan Gohman475871a2008-07-27 21:46:04 +00001202 SDValue Ops[] = { N->getOperand(0).getOperand(0),
Evan Cheng0b828e02006-08-27 08:14:06 +00001203 getI32Imm(SH), getI32Imm(MB), getI32Imm(ME) };
Owen Anderson825b72b2009-08-11 20:47:22 +00001204 return CurDAG->SelectNodeTo(N, PPC::RLWINM, MVT::i32, Ops, 4);
Nate Begeman8d948322005-10-19 01:12:32 +00001205 }
Andrew Trick6e8f4c42010-12-24 04:28:06 +00001206
Nate Begeman2d5aff72005-10-19 18:42:01 +00001207 // Other cases are autogenerated.
1208 break;
Nate Begemanc15ed442005-08-18 23:38:00 +00001209 }
Chris Lattner13794f52005-08-26 18:46:49 +00001210 case ISD::SELECT_CC: {
1211 ISD::CondCode CC = cast<CondCodeSDNode>(N->getOperand(4))->get();
Roman Divacky8e9d6722011-06-20 15:28:39 +00001212 EVT PtrVT = CurDAG->getTargetLoweringInfo().getPointerTy();
1213 bool isPPC64 = (PtrVT == MVT::i64);
Andrew Trick6e8f4c42010-12-24 04:28:06 +00001214
Chris Lattnerc08f9022006-06-27 00:04:13 +00001215 // Handle the setcc cases here. select_cc lhs, 0, 1, 0, cc
Roman Divacky8e9d6722011-06-20 15:28:39 +00001216 if (!isPPC64)
1217 if (ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N->getOperand(1)))
1218 if (ConstantSDNode *N2C = dyn_cast<ConstantSDNode>(N->getOperand(2)))
1219 if (ConstantSDNode *N3C = dyn_cast<ConstantSDNode>(N->getOperand(3)))
1220 if (N1C->isNullValue() && N3C->isNullValue() &&
1221 N2C->getZExtValue() == 1ULL && CC == ISD::SETNE &&
1222 // FIXME: Implement this optzn for PPC64.
1223 N->getValueType(0) == MVT::i32) {
1224 SDNode *Tmp =
1225 CurDAG->getMachineNode(PPC::ADDIC, dl, MVT::i32, MVT::Glue,
1226 N->getOperand(0), getI32Imm(~0U));
1227 return CurDAG->SelectNodeTo(N, PPC::SUBFE, MVT::i32,
1228 SDValue(Tmp, 0), N->getOperand(0),
1229 SDValue(Tmp, 1));
1230 }
Chris Lattner8a2d3ca2005-08-26 21:23:58 +00001231
Dale Johannesenf5f5dce2009-02-06 19:16:40 +00001232 SDValue CCReg = SelectCC(N->getOperand(0), N->getOperand(1), CC, dl);
Chris Lattnerdf4ed632006-11-17 22:10:59 +00001233 unsigned BROpc = getPredicateForSetCC(CC);
Chris Lattner8a2d3ca2005-08-26 21:23:58 +00001234
Chris Lattner919c0322005-10-01 01:35:02 +00001235 unsigned SelectCCOp;
Owen Anderson825b72b2009-08-11 20:47:22 +00001236 if (N->getValueType(0) == MVT::i32)
Chris Lattnerc08f9022006-06-27 00:04:13 +00001237 SelectCCOp = PPC::SELECT_CC_I4;
Owen Anderson825b72b2009-08-11 20:47:22 +00001238 else if (N->getValueType(0) == MVT::i64)
Chris Lattnerc08f9022006-06-27 00:04:13 +00001239 SelectCCOp = PPC::SELECT_CC_I8;
Owen Anderson825b72b2009-08-11 20:47:22 +00001240 else if (N->getValueType(0) == MVT::f32)
Chris Lattner919c0322005-10-01 01:35:02 +00001241 SelectCCOp = PPC::SELECT_CC_F4;
Owen Anderson825b72b2009-08-11 20:47:22 +00001242 else if (N->getValueType(0) == MVT::f64)
Chris Lattner919c0322005-10-01 01:35:02 +00001243 SelectCCOp = PPC::SELECT_CC_F8;
Chris Lattner710ff322006-04-08 22:45:08 +00001244 else
1245 SelectCCOp = PPC::SELECT_CC_VRRC;
1246
Dan Gohman475871a2008-07-27 21:46:04 +00001247 SDValue Ops[] = { CCReg, N->getOperand(2), N->getOperand(3),
Evan Cheng0b828e02006-08-27 08:14:06 +00001248 getI32Imm(BROpc) };
1249 return CurDAG->SelectNodeTo(N, SelectCCOp, N->getValueType(0), Ops, 4);
Chris Lattner13794f52005-08-26 18:46:49 +00001250 }
Chris Lattner18258c62006-11-17 22:37:34 +00001251 case PPCISD::COND_BRANCH: {
Dan Gohmancbb7ab22008-11-05 17:16:24 +00001252 // Op #0 is the Chain.
Chris Lattner18258c62006-11-17 22:37:34 +00001253 // Op #1 is the PPC::PRED_* number.
1254 // Op #2 is the CR#
1255 // Op #3 is the Dest MBB
Dan Gohman8be6bbe2008-11-05 04:14:16 +00001256 // Op #4 is the Flag.
Evan Cheng2bda17c2007-06-29 01:25:06 +00001257 // Prevent PPC::PRED_* from being selected into LI.
Dan Gohman475871a2008-07-27 21:46:04 +00001258 SDValue Pred =
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00001259 getI32Imm(cast<ConstantSDNode>(N->getOperand(1))->getZExtValue());
Dan Gohman475871a2008-07-27 21:46:04 +00001260 SDValue Ops[] = { Pred, N->getOperand(2), N->getOperand(3),
Chris Lattner18258c62006-11-17 22:37:34 +00001261 N->getOperand(0), N->getOperand(4) };
Owen Anderson825b72b2009-08-11 20:47:22 +00001262 return CurDAG->SelectNodeTo(N, PPC::BCC, MVT::Other, Ops, 5);
Chris Lattner18258c62006-11-17 22:37:34 +00001263 }
Nate Begeman81e80972006-03-17 01:40:33 +00001264 case ISD::BR_CC: {
Chris Lattner2fbb4572005-08-21 18:50:37 +00001265 ISD::CondCode CC = cast<CondCodeSDNode>(N->getOperand(1))->get();
Dale Johannesenf5f5dce2009-02-06 19:16:40 +00001266 SDValue CondCode = SelectCC(N->getOperand(2), N->getOperand(3), CC, dl);
Andrew Trick6e8f4c42010-12-24 04:28:06 +00001267 SDValue Ops[] = { getI32Imm(getPredicateForSetCC(CC)), CondCode,
Evan Cheng0b828e02006-08-27 08:14:06 +00001268 N->getOperand(4), N->getOperand(0) };
Owen Anderson825b72b2009-08-11 20:47:22 +00001269 return CurDAG->SelectNodeTo(N, PPC::BCC, MVT::Other, Ops, 4);
Chris Lattner2fbb4572005-08-21 18:50:37 +00001270 }
Nate Begeman37efe672006-04-22 18:53:45 +00001271 case ISD::BRIND: {
Chris Lattnercf006312006-06-10 01:15:02 +00001272 // FIXME: Should custom lower this.
Dan Gohman475871a2008-07-27 21:46:04 +00001273 SDValue Chain = N->getOperand(0);
1274 SDValue Target = N->getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +00001275 unsigned Opc = Target.getValueType() == MVT::i32 ? PPC::MTCTR : PPC::MTCTR8;
Roman Divacky0c9b5592011-06-03 15:47:49 +00001276 unsigned Reg = Target.getValueType() == MVT::i32 ? PPC::BCTR : PPC::BCTR8;
Hal Finkel67724522011-12-08 04:36:44 +00001277 Chain = SDValue(CurDAG->getMachineNode(Opc, dl, MVT::Glue, Target,
Dan Gohman602b0c82009-09-25 18:54:59 +00001278 Chain), 0);
Roman Divacky0c9b5592011-06-03 15:47:49 +00001279 return CurDAG->SelectNodeTo(N, Reg, MVT::Other, Chain);
Nate Begeman37efe672006-04-22 18:53:45 +00001280 }
Bill Schmidt34a9d4b2012-11-27 17:35:46 +00001281 case PPCISD::TOC_ENTRY: {
1282 assert (PPCSubTarget.isPPC64() && "Only supported for 64-bit ABI");
1283
1284 // For medium code model, we generate two instructions as described
1285 // below. Otherwise we allow SelectCodeCommon to handle this, selecting
1286 // one of LDtoc, LDtocJTI, and LDtocCPT.
1287 if (TM.getCodeModel() != CodeModel::Medium)
1288 break;
1289
1290 // The first source operand is a TargetGlobalAddress or a
1291 // TargetJumpTable. If it is an externally defined symbol, a symbol
1292 // with common linkage, a function address, or a jump table address,
1293 // we generate:
1294 // LDtocL(<ga:@sym>, ADDIStocHA(%X2, <ga:@sym>))
1295 // Otherwise we generate:
1296 // ADDItocL(ADDIStocHA(%X2, <ga:@sym>), <ga:@sym>)
1297 SDValue GA = N->getOperand(0);
1298 SDValue TOCbase = N->getOperand(1);
1299 SDNode *Tmp = CurDAG->getMachineNode(PPC::ADDIStocHA, dl, MVT::i64,
1300 TOCbase, GA);
1301
1302 if (isa<JumpTableSDNode>(GA))
1303 return CurDAG->getMachineNode(PPC::LDtocL, dl, MVT::i64, GA,
1304 SDValue(Tmp, 0));
1305
1306 if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(GA)) {
1307 const GlobalValue *GValue = G->getGlobal();
Bill Schmidt5b7f9212013-01-07 19:29:18 +00001308 const GlobalAlias *GAlias = dyn_cast<GlobalAlias>(GValue);
1309 const GlobalValue *RealGValue = GAlias ?
1310 GAlias->resolveAliasedGlobal(false) : GValue;
1311 const GlobalVariable *GVar = dyn_cast<GlobalVariable>(RealGValue);
1312 assert((GVar || isa<Function>(RealGValue)) &&
Bill Schmidt34a9d4b2012-11-27 17:35:46 +00001313 "Unexpected global value subclass!");
1314
1315 // An external variable is one without an initializer. For these,
1316 // for variables with common linkage, and for Functions, generate
1317 // the LDtocL form.
Bill Schmidt5b7f9212013-01-07 19:29:18 +00001318 if (!GVar || !GVar->hasInitializer() || RealGValue->hasCommonLinkage() ||
1319 RealGValue->hasAvailableExternallyLinkage())
Bill Schmidt34a9d4b2012-11-27 17:35:46 +00001320 return CurDAG->getMachineNode(PPC::LDtocL, dl, MVT::i64, GA,
1321 SDValue(Tmp, 0));
1322 }
1323
1324 return CurDAG->getMachineNode(PPC::ADDItocL, dl, MVT::i64,
1325 SDValue(Tmp, 0), GA);
1326 }
Bill Schmidtb34c79e2013-02-20 15:50:31 +00001327 case PPCISD::VADD_SPLAT: {
Bill Schmidtabc40282013-02-20 20:41:42 +00001328 // This expands into one of three sequences, depending on whether
1329 // the first operand is odd or even, positive or negative.
Bill Schmidtb34c79e2013-02-20 15:50:31 +00001330 assert(isa<ConstantSDNode>(N->getOperand(0)) &&
1331 isa<ConstantSDNode>(N->getOperand(1)) &&
1332 "Invalid operand on VADD_SPLAT!");
Bill Schmidtabc40282013-02-20 20:41:42 +00001333
1334 int Elt = N->getConstantOperandVal(0);
Bill Schmidtb34c79e2013-02-20 15:50:31 +00001335 int EltSize = N->getConstantOperandVal(1);
Bill Schmidtabc40282013-02-20 20:41:42 +00001336 unsigned Opc1, Opc2, Opc3;
Bill Schmidtb34c79e2013-02-20 15:50:31 +00001337 EVT VT;
Bill Schmidtabc40282013-02-20 20:41:42 +00001338
Bill Schmidtb34c79e2013-02-20 15:50:31 +00001339 if (EltSize == 1) {
1340 Opc1 = PPC::VSPLTISB;
1341 Opc2 = PPC::VADDUBM;
Bill Schmidtabc40282013-02-20 20:41:42 +00001342 Opc3 = PPC::VSUBUBM;
Bill Schmidtb34c79e2013-02-20 15:50:31 +00001343 VT = MVT::v16i8;
1344 } else if (EltSize == 2) {
1345 Opc1 = PPC::VSPLTISH;
1346 Opc2 = PPC::VADDUHM;
Bill Schmidtabc40282013-02-20 20:41:42 +00001347 Opc3 = PPC::VSUBUHM;
Bill Schmidtb34c79e2013-02-20 15:50:31 +00001348 VT = MVT::v8i16;
1349 } else {
1350 assert(EltSize == 4 && "Invalid element size on VADD_SPLAT!");
1351 Opc1 = PPC::VSPLTISW;
1352 Opc2 = PPC::VADDUWM;
Bill Schmidtabc40282013-02-20 20:41:42 +00001353 Opc3 = PPC::VSUBUWM;
Bill Schmidtb34c79e2013-02-20 15:50:31 +00001354 VT = MVT::v4i32;
1355 }
Bill Schmidtabc40282013-02-20 20:41:42 +00001356
1357 if ((Elt & 1) == 0) {
1358 // Elt is even, in the range [-32,-18] + [16,30].
1359 //
1360 // Convert: VADD_SPLAT elt, size
1361 // Into: tmp = VSPLTIS[BHW] elt
1362 // VADDU[BHW]M tmp, tmp
1363 // Where: [BHW] = B for size = 1, H for size = 2, W for size = 4
1364 SDValue EltVal = getI32Imm(Elt >> 1);
1365 SDNode *Tmp = CurDAG->getMachineNode(Opc1, dl, VT, EltVal);
1366 SDValue TmpVal = SDValue(Tmp, 0);
1367 return CurDAG->getMachineNode(Opc2, dl, VT, TmpVal, TmpVal);
1368
1369 } else if (Elt > 0) {
1370 // Elt is odd and positive, in the range [17,31].
1371 //
1372 // Convert: VADD_SPLAT elt, size
1373 // Into: tmp1 = VSPLTIS[BHW] elt-16
1374 // tmp2 = VSPLTIS[BHW] -16
1375 // VSUBU[BHW]M tmp1, tmp2
1376 SDValue EltVal = getI32Imm(Elt - 16);
1377 SDNode *Tmp1 = CurDAG->getMachineNode(Opc1, dl, VT, EltVal);
1378 EltVal = getI32Imm(-16);
1379 SDNode *Tmp2 = CurDAG->getMachineNode(Opc1, dl, VT, EltVal);
1380 return CurDAG->getMachineNode(Opc3, dl, VT, SDValue(Tmp1, 0),
1381 SDValue(Tmp2, 0));
1382
1383 } else {
1384 // Elt is odd and negative, in the range [-31,-17].
1385 //
1386 // Convert: VADD_SPLAT elt, size
1387 // Into: tmp1 = VSPLTIS[BHW] elt+16
1388 // tmp2 = VSPLTIS[BHW] -16
1389 // VADDU[BHW]M tmp1, tmp2
1390 SDValue EltVal = getI32Imm(Elt + 16);
1391 SDNode *Tmp1 = CurDAG->getMachineNode(Opc1, dl, VT, EltVal);
1392 EltVal = getI32Imm(-16);
1393 SDNode *Tmp2 = CurDAG->getMachineNode(Opc1, dl, VT, EltVal);
1394 return CurDAG->getMachineNode(Opc2, dl, VT, SDValue(Tmp1, 0),
1395 SDValue(Tmp2, 0));
1396 }
Bill Schmidtb34c79e2013-02-20 15:50:31 +00001397 }
Chris Lattnera5a91b12005-08-17 19:33:03 +00001398 }
Andrew Trick6e8f4c42010-12-24 04:28:06 +00001399
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001400 return SelectCode(N);
Chris Lattnera5a91b12005-08-17 19:33:03 +00001401}
1402
Bill Schmidt42102112013-02-21 00:38:25 +00001403/// PostProcessISelDAG - Perform some late peephole optimizations
1404/// on the DAG representation.
1405void PPCDAGToDAGISel::PostprocessISelDAG() {
1406
1407 // Skip peepholes at -O0.
1408 if (TM.getOptLevel() == CodeGenOpt::None)
1409 return;
1410
1411 // These optimizations are currently supported only for 64-bit SVR4.
1412 if (PPCSubTarget.isDarwin() || !PPCSubTarget.isPPC64())
1413 return;
1414
1415 SelectionDAG::allnodes_iterator Position(CurDAG->getRoot().getNode());
1416 ++Position;
1417
1418 while (Position != CurDAG->allnodes_begin()) {
1419 SDNode *N = --Position;
1420 // Skip dead nodes and any non-machine opcodes.
1421 if (N->use_empty() || !N->isMachineOpcode())
1422 continue;
1423
1424 unsigned FirstOp;
1425 unsigned StorageOpcode = N->getMachineOpcode();
1426
1427 switch (StorageOpcode) {
1428 default: continue;
1429
1430 case PPC::LBZ:
1431 case PPC::LBZ8:
1432 case PPC::LD:
1433 case PPC::LFD:
1434 case PPC::LFS:
1435 case PPC::LHA:
1436 case PPC::LHA8:
1437 case PPC::LHZ:
1438 case PPC::LHZ8:
1439 case PPC::LWA:
1440 case PPC::LWZ:
1441 case PPC::LWZ8:
1442 FirstOp = 0;
1443 break;
1444
1445 case PPC::STB:
1446 case PPC::STB8:
1447 case PPC::STD:
1448 case PPC::STFD:
1449 case PPC::STFS:
1450 case PPC::STH:
1451 case PPC::STH8:
1452 case PPC::STW:
1453 case PPC::STW8:
1454 FirstOp = 1;
1455 break;
1456 }
1457
1458 // If this is a load or store with a zero offset, we may be able to
1459 // fold an add-immediate into the memory operation.
1460 if (!isa<ConstantSDNode>(N->getOperand(FirstOp)) ||
1461 N->getConstantOperandVal(FirstOp) != 0)
1462 continue;
1463
1464 SDValue Base = N->getOperand(FirstOp + 1);
1465 if (!Base.isMachineOpcode())
1466 continue;
1467
1468 unsigned Flags = 0;
1469 bool ReplaceFlags = true;
1470
1471 // When the feeding operation is an add-immediate of some sort,
1472 // determine whether we need to add relocation information to the
1473 // target flags on the immediate operand when we fold it into the
1474 // load instruction.
1475 //
1476 // For something like ADDItocL, the relocation information is
1477 // inferred from the opcode; when we process it in the AsmPrinter,
1478 // we add the necessary relocation there. A load, though, can receive
1479 // relocation from various flavors of ADDIxxx, so we need to carry
1480 // the relocation information in the target flags.
1481 switch (Base.getMachineOpcode()) {
1482 default: continue;
1483
1484 case PPC::ADDI8:
1485 case PPC::ADDI8L:
1486 case PPC::ADDIL:
1487 // In some cases (such as TLS) the relocation information
1488 // is already in place on the operand, so copying the operand
1489 // is sufficient.
1490 ReplaceFlags = false;
1491 // For these cases, the immediate may not be divisible by 4, in
1492 // which case the fold is illegal for DS-form instructions. (The
1493 // other cases provide aligned addresses and are always safe.)
1494 if ((StorageOpcode == PPC::LWA ||
1495 StorageOpcode == PPC::LD ||
1496 StorageOpcode == PPC::STD) &&
1497 (!isa<ConstantSDNode>(Base.getOperand(1)) ||
1498 Base.getConstantOperandVal(1) % 4 != 0))
1499 continue;
1500 break;
1501 case PPC::ADDIdtprelL:
1502 Flags = PPCII::MO_DTPREL16_LO;
1503 break;
1504 case PPC::ADDItlsldL:
1505 Flags = PPCII::MO_TLSLD16_LO;
1506 break;
1507 case PPC::ADDItocL:
1508 Flags = PPCII::MO_TOC16_LO;
1509 break;
1510 }
1511
1512 // We found an opportunity. Reverse the operands from the add
1513 // immediate and substitute them into the load or store. If
1514 // needed, update the target flags for the immediate operand to
1515 // reflect the necessary relocation information.
1516 DEBUG(dbgs() << "Folding add-immediate into mem-op:\nBase: ");
1517 DEBUG(Base->dump(CurDAG));
1518 DEBUG(dbgs() << "\nN: ");
1519 DEBUG(N->dump(CurDAG));
1520 DEBUG(dbgs() << "\n");
1521
1522 SDValue ImmOpnd = Base.getOperand(1);
1523
1524 // If the relocation information isn't already present on the
1525 // immediate operand, add it now.
1526 if (ReplaceFlags) {
Bill Schmidt05145952013-02-21 14:35:42 +00001527 if (GlobalAddressSDNode *GA = dyn_cast<GlobalAddressSDNode>(ImmOpnd)) {
Bill Schmidt42102112013-02-21 00:38:25 +00001528 DebugLoc dl = GA->getDebugLoc();
1529 const GlobalValue *GV = GA->getGlobal();
1530 ImmOpnd = CurDAG->getTargetGlobalAddress(GV, dl, MVT::i64, 0, Flags);
Bill Schmidt05145952013-02-21 14:35:42 +00001531 }
1532 else if (ConstantPoolSDNode *CP = dyn_cast<ConstantPoolSDNode>(ImmOpnd)) {
1533 const Constant *C = CP->getConstVal();
1534 ImmOpnd = CurDAG->getTargetConstantPool(C, MVT::i64,
1535 CP->getAlignment(),
1536 0, Flags);
Bill Schmidt42102112013-02-21 00:38:25 +00001537 }
1538 }
1539
1540 if (FirstOp == 1) // Store
1541 (void)CurDAG->UpdateNodeOperands(N, N->getOperand(0), ImmOpnd,
1542 Base.getOperand(0), N->getOperand(3));
1543 else // Load
1544 (void)CurDAG->UpdateNodeOperands(N, ImmOpnd, Base.getOperand(0),
1545 N->getOperand(2));
1546
1547 // The add-immediate may now be dead, in which case remove it.
1548 if (Base.getNode()->use_empty())
1549 CurDAG->RemoveDeadNode(Base.getNode());
1550 }
1551}
Chris Lattnera5a91b12005-08-17 19:33:03 +00001552
Chris Lattnercf006312006-06-10 01:15:02 +00001553
Andrew Trick6e8f4c42010-12-24 04:28:06 +00001554/// createPPCISelDag - This pass converts a legalized DAG into a
Chris Lattnera5a91b12005-08-17 19:33:03 +00001555/// PowerPC-specific DAG, ready for instruction scheduling.
1556///
Evan Chengc4c62572006-03-13 23:20:37 +00001557FunctionPass *llvm::createPPCISelDag(PPCTargetMachine &TM) {
Nate Begeman1d9d7422005-10-18 00:28:58 +00001558 return new PPCDAGToDAGISel(TM);
Chris Lattnera5a91b12005-08-17 19:33:03 +00001559}
1560
Krzysztof Parzyszek96848df2013-02-13 17:40:07 +00001561static void initializePassOnce(PassRegistry &Registry) {
1562 const char *Name = "PowerPC DAG->DAG Pattern Instruction Selection";
1563 PassInfo *PI = new PassInfo(Name, "ppc-codegen", &SelectionDAGISel::ID, 0,
1564 false, false);
1565 Registry.registerPass(*PI, true);
1566}
1567
1568void llvm::initializePPCDAGToDAGISelPass(PassRegistry &Registry) {
1569 CALL_ONCE_INITIALIZATION(initializePassOnce);
1570}
1571