LLVM 24.0.0git
Mips16ISelLowering.cpp
Go to the documentation of this file.
1//===-- Mips16ISelLowering.h - Mips16 DAG Lowering Interface ----*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// Subclass of MipsTargetLowering specialized for mips16.
10//
11//===----------------------------------------------------------------------===//
12#include "Mips16ISelLowering.h"
14#include "Mips16HardFloatInfo.h"
15#include "MipsMachineFunction.h"
16#include "MipsRegisterInfo.h"
17#include "MipsTargetMachine.h"
20
21using namespace llvm;
22
23#define DEBUG_TYPE "mips-lower"
24
25namespace {
26struct Mips16IntrinsicHelperType{
27 const char* Name;
28 const char* Helper;
29
30 bool operator<(const Mips16IntrinsicHelperType &RHS) const {
31 return std::strcmp(Name, RHS.Name) < 0;
32 }
33 bool operator==(const Mips16IntrinsicHelperType &RHS) const {
34 return std::strcmp(Name, RHS.Name) == 0;
35 }
36};
37} // namespace
38
39static const Mips16IntrinsicHelperType Mips16IntrinsicHelper[] = {
40 {"__fixunsdfsi", "__mips16_call_stub_2" },
41 {"ceil", "__mips16_call_stub_df_2"},
42 {"ceilf", "__mips16_call_stub_sf_1"},
43 {"copysign", "__mips16_call_stub_df_10"},
44 {"copysignf", "__mips16_call_stub_sf_5"},
45 {"cos", "__mips16_call_stub_df_2"},
46 {"cosf", "__mips16_call_stub_sf_1"},
47 {"exp2", "__mips16_call_stub_df_2"},
48 {"exp2f", "__mips16_call_stub_sf_1"},
49 {"floor", "__mips16_call_stub_df_2"},
50 {"floorf", "__mips16_call_stub_sf_1"},
51 {"log2", "__mips16_call_stub_df_2"},
52 {"log2f", "__mips16_call_stub_sf_1"},
53 {"nearbyint", "__mips16_call_stub_df_2"},
54 {"nearbyintf", "__mips16_call_stub_sf_1"},
55 {"rint", "__mips16_call_stub_df_2"},
56 {"rintf", "__mips16_call_stub_sf_1"},
57 {"sin", "__mips16_call_stub_df_2"},
58 {"sinf", "__mips16_call_stub_sf_1"},
59 {"sqrt", "__mips16_call_stub_df_2"},
60 {"sqrtf", "__mips16_call_stub_sf_1"},
61 {"trunc", "__mips16_call_stub_df_2"},
62 {"truncf", "__mips16_call_stub_sf_1"},
63};
64
87
90 const MipsSubtarget &STI) {
91 return new Mips16TargetLowering(TM, STI);
92}
93
95 EVT VT, unsigned, Align, MachineMemOperand::Flags, unsigned *Fast) const {
96 return false;
97}
98
101 MachineBasicBlock *BB) const {
102 switch (MI.getOpcode()) {
103 default:
105 case Mips::SelBeqZ:
106 return emitSel16(Mips::BeqzRxImm16, MI, BB);
107 case Mips::SelBneZ:
108 return emitSel16(Mips::BnezRxImm16, MI, BB);
109 case Mips::SelTBteqZCmpi:
110 return emitSeliT16(Mips::Bteqz16, Mips::CmpiRxImmX16, MI, BB);
111 case Mips::SelTBteqZSlti:
112 return emitSeliT16(Mips::Bteqz16, Mips::SltiRxImmX16, MI, BB);
113 case Mips::SelTBteqZSltiu:
114 return emitSeliT16(Mips::Bteqz16, Mips::SltiuRxImmX16, MI, BB);
115 case Mips::SelTBtneZCmpi:
116 return emitSeliT16(Mips::Btnez16, Mips::CmpiRxImmX16, MI, BB);
117 case Mips::SelTBtneZSlti:
118 return emitSeliT16(Mips::Btnez16, Mips::SltiRxImmX16, MI, BB);
119 case Mips::SelTBtneZSltiu:
120 return emitSeliT16(Mips::Btnez16, Mips::SltiuRxImmX16, MI, BB);
121 case Mips::SelTBteqZCmp:
122 return emitSelT16(Mips::Bteqz16, Mips::CmpRxRy16, MI, BB);
123 case Mips::SelTBteqZSlt:
124 return emitSelT16(Mips::Bteqz16, Mips::SltRxRy16, MI, BB);
125 case Mips::SelTBteqZSltu:
126 return emitSelT16(Mips::Bteqz16, Mips::SltuRxRy16, MI, BB);
127 case Mips::SelTBtneZCmp:
128 return emitSelT16(Mips::Btnez16, Mips::CmpRxRy16, MI, BB);
129 case Mips::SelTBtneZSlt:
130 return emitSelT16(Mips::Btnez16, Mips::SltRxRy16, MI, BB);
131 case Mips::SelTBtneZSltu:
132 return emitSelT16(Mips::Btnez16, Mips::SltuRxRy16, MI, BB);
133 case Mips::BteqzT8CmpX16:
134 return emitFEXT_T8I816_ins(Mips::Bteqz16, Mips::CmpRxRy16, MI, BB);
135 case Mips::BteqzT8SltX16:
136 return emitFEXT_T8I816_ins(Mips::Bteqz16, Mips::SltRxRy16, MI, BB);
137 case Mips::BteqzT8SltuX16:
138 // TBD: figure out a way to get this or remove the instruction
139 // altogether.
140 return emitFEXT_T8I816_ins(Mips::Bteqz16, Mips::SltuRxRy16, MI, BB);
141 case Mips::BtnezT8CmpX16:
142 return emitFEXT_T8I816_ins(Mips::Btnez16, Mips::CmpRxRy16, MI, BB);
143 case Mips::BtnezT8SltX16:
144 return emitFEXT_T8I816_ins(Mips::Btnez16, Mips::SltRxRy16, MI, BB);
145 case Mips::BtnezT8SltuX16:
146 // TBD: figure out a way to get this or remove the instruction
147 // altogether.
148 return emitFEXT_T8I816_ins(Mips::Btnez16, Mips::SltuRxRy16, MI, BB);
149 case Mips::BteqzT8CmpiX16: return emitFEXT_T8I8I16_ins(
150 Mips::Bteqz16, Mips::CmpiRxImm16, Mips::CmpiRxImmX16, false, MI, BB);
151 case Mips::BteqzT8SltiX16: return emitFEXT_T8I8I16_ins(
152 Mips::Bteqz16, Mips::SltiRxImm16, Mips::SltiRxImmX16, true, MI, BB);
153 case Mips::BteqzT8SltiuX16: return emitFEXT_T8I8I16_ins(
154 Mips::Bteqz16, Mips::SltiuRxImm16, Mips::SltiuRxImmX16, false, MI, BB);
155 case Mips::BtnezT8CmpiX16: return emitFEXT_T8I8I16_ins(
156 Mips::Btnez16, Mips::CmpiRxImm16, Mips::CmpiRxImmX16, false, MI, BB);
157 case Mips::BtnezT8SltiX16: return emitFEXT_T8I8I16_ins(
158 Mips::Btnez16, Mips::SltiRxImm16, Mips::SltiRxImmX16, true, MI, BB);
159 case Mips::BtnezT8SltiuX16: return emitFEXT_T8I8I16_ins(
160 Mips::Btnez16, Mips::SltiuRxImm16, Mips::SltiuRxImmX16, false, MI, BB);
161 break;
162 case Mips::SltCCRxRy16:
163 return emitFEXT_CCRX16_ins(Mips::SltRxRy16, MI, BB);
164 break;
165 case Mips::SltiCCRxImmX16:
166 return emitFEXT_CCRXI16_ins
167 (Mips::SltiRxImm16, Mips::SltiRxImmX16, MI, BB);
168 case Mips::SltiuCCRxImmX16:
169 return emitFEXT_CCRXI16_ins
170 (Mips::SltiuRxImm16, Mips::SltiuRxImmX16, MI, BB);
171 case Mips::SltuCCRxRy16:
172 return emitFEXT_CCRX16_ins
173 (Mips::SltuRxRy16, MI, BB);
174 }
175}
176
177bool Mips16TargetLowering::isEligibleForTailCallOptimization(
178 const CCState &CCInfo, unsigned NextStackOffset,
179 const MipsFunctionInfo &FI) const {
180 // No tail call optimization for mips16.
181 return false;
182}
183
184//
185// The Mips16 hard float is a crazy quilt inherited from gcc. I have a much
186// cleaner way to do all of this but it will have to wait until the traditional
187// gcc mechanism is completed.
188//
189// For Pic, in order for Mips16 code to call Mips32 code which according the abi
190// have either arguments or returned values placed in floating point registers,
191// we use a set of helper functions. (This includes functions which return type
192// complex which on Mips are returned in a pair of floating point registers).
193//
194// This is an encoding that we inherited from gcc.
195// In Mips traditional O32, N32 ABI, floating point numbers are passed in
196// floating point argument registers 1,2 only when the first and optionally
197// the second arguments are float (sf) or double (df).
198// For Mips16 we are only concerned with the situations where floating point
199// arguments are being passed in floating point registers by the ABI, because
200// Mips16 mode code cannot execute floating point instructions to load those
201// values and hence helper functions are needed.
202// The possibilities are (), (sf), (sf, sf), (sf, df), (df), (df, sf), (df, df)
203// the helper function suffixs for these are:
204// 0, 1, 5, 9, 2, 6, 10
205// this suffix can then be calculated as follows:
206// for a given argument Arg:
207// Arg1x, Arg2x = 1 : Arg is sf
208// 2 : Arg is df
209// 0: Arg is neither sf or df
210// So this stub is the string for number Arg1x + Arg2x*4.
211// However not all numbers between 0 and 10 are possible, we check anyway and
212// assert if the impossible exists.
213//
214
215unsigned int Mips16TargetLowering::getMips16HelperFunctionStubNumber
216 (ArgListTy &Args) const {
217 unsigned int resultNum = 0;
218 if (Args.size() >= 1) {
219 Type *t = Args[0].Ty;
220 if (t->isFloatTy()) {
221 resultNum = 1;
222 }
223 else if (t->isDoubleTy()) {
224 resultNum = 2;
225 }
226 }
227 if (resultNum) {
228 if (Args.size() >=2) {
229 Type *t = Args[1].Ty;
230 if (t->isFloatTy()) {
231 resultNum += 4;
232 }
233 else if (t->isDoubleTy()) {
234 resultNum += 8;
235 }
236 }
237 }
238 return resultNum;
239}
240
241//
242// Prefixes are attached to stub numbers depending on the return type.
243// return type: float sf_
244// double df_
245// single complex sc_
246// double complext dc_
247// others NO PREFIX
248//
249//
250// The full name of a helper function is__mips16_call_stub +
251// return type dependent prefix + stub number
252//
253// FIXME: This is something that probably should be in a different source file
254// and perhaps done differently but my main purpose is to not waste runtime
255// on something that we can enumerate in the source. Another possibility is
256// to have a python script to generate these mapping tables. This will do
257// for now. There are a whole series of helper function mapping arrays, one
258// for each return type class as outlined above. There there are 11 possible
259// entries. Ones with 0 are ones which should never be selected.
260//
261// All the arrays are similar except for ones which return neither
262// sf, df, sc, dc, in which we only care about ones which have sf or df as a
263// first parameter.
264//
265#define P_ "__mips16_call_stub_"
266#define MAX_STUB_NUMBER 10
267#define T1 P "1", P "2", 0, 0, P "5", P "6", 0, 0, P "9", P "10"
268#define T P "0" , T1
269#define P P_
270static char const * vMips16Helper[MAX_STUB_NUMBER+1] =
271 {nullptr, T1 };
272#undef P
273#define P P_ "sf_"
274static char const * sfMips16Helper[MAX_STUB_NUMBER+1] =
275 { T };
276#undef P
277#define P P_ "df_"
278static char const * dfMips16Helper[MAX_STUB_NUMBER+1] =
279 { T };
280#undef P
281#define P P_ "sc_"
282static char const * scMips16Helper[MAX_STUB_NUMBER+1] =
283 { T };
284#undef P
285#define P P_ "dc_"
286static char const * dcMips16Helper[MAX_STUB_NUMBER+1] =
287 { T };
288#undef P
289#undef P_
290
291
292const char* Mips16TargetLowering::
293 getMips16HelperFunction
294 (Type* RetTy, ArgListTy &Args, bool &needHelper) const {
295 const unsigned int stubNum = getMips16HelperFunctionStubNumber(Args);
296#ifndef NDEBUG
297 const unsigned int maxStubNum = 10;
298 assert(stubNum <= maxStubNum);
299 const bool validStubNum[maxStubNum+1] =
300 {true, true, true, false, false, true, true, false, false, true, true};
301 assert(validStubNum[stubNum]);
302#endif
303 const char *result;
304 if (RetTy->isFloatTy()) {
305 result = sfMips16Helper[stubNum];
306 }
307 else if (RetTy ->isDoubleTy()) {
308 result = dfMips16Helper[stubNum];
309 } else if (StructType *SRetTy = dyn_cast<StructType>(RetTy)) {
310 // check if it's complex
311 if (SRetTy->getNumElements() == 2) {
312 if ((SRetTy->getElementType(0)->isFloatTy()) &&
313 (SRetTy->getElementType(1)->isFloatTy())) {
314 result = scMips16Helper[stubNum];
315 } else if ((SRetTy->getElementType(0)->isDoubleTy()) &&
316 (SRetTy->getElementType(1)->isDoubleTy())) {
317 result = dcMips16Helper[stubNum];
318 } else {
319 llvm_unreachable("Uncovered condition");
320 }
321 } else {
322 llvm_unreachable("Uncovered condition");
323 }
324 } else {
325 if (stubNum == 0) {
326 needHelper = false;
327 return "";
328 }
329 result = vMips16Helper[stubNum];
330 }
331 needHelper = true;
332 return result;
333}
334
336 // FIXME: Use getSupportedLibcallImpl instead of blindly parsing the name.
337 iota_range<RTLIB::LibcallImpl> ParsedLibcalls =
339 return !ParsedLibcalls.empty() &&
341 *ParsedLibcalls.begin());
342}
343
344void Mips16TargetLowering::getOpndList(
346 std::deque<std::pair<unsigned, SDValue>> &RegsToPass, bool IsPICCall,
347 bool GlobalOrExternal, bool LocalLinkage, bool IsCallReloc,
348 CallLoweringInfo &CLI, SDValue Callee, SDValue Chain) const {
349 SelectionDAG &DAG = CLI.DAG;
351 MipsFunctionInfo *FuncInfo = MF.getInfo<MipsFunctionInfo>();
352 const char* Mips16HelperFunction = nullptr;
353 bool NeedMips16Helper = false;
354
355 if (Subtarget.inMips16HardFloat()) {
356 //
357 // currently we don't have symbols tagged with the mips16 or mips32
358 // qualifier so we will assume that we don't know what kind it is.
359 // and generate the helper
360 //
361 bool LookupHelper = true;
362 if (ExternalSymbolSDNode *S = dyn_cast<ExternalSymbolSDNode>(CLI.Callee)) {
363 if (isMips16HardFloatLibcall(S->getSymbol()))
364 LookupHelper = false;
365 else {
366 const char *Symbol = S->getSymbol();
367 Mips16IntrinsicHelperType IntrinsicFind = { Symbol, "" };
368 const Mips16HardFloatInfo::FuncSignature *Signature =
370 if (!IsPICCall && Signature &&
371 FuncInfo->StubsNeeded.try_emplace(Symbol, Signature).second) {
372 //
373 // S2 is normally saved if the stub is for a function which
374 // returns a float or double value and is not otherwise. This is
375 // because more work is required after the function the stub
376 // is calling completes, and so the stub cannot directly return
377 // and the stub has no stack space to store the return address so
378 // S2 is used for that purpose.
379 // In order to take advantage of not saving S2, we need to also
380 // optimize the call in the stub and this requires some further
381 // functionality in MipsAsmPrinter which we don't have yet.
382 // So for now we always save S2. The optimization will be done
383 // in a follow-on patch.
384 //
385 if (true || (Signature->RetSig != Mips16HardFloatInfo::NoFPRet))
386 FuncInfo->setSaveS2();
387 }
388 // one more look at list of intrinsics
389 const Mips16IntrinsicHelperType *Helper =
391 if (Helper != std::end(Mips16IntrinsicHelper) &&
392 *Helper == IntrinsicFind) {
393 Mips16HelperFunction = Helper->Helper;
394 NeedMips16Helper = true;
395 LookupHelper = false;
396 }
397
398 }
399 } else if (GlobalAddressSDNode *G =
400 dyn_cast<GlobalAddressSDNode>(CLI.Callee)) {
401
402 if (isMips16HardFloatLibcall(G->getGlobal()->getName()))
403 LookupHelper = false;
404 }
405 if (LookupHelper)
406 Mips16HelperFunction =
407 getMips16HelperFunction(CLI.RetTy, CLI.getArgs(), NeedMips16Helper);
408 }
409
410 SDValue JumpTarget = Callee;
411
412 // T9 should contain the address of the callee function if
413 // -relocation-model=pic or it is an indirect call.
414 if (IsPICCall || !GlobalOrExternal) {
415 unsigned V0Reg = Mips::R2;
416 if (NeedMips16Helper) {
417 RegsToPass.push_front(std::make_pair(V0Reg, Callee));
418 JumpTarget = DAG.getExternalSymbol(Mips16HelperFunction,
420 ExternalSymbolSDNode *S = cast<ExternalSymbolSDNode>(JumpTarget);
421 JumpTarget = getAddrGlobal(S, CLI.DL, JumpTarget.getValueType(), DAG,
422 MipsII::MO_GOT, Chain,
423 FuncInfo->callPtrInfo(MF, S->getSymbol()));
424 } else
425 RegsToPass.push_front(std::make_pair((unsigned)Mips::R25, Callee));
426 }
427
428 Ops.push_back(JumpTarget);
429
430 MipsTargetLowering::getOpndList(Ops, RegsToPass, IsPICCall, GlobalOrExternal,
431 LocalLinkage, IsCallReloc, CLI, Callee,
432 Chain);
433}
434
436Mips16TargetLowering::emitSel16(unsigned Opc, MachineInstr &MI,
437 MachineBasicBlock *BB) const {
438 if (Subtarget.getCLOpts().mips16_dont_expand_cond_pseudo)
439 return BB;
440 const TargetInstrInfo *TII = Subtarget.getInstrInfo();
441 DebugLoc DL = MI.getDebugLoc();
442 // To "insert" a SELECT_CC instruction, we actually have to insert the
443 // diamond control-flow pattern. The incoming instruction knows the
444 // destination vreg to set, the condition code register to branch on, the
445 // true/false values to select between, and a branch opcode to use.
446 const BasicBlock *LLVM_BB = BB->getBasicBlock();
448
449 // thisMBB:
450 // ...
451 // TrueVal = ...
452 // setcc r1, r2, r3
453 // bNE r1, r0, copy1MBB
454 // fallthrough --> copy0MBB
455 MachineBasicBlock *thisMBB = BB;
456 MachineFunction *F = BB->getParent();
457 MachineBasicBlock *copy0MBB = F->CreateMachineBasicBlock(LLVM_BB);
458 MachineBasicBlock *sinkMBB = F->CreateMachineBasicBlock(LLVM_BB);
459 F->insert(It, copy0MBB);
460 F->insert(It, sinkMBB);
461
462 // Transfer the remainder of BB and its successor edges to sinkMBB.
463 sinkMBB->splice(sinkMBB->begin(), BB,
464 std::next(MachineBasicBlock::iterator(MI)), BB->end());
466
467 // Next, add the true and fallthrough blocks as its successors.
468 BB->addSuccessor(copy0MBB);
469 BB->addSuccessor(sinkMBB);
470
471 BuildMI(BB, DL, TII->get(Opc))
472 .addReg(MI.getOperand(3).getReg())
473 .addMBB(sinkMBB);
474
475 // copy0MBB:
476 // %FalseValue = ...
477 // # fallthrough to sinkMBB
478 BB = copy0MBB;
479
480 // Update machine-CFG edges
481 BB->addSuccessor(sinkMBB);
482
483 // sinkMBB:
484 // %Result = phi [ %TrueValue, thisMBB ], [ %FalseValue, copy0MBB ]
485 // ...
486 BB = sinkMBB;
487
488 BuildMI(*BB, BB->begin(), DL, TII->get(Mips::PHI), MI.getOperand(0).getReg())
489 .addReg(MI.getOperand(1).getReg())
490 .addMBB(thisMBB)
491 .addReg(MI.getOperand(2).getReg())
492 .addMBB(copy0MBB);
493
494 MI.eraseFromParent(); // The pseudo instruction is gone now.
495 return BB;
496}
497
499Mips16TargetLowering::emitSelT16(unsigned Opc1, unsigned Opc2, MachineInstr &MI,
500 MachineBasicBlock *BB) const {
501 if (Subtarget.getCLOpts().mips16_dont_expand_cond_pseudo)
502 return BB;
503 const TargetInstrInfo *TII = Subtarget.getInstrInfo();
504 DebugLoc DL = MI.getDebugLoc();
505 // To "insert" a SELECT_CC instruction, we actually have to insert the
506 // diamond control-flow pattern. The incoming instruction knows the
507 // destination vreg to set, the condition code register to branch on, the
508 // true/false values to select between, and a branch opcode to use.
509 const BasicBlock *LLVM_BB = BB->getBasicBlock();
511
512 // thisMBB:
513 // ...
514 // TrueVal = ...
515 // setcc r1, r2, r3
516 // bNE r1, r0, copy1MBB
517 // fallthrough --> copy0MBB
518 MachineBasicBlock *thisMBB = BB;
519 MachineFunction *F = BB->getParent();
520 MachineBasicBlock *copy0MBB = F->CreateMachineBasicBlock(LLVM_BB);
521 MachineBasicBlock *sinkMBB = F->CreateMachineBasicBlock(LLVM_BB);
522 F->insert(It, copy0MBB);
523 F->insert(It, sinkMBB);
524
525 // Transfer the remainder of BB and its successor edges to sinkMBB.
526 sinkMBB->splice(sinkMBB->begin(), BB,
527 std::next(MachineBasicBlock::iterator(MI)), BB->end());
529
530 // Next, add the true and fallthrough blocks as its successors.
531 BB->addSuccessor(copy0MBB);
532 BB->addSuccessor(sinkMBB);
533
534 BuildMI(BB, DL, TII->get(Opc2))
535 .addReg(MI.getOperand(3).getReg())
536 .addReg(MI.getOperand(4).getReg());
537 BuildMI(BB, DL, TII->get(Opc1)).addMBB(sinkMBB);
538
539 // copy0MBB:
540 // %FalseValue = ...
541 // # fallthrough to sinkMBB
542 BB = copy0MBB;
543
544 // Update machine-CFG edges
545 BB->addSuccessor(sinkMBB);
546
547 // sinkMBB:
548 // %Result = phi [ %TrueValue, thisMBB ], [ %FalseValue, copy0MBB ]
549 // ...
550 BB = sinkMBB;
551
552 BuildMI(*BB, BB->begin(), DL, TII->get(Mips::PHI), MI.getOperand(0).getReg())
553 .addReg(MI.getOperand(1).getReg())
554 .addMBB(thisMBB)
555 .addReg(MI.getOperand(2).getReg())
556 .addMBB(copy0MBB);
557
558 MI.eraseFromParent(); // The pseudo instruction is gone now.
559 return BB;
560
561}
562
564Mips16TargetLowering::emitSeliT16(unsigned Opc1, unsigned Opc2,
566 MachineBasicBlock *BB) const {
567 if (Subtarget.getCLOpts().mips16_dont_expand_cond_pseudo)
568 return BB;
569 const TargetInstrInfo *TII = Subtarget.getInstrInfo();
570 DebugLoc DL = MI.getDebugLoc();
571 // To "insert" a SELECT_CC instruction, we actually have to insert the
572 // diamond control-flow pattern. The incoming instruction knows the
573 // destination vreg to set, the condition code register to branch on, the
574 // true/false values to select between, and a branch opcode to use.
575 const BasicBlock *LLVM_BB = BB->getBasicBlock();
577
578 // thisMBB:
579 // ...
580 // TrueVal = ...
581 // setcc r1, r2, r3
582 // bNE r1, r0, copy1MBB
583 // fallthrough --> copy0MBB
584 MachineBasicBlock *thisMBB = BB;
585 MachineFunction *F = BB->getParent();
586 MachineBasicBlock *copy0MBB = F->CreateMachineBasicBlock(LLVM_BB);
587 MachineBasicBlock *sinkMBB = F->CreateMachineBasicBlock(LLVM_BB);
588 F->insert(It, copy0MBB);
589 F->insert(It, sinkMBB);
590
591 // Transfer the remainder of BB and its successor edges to sinkMBB.
592 sinkMBB->splice(sinkMBB->begin(), BB,
593 std::next(MachineBasicBlock::iterator(MI)), BB->end());
595
596 // Next, add the true and fallthrough blocks as its successors.
597 BB->addSuccessor(copy0MBB);
598 BB->addSuccessor(sinkMBB);
599
600 BuildMI(BB, DL, TII->get(Opc2))
601 .addReg(MI.getOperand(3).getReg())
602 .addImm(MI.getOperand(4).getImm());
603 BuildMI(BB, DL, TII->get(Opc1)).addMBB(sinkMBB);
604
605 // copy0MBB:
606 // %FalseValue = ...
607 // # fallthrough to sinkMBB
608 BB = copy0MBB;
609
610 // Update machine-CFG edges
611 BB->addSuccessor(sinkMBB);
612
613 // sinkMBB:
614 // %Result = phi [ %TrueValue, thisMBB ], [ %FalseValue, copy0MBB ]
615 // ...
616 BB = sinkMBB;
617
618 BuildMI(*BB, BB->begin(), DL, TII->get(Mips::PHI), MI.getOperand(0).getReg())
619 .addReg(MI.getOperand(1).getReg())
620 .addMBB(thisMBB)
621 .addReg(MI.getOperand(2).getReg())
622 .addMBB(copy0MBB);
623
624 MI.eraseFromParent(); // The pseudo instruction is gone now.
625 return BB;
626
627}
628
630Mips16TargetLowering::emitFEXT_T8I816_ins(unsigned BtOpc, unsigned CmpOpc,
632 MachineBasicBlock *BB) const {
633 if (Subtarget.getCLOpts().mips16_dont_expand_cond_pseudo)
634 return BB;
635 const TargetInstrInfo *TII = Subtarget.getInstrInfo();
636 Register regX = MI.getOperand(0).getReg();
637 Register regY = MI.getOperand(1).getReg();
638 MachineBasicBlock *target = MI.getOperand(2).getMBB();
639 BuildMI(*BB, MI, MI.getDebugLoc(), TII->get(CmpOpc))
640 .addReg(regX)
641 .addReg(regY);
642 BuildMI(*BB, MI, MI.getDebugLoc(), TII->get(BtOpc)).addMBB(target);
643 MI.eraseFromParent(); // The pseudo instruction is gone now.
644 return BB;
645}
646
647MachineBasicBlock *Mips16TargetLowering::emitFEXT_T8I8I16_ins(
648 unsigned BtOpc, unsigned CmpiOpc, unsigned CmpiXOpc, bool ImmSigned,
649 MachineInstr &MI, MachineBasicBlock *BB) const {
650 if (Subtarget.getCLOpts().mips16_dont_expand_cond_pseudo)
651 return BB;
652 const TargetInstrInfo *TII = Subtarget.getInstrInfo();
653 Register regX = MI.getOperand(0).getReg();
654 int64_t imm = MI.getOperand(1).getImm();
655 MachineBasicBlock *target = MI.getOperand(2).getMBB();
656 unsigned CmpOpc;
657 if (isUInt<8>(imm))
658 CmpOpc = CmpiOpc;
659 else if ((!ImmSigned && isUInt<16>(imm)) ||
660 (ImmSigned && isInt<16>(imm)))
661 CmpOpc = CmpiXOpc;
662 else
663 llvm_unreachable("immediate field not usable");
664 BuildMI(*BB, MI, MI.getDebugLoc(), TII->get(CmpOpc)).addReg(regX).addImm(imm);
665 BuildMI(*BB, MI, MI.getDebugLoc(), TII->get(BtOpc)).addMBB(target);
666 MI.eraseFromParent(); // The pseudo instruction is gone now.
667 return BB;
668}
669
671 (unsigned shortOp, unsigned longOp, int64_t Imm) {
672 if (isUInt<8>(Imm))
673 return shortOp;
674 else if (isInt<16>(Imm))
675 return longOp;
676 else
677 llvm_unreachable("immediate field not usable");
678}
679
681Mips16TargetLowering::emitFEXT_CCRX16_ins(unsigned SltOpc, MachineInstr &MI,
682 MachineBasicBlock *BB) const {
683 if (Subtarget.getCLOpts().mips16_dont_expand_cond_pseudo)
684 return BB;
685 const TargetInstrInfo *TII = Subtarget.getInstrInfo();
686 Register CC = MI.getOperand(0).getReg();
687 Register regX = MI.getOperand(1).getReg();
688 Register regY = MI.getOperand(2).getReg();
689 BuildMI(*BB, MI, MI.getDebugLoc(), TII->get(SltOpc))
690 .addReg(regX)
691 .addReg(regY);
692 BuildMI(*BB, MI, MI.getDebugLoc(), TII->get(Mips::MoveR3216), CC)
693 .addReg(Mips::R24);
694 MI.eraseFromParent(); // The pseudo instruction is gone now.
695 return BB;
696}
697
699Mips16TargetLowering::emitFEXT_CCRXI16_ins(unsigned SltiOpc, unsigned SltiXOpc,
701 MachineBasicBlock *BB) const {
702 if (Subtarget.getCLOpts().mips16_dont_expand_cond_pseudo)
703 return BB;
704 const TargetInstrInfo *TII = Subtarget.getInstrInfo();
705 Register CC = MI.getOperand(0).getReg();
706 Register regX = MI.getOperand(1).getReg();
707 int64_t Imm = MI.getOperand(2).getImm();
708 unsigned SltOpc = Mips16WhichOp8uOr16simm(SltiOpc, SltiXOpc, Imm);
709 BuildMI(*BB, MI, MI.getDebugLoc(), TII->get(SltOpc)).addReg(regX).addImm(Imm);
710 BuildMI(*BB, MI, MI.getDebugLoc(), TII->get(Mips::MoveR3216), CC)
711 .addReg(Mips::R24);
712 MI.eraseFromParent(); // The pseudo instruction is gone now.
713 return BB;
714
715}
return SDValue()
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
uint64_t Imm
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
const HexagonInstrInfo * TII
IRTranslator LLVM IR MI
const AbstractManglingParser< Derived, Alloc >::OperatorInfo AbstractManglingParser< Derived, Alloc >::Ops[]
#define F(x, y, z)
Definition MD5.cpp:54
#define G(x, y, z)
Definition MD5.cpp:55
Promote Memory to Register
Definition Mem2Reg.cpp:110
static char const * vMips16Helper[MAX_STUB_NUMBER+1]
#define T
static char const * dcMips16Helper[MAX_STUB_NUMBER+1]
static char const * dfMips16Helper[MAX_STUB_NUMBER+1]
static const Mips16IntrinsicHelperType Mips16IntrinsicHelper[]
#define MAX_STUB_NUMBER
static char const * sfMips16Helper[MAX_STUB_NUMBER+1]
#define T1
static unsigned Mips16WhichOp8uOr16simm(unsigned shortOp, unsigned longOp, int64_t Imm)
static char const * scMips16Helper[MAX_STUB_NUMBER+1]
static bool isMips16HardFloatLibcall(StringRef Name)
RISCVCC::CondCode CC
Value * RHS
CCState - This class holds information needed while lowering arguments and return values.
const char * getSymbol() const
LLVM_ABI void transferSuccessorsAndUpdatePHIs(MachineBasicBlock *FromMBB)
Transfers all the successors, as in transferSuccessors, and update PHI operands in the successor bloc...
LLVM_ABI instr_iterator insert(instr_iterator I, MachineInstr *M)
Insert MI into the instruction list before I, possibly inside a bundle.
const BasicBlock * getBasicBlock() const
Return the LLVM basic block that this instance corresponded to originally.
LLVM_ABI void addSuccessor(MachineBasicBlock *Succ, BranchProbability Prob=BranchProbability::getUnknown())
Add Succ as a successor of this MachineBasicBlock.
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
void splice(iterator Where, MachineBasicBlock *Other, iterator From)
Take an instruction from MBB 'Other' at the position From, and insert it into this MBB right before '...
MachineInstrBundleIterator< MachineInstr > iterator
BasicBlockListType::iterator iterator
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
MachineBasicBlock * CreateMachineBasicBlock(const BasicBlock *BB=nullptr, std::optional< UniqueBBID > BBID=std::nullopt)
CreateMachineInstr - Allocate a new MachineInstr.
const MachineInstrBuilder & addReg(Register RegNo, RegState Flags={}, unsigned SubReg=0) const
Add a new virtual register operand.
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
const MachineInstrBuilder & addMBB(MachineBasicBlock *MBB, unsigned TargetFlags=0) const
Representation of each machine instruction.
Flags
Flags values. These may be or'd together.
MachineBasicBlock * EmitInstrWithCustomInserter(MachineInstr &MI, MachineBasicBlock *MBB) const override
This method should be implemented by targets that mark instructions with the 'usesCustomInserter' fla...
Mips16TargetLowering(const MipsTargetMachine &TM, const MipsSubtarget &STI)
bool allowsMisalignedMemoryAccesses(EVT VT, unsigned AddrSpace, Align Alignment, MachineMemOperand::Flags Flags, unsigned *Fast) const override
Determine if the target supports unaligned memory accesses.
MipsFunctionInfo - This class is derived from MachineFunction private Mips target-specific informatio...
MachinePointerInfo callPtrInfo(MachineFunction &MF, const char *ES)
Create a MachinePointerInfo that has an ExternalSymbolPseudoSourceValue object representing a GOT ent...
std::map< const char *, const Mips16HardFloatInfo::FuncSignature * > StubsNeeded
const MipsRegisterInfo * getRegisterInfo() const override
static const RTLIB::LibcallImpl HardFloatLibCalls[34]
SDValue getAddrGlobal(NodeTy *N, const SDLoc &DL, EVT Ty, SelectionDAG &DAG, unsigned Flag, SDValue Chain, const MachinePointerInfo &PtrInfo) const
MipsTargetLowering(const MipsTargetMachine &TM, const MipsSubtarget &STI)
MachineBasicBlock * EmitInstrWithCustomInserter(MachineInstr &MI, MachineBasicBlock *MBB) const override
This method should be implemented by targets that mark instructions with the 'usesCustomInserter' fla...
virtual void getOpndList(SmallVectorImpl< SDValue > &Ops, std::deque< std::pair< unsigned, SDValue > > &RegsToPass, bool IsPICCall, bool GlobalOrExternal, bool LocalLinkage, bool IsCallReloc, CallLoweringInfo &CLI, SDValue Callee, SDValue Chain) const
This function fills Ops, which is the list of operands that will later be used when a function call n...
const MipsSubtarget & Subtarget
Unlike LLVM values, Selection DAG nodes may return multiple values as the result of a computation.
EVT getValueType() const
Return the ValueType of the referenced return value.
const DataLayout & getDataLayout() const
LLVM_ABI SDValue getExternalSymbol(const char *Sym, EVT VT)
MachineFunction & getMachineFunction() const
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
void setOperationAction(unsigned Op, MVT VT, LegalizeAction Action)
Indicate that the specified operation does not work with the specified type and indicate what to do a...
void computeRegisterProperties(const TargetRegisterInfo *TRI)
Once all of the register classes are added, this allows us to compute derived properties we expose.
void addRegisterClass(MVT VT, const TargetRegisterClass *RC)
Add the specified register class as an available regclass for the specified value type.
virtual MVT getPointerTy(const DataLayout &DL, uint32_t AS=0) const
Return the pointer type for the given address space, defaults to the pointer type from the data layou...
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
bool isFloatTy() const
Return true if this is 'float', a 32-bit IEEE fp type.
Definition Type.h:155
bool isDoubleTy() const
Return true if this is 'double', a 64-bit IEEE fp type.
Definition Type.h:158
self_iterator getIterator()
Definition ilist_node.h:123
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
@ BSWAP
Byte Swap and Counting operators.
Definition ISDOpcodes.h:811
@ ATOMIC_FENCE
OUTCHAIN = ATOMIC_FENCE(INCHAIN, ordering, scope) This corresponds to the fence instruction.
@ BasicBlock
Various leaf nodes.
Definition ISDOpcodes.h:83
@ ATOMIC_CMP_SWAP
Val, OUTCHAIN = ATOMIC_CMP_SWAP(INCHAIN, ptr, cmp, swap) For double-word atomic operations: ValLo,...
@ ATOMIC_SWAP
Val, OUTCHAIN = ATOMIC_SWAP(INCHAIN, ptr, amt) Val, OUTCHAIN = ATOMIC_LOAD_[OpName](INCHAIN,...
FuncSignature const * findFuncSignature(const char *name)
This is an optimization pass for GlobalISel generic memory operations.
bool operator<(int64_t V1, const APSInt &V2)
Definition APSInt.h:360
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
constexpr bool isInt(int64_t x)
Checks if an integer fits into the given bit width.
Definition MathExtras.h:166
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
auto binary_search(R &&Range, T &&Value)
Provide wrappers to std::binary_search which take ranges instead of having to pass begin/end explicit...
Definition STLExtras.h:2055
bool operator==(const AddressRangeValuePair &LHS, const AddressRangeValuePair &RHS)
constexpr bool isUInt(uint64_t x)
Checks if an unsigned integer fits into the given bit width.
Definition MathExtras.h:190
const MipsTargetLowering * createMips16TargetLowering(const MipsTargetMachine &TM, const MipsSubtarget &STI)
Create MipsTargetLowering objects.
auto lower_bound(R &&Range, T &&Value)
Provide wrappers to std::lower_bound which take ranges instead of having to pass begin/end explicitly...
Definition STLExtras.h:2068
@ Fast
Assign the register banks as fast as possible (default).
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition Alignment.h:39
Extended Value Type.
Definition ValueTypes.h:35
static iota_range< RTLIB::LibcallImpl > lookupLibcallImplName(StringRef Name)
Check if a function name is a recognized runtime call of any kind.
constexpr auto begin() const
Definition Sequence.h:317
constexpr bool empty() const
Definition Sequence.h:315