1 //===-- MipsSEISelLowering.cpp - MipsSE DAG Lowering Interface --*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // Subclass of MipsTargetLowering specialized for mips32/64.
12 //===----------------------------------------------------------------------===//
13 #include "MipsSEISelLowering.h"
14 #include "MipsRegisterInfo.h"
15 #include "MipsTargetMachine.h"
16 #include "llvm/CodeGen/MachineInstrBuilder.h"
17 #include "llvm/CodeGen/MachineRegisterInfo.h"
18 #include "llvm/IR/Intrinsics.h"
19 #include "llvm/Support/CommandLine.h"
20 #include "llvm/Target/TargetInstrInfo.h"
25 EnableMipsTailCalls("enable-mips-tail-calls", cl::Hidden,
26 cl::desc("MIPS: Enable tail calls."), cl::init(false));
28 MipsSETargetLowering::MipsSETargetLowering(MipsTargetMachine &TM)
29 : MipsTargetLowering(TM) {
30 // Set up the register classes
32 clearRegisterClasses();
34 addRegisterClass(MVT::i32, &Mips::CPURegsRegClass);
37 addRegisterClass(MVT::i64, &Mips::CPU64RegsRegClass);
39 if (Subtarget->hasDSP()) {
40 MVT::SimpleValueType VecTys[2] = {MVT::v2i16, MVT::v4i8};
42 for (unsigned i = 0; i < array_lengthof(VecTys); ++i) {
43 addRegisterClass(VecTys[i], &Mips::DSPRegsRegClass);
45 // Expand all builtin opcodes.
46 for (unsigned Opc = 0; Opc < ISD::BUILTIN_OP_END; ++Opc)
47 setOperationAction(Opc, VecTys[i], Expand);
49 setOperationAction(ISD::ADD, VecTys[i], Legal);
50 setOperationAction(ISD::SUB, VecTys[i], Legal);
51 setOperationAction(ISD::LOAD, VecTys[i], Legal);
52 setOperationAction(ISD::STORE, VecTys[i], Legal);
53 setOperationAction(ISD::BITCAST, VecTys[i], Legal);
56 setTargetDAGCombine(ISD::SHL);
57 setTargetDAGCombine(ISD::SRA);
58 setTargetDAGCombine(ISD::SRL);
61 if (Subtarget->hasDSPR2())
62 setOperationAction(ISD::MUL, MVT::v2i16, Legal);
64 if (!TM.Options.UseSoftFloat) {
65 addRegisterClass(MVT::f32, &Mips::FGR32RegClass);
67 // When dealing with single precision only, use libcalls
68 if (!Subtarget->isSingleFloat()) {
70 addRegisterClass(MVT::f64, &Mips::FGR64RegClass);
72 addRegisterClass(MVT::f64, &Mips::AFGR64RegClass);
76 setOperationAction(ISD::SMUL_LOHI, MVT::i32, Custom);
77 setOperationAction(ISD::UMUL_LOHI, MVT::i32, Custom);
78 setOperationAction(ISD::MULHS, MVT::i32, Custom);
79 setOperationAction(ISD::MULHU, MVT::i32, Custom);
82 setOperationAction(ISD::MULHS, MVT::i64, Custom);
83 setOperationAction(ISD::MULHU, MVT::i64, Custom);
84 setOperationAction(ISD::MUL, MVT::i64, Custom);
87 setOperationAction(ISD::INTRINSIC_WO_CHAIN, MVT::i64, Custom);
88 setOperationAction(ISD::INTRINSIC_W_CHAIN, MVT::i64, Custom);
90 setOperationAction(ISD::SDIVREM, MVT::i32, Custom);
91 setOperationAction(ISD::UDIVREM, MVT::i32, Custom);
92 setOperationAction(ISD::SDIVREM, MVT::i64, Custom);
93 setOperationAction(ISD::UDIVREM, MVT::i64, Custom);
94 setOperationAction(ISD::ATOMIC_FENCE, MVT::Other, Custom);
95 setOperationAction(ISD::LOAD, MVT::i32, Custom);
96 setOperationAction(ISD::STORE, MVT::i32, Custom);
98 setTargetDAGCombine(ISD::ADDE);
99 setTargetDAGCombine(ISD::SUBE);
101 computeRegisterProperties();
104 const MipsTargetLowering *
105 llvm::createMipsSETargetLowering(MipsTargetMachine &TM) {
106 return new MipsSETargetLowering(TM);
111 MipsSETargetLowering::allowsUnalignedMemoryAccesses(EVT VT, bool *Fast) const {
112 MVT::SimpleValueType SVT = VT.getSimpleVT().SimpleTy;
125 SDValue MipsSETargetLowering::LowerOperation(SDValue Op,
126 SelectionDAG &DAG) const {
127 switch(Op.getOpcode()) {
128 case ISD::SMUL_LOHI: return lowerMulDiv(Op, MipsISD::Mult, true, true, DAG);
129 case ISD::UMUL_LOHI: return lowerMulDiv(Op, MipsISD::Multu, true, true, DAG);
130 case ISD::MULHS: return lowerMulDiv(Op, MipsISD::Mult, false, true, DAG);
131 case ISD::MULHU: return lowerMulDiv(Op, MipsISD::Multu, false, true, DAG);
132 case ISD::MUL: return lowerMulDiv(Op, MipsISD::Mult, true, false, DAG);
133 case ISD::SDIVREM: return lowerMulDiv(Op, MipsISD::DivRem, true, true, DAG);
134 case ISD::UDIVREM: return lowerMulDiv(Op, MipsISD::DivRemU, true, true,
136 case ISD::INTRINSIC_WO_CHAIN: return lowerINTRINSIC_WO_CHAIN(Op, DAG);
137 case ISD::INTRINSIC_W_CHAIN: return lowerINTRINSIC_W_CHAIN(Op, DAG);
140 return MipsTargetLowering::LowerOperation(Op, DAG);
144 // Transforms a subgraph in CurDAG if the following pattern is found:
145 // (addc multLo, Lo0), (adde multHi, Hi0),
147 // multHi/Lo: product of multiplication
148 // Lo0: initial value of Lo register
149 // Hi0: initial value of Hi register
150 // Return true if pattern matching was successful.
151 static bool selectMADD(SDNode *ADDENode, SelectionDAG *CurDAG) {
152 // ADDENode's second operand must be a flag output of an ADDC node in order
153 // for the matching to be successful.
154 SDNode *ADDCNode = ADDENode->getOperand(2).getNode();
156 if (ADDCNode->getOpcode() != ISD::ADDC)
159 SDValue MultHi = ADDENode->getOperand(0);
160 SDValue MultLo = ADDCNode->getOperand(0);
161 SDNode *MultNode = MultHi.getNode();
162 unsigned MultOpc = MultHi.getOpcode();
164 // MultHi and MultLo must be generated by the same node,
165 if (MultLo.getNode() != MultNode)
168 // and it must be a multiplication.
169 if (MultOpc != ISD::SMUL_LOHI && MultOpc != ISD::UMUL_LOHI)
172 // MultLo amd MultHi must be the first and second output of MultNode
174 if (MultHi.getResNo() != 1 || MultLo.getResNo() != 0)
177 // Transform this to a MADD only if ADDENode and ADDCNode are the only users
178 // of the values of MultNode, in which case MultNode will be removed in later
180 // If there exist users other than ADDENode or ADDCNode, this function returns
181 // here, which will result in MultNode being mapped to a single MULT
182 // instruction node rather than a pair of MULT and MADD instructions being
184 if (!MultHi.hasOneUse() || !MultLo.hasOneUse())
187 DebugLoc DL = ADDENode->getDebugLoc();
189 // Initialize accumulator.
190 SDValue ACCIn = CurDAG->getNode(MipsISD::InsertLOHI, DL, MVT::Untyped,
191 ADDCNode->getOperand(1),
192 ADDENode->getOperand(1));
194 // create MipsMAdd(u) node
195 MultOpc = MultOpc == ISD::UMUL_LOHI ? MipsISD::MAddu : MipsISD::MAdd;
197 SDValue MAdd = CurDAG->getNode(MultOpc, DL, MVT::Untyped,
198 MultNode->getOperand(0),// Factor 0
199 MultNode->getOperand(1),// Factor 1
202 // replace uses of adde and addc here
203 if (!SDValue(ADDCNode, 0).use_empty()) {
204 SDValue LoIdx = CurDAG->getConstant(Mips::sub_lo, MVT::i32);
205 SDValue LoOut = CurDAG->getNode(MipsISD::ExtractLOHI, DL, MVT::i32, MAdd,
207 CurDAG->ReplaceAllUsesOfValueWith(SDValue(ADDCNode, 0), LoOut);
209 if (!SDValue(ADDENode, 0).use_empty()) {
210 SDValue HiIdx = CurDAG->getConstant(Mips::sub_hi, MVT::i32);
211 SDValue HiOut = CurDAG->getNode(MipsISD::ExtractLOHI, DL, MVT::i32, MAdd,
213 CurDAG->ReplaceAllUsesOfValueWith(SDValue(ADDENode, 0), HiOut);
220 // Transforms a subgraph in CurDAG if the following pattern is found:
221 // (addc Lo0, multLo), (sube Hi0, multHi),
223 // multHi/Lo: product of multiplication
224 // Lo0: initial value of Lo register
225 // Hi0: initial value of Hi register
226 // Return true if pattern matching was successful.
227 static bool selectMSUB(SDNode *SUBENode, SelectionDAG *CurDAG) {
228 // SUBENode's second operand must be a flag output of an SUBC node in order
229 // for the matching to be successful.
230 SDNode *SUBCNode = SUBENode->getOperand(2).getNode();
232 if (SUBCNode->getOpcode() != ISD::SUBC)
235 SDValue MultHi = SUBENode->getOperand(1);
236 SDValue MultLo = SUBCNode->getOperand(1);
237 SDNode *MultNode = MultHi.getNode();
238 unsigned MultOpc = MultHi.getOpcode();
240 // MultHi and MultLo must be generated by the same node,
241 if (MultLo.getNode() != MultNode)
244 // and it must be a multiplication.
245 if (MultOpc != ISD::SMUL_LOHI && MultOpc != ISD::UMUL_LOHI)
248 // MultLo amd MultHi must be the first and second output of MultNode
250 if (MultHi.getResNo() != 1 || MultLo.getResNo() != 0)
253 // Transform this to a MSUB only if SUBENode and SUBCNode are the only users
254 // of the values of MultNode, in which case MultNode will be removed in later
256 // If there exist users other than SUBENode or SUBCNode, this function returns
257 // here, which will result in MultNode being mapped to a single MULT
258 // instruction node rather than a pair of MULT and MSUB instructions being
260 if (!MultHi.hasOneUse() || !MultLo.hasOneUse())
263 DebugLoc DL = SUBENode->getDebugLoc();
265 // Initialize accumulator.
266 SDValue ACCIn = CurDAG->getNode(MipsISD::InsertLOHI, DL, MVT::Untyped,
267 SUBCNode->getOperand(0),
268 SUBENode->getOperand(0));
270 // create MipsSub(u) node
271 MultOpc = MultOpc == ISD::UMUL_LOHI ? MipsISD::MSubu : MipsISD::MSub;
273 SDValue MSub = CurDAG->getNode(MultOpc, DL, MVT::Glue,
274 MultNode->getOperand(0),// Factor 0
275 MultNode->getOperand(1),// Factor 1
278 // replace uses of sube and subc here
279 if (!SDValue(SUBCNode, 0).use_empty()) {
280 SDValue LoIdx = CurDAG->getConstant(Mips::sub_lo, MVT::i32);
281 SDValue LoOut = CurDAG->getNode(MipsISD::ExtractLOHI, DL, MVT::i32, MSub,
283 CurDAG->ReplaceAllUsesOfValueWith(SDValue(SUBCNode, 0), LoOut);
285 if (!SDValue(SUBENode, 0).use_empty()) {
286 SDValue HiIdx = CurDAG->getConstant(Mips::sub_hi, MVT::i32);
287 SDValue HiOut = CurDAG->getNode(MipsISD::ExtractLOHI, DL, MVT::i32, MSub,
289 CurDAG->ReplaceAllUsesOfValueWith(SDValue(SUBENode, 0), HiOut);
295 static SDValue performADDECombine(SDNode *N, SelectionDAG &DAG,
296 TargetLowering::DAGCombinerInfo &DCI,
297 const MipsSubtarget *Subtarget) {
298 if (DCI.isBeforeLegalize())
301 if (Subtarget->hasMips32() && N->getValueType(0) == MVT::i32 &&
303 return SDValue(N, 0);
308 static SDValue performSUBECombine(SDNode *N, SelectionDAG &DAG,
309 TargetLowering::DAGCombinerInfo &DCI,
310 const MipsSubtarget *Subtarget) {
311 if (DCI.isBeforeLegalize())
314 if (Subtarget->hasMips32() && N->getValueType(0) == MVT::i32 &&
316 return SDValue(N, 0);
321 static SDValue performDSPShiftCombine(unsigned Opc, SDNode *N, EVT Ty,
323 const MipsSubtarget *Subtarget) {
324 // See if this is a vector splat immediate node.
325 APInt SplatValue, SplatUndef;
326 unsigned SplatBitSize;
328 unsigned EltSize = Ty.getVectorElementType().getSizeInBits();
329 BuildVectorSDNode *BV = dyn_cast<BuildVectorSDNode>(N->getOperand(1));
332 !BV->isConstantSplat(SplatValue, SplatUndef, SplatBitSize, HasAnyUndefs,
333 EltSize,!Subtarget->isLittle()) ||
334 (SplatBitSize != EltSize) ||
335 !isUIntN(Log2_32(EltSize), SplatValue.getZExtValue()))
338 return DAG.getNode(Opc, N->getDebugLoc(), Ty, N->getOperand(0),
339 DAG.getConstant(SplatValue.getZExtValue(), MVT::i32));
342 static SDValue performSHLCombine(SDNode *N, SelectionDAG &DAG,
343 TargetLowering::DAGCombinerInfo &DCI,
344 const MipsSubtarget *Subtarget) {
345 EVT Ty = N->getValueType(0);
347 if ((Ty != MVT::v2i16) && (Ty != MVT::v4i8))
350 return performDSPShiftCombine(MipsISD::SHLL_DSP, N, Ty, DAG, Subtarget);
353 static SDValue performSRACombine(SDNode *N, SelectionDAG &DAG,
354 TargetLowering::DAGCombinerInfo &DCI,
355 const MipsSubtarget *Subtarget) {
356 EVT Ty = N->getValueType(0);
358 if ((Ty != MVT::v2i16) && ((Ty != MVT::v4i8) || !Subtarget->hasDSPR2()))
361 return performDSPShiftCombine(MipsISD::SHRA_DSP, N, Ty, DAG, Subtarget);
365 static SDValue performSRLCombine(SDNode *N, SelectionDAG &DAG,
366 TargetLowering::DAGCombinerInfo &DCI,
367 const MipsSubtarget *Subtarget) {
368 EVT Ty = N->getValueType(0);
370 if (((Ty != MVT::v2i16) || !Subtarget->hasDSPR2()) && (Ty != MVT::v4i8))
373 return performDSPShiftCombine(MipsISD::SHRL_DSP, N, Ty, DAG, Subtarget);
377 MipsSETargetLowering::PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const {
378 SelectionDAG &DAG = DCI.DAG;
380 switch (N->getOpcode()) {
382 return performADDECombine(N, DAG, DCI, Subtarget);
384 return performSUBECombine(N, DAG, DCI, Subtarget);
386 return performSHLCombine(N, DAG, DCI, Subtarget);
388 return performSRACombine(N, DAG, DCI, Subtarget);
390 return performSRLCombine(N, DAG, DCI, Subtarget);
392 return MipsTargetLowering::PerformDAGCombine(N, DCI);
397 MipsSETargetLowering::EmitInstrWithCustomInserter(MachineInstr *MI,
398 MachineBasicBlock *BB) const {
399 switch (MI->getOpcode()) {
401 return MipsTargetLowering::EmitInstrWithCustomInserter(MI, BB);
402 case Mips::BPOSGE32_PSEUDO:
403 return emitBPOSGE32(MI, BB);
407 bool MipsSETargetLowering::
408 isEligibleForTailCallOptimization(const MipsCC &MipsCCInfo,
409 unsigned NextStackOffset,
410 const MipsFunctionInfo& FI) const {
411 if (!EnableMipsTailCalls)
414 // Return false if either the callee or caller has a byval argument.
415 if (MipsCCInfo.hasByValArg() || FI.hasByvalArg())
418 // Return true if the callee's argument area is no larger than the
420 return NextStackOffset <= FI.getIncomingArgSize();
423 void MipsSETargetLowering::
424 getOpndList(SmallVectorImpl<SDValue> &Ops,
425 std::deque< std::pair<unsigned, SDValue> > &RegsToPass,
426 bool IsPICCall, bool GlobalOrExternal, bool InternalLinkage,
427 CallLoweringInfo &CLI, SDValue Callee, SDValue Chain) const {
428 // T9 should contain the address of the callee function if
429 // -reloction-model=pic or it is an indirect call.
430 if (IsPICCall || !GlobalOrExternal) {
431 unsigned T9Reg = IsN64 ? Mips::T9_64 : Mips::T9;
432 RegsToPass.push_front(std::make_pair(T9Reg, Callee));
434 Ops.push_back(Callee);
436 MipsTargetLowering::getOpndList(Ops, RegsToPass, IsPICCall, GlobalOrExternal,
437 InternalLinkage, CLI, Callee, Chain);
440 SDValue MipsSETargetLowering::lowerMulDiv(SDValue Op, unsigned NewOpc,
441 bool HasLo, bool HasHi,
442 SelectionDAG &DAG) const {
443 EVT Ty = Op.getOperand(0).getValueType();
444 DebugLoc DL = Op.getDebugLoc();
445 SDValue Mult = DAG.getNode(NewOpc, DL, MVT::Untyped,
446 Op.getOperand(0), Op.getOperand(1));
450 Lo = DAG.getNode(MipsISD::ExtractLOHI, DL, Ty, Mult,
451 DAG.getConstant(Mips::sub_lo, MVT::i32));
453 Hi = DAG.getNode(MipsISD::ExtractLOHI, DL, Ty, Mult,
454 DAG.getConstant(Mips::sub_hi, MVT::i32));
456 if (!HasLo || !HasHi)
457 return HasLo ? Lo : Hi;
459 SDValue Vals[] = { Lo, Hi };
460 return DAG.getMergeValues(Vals, 2, DL);
464 static SDValue initAccumulator(SDValue In, DebugLoc DL, SelectionDAG &DAG) {
465 SDValue InLo = DAG.getNode(ISD::EXTRACT_ELEMENT, DL, MVT::i32, In,
466 DAG.getConstant(0, MVT::i32));
467 SDValue InHi = DAG.getNode(ISD::EXTRACT_ELEMENT, DL, MVT::i32, In,
468 DAG.getConstant(1, MVT::i32));
469 return DAG.getNode(MipsISD::InsertLOHI, DL, MVT::Untyped, InLo, InHi);
472 static SDValue extractLOHI(SDValue Op, DebugLoc DL, SelectionDAG &DAG) {
473 SDValue Lo = DAG.getNode(MipsISD::ExtractLOHI, DL, MVT::i32, Op,
474 DAG.getConstant(Mips::sub_lo, MVT::i32));
475 SDValue Hi = DAG.getNode(MipsISD::ExtractLOHI, DL, MVT::i32, Op,
476 DAG.getConstant(Mips::sub_hi, MVT::i32));
477 return DAG.getNode(ISD::BUILD_PAIR, DL, MVT::i64, Lo, Hi);
480 // This function expands mips intrinsic nodes which have 64-bit input operands
483 // out64 = intrinsic-node in64
485 // lo = copy (extract-element (in64, 0))
486 // hi = copy (extract-element (in64, 1))
487 // mips-specific-node
490 // out64 = merge-values (v0, v1)
492 static SDValue lowerDSPIntr(SDValue Op, SelectionDAG &DAG, unsigned Opc) {
493 DebugLoc DL = Op.getDebugLoc();
494 bool HasChainIn = Op->getOperand(0).getValueType() == MVT::Other;
495 SmallVector<SDValue, 3> Ops;
498 // See if Op has a chain input.
500 Ops.push_back(Op->getOperand(OpNo++));
502 // The next operand is the intrinsic opcode.
503 assert(Op->getOperand(OpNo).getOpcode() == ISD::TargetConstant);
505 // See if the next operand has type i64.
506 SDValue Opnd = Op->getOperand(++OpNo), In64;
508 if (Opnd.getValueType() == MVT::i64)
509 In64 = initAccumulator(Opnd, DL, DAG);
513 // Push the remaining operands.
514 for (++OpNo ; OpNo < Op->getNumOperands(); ++OpNo)
515 Ops.push_back(Op->getOperand(OpNo));
517 // Add In64 to the end of the list.
522 SmallVector<EVT, 2> ResTys;
524 for (SDNode::value_iterator I = Op->value_begin(), E = Op->value_end();
526 ResTys.push_back((*I == MVT::i64) ? MVT::Untyped : *I);
529 SDValue Val = DAG.getNode(Opc, DL, ResTys, &Ops[0], Ops.size());
530 SDValue Out = (ResTys[0] == MVT::Untyped) ? extractLOHI(Val, DL, DAG) : Val;
535 assert(Val->getValueType(1) == MVT::Other);
536 SDValue Vals[] = { Out, SDValue(Val.getNode(), 1) };
537 return DAG.getMergeValues(Vals, 2, DL);
540 SDValue MipsSETargetLowering::lowerINTRINSIC_WO_CHAIN(SDValue Op,
541 SelectionDAG &DAG) const {
542 switch (cast<ConstantSDNode>(Op->getOperand(0))->getZExtValue()) {
545 case Intrinsic::mips_shilo:
546 return lowerDSPIntr(Op, DAG, MipsISD::SHILO);
547 case Intrinsic::mips_dpau_h_qbl:
548 return lowerDSPIntr(Op, DAG, MipsISD::DPAU_H_QBL);
549 case Intrinsic::mips_dpau_h_qbr:
550 return lowerDSPIntr(Op, DAG, MipsISD::DPAU_H_QBR);
551 case Intrinsic::mips_dpsu_h_qbl:
552 return lowerDSPIntr(Op, DAG, MipsISD::DPSU_H_QBL);
553 case Intrinsic::mips_dpsu_h_qbr:
554 return lowerDSPIntr(Op, DAG, MipsISD::DPSU_H_QBR);
555 case Intrinsic::mips_dpa_w_ph:
556 return lowerDSPIntr(Op, DAG, MipsISD::DPA_W_PH);
557 case Intrinsic::mips_dps_w_ph:
558 return lowerDSPIntr(Op, DAG, MipsISD::DPS_W_PH);
559 case Intrinsic::mips_dpax_w_ph:
560 return lowerDSPIntr(Op, DAG, MipsISD::DPAX_W_PH);
561 case Intrinsic::mips_dpsx_w_ph:
562 return lowerDSPIntr(Op, DAG, MipsISD::DPSX_W_PH);
563 case Intrinsic::mips_mulsa_w_ph:
564 return lowerDSPIntr(Op, DAG, MipsISD::MULSA_W_PH);
565 case Intrinsic::mips_mult:
566 return lowerDSPIntr(Op, DAG, MipsISD::Mult);
567 case Intrinsic::mips_multu:
568 return lowerDSPIntr(Op, DAG, MipsISD::Multu);
569 case Intrinsic::mips_madd:
570 return lowerDSPIntr(Op, DAG, MipsISD::MAdd);
571 case Intrinsic::mips_maddu:
572 return lowerDSPIntr(Op, DAG, MipsISD::MAddu);
573 case Intrinsic::mips_msub:
574 return lowerDSPIntr(Op, DAG, MipsISD::MSub);
575 case Intrinsic::mips_msubu:
576 return lowerDSPIntr(Op, DAG, MipsISD::MSubu);
580 SDValue MipsSETargetLowering::lowerINTRINSIC_W_CHAIN(SDValue Op,
581 SelectionDAG &DAG) const {
582 switch (cast<ConstantSDNode>(Op->getOperand(1))->getZExtValue()) {
585 case Intrinsic::mips_extp:
586 return lowerDSPIntr(Op, DAG, MipsISD::EXTP);
587 case Intrinsic::mips_extpdp:
588 return lowerDSPIntr(Op, DAG, MipsISD::EXTPDP);
589 case Intrinsic::mips_extr_w:
590 return lowerDSPIntr(Op, DAG, MipsISD::EXTR_W);
591 case Intrinsic::mips_extr_r_w:
592 return lowerDSPIntr(Op, DAG, MipsISD::EXTR_R_W);
593 case Intrinsic::mips_extr_rs_w:
594 return lowerDSPIntr(Op, DAG, MipsISD::EXTR_RS_W);
595 case Intrinsic::mips_extr_s_h:
596 return lowerDSPIntr(Op, DAG, MipsISD::EXTR_S_H);
597 case Intrinsic::mips_mthlip:
598 return lowerDSPIntr(Op, DAG, MipsISD::MTHLIP);
599 case Intrinsic::mips_mulsaq_s_w_ph:
600 return lowerDSPIntr(Op, DAG, MipsISD::MULSAQ_S_W_PH);
601 case Intrinsic::mips_maq_s_w_phl:
602 return lowerDSPIntr(Op, DAG, MipsISD::MAQ_S_W_PHL);
603 case Intrinsic::mips_maq_s_w_phr:
604 return lowerDSPIntr(Op, DAG, MipsISD::MAQ_S_W_PHR);
605 case Intrinsic::mips_maq_sa_w_phl:
606 return lowerDSPIntr(Op, DAG, MipsISD::MAQ_SA_W_PHL);
607 case Intrinsic::mips_maq_sa_w_phr:
608 return lowerDSPIntr(Op, DAG, MipsISD::MAQ_SA_W_PHR);
609 case Intrinsic::mips_dpaq_s_w_ph:
610 return lowerDSPIntr(Op, DAG, MipsISD::DPAQ_S_W_PH);
611 case Intrinsic::mips_dpsq_s_w_ph:
612 return lowerDSPIntr(Op, DAG, MipsISD::DPSQ_S_W_PH);
613 case Intrinsic::mips_dpaq_sa_l_w:
614 return lowerDSPIntr(Op, DAG, MipsISD::DPAQ_SA_L_W);
615 case Intrinsic::mips_dpsq_sa_l_w:
616 return lowerDSPIntr(Op, DAG, MipsISD::DPSQ_SA_L_W);
617 case Intrinsic::mips_dpaqx_s_w_ph:
618 return lowerDSPIntr(Op, DAG, MipsISD::DPAQX_S_W_PH);
619 case Intrinsic::mips_dpaqx_sa_w_ph:
620 return lowerDSPIntr(Op, DAG, MipsISD::DPAQX_SA_W_PH);
621 case Intrinsic::mips_dpsqx_s_w_ph:
622 return lowerDSPIntr(Op, DAG, MipsISD::DPSQX_S_W_PH);
623 case Intrinsic::mips_dpsqx_sa_w_ph:
624 return lowerDSPIntr(Op, DAG, MipsISD::DPSQX_SA_W_PH);
628 MachineBasicBlock * MipsSETargetLowering::
629 emitBPOSGE32(MachineInstr *MI, MachineBasicBlock *BB) const{
631 // bposge32_pseudo $vr0
641 // $vr0 = phi($vr2, $fbb, $vr1, $tbb)
643 MachineRegisterInfo &RegInfo = BB->getParent()->getRegInfo();
644 const TargetInstrInfo *TII = getTargetMachine().getInstrInfo();
645 const TargetRegisterClass *RC = &Mips::CPURegsRegClass;
646 DebugLoc DL = MI->getDebugLoc();
647 const BasicBlock *LLVM_BB = BB->getBasicBlock();
648 MachineFunction::iterator It = llvm::next(MachineFunction::iterator(BB));
649 MachineFunction *F = BB->getParent();
650 MachineBasicBlock *FBB = F->CreateMachineBasicBlock(LLVM_BB);
651 MachineBasicBlock *TBB = F->CreateMachineBasicBlock(LLVM_BB);
652 MachineBasicBlock *Sink = F->CreateMachineBasicBlock(LLVM_BB);
657 // Transfer the remainder of BB and its successor edges to Sink.
658 Sink->splice(Sink->begin(), BB, llvm::next(MachineBasicBlock::iterator(MI)),
660 Sink->transferSuccessorsAndUpdatePHIs(BB);
663 BB->addSuccessor(FBB);
664 BB->addSuccessor(TBB);
665 FBB->addSuccessor(Sink);
666 TBB->addSuccessor(Sink);
668 // Insert the real bposge32 instruction to $BB.
669 BuildMI(BB, DL, TII->get(Mips::BPOSGE32)).addMBB(TBB);
672 unsigned VR2 = RegInfo.createVirtualRegister(RC);
673 BuildMI(*FBB, FBB->end(), DL, TII->get(Mips::ADDiu), VR2)
674 .addReg(Mips::ZERO).addImm(0);
675 BuildMI(*FBB, FBB->end(), DL, TII->get(Mips::B)).addMBB(Sink);
678 unsigned VR1 = RegInfo.createVirtualRegister(RC);
679 BuildMI(*TBB, TBB->end(), DL, TII->get(Mips::ADDiu), VR1)
680 .addReg(Mips::ZERO).addImm(1);
682 // Insert phi function to $Sink.
683 BuildMI(*Sink, Sink->begin(), DL, TII->get(Mips::PHI),
684 MI->getOperand(0).getReg())
685 .addReg(VR2).addMBB(FBB).addReg(VR1).addMBB(TBB);
687 MI->eraseFromParent(); // The pseudo instruction is gone now.