xref: /minix3/external/bsd/llvm/dist/llvm/lib/Target/Mips/Mips16ISelDAGToDAG.cpp (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1f4a2713aSLionel Sambuc //===-- Mips16ISelDAGToDAG.cpp - A Dag to Dag Inst Selector for Mips16 ----===//
2f4a2713aSLionel Sambuc //
3f4a2713aSLionel Sambuc //                     The LLVM Compiler Infrastructure
4f4a2713aSLionel Sambuc //
5f4a2713aSLionel Sambuc // This file is distributed under the University of Illinois Open Source
6f4a2713aSLionel Sambuc // License. See LICENSE.TXT for details.
7f4a2713aSLionel Sambuc //
8f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
9f4a2713aSLionel Sambuc //
10f4a2713aSLionel Sambuc // Subclass of MipsDAGToDAGISel specialized for mips16.
11f4a2713aSLionel Sambuc //
12f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
13f4a2713aSLionel Sambuc 
14f4a2713aSLionel Sambuc #include "Mips16ISelDAGToDAG.h"
15f4a2713aSLionel Sambuc #include "MCTargetDesc/MipsBaseInfo.h"
16*0a6a1f1dSLionel Sambuc #include "Mips.h"
17f4a2713aSLionel Sambuc #include "MipsAnalyzeImmediate.h"
18f4a2713aSLionel Sambuc #include "MipsMachineFunction.h"
19f4a2713aSLionel Sambuc #include "MipsRegisterInfo.h"
20f4a2713aSLionel Sambuc #include "llvm/CodeGen/MachineConstantPool.h"
21f4a2713aSLionel Sambuc #include "llvm/CodeGen/MachineFrameInfo.h"
22f4a2713aSLionel Sambuc #include "llvm/CodeGen/MachineFunction.h"
23f4a2713aSLionel Sambuc #include "llvm/CodeGen/MachineInstrBuilder.h"
24f4a2713aSLionel Sambuc #include "llvm/CodeGen/MachineRegisterInfo.h"
25f4a2713aSLionel Sambuc #include "llvm/CodeGen/SelectionDAGNodes.h"
26*0a6a1f1dSLionel Sambuc #include "llvm/IR/CFG.h"
27f4a2713aSLionel Sambuc #include "llvm/IR/GlobalValue.h"
28f4a2713aSLionel Sambuc #include "llvm/IR/Instructions.h"
29f4a2713aSLionel Sambuc #include "llvm/IR/Intrinsics.h"
30f4a2713aSLionel Sambuc #include "llvm/IR/Type.h"
31f4a2713aSLionel Sambuc #include "llvm/Support/Debug.h"
32f4a2713aSLionel Sambuc #include "llvm/Support/ErrorHandling.h"
33f4a2713aSLionel Sambuc #include "llvm/Support/raw_ostream.h"
34f4a2713aSLionel Sambuc #include "llvm/Target/TargetMachine.h"
35f4a2713aSLionel Sambuc using namespace llvm;
36f4a2713aSLionel Sambuc 
37*0a6a1f1dSLionel Sambuc #define DEBUG_TYPE "mips-isel"
38*0a6a1f1dSLionel Sambuc 
runOnMachineFunction(MachineFunction & MF)39f4a2713aSLionel Sambuc bool Mips16DAGToDAGISel::runOnMachineFunction(MachineFunction &MF) {
40*0a6a1f1dSLionel Sambuc   Subtarget = &TM.getSubtarget<MipsSubtarget>();
41*0a6a1f1dSLionel Sambuc   if (!Subtarget->inMips16Mode())
42f4a2713aSLionel Sambuc     return false;
43f4a2713aSLionel Sambuc   return MipsDAGToDAGISel::runOnMachineFunction(MF);
44f4a2713aSLionel Sambuc }
45f4a2713aSLionel Sambuc /// Select multiply instructions.
46f4a2713aSLionel Sambuc std::pair<SDNode*, SDNode*>
selectMULT(SDNode * N,unsigned Opc,SDLoc DL,EVT Ty,bool HasLo,bool HasHi)47f4a2713aSLionel Sambuc Mips16DAGToDAGISel::selectMULT(SDNode *N, unsigned Opc, SDLoc DL, EVT Ty,
48f4a2713aSLionel Sambuc                                bool HasLo, bool HasHi) {
49*0a6a1f1dSLionel Sambuc   SDNode *Lo = nullptr, *Hi = nullptr;
50f4a2713aSLionel Sambuc   SDNode *Mul = CurDAG->getMachineNode(Opc, DL, MVT::Glue, N->getOperand(0),
51f4a2713aSLionel Sambuc                                        N->getOperand(1));
52f4a2713aSLionel Sambuc   SDValue InFlag = SDValue(Mul, 0);
53f4a2713aSLionel Sambuc 
54f4a2713aSLionel Sambuc   if (HasLo) {
55f4a2713aSLionel Sambuc     unsigned Opcode = Mips::Mflo16;
56f4a2713aSLionel Sambuc     Lo = CurDAG->getMachineNode(Opcode, DL, Ty, MVT::Glue, InFlag);
57f4a2713aSLionel Sambuc     InFlag = SDValue(Lo, 1);
58f4a2713aSLionel Sambuc   }
59f4a2713aSLionel Sambuc   if (HasHi) {
60f4a2713aSLionel Sambuc     unsigned Opcode = Mips::Mfhi16;
61f4a2713aSLionel Sambuc     Hi = CurDAG->getMachineNode(Opcode, DL, Ty, InFlag);
62f4a2713aSLionel Sambuc   }
63f4a2713aSLionel Sambuc   return std::make_pair(Lo, Hi);
64f4a2713aSLionel Sambuc }
65f4a2713aSLionel Sambuc 
initGlobalBaseReg(MachineFunction & MF)66f4a2713aSLionel Sambuc void Mips16DAGToDAGISel::initGlobalBaseReg(MachineFunction &MF) {
67f4a2713aSLionel Sambuc   MipsFunctionInfo *MipsFI = MF.getInfo<MipsFunctionInfo>();
68f4a2713aSLionel Sambuc 
69f4a2713aSLionel Sambuc   if (!MipsFI->globalBaseRegSet())
70f4a2713aSLionel Sambuc     return;
71f4a2713aSLionel Sambuc 
72f4a2713aSLionel Sambuc   MachineBasicBlock &MBB = MF.front();
73f4a2713aSLionel Sambuc   MachineBasicBlock::iterator I = MBB.begin();
74f4a2713aSLionel Sambuc   MachineRegisterInfo &RegInfo = MF.getRegInfo();
75*0a6a1f1dSLionel Sambuc   const TargetInstrInfo &TII = *MF.getSubtarget().getInstrInfo();
76f4a2713aSLionel Sambuc   DebugLoc DL = I != MBB.end() ? I->getDebugLoc() : DebugLoc();
77f4a2713aSLionel Sambuc   unsigned V0, V1, V2, GlobalBaseReg = MipsFI->getGlobalBaseReg();
78*0a6a1f1dSLionel Sambuc   const TargetRegisterClass *RC = &Mips::CPU16RegsRegClass;
79f4a2713aSLionel Sambuc 
80f4a2713aSLionel Sambuc   V0 = RegInfo.createVirtualRegister(RC);
81f4a2713aSLionel Sambuc   V1 = RegInfo.createVirtualRegister(RC);
82f4a2713aSLionel Sambuc   V2 = RegInfo.createVirtualRegister(RC);
83f4a2713aSLionel Sambuc 
84f4a2713aSLionel Sambuc   BuildMI(MBB, I, DL, TII.get(Mips::GotPrologue16), V0).
85f4a2713aSLionel Sambuc     addReg(V1, RegState::Define).
86f4a2713aSLionel Sambuc     addExternalSymbol("_gp_disp", MipsII::MO_ABS_HI).
87f4a2713aSLionel Sambuc     addExternalSymbol("_gp_disp", MipsII::MO_ABS_LO);
88f4a2713aSLionel Sambuc 
89f4a2713aSLionel Sambuc   BuildMI(MBB, I, DL, TII.get(Mips::SllX16), V2).addReg(V0).addImm(16);
90f4a2713aSLionel Sambuc   BuildMI(MBB, I, DL, TII.get(Mips::AdduRxRyRz16), GlobalBaseReg)
91f4a2713aSLionel Sambuc     .addReg(V1).addReg(V2);
92f4a2713aSLionel Sambuc }
93f4a2713aSLionel Sambuc 
94f4a2713aSLionel Sambuc // Insert instructions to initialize the Mips16 SP Alias register in the
95f4a2713aSLionel Sambuc // first MBB of the function.
96f4a2713aSLionel Sambuc //
initMips16SPAliasReg(MachineFunction & MF)97f4a2713aSLionel Sambuc void Mips16DAGToDAGISel::initMips16SPAliasReg(MachineFunction &MF) {
98f4a2713aSLionel Sambuc   MipsFunctionInfo *MipsFI = MF.getInfo<MipsFunctionInfo>();
99f4a2713aSLionel Sambuc 
100f4a2713aSLionel Sambuc   if (!MipsFI->mips16SPAliasRegSet())
101f4a2713aSLionel Sambuc     return;
102f4a2713aSLionel Sambuc 
103f4a2713aSLionel Sambuc   MachineBasicBlock &MBB = MF.front();
104f4a2713aSLionel Sambuc   MachineBasicBlock::iterator I = MBB.begin();
105*0a6a1f1dSLionel Sambuc   const TargetInstrInfo &TII = *MF.getSubtarget().getInstrInfo();
106f4a2713aSLionel Sambuc   DebugLoc DL = I != MBB.end() ? I->getDebugLoc() : DebugLoc();
107f4a2713aSLionel Sambuc   unsigned Mips16SPAliasReg = MipsFI->getMips16SPAliasReg();
108f4a2713aSLionel Sambuc 
109f4a2713aSLionel Sambuc   BuildMI(MBB, I, DL, TII.get(Mips::MoveR3216), Mips16SPAliasReg)
110f4a2713aSLionel Sambuc     .addReg(Mips::SP);
111f4a2713aSLionel Sambuc }
112f4a2713aSLionel Sambuc 
processFunctionAfterISel(MachineFunction & MF)113f4a2713aSLionel Sambuc void Mips16DAGToDAGISel::processFunctionAfterISel(MachineFunction &MF) {
114f4a2713aSLionel Sambuc   initGlobalBaseReg(MF);
115f4a2713aSLionel Sambuc   initMips16SPAliasReg(MF);
116f4a2713aSLionel Sambuc }
117f4a2713aSLionel Sambuc 
118f4a2713aSLionel Sambuc /// getMips16SPAliasReg - Output the instructions required to put the
119f4a2713aSLionel Sambuc /// SP into a Mips16 accessible aliased register.
getMips16SPAliasReg()120f4a2713aSLionel Sambuc SDValue Mips16DAGToDAGISel::getMips16SPAliasReg() {
121f4a2713aSLionel Sambuc   unsigned Mips16SPAliasReg =
122f4a2713aSLionel Sambuc     MF->getInfo<MipsFunctionInfo>()->getMips16SPAliasReg();
123f4a2713aSLionel Sambuc   return CurDAG->getRegister(Mips16SPAliasReg,
124f4a2713aSLionel Sambuc                              getTargetLowering()->getPointerTy());
125f4a2713aSLionel Sambuc }
126f4a2713aSLionel Sambuc 
getMips16SPRefReg(SDNode * Parent,SDValue & AliasReg)127f4a2713aSLionel Sambuc void Mips16DAGToDAGISel::getMips16SPRefReg(SDNode *Parent, SDValue &AliasReg) {
128f4a2713aSLionel Sambuc   SDValue AliasFPReg = CurDAG->getRegister(Mips::S0,
129f4a2713aSLionel Sambuc                                            getTargetLowering()->getPointerTy());
130f4a2713aSLionel Sambuc   if (Parent) {
131f4a2713aSLionel Sambuc     switch (Parent->getOpcode()) {
132f4a2713aSLionel Sambuc       case ISD::LOAD: {
133f4a2713aSLionel Sambuc         LoadSDNode *SD = dyn_cast<LoadSDNode>(Parent);
134f4a2713aSLionel Sambuc         switch (SD->getMemoryVT().getSizeInBits()) {
135f4a2713aSLionel Sambuc         case 8:
136f4a2713aSLionel Sambuc         case 16:
137*0a6a1f1dSLionel Sambuc           AliasReg = TM.getSubtargetImpl()->getFrameLowering()->hasFP(*MF)
138*0a6a1f1dSLionel Sambuc                          ? AliasFPReg
139*0a6a1f1dSLionel Sambuc                          : getMips16SPAliasReg();
140f4a2713aSLionel Sambuc           return;
141f4a2713aSLionel Sambuc         }
142f4a2713aSLionel Sambuc         break;
143f4a2713aSLionel Sambuc       }
144f4a2713aSLionel Sambuc       case ISD::STORE: {
145f4a2713aSLionel Sambuc         StoreSDNode *SD = dyn_cast<StoreSDNode>(Parent);
146f4a2713aSLionel Sambuc         switch (SD->getMemoryVT().getSizeInBits()) {
147f4a2713aSLionel Sambuc         case 8:
148f4a2713aSLionel Sambuc         case 16:
149*0a6a1f1dSLionel Sambuc           AliasReg = TM.getSubtargetImpl()->getFrameLowering()->hasFP(*MF)
150*0a6a1f1dSLionel Sambuc                          ? AliasFPReg
151*0a6a1f1dSLionel Sambuc                          : getMips16SPAliasReg();
152f4a2713aSLionel Sambuc           return;
153f4a2713aSLionel Sambuc         }
154f4a2713aSLionel Sambuc         break;
155f4a2713aSLionel Sambuc       }
156f4a2713aSLionel Sambuc     }
157f4a2713aSLionel Sambuc   }
158f4a2713aSLionel Sambuc   AliasReg = CurDAG->getRegister(Mips::SP, getTargetLowering()->getPointerTy());
159f4a2713aSLionel Sambuc   return;
160f4a2713aSLionel Sambuc 
161f4a2713aSLionel Sambuc }
162f4a2713aSLionel Sambuc 
selectAddr16(SDNode * Parent,SDValue Addr,SDValue & Base,SDValue & Offset,SDValue & Alias)163f4a2713aSLionel Sambuc bool Mips16DAGToDAGISel::selectAddr16(
164f4a2713aSLionel Sambuc   SDNode *Parent, SDValue Addr, SDValue &Base, SDValue &Offset,
165f4a2713aSLionel Sambuc   SDValue &Alias) {
166f4a2713aSLionel Sambuc   EVT ValTy = Addr.getValueType();
167f4a2713aSLionel Sambuc 
168f4a2713aSLionel Sambuc   Alias = CurDAG->getTargetConstant(0, ValTy);
169f4a2713aSLionel Sambuc 
170f4a2713aSLionel Sambuc   // if Address is FI, get the TargetFrameIndex.
171f4a2713aSLionel Sambuc   if (FrameIndexSDNode *FIN = dyn_cast<FrameIndexSDNode>(Addr)) {
172f4a2713aSLionel Sambuc     Base   = CurDAG->getTargetFrameIndex(FIN->getIndex(), ValTy);
173f4a2713aSLionel Sambuc     Offset = CurDAG->getTargetConstant(0, ValTy);
174f4a2713aSLionel Sambuc     getMips16SPRefReg(Parent, Alias);
175f4a2713aSLionel Sambuc     return true;
176f4a2713aSLionel Sambuc   }
177f4a2713aSLionel Sambuc   // on PIC code Load GA
178f4a2713aSLionel Sambuc   if (Addr.getOpcode() == MipsISD::Wrapper) {
179f4a2713aSLionel Sambuc     Base   = Addr.getOperand(0);
180f4a2713aSLionel Sambuc     Offset = Addr.getOperand(1);
181f4a2713aSLionel Sambuc     return true;
182f4a2713aSLionel Sambuc   }
183f4a2713aSLionel Sambuc   if (TM.getRelocationModel() != Reloc::PIC_) {
184f4a2713aSLionel Sambuc     if ((Addr.getOpcode() == ISD::TargetExternalSymbol ||
185f4a2713aSLionel Sambuc         Addr.getOpcode() == ISD::TargetGlobalAddress))
186f4a2713aSLionel Sambuc       return false;
187f4a2713aSLionel Sambuc   }
188f4a2713aSLionel Sambuc   // Addresses of the form FI+const or FI|const
189f4a2713aSLionel Sambuc   if (CurDAG->isBaseWithConstantOffset(Addr)) {
190f4a2713aSLionel Sambuc     ConstantSDNode *CN = dyn_cast<ConstantSDNode>(Addr.getOperand(1));
191f4a2713aSLionel Sambuc     if (isInt<16>(CN->getSExtValue())) {
192f4a2713aSLionel Sambuc 
193f4a2713aSLionel Sambuc       // If the first operand is a FI, get the TargetFI Node
194f4a2713aSLionel Sambuc       if (FrameIndexSDNode *FIN = dyn_cast<FrameIndexSDNode>
195f4a2713aSLionel Sambuc                                   (Addr.getOperand(0))) {
196f4a2713aSLionel Sambuc         Base = CurDAG->getTargetFrameIndex(FIN->getIndex(), ValTy);
197f4a2713aSLionel Sambuc         getMips16SPRefReg(Parent, Alias);
198f4a2713aSLionel Sambuc       }
199f4a2713aSLionel Sambuc       else
200f4a2713aSLionel Sambuc         Base = Addr.getOperand(0);
201f4a2713aSLionel Sambuc 
202f4a2713aSLionel Sambuc       Offset = CurDAG->getTargetConstant(CN->getZExtValue(), ValTy);
203f4a2713aSLionel Sambuc       return true;
204f4a2713aSLionel Sambuc     }
205f4a2713aSLionel Sambuc   }
206f4a2713aSLionel Sambuc   // Operand is a result from an ADD.
207f4a2713aSLionel Sambuc   if (Addr.getOpcode() == ISD::ADD) {
208f4a2713aSLionel Sambuc     // When loading from constant pools, load the lower address part in
209f4a2713aSLionel Sambuc     // the instruction itself. Example, instead of:
210f4a2713aSLionel Sambuc     //  lui $2, %hi($CPI1_0)
211f4a2713aSLionel Sambuc     //  addiu $2, $2, %lo($CPI1_0)
212f4a2713aSLionel Sambuc     //  lwc1 $f0, 0($2)
213f4a2713aSLionel Sambuc     // Generate:
214f4a2713aSLionel Sambuc     //  lui $2, %hi($CPI1_0)
215f4a2713aSLionel Sambuc     //  lwc1 $f0, %lo($CPI1_0)($2)
216f4a2713aSLionel Sambuc     if (Addr.getOperand(1).getOpcode() == MipsISD::Lo ||
217f4a2713aSLionel Sambuc         Addr.getOperand(1).getOpcode() == MipsISD::GPRel) {
218f4a2713aSLionel Sambuc       SDValue Opnd0 = Addr.getOperand(1).getOperand(0);
219f4a2713aSLionel Sambuc       if (isa<ConstantPoolSDNode>(Opnd0) || isa<GlobalAddressSDNode>(Opnd0) ||
220f4a2713aSLionel Sambuc           isa<JumpTableSDNode>(Opnd0)) {
221f4a2713aSLionel Sambuc         Base = Addr.getOperand(0);
222f4a2713aSLionel Sambuc         Offset = Opnd0;
223f4a2713aSLionel Sambuc         return true;
224f4a2713aSLionel Sambuc       }
225f4a2713aSLionel Sambuc     }
226f4a2713aSLionel Sambuc 
227f4a2713aSLionel Sambuc     // If an indexed floating point load/store can be emitted, return false.
228f4a2713aSLionel Sambuc     const LSBaseSDNode *LS = dyn_cast<LSBaseSDNode>(Parent);
229f4a2713aSLionel Sambuc 
230*0a6a1f1dSLionel Sambuc     if (LS) {
231*0a6a1f1dSLionel Sambuc       if (LS->getMemoryVT() == MVT::f32 && Subtarget->hasMips4_32r2())
232f4a2713aSLionel Sambuc         return false;
233*0a6a1f1dSLionel Sambuc       if (LS->getMemoryVT() == MVT::f64 && Subtarget->hasMips4_32r2())
234*0a6a1f1dSLionel Sambuc         return false;
235*0a6a1f1dSLionel Sambuc     }
236f4a2713aSLionel Sambuc   }
237f4a2713aSLionel Sambuc   Base   = Addr;
238f4a2713aSLionel Sambuc   Offset = CurDAG->getTargetConstant(0, ValTy);
239f4a2713aSLionel Sambuc   return true;
240f4a2713aSLionel Sambuc }
241f4a2713aSLionel Sambuc 
242f4a2713aSLionel Sambuc /// Select instructions not customized! Used for
243f4a2713aSLionel Sambuc /// expanded, promoted and normal instructions
selectNode(SDNode * Node)244f4a2713aSLionel Sambuc std::pair<bool, SDNode*> Mips16DAGToDAGISel::selectNode(SDNode *Node) {
245f4a2713aSLionel Sambuc   unsigned Opcode = Node->getOpcode();
246f4a2713aSLionel Sambuc   SDLoc DL(Node);
247f4a2713aSLionel Sambuc 
248f4a2713aSLionel Sambuc   ///
249f4a2713aSLionel Sambuc   // Instruction Selection not handled by the auto-generated
250f4a2713aSLionel Sambuc   // tablegen selection should be handled here.
251f4a2713aSLionel Sambuc   ///
252f4a2713aSLionel Sambuc   EVT NodeTy = Node->getValueType(0);
253f4a2713aSLionel Sambuc   unsigned MultOpc;
254f4a2713aSLionel Sambuc 
255f4a2713aSLionel Sambuc   switch(Opcode) {
256f4a2713aSLionel Sambuc   default: break;
257f4a2713aSLionel Sambuc 
258f4a2713aSLionel Sambuc   case ISD::SUBE:
259f4a2713aSLionel Sambuc   case ISD::ADDE: {
260f4a2713aSLionel Sambuc     SDValue InFlag = Node->getOperand(2), CmpLHS;
261f4a2713aSLionel Sambuc     unsigned Opc = InFlag.getOpcode(); (void)Opc;
262f4a2713aSLionel Sambuc     assert(((Opc == ISD::ADDC || Opc == ISD::ADDE) ||
263f4a2713aSLionel Sambuc             (Opc == ISD::SUBC || Opc == ISD::SUBE)) &&
264f4a2713aSLionel Sambuc            "(ADD|SUB)E flag operand must come from (ADD|SUB)C/E insn");
265f4a2713aSLionel Sambuc 
266f4a2713aSLionel Sambuc     unsigned MOp;
267f4a2713aSLionel Sambuc     if (Opcode == ISD::ADDE) {
268f4a2713aSLionel Sambuc       CmpLHS = InFlag.getValue(0);
269f4a2713aSLionel Sambuc       MOp = Mips::AdduRxRyRz16;
270f4a2713aSLionel Sambuc     } else {
271f4a2713aSLionel Sambuc       CmpLHS = InFlag.getOperand(0);
272f4a2713aSLionel Sambuc       MOp = Mips::SubuRxRyRz16;
273f4a2713aSLionel Sambuc     }
274f4a2713aSLionel Sambuc 
275f4a2713aSLionel Sambuc     SDValue Ops[] = { CmpLHS, InFlag.getOperand(1) };
276f4a2713aSLionel Sambuc 
277f4a2713aSLionel Sambuc     SDValue LHS = Node->getOperand(0);
278f4a2713aSLionel Sambuc     SDValue RHS = Node->getOperand(1);
279f4a2713aSLionel Sambuc 
280f4a2713aSLionel Sambuc     EVT VT = LHS.getValueType();
281f4a2713aSLionel Sambuc 
282f4a2713aSLionel Sambuc     unsigned Sltu_op = Mips::SltuRxRyRz16;
283f4a2713aSLionel Sambuc     SDNode *Carry = CurDAG->getMachineNode(Sltu_op, DL, VT, Ops);
284f4a2713aSLionel Sambuc     unsigned Addu_op = Mips::AdduRxRyRz16;
285f4a2713aSLionel Sambuc     SDNode *AddCarry = CurDAG->getMachineNode(Addu_op, DL, VT,
286f4a2713aSLionel Sambuc                                               SDValue(Carry,0), RHS);
287f4a2713aSLionel Sambuc 
288f4a2713aSLionel Sambuc     SDNode *Result = CurDAG->SelectNodeTo(Node, MOp, VT, MVT::Glue, LHS,
289f4a2713aSLionel Sambuc                                           SDValue(AddCarry,0));
290f4a2713aSLionel Sambuc     return std::make_pair(true, Result);
291f4a2713aSLionel Sambuc   }
292f4a2713aSLionel Sambuc 
293f4a2713aSLionel Sambuc   /// Mul with two results
294f4a2713aSLionel Sambuc   case ISD::SMUL_LOHI:
295f4a2713aSLionel Sambuc   case ISD::UMUL_LOHI: {
296f4a2713aSLionel Sambuc     MultOpc = (Opcode == ISD::UMUL_LOHI ? Mips::MultuRxRy16 : Mips::MultRxRy16);
297f4a2713aSLionel Sambuc     std::pair<SDNode*, SDNode*> LoHi = selectMULT(Node, MultOpc, DL, NodeTy,
298f4a2713aSLionel Sambuc                                                   true, true);
299f4a2713aSLionel Sambuc     if (!SDValue(Node, 0).use_empty())
300f4a2713aSLionel Sambuc       ReplaceUses(SDValue(Node, 0), SDValue(LoHi.first, 0));
301f4a2713aSLionel Sambuc 
302f4a2713aSLionel Sambuc     if (!SDValue(Node, 1).use_empty())
303f4a2713aSLionel Sambuc       ReplaceUses(SDValue(Node, 1), SDValue(LoHi.second, 0));
304f4a2713aSLionel Sambuc 
305*0a6a1f1dSLionel Sambuc     return std::make_pair(true, nullptr);
306f4a2713aSLionel Sambuc   }
307f4a2713aSLionel Sambuc 
308f4a2713aSLionel Sambuc   case ISD::MULHS:
309f4a2713aSLionel Sambuc   case ISD::MULHU: {
310f4a2713aSLionel Sambuc     MultOpc = (Opcode == ISD::MULHU ? Mips::MultuRxRy16 : Mips::MultRxRy16);
311f4a2713aSLionel Sambuc     SDNode *Result = selectMULT(Node, MultOpc, DL, NodeTy, false, true).second;
312f4a2713aSLionel Sambuc     return std::make_pair(true, Result);
313f4a2713aSLionel Sambuc   }
314f4a2713aSLionel Sambuc   }
315f4a2713aSLionel Sambuc 
316*0a6a1f1dSLionel Sambuc   return std::make_pair(false, nullptr);
317f4a2713aSLionel Sambuc }
318f4a2713aSLionel Sambuc 
createMips16ISelDag(MipsTargetMachine & TM)319f4a2713aSLionel Sambuc FunctionPass *llvm::createMips16ISelDag(MipsTargetMachine &TM) {
320f4a2713aSLionel Sambuc   return new Mips16DAGToDAGISel(TM);
321f4a2713aSLionel Sambuc }
322