1 //===-- Mips16ISelLowering.h - Mips16 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 mips16.
12 //===----------------------------------------------------------------------===//
13 #define DEBUG_TYPE "mips-lower"
14 #include "Mips16ISelLowering.h"
15 #include "MipsRegisterInfo.h"
16 #include "MipsTargetMachine.h"
17 #include "MCTargetDesc/MipsBaseInfo.h"
18 #include "llvm/CodeGen/MachineInstrBuilder.h"
19 #include "llvm/Support/CommandLine.h"
20 #include "llvm/Target/TargetInstrInfo.h"
25 static cl::opt<bool> DontExpandCondPseudos16(
26 "mips16-dont-expand-cond-pseudo",
28 cl::desc("Dont expand conditional move related "
29 "pseudos for Mips 16"),
33 std::set<const char*, MipsTargetLowering::LTStr> NoHelperNeeded;
36 Mips16TargetLowering::Mips16TargetLowering(MipsTargetMachine &TM)
37 : MipsTargetLowering(TM) {
39 // set up as if mips32 and then revert so we can test the mechanism
41 addRegisterClass(MVT::i32, &Mips::CPURegsRegClass);
42 addRegisterClass(MVT::f32, &Mips::FGR32RegClass);
43 computeRegisterProperties();
44 clearRegisterClasses();
46 // Set up the register classes
47 addRegisterClass(MVT::i32, &Mips::CPU16RegsRegClass);
49 if (Subtarget->inMips16HardFloat()) {
50 setMips16HardFloatLibCalls();
51 NoHelperNeeded.insert("__mips16_ret_sf");
52 NoHelperNeeded.insert("__mips16_ret_df");
53 NoHelperNeeded.insert("__mips16_ret_sc");
54 NoHelperNeeded.insert("__mips16_ret_dc");
56 setOperationAction(ISD::ATOMIC_FENCE, MVT::Other, Expand);
57 setOperationAction(ISD::ATOMIC_CMP_SWAP, MVT::i32, Expand);
58 setOperationAction(ISD::ATOMIC_SWAP, MVT::i32, Expand);
59 setOperationAction(ISD::ATOMIC_LOAD_ADD, MVT::i32, Expand);
60 setOperationAction(ISD::ATOMIC_LOAD_SUB, MVT::i32, Expand);
61 setOperationAction(ISD::ATOMIC_LOAD_AND, MVT::i32, Expand);
62 setOperationAction(ISD::ATOMIC_LOAD_OR, MVT::i32, Expand);
63 setOperationAction(ISD::ATOMIC_LOAD_XOR, MVT::i32, Expand);
64 setOperationAction(ISD::ATOMIC_LOAD_NAND, MVT::i32, Expand);
65 setOperationAction(ISD::ATOMIC_LOAD_MIN, MVT::i32, Expand);
66 setOperationAction(ISD::ATOMIC_LOAD_MAX, MVT::i32, Expand);
67 setOperationAction(ISD::ATOMIC_LOAD_UMIN, MVT::i32, Expand);
68 setOperationAction(ISD::ATOMIC_LOAD_UMAX, MVT::i32, Expand);
70 computeRegisterProperties();
73 const MipsTargetLowering *
74 llvm::createMips16TargetLowering(MipsTargetMachine &TM) {
75 return new Mips16TargetLowering(TM);
79 Mips16TargetLowering::allowsUnalignedMemoryAccesses(EVT VT, bool *Fast) const {
84 Mips16TargetLowering::EmitInstrWithCustomInserter(MachineInstr *MI,
85 MachineBasicBlock *BB) const {
86 switch (MI->getOpcode()) {
88 return MipsTargetLowering::EmitInstrWithCustomInserter(MI, BB);
90 return emitSel16(Mips::BeqzRxImm16, MI, BB);
92 return emitSel16(Mips::BnezRxImm16, MI, BB);
93 case Mips::SelTBteqZCmpi:
94 return emitSeliT16(Mips::BteqzX16, Mips::CmpiRxImmX16, MI, BB);
95 case Mips::SelTBteqZSlti:
96 return emitSeliT16(Mips::BteqzX16, Mips::SltiRxImmX16, MI, BB);
97 case Mips::SelTBteqZSltiu:
98 return emitSeliT16(Mips::BteqzX16, Mips::SltiuRxImmX16, MI, BB);
99 case Mips::SelTBtneZCmpi:
100 return emitSeliT16(Mips::BtnezX16, Mips::CmpiRxImmX16, MI, BB);
101 case Mips::SelTBtneZSlti:
102 return emitSeliT16(Mips::BtnezX16, Mips::SltiRxImmX16, MI, BB);
103 case Mips::SelTBtneZSltiu:
104 return emitSeliT16(Mips::BtnezX16, Mips::SltiuRxImmX16, MI, BB);
105 case Mips::SelTBteqZCmp:
106 return emitSelT16(Mips::BteqzX16, Mips::CmpRxRy16, MI, BB);
107 case Mips::SelTBteqZSlt:
108 return emitSelT16(Mips::BteqzX16, Mips::SltRxRy16, MI, BB);
109 case Mips::SelTBteqZSltu:
110 return emitSelT16(Mips::BteqzX16, Mips::SltuRxRy16, MI, BB);
111 case Mips::SelTBtneZCmp:
112 return emitSelT16(Mips::BtnezX16, Mips::CmpRxRy16, MI, BB);
113 case Mips::SelTBtneZSlt:
114 return emitSelT16(Mips::BtnezX16, Mips::SltRxRy16, MI, BB);
115 case Mips::SelTBtneZSltu:
116 return emitSelT16(Mips::BtnezX16, Mips::SltuRxRy16, MI, BB);
117 case Mips::BteqzT8CmpX16:
118 return emitFEXT_T8I816_ins(Mips::BteqzX16, Mips::CmpRxRy16, MI, BB);
119 case Mips::BteqzT8SltX16:
120 return emitFEXT_T8I816_ins(Mips::BteqzX16, Mips::SltRxRy16, MI, BB);
121 case Mips::BteqzT8SltuX16:
122 // TBD: figure out a way to get this or remove the instruction
124 return emitFEXT_T8I816_ins(Mips::BteqzX16, Mips::SltuRxRy16, MI, BB);
125 case Mips::BtnezT8CmpX16:
126 return emitFEXT_T8I816_ins(Mips::BtnezX16, Mips::CmpRxRy16, MI, BB);
127 case Mips::BtnezT8SltX16:
128 return emitFEXT_T8I816_ins(Mips::BtnezX16, Mips::SltRxRy16, MI, BB);
129 case Mips::BtnezT8SltuX16:
130 // TBD: figure out a way to get this or remove the instruction
132 return emitFEXT_T8I816_ins(Mips::BtnezX16, Mips::SltuRxRy16, MI, BB);
133 case Mips::BteqzT8CmpiX16: return emitFEXT_T8I8I16_ins(
134 Mips::BteqzX16, Mips::CmpiRxImm16, Mips::CmpiRxImmX16, MI, BB);
135 case Mips::BteqzT8SltiX16: return emitFEXT_T8I8I16_ins(
136 Mips::BteqzX16, Mips::SltiRxImm16, Mips::SltiRxImmX16, MI, BB);
137 case Mips::BteqzT8SltiuX16: return emitFEXT_T8I8I16_ins(
138 Mips::BteqzX16, Mips::SltiuRxImm16, Mips::SltiuRxImmX16, MI, BB);
139 case Mips::BtnezT8CmpiX16: return emitFEXT_T8I8I16_ins(
140 Mips::BtnezX16, Mips::CmpiRxImm16, Mips::CmpiRxImmX16, MI, BB);
141 case Mips::BtnezT8SltiX16: return emitFEXT_T8I8I16_ins(
142 Mips::BtnezX16, Mips::SltiRxImm16, Mips::SltiRxImmX16, MI, BB);
143 case Mips::BtnezT8SltiuX16: return emitFEXT_T8I8I16_ins(
144 Mips::BtnezX16, Mips::SltiuRxImm16, Mips::SltiuRxImmX16, MI, BB);
146 case Mips::SltCCRxRy16:
147 return emitFEXT_CCRX16_ins(Mips::SltRxRy16, MI, BB);
149 case Mips::SltiCCRxImmX16:
150 return emitFEXT_CCRXI16_ins
151 (Mips::SltiRxImm16, Mips::SltiRxImmX16, MI, BB);
152 case Mips::SltiuCCRxImmX16:
153 return emitFEXT_CCRXI16_ins
154 (Mips::SltiuRxImm16, Mips::SltiuRxImmX16, MI, BB);
155 case Mips::SltuCCRxRy16:
156 return emitFEXT_CCRX16_ins
157 (Mips::SltuRxRy16, MI, BB);
161 bool Mips16TargetLowering::
162 isEligibleForTailCallOptimization(const MipsCC &MipsCCInfo,
163 unsigned NextStackOffset,
164 const MipsFunctionInfo& FI) const {
165 // No tail call optimization for mips16.
169 void Mips16TargetLowering::setMips16LibcallName
170 (RTLIB::Libcall L, const char *Name) {
171 setLibcallName(L, Name);
172 NoHelperNeeded.insert(Name);
175 void Mips16TargetLowering::setMips16HardFloatLibCalls() {
176 setMips16LibcallName(RTLIB::ADD_F32, "__mips16_addsf3");
177 setMips16LibcallName(RTLIB::ADD_F64, "__mips16_adddf3");
178 setMips16LibcallName(RTLIB::SUB_F32, "__mips16_subsf3");
179 setMips16LibcallName(RTLIB::SUB_F64, "__mips16_subdf3");
180 setMips16LibcallName(RTLIB::MUL_F32, "__mips16_mulsf3");
181 setMips16LibcallName(RTLIB::MUL_F64, "__mips16_muldf3");
182 setMips16LibcallName(RTLIB::DIV_F32, "__mips16_divsf3");
183 setMips16LibcallName(RTLIB::DIV_F64, "__mips16_divdf3");
184 setMips16LibcallName(RTLIB::FPEXT_F32_F64, "__mips16_extendsfdf2");
185 setMips16LibcallName(RTLIB::FPROUND_F64_F32, "__mips16_truncdfsf2");
186 setMips16LibcallName(RTLIB::FPTOSINT_F32_I32, "__mips16_fix_truncsfsi");
187 setMips16LibcallName(RTLIB::FPTOSINT_F64_I32, "__mips16_fix_truncdfsi");
188 setMips16LibcallName(RTLIB::SINTTOFP_I32_F32, "__mips16_floatsisf");
189 setMips16LibcallName(RTLIB::SINTTOFP_I32_F64, "__mips16_floatsidf");
190 setMips16LibcallName(RTLIB::UINTTOFP_I32_F32, "__mips16_floatunsisf");
191 setMips16LibcallName(RTLIB::UINTTOFP_I32_F64, "__mips16_floatunsidf");
192 setMips16LibcallName(RTLIB::OEQ_F32, "__mips16_eqsf2");
193 setMips16LibcallName(RTLIB::OEQ_F64, "__mips16_eqdf2");
194 setMips16LibcallName(RTLIB::UNE_F32, "__mips16_nesf2");
195 setMips16LibcallName(RTLIB::UNE_F64, "__mips16_nedf2");
196 setMips16LibcallName(RTLIB::OGE_F32, "__mips16_gesf2");
197 setMips16LibcallName(RTLIB::OGE_F64, "__mips16_gedf2");
198 setMips16LibcallName(RTLIB::OLT_F32, "__mips16_ltsf2");
199 setMips16LibcallName(RTLIB::OLT_F64, "__mips16_ltdf2");
200 setMips16LibcallName(RTLIB::OLE_F32, "__mips16_lesf2");
201 setMips16LibcallName(RTLIB::OLE_F64, "__mips16_ledf2");
202 setMips16LibcallName(RTLIB::OGT_F32, "__mips16_gtsf2");
203 setMips16LibcallName(RTLIB::OGT_F64, "__mips16_gtdf2");
204 setMips16LibcallName(RTLIB::UO_F32, "__mips16_unordsf2");
205 setMips16LibcallName(RTLIB::UO_F64, "__mips16_unorddf2");
206 setMips16LibcallName(RTLIB::O_F32, "__mips16_unordsf2");
207 setMips16LibcallName(RTLIB::O_F64, "__mips16_unorddf2");
212 // The Mips16 hard float is a crazy quilt inherited from gcc. I have a much
213 // cleaner way to do all of this but it will have to wait until the traditional
214 // gcc mechanism is completed.
216 // For Pic, in order for Mips16 code to call Mips32 code which according the abi
217 // have either arguments or returned values placed in floating point registers,
218 // we use a set of helper functions. (This includes functions which return type
219 // complex which on Mips are returned in a pair of floating point registers).
221 // This is an encoding that we inherited from gcc.
222 // In Mips traditional O32, N32 ABI, floating point numbers are passed in
223 // floating point argument registers 1,2 only when the first and optionally
224 // the second arguments are float (sf) or double (df).
225 // For Mips16 we are only concerned with the situations where floating point
226 // arguments are being passed in floating point registers by the ABI, because
227 // Mips16 mode code cannot execute floating point instructions to load those
228 // values and hence helper functions are needed.
229 // The possibilities are (), (sf), (sf, sf), (sf, df), (df), (df, sf), (df, df)
230 // the helper function suffixs for these are:
231 // 0, 1, 5, 9, 2, 6, 10
232 // this suffix can then be calculated as follows:
233 // for a given argument Arg:
234 // Arg1x, Arg2x = 1 : Arg is sf
236 // 0: Arg is neither sf or df
237 // So this stub is the string for number Arg1x + Arg2x*4.
238 // However not all numbers between 0 and 10 are possible, we check anyway and
239 // assert if the impossible exists.
242 unsigned int Mips16TargetLowering::getMips16HelperFunctionStubNumber
243 (ArgListTy &Args) const {
244 unsigned int resultNum = 0;
245 if (Args.size() >= 1) {
246 Type *t = Args[0].Ty;
247 if (t->isFloatTy()) {
250 else if (t->isDoubleTy()) {
255 if (Args.size() >=2) {
256 Type *t = Args[1].Ty;
257 if (t->isFloatTy()) {
260 else if (t->isDoubleTy()) {
269 // prefixs are attached to stub numbers depending on the return type .
270 // return type: float sf_
272 // single complex sc_
273 // double complext dc_
277 // The full name of a helper function is__mips16_call_stub +
278 // return type dependent prefix + stub number
281 // This is something that probably should be in a different source file and
282 // perhaps done differently but my main purpose is to not waste runtime
283 // on something that we can enumerate in the source. Another possibility is
284 // to have a python script to generate these mapping tables. This will do
285 // for now. There are a whole series of helper function mapping arrays, one
286 // for each return type class as outlined above. There there are 11 possible
287 // entries. Ones with 0 are ones which should never be selected
289 // All the arrays are similar except for ones which return neither
290 // sf, df, sc, dc, in which only care about ones which have sf or df as a
293 #define P_ "__mips16_call_stub_"
294 #define MAX_STUB_NUMBER 10
295 #define T1 P "1", P "2", 0, 0, P "5", P "6", 0, 0, P "9", P "10"
298 static char const * vMips16Helper[MAX_STUB_NUMBER+1] =
302 static char const * sfMips16Helper[MAX_STUB_NUMBER+1] =
306 static char const * dfMips16Helper[MAX_STUB_NUMBER+1] =
310 static char const * scMips16Helper[MAX_STUB_NUMBER+1] =
314 static char const * dcMips16Helper[MAX_STUB_NUMBER+1] =
320 const char* Mips16TargetLowering::
321 getMips16HelperFunction
322 (Type* RetTy, ArgListTy &Args, bool &needHelper) const {
323 const unsigned int stubNum = getMips16HelperFunctionStubNumber(Args);
325 const unsigned int maxStubNum = 10;
326 assert(stubNum <= maxStubNum);
327 const bool validStubNum[maxStubNum+1] =
328 {true, true, true, false, false, true, true, false, false, true, true};
329 assert(validStubNum[stubNum]);
332 if (RetTy->isFloatTy()) {
333 result = sfMips16Helper[stubNum];
335 else if (RetTy ->isDoubleTy()) {
336 result = dfMips16Helper[stubNum];
338 else if (RetTy->isStructTy()) {
339 // check if it's complex
340 if (RetTy->getNumContainedTypes() == 2) {
341 if ((RetTy->getContainedType(0)->isFloatTy()) &&
342 (RetTy->getContainedType(1)->isFloatTy())) {
343 result = scMips16Helper[stubNum];
345 else if ((RetTy->getContainedType(0)->isDoubleTy()) &&
346 (RetTy->getContainedType(1)->isDoubleTy())) {
347 result = dcMips16Helper[stubNum];
350 llvm_unreachable("Uncovered condition");
354 llvm_unreachable("Uncovered condition");
362 result = vMips16Helper[stubNum];
368 void Mips16TargetLowering::
369 getOpndList(SmallVectorImpl<SDValue> &Ops,
370 std::deque< std::pair<unsigned, SDValue> > &RegsToPass,
371 bool IsPICCall, bool GlobalOrExternal, bool InternalLinkage,
372 CallLoweringInfo &CLI, SDValue Callee, SDValue Chain) const {
373 SelectionDAG &DAG = CLI.DAG;
374 const char* Mips16HelperFunction = 0;
375 bool NeedMips16Helper = false;
377 if (getTargetMachine().Options.UseSoftFloat &&
378 Subtarget->inMips16HardFloat()) {
380 // currently we don't have symbols tagged with the mips16 or mips32
381 // qualifier so we will assume that we don't know what kind it is.
382 // and generate the helper
384 bool LookupHelper = true;
385 if (ExternalSymbolSDNode *S = dyn_cast<ExternalSymbolSDNode>(CLI.Callee)) {
386 if (NoHelperNeeded.find(S->getSymbol()) != NoHelperNeeded.end()) {
387 LookupHelper = false;
390 else if (GlobalAddressSDNode *G =
391 dyn_cast<GlobalAddressSDNode>(CLI.Callee)) {
392 if (NoHelperNeeded.find(G->getGlobal()->getName().data()) !=
393 NoHelperNeeded.end()) {
394 LookupHelper = false;
397 if (LookupHelper) Mips16HelperFunction =
398 getMips16HelperFunction(CLI.RetTy, CLI.Args, NeedMips16Helper);
402 SDValue JumpTarget = Callee;
404 // T9 should contain the address of the callee function if
405 // -reloction-model=pic or it is an indirect call.
406 if (IsPICCall || !GlobalOrExternal) {
407 unsigned V0Reg = Mips::V0;
408 if (NeedMips16Helper) {
409 RegsToPass.push_front(std::make_pair(V0Reg, Callee));
410 JumpTarget = DAG.getExternalSymbol(Mips16HelperFunction, getPointerTy());
411 JumpTarget = getAddrGlobal(JumpTarget, DAG, MipsII::MO_GOT);
413 RegsToPass.push_front(std::make_pair((unsigned)Mips::T9, Callee));
416 Ops.push_back(JumpTarget);
418 MipsTargetLowering::getOpndList(Ops, RegsToPass, IsPICCall, GlobalOrExternal,
419 InternalLinkage, CLI, Callee, Chain);
422 MachineBasicBlock *Mips16TargetLowering::
423 emitSel16(unsigned Opc, MachineInstr *MI, MachineBasicBlock *BB) const {
424 if (DontExpandCondPseudos16)
426 const TargetInstrInfo *TII = getTargetMachine().getInstrInfo();
427 DebugLoc DL = MI->getDebugLoc();
428 // To "insert" a SELECT_CC instruction, we actually have to insert the
429 // diamond control-flow pattern. The incoming instruction knows the
430 // destination vreg to set, the condition code register to branch on, the
431 // true/false values to select between, and a branch opcode to use.
432 const BasicBlock *LLVM_BB = BB->getBasicBlock();
433 MachineFunction::iterator It = BB;
440 // bNE r1, r0, copy1MBB
441 // fallthrough --> copy0MBB
442 MachineBasicBlock *thisMBB = BB;
443 MachineFunction *F = BB->getParent();
444 MachineBasicBlock *copy0MBB = F->CreateMachineBasicBlock(LLVM_BB);
445 MachineBasicBlock *sinkMBB = F->CreateMachineBasicBlock(LLVM_BB);
446 F->insert(It, copy0MBB);
447 F->insert(It, sinkMBB);
449 // Transfer the remainder of BB and its successor edges to sinkMBB.
450 sinkMBB->splice(sinkMBB->begin(), BB,
451 llvm::next(MachineBasicBlock::iterator(MI)),
453 sinkMBB->transferSuccessorsAndUpdatePHIs(BB);
455 // Next, add the true and fallthrough blocks as its successors.
456 BB->addSuccessor(copy0MBB);
457 BB->addSuccessor(sinkMBB);
459 BuildMI(BB, DL, TII->get(Opc)).addReg(MI->getOperand(3).getReg())
464 // # fallthrough to sinkMBB
467 // Update machine-CFG edges
468 BB->addSuccessor(sinkMBB);
471 // %Result = phi [ %TrueValue, thisMBB ], [ %FalseValue, copy0MBB ]
475 BuildMI(*BB, BB->begin(), DL,
476 TII->get(Mips::PHI), MI->getOperand(0).getReg())
477 .addReg(MI->getOperand(1).getReg()).addMBB(thisMBB)
478 .addReg(MI->getOperand(2).getReg()).addMBB(copy0MBB);
480 MI->eraseFromParent(); // The pseudo instruction is gone now.
484 MachineBasicBlock *Mips16TargetLowering::emitSelT16
485 (unsigned Opc1, unsigned Opc2,
486 MachineInstr *MI, MachineBasicBlock *BB) const {
487 if (DontExpandCondPseudos16)
489 const TargetInstrInfo *TII = getTargetMachine().getInstrInfo();
490 DebugLoc DL = MI->getDebugLoc();
491 // To "insert" a SELECT_CC instruction, we actually have to insert the
492 // diamond control-flow pattern. The incoming instruction knows the
493 // destination vreg to set, the condition code register to branch on, the
494 // true/false values to select between, and a branch opcode to use.
495 const BasicBlock *LLVM_BB = BB->getBasicBlock();
496 MachineFunction::iterator It = BB;
503 // bNE r1, r0, copy1MBB
504 // fallthrough --> copy0MBB
505 MachineBasicBlock *thisMBB = BB;
506 MachineFunction *F = BB->getParent();
507 MachineBasicBlock *copy0MBB = F->CreateMachineBasicBlock(LLVM_BB);
508 MachineBasicBlock *sinkMBB = F->CreateMachineBasicBlock(LLVM_BB);
509 F->insert(It, copy0MBB);
510 F->insert(It, sinkMBB);
512 // Transfer the remainder of BB and its successor edges to sinkMBB.
513 sinkMBB->splice(sinkMBB->begin(), BB,
514 llvm::next(MachineBasicBlock::iterator(MI)),
516 sinkMBB->transferSuccessorsAndUpdatePHIs(BB);
518 // Next, add the true and fallthrough blocks as its successors.
519 BB->addSuccessor(copy0MBB);
520 BB->addSuccessor(sinkMBB);
522 BuildMI(BB, DL, TII->get(Opc2)).addReg(MI->getOperand(3).getReg())
523 .addReg(MI->getOperand(4).getReg());
524 BuildMI(BB, DL, TII->get(Opc1)).addMBB(sinkMBB);
528 // # fallthrough to sinkMBB
531 // Update machine-CFG edges
532 BB->addSuccessor(sinkMBB);
535 // %Result = phi [ %TrueValue, thisMBB ], [ %FalseValue, copy0MBB ]
539 BuildMI(*BB, BB->begin(), DL,
540 TII->get(Mips::PHI), MI->getOperand(0).getReg())
541 .addReg(MI->getOperand(1).getReg()).addMBB(thisMBB)
542 .addReg(MI->getOperand(2).getReg()).addMBB(copy0MBB);
544 MI->eraseFromParent(); // The pseudo instruction is gone now.
549 MachineBasicBlock *Mips16TargetLowering::emitSeliT16
550 (unsigned Opc1, unsigned Opc2,
551 MachineInstr *MI, MachineBasicBlock *BB) const {
552 if (DontExpandCondPseudos16)
554 const TargetInstrInfo *TII = getTargetMachine().getInstrInfo();
555 DebugLoc DL = MI->getDebugLoc();
556 // To "insert" a SELECT_CC instruction, we actually have to insert the
557 // diamond control-flow pattern. The incoming instruction knows the
558 // destination vreg to set, the condition code register to branch on, the
559 // true/false values to select between, and a branch opcode to use.
560 const BasicBlock *LLVM_BB = BB->getBasicBlock();
561 MachineFunction::iterator It = BB;
568 // bNE r1, r0, copy1MBB
569 // fallthrough --> copy0MBB
570 MachineBasicBlock *thisMBB = BB;
571 MachineFunction *F = BB->getParent();
572 MachineBasicBlock *copy0MBB = F->CreateMachineBasicBlock(LLVM_BB);
573 MachineBasicBlock *sinkMBB = F->CreateMachineBasicBlock(LLVM_BB);
574 F->insert(It, copy0MBB);
575 F->insert(It, sinkMBB);
577 // Transfer the remainder of BB and its successor edges to sinkMBB.
578 sinkMBB->splice(sinkMBB->begin(), BB,
579 llvm::next(MachineBasicBlock::iterator(MI)),
581 sinkMBB->transferSuccessorsAndUpdatePHIs(BB);
583 // Next, add the true and fallthrough blocks as its successors.
584 BB->addSuccessor(copy0MBB);
585 BB->addSuccessor(sinkMBB);
587 BuildMI(BB, DL, TII->get(Opc2)).addReg(MI->getOperand(3).getReg())
588 .addImm(MI->getOperand(4).getImm());
589 BuildMI(BB, DL, TII->get(Opc1)).addMBB(sinkMBB);
593 // # fallthrough to sinkMBB
596 // Update machine-CFG edges
597 BB->addSuccessor(sinkMBB);
600 // %Result = phi [ %TrueValue, thisMBB ], [ %FalseValue, copy0MBB ]
604 BuildMI(*BB, BB->begin(), DL,
605 TII->get(Mips::PHI), MI->getOperand(0).getReg())
606 .addReg(MI->getOperand(1).getReg()).addMBB(thisMBB)
607 .addReg(MI->getOperand(2).getReg()).addMBB(copy0MBB);
609 MI->eraseFromParent(); // The pseudo instruction is gone now.
615 *Mips16TargetLowering::emitFEXT_T8I816_ins(unsigned BtOpc, unsigned CmpOpc,
617 MachineBasicBlock *BB) const {
618 if (DontExpandCondPseudos16)
620 const TargetInstrInfo *TII = getTargetMachine().getInstrInfo();
621 unsigned regX = MI->getOperand(0).getReg();
622 unsigned regY = MI->getOperand(1).getReg();
623 MachineBasicBlock *target = MI->getOperand(2).getMBB();
624 BuildMI(*BB, MI, MI->getDebugLoc(), TII->get(CmpOpc)).addReg(regX)
626 BuildMI(*BB, MI, MI->getDebugLoc(), TII->get(BtOpc)).addMBB(target);
627 MI->eraseFromParent(); // The pseudo instruction is gone now.
631 MachineBasicBlock *Mips16TargetLowering::emitFEXT_T8I8I16_ins(
632 unsigned BtOpc, unsigned CmpiOpc, unsigned CmpiXOpc,
633 MachineInstr *MI, MachineBasicBlock *BB) const {
634 if (DontExpandCondPseudos16)
636 const TargetInstrInfo *TII = getTargetMachine().getInstrInfo();
637 unsigned regX = MI->getOperand(0).getReg();
638 int64_t imm = MI->getOperand(1).getImm();
639 MachineBasicBlock *target = MI->getOperand(2).getMBB();
643 else if (isUInt<16>(imm))
646 llvm_unreachable("immediate field not usable");
647 BuildMI(*BB, MI, MI->getDebugLoc(), TII->get(CmpOpc)).addReg(regX)
649 BuildMI(*BB, MI, MI->getDebugLoc(), TII->get(BtOpc)).addMBB(target);
650 MI->eraseFromParent(); // The pseudo instruction is gone now.
654 static unsigned Mips16WhichOp8uOr16simm
655 (unsigned shortOp, unsigned longOp, int64_t Imm) {
658 else if (isInt<16>(Imm))
661 llvm_unreachable("immediate field not usable");
664 MachineBasicBlock *Mips16TargetLowering::emitFEXT_CCRX16_ins(
666 MachineInstr *MI, MachineBasicBlock *BB) const {
667 if (DontExpandCondPseudos16)
669 const TargetInstrInfo *TII = getTargetMachine().getInstrInfo();
670 unsigned CC = MI->getOperand(0).getReg();
671 unsigned regX = MI->getOperand(1).getReg();
672 unsigned regY = MI->getOperand(2).getReg();
673 BuildMI(*BB, MI, MI->getDebugLoc(),
674 TII->get(SltOpc)).addReg(regX).addReg(regY);
675 BuildMI(*BB, MI, MI->getDebugLoc(),
676 TII->get(Mips::MoveR3216), CC).addReg(Mips::T8);
677 MI->eraseFromParent(); // The pseudo instruction is gone now.
681 MachineBasicBlock *Mips16TargetLowering::emitFEXT_CCRXI16_ins(
682 unsigned SltiOpc, unsigned SltiXOpc,
683 MachineInstr *MI, MachineBasicBlock *BB )const {
684 if (DontExpandCondPseudos16)
686 const TargetInstrInfo *TII = getTargetMachine().getInstrInfo();
687 unsigned CC = MI->getOperand(0).getReg();
688 unsigned regX = MI->getOperand(1).getReg();
689 int64_t Imm = MI->getOperand(2).getImm();
690 unsigned SltOpc = Mips16WhichOp8uOr16simm(SltiOpc, SltiXOpc, Imm);
691 BuildMI(*BB, MI, MI->getDebugLoc(),
692 TII->get(SltOpc)).addReg(regX).addImm(Imm);
693 BuildMI(*BB, MI, MI->getDebugLoc(),
694 TII->get(Mips::MoveR3216), CC).addReg(Mips::T8);
695 MI->eraseFromParent(); // The pseudo instruction is gone now.