1 //===-- PPCISelDAGToDAG.cpp - PPC --pattern matching inst selector --------===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by Chris Lattner and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines a pattern matching instruction selector for PowerPC,
11 // converting from a legalized dag to a PPC dag.
13 //===----------------------------------------------------------------------===//
15 #define DEBUG_TYPE "ppc-codegen"
17 #include "PPCPredicates.h"
18 #include "PPCTargetMachine.h"
19 #include "PPCISelLowering.h"
20 #include "PPCHazardRecognizers.h"
21 #include "llvm/CodeGen/MachineInstrBuilder.h"
22 #include "llvm/CodeGen/MachineFunction.h"
23 #include "llvm/CodeGen/SSARegMap.h"
24 #include "llvm/CodeGen/SelectionDAG.h"
25 #include "llvm/CodeGen/SelectionDAGISel.h"
26 #include "llvm/Target/TargetOptions.h"
27 #include "llvm/Constants.h"
28 #include "llvm/GlobalValue.h"
29 #include "llvm/Intrinsics.h"
30 #include "llvm/Support/Debug.h"
31 #include "llvm/Support/MathExtras.h"
32 #include "llvm/Support/Compiler.h"
38 //===--------------------------------------------------------------------===//
39 /// PPCDAGToDAGISel - PPC specific code to select PPC machine
40 /// instructions for SelectionDAG operations.
42 class VISIBILITY_HIDDEN PPCDAGToDAGISel
: public SelectionDAGISel
{
44 PPCTargetLowering PPCLowering
;
45 unsigned GlobalBaseReg
;
47 PPCDAGToDAGISel(PPCTargetMachine
&tm
)
48 : SelectionDAGISel(PPCLowering
), TM(tm
),
49 PPCLowering(*TM
.getTargetLowering()) {}
51 virtual bool runOnFunction(Function
&Fn
) {
52 // Make sure we re-emit a set of the global base reg if necessary
54 SelectionDAGISel::runOnFunction(Fn
);
60 /// getI32Imm - Return a target constant with the specified value, of type
62 inline SDOperand
getI32Imm(unsigned Imm
) {
63 return CurDAG
->getTargetConstant(Imm
, MVT::i32
);
66 /// getI64Imm - Return a target constant with the specified value, of type
68 inline SDOperand
getI64Imm(uint64_t Imm
) {
69 return CurDAG
->getTargetConstant(Imm
, MVT::i64
);
72 /// getSmallIPtrImm - Return a target constant of pointer type.
73 inline SDOperand
getSmallIPtrImm(unsigned Imm
) {
74 return CurDAG
->getTargetConstant(Imm
, PPCLowering
.getPointerTy());
77 /// isRunOfOnes - Returns true iff Val consists of one contiguous run of 1s
78 /// with any number of 0s on either side. The 1s are allowed to wrap from
79 /// LSB to MSB, so 0x000FFF0, 0x0000FFFF, and 0xFF0000FF are all runs.
80 /// 0x0F0F0000 is not, since all 1s are not contiguous.
81 static bool isRunOfOnes(unsigned Val
, unsigned &MB
, unsigned &ME
);
84 /// isRotateAndMask - Returns true if Mask and Shift can be folded into a
85 /// rotate and mask opcode and mask operation.
86 static bool isRotateAndMask(SDNode
*N
, unsigned Mask
, bool IsShiftMask
,
87 unsigned &SH
, unsigned &MB
, unsigned &ME
);
89 /// getGlobalBaseReg - insert code into the entry mbb to materialize the PIC
90 /// base register. Return the virtual register that holds this value.
91 SDNode
*getGlobalBaseReg();
93 // Select - Convert the specified operand from a target-independent to a
94 // target-specific node if it hasn't already been changed.
95 SDNode
*Select(SDOperand Op
);
97 SDNode
*SelectBitfieldInsert(SDNode
*N
);
99 /// SelectCC - Select a comparison of the specified values with the
100 /// specified condition code, returning the CR# of the expression.
101 SDOperand
SelectCC(SDOperand LHS
, SDOperand RHS
, ISD::CondCode CC
);
103 /// SelectAddrImm - Returns true if the address N can be represented by
104 /// a base register plus a signed 16-bit displacement [r+imm].
105 bool SelectAddrImm(SDOperand Op
, SDOperand N
, SDOperand
&Disp
,
107 return PPCLowering
.SelectAddressRegImm(N
, Disp
, Base
, *CurDAG
);
110 /// SelectAddrImmOffs - Return true if the operand is valid for a preinc
111 /// immediate field. Because preinc imms have already been validated, just
113 bool SelectAddrImmOffs(SDOperand Op
, SDOperand N
, SDOperand
&Out
) const {
118 /// SelectAddrIdx - Given the specified addressed, check to see if it can be
119 /// represented as an indexed [r+r] operation. Returns false if it can
120 /// be represented by [r+imm], which are preferred.
121 bool SelectAddrIdx(SDOperand Op
, SDOperand N
, SDOperand
&Base
,
123 return PPCLowering
.SelectAddressRegReg(N
, Base
, Index
, *CurDAG
);
126 /// SelectAddrIdxOnly - Given the specified addressed, force it to be
127 /// represented as an indexed [r+r] operation.
128 bool SelectAddrIdxOnly(SDOperand Op
, SDOperand N
, SDOperand
&Base
,
130 return PPCLowering
.SelectAddressRegRegOnly(N
, Base
, Index
, *CurDAG
);
133 /// SelectAddrImmShift - Returns true if the address N can be represented by
134 /// a base register plus a signed 14-bit displacement [r+imm*4]. Suitable
135 /// for use by STD and friends.
136 bool SelectAddrImmShift(SDOperand Op
, SDOperand N
, SDOperand
&Disp
,
138 return PPCLowering
.SelectAddressRegImmShift(N
, Disp
, Base
, *CurDAG
);
141 /// SelectInlineAsmMemoryOperand - Implement addressing mode selection for
142 /// inline asm expressions.
143 virtual bool SelectInlineAsmMemoryOperand(const SDOperand
&Op
,
145 std::vector
<SDOperand
> &OutOps
,
148 switch (ConstraintCode
) {
149 default: return true;
151 if (!SelectAddrIdx(Op
, Op
, Op0
, Op1
))
152 SelectAddrImm(Op
, Op
, Op0
, Op1
);
154 case 'o': // offsetable
155 if (!SelectAddrImm(Op
, Op
, Op0
, Op1
)) {
157 AddToISelQueue(Op0
); // r+0.
158 Op1
= getSmallIPtrImm(0);
161 case 'v': // not offsetable
162 SelectAddrIdxOnly(Op
, Op
, Op0
, Op1
);
166 OutOps
.push_back(Op0
);
167 OutOps
.push_back(Op1
);
171 SDOperand
BuildSDIVSequence(SDNode
*N
);
172 SDOperand
BuildUDIVSequence(SDNode
*N
);
174 /// InstructionSelectBasicBlock - This callback is invoked by
175 /// SelectionDAGISel when it has created a SelectionDAG for us to codegen.
176 virtual void InstructionSelectBasicBlock(SelectionDAG
&DAG
);
178 void InsertVRSaveCode(Function
&Fn
);
180 virtual const char *getPassName() const {
181 return "PowerPC DAG->DAG Pattern Instruction Selection";
184 /// CreateTargetHazardRecognizer - Return the hazard recognizer to use for
185 /// this target when scheduling the DAG.
186 virtual HazardRecognizer
*CreateTargetHazardRecognizer() {
187 // Should use subtarget info to pick the right hazard recognizer. For
188 // now, always return a PPC970 recognizer.
189 const TargetInstrInfo
*II
= PPCLowering
.getTargetMachine().getInstrInfo();
190 assert(II
&& "No InstrInfo?");
191 return new PPCHazardRecognizer970(*II
);
194 // Include the pieces autogenerated from the target description.
195 #include "PPCGenDAGISel.inc"
198 SDNode
*SelectSETCC(SDOperand Op
);
202 /// InstructionSelectBasicBlock - This callback is invoked by
203 /// SelectionDAGISel when it has created a SelectionDAG for us to codegen.
204 void PPCDAGToDAGISel::InstructionSelectBasicBlock(SelectionDAG
&DAG
) {
207 // Select target instructions for the DAG.
208 DAG
.setRoot(SelectRoot(DAG
.getRoot()));
209 DAG
.RemoveDeadNodes();
211 // Emit machine code to BB.
212 ScheduleAndEmitDAG(DAG
);
215 /// InsertVRSaveCode - Once the entire function has been instruction selected,
216 /// all virtual registers are created and all machine instructions are built,
217 /// check to see if we need to save/restore VRSAVE. If so, do it.
218 void PPCDAGToDAGISel::InsertVRSaveCode(Function
&F
) {
219 // Check to see if this function uses vector registers, which means we have to
220 // save and restore the VRSAVE register and update it with the regs we use.
222 // In this case, there will be virtual registers of vector type type created
223 // by the scheduler. Detect them now.
224 MachineFunction
&Fn
= MachineFunction::get(&F
);
225 SSARegMap
*RegMap
= Fn
.getSSARegMap();
226 bool HasVectorVReg
= false;
227 for (unsigned i
= MRegisterInfo::FirstVirtualRegister
,
228 e
= RegMap
->getLastVirtReg()+1; i
!= e
; ++i
)
229 if (RegMap
->getRegClass(i
) == &PPC::VRRCRegClass
) {
230 HasVectorVReg
= true;
233 if (!HasVectorVReg
) return; // nothing to do.
235 // If we have a vector register, we want to emit code into the entry and exit
236 // blocks to save and restore the VRSAVE register. We do this here (instead
237 // of marking all vector instructions as clobbering VRSAVE) for two reasons:
239 // 1. This (trivially) reduces the load on the register allocator, by not
240 // having to represent the live range of the VRSAVE register.
241 // 2. This (more significantly) allows us to create a temporary virtual
242 // register to hold the saved VRSAVE value, allowing this temporary to be
243 // register allocated, instead of forcing it to be spilled to the stack.
245 // Create two vregs - one to hold the VRSAVE register that is live-in to the
246 // function and one for the value after having bits or'd into it.
247 unsigned InVRSAVE
= RegMap
->createVirtualRegister(&PPC::GPRCRegClass
);
248 unsigned UpdatedVRSAVE
= RegMap
->createVirtualRegister(&PPC::GPRCRegClass
);
250 const TargetInstrInfo
&TII
= *TM
.getInstrInfo();
251 MachineBasicBlock
&EntryBB
= *Fn
.begin();
252 // Emit the following code into the entry block:
253 // InVRSAVE = MFVRSAVE
254 // UpdatedVRSAVE = UPDATE_VRSAVE InVRSAVE
255 // MTVRSAVE UpdatedVRSAVE
256 MachineBasicBlock::iterator IP
= EntryBB
.begin(); // Insert Point
257 BuildMI(EntryBB
, IP
, TII
.get(PPC::MFVRSAVE
), InVRSAVE
);
258 BuildMI(EntryBB
, IP
, TII
.get(PPC::UPDATE_VRSAVE
), UpdatedVRSAVE
).addReg(InVRSAVE
);
259 BuildMI(EntryBB
, IP
, TII
.get(PPC::MTVRSAVE
)).addReg(UpdatedVRSAVE
);
261 // Find all return blocks, outputting a restore in each epilog.
262 for (MachineFunction::iterator BB
= Fn
.begin(), E
= Fn
.end(); BB
!= E
; ++BB
) {
263 if (!BB
->empty() && TII
.isReturn(BB
->back().getOpcode())) {
264 IP
= BB
->end(); --IP
;
266 // Skip over all terminator instructions, which are part of the return
268 MachineBasicBlock::iterator I2
= IP
;
269 while (I2
!= BB
->begin() && TII
.isTerminatorInstr((--I2
)->getOpcode()))
272 // Emit: MTVRSAVE InVRSave
273 BuildMI(*BB
, IP
, TII
.get(PPC::MTVRSAVE
)).addReg(InVRSAVE
);
279 /// getGlobalBaseReg - Output the instructions required to put the
280 /// base address to use for accessing globals into a register.
282 SDNode
*PPCDAGToDAGISel::getGlobalBaseReg() {
283 if (!GlobalBaseReg
) {
284 const TargetInstrInfo
&TII
= *TM
.getInstrInfo();
285 // Insert the set of GlobalBaseReg into the first MBB of the function
286 MachineBasicBlock
&FirstMBB
= BB
->getParent()->front();
287 MachineBasicBlock::iterator MBBI
= FirstMBB
.begin();
288 SSARegMap
*RegMap
= BB
->getParent()->getSSARegMap();
290 if (PPCLowering
.getPointerTy() == MVT::i32
) {
291 GlobalBaseReg
= RegMap
->createVirtualRegister(PPC::GPRCRegisterClass
);
292 BuildMI(FirstMBB
, MBBI
, TII
.get(PPC::MovePCtoLR
), PPC::LR
);
293 BuildMI(FirstMBB
, MBBI
, TII
.get(PPC::MFLR
), GlobalBaseReg
);
295 GlobalBaseReg
= RegMap
->createVirtualRegister(PPC::G8RCRegisterClass
);
296 BuildMI(FirstMBB
, MBBI
, TII
.get(PPC::MovePCtoLR8
), PPC::LR8
);
297 BuildMI(FirstMBB
, MBBI
, TII
.get(PPC::MFLR8
), GlobalBaseReg
);
300 return CurDAG
->getRegister(GlobalBaseReg
, PPCLowering
.getPointerTy()).Val
;
303 /// isIntS16Immediate - This method tests to see if the node is either a 32-bit
304 /// or 64-bit immediate, and if the value can be accurately represented as a
305 /// sign extension from a 16-bit value. If so, this returns true and the
307 static bool isIntS16Immediate(SDNode
*N
, short &Imm
) {
308 if (N
->getOpcode() != ISD::Constant
)
311 Imm
= (short)cast
<ConstantSDNode
>(N
)->getValue();
312 if (N
->getValueType(0) == MVT::i32
)
313 return Imm
== (int32_t)cast
<ConstantSDNode
>(N
)->getValue();
315 return Imm
== (int64_t)cast
<ConstantSDNode
>(N
)->getValue();
318 static bool isIntS16Immediate(SDOperand Op
, short &Imm
) {
319 return isIntS16Immediate(Op
.Val
, Imm
);
323 /// isInt32Immediate - This method tests to see if the node is a 32-bit constant
324 /// operand. If so Imm will receive the 32-bit value.
325 static bool isInt32Immediate(SDNode
*N
, unsigned &Imm
) {
326 if (N
->getOpcode() == ISD::Constant
&& N
->getValueType(0) == MVT::i32
) {
327 Imm
= cast
<ConstantSDNode
>(N
)->getValue();
333 /// isInt64Immediate - This method tests to see if the node is a 64-bit constant
334 /// operand. If so Imm will receive the 64-bit value.
335 static bool isInt64Immediate(SDNode
*N
, uint64_t &Imm
) {
336 if (N
->getOpcode() == ISD::Constant
&& N
->getValueType(0) == MVT::i64
) {
337 Imm
= cast
<ConstantSDNode
>(N
)->getValue();
343 // isInt32Immediate - This method tests to see if a constant operand.
344 // If so Imm will receive the 32 bit value.
345 static bool isInt32Immediate(SDOperand N
, unsigned &Imm
) {
346 return isInt32Immediate(N
.Val
, Imm
);
350 // isOpcWithIntImmediate - This method tests to see if the node is a specific
351 // opcode and that it has a immediate integer right operand.
352 // If so Imm will receive the 32 bit value.
353 static bool isOpcWithIntImmediate(SDNode
*N
, unsigned Opc
, unsigned& Imm
) {
354 return N
->getOpcode() == Opc
&& isInt32Immediate(N
->getOperand(1).Val
, Imm
);
357 bool PPCDAGToDAGISel::isRunOfOnes(unsigned Val
, unsigned &MB
, unsigned &ME
) {
358 if (isShiftedMask_32(Val
)) {
359 // look for the first non-zero bit
360 MB
= CountLeadingZeros_32(Val
);
361 // look for the first zero bit after the run of ones
362 ME
= CountLeadingZeros_32((Val
- 1) ^ Val
);
365 Val
= ~Val
; // invert mask
366 if (isShiftedMask_32(Val
)) {
367 // effectively look for the first zero bit
368 ME
= CountLeadingZeros_32(Val
) - 1;
369 // effectively look for the first one bit after the run of zeros
370 MB
= CountLeadingZeros_32((Val
- 1) ^ Val
) + 1;
378 bool PPCDAGToDAGISel::isRotateAndMask(SDNode
*N
, unsigned Mask
,
379 bool IsShiftMask
, unsigned &SH
,
380 unsigned &MB
, unsigned &ME
) {
381 // Don't even go down this path for i64, since different logic will be
382 // necessary for rldicl/rldicr/rldimi.
383 if (N
->getValueType(0) != MVT::i32
)
387 unsigned Indeterminant
= ~0; // bit mask marking indeterminant results
388 unsigned Opcode
= N
->getOpcode();
389 if (N
->getNumOperands() != 2 ||
390 !isInt32Immediate(N
->getOperand(1).Val
, Shift
) || (Shift
> 31))
393 if (Opcode
== ISD::SHL
) {
394 // apply shift left to mask if it comes first
395 if (IsShiftMask
) Mask
= Mask
<< Shift
;
396 // determine which bits are made indeterminant by shift
397 Indeterminant
= ~(0xFFFFFFFFu
<< Shift
);
398 } else if (Opcode
== ISD::SRL
) {
399 // apply shift right to mask if it comes first
400 if (IsShiftMask
) Mask
= Mask
>> Shift
;
401 // determine which bits are made indeterminant by shift
402 Indeterminant
= ~(0xFFFFFFFFu
>> Shift
);
403 // adjust for the left rotate
405 } else if (Opcode
== ISD::ROTL
) {
411 // if the mask doesn't intersect any Indeterminant bits
412 if (Mask
&& !(Mask
& Indeterminant
)) {
414 // make sure the mask is still a mask (wrap arounds may not be)
415 return isRunOfOnes(Mask
, MB
, ME
);
420 /// SelectBitfieldInsert - turn an or of two masked values into
421 /// the rotate left word immediate then mask insert (rlwimi) instruction.
422 SDNode
*PPCDAGToDAGISel::SelectBitfieldInsert(SDNode
*N
) {
423 SDOperand Op0
= N
->getOperand(0);
424 SDOperand Op1
= N
->getOperand(1);
426 uint64_t LKZ
, LKO
, RKZ
, RKO
;
427 CurDAG
->ComputeMaskedBits(Op0
, 0xFFFFFFFFULL
, LKZ
, LKO
);
428 CurDAG
->ComputeMaskedBits(Op1
, 0xFFFFFFFFULL
, RKZ
, RKO
);
430 unsigned TargetMask
= LKZ
;
431 unsigned InsertMask
= RKZ
;
433 if ((TargetMask
| InsertMask
) == 0xFFFFFFFF) {
434 unsigned Op0Opc
= Op0
.getOpcode();
435 unsigned Op1Opc
= Op1
.getOpcode();
436 unsigned Value
, SH
= 0;
437 TargetMask
= ~TargetMask
;
438 InsertMask
= ~InsertMask
;
440 // If the LHS has a foldable shift and the RHS does not, then swap it to the
441 // RHS so that we can fold the shift into the insert.
442 if (Op0Opc
== ISD::AND
&& Op1Opc
== ISD::AND
) {
443 if (Op0
.getOperand(0).getOpcode() == ISD::SHL
||
444 Op0
.getOperand(0).getOpcode() == ISD::SRL
) {
445 if (Op1
.getOperand(0).getOpcode() != ISD::SHL
&&
446 Op1
.getOperand(0).getOpcode() != ISD::SRL
) {
448 std::swap(Op0Opc
, Op1Opc
);
449 std::swap(TargetMask
, InsertMask
);
452 } else if (Op0Opc
== ISD::SHL
|| Op0Opc
== ISD::SRL
) {
453 if (Op1Opc
== ISD::AND
&& Op1
.getOperand(0).getOpcode() != ISD::SHL
&&
454 Op1
.getOperand(0).getOpcode() != ISD::SRL
) {
456 std::swap(Op0Opc
, Op1Opc
);
457 std::swap(TargetMask
, InsertMask
);
462 if (InsertMask
&& isRunOfOnes(InsertMask
, MB
, ME
)) {
463 SDOperand Tmp1
, Tmp2
, Tmp3
;
464 bool DisjointMask
= (TargetMask
^ InsertMask
) == 0xFFFFFFFF;
466 if ((Op1Opc
== ISD::SHL
|| Op1Opc
== ISD::SRL
) &&
467 isInt32Immediate(Op1
.getOperand(1), Value
)) {
468 Op1
= Op1
.getOperand(0);
469 SH
= (Op1Opc
== ISD::SHL
) ? Value
: 32 - Value
;
471 if (Op1Opc
== ISD::AND
) {
472 unsigned SHOpc
= Op1
.getOperand(0).getOpcode();
473 if ((SHOpc
== ISD::SHL
|| SHOpc
== ISD::SRL
) &&
474 isInt32Immediate(Op1
.getOperand(0).getOperand(1), Value
)) {
475 Op1
= Op1
.getOperand(0).getOperand(0);
476 SH
= (SHOpc
== ISD::SHL
) ? Value
: 32 - Value
;
478 Op1
= Op1
.getOperand(0);
482 Tmp3
= (Op0Opc
== ISD::AND
&& DisjointMask
) ? Op0
.getOperand(0) : Op0
;
483 AddToISelQueue(Tmp3
);
486 SDOperand Ops
[] = { Tmp3
, Op1
, getI32Imm(SH
), getI32Imm(MB
),
488 return CurDAG
->getTargetNode(PPC::RLWIMI
, MVT::i32
, Ops
, 5);
494 /// SelectCC - Select a comparison of the specified values with the specified
495 /// condition code, returning the CR# of the expression.
496 SDOperand
PPCDAGToDAGISel::SelectCC(SDOperand LHS
, SDOperand RHS
,
498 // Always select the LHS.
502 if (LHS
.getValueType() == MVT::i32
) {
504 if (CC
== ISD::SETEQ
|| CC
== ISD::SETNE
) {
505 if (isInt32Immediate(RHS
, Imm
)) {
506 // SETEQ/SETNE comparison with 16-bit immediate, fold it.
508 return SDOperand(CurDAG
->getTargetNode(PPC::CMPLWI
, MVT::i32
, LHS
,
509 getI32Imm(Imm
& 0xFFFF)), 0);
510 // If this is a 16-bit signed immediate, fold it.
511 if (isInt16((int)Imm
))
512 return SDOperand(CurDAG
->getTargetNode(PPC::CMPWI
, MVT::i32
, LHS
,
513 getI32Imm(Imm
& 0xFFFF)), 0);
515 // For non-equality comparisons, the default code would materialize the
516 // constant, then compare against it, like this:
520 // Since we are just comparing for equality, we can emit this instead:
521 // xoris r0,r3,0x1234
522 // cmplwi cr0,r0,0x5678
524 SDOperand
Xor(CurDAG
->getTargetNode(PPC::XORIS
, MVT::i32
, LHS
,
525 getI32Imm(Imm
>> 16)), 0);
526 return SDOperand(CurDAG
->getTargetNode(PPC::CMPLWI
, MVT::i32
, Xor
,
527 getI32Imm(Imm
& 0xFFFF)), 0);
530 } else if (ISD::isUnsignedIntSetCC(CC
)) {
531 if (isInt32Immediate(RHS
, Imm
) && isUInt16(Imm
))
532 return SDOperand(CurDAG
->getTargetNode(PPC::CMPLWI
, MVT::i32
, LHS
,
533 getI32Imm(Imm
& 0xFFFF)), 0);
537 if (isIntS16Immediate(RHS
, SImm
))
538 return SDOperand(CurDAG
->getTargetNode(PPC::CMPWI
, MVT::i32
, LHS
,
539 getI32Imm((int)SImm
& 0xFFFF)),
543 } else if (LHS
.getValueType() == MVT::i64
) {
545 if (CC
== ISD::SETEQ
|| CC
== ISD::SETNE
) {
546 if (isInt64Immediate(RHS
.Val
, Imm
)) {
547 // SETEQ/SETNE comparison with 16-bit immediate, fold it.
549 return SDOperand(CurDAG
->getTargetNode(PPC::CMPLDI
, MVT::i64
, LHS
,
550 getI32Imm(Imm
& 0xFFFF)), 0);
551 // If this is a 16-bit signed immediate, fold it.
553 return SDOperand(CurDAG
->getTargetNode(PPC::CMPDI
, MVT::i64
, LHS
,
554 getI32Imm(Imm
& 0xFFFF)), 0);
556 // For non-equality comparisons, the default code would materialize the
557 // constant, then compare against it, like this:
561 // Since we are just comparing for equality, we can emit this instead:
562 // xoris r0,r3,0x1234
563 // cmpldi cr0,r0,0x5678
566 SDOperand
Xor(CurDAG
->getTargetNode(PPC::XORIS8
, MVT::i64
, LHS
,
567 getI64Imm(Imm
>> 16)), 0);
568 return SDOperand(CurDAG
->getTargetNode(PPC::CMPLDI
, MVT::i64
, Xor
,
569 getI64Imm(Imm
& 0xFFFF)), 0);
573 } else if (ISD::isUnsignedIntSetCC(CC
)) {
574 if (isInt64Immediate(RHS
.Val
, Imm
) && isUInt16(Imm
))
575 return SDOperand(CurDAG
->getTargetNode(PPC::CMPLDI
, MVT::i64
, LHS
,
576 getI64Imm(Imm
& 0xFFFF)), 0);
580 if (isIntS16Immediate(RHS
, SImm
))
581 return SDOperand(CurDAG
->getTargetNode(PPC::CMPDI
, MVT::i64
, LHS
,
582 getI64Imm(SImm
& 0xFFFF)),
586 } else if (LHS
.getValueType() == MVT::f32
) {
589 assert(LHS
.getValueType() == MVT::f64
&& "Unknown vt!");
593 return SDOperand(CurDAG
->getTargetNode(Opc
, MVT::i32
, LHS
, RHS
), 0);
596 static PPC::Predicate
getPredicateForSetCC(ISD::CondCode CC
) {
598 default: assert(0 && "Unknown condition!"); abort();
599 case ISD::SETOEQ
: // FIXME: This is incorrect see PR642.
601 case ISD::SETEQ
: return PPC::PRED_EQ
;
602 case ISD::SETONE
: // FIXME: This is incorrect see PR642.
604 case ISD::SETNE
: return PPC::PRED_NE
;
605 case ISD::SETOLT
: // FIXME: This is incorrect see PR642.
607 case ISD::SETLT
: return PPC::PRED_LT
;
608 case ISD::SETOLE
: // FIXME: This is incorrect see PR642.
610 case ISD::SETLE
: return PPC::PRED_LE
;
611 case ISD::SETOGT
: // FIXME: This is incorrect see PR642.
613 case ISD::SETGT
: return PPC::PRED_GT
;
614 case ISD::SETOGE
: // FIXME: This is incorrect see PR642.
616 case ISD::SETGE
: return PPC::PRED_GE
;
618 case ISD::SETO
: return PPC::PRED_NU
;
619 case ISD::SETUO
: return PPC::PRED_UN
;
623 /// getCRIdxForSetCC - Return the index of the condition register field
624 /// associated with the SetCC condition, and whether or not the field is
625 /// treated as inverted. That is, lt = 0; ge = 0 inverted.
626 static unsigned getCRIdxForSetCC(ISD::CondCode CC
, bool& Inv
) {
628 default: assert(0 && "Unknown condition!"); abort();
629 case ISD::SETOLT
: // FIXME: This is incorrect see PR642.
631 case ISD::SETLT
: Inv
= false; return 0;
632 case ISD::SETOGE
: // FIXME: This is incorrect see PR642.
634 case ISD::SETGE
: Inv
= true; return 0;
635 case ISD::SETOGT
: // FIXME: This is incorrect see PR642.
637 case ISD::SETGT
: Inv
= false; return 1;
638 case ISD::SETOLE
: // FIXME: This is incorrect see PR642.
640 case ISD::SETLE
: Inv
= true; return 1;
641 case ISD::SETOEQ
: // FIXME: This is incorrect see PR642.
643 case ISD::SETEQ
: Inv
= false; return 2;
644 case ISD::SETONE
: // FIXME: This is incorrect see PR642.
646 case ISD::SETNE
: Inv
= true; return 2;
647 case ISD::SETO
: Inv
= true; return 3;
648 case ISD::SETUO
: Inv
= false; return 3;
653 SDNode
*PPCDAGToDAGISel::SelectSETCC(SDOperand Op
) {
656 ISD::CondCode CC
= cast
<CondCodeSDNode
>(N
->getOperand(2))->get();
657 if (isInt32Immediate(N
->getOperand(1), Imm
)) {
658 // We can codegen setcc op, imm very efficiently compared to a brcond.
659 // Check for those cases here.
662 SDOperand Op
= N
->getOperand(0);
667 Op
= SDOperand(CurDAG
->getTargetNode(PPC::CNTLZW
, MVT::i32
, Op
), 0);
668 SDOperand Ops
[] = { Op
, getI32Imm(27), getI32Imm(5), getI32Imm(31) };
669 return CurDAG
->SelectNodeTo(N
, PPC::RLWINM
, MVT::i32
, Ops
, 4);
673 SDOperand(CurDAG
->getTargetNode(PPC::ADDIC
, MVT::i32
, MVT::Flag
,
674 Op
, getI32Imm(~0U)), 0);
675 return CurDAG
->SelectNodeTo(N
, PPC::SUBFE
, MVT::i32
, AD
, Op
,
679 SDOperand Ops
[] = { Op
, getI32Imm(1), getI32Imm(31), getI32Imm(31) };
680 return CurDAG
->SelectNodeTo(N
, PPC::RLWINM
, MVT::i32
, Ops
, 4);
684 SDOperand(CurDAG
->getTargetNode(PPC::NEG
, MVT::i32
, Op
), 0);
685 T
= SDOperand(CurDAG
->getTargetNode(PPC::ANDC
, MVT::i32
, T
, Op
), 0);
686 SDOperand Ops
[] = { T
, getI32Imm(1), getI32Imm(31), getI32Imm(31) };
687 return CurDAG
->SelectNodeTo(N
, PPC::RLWINM
, MVT::i32
, Ops
, 4);
690 } else if (Imm
== ~0U) { // setcc op, -1
691 SDOperand Op
= N
->getOperand(0);
696 Op
= SDOperand(CurDAG
->getTargetNode(PPC::ADDIC
, MVT::i32
, MVT::Flag
,
697 Op
, getI32Imm(1)), 0);
698 return CurDAG
->SelectNodeTo(N
, PPC::ADDZE
, MVT::i32
,
699 SDOperand(CurDAG
->getTargetNode(PPC::LI
, MVT::i32
,
703 Op
= SDOperand(CurDAG
->getTargetNode(PPC::NOR
, MVT::i32
, Op
, Op
), 0);
704 SDNode
*AD
= CurDAG
->getTargetNode(PPC::ADDIC
, MVT::i32
, MVT::Flag
,
706 return CurDAG
->SelectNodeTo(N
, PPC::SUBFE
, MVT::i32
, SDOperand(AD
, 0),
707 Op
, SDOperand(AD
, 1));
710 SDOperand AD
= SDOperand(CurDAG
->getTargetNode(PPC::ADDI
, MVT::i32
, Op
,
712 SDOperand AN
= SDOperand(CurDAG
->getTargetNode(PPC::AND
, MVT::i32
, AD
,
714 SDOperand Ops
[] = { AN
, getI32Imm(1), getI32Imm(31), getI32Imm(31) };
715 return CurDAG
->SelectNodeTo(N
, PPC::RLWINM
, MVT::i32
, Ops
, 4);
718 SDOperand Ops
[] = { Op
, getI32Imm(1), getI32Imm(31), getI32Imm(31) };
719 Op
= SDOperand(CurDAG
->getTargetNode(PPC::RLWINM
, MVT::i32
, Ops
, 4), 0);
720 return CurDAG
->SelectNodeTo(N
, PPC::XORI
, MVT::i32
, Op
,
728 unsigned Idx
= getCRIdxForSetCC(CC
, Inv
);
729 SDOperand CCReg
= SelectCC(N
->getOperand(0), N
->getOperand(1), CC
);
732 // Force the ccreg into CR7.
733 SDOperand CR7Reg
= CurDAG
->getRegister(PPC::CR7
, MVT::i32
);
735 SDOperand
InFlag(0, 0); // Null incoming flag value.
736 CCReg
= CurDAG
->getCopyToReg(CurDAG
->getEntryNode(), CR7Reg
, CCReg
,
739 if (TLI
.getTargetMachine().getSubtarget
<PPCSubtarget
>().isGigaProcessor())
740 IntCR
= SDOperand(CurDAG
->getTargetNode(PPC::MFOCRF
, MVT::i32
, CR7Reg
,
743 IntCR
= SDOperand(CurDAG
->getTargetNode(PPC::MFCR
, MVT::i32
, CCReg
), 0);
745 SDOperand Ops
[] = { IntCR
, getI32Imm((32-(3-Idx
)) & 31),
746 getI32Imm(31), getI32Imm(31) };
748 return CurDAG
->SelectNodeTo(N
, PPC::RLWINM
, MVT::i32
, Ops
, 4);
751 SDOperand(CurDAG
->getTargetNode(PPC::RLWINM
, MVT::i32
, Ops
, 4), 0);
752 return CurDAG
->SelectNodeTo(N
, PPC::XORI
, MVT::i32
, Tmp
, getI32Imm(1));
757 // Select - Convert the specified operand from a target-independent to a
758 // target-specific node if it hasn't already been changed.
759 SDNode
*PPCDAGToDAGISel::Select(SDOperand Op
) {
761 if (N
->getOpcode() >= ISD::BUILTIN_OP_END
&&
762 N
->getOpcode() < PPCISD::FIRST_NUMBER
)
763 return NULL
; // Already selected.
765 switch (N
->getOpcode()) {
768 case ISD::Constant
: {
769 if (N
->getValueType(0) == MVT::i64
) {
771 int64_t Imm
= cast
<ConstantSDNode
>(N
)->getValue();
772 // Assume no remaining bits.
773 unsigned Remainder
= 0;
774 // Assume no shift required.
777 // If it can't be represented as a 32 bit value.
779 Shift
= CountTrailingZeros_64(Imm
);
780 int64_t ImmSh
= static_cast<uint64_t>(Imm
) >> Shift
;
782 // If the shifted value fits 32 bits.
783 if (isInt32(ImmSh
)) {
784 // Go with the shifted value.
787 // Still stuck with a 64 bit value.
794 // Intermediate operand.
797 // Handle first 32 bits.
798 unsigned Lo
= Imm
& 0xFFFF;
799 unsigned Hi
= (Imm
>> 16) & 0xFFFF;
804 Result
= CurDAG
->getTargetNode(PPC::LI8
, MVT::i64
, getI32Imm(Lo
));
806 // Handle the Hi bits.
807 unsigned OpC
= Hi
? PPC::LIS8
: PPC::LI8
;
808 Result
= CurDAG
->getTargetNode(OpC
, MVT::i64
, getI32Imm(Hi
));
810 Result
= CurDAG
->getTargetNode(PPC::ORI8
, MVT::i64
,
811 SDOperand(Result
, 0), getI32Imm(Lo
));
814 Result
= CurDAG
->getTargetNode(PPC::LIS8
, MVT::i64
, getI32Imm(Hi
));
817 // If no shift, we're done.
818 if (!Shift
) return Result
;
820 // Shift for next step if the upper 32-bits were not zero.
822 Result
= CurDAG
->getTargetNode(PPC::RLDICR
, MVT::i64
,
823 SDOperand(Result
, 0),
824 getI32Imm(Shift
), getI32Imm(63 - Shift
));
827 // Add in the last bits as required.
828 if ((Hi
= (Remainder
>> 16) & 0xFFFF)) {
829 Result
= CurDAG
->getTargetNode(PPC::ORIS8
, MVT::i64
,
830 SDOperand(Result
, 0), getI32Imm(Hi
));
832 if ((Lo
= Remainder
& 0xFFFF)) {
833 Result
= CurDAG
->getTargetNode(PPC::ORI8
, MVT::i64
,
834 SDOperand(Result
, 0), getI32Imm(Lo
));
843 return SelectSETCC(Op
);
844 case PPCISD::GlobalBaseReg
:
845 return getGlobalBaseReg();
847 case ISD::FrameIndex
: {
848 int FI
= cast
<FrameIndexSDNode
>(N
)->getIndex();
849 SDOperand TFI
= CurDAG
->getTargetFrameIndex(FI
, Op
.getValueType());
850 unsigned Opc
= Op
.getValueType() == MVT::i32
? PPC::ADDI
: PPC::ADDI8
;
852 return CurDAG
->SelectNodeTo(N
, Opc
, Op
.getValueType(), TFI
,
854 return CurDAG
->getTargetNode(Opc
, Op
.getValueType(), TFI
,
859 SDOperand InFlag
= N
->getOperand(1);
860 AddToISelQueue(InFlag
);
861 // Use MFOCRF if supported.
862 if (TLI
.getTargetMachine().getSubtarget
<PPCSubtarget
>().isGigaProcessor())
863 return CurDAG
->getTargetNode(PPC::MFOCRF
, MVT::i32
,
864 N
->getOperand(0), InFlag
);
866 return CurDAG
->getTargetNode(PPC::MFCR
, MVT::i32
, InFlag
);
870 // FIXME: since this depends on the setting of the carry flag from the srawi
871 // we should really be making notes about that for the scheduler.
872 // FIXME: It sure would be nice if we could cheaply recognize the
873 // srl/add/sra pattern the dag combiner will generate for this as
874 // sra/addze rather than having to handle sdiv ourselves. oh well.
876 if (isInt32Immediate(N
->getOperand(1), Imm
)) {
877 SDOperand N0
= N
->getOperand(0);
879 if ((signed)Imm
> 0 && isPowerOf2_32(Imm
)) {
881 CurDAG
->getTargetNode(PPC::SRAWI
, MVT::i32
, MVT::Flag
,
882 N0
, getI32Imm(Log2_32(Imm
)));
883 return CurDAG
->SelectNodeTo(N
, PPC::ADDZE
, MVT::i32
,
884 SDOperand(Op
, 0), SDOperand(Op
, 1));
885 } else if ((signed)Imm
< 0 && isPowerOf2_32(-Imm
)) {
887 CurDAG
->getTargetNode(PPC::SRAWI
, MVT::i32
, MVT::Flag
,
888 N0
, getI32Imm(Log2_32(-Imm
)));
890 SDOperand(CurDAG
->getTargetNode(PPC::ADDZE
, MVT::i32
,
891 SDOperand(Op
, 0), SDOperand(Op
, 1)),
893 return CurDAG
->SelectNodeTo(N
, PPC::NEG
, MVT::i32
, PT
);
897 // Other cases are autogenerated.
902 // Handle preincrement loads.
903 LoadSDNode
*LD
= cast
<LoadSDNode
>(Op
);
904 MVT::ValueType LoadedVT
= LD
->getLoadedVT();
906 // Normal loads are handled by code generated from the .td file.
907 if (LD
->getAddressingMode() != ISD::PRE_INC
)
910 SDOperand Offset
= LD
->getOffset();
911 if (isa
<ConstantSDNode
>(Offset
) ||
912 Offset
.getOpcode() == ISD::TargetGlobalAddress
) {
915 bool isSExt
= LD
->getExtensionType() == ISD::SEXTLOAD
;
916 if (LD
->getValueType(0) != MVT::i64
) {
917 // Handle PPC32 integer and normal FP loads.
918 assert(!isSExt
|| LoadedVT
== MVT::i16
&& "Invalid sext update load");
920 default: assert(0 && "Invalid PPC load type!");
921 case MVT::f64
: Opcode
= PPC::LFDU
; break;
922 case MVT::f32
: Opcode
= PPC::LFSU
; break;
923 case MVT::i32
: Opcode
= PPC::LWZU
; break;
924 case MVT::i16
: Opcode
= isSExt
? PPC::LHAU
: PPC::LHZU
; break;
926 case MVT::i8
: Opcode
= PPC::LBZU
; break;
929 assert(LD
->getValueType(0) == MVT::i64
&& "Unknown load result type!");
930 assert(!isSExt
|| LoadedVT
== MVT::i16
&& "Invalid sext update load");
932 default: assert(0 && "Invalid PPC load type!");
933 case MVT::i64
: Opcode
= PPC::LDU
; break;
934 case MVT::i32
: Opcode
= PPC::LWZU8
; break;
935 case MVT::i16
: Opcode
= isSExt
? PPC::LHAU8
: PPC::LHZU8
; break;
937 case MVT::i8
: Opcode
= PPC::LBZU8
; break;
941 SDOperand Chain
= LD
->getChain();
942 SDOperand Base
= LD
->getBasePtr();
943 AddToISelQueue(Chain
);
944 AddToISelQueue(Base
);
945 AddToISelQueue(Offset
);
946 SDOperand Ops
[] = { Offset
, Base
, Chain
};
948 return CurDAG
->getTargetNode(Opcode
, MVT::i32
, MVT::i32
,
951 assert(0 && "R+R preindex loads not supported yet!");
956 unsigned Imm
, Imm2
, SH
, MB
, ME
;
958 // If this is an and of a value rotated between 0 and 31 bits and then and'd
959 // with a mask, emit rlwinm
960 if (isInt32Immediate(N
->getOperand(1), Imm
) &&
961 isRotateAndMask(N
->getOperand(0).Val
, Imm
, false, SH
, MB
, ME
)) {
962 SDOperand Val
= N
->getOperand(0).getOperand(0);
964 SDOperand Ops
[] = { Val
, getI32Imm(SH
), getI32Imm(MB
), getI32Imm(ME
) };
965 return CurDAG
->SelectNodeTo(N
, PPC::RLWINM
, MVT::i32
, Ops
, 4);
967 // If this is just a masked value where the input is not handled above, and
968 // is not a rotate-left (handled by a pattern in the .td file), emit rlwinm
969 if (isInt32Immediate(N
->getOperand(1), Imm
) &&
970 isRunOfOnes(Imm
, MB
, ME
) &&
971 N
->getOperand(0).getOpcode() != ISD::ROTL
) {
972 SDOperand Val
= N
->getOperand(0);
974 SDOperand Ops
[] = { Val
, getI32Imm(0), getI32Imm(MB
), getI32Imm(ME
) };
975 return CurDAG
->SelectNodeTo(N
, PPC::RLWINM
, MVT::i32
, Ops
, 4);
977 // AND X, 0 -> 0, not "rlwinm 32".
978 if (isInt32Immediate(N
->getOperand(1), Imm
) && (Imm
== 0)) {
979 AddToISelQueue(N
->getOperand(1));
980 ReplaceUses(SDOperand(N
, 0), N
->getOperand(1));
983 // ISD::OR doesn't get all the bitfield insertion fun.
984 // (and (or x, c1), c2) where isRunOfOnes(~(c1^c2)) is a bitfield insert
985 if (isInt32Immediate(N
->getOperand(1), Imm
) &&
986 N
->getOperand(0).getOpcode() == ISD::OR
&&
987 isInt32Immediate(N
->getOperand(0).getOperand(1), Imm2
)) {
990 if (isRunOfOnes(Imm
, MB
, ME
)) {
991 AddToISelQueue(N
->getOperand(0).getOperand(0));
992 AddToISelQueue(N
->getOperand(0).getOperand(1));
993 SDOperand Ops
[] = { N
->getOperand(0).getOperand(0),
994 N
->getOperand(0).getOperand(1),
995 getI32Imm(0), getI32Imm(MB
),getI32Imm(ME
) };
996 return CurDAG
->getTargetNode(PPC::RLWIMI
, MVT::i32
, Ops
, 5);
1000 // Other cases are autogenerated.
1004 if (N
->getValueType(0) == MVT::i32
)
1005 if (SDNode
*I
= SelectBitfieldInsert(N
))
1008 // Other cases are autogenerated.
1011 unsigned Imm
, SH
, MB
, ME
;
1012 if (isOpcWithIntImmediate(N
->getOperand(0).Val
, ISD::AND
, Imm
) &&
1013 isRotateAndMask(N
, Imm
, true, SH
, MB
, ME
)) {
1014 AddToISelQueue(N
->getOperand(0).getOperand(0));
1015 SDOperand Ops
[] = { N
->getOperand(0).getOperand(0),
1016 getI32Imm(SH
), getI32Imm(MB
), getI32Imm(ME
) };
1017 return CurDAG
->SelectNodeTo(N
, PPC::RLWINM
, MVT::i32
, Ops
, 4);
1020 // Other cases are autogenerated.
1024 unsigned Imm
, SH
, MB
, ME
;
1025 if (isOpcWithIntImmediate(N
->getOperand(0).Val
, ISD::AND
, Imm
) &&
1026 isRotateAndMask(N
, Imm
, true, SH
, MB
, ME
)) {
1027 AddToISelQueue(N
->getOperand(0).getOperand(0));
1028 SDOperand Ops
[] = { N
->getOperand(0).getOperand(0),
1029 getI32Imm(SH
), getI32Imm(MB
), getI32Imm(ME
) };
1030 return CurDAG
->SelectNodeTo(N
, PPC::RLWINM
, MVT::i32
, Ops
, 4);
1033 // Other cases are autogenerated.
1036 case ISD::SELECT_CC
: {
1037 ISD::CondCode CC
= cast
<CondCodeSDNode
>(N
->getOperand(4))->get();
1039 // Handle the setcc cases here. select_cc lhs, 0, 1, 0, cc
1040 if (ConstantSDNode
*N1C
= dyn_cast
<ConstantSDNode
>(N
->getOperand(1)))
1041 if (ConstantSDNode
*N2C
= dyn_cast
<ConstantSDNode
>(N
->getOperand(2)))
1042 if (ConstantSDNode
*N3C
= dyn_cast
<ConstantSDNode
>(N
->getOperand(3)))
1043 if (N1C
->isNullValue() && N3C
->isNullValue() &&
1044 N2C
->getValue() == 1ULL && CC
== ISD::SETNE
&&
1045 // FIXME: Implement this optzn for PPC64.
1046 N
->getValueType(0) == MVT::i32
) {
1047 AddToISelQueue(N
->getOperand(0));
1049 CurDAG
->getTargetNode(PPC::ADDIC
, MVT::i32
, MVT::Flag
,
1050 N
->getOperand(0), getI32Imm(~0U));
1051 return CurDAG
->SelectNodeTo(N
, PPC::SUBFE
, MVT::i32
,
1052 SDOperand(Tmp
, 0), N
->getOperand(0),
1056 SDOperand CCReg
= SelectCC(N
->getOperand(0), N
->getOperand(1), CC
);
1057 unsigned BROpc
= getPredicateForSetCC(CC
);
1059 unsigned SelectCCOp
;
1060 if (N
->getValueType(0) == MVT::i32
)
1061 SelectCCOp
= PPC::SELECT_CC_I4
;
1062 else if (N
->getValueType(0) == MVT::i64
)
1063 SelectCCOp
= PPC::SELECT_CC_I8
;
1064 else if (N
->getValueType(0) == MVT::f32
)
1065 SelectCCOp
= PPC::SELECT_CC_F4
;
1066 else if (N
->getValueType(0) == MVT::f64
)
1067 SelectCCOp
= PPC::SELECT_CC_F8
;
1069 SelectCCOp
= PPC::SELECT_CC_VRRC
;
1071 AddToISelQueue(N
->getOperand(2));
1072 AddToISelQueue(N
->getOperand(3));
1073 SDOperand Ops
[] = { CCReg
, N
->getOperand(2), N
->getOperand(3),
1075 return CurDAG
->SelectNodeTo(N
, SelectCCOp
, N
->getValueType(0), Ops
, 4);
1077 case PPCISD::COND_BRANCH
: {
1078 AddToISelQueue(N
->getOperand(0)); // Op #0 is the Chain.
1079 // Op #1 is the PPC::PRED_* number.
1081 // Op #3 is the Dest MBB
1082 AddToISelQueue(N
->getOperand(4)); // Op #4 is the Flag.
1083 // Prevent PPC::PRED_* from being selected into LI.
1085 getI32Imm(cast
<ConstantSDNode
>(N
->getOperand(1))->getValue());
1086 SDOperand Ops
[] = { Pred
, N
->getOperand(2), N
->getOperand(3),
1087 N
->getOperand(0), N
->getOperand(4) };
1088 return CurDAG
->SelectNodeTo(N
, PPC::BCC
, MVT::Other
, Ops
, 5);
1091 AddToISelQueue(N
->getOperand(0));
1092 ISD::CondCode CC
= cast
<CondCodeSDNode
>(N
->getOperand(1))->get();
1093 SDOperand CondCode
= SelectCC(N
->getOperand(2), N
->getOperand(3), CC
);
1094 SDOperand Ops
[] = { getI32Imm(getPredicateForSetCC(CC
)), CondCode
,
1095 N
->getOperand(4), N
->getOperand(0) };
1096 return CurDAG
->SelectNodeTo(N
, PPC::BCC
, MVT::Other
, Ops
, 4);
1099 // FIXME: Should custom lower this.
1100 SDOperand Chain
= N
->getOperand(0);
1101 SDOperand Target
= N
->getOperand(1);
1102 AddToISelQueue(Chain
);
1103 AddToISelQueue(Target
);
1104 unsigned Opc
= Target
.getValueType() == MVT::i32
? PPC::MTCTR
: PPC::MTCTR8
;
1105 Chain
= SDOperand(CurDAG
->getTargetNode(Opc
, MVT::Other
, Target
,
1107 return CurDAG
->SelectNodeTo(N
, PPC::BCTR
, MVT::Other
, Chain
);
1111 return SelectCode(Op
);
1116 /// createPPCISelDag - This pass converts a legalized DAG into a
1117 /// PowerPC-specific DAG, ready for instruction scheduling.
1119 FunctionPass
*llvm::createPPCISelDag(PPCTargetMachine
&TM
) {
1120 return new PPCDAGToDAGISel(TM
);