LLVM 23.0.0git
LoongArchInstrInfo.cpp
Go to the documentation of this file.
1//=- LoongArchInstrInfo.cpp - LoongArch Instruction Information -*- 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// This file contains the LoongArch implementation of the TargetInstrInfo class.
10//
11//===----------------------------------------------------------------------===//
12
13#include "LoongArchInstrInfo.h"
14#include "LoongArch.h"
21#include "llvm/MC/MCContext.h"
24
25using namespace llvm;
26
28 "loongarch-disable-reloc-sched",
29 cl::desc("Disable scheduling of instructions with target flags"),
30 cl::init(false), cl::Hidden);
31
32#define GET_INSTRINFO_CTOR_DTOR
33#include "LoongArchGenInstrInfo.inc"
34
36 : LoongArchGenInstrInfo(STI, RegInfo, LoongArch::ADJCALLSTACKDOWN,
37 LoongArch::ADJCALLSTACKUP),
38 RegInfo(STI.getHwMode()), STI(STI) {}
39
41 return MCInstBuilder(LoongArch::ANDI)
42 .addReg(LoongArch::R0)
43 .addReg(LoongArch::R0)
44 .addImm(0);
45}
46
49 const DebugLoc &DL, Register DstReg,
50 Register SrcReg, bool KillSrc,
51 bool RenamableDest,
52 bool RenamableSrc) const {
53 if (LoongArch::GPRRegClass.contains(DstReg, SrcReg)) {
54 BuildMI(MBB, MBBI, DL, get(LoongArch::OR), DstReg)
55 .addReg(SrcReg, getKillRegState(KillSrc))
56 .addReg(LoongArch::R0);
57 return;
58 }
59
60 // VR->VR copies.
61 if (LoongArch::LSX128RegClass.contains(DstReg, SrcReg)) {
62 BuildMI(MBB, MBBI, DL, get(LoongArch::VORI_B), DstReg)
63 .addReg(SrcReg, getKillRegState(KillSrc))
64 .addImm(0);
65 return;
66 }
67
68 // XR->XR copies.
69 if (LoongArch::LASX256RegClass.contains(DstReg, SrcReg)) {
70 BuildMI(MBB, MBBI, DL, get(LoongArch::XVORI_B), DstReg)
71 .addReg(SrcReg, getKillRegState(KillSrc))
72 .addImm(0);
73 return;
74 }
75
76 // GPR->CFR copy.
77 if (LoongArch::CFRRegClass.contains(DstReg) &&
78 LoongArch::GPRRegClass.contains(SrcReg)) {
79 BuildMI(MBB, MBBI, DL, get(LoongArch::MOVGR2CF), DstReg)
80 .addReg(SrcReg, getKillRegState(KillSrc));
81 return;
82 }
83 // CFR->GPR copy.
84 if (LoongArch::GPRRegClass.contains(DstReg) &&
85 LoongArch::CFRRegClass.contains(SrcReg)) {
86 BuildMI(MBB, MBBI, DL, get(LoongArch::MOVCF2GR), DstReg)
87 .addReg(SrcReg, getKillRegState(KillSrc));
88 return;
89 }
90 // CFR->CFR copy.
91 if (LoongArch::CFRRegClass.contains(DstReg, SrcReg)) {
92 BuildMI(MBB, MBBI, DL, get(LoongArch::PseudoCopyCFR), DstReg)
93 .addReg(SrcReg, getKillRegState(KillSrc));
94 return;
95 }
96
97 // FPR->FPR copies.
98 unsigned Opc;
99 if (LoongArch::FPR32RegClass.contains(DstReg, SrcReg)) {
100 Opc = LoongArch::FMOV_S;
101 } else if (LoongArch::FPR64RegClass.contains(DstReg, SrcReg)) {
102 Opc = LoongArch::FMOV_D;
103 } else if (LoongArch::GPRRegClass.contains(DstReg) &&
104 LoongArch::FPR32RegClass.contains(SrcReg)) {
105 // FPR32 -> GPR copies
106 Opc = LoongArch::MOVFR2GR_S;
107 } else if (LoongArch::GPRRegClass.contains(DstReg) &&
108 LoongArch::FPR64RegClass.contains(SrcReg)) {
109 // FPR64 -> GPR copies
110 Opc = LoongArch::MOVFR2GR_D;
111 } else {
112 // TODO: support other copies.
113 llvm_unreachable("Impossible reg-to-reg copy");
114 }
115
116 BuildMI(MBB, MBBI, DL, get(Opc), DstReg)
117 .addReg(SrcReg, getKillRegState(KillSrc));
118}
119
122 bool IsKill, int FI, const TargetRegisterClass *RC,
123
124 Register VReg, MachineInstr::MIFlag Flags) const {
125 MachineFunction *MF = MBB.getParent();
126 MachineFrameInfo &MFI = MF->getFrameInfo();
127
128 unsigned Opcode;
129 if (LoongArch::GPRRegClass.hasSubClassEq(RC))
130 Opcode = TRI.getRegSizeInBits(LoongArch::GPRRegClass) == 32
131 ? LoongArch::ST_W
132 : LoongArch::ST_D;
133 else if (LoongArch::FPR32RegClass.hasSubClassEq(RC))
134 Opcode = LoongArch::FST_S;
135 else if (LoongArch::FPR64RegClass.hasSubClassEq(RC))
136 Opcode = LoongArch::FST_D;
137 else if (LoongArch::LSX128RegClass.hasSubClassEq(RC))
138 Opcode = LoongArch::VST;
139 else if (LoongArch::LASX256RegClass.hasSubClassEq(RC))
140 Opcode = LoongArch::XVST;
141 else if (LoongArch::CFRRegClass.hasSubClassEq(RC))
142 Opcode = LoongArch::PseudoST_CFR;
143 else
144 llvm_unreachable("Can't store this register to stack slot");
145
148 MFI.getObjectSize(FI), MFI.getObjectAlign(FI));
149
150 BuildMI(MBB, I, DebugLoc(), get(Opcode))
151 .addReg(SrcReg, getKillRegState(IsKill))
152 .addFrameIndex(FI)
153 .addImm(0)
154 .addMemOperand(MMO);
155}
156
159 int FI, const TargetRegisterClass *RC, Register VReg, unsigned SubReg,
160 MachineInstr::MIFlag Flags) const {
161 MachineFunction *MF = MBB.getParent();
162 MachineFrameInfo &MFI = MF->getFrameInfo();
163 DebugLoc DL;
164 if (I != MBB.end())
165 DL = I->getDebugLoc();
166
167 unsigned Opcode;
168 if (LoongArch::GPRRegClass.hasSubClassEq(RC))
169 Opcode = RegInfo.getRegSizeInBits(LoongArch::GPRRegClass) == 32
170 ? LoongArch::LD_W
171 : LoongArch::LD_D;
172 else if (LoongArch::FPR32RegClass.hasSubClassEq(RC))
173 Opcode = LoongArch::FLD_S;
174 else if (LoongArch::FPR64RegClass.hasSubClassEq(RC))
175 Opcode = LoongArch::FLD_D;
176 else if (LoongArch::LSX128RegClass.hasSubClassEq(RC))
177 Opcode = LoongArch::VLD;
178 else if (LoongArch::LASX256RegClass.hasSubClassEq(RC))
179 Opcode = LoongArch::XVLD;
180 else if (LoongArch::CFRRegClass.hasSubClassEq(RC))
181 Opcode = LoongArch::PseudoLD_CFR;
182 else
183 llvm_unreachable("Can't load this register from stack slot");
184
187 MFI.getObjectSize(FI), MFI.getObjectAlign(FI));
188
189 BuildMI(MBB, I, DL, get(Opcode), DstReg)
190 .addFrameIndex(FI)
191 .addImm(0)
192 .addMemOperand(MMO);
193}
194
197 const DebugLoc &DL, Register DstReg,
198 uint64_t Val, MachineInstr::MIFlag Flag) const {
199 Register SrcReg = LoongArch::R0;
200
201 if (!STI.is64Bit() && !isInt<32>(Val))
202 report_fatal_error("Should only materialize 32-bit constants for LA32");
203
204 auto Seq = LoongArchMatInt::generateInstSeq(Val);
205 assert(!Seq.empty());
206
207 for (auto &Inst : Seq) {
208 switch (Inst.Opc) {
209 case LoongArch::LU12I_W:
210 BuildMI(MBB, MBBI, DL, get(Inst.Opc), DstReg)
211 .addImm(Inst.Imm)
212 .setMIFlag(Flag);
213 break;
214 case LoongArch::ADDI_W:
215 case LoongArch::ORI:
216 case LoongArch::LU32I_D: // "rj" is needed due to InstrInfo pattern
217 case LoongArch::LU52I_D:
218 BuildMI(MBB, MBBI, DL, get(Inst.Opc), DstReg)
219 .addReg(SrcReg, RegState::Kill)
220 .addImm(Inst.Imm)
221 .setMIFlag(Flag);
222 break;
223 case LoongArch::BSTRINS_D:
224 BuildMI(MBB, MBBI, DL, get(Inst.Opc), DstReg)
225 .addReg(SrcReg, RegState::Kill)
226 .addReg(SrcReg, RegState::Kill)
227 .addImm(Inst.Imm >> 32)
228 .addImm(Inst.Imm & 0xFF)
229 .setMIFlag(Flag);
230 break;
231 default:
232 assert(false && "Unknown insn emitted by LoongArchMatInt");
233 }
234
235 // Only the first instruction has $zero as its source.
236 SrcReg = DstReg;
237 }
238}
239
241 unsigned Opcode = MI.getOpcode();
242
243 if (Opcode == TargetOpcode::INLINEASM ||
244 Opcode == TargetOpcode::INLINEASM_BR) {
245 const MachineFunction *MF = MI.getParent()->getParent();
246 const MCAsmInfo *MAI = MF->getTarget().getMCAsmInfo();
247 return getInlineAsmLength(MI.getOperand(0).getSymbolName(), *MAI);
248 }
249
250 unsigned NumBytes = 0;
251 const MCInstrDesc &Desc = MI.getDesc();
252
253 // Size should be preferably set in
254 // llvm/lib/Target/LoongArch/LoongArch*InstrInfo.td (default case).
255 // Specific cases handle instructions of variable sizes.
256 switch (Desc.getOpcode()) {
257 default:
258 return Desc.getSize();
259 case TargetOpcode::STATEPOINT:
260 NumBytes = StatepointOpers(&MI).getNumPatchBytes();
261 assert(NumBytes % 4 == 0 && "Invalid number of NOP bytes requested!");
262 // No patch bytes means a normal call inst (i.e. `bl`) is emitted.
263 if (NumBytes == 0)
264 NumBytes = 4;
265 break;
266 case TargetOpcode::PATCHABLE_FUNCTION_ENTER: {
267 const MachineFunction *MF = MI.getParent()->getParent();
268 const Function &F = MF->getFunction();
269 if (F.hasFnAttribute("patchable-function-entry")) {
270 unsigned Num;
271 if (F.getFnAttribute("patchable-function-entry")
272 .getValueAsString()
273 .getAsInteger(10, Num))
274 return 0;
275 return Num * 4;
276 }
277 [[fallthrough]];
278 }
279 case TargetOpcode::PATCHABLE_FUNCTION_EXIT:
280 case TargetOpcode::PATCHABLE_TAIL_CALL:
281 // Size of xray sled (branch + 11 nops).
282 return 12 * 4;
283 case TargetOpcode::BUNDLE:
284 return getInstBundleSize(MI);
285 }
286 return NumBytes;
287}
288
290 const unsigned Opcode = MI.getOpcode();
291 switch (Opcode) {
292 default:
293 break;
294 case LoongArch::ADDI_D:
295 case LoongArch::ORI:
296 case LoongArch::XORI:
297 return (MI.getOperand(1).isReg() &&
298 MI.getOperand(1).getReg() == LoongArch::R0) ||
299 (MI.getOperand(2).isImm() && MI.getOperand(2).getImm() == 0);
300 }
301 return MI.isAsCheapAsAMove();
302}
303
306 assert(MI.getDesc().isBranch() && "Unexpected opcode!");
307 // The branch target is always the last operand.
308 return MI.getOperand(MI.getNumExplicitOperands() - 1).getMBB();
309}
310
313 // Block ends with fall-through condbranch.
314 assert(LastInst.getDesc().isConditionalBranch() &&
315 "Unknown conditional branch");
316 int NumOp = LastInst.getNumExplicitOperands();
317 Target = LastInst.getOperand(NumOp - 1).getMBB();
318
319 Cond.push_back(MachineOperand::CreateImm(LastInst.getOpcode()));
320 for (int i = 0; i < NumOp - 1; i++)
321 Cond.push_back(LastInst.getOperand(i));
322}
323
326 MachineBasicBlock *&FBB,
328 bool AllowModify) const {
329 TBB = FBB = nullptr;
330 Cond.clear();
331
332 // If the block has no terminators, it just falls into the block after it.
333 MachineBasicBlock::iterator I = MBB.getLastNonDebugInstr();
334 if (I == MBB.end() || !isUnpredicatedTerminator(*I))
335 return false;
336
337 // Count the number of terminators and find the first unconditional or
338 // indirect branch.
339 MachineBasicBlock::iterator FirstUncondOrIndirectBr = MBB.end();
340 int NumTerminators = 0;
341 for (auto J = I.getReverse(); J != MBB.rend() && isUnpredicatedTerminator(*J);
342 J++) {
343 NumTerminators++;
344 if (J->getDesc().isUnconditionalBranch() ||
345 J->getDesc().isIndirectBranch()) {
346 FirstUncondOrIndirectBr = J.getReverse();
347 }
348 }
349
350 // If AllowModify is true, we can erase any terminators after
351 // FirstUncondOrIndirectBR.
352 if (AllowModify && FirstUncondOrIndirectBr != MBB.end()) {
353 while (std::next(FirstUncondOrIndirectBr) != MBB.end()) {
354 std::next(FirstUncondOrIndirectBr)->eraseFromParent();
355 NumTerminators--;
356 }
357 I = FirstUncondOrIndirectBr;
358 }
359
360 // Handle a single unconditional branch.
361 if (NumTerminators == 1 && I->getDesc().isUnconditionalBranch()) {
363 return false;
364 }
365
366 // Handle a single conditional branch.
367 if (NumTerminators == 1 && I->getDesc().isConditionalBranch()) {
369 return false;
370 }
371
372 // Handle a conditional branch followed by an unconditional branch.
373 if (NumTerminators == 2 && std::prev(I)->getDesc().isConditionalBranch() &&
374 I->getDesc().isUnconditionalBranch()) {
375 parseCondBranch(*std::prev(I), TBB, Cond);
376 FBB = getBranchDestBlock(*I);
377 return false;
378 }
379
380 // Otherwise, we can't handle this.
381 return true;
382}
383
385 int64_t BrOffset) const {
386 switch (BranchOp) {
387 default:
388 llvm_unreachable("Unknown branch instruction!");
389 case LoongArch::BEQ:
390 case LoongArch::BNE:
391 case LoongArch::BLT:
392 case LoongArch::BGE:
393 case LoongArch::BLTU:
394 case LoongArch::BGEU:
395 return isInt<18>(BrOffset);
396 case LoongArch::BEQZ:
397 case LoongArch::BNEZ:
398 case LoongArch::BCEQZ:
399 case LoongArch::BCNEZ:
400 return isInt<23>(BrOffset);
401 case LoongArch::B:
402 case LoongArch::PseudoBR:
403 return isInt<28>(BrOffset);
404 }
405}
406
408 const MachineBasicBlock *MBB,
409 const MachineFunction &MF) const {
410 if (DisableRelocSched) {
411 for (const MachineOperand &MO : MI.operands())
412 if (MO.getTargetFlags())
413 return false;
414 }
415
416 auto MII = MI.getIterator();
417 auto MIE = MBB->end();
418
419 // According to psABI v2.30:
420 //
421 // https://github.com/loongson/la-abi-specs/releases/tag/v2.30
422 //
423 // The following instruction patterns are prohibited from being reordered:
424 //
425 // * pcalau12i $a0, %pc_hi20(s)
426 // addi.d $a1, $zero, %pc_lo12(s)
427 // lu32i.d $a1, %pc64_lo20(s)
428 // lu52i.d $a1, $a1, %pc64_hi12(s)
429 //
430 // * pcalau12i $a0, %got_pc_hi20(s) | %ld_pc_hi20(s) | %gd_pc_hi20(s)
431 // addi.d $a1, $zero, %got_pc_lo12(s)
432 // lu32i.d $a1, %got64_pc_lo20(s)
433 // lu52i.d $a1, $a1, %got64_pc_hi12(s)
434 //
435 // * pcalau12i $a0, %ie_pc_hi20(s)
436 // addi.d $a1, $zero, %ie_pc_lo12(s)
437 // lu32i.d $a1, %ie64_pc_lo20(s)
438 // lu52i.d $a1, $a1, %ie64_pc_hi12(s)
439 //
440 // * pcalau12i $a0, %desc_pc_hi20(s)
441 // addi.d $a1, $zero, %desc_pc_lo12(s)
442 // lu32i.d $a1, %desc64_pc_lo20(s)
443 // lu52i.d $a1, $a1, %desc64_pc_hi12(s)
444 //
445 // For simplicity, only pcalau12i and lu52i.d are marked as scheduling
446 // boundaries, and the instructions between them are guaranteed to be
447 // ordered according to data dependencies.
448 switch (MI.getOpcode()) {
449 case LoongArch::PCALAU12I: {
450 auto AddI = std::next(MII);
451 if (AddI == MIE || AddI->getOpcode() != LoongArch::ADDI_D)
452 break;
453 auto Lu32I = std::next(AddI);
454 if (Lu32I == MIE || Lu32I->getOpcode() != LoongArch::LU32I_D)
455 break;
456 auto MO0 = MI.getOperand(1).getTargetFlags();
457 auto MO1 = AddI->getOperand(2).getTargetFlags();
458 auto MO2 = Lu32I->getOperand(2).getTargetFlags();
461 return false;
463 MO0 == LoongArchII::MO_GD_PC_HI) &&
465 return false;
468 return false;
469 if (MO0 == LoongArchII::MO_DESC_PC_HI &&
472 return false;
473 break;
474 }
475 case LoongArch::LU52I_D: {
476 auto MO = MI.getOperand(2).getTargetFlags();
479 return false;
480 break;
481 }
482 default:
483 break;
484 }
485
486 const auto &STI = MF.getSubtarget<LoongArchSubtarget>();
487 if (STI.hasFeature(LoongArch::FeatureRelax)) {
488 // When linker relaxation enabled, the following instruction patterns are
489 // prohibited from being reordered:
490 //
491 // * pcalau12i $a0, %pc_hi20(s)
492 // addi.w/d $a0, $a0, %pc_lo12(s)
493 //
494 // * pcalau12i $a0, %got_pc_hi20(s)
495 // ld.w/d $a0, $a0, %got_pc_lo12(s)
496 //
497 // * pcalau12i $a0, %ld_pc_hi20(s) | %gd_pc_hi20(s)
498 // addi.w/d $a0, $a0, %got_pc_lo12(s)
499 //
500 // * pcalau12i $a0, %desc_pc_hi20(s)
501 // addi.w/d $a0, $a0, %desc_pc_lo12(s)
502 // ld.w/d $ra, $a0, %desc_ld(s)
503 // jirl $ra, $ra, %desc_call(s)
504 unsigned AddiOp = STI.is64Bit() ? LoongArch::ADDI_D : LoongArch::ADDI_W;
505 unsigned LdOp = STI.is64Bit() ? LoongArch::LD_D : LoongArch::LD_W;
506 switch (MI.getOpcode()) {
507 case LoongArch::PCALAU12I: {
508 auto MO0 = LoongArchII::getDirectFlags(MI.getOperand(1));
509 auto SecondOp = std::next(MII);
510 if (MO0 == LoongArchII::MO_DESC_PC_HI) {
511 if (SecondOp == MIE || SecondOp->getOpcode() != AddiOp)
512 break;
513 auto Ld = std::next(SecondOp);
514 if (Ld == MIE || Ld->getOpcode() != LdOp)
515 break;
516 auto MO1 = LoongArchII::getDirectFlags(SecondOp->getOperand(2));
517 auto MO2 = LoongArchII::getDirectFlags(Ld->getOperand(2));
519 return false;
520 break;
521 }
522 if (SecondOp == MIE ||
523 (SecondOp->getOpcode() != AddiOp && SecondOp->getOpcode() != LdOp))
524 break;
525 auto MO1 = LoongArchII::getDirectFlags(SecondOp->getOperand(2));
526 if (MO0 == LoongArchII::MO_PCREL_HI && SecondOp->getOpcode() == AddiOp &&
528 return false;
529 if (MO0 == LoongArchII::MO_GOT_PC_HI && SecondOp->getOpcode() == LdOp &&
531 return false;
532 if ((MO0 == LoongArchII::MO_LD_PC_HI ||
533 MO0 == LoongArchII::MO_GD_PC_HI) &&
534 SecondOp->getOpcode() == AddiOp && MO1 == LoongArchII::MO_GOT_PC_LO)
535 return false;
536 break;
537 }
538 case LoongArch::ADDI_W:
539 case LoongArch::ADDI_D: {
540 auto MO = LoongArchII::getDirectFlags(MI.getOperand(2));
542 return false;
543 break;
544 }
545 case LoongArch::LD_W:
546 case LoongArch::LD_D: {
547 auto MO = LoongArchII::getDirectFlags(MI.getOperand(2));
549 return false;
550 break;
551 }
552 case LoongArch::PseudoDESC_CALL: {
553 auto MO = LoongArchII::getDirectFlags(MI.getOperand(2));
555 return false;
556 break;
557 }
558 default:
559 break;
560 }
561 }
562
563 return true;
564}
565
567 const MachineBasicBlock *MBB,
568 const MachineFunction &MF) const {
570 return true;
571
572 if (!isSafeToMove(MI, MBB, MF))
573 return true;
574
575 return false;
576}
577
579 int *BytesRemoved) const {
580 if (BytesRemoved)
581 *BytesRemoved = 0;
582 MachineBasicBlock::iterator I = MBB.getLastNonDebugInstr();
583 if (I == MBB.end())
584 return 0;
585
586 if (!I->getDesc().isBranch())
587 return 0;
588
589 // Remove the branch.
590 if (BytesRemoved)
591 *BytesRemoved += getInstSizeInBytes(*I);
592 I->eraseFromParent();
593
594 I = MBB.end();
595
596 if (I == MBB.begin())
597 return 1;
598 --I;
599 if (!I->getDesc().isConditionalBranch())
600 return 1;
601
602 // Remove the branch.
603 if (BytesRemoved)
604 *BytesRemoved += getInstSizeInBytes(*I);
605 I->eraseFromParent();
606 return 2;
607}
608
609// Inserts a branch into the end of the specific MachineBasicBlock, returning
610// the number of instructions inserted.
613 ArrayRef<MachineOperand> Cond, const DebugLoc &DL, int *BytesAdded) const {
614 if (BytesAdded)
615 *BytesAdded = 0;
616
617 // Shouldn't be a fall through.
618 assert(TBB && "insertBranch must not be told to insert a fallthrough");
619 assert(Cond.size() <= 3 && Cond.size() != 1 &&
620 "LoongArch branch conditions have at most two components!");
621
622 // Unconditional branch.
623 if (Cond.empty()) {
624 MachineInstr &MI = *BuildMI(&MBB, DL, get(LoongArch::PseudoBR)).addMBB(TBB);
625 if (BytesAdded)
626 *BytesAdded += getInstSizeInBytes(MI);
627 return 1;
628 }
629
630 // Either a one or two-way conditional branch.
632 for (unsigned i = 1; i < Cond.size(); ++i)
633 MIB.add(Cond[i]);
634 MIB.addMBB(TBB);
635 if (BytesAdded)
636 *BytesAdded += getInstSizeInBytes(*MIB);
637
638 // One-way conditional branch.
639 if (!FBB)
640 return 1;
641
642 // Two-way conditional branch.
643 MachineInstr &MI = *BuildMI(&MBB, DL, get(LoongArch::PseudoBR)).addMBB(FBB);
644 if (BytesAdded)
645 *BytesAdded += getInstSizeInBytes(MI);
646 return 2;
647}
648
650 MachineBasicBlock &DestBB,
651 MachineBasicBlock &RestoreBB,
652 const DebugLoc &DL,
653 int64_t BrOffset,
654 RegScavenger *RS) const {
655 assert(RS && "RegScavenger required for long branching");
656 assert(MBB.empty() &&
657 "new block should be inserted for expanding unconditional branch");
658 assert(MBB.pred_size() == 1);
659
660 MachineFunction *MF = MBB.getParent();
661 MachineRegisterInfo &MRI = MF->getRegInfo();
665 bool Has32S = STI.hasFeature(LoongArch::Feature32S);
666
667 if (!isInt<32>(BrOffset))
669 "Branch offsets outside of the signed 32-bit range not supported");
670
671 Register ScratchReg = MRI.createVirtualRegister(&LoongArch::GPRRegClass);
672 MachineInstr *PCAI = nullptr;
673 MachineInstr *ADDI = nullptr;
674 auto II = MBB.end();
675 unsigned ADDIOp = STI.is64Bit() ? LoongArch::ADDI_D : LoongArch::ADDI_W;
676
677 if (Has32S) {
678 PCAI = BuildMI(MBB, II, DL, get(LoongArch::PCALAU12I), ScratchReg)
680 ADDI = BuildMI(MBB, II, DL, get(ADDIOp), ScratchReg)
681 .addReg(ScratchReg)
683 } else {
684 MCSymbol *PCAddSymbol = MF->getContext().createNamedTempSymbol("pcadd_hi");
685 PCAI = BuildMI(MBB, II, DL, get(LoongArch::PCADDU12I), ScratchReg)
687 PCAI->setPreInstrSymbol(*MF, PCAddSymbol);
688 ADDI = BuildMI(MBB, II, DL, get(ADDIOp), ScratchReg)
689 .addReg(ScratchReg)
690 .addSym(PCAddSymbol, LoongArchII::MO_PCADD_LO);
691 }
692 BuildMI(MBB, II, DL, get(LoongArch::PseudoBRIND))
693 .addReg(ScratchReg, RegState::Kill)
694 .addImm(0);
695
696 RS->enterBasicBlockEnd(MBB);
697 Register Scav = RS->scavengeRegisterBackwards(
698 LoongArch::GPRRegClass, PCAI->getIterator(), /*RestoreAfter=*/false,
699 /*SPAdj=*/0, /*AllowSpill=*/false);
700 if (Scav != LoongArch::NoRegister)
701 RS->setRegUsed(Scav);
702 else {
703 // When there is no scavenged register, it needs to specify a register.
704 // Specify t8 register because it won't be used too often.
705 Scav = LoongArch::R20;
706 int FrameIndex = LAFI->getBranchRelaxationSpillFrameIndex();
707 if (FrameIndex == -1)
708 report_fatal_error("The function size is incorrectly estimated.");
709 storeRegToStackSlot(MBB, PCAI, Scav, /*IsKill=*/true, FrameIndex,
710 &LoongArch::GPRRegClass, Register());
711 TRI->eliminateFrameIndex(std::prev(PCAI->getIterator()),
712 /*SpAdj=*/0, /*FIOperandNum=*/1);
713 PCAI->getOperand(1).setMBB(&RestoreBB);
714 if (Has32S)
715 ADDI->getOperand(2).setMBB(&RestoreBB);
716 loadRegFromStackSlot(RestoreBB, RestoreBB.end(), Scav, FrameIndex,
717 &LoongArch::GPRRegClass, Register());
718 TRI->eliminateFrameIndex(RestoreBB.back(),
719 /*SpAdj=*/0, /*FIOperandNum=*/1);
720 }
721 MRI.replaceRegWith(ScratchReg, Scav);
722 MRI.clearVirtRegs();
723}
724
725static unsigned getOppositeBranchOpc(unsigned Opc) {
726 switch (Opc) {
727 default:
728 llvm_unreachable("Unrecognized conditional branch");
729 case LoongArch::BEQ:
730 return LoongArch::BNE;
731 case LoongArch::BNE:
732 return LoongArch::BEQ;
733 case LoongArch::BEQZ:
734 return LoongArch::BNEZ;
735 case LoongArch::BNEZ:
736 return LoongArch::BEQZ;
737 case LoongArch::BCEQZ:
738 return LoongArch::BCNEZ;
739 case LoongArch::BCNEZ:
740 return LoongArch::BCEQZ;
741 case LoongArch::BLT:
742 return LoongArch::BGE;
743 case LoongArch::BGE:
744 return LoongArch::BLT;
745 case LoongArch::BLTU:
746 return LoongArch::BGEU;
747 case LoongArch::BGEU:
748 return LoongArch::BLTU;
749 }
750}
751
754 assert((Cond.size() && Cond.size() <= 3) && "Invalid branch condition!");
755 Cond[0].setImm(getOppositeBranchOpc(Cond[0].getImm()));
756 return false;
757}
758
759std::pair<unsigned, unsigned>
761 const unsigned Mask = LoongArchII::MO_DIRECT_FLAG_MASK;
762 return std::make_pair(TF & Mask, TF & ~Mask);
763}
764
767 using namespace LoongArchII;
768 // TODO: Add more target flags.
769 static const std::pair<unsigned, const char *> TargetFlags[] = {
770 {MO_CALL, "loongarch-call"},
771 {MO_CALL_PLT, "loongarch-call-plt"},
772 {MO_PCREL_HI, "loongarch-pcrel-hi"},
773 {MO_PCREL_LO, "loongarch-pcrel-lo"},
774 {MO_PCREL64_LO, "loongarch-pcrel64-lo"},
775 {MO_PCREL64_HI, "loongarch-pcrel64-hi"},
776 {MO_GOT_PC_HI, "loongarch-got-pc-hi"},
777 {MO_GOT_PC_LO, "loongarch-got-pc-lo"},
778 {MO_GOT_PC64_LO, "loongarch-got-pc64-lo"},
779 {MO_GOT_PC64_HI, "loongarch-got-pc64-hi"},
780 {MO_LE_HI, "loongarch-le-hi"},
781 {MO_LE_LO, "loongarch-le-lo"},
782 {MO_LE64_LO, "loongarch-le64-lo"},
783 {MO_LE64_HI, "loongarch-le64-hi"},
784 {MO_IE_PC_HI, "loongarch-ie-pc-hi"},
785 {MO_IE_PC_LO, "loongarch-ie-pc-lo"},
786 {MO_IE_PC64_LO, "loongarch-ie-pc64-lo"},
787 {MO_IE_PC64_HI, "loongarch-ie-pc64-hi"},
788 {MO_LD_PC_HI, "loongarch-ld-pc-hi"},
789 {MO_GD_PC_HI, "loongarch-gd-pc-hi"},
790 {MO_CALL30, "loongarch-call30"},
791 {MO_CALL36, "loongarch-call36"},
792 {MO_DESC_PC_HI, "loongarch-desc-pc-hi"},
793 {MO_DESC_PC_LO, "loongarch-desc-pc-lo"},
794 {MO_DESC64_PC_LO, "loongarch-desc64-pc-lo"},
795 {MO_DESC64_PC_HI, "loongarch-desc64-pc-hi"},
796 {MO_DESC_LD, "loongarch-desc-ld"},
797 {MO_DESC_CALL, "loongarch-desc-call"},
798 {MO_LE_HI_R, "loongarch-le-hi-r"},
799 {MO_LE_ADD_R, "loongarch-le-add-r"},
800 {MO_LE_LO_R, "loongarch-le-lo-r"},
801 {MO_PCADD_HI, "loongarch-pcadd-hi"},
802 {MO_PCADD_LO, "loongarch-pcadd-lo"},
803 {MO_GOT_PCADD_HI, "loongarch-got-pcadd-hi"},
804 {MO_GOT_PCADD_LO, "loongarch-got-pcadd-lo"},
805 {MO_IE_PCADD_HI, "loongarch-ie-pcadd-hi"},
806 {MO_IE_PCADD_LO, "loongarch-ie-pcadd-lo"},
807 {MO_LD_PCADD_HI, "loongarch-ld-pcadd-hi"},
808 {MO_LD_PCADD_LO, "loongarch-ld-pcadd-lo"},
809 {MO_GD_PCADD_HI, "loongarch-gd-pcadd-hi"},
810 {MO_GD_PCADD_LO, "loongarch-gd-pcadd-lo"},
811 {MO_DESC_PCADD_HI, "loongarch-pcadd-desc-hi"},
812 {MO_DESC_PCADD_LO, "loongarch-pcadd-desc-lo"}};
813 return ArrayRef(TargetFlags);
814}
815
818 using namespace LoongArchII;
819 static const std::pair<unsigned, const char *> TargetFlags[] = {
820 {MO_RELAX, "loongarch-relax"}};
821 return ArrayRef(TargetFlags);
822}
823
825 Register Reg,
826 const MachineInstr &AddrI,
827 ExtAddrMode &AM) const {
828 enum MemIOffsetType {
829 Imm14Shift2,
830 Imm12,
831 Imm11Shift1,
832 Imm10Shift2,
833 Imm9Shift3,
834 Imm8,
835 Imm8Shift1,
836 Imm8Shift2,
837 Imm8Shift3
838 };
839
840 MemIOffsetType OT;
841 switch (MemI.getOpcode()) {
842 default:
843 return false;
844 case LoongArch::LDPTR_W:
845 case LoongArch::LDPTR_D:
846 case LoongArch::STPTR_W:
847 case LoongArch::STPTR_D:
848 OT = Imm14Shift2;
849 break;
850 case LoongArch::LD_B:
851 case LoongArch::LD_H:
852 case LoongArch::LD_W:
853 case LoongArch::LD_D:
854 case LoongArch::LD_BU:
855 case LoongArch::LD_HU:
856 case LoongArch::LD_WU:
857 case LoongArch::ST_B:
858 case LoongArch::ST_H:
859 case LoongArch::ST_W:
860 case LoongArch::ST_D:
861 case LoongArch::FLD_S:
862 case LoongArch::FLD_D:
863 case LoongArch::FST_S:
864 case LoongArch::FST_D:
865 case LoongArch::VLD:
866 case LoongArch::VST:
867 case LoongArch::XVLD:
868 case LoongArch::XVST:
869 case LoongArch::VLDREPL_B:
870 case LoongArch::XVLDREPL_B:
871 OT = Imm12;
872 break;
873 case LoongArch::VLDREPL_H:
874 case LoongArch::XVLDREPL_H:
875 OT = Imm11Shift1;
876 break;
877 case LoongArch::VLDREPL_W:
878 case LoongArch::XVLDREPL_W:
879 OT = Imm10Shift2;
880 break;
881 case LoongArch::VLDREPL_D:
882 case LoongArch::XVLDREPL_D:
883 OT = Imm9Shift3;
884 break;
885 case LoongArch::VSTELM_B:
886 case LoongArch::XVSTELM_B:
887 OT = Imm8;
888 break;
889 case LoongArch::VSTELM_H:
890 case LoongArch::XVSTELM_H:
891 OT = Imm8Shift1;
892 break;
893 case LoongArch::VSTELM_W:
894 case LoongArch::XVSTELM_W:
895 OT = Imm8Shift2;
896 break;
897 case LoongArch::VSTELM_D:
898 case LoongArch::XVSTELM_D:
899 OT = Imm8Shift3;
900 break;
901 }
902
903 if (MemI.getOperand(0).getReg() == Reg)
904 return false;
905
906 if ((AddrI.getOpcode() != LoongArch::ADDI_W &&
907 AddrI.getOpcode() != LoongArch::ADDI_D) ||
908 !AddrI.getOperand(1).isReg() || !AddrI.getOperand(2).isImm())
909 return false;
910
911 int64_t OldOffset = MemI.getOperand(2).getImm();
912 int64_t Disp = AddrI.getOperand(2).getImm();
913 int64_t NewOffset = OldOffset + Disp;
914 if (!STI.is64Bit())
915 NewOffset = SignExtend64<32>(NewOffset);
916
917 if (!(OT == Imm14Shift2 && isShiftedInt<14, 2>(NewOffset) && STI.hasUAL()) &&
918 !(OT == Imm12 && isInt<12>(NewOffset)) &&
919 !(OT == Imm11Shift1 && isShiftedInt<11, 1>(NewOffset)) &&
920 !(OT == Imm10Shift2 && isShiftedInt<10, 2>(NewOffset)) &&
921 !(OT == Imm9Shift3 && isShiftedInt<9, 3>(NewOffset)) &&
922 !(OT == Imm8 && isInt<8>(NewOffset)) &&
923 !(OT == Imm8Shift1 && isShiftedInt<8, 1>(NewOffset)) &&
924 !(OT == Imm8Shift2 && isShiftedInt<8, 2>(NewOffset)) &&
925 !(OT == Imm8Shift3 && isShiftedInt<8, 3>(NewOffset)))
926 return false;
927
928 AM.BaseReg = AddrI.getOperand(1).getReg();
929 AM.ScaledReg = 0;
930 AM.Scale = 0;
931 AM.Displacement = NewOffset;
933 return true;
934}
935
938 const ExtAddrMode &AM) const {
939 const DebugLoc &DL = MemI.getDebugLoc();
941
942 assert(AM.ScaledReg == 0 && AM.Scale == 0 &&
943 "Addressing mode not supported for folding");
944
945 unsigned MemIOp = MemI.getOpcode();
946 switch (MemIOp) {
947 default:
948 return BuildMI(MBB, MemI, DL, get(MemIOp))
949 .addReg(MemI.getOperand(0).getReg(), getDefRegState(MemI.mayLoad()))
950 .addReg(AM.BaseReg)
952 .setMemRefs(MemI.memoperands())
953 .setMIFlags(MemI.getFlags());
954 case LoongArch::VSTELM_B:
955 case LoongArch::VSTELM_H:
956 case LoongArch::VSTELM_W:
957 case LoongArch::VSTELM_D:
958 case LoongArch::XVSTELM_B:
959 case LoongArch::XVSTELM_H:
960 case LoongArch::XVSTELM_W:
961 case LoongArch::XVSTELM_D:
962 return BuildMI(MBB, MemI, DL, get(MemIOp))
963 .addReg(MemI.getOperand(0).getReg())
964 .addReg(AM.BaseReg)
966 .addImm(MemI.getOperand(3).getImm())
967 .setMemRefs(MemI.memoperands())
968 .setMIFlags(MemI.getFlags());
969 }
970}
971
972// Returns true if this is the sext.w pattern, addi.w rd, rs, 0.
974 return MI.getOpcode() == LoongArch::ADDI_W && MI.getOperand(1).isReg() &&
975 MI.getOperand(2).isImm() && MI.getOperand(2).getImm() == 0;
976}
static void parseCondBranch(MachineInstr *LastInst, MachineBasicBlock *&Target, SmallVectorImpl< MachineOperand > &Cond)
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock & MBB
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
MachineBasicBlock MachineBasicBlock::iterator MBBI
static unsigned getOppositeBranchOpc(unsigned Opcode)
IRTranslator LLVM IR MI
static cl::opt< bool > DisableRelocSched("loongarch-disable-reloc-sched", cl::desc("Disable scheduling of instructions with target flags"), cl::init(false), cl::Hidden)
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
Register const TargetRegisterInfo * TRI
Promote Memory to Register
Definition Mem2Reg.cpp:110
uint64_t IntrinsicInst * II
const SmallVectorImpl< MachineOperand > MachineBasicBlock * TBB
const SmallVectorImpl< MachineOperand > & Cond
This file declares the machine register scavenger class.
static bool contains(SmallPtrSetImpl< ConstantExpr * > &Cache, ConstantExpr *Expr, Constant *C)
Definition Value.cpp:483
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
A debug info location.
Definition DebugLoc.h:123
void copyPhysReg(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, const DebugLoc &DL, Register DstReg, Register SrcReg, bool KillSrc, bool RenamableDest=false, bool RenamableSrc=false) const override
ArrayRef< std::pair< unsigned, const char * > > getSerializableBitmaskMachineOperandTargetFlags() const override
const LoongArchSubtarget & STI
bool reverseBranchCondition(SmallVectorImpl< MachineOperand > &Cond) const override
bool isSafeToMove(const MachineInstr &MI, const MachineBasicBlock *MBB, const MachineFunction &MF) const override
bool analyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB, MachineBasicBlock *&FBB, SmallVectorImpl< MachineOperand > &Cond, bool AllowModify) const override
void storeRegToStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, Register SrcReg, bool IsKill, int FrameIndex, const TargetRegisterClass *RC, Register VReg, MachineInstr::MIFlag Flags=MachineInstr::NoFlags) const override
std::pair< unsigned, unsigned > decomposeMachineOperandsTargetFlags(unsigned TF) const override
bool isAsCheapAsAMove(const MachineInstr &MI) const override
MCInst getNop() const override
LoongArchInstrInfo(const LoongArchSubtarget &STI)
ArrayRef< std::pair< unsigned, const char * > > getSerializableDirectMachineOperandTargetFlags() const override
unsigned removeBranch(MachineBasicBlock &MBB, int *BytesRemoved=nullptr) const override
void movImm(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, const DebugLoc &DL, Register DstReg, uint64_t Val, MachineInstr::MIFlag Flag=MachineInstr::NoFlags) const
unsigned insertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB, MachineBasicBlock *FBB, ArrayRef< MachineOperand > Cond, const DebugLoc &dl, int *BytesAdded=nullptr) const override
void insertIndirectBranch(MachineBasicBlock &MBB, MachineBasicBlock &NewDestBB, MachineBasicBlock &RestoreBB, const DebugLoc &DL, int64_t BrOffset, RegScavenger *RS) const override
void loadRegFromStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, Register DstReg, int FrameIndex, const TargetRegisterClass *RC, Register VReg, unsigned SubReg=0, MachineInstr::MIFlag Flags=MachineInstr::NoFlags) const override
bool isSchedulingBoundary(const MachineInstr &MI, const MachineBasicBlock *MBB, const MachineFunction &MF) const override
bool isBranchOffsetInRange(unsigned BranchOpc, int64_t BrOffset) const override
bool canFoldIntoAddrMode(const MachineInstr &MemI, Register Reg, const MachineInstr &AddrI, ExtAddrMode &AM) const override
unsigned getInstSizeInBytes(const MachineInstr &MI) const override
MachineBasicBlock * getBranchDestBlock(const MachineInstr &MI) const override
MachineInstr * emitLdStWithAddr(MachineInstr &MemI, const ExtAddrMode &AM) const override
LoongArchMachineFunctionInfo - This class is derived from MachineFunctionInfo and contains private Lo...
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition MCAsmInfo.h:64
LLVM_ABI MCSymbol * createNamedTempSymbol()
Create a temporary symbol with a unique name whose name cannot be omitted in the symbol table.
MCInstBuilder & addReg(MCRegister Reg)
Add a new register operand.
MCInstBuilder & addImm(int64_t Val)
Add a new integer immediate operand.
Instances of this class represent a single low-level machine instruction.
Definition MCInst.h:188
Describe properties that are true of each instruction in the target description file.
bool isConditionalBranch() const
Return true if this is a branch which may fall through to the next instruction or may transfer contro...
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition MCSymbol.h:42
MachineInstrBundleIterator< MachineInstr > iterator
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted.
Align getObjectAlign(int ObjectIdx) const
Return the alignment of the specified stack object.
int64_t getObjectSize(int ObjectIdx) const
Return the size of the specified object.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
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.
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
MCContext & getContext() const
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
Function & getFunction()
Return the LLVM function that this machine code represents.
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
const TargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
const MachineInstrBuilder & setMemRefs(ArrayRef< MachineMemOperand * > MMOs) const
const MachineInstrBuilder & addReg(Register RegNo, RegState Flags={}, unsigned SubReg=0) const
Add a new virtual register operand.
const MachineInstrBuilder & setMIFlag(MachineInstr::MIFlag Flag) const
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
const MachineInstrBuilder & add(const MachineOperand &MO) const
const MachineInstrBuilder & addSym(MCSymbol *Sym, unsigned char TargetFlags=0) const
const MachineInstrBuilder & addFrameIndex(int Idx) const
const MachineInstrBuilder & addMBB(MachineBasicBlock *MBB, unsigned TargetFlags=0) const
const MachineInstrBuilder & setMIFlags(unsigned Flags) const
const MachineInstrBuilder & addMemOperand(MachineMemOperand *MMO) const
reverse_iterator getReverse() const
Get a reverse iterator to the same node.
Representation of each machine instruction.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
const MachineBasicBlock * getParent() const
LLVM_ABI void setPreInstrSymbol(MachineFunction &MF, MCSymbol *Symbol)
Set a symbol that will be emitted just prior to the instruction itself.
LLVM_ABI unsigned getNumExplicitOperands() const
Returns the number of non-implicit operands.
bool mayLoad(QueryType Type=AnyInBundle) const
Return true if this instruction could possibly read memory.
const MCInstrDesc & getDesc() const
Returns the target instruction descriptor of this MachineInstr.
ArrayRef< MachineMemOperand * > memoperands() const
Access to memory operands of the instruction.
const DebugLoc & getDebugLoc() const
Returns the debug location id of this MachineInstr.
const MachineOperand & getOperand(unsigned i) const
uint32_t getFlags() const
Return the MI flags bitvector.
A description of a memory reference used in the backend.
@ MOLoad
The memory access reads data.
@ MOStore
The memory access writes data.
MachineOperand class - Representation of each machine instruction operand.
int64_t getImm() const
bool isReg() const
isReg - Tests if this is a MO_Register operand.
MachineBasicBlock * getMBB() const
bool isImm() const
isImm - Tests if this is a MO_Immediate operand.
void setMBB(MachineBasicBlock *MBB)
static MachineOperand CreateImm(int64_t Val)
Register getReg() const
getReg - Returns the register number.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
LLVM_ABI Register createVirtualRegister(const TargetRegisterClass *RegClass, StringRef Name="")
createVirtualRegister - Create and return a new virtual register in the function with the specified r...
LLVM_ABI void clearVirtRegs()
clearVirtRegs - Remove all virtual registers (after physreg assignment).
LLVM_ABI void replaceRegWith(Register FromReg, Register ToReg)
replaceRegWith - Replace all instances of FromReg with ToReg in the machine function.
Wrapper class representing virtual and physical registers.
Definition Register.h:20
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
MI-level Statepoint operands.
Definition StackMaps.h:159
uint32_t getNumPatchBytes() const
Return the number of patchable bytes the given statepoint should emit.
Definition StackMaps.h:208
virtual bool isSchedulingBoundary(const MachineInstr &MI, const MachineBasicBlock *MBB, const MachineFunction &MF) const
Test if the given instruction should be considered a scheduling boundary.
const MCAsmInfo * getMCAsmInfo() const
Return target specific asm information.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
virtual const TargetRegisterInfo * getRegisterInfo() const =0
Return the target's register information.
Target - Wrapper for Target specific information.
self_iterator getIterator()
Definition ilist_node.h:123
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
static unsigned getDirectFlags(const MachineOperand &MO)
InstSeq generateInstSeq(int64_t Val)
bool isSEXT_W(const MachineInstr &MI)
initializer< Ty > init(const Ty &Val)
This is an optimization pass for GlobalISel generic memory operations.
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
@ Kill
The last use of a register.
constexpr RegState getKillRegState(bool B)
Op::Description Desc
MachineInstr * getImm(const MachineOperand &MO, const MachineRegisterInfo *MRI)
decltype(auto) get(const PointerIntPair< PointerTy, IntBits, IntType, PtrTraits, Info > &Pair)
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
Definition Error.cpp:163
constexpr RegState getDefRegState(bool B)
ArrayRef(const T &OneElt) -> ArrayRef< T >
constexpr bool isShiftedInt(int64_t x)
Checks if a signed integer is an N bit number shifted left by S.
Definition MathExtras.h:182
constexpr int64_t SignExtend64(uint64_t x)
Sign-extend the number in the bottom B bits of X to a 64-bit integer.
Definition MathExtras.h:572
Used to describe addressing mode similar to ExtAddrMode in CodeGenPrepare.
static LLVM_ABI MachinePointerInfo getFixedStack(MachineFunction &MF, int FI, int64_t Offset=0)
Return a MachinePointerInfo record that refers to the specified FrameIndex.