LLVM 23.0.0git
MipsLegalizerInfo.cpp
Go to the documentation of this file.
1//===- MipsLegalizerInfo.cpp ------------------------------------*- 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/// \file
9/// This file implements the targeting of the Machinelegalizer class for Mips.
10/// \todo This should be generated by TableGen.
11//===----------------------------------------------------------------------===//
12
13#include "MipsLegalizerInfo.h"
14#include "MipsTargetMachine.h"
18#include "llvm/IR/IntrinsicsMips.h"
19
20using namespace llvm;
21
28
29// Assumes power of 2 memory size. Subtargets that have only naturally-aligned
30// memory access need to perform additional legalization here.
31static bool isUnalignedMemmoryAccess(uint64_t MemSize, uint64_t AlignInBits) {
32 assert(isPowerOf2_64(MemSize) && "Expected power of 2 memory size");
33 assert(isPowerOf2_64(AlignInBits) && "Expected power of 2 align");
34 if (MemSize > AlignInBits)
35 return true;
36 return false;
37}
38
39static bool
41 std::initializer_list<TypesAndMemOps> SupportedValues) {
42 unsigned QueryMemSize = Query.MMODescrs[0].MemoryTy.getSizeInBits();
43
44 // Non power of two memory access is never legal.
45 if (!isPowerOf2_64(QueryMemSize))
46 return false;
47
48 for (auto &Val : SupportedValues) {
49 if (Val.ValTy != Query.Types[0])
50 continue;
51 if (Val.PtrTy != Query.Types[1])
52 continue;
53 if (Val.MemSize != QueryMemSize)
54 continue;
55 if (!Val.SystemSupportsUnalignedAccess &&
56 isUnalignedMemmoryAccess(QueryMemSize, Query.MMODescrs[0].AlignInBits))
57 return false;
58 return true;
59 }
60 return false;
61}
62
63static bool CheckTyN(unsigned N, const LegalityQuery &Query,
64 std::initializer_list<LLT> SupportedValues) {
65 return llvm::is_contained(SupportedValues, Query.Types[N]);
66}
67
69 using namespace TargetOpcode;
70
71 const LLT s1 = LLT::scalar(1);
72 const LLT s8 = LLT::scalar(8);
73 const LLT s16 = LLT::scalar(16);
74 const LLT s32 = LLT::scalar(32);
75 const LLT s64 = LLT::scalar(64);
76 const LLT v16s8 = LLT::fixed_vector(16, 8);
77 const LLT v8s16 = LLT::fixed_vector(8, 16);
78 const LLT v4s32 = LLT::fixed_vector(4, 32);
79 const LLT v2s64 = LLT::fixed_vector(2, 64);
80 const LLT p0 = LLT::pointer(0, 32);
81
82 getActionDefinitionsBuilder({G_ADD, G_SUB, G_MUL})
83 .legalIf([=, &ST](const LegalityQuery &Query) {
84 if (CheckTyN(0, Query, {s32}))
85 return true;
86 if (ST.hasMSA() && CheckTyN(0, Query, {v16s8, v8s16, v4s32, v2s64}))
87 return true;
88 return false;
89 })
90 .clampScalar(0, s32, s32);
91
92 getActionDefinitionsBuilder({G_UADDO, G_UADDE, G_USUBO, G_USUBE, G_UMULO})
93 .lowerFor({{s32, s1}});
94
96 .legalFor({s32})
97 .maxScalar(0, s32);
98
99 // MIPS32r6 does not have alignment restrictions for memory access.
100 // For MIPS32r5 and older memory access must be naturally-aligned i.e. aligned
101 // to at least a multiple of its own size. There is however a two instruction
102 // combination that performs 4 byte unaligned access (lwr/lwl and swl/swr)
103 // therefore 4 byte load and store are legal and will use NoAlignRequirements.
104 bool NoAlignRequirements = true;
105
106 getActionDefinitionsBuilder({G_LOAD, G_STORE})
107 .legalIf([=, &ST](const LegalityQuery &Query) {
109 Query, {{s32, p0, 8, NoAlignRequirements},
110 {s32, p0, 16, ST.systemSupportsUnalignedAccess()},
111 {s32, p0, 32, NoAlignRequirements},
112 {p0, p0, 32, NoAlignRequirements},
113 {s64, p0, 64, ST.systemSupportsUnalignedAccess()}}))
114 return true;
115 if (ST.hasMSA() && CheckTy0Ty1MemSizeAlign(
116 Query, {{v16s8, p0, 128, NoAlignRequirements},
117 {v8s16, p0, 128, NoAlignRequirements},
118 {v4s32, p0, 128, NoAlignRequirements},
119 {v2s64, p0, 128, NoAlignRequirements}}))
120 return true;
121 return false;
122 })
123 // Custom lower scalar memory access, up to 8 bytes, for:
124 // - non-power-of-2 MemSizes
125 // - unaligned 2 or 8 byte MemSizes for MIPS32r5 and older
126 .customIf([=, &ST](const LegalityQuery &Query) {
127 if (!Query.Types[0].isScalar() || Query.Types[1] != p0 ||
128 Query.Types[0] == s1)
129 return false;
130
131 unsigned Size = Query.Types[0].getSizeInBits();
132 unsigned QueryMemSize = Query.MMODescrs[0].MemoryTy.getSizeInBits();
133 assert(QueryMemSize <= Size && "Scalar can't hold MemSize");
134
135 if (Size > 64 || QueryMemSize > 64)
136 return false;
137
138 if (!isPowerOf2_64(Query.MMODescrs[0].MemoryTy.getSizeInBits()))
139 return true;
140
141 if (!ST.systemSupportsUnalignedAccess() &&
142 isUnalignedMemmoryAccess(QueryMemSize,
143 Query.MMODescrs[0].AlignInBits)) {
144 assert(QueryMemSize != 32 && "4 byte load and store are legal");
145 return true;
146 }
147
148 return false;
149 })
150 .minScalar(0, s32)
151 .lower();
152
153 getActionDefinitionsBuilder(G_IMPLICIT_DEF)
154 .legalFor({s32, s64});
155
156 getActionDefinitionsBuilder(G_UNMERGE_VALUES)
157 .legalFor({{s32, s64}});
158
159 getActionDefinitionsBuilder(G_MERGE_VALUES)
160 .legalFor({{s64, s32}});
161
162 getActionDefinitionsBuilder({G_ZEXTLOAD, G_SEXTLOAD})
163 .legalForTypesWithMemDesc({{s32, p0, s8, 8},
164 {s32, p0, s16, 8}})
165 .clampScalar(0, s32, s32);
166
167 getActionDefinitionsBuilder({G_ZEXT, G_SEXT, G_ANYEXT})
168 .legalIf([](const LegalityQuery &Query) { return false; })
169 .maxScalar(0, s32);
170
172 .legalIf([](const LegalityQuery &Query) { return false; })
173 .maxScalar(1, s32);
174
176 .legalForCartesianProduct({p0, s32, s64}, {s32})
177 .minScalar(0, s32)
178 .minScalar(1, s32);
179
181
183 .legalFor({s32})
184 .minScalar(0, s32);
185
187 .legalFor({{p0, s32}});
188
189 getActionDefinitionsBuilder(G_BRINDIRECT)
190 .legalFor({p0});
191
193 .legalFor({p0, s32, s64})
194 .minScalar(0, s32);
195
196 getActionDefinitionsBuilder({G_AND, G_OR, G_XOR})
197 .legalFor({s32})
198 .clampScalar(0, s32, s32);
199
200 getActionDefinitionsBuilder({G_SDIV, G_SREM, G_UDIV, G_UREM})
201 .legalIf([=, &ST](const LegalityQuery &Query) {
202 if (CheckTyN(0, Query, {s32}))
203 return true;
204 if (ST.hasMSA() && CheckTyN(0, Query, {v16s8, v8s16, v4s32, v2s64}))
205 return true;
206 return false;
207 })
208 .minScalar(0, s32)
209 .libcallFor({s64});
210
211 getActionDefinitionsBuilder({G_SHL, G_ASHR, G_LSHR})
212 .legalFor({{s32, s32}})
213 .clampScalar(1, s32, s32)
214 .clampScalar(0, s32, s32);
215
217 .legalForCartesianProduct({s32}, {s32, p0})
218 .clampScalar(1, s32, s32)
219 .minScalar(0, s32);
220
222 .legalFor({s32})
223 .clampScalar(0, s32, s32);
224
225 getActionDefinitionsBuilder({G_PTR_ADD, G_INTTOPTR})
226 .legalFor({{p0, s32}});
227
229 .legalFor({{s32, p0}});
230
231 getActionDefinitionsBuilder(G_FRAME_INDEX)
232 .legalFor({p0});
233
234 getActionDefinitionsBuilder({G_GLOBAL_VALUE, G_JUMP_TABLE})
235 .legalFor({p0});
236
237 getActionDefinitionsBuilder(G_DYN_STACKALLOC)
238 .lowerFor({{p0, s32}});
239
241 .legalFor({p0});
242
244 .legalIf([=, &ST](const LegalityQuery &Query) {
245 if (ST.hasMips32r2() && CheckTyN(0, Query, {s32}))
246 return true;
247 return false;
248 })
249 .lowerIf([=, &ST](const LegalityQuery &Query) {
250 if (!ST.hasMips32r2() && CheckTyN(0, Query, {s32}))
251 return true;
252 return false;
253 })
254 .maxScalar(0, s32);
255
256 getActionDefinitionsBuilder(G_BITREVERSE)
257 .lowerFor({s32})
258 .maxScalar(0, s32);
259
261 .legalFor({{s32, s32}})
262 .maxScalar(0, s32)
263 .maxScalar(1, s32);
264 getActionDefinitionsBuilder(G_CTLZ_ZERO_POISON)
265 .lowerFor({{s32, s32}});
266
268 .lowerFor({{s32, s32}})
269 .maxScalar(0, s32)
270 .maxScalar(1, s32);
271 getActionDefinitionsBuilder(G_CTTZ_ZERO_POISON)
272 .lowerFor({{s32, s32}, {s64, s64}});
273
275 .lowerFor({{s32, s32}})
276 .clampScalar(0, s32, s32)
277 .clampScalar(1, s32, s32);
278
279 // FP instructions
280 getActionDefinitionsBuilder(G_FCONSTANT)
281 .legalFor({s32, s64});
282
283 getActionDefinitionsBuilder({G_FADD, G_FSUB, G_FMUL, G_FDIV, G_FABS, G_FSQRT})
284 .legalIf([=, &ST](const LegalityQuery &Query) {
285 if (CheckTyN(0, Query, {s32, s64}))
286 return true;
287 if (ST.hasMSA() && CheckTyN(0, Query, {v16s8, v8s16, v4s32, v2s64}))
288 return true;
289 return false;
290 });
291
293 .legalFor({{s32, s32}, {s32, s64}})
294 .minScalar(0, s32);
295
296 getActionDefinitionsBuilder({G_FCEIL, G_FFLOOR})
297 .libcallFor({s32, s64});
298
300 .legalFor({{s64, s32}});
301
303 .legalFor({{s32, s64}});
304
305 // FP to int conversion instructions
307 .legalForCartesianProduct({s32}, {s64, s32})
308 .libcallForCartesianProduct({s64}, {s64, s32})
309 .minScalar(0, s32);
310
312 .libcallForCartesianProduct({s64}, {s64, s32})
313 .lowerForCartesianProduct({s32}, {s64, s32})
314 .minScalar(0, s32);
315
316 // Int to FP conversion instructions
318 .legalForCartesianProduct({s64, s32}, {s32})
319 .libcallForCartesianProduct({s64, s32}, {s64})
320 .minScalar(1, s32);
321
323 .libcallForCartesianProduct({s64, s32}, {s64})
324 .customForCartesianProduct({s64, s32}, {s32})
325 .minScalar(1, s32);
326
327 getActionDefinitionsBuilder(G_SEXT_INREG).lower();
328
329 getActionDefinitionsBuilder({G_MEMCPY, G_MEMMOVE, G_MEMSET}).libcall();
330
332 getActionDefinitionsBuilder({G_TRAP, G_DEBUGTRAP, G_UBSANTRAP}).alwaysLegal();
333
335 verify(*ST.getInstrInfo());
336}
337
340 LostDebugLocObserver &LocObserver) const {
341 using namespace TargetOpcode;
342
343 MachineIRBuilder &MIRBuilder = Helper.MIRBuilder;
344 MachineRegisterInfo &MRI = *MIRBuilder.getMRI();
345
346 const LLT s32 = LLT::scalar(32);
347 const LLT s64 = LLT::scalar(64);
348
349 switch (MI.getOpcode()) {
350 case G_LOAD:
351 case G_STORE: {
352 unsigned MemSize = (**MI.memoperands_begin()).getSize().getValue();
353 Register Val = MI.getOperand(0).getReg();
354 unsigned Size = MRI.getType(Val).getSizeInBits();
355
356 MachineMemOperand *MMOBase = *MI.memoperands_begin();
357
358 assert(MemSize <= 8 && "MemSize is too large");
359 assert(Size <= 64 && "Scalar size is too large");
360
361 // Split MemSize into two, P2HalfMemSize is largest power of two smaller
362 // then MemSize. e.g. 8 = 4 + 4 , 6 = 4 + 2, 3 = 2 + 1.
363 unsigned P2HalfMemSize, RemMemSize;
364 if (isPowerOf2_64(MemSize)) {
365 P2HalfMemSize = RemMemSize = MemSize / 2;
366 } else {
367 P2HalfMemSize = 1 << Log2_32(MemSize);
368 RemMemSize = MemSize - P2HalfMemSize;
369 }
370
371 Register BaseAddr = MI.getOperand(1).getReg();
372 LLT PtrTy = MRI.getType(BaseAddr);
373 MachineFunction &MF = MIRBuilder.getMF();
374
375 auto P2HalfMemOp = MF.getMachineMemOperand(MMOBase, 0, P2HalfMemSize);
376 auto RemMemOp = MF.getMachineMemOperand(MMOBase, P2HalfMemSize, RemMemSize);
377
378 if (MI.getOpcode() == G_STORE) {
379 // Widen Val to s32 or s64 in order to create legal G_LSHR or G_UNMERGE.
380 if (Size < 32)
381 Val = MIRBuilder.buildAnyExt(s32, Val).getReg(0);
382 if (Size > 32 && Size < 64)
383 Val = MIRBuilder.buildAnyExt(s64, Val).getReg(0);
384
385 auto C_P2HalfMemSize = MIRBuilder.buildConstant(s32, P2HalfMemSize);
386 auto Addr = MIRBuilder.buildPtrAdd(PtrTy, BaseAddr, C_P2HalfMemSize);
387
388 if (MI.getOpcode() == G_STORE && MemSize <= 4) {
389 MIRBuilder.buildStore(Val, BaseAddr, *P2HalfMemOp);
390 auto C_P2Half_InBits = MIRBuilder.buildConstant(s32, P2HalfMemSize * 8);
391 auto Shift = MIRBuilder.buildLShr(s32, Val, C_P2Half_InBits);
392 MIRBuilder.buildStore(Shift, Addr, *RemMemOp);
393 } else {
394 auto Unmerge = MIRBuilder.buildUnmerge(s32, Val);
395 MIRBuilder.buildStore(Unmerge.getReg(0), BaseAddr, *P2HalfMemOp);
396 MIRBuilder.buildStore(Unmerge.getReg(1), Addr, *RemMemOp);
397 }
398 }
399
400 if (MI.getOpcode() == G_LOAD) {
401
402 if (MemSize <= 4) {
403 // This is anyextending load, use 4 byte lwr/lwl.
404 auto *Load4MMO = MF.getMachineMemOperand(MMOBase, 0, 4);
405
406 if (Size == 32)
407 MIRBuilder.buildLoad(Val, BaseAddr, *Load4MMO);
408 else {
409 auto Load = MIRBuilder.buildLoad(s32, BaseAddr, *Load4MMO);
410 MIRBuilder.buildTrunc(Val, Load.getReg(0));
411 }
412
413 } else {
414 auto C_P2HalfMemSize = MIRBuilder.buildConstant(s32, P2HalfMemSize);
415 auto Addr = MIRBuilder.buildPtrAdd(PtrTy, BaseAddr, C_P2HalfMemSize);
416
417 auto Load_P2Half = MIRBuilder.buildLoad(s32, BaseAddr, *P2HalfMemOp);
418 auto Load_Rem = MIRBuilder.buildLoad(s32, Addr, *RemMemOp);
419
420 if (Size == 64)
421 MIRBuilder.buildMergeLikeInstr(Val, {Load_P2Half, Load_Rem});
422 else {
423 auto Merge =
424 MIRBuilder.buildMergeLikeInstr(s64, {Load_P2Half, Load_Rem});
425 MIRBuilder.buildTrunc(Val, Merge);
426 }
427 }
428 }
429 MI.eraseFromParent();
430 break;
431 }
432 case G_UITOFP: {
433 Register Dst = MI.getOperand(0).getReg();
434 Register Src = MI.getOperand(1).getReg();
435 LLT DstTy = MRI.getType(Dst);
436 LLT SrcTy = MRI.getType(Src);
437
438 if (SrcTy != s32)
439 return false;
440 if (DstTy != s32 && DstTy != s64)
441 return false;
442
443 // Let 0xABCDEFGH be given unsigned in MI.getOperand(1). First let's convert
444 // unsigned to double. Mantissa has 52 bits so we use following trick:
445 // First make floating point bit mask 0x43300000ABCDEFGH.
446 // Mask represents 2^52 * 0x1.00000ABCDEFGH i.e. 0x100000ABCDEFGH.0 .
447 // Next, subtract 2^52 * 0x1.0000000000000 i.e. 0x10000000000000.0 from it.
448 // Done. Trunc double to float if needed.
449
450 auto C_HiMask = MIRBuilder.buildConstant(s32, UINT32_C(0x43300000));
451 auto Bitcast =
452 MIRBuilder.buildMergeLikeInstr(s64, {Src, C_HiMask.getReg(0)});
453
454 MachineInstrBuilder TwoP52FP = MIRBuilder.buildFConstant(
455 s64, llvm::bit_cast<double>(UINT64_C(0x4330000000000000)));
456
457 if (DstTy == s64)
458 MIRBuilder.buildFSub(Dst, Bitcast, TwoP52FP);
459 else {
460 MachineInstrBuilder ResF64 = MIRBuilder.buildFSub(s64, Bitcast, TwoP52FP);
461 MIRBuilder.buildFPTrunc(Dst, ResF64);
462 }
463
464 MI.eraseFromParent();
465 break;
466 }
467 default:
468 return false;
469 }
470
471 return true;
472}
473
474static bool SelectMSA3OpIntrinsic(MachineInstr &MI, unsigned Opcode,
475 MachineIRBuilder &MIRBuilder,
476 const MipsSubtarget &ST) {
477 assert(ST.hasMSA() && "MSA intrinsic not supported on target without MSA.");
478 MIRBuilder.buildInstr(Opcode)
479 .add(MI.getOperand(0))
480 .add(MI.getOperand(2))
481 .add(MI.getOperand(3))
482 .constrainAllUses(MIRBuilder.getTII(), *ST.getRegisterInfo(),
483 *ST.getRegBankInfo());
484 MI.eraseFromParent();
485 return true;
486}
487
488static bool MSA3OpIntrinsicToGeneric(MachineInstr &MI, unsigned Opcode,
489 MachineIRBuilder &MIRBuilder,
490 const MipsSubtarget &ST) {
491 assert(ST.hasMSA() && "MSA intrinsic not supported on target without MSA.");
492 MIRBuilder.buildInstr(Opcode)
493 .add(MI.getOperand(0))
494 .add(MI.getOperand(2))
495 .add(MI.getOperand(3));
496 MI.eraseFromParent();
497 return true;
498}
499
500static bool MSA2OpIntrinsicToGeneric(MachineInstr &MI, unsigned Opcode,
501 MachineIRBuilder &MIRBuilder,
502 const MipsSubtarget &ST) {
503 assert(ST.hasMSA() && "MSA intrinsic not supported on target without MSA.");
504 MIRBuilder.buildInstr(Opcode)
505 .add(MI.getOperand(0))
506 .add(MI.getOperand(2));
507 MI.eraseFromParent();
508 return true;
509}
510
512 MachineInstr &MI) const {
513 MachineIRBuilder &MIRBuilder = Helper.MIRBuilder;
514 const MipsSubtarget &ST = MI.getMF()->getSubtarget<MipsSubtarget>();
515
517 case Intrinsic::vacopy: {
519 LLT PtrTy = LLT::pointer(0, 32);
520 auto Tmp =
521 MIRBuilder.buildLoad(PtrTy, MI.getOperand(2),
522 *MI.getMF()->getMachineMemOperand(
523 MPO, MachineMemOperand::MOLoad, PtrTy, Align(4)));
524 MIRBuilder.buildStore(Tmp, MI.getOperand(1),
525 *MI.getMF()->getMachineMemOperand(
526 MPO, MachineMemOperand::MOStore, PtrTy, Align(4)));
527 MI.eraseFromParent();
528 return true;
529 }
530 case Intrinsic::mips_addv_b:
531 case Intrinsic::mips_addv_h:
532 case Intrinsic::mips_addv_w:
533 case Intrinsic::mips_addv_d:
534 return MSA3OpIntrinsicToGeneric(MI, TargetOpcode::G_ADD, MIRBuilder, ST);
535 case Intrinsic::mips_addvi_b:
536 return SelectMSA3OpIntrinsic(MI, Mips::ADDVI_B, MIRBuilder, ST);
537 case Intrinsic::mips_addvi_h:
538 return SelectMSA3OpIntrinsic(MI, Mips::ADDVI_H, MIRBuilder, ST);
539 case Intrinsic::mips_addvi_w:
540 return SelectMSA3OpIntrinsic(MI, Mips::ADDVI_W, MIRBuilder, ST);
541 case Intrinsic::mips_addvi_d:
542 return SelectMSA3OpIntrinsic(MI, Mips::ADDVI_D, MIRBuilder, ST);
543 case Intrinsic::mips_subv_b:
544 case Intrinsic::mips_subv_h:
545 case Intrinsic::mips_subv_w:
546 case Intrinsic::mips_subv_d:
547 return MSA3OpIntrinsicToGeneric(MI, TargetOpcode::G_SUB, MIRBuilder, ST);
548 case Intrinsic::mips_subvi_b:
549 return SelectMSA3OpIntrinsic(MI, Mips::SUBVI_B, MIRBuilder, ST);
550 case Intrinsic::mips_subvi_h:
551 return SelectMSA3OpIntrinsic(MI, Mips::SUBVI_H, MIRBuilder, ST);
552 case Intrinsic::mips_subvi_w:
553 return SelectMSA3OpIntrinsic(MI, Mips::SUBVI_W, MIRBuilder, ST);
554 case Intrinsic::mips_subvi_d:
555 return SelectMSA3OpIntrinsic(MI, Mips::SUBVI_D, MIRBuilder, ST);
556 case Intrinsic::mips_mulv_b:
557 case Intrinsic::mips_mulv_h:
558 case Intrinsic::mips_mulv_w:
559 case Intrinsic::mips_mulv_d:
560 return MSA3OpIntrinsicToGeneric(MI, TargetOpcode::G_MUL, MIRBuilder, ST);
561 case Intrinsic::mips_div_s_b:
562 case Intrinsic::mips_div_s_h:
563 case Intrinsic::mips_div_s_w:
564 case Intrinsic::mips_div_s_d:
565 return MSA3OpIntrinsicToGeneric(MI, TargetOpcode::G_SDIV, MIRBuilder, ST);
566 case Intrinsic::mips_mod_s_b:
567 case Intrinsic::mips_mod_s_h:
568 case Intrinsic::mips_mod_s_w:
569 case Intrinsic::mips_mod_s_d:
570 return MSA3OpIntrinsicToGeneric(MI, TargetOpcode::G_SREM, MIRBuilder, ST);
571 case Intrinsic::mips_div_u_b:
572 case Intrinsic::mips_div_u_h:
573 case Intrinsic::mips_div_u_w:
574 case Intrinsic::mips_div_u_d:
575 return MSA3OpIntrinsicToGeneric(MI, TargetOpcode::G_UDIV, MIRBuilder, ST);
576 case Intrinsic::mips_mod_u_b:
577 case Intrinsic::mips_mod_u_h:
578 case Intrinsic::mips_mod_u_w:
579 case Intrinsic::mips_mod_u_d:
580 return MSA3OpIntrinsicToGeneric(MI, TargetOpcode::G_UREM, MIRBuilder, ST);
581 case Intrinsic::mips_fadd_w:
582 case Intrinsic::mips_fadd_d:
583 return MSA3OpIntrinsicToGeneric(MI, TargetOpcode::G_FADD, MIRBuilder, ST);
584 case Intrinsic::mips_fsub_w:
585 case Intrinsic::mips_fsub_d:
586 return MSA3OpIntrinsicToGeneric(MI, TargetOpcode::G_FSUB, MIRBuilder, ST);
587 case Intrinsic::mips_fmul_w:
588 case Intrinsic::mips_fmul_d:
589 return MSA3OpIntrinsicToGeneric(MI, TargetOpcode::G_FMUL, MIRBuilder, ST);
590 case Intrinsic::mips_fdiv_w:
591 case Intrinsic::mips_fdiv_d:
592 return MSA3OpIntrinsicToGeneric(MI, TargetOpcode::G_FDIV, MIRBuilder, ST);
593 case Intrinsic::mips_fmax_a_w:
594 return SelectMSA3OpIntrinsic(MI, Mips::FMAX_A_W, MIRBuilder, ST);
595 case Intrinsic::mips_fmax_a_d:
596 return SelectMSA3OpIntrinsic(MI, Mips::FMAX_A_D, MIRBuilder, ST);
597 case Intrinsic::mips_fsqrt_w:
598 return MSA2OpIntrinsicToGeneric(MI, TargetOpcode::G_FSQRT, MIRBuilder, ST);
599 case Intrinsic::mips_fsqrt_d:
600 return MSA2OpIntrinsicToGeneric(MI, TargetOpcode::G_FSQRT, MIRBuilder, ST);
601 default:
602 break;
603 }
604 return true;
605}
static unsigned getIntrinsicID(const SDNode *N)
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
Declares convenience wrapper classes for interpreting MachineInstr instances as specific generic oper...
IRTranslator LLVM IR MI
This file declares the MachineIRBuilder class.
static bool CheckTy0Ty1MemSizeAlign(const LegalityQuery &Query, std::initializer_list< TypesAndMemOps > SupportedValues)
static bool CheckTyN(unsigned N, const LegalityQuery &Query, std::initializer_list< LLT > SupportedValues)
static bool MSA2OpIntrinsicToGeneric(MachineInstr &MI, unsigned Opcode, MachineIRBuilder &MIRBuilder, const MipsSubtarget &ST)
static bool SelectMSA3OpIntrinsic(MachineInstr &MI, unsigned Opcode, MachineIRBuilder &MIRBuilder, const MipsSubtarget &ST)
static bool isUnalignedMemmoryAccess(uint64_t MemSize, uint64_t AlignInBits)
static bool MSA3OpIntrinsicToGeneric(MachineInstr &MI, unsigned Opcode, MachineIRBuilder &MIRBuilder, const MipsSubtarget &ST)
This file declares the targeting of the Machinelegalizer class for Mips.
ppc ctr loops verify
R600 Clause Merge
static constexpr LLT scalar(unsigned SizeInBits)
Get a low-level scalar or aggregate "bag of bits".
static constexpr LLT pointer(unsigned AddressSpace, unsigned SizeInBits)
Get a low-level pointer in the given address space.
constexpr TypeSize getSizeInBits() const
Returns the total size of the type. Must only be called on sized types.
static constexpr LLT fixed_vector(unsigned NumElements, unsigned ScalarSizeInBits)
Get a low-level fixed-width vector of some number of elements and element width.
LLVM_ABI void computeTables()
Compute any ancillary tables needed to quickly decide how an operation should be handled.
LegalizeRuleSet & minScalar(unsigned TypeIdx, const LLT Ty)
Ensure the scalar is at least as wide as Ty.
LegalizeRuleSet & legalFor(std::initializer_list< LLT > Types)
The instruction is legal when type index 0 is any type in the given list.
LegalizeRuleSet & libcallFor(std::initializer_list< LLT > Types)
LegalizeRuleSet & maxScalar(unsigned TypeIdx, const LLT Ty)
Ensure the scalar is at most as wide as Ty.
LegalizeRuleSet & libcallForCartesianProduct(std::initializer_list< LLT > Types)
LegalizeRuleSet & lower()
The instruction is lowered.
LegalizeRuleSet & lowerFor(std::initializer_list< LLT > Types)
The instruction is lowered when type index 0 is any type in the given list.
LegalizeRuleSet & clampScalar(unsigned TypeIdx, const LLT MinTy, const LLT MaxTy)
Limit the range of scalar sizes to MinTy and MaxTy.
LegalizeRuleSet & alwaysLegal()
LegalizeRuleSet & legalForCartesianProduct(std::initializer_list< LLT > Types)
The instruction is legal when type indexes 0 and 1 are both in the given list.
LegalizeRuleSet & legalIf(LegalityPredicate Predicate)
The instruction is legal if predicate is true.
MachineIRBuilder & MIRBuilder
Expose MIRBuilder so clients can set their own RecordInsertInstruction functions.
LegalizeRuleSet & getActionDefinitionsBuilder(unsigned Opcode)
Get the action definition builder for the given opcode.
const LegacyLegalizerInfo & getLegacyLegalizerInfo() const
MachineMemOperand * getMachineMemOperand(MachinePointerInfo PtrInfo, MachineMemOperand::Flags f, LLT MemTy, Align base_alignment, const AAMDNodes &AAInfo=AAMDNodes(), const MDNode *Ranges=nullptr, SyncScope::ID SSID=SyncScope::System, AtomicOrdering Ordering=AtomicOrdering::NotAtomic, AtomicOrdering FailureOrdering=AtomicOrdering::NotAtomic)
getMachineMemOperand - Allocate a new MachineMemOperand.
Helper class to build MachineInstr.
MachineInstrBuilder buildFSub(const DstOp &Dst, const SrcOp &Src0, const SrcOp &Src1, std::optional< unsigned > Flags=std::nullopt)
Build and insert Res = G_FSUB Op0, Op1.
MachineInstrBuilder buildUnmerge(ArrayRef< LLT > Res, const SrcOp &Op)
Build and insert Res0, ... = G_UNMERGE_VALUES Op.
const TargetInstrInfo & getTII()
MachineInstrBuilder buildLShr(const DstOp &Dst, const SrcOp &Src0, const SrcOp &Src1, std::optional< unsigned > Flags=std::nullopt)
MachineInstrBuilder buildMergeLikeInstr(const DstOp &Res, ArrayRef< Register > Ops)
Build and insert Res = G_MERGE_VALUES Op0, ... or Res = G_BUILD_VECTOR Op0, ... or Res = G_CONCAT_VEC...
MachineInstrBuilder buildLoad(const DstOp &Res, const SrcOp &Addr, MachineMemOperand &MMO)
Build and insert Res = G_LOAD Addr, MMO.
MachineInstrBuilder buildPtrAdd(const DstOp &Res, const SrcOp &Op0, const SrcOp &Op1, std::optional< unsigned > Flags=std::nullopt)
Build and insert Res = G_PTR_ADD Op0, Op1.
virtual MachineInstrBuilder buildFConstant(const DstOp &Res, const ConstantFP &Val)
Build and insert Res = G_FCONSTANT Val.
MachineInstrBuilder buildStore(const SrcOp &Val, const SrcOp &Addr, MachineMemOperand &MMO)
Build and insert G_STORE Val, Addr, MMO.
MachineInstrBuilder buildInstr(unsigned Opcode)
Build and insert <empty> = Opcode <empty>.
MachineFunction & getMF()
Getter for the function we currently build.
MachineInstrBuilder buildTrunc(const DstOp &Res, const SrcOp &Op, std::optional< unsigned > Flags=std::nullopt)
Build and insert Res = G_TRUNC Op.
MachineInstrBuilder buildAnyExt(const DstOp &Res, const SrcOp &Op)
Build and insert Res = G_ANYEXT Op0.
MachineRegisterInfo * getMRI()
Getter for MRI.
MachineInstrBuilder buildFPTrunc(const DstOp &Res, const SrcOp &Op, std::optional< unsigned > Flags=std::nullopt)
Build and insert Res = G_FPTRUNC Op.
virtual MachineInstrBuilder buildConstant(const DstOp &Res, const ConstantInt &Val)
Build and insert Res = G_CONSTANT Val.
Register getReg(unsigned Idx) const
Get the register for the operand index.
void constrainAllUses(const TargetInstrInfo &TII, const TargetRegisterInfo &TRI, const RegisterBankInfo &RBI) const
const MachineInstrBuilder & add(const MachineOperand &MO) const
Representation of each machine instruction.
A description of a memory reference used in the backend.
@ MOLoad
The memory access reads data.
@ MOStore
The memory access writes data.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
LLT getType(Register Reg) const
Get the low-level type of Reg or LLT{} if Reg is not a generic (target independent) virtual register.
MipsLegalizerInfo(const MipsSubtarget &ST)
bool legalizeCustom(LegalizerHelper &Helper, MachineInstr &MI, LostDebugLocObserver &LocObserver) const override
Called for instructions with the Custom LegalizationAction.
bool legalizeIntrinsic(LegalizerHelper &Helper, MachineInstr &MI) const override
Wrapper class representing virtual and physical registers.
Definition Register.h:20
Invariant opcodes: All instruction sets have these as their low opcodes.
This is an optimization pass for GlobalISel generic memory operations.
constexpr bool isPowerOf2_64(uint64_t Value)
Return true if the argument is a power of two > 0 (64 bit edition.)
Definition MathExtras.h:284
unsigned Log2_32(uint32_t Value)
Return the floor log base 2 of the specified value, -1 if the value is zero.
Definition MathExtras.h:331
To bit_cast(const From &from) noexcept
Definition bit.h:90
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
Definition STLExtras.h:1946
#define N
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition Alignment.h:39
The LegalityQuery object bundles together all the information that's needed to decide whether a given...
ArrayRef< MemDesc > MMODescrs
Operations which require memory can use this to place requirements on the memory type for each MMO.
ArrayRef< LLT > Types
This class contains a discriminated union of information about pointers in memory operands,...