LLVM 22.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"
21
22using namespace llvm;
23
24#define DEBUG_TYPE "mips-lower"
25
27 "mips16-dont-expand-cond-pseudo",
28 cl::init(false),
29 cl::desc("Don't expand conditional move related "
30 "pseudos for Mips 16"),
32
33namespace {
34struct Mips16IntrinsicHelperType{
35 const char* Name;
36 const char* Helper;
37
38 bool operator<(const Mips16IntrinsicHelperType &RHS) const {
39 return std::strcmp(Name, RHS.Name) < 0;
40 }
41 bool operator==(const Mips16IntrinsicHelperType &RHS) const {
42 return std::strcmp(Name, RHS.Name) == 0;
43 }
44};
45} // namespace
46
47static const Mips16IntrinsicHelperType Mips16IntrinsicHelper[] = {
48 {"__fixunsdfsi", "__mips16_call_stub_2" },
49 {"ceil", "__mips16_call_stub_df_2"},
50 {"ceilf", "__mips16_call_stub_sf_1"},
51 {"copysign", "__mips16_call_stub_df_10"},
52 {"copysignf", "__mips16_call_stub_sf_5"},
53 {"cos", "__mips16_call_stub_df_2"},
54 {"cosf", "__mips16_call_stub_sf_1"},
55 {"exp2", "__mips16_call_stub_df_2"},
56 {"exp2f", "__mips16_call_stub_sf_1"},
57 {"floor", "__mips16_call_stub_df_2"},
58 {"floorf", "__mips16_call_stub_sf_1"},
59 {"log2", "__mips16_call_stub_df_2"},
60 {"log2f", "__mips16_call_stub_sf_1"},
61 {"nearbyint", "__mips16_call_stub_df_2"},
62 {"nearbyintf", "__mips16_call_stub_sf_1"},
63 {"rint", "__mips16_call_stub_df_2"},
64 {"rintf", "__mips16_call_stub_sf_1"},
65 {"sin", "__mips16_call_stub_df_2"},
66 {"sinf", "__mips16_call_stub_sf_1"},
67 {"sqrt", "__mips16_call_stub_df_2"},
68 {"sqrtf", "__mips16_call_stub_sf_1"},
69 {"trunc", "__mips16_call_stub_df_2"},
70 {"truncf", "__mips16_call_stub_sf_1"},
71};
72
74 const MipsSubtarget &STI)
75 : MipsTargetLowering(TM, STI) {
76
77 // Set up the register classes
78 addRegisterClass(MVT::i32, &Mips::CPU16RegsRegClass);
79
80 setOperationAction(ISD::ATOMIC_FENCE, MVT::Other, LibCall);
81 setOperationAction(ISD::ATOMIC_CMP_SWAP, MVT::i32, LibCall);
82 setOperationAction(ISD::ATOMIC_SWAP, MVT::i32, LibCall);
83 setOperationAction(ISD::ATOMIC_LOAD_ADD, MVT::i32, LibCall);
84 setOperationAction(ISD::ATOMIC_LOAD_SUB, MVT::i32, LibCall);
85 setOperationAction(ISD::ATOMIC_LOAD_AND, MVT::i32, LibCall);
86 setOperationAction(ISD::ATOMIC_LOAD_OR, MVT::i32, LibCall);
87 setOperationAction(ISD::ATOMIC_LOAD_XOR, MVT::i32, LibCall);
88 setOperationAction(ISD::ATOMIC_LOAD_NAND, MVT::i32, LibCall);
89 setOperationAction(ISD::ATOMIC_LOAD_MIN, MVT::i32, LibCall);
90 setOperationAction(ISD::ATOMIC_LOAD_MAX, MVT::i32, LibCall);
91 setOperationAction(ISD::ATOMIC_LOAD_UMIN, MVT::i32, LibCall);
92 setOperationAction(ISD::ATOMIC_LOAD_UMAX, MVT::i32, LibCall);
93
98
100}
101
102const MipsTargetLowering *
104 const MipsSubtarget &STI) {
105 return new Mips16TargetLowering(TM, STI);
106}
107
109 EVT VT, unsigned, Align, MachineMemOperand::Flags, unsigned *Fast) const {
110 return false;
111}
112
115 MachineBasicBlock *BB) const {
116 switch (MI.getOpcode()) {
117 default:
119 case Mips::SelBeqZ:
120 return emitSel16(Mips::BeqzRxImm16, MI, BB);
121 case Mips::SelBneZ:
122 return emitSel16(Mips::BnezRxImm16, MI, BB);
123 case Mips::SelTBteqZCmpi:
124 return emitSeliT16(Mips::Bteqz16, Mips::CmpiRxImmX16, MI, BB);
125 case Mips::SelTBteqZSlti:
126 return emitSeliT16(Mips::Bteqz16, Mips::SltiRxImmX16, MI, BB);
127 case Mips::SelTBteqZSltiu:
128 return emitSeliT16(Mips::Bteqz16, Mips::SltiuRxImmX16, MI, BB);
129 case Mips::SelTBtneZCmpi:
130 return emitSeliT16(Mips::Btnez16, Mips::CmpiRxImmX16, MI, BB);
131 case Mips::SelTBtneZSlti:
132 return emitSeliT16(Mips::Btnez16, Mips::SltiRxImmX16, MI, BB);
133 case Mips::SelTBtneZSltiu:
134 return emitSeliT16(Mips::Btnez16, Mips::SltiuRxImmX16, MI, BB);
135 case Mips::SelTBteqZCmp:
136 return emitSelT16(Mips::Bteqz16, Mips::CmpRxRy16, MI, BB);
137 case Mips::SelTBteqZSlt:
138 return emitSelT16(Mips::Bteqz16, Mips::SltRxRy16, MI, BB);
139 case Mips::SelTBteqZSltu:
140 return emitSelT16(Mips::Bteqz16, Mips::SltuRxRy16, MI, BB);
141 case Mips::SelTBtneZCmp:
142 return emitSelT16(Mips::Btnez16, Mips::CmpRxRy16, MI, BB);
143 case Mips::SelTBtneZSlt:
144 return emitSelT16(Mips::Btnez16, Mips::SltRxRy16, MI, BB);
145 case Mips::SelTBtneZSltu:
146 return emitSelT16(Mips::Btnez16, Mips::SltuRxRy16, MI, BB);
147 case Mips::BteqzT8CmpX16:
148 return emitFEXT_T8I816_ins(Mips::Bteqz16, Mips::CmpRxRy16, MI, BB);
149 case Mips::BteqzT8SltX16:
150 return emitFEXT_T8I816_ins(Mips::Bteqz16, Mips::SltRxRy16, MI, BB);
151 case Mips::BteqzT8SltuX16:
152 // TBD: figure out a way to get this or remove the instruction
153 // altogether.
154 return emitFEXT_T8I816_ins(Mips::Bteqz16, Mips::SltuRxRy16, MI, BB);
155 case Mips::BtnezT8CmpX16:
156 return emitFEXT_T8I816_ins(Mips::Btnez16, Mips::CmpRxRy16, MI, BB);
157 case Mips::BtnezT8SltX16:
158 return emitFEXT_T8I816_ins(Mips::Btnez16, Mips::SltRxRy16, MI, BB);
159 case Mips::BtnezT8SltuX16:
160 // TBD: figure out a way to get this or remove the instruction
161 // altogether.
162 return emitFEXT_T8I816_ins(Mips::Btnez16, Mips::SltuRxRy16, MI, BB);
163 case Mips::BteqzT8CmpiX16: return emitFEXT_T8I8I16_ins(
164 Mips::Bteqz16, Mips::CmpiRxImm16, Mips::CmpiRxImmX16, false, MI, BB);
165 case Mips::BteqzT8SltiX16: return emitFEXT_T8I8I16_ins(
166 Mips::Bteqz16, Mips::SltiRxImm16, Mips::SltiRxImmX16, true, MI, BB);
167 case Mips::BteqzT8SltiuX16: return emitFEXT_T8I8I16_ins(
168 Mips::Bteqz16, Mips::SltiuRxImm16, Mips::SltiuRxImmX16, false, MI, BB);
169 case Mips::BtnezT8CmpiX16: return emitFEXT_T8I8I16_ins(
170 Mips::Btnez16, Mips::CmpiRxImm16, Mips::CmpiRxImmX16, false, MI, BB);
171 case Mips::BtnezT8SltiX16: return emitFEXT_T8I8I16_ins(
172 Mips::Btnez16, Mips::SltiRxImm16, Mips::SltiRxImmX16, true, MI, BB);
173 case Mips::BtnezT8SltiuX16: return emitFEXT_T8I8I16_ins(
174 Mips::Btnez16, Mips::SltiuRxImm16, Mips::SltiuRxImmX16, false, MI, BB);
175 break;
176 case Mips::SltCCRxRy16:
177 return emitFEXT_CCRX16_ins(Mips::SltRxRy16, MI, BB);
178 break;
179 case Mips::SltiCCRxImmX16:
180 return emitFEXT_CCRXI16_ins
181 (Mips::SltiRxImm16, Mips::SltiRxImmX16, MI, BB);
182 case Mips::SltiuCCRxImmX16:
183 return emitFEXT_CCRXI16_ins
184 (Mips::SltiuRxImm16, Mips::SltiuRxImmX16, MI, BB);
185 case Mips::SltuCCRxRy16:
186 return emitFEXT_CCRX16_ins
187 (Mips::SltuRxRy16, MI, BB);
188 }
189}
190
191bool Mips16TargetLowering::isEligibleForTailCallOptimization(
192 const CCState &CCInfo, unsigned NextStackOffset,
193 const MipsFunctionInfo &FI) const {
194 // No tail call optimization for mips16.
195 return false;
196}
197
198//
199// The Mips16 hard float is a crazy quilt inherited from gcc. I have a much
200// cleaner way to do all of this but it will have to wait until the traditional
201// gcc mechanism is completed.
202//
203// For Pic, in order for Mips16 code to call Mips32 code which according the abi
204// have either arguments or returned values placed in floating point registers,
205// we use a set of helper functions. (This includes functions which return type
206// complex which on Mips are returned in a pair of floating point registers).
207//
208// This is an encoding that we inherited from gcc.
209// In Mips traditional O32, N32 ABI, floating point numbers are passed in
210// floating point argument registers 1,2 only when the first and optionally
211// the second arguments are float (sf) or double (df).
212// For Mips16 we are only concerned with the situations where floating point
213// arguments are being passed in floating point registers by the ABI, because
214// Mips16 mode code cannot execute floating point instructions to load those
215// values and hence helper functions are needed.
216// The possibilities are (), (sf), (sf, sf), (sf, df), (df), (df, sf), (df, df)
217// the helper function suffixs for these are:
218// 0, 1, 5, 9, 2, 6, 10
219// this suffix can then be calculated as follows:
220// for a given argument Arg:
221// Arg1x, Arg2x = 1 : Arg is sf
222// 2 : Arg is df
223// 0: Arg is neither sf or df
224// So this stub is the string for number Arg1x + Arg2x*4.
225// However not all numbers between 0 and 10 are possible, we check anyway and
226// assert if the impossible exists.
227//
228
229unsigned int Mips16TargetLowering::getMips16HelperFunctionStubNumber
230 (ArgListTy &Args) const {
231 unsigned int resultNum = 0;
232 if (Args.size() >= 1) {
233 Type *t = Args[0].Ty;
234 if (t->isFloatTy()) {
235 resultNum = 1;
236 }
237 else if (t->isDoubleTy()) {
238 resultNum = 2;
239 }
240 }
241 if (resultNum) {
242 if (Args.size() >=2) {
243 Type *t = Args[1].Ty;
244 if (t->isFloatTy()) {
245 resultNum += 4;
246 }
247 else if (t->isDoubleTy()) {
248 resultNum += 8;
249 }
250 }
251 }
252 return resultNum;
253}
254
255//
256// Prefixes are attached to stub numbers depending on the return type.
257// return type: float sf_
258// double df_
259// single complex sc_
260// double complext dc_
261// others NO PREFIX
262//
263//
264// The full name of a helper function is__mips16_call_stub +
265// return type dependent prefix + stub number
266//
267// FIXME: This is something that probably should be in a different source file
268// and perhaps done differently but my main purpose is to not waste runtime
269// on something that we can enumerate in the source. Another possibility is
270// to have a python script to generate these mapping tables. This will do
271// for now. There are a whole series of helper function mapping arrays, one
272// for each return type class as outlined above. There there are 11 possible
273// entries. Ones with 0 are ones which should never be selected.
274//
275// All the arrays are similar except for ones which return neither
276// sf, df, sc, dc, in which we only care about ones which have sf or df as a
277// first parameter.
278//
279#define P_ "__mips16_call_stub_"
280#define MAX_STUB_NUMBER 10
281#define T1 P "1", P "2", 0, 0, P "5", P "6", 0, 0, P "9", P "10"
282#define T P "0" , T1
283#define P P_
284static char const * vMips16Helper[MAX_STUB_NUMBER+1] =
285 {nullptr, T1 };
286#undef P
287#define P P_ "sf_"
288static char const * sfMips16Helper[MAX_STUB_NUMBER+1] =
289 { T };
290#undef P
291#define P P_ "df_"
292static char const * dfMips16Helper[MAX_STUB_NUMBER+1] =
293 { T };
294#undef P
295#define P P_ "sc_"
296static char const * scMips16Helper[MAX_STUB_NUMBER+1] =
297 { T };
298#undef P
299#define P P_ "dc_"
300static char const * dcMips16Helper[MAX_STUB_NUMBER+1] =
301 { T };
302#undef P
303#undef P_
304
305
306const char* Mips16TargetLowering::
307 getMips16HelperFunction
308 (Type* RetTy, ArgListTy &Args, bool &needHelper) const {
309 const unsigned int stubNum = getMips16HelperFunctionStubNumber(Args);
310#ifndef NDEBUG
311 const unsigned int maxStubNum = 10;
312 assert(stubNum <= maxStubNum);
313 const bool validStubNum[maxStubNum+1] =
314 {true, true, true, false, false, true, true, false, false, true, true};
315 assert(validStubNum[stubNum]);
316#endif
317 const char *result;
318 if (RetTy->isFloatTy()) {
319 result = sfMips16Helper[stubNum];
320 }
321 else if (RetTy ->isDoubleTy()) {
322 result = dfMips16Helper[stubNum];
323 } else if (StructType *SRetTy = dyn_cast<StructType>(RetTy)) {
324 // check if it's complex
325 if (SRetTy->getNumElements() == 2) {
326 if ((SRetTy->getElementType(0)->isFloatTy()) &&
327 (SRetTy->getElementType(1)->isFloatTy())) {
328 result = scMips16Helper[stubNum];
329 } else if ((SRetTy->getElementType(0)->isDoubleTy()) &&
330 (SRetTy->getElementType(1)->isDoubleTy())) {
331 result = dcMips16Helper[stubNum];
332 } else {
333 llvm_unreachable("Uncovered condition");
334 }
335 } else {
336 llvm_unreachable("Uncovered condition");
337 }
338 } else {
339 if (stubNum == 0) {
340 needHelper = false;
341 return "";
342 }
343 result = vMips16Helper[stubNum];
344 }
345 needHelper = true;
346 return result;
347}
348
350 // FIXME: Use getSupportedLibcallImpl instead of blindly parsing the name.
351 iota_range<RTLIB::LibcallImpl> ParsedLibcalls =
353 return !ParsedLibcalls.empty() &&
355 *ParsedLibcalls.begin());
356}
357
358void Mips16TargetLowering::
359getOpndList(SmallVectorImpl<SDValue> &Ops,
360 std::deque< std::pair<unsigned, SDValue> > &RegsToPass,
361 bool IsPICCall, bool GlobalOrExternal, bool InternalLinkage,
362 bool IsCallReloc, CallLoweringInfo &CLI, SDValue Callee,
363 SDValue Chain) const {
364 SelectionDAG &DAG = CLI.DAG;
365 MachineFunction &MF = DAG.getMachineFunction();
366 MipsFunctionInfo *FuncInfo = MF.getInfo<MipsFunctionInfo>();
367 const char* Mips16HelperFunction = nullptr;
368 bool NeedMips16Helper = false;
369
370 if (Subtarget.inMips16HardFloat()) {
371 //
372 // currently we don't have symbols tagged with the mips16 or mips32
373 // qualifier so we will assume that we don't know what kind it is.
374 // and generate the helper
375 //
376 bool LookupHelper = true;
377 if (ExternalSymbolSDNode *S = dyn_cast<ExternalSymbolSDNode>(CLI.Callee)) {
378 if (isMips16HardFloatLibcall(S->getSymbol()))
379 LookupHelper = false;
380 else {
381 const char *Symbol = S->getSymbol();
382 Mips16IntrinsicHelperType IntrinsicFind = { Symbol, "" };
383 const Mips16HardFloatInfo::FuncSignature *Signature =
385 if (!IsPICCall && Signature &&
386 FuncInfo->StubsNeeded.try_emplace(Symbol, Signature).second) {
387 //
388 // S2 is normally saved if the stub is for a function which
389 // returns a float or double value and is not otherwise. This is
390 // because more work is required after the function the stub
391 // is calling completes, and so the stub cannot directly return
392 // and the stub has no stack space to store the return address so
393 // S2 is used for that purpose.
394 // In order to take advantage of not saving S2, we need to also
395 // optimize the call in the stub and this requires some further
396 // functionality in MipsAsmPrinter which we don't have yet.
397 // So for now we always save S2. The optimization will be done
398 // in a follow-on patch.
399 //
400 if (true || (Signature->RetSig != Mips16HardFloatInfo::NoFPRet))
401 FuncInfo->setSaveS2();
402 }
403 // one more look at list of intrinsics
404 const Mips16IntrinsicHelperType *Helper =
406 if (Helper != std::end(Mips16IntrinsicHelper) &&
407 *Helper == IntrinsicFind) {
408 Mips16HelperFunction = Helper->Helper;
409 NeedMips16Helper = true;
410 LookupHelper = false;
411 }
412
413 }
414 } else if (GlobalAddressSDNode *G =
415 dyn_cast<GlobalAddressSDNode>(CLI.Callee)) {
416
417 if (isMips16HardFloatLibcall(G->getGlobal()->getName()))
418 LookupHelper = false;
419 }
420 if (LookupHelper)
421 Mips16HelperFunction =
422 getMips16HelperFunction(CLI.RetTy, CLI.getArgs(), NeedMips16Helper);
423 }
424
425 SDValue JumpTarget = Callee;
426
427 // T9 should contain the address of the callee function if
428 // -relocation-model=pic or it is an indirect call.
429 if (IsPICCall || !GlobalOrExternal) {
430 unsigned V0Reg = Mips::V0;
431 if (NeedMips16Helper) {
432 RegsToPass.push_front(std::make_pair(V0Reg, Callee));
433 JumpTarget = DAG.getExternalSymbol(Mips16HelperFunction,
435 ExternalSymbolSDNode *S = cast<ExternalSymbolSDNode>(JumpTarget);
436 JumpTarget = getAddrGlobal(S, CLI.DL, JumpTarget.getValueType(), DAG,
437 MipsII::MO_GOT, Chain,
438 FuncInfo->callPtrInfo(MF, S->getSymbol()));
439 } else
440 RegsToPass.push_front(std::make_pair((unsigned)Mips::T9, Callee));
441 }
442
443 Ops.push_back(JumpTarget);
444
445 MipsTargetLowering::getOpndList(Ops, RegsToPass, IsPICCall, GlobalOrExternal,
446 InternalLinkage, IsCallReloc, CLI, Callee,
447 Chain);
448}
449
451Mips16TargetLowering::emitSel16(unsigned Opc, MachineInstr &MI,
452 MachineBasicBlock *BB) const {
454 return BB;
455 const TargetInstrInfo *TII = Subtarget.getInstrInfo();
456 DebugLoc DL = MI.getDebugLoc();
457 // To "insert" a SELECT_CC instruction, we actually have to insert the
458 // diamond control-flow pattern. The incoming instruction knows the
459 // destination vreg to set, the condition code register to branch on, the
460 // true/false values to select between, and a branch opcode to use.
461 const BasicBlock *LLVM_BB = BB->getBasicBlock();
463
464 // thisMBB:
465 // ...
466 // TrueVal = ...
467 // setcc r1, r2, r3
468 // bNE r1, r0, copy1MBB
469 // fallthrough --> copy0MBB
470 MachineBasicBlock *thisMBB = BB;
471 MachineFunction *F = BB->getParent();
472 MachineBasicBlock *copy0MBB = F->CreateMachineBasicBlock(LLVM_BB);
473 MachineBasicBlock *sinkMBB = F->CreateMachineBasicBlock(LLVM_BB);
474 F->insert(It, copy0MBB);
475 F->insert(It, sinkMBB);
476
477 // Transfer the remainder of BB and its successor edges to sinkMBB.
478 sinkMBB->splice(sinkMBB->begin(), BB,
479 std::next(MachineBasicBlock::iterator(MI)), BB->end());
481
482 // Next, add the true and fallthrough blocks as its successors.
483 BB->addSuccessor(copy0MBB);
484 BB->addSuccessor(sinkMBB);
485
486 BuildMI(BB, DL, TII->get(Opc))
487 .addReg(MI.getOperand(3).getReg())
488 .addMBB(sinkMBB);
489
490 // copy0MBB:
491 // %FalseValue = ...
492 // # fallthrough to sinkMBB
493 BB = copy0MBB;
494
495 // Update machine-CFG edges
496 BB->addSuccessor(sinkMBB);
497
498 // sinkMBB:
499 // %Result = phi [ %TrueValue, thisMBB ], [ %FalseValue, copy0MBB ]
500 // ...
501 BB = sinkMBB;
502
503 BuildMI(*BB, BB->begin(), DL, TII->get(Mips::PHI), MI.getOperand(0).getReg())
504 .addReg(MI.getOperand(1).getReg())
505 .addMBB(thisMBB)
506 .addReg(MI.getOperand(2).getReg())
507 .addMBB(copy0MBB);
508
509 MI.eraseFromParent(); // The pseudo instruction is gone now.
510 return BB;
511}
512
514Mips16TargetLowering::emitSelT16(unsigned Opc1, unsigned Opc2, MachineInstr &MI,
515 MachineBasicBlock *BB) const {
517 return BB;
518 const TargetInstrInfo *TII = Subtarget.getInstrInfo();
519 DebugLoc DL = MI.getDebugLoc();
520 // To "insert" a SELECT_CC instruction, we actually have to insert the
521 // diamond control-flow pattern. The incoming instruction knows the
522 // destination vreg to set, the condition code register to branch on, the
523 // true/false values to select between, and a branch opcode to use.
524 const BasicBlock *LLVM_BB = BB->getBasicBlock();
526
527 // thisMBB:
528 // ...
529 // TrueVal = ...
530 // setcc r1, r2, r3
531 // bNE r1, r0, copy1MBB
532 // fallthrough --> copy0MBB
533 MachineBasicBlock *thisMBB = BB;
534 MachineFunction *F = BB->getParent();
535 MachineBasicBlock *copy0MBB = F->CreateMachineBasicBlock(LLVM_BB);
536 MachineBasicBlock *sinkMBB = F->CreateMachineBasicBlock(LLVM_BB);
537 F->insert(It, copy0MBB);
538 F->insert(It, sinkMBB);
539
540 // Transfer the remainder of BB and its successor edges to sinkMBB.
541 sinkMBB->splice(sinkMBB->begin(), BB,
542 std::next(MachineBasicBlock::iterator(MI)), BB->end());
544
545 // Next, add the true and fallthrough blocks as its successors.
546 BB->addSuccessor(copy0MBB);
547 BB->addSuccessor(sinkMBB);
548
549 BuildMI(BB, DL, TII->get(Opc2))
550 .addReg(MI.getOperand(3).getReg())
551 .addReg(MI.getOperand(4).getReg());
552 BuildMI(BB, DL, TII->get(Opc1)).addMBB(sinkMBB);
553
554 // copy0MBB:
555 // %FalseValue = ...
556 // # fallthrough to sinkMBB
557 BB = copy0MBB;
558
559 // Update machine-CFG edges
560 BB->addSuccessor(sinkMBB);
561
562 // sinkMBB:
563 // %Result = phi [ %TrueValue, thisMBB ], [ %FalseValue, copy0MBB ]
564 // ...
565 BB = sinkMBB;
566
567 BuildMI(*BB, BB->begin(), DL, TII->get(Mips::PHI), MI.getOperand(0).getReg())
568 .addReg(MI.getOperand(1).getReg())
569 .addMBB(thisMBB)
570 .addReg(MI.getOperand(2).getReg())
571 .addMBB(copy0MBB);
572
573 MI.eraseFromParent(); // The pseudo instruction is gone now.
574 return BB;
575
576}
577
579Mips16TargetLowering::emitSeliT16(unsigned Opc1, unsigned Opc2,
581 MachineBasicBlock *BB) const {
583 return BB;
584 const TargetInstrInfo *TII = Subtarget.getInstrInfo();
585 DebugLoc DL = MI.getDebugLoc();
586 // To "insert" a SELECT_CC instruction, we actually have to insert the
587 // diamond control-flow pattern. The incoming instruction knows the
588 // destination vreg to set, the condition code register to branch on, the
589 // true/false values to select between, and a branch opcode to use.
590 const BasicBlock *LLVM_BB = BB->getBasicBlock();
592
593 // thisMBB:
594 // ...
595 // TrueVal = ...
596 // setcc r1, r2, r3
597 // bNE r1, r0, copy1MBB
598 // fallthrough --> copy0MBB
599 MachineBasicBlock *thisMBB = BB;
600 MachineFunction *F = BB->getParent();
601 MachineBasicBlock *copy0MBB = F->CreateMachineBasicBlock(LLVM_BB);
602 MachineBasicBlock *sinkMBB = F->CreateMachineBasicBlock(LLVM_BB);
603 F->insert(It, copy0MBB);
604 F->insert(It, sinkMBB);
605
606 // Transfer the remainder of BB and its successor edges to sinkMBB.
607 sinkMBB->splice(sinkMBB->begin(), BB,
608 std::next(MachineBasicBlock::iterator(MI)), BB->end());
610
611 // Next, add the true and fallthrough blocks as its successors.
612 BB->addSuccessor(copy0MBB);
613 BB->addSuccessor(sinkMBB);
614
615 BuildMI(BB, DL, TII->get(Opc2))
616 .addReg(MI.getOperand(3).getReg())
617 .addImm(MI.getOperand(4).getImm());
618 BuildMI(BB, DL, TII->get(Opc1)).addMBB(sinkMBB);
619
620 // copy0MBB:
621 // %FalseValue = ...
622 // # fallthrough to sinkMBB
623 BB = copy0MBB;
624
625 // Update machine-CFG edges
626 BB->addSuccessor(sinkMBB);
627
628 // sinkMBB:
629 // %Result = phi [ %TrueValue, thisMBB ], [ %FalseValue, copy0MBB ]
630 // ...
631 BB = sinkMBB;
632
633 BuildMI(*BB, BB->begin(), DL, TII->get(Mips::PHI), MI.getOperand(0).getReg())
634 .addReg(MI.getOperand(1).getReg())
635 .addMBB(thisMBB)
636 .addReg(MI.getOperand(2).getReg())
637 .addMBB(copy0MBB);
638
639 MI.eraseFromParent(); // The pseudo instruction is gone now.
640 return BB;
641
642}
643
645Mips16TargetLowering::emitFEXT_T8I816_ins(unsigned BtOpc, unsigned CmpOpc,
647 MachineBasicBlock *BB) const {
649 return BB;
650 const TargetInstrInfo *TII = Subtarget.getInstrInfo();
651 Register regX = MI.getOperand(0).getReg();
652 Register regY = MI.getOperand(1).getReg();
653 MachineBasicBlock *target = MI.getOperand(2).getMBB();
654 BuildMI(*BB, MI, MI.getDebugLoc(), TII->get(CmpOpc))
655 .addReg(regX)
656 .addReg(regY);
657 BuildMI(*BB, MI, MI.getDebugLoc(), TII->get(BtOpc)).addMBB(target);
658 MI.eraseFromParent(); // The pseudo instruction is gone now.
659 return BB;
660}
661
662MachineBasicBlock *Mips16TargetLowering::emitFEXT_T8I8I16_ins(
663 unsigned BtOpc, unsigned CmpiOpc, unsigned CmpiXOpc, bool ImmSigned,
664 MachineInstr &MI, MachineBasicBlock *BB) const {
666 return BB;
667 const TargetInstrInfo *TII = Subtarget.getInstrInfo();
668 Register regX = MI.getOperand(0).getReg();
669 int64_t imm = MI.getOperand(1).getImm();
670 MachineBasicBlock *target = MI.getOperand(2).getMBB();
671 unsigned CmpOpc;
672 if (isUInt<8>(imm))
673 CmpOpc = CmpiOpc;
674 else if ((!ImmSigned && isUInt<16>(imm)) ||
675 (ImmSigned && isInt<16>(imm)))
676 CmpOpc = CmpiXOpc;
677 else
678 llvm_unreachable("immediate field not usable");
679 BuildMI(*BB, MI, MI.getDebugLoc(), TII->get(CmpOpc)).addReg(regX).addImm(imm);
680 BuildMI(*BB, MI, MI.getDebugLoc(), TII->get(BtOpc)).addMBB(target);
681 MI.eraseFromParent(); // The pseudo instruction is gone now.
682 return BB;
683}
684
686 (unsigned shortOp, unsigned longOp, int64_t Imm) {
687 if (isUInt<8>(Imm))
688 return shortOp;
689 else if (isInt<16>(Imm))
690 return longOp;
691 else
692 llvm_unreachable("immediate field not usable");
693}
694
696Mips16TargetLowering::emitFEXT_CCRX16_ins(unsigned SltOpc, MachineInstr &MI,
697 MachineBasicBlock *BB) const {
699 return BB;
700 const TargetInstrInfo *TII = Subtarget.getInstrInfo();
701 Register CC = MI.getOperand(0).getReg();
702 Register regX = MI.getOperand(1).getReg();
703 Register regY = MI.getOperand(2).getReg();
704 BuildMI(*BB, MI, MI.getDebugLoc(), TII->get(SltOpc))
705 .addReg(regX)
706 .addReg(regY);
707 BuildMI(*BB, MI, MI.getDebugLoc(), TII->get(Mips::MoveR3216), CC)
708 .addReg(Mips::T8);
709 MI.eraseFromParent(); // The pseudo instruction is gone now.
710 return BB;
711}
712
714Mips16TargetLowering::emitFEXT_CCRXI16_ins(unsigned SltiOpc, unsigned SltiXOpc,
716 MachineBasicBlock *BB) const {
718 return BB;
719 const TargetInstrInfo *TII = Subtarget.getInstrInfo();
720 Register CC = MI.getOperand(0).getReg();
721 Register regX = MI.getOperand(1).getReg();
722 int64_t Imm = MI.getOperand(2).getImm();
723 unsigned SltOpc = Mips16WhichOp8uOr16simm(SltiOpc, SltiXOpc, Imm);
724 BuildMI(*BB, MI, MI.getDebugLoc(), TII->get(SltOpc)).addReg(regX).addImm(Imm);
725 BuildMI(*BB, MI, MI.getDebugLoc(), TII->get(Mips::MoveR3216), CC)
726 .addReg(Mips::T8);
727 MI.eraseFromParent(); // The pseudo instruction is gone now.
728 return BB;
729
730}
return SDValue()
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
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 cl::opt< bool > DontExpandCondPseudos16("mips16-dont-expand-cond-pseudo", cl::init(false), cl::desc("Don't expand conditional move related " "pseudos for Mips 16"), cl::Hidden)
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)
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 & addImm(int64_t Val) const
Add a new immediate operand.
const MachineInstrBuilder & addReg(Register RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register 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 InternalLinkage, 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...
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
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:45
bool isFloatTy() const
Return true if this is 'float', a 32-bit IEEE fp type.
Definition Type.h:153
bool isDoubleTy() const
Return true if this is 'double', a 64-bit IEEE fp type.
Definition Type.h:156
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.
@ Fast
Attempts to make calls as fast as possible (e.g.
Definition CallingConv.h:41
@ BSWAP
Byte Swap and Counting operators.
Definition ISDOpcodes.h:771
@ BasicBlock
Various leaf nodes.
Definition ISDOpcodes.h:81
FuncSignature const * findFuncSignature(const char *name)
initializer< Ty > init(const Ty &Val)
This is an optimization pass for GlobalISel generic memory operations.
bool operator<(int64_t V1, const APSInt &V2)
Definition APSInt.h:362
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:165
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:1981
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:189
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:1994
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 LLVM_ABI iota_range< RTLIB::LibcallImpl > lookupLibcallImplName(StringRef Name)
Check if a function name is a recognized runtime call of any kind.
auto begin() const
Definition Sequence.h:283
bool empty() const
Definition Sequence.h:281