LLVM 24.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
196 int &FrameIndex) const {
197 TypeSize Dummy = TypeSize::getZero();
198 return isLoadFromStackSlot(MI, FrameIndex, Dummy);
199}
200
202 int &FrameIndex,
203 TypeSize &MemBytes) const {
204 switch (MI.getOpcode()) {
205 default:
206 return Register();
207 case LoongArch::LD_W:
208 case LoongArch::FLD_S:
209 MemBytes = TypeSize::getFixed(4);
210 break;
211 case LoongArch::LD_D:
212 case LoongArch::FLD_D:
213 MemBytes = TypeSize::getFixed(8);
214 break;
215 case LoongArch::VLD:
216 MemBytes = TypeSize::getFixed(16);
217 break;
218 case LoongArch::XVLD:
219 MemBytes = TypeSize::getFixed(32);
220 break;
221 }
222
223 if ((MI.getOperand(1).isFI()) && // is a stack slot
224 (MI.getOperand(2).isImm()) && // the imm is zero
225 (MI.getOperand(2).getImm() == 0)) {
226 FrameIndex = MI.getOperand(1).getIndex();
227 return MI.getOperand(0).getReg();
228 }
229
230 return Register();
231}
232
234 int &FrameIndex) const {
235 TypeSize Dummy = TypeSize::getZero();
236 return isStoreToStackSlot(MI, FrameIndex, Dummy);
237}
238
240 int &FrameIndex,
241 TypeSize &MemBytes) const {
242 switch (MI.getOpcode()) {
243 default:
244 return Register();
245 case LoongArch::ST_W:
246 case LoongArch::FST_S:
247 MemBytes = TypeSize::getFixed(4);
248 break;
249 case LoongArch::ST_D:
250 case LoongArch::FST_D:
251 MemBytes = TypeSize::getFixed(8);
252 break;
253 case LoongArch::VST:
254 MemBytes = TypeSize::getFixed(16);
255 break;
256 case LoongArch::XVST:
257 MemBytes = TypeSize::getFixed(32);
258 break;
259 }
260
261 if ((MI.getOperand(1).isFI()) && // is a stack slot
262 (MI.getOperand(2).isImm()) && // the imm is zero
263 (MI.getOperand(2).getImm() == 0)) {
264 FrameIndex = MI.getOperand(1).getIndex();
265 return MI.getOperand(0).getReg();
266 }
267
268 return Register();
269}
270
273 const DebugLoc &DL, Register DstReg,
274 uint64_t Val, MachineInstr::MIFlag Flag) const {
275 Register SrcReg = LoongArch::R0;
276
277 if (!STI.is64Bit() && !isInt<32>(Val))
278 report_fatal_error("Should only materialize 32-bit constants for LA32");
279
280 auto Seq = LoongArchMatInt::generateInstSeq(Val);
281 assert(!Seq.empty());
282
283 for (auto &Inst : Seq) {
284 switch (Inst.Opc) {
285 case LoongArch::LU12I_W:
286 BuildMI(MBB, MBBI, DL, get(Inst.Opc), DstReg)
287 .addImm(Inst.Imm)
288 .setMIFlag(Flag);
289 break;
290 case LoongArch::ADDI_W:
291 case LoongArch::ORI:
292 case LoongArch::LU32I_D: // "rj" is needed due to InstrInfo pattern
293 case LoongArch::LU52I_D:
294 BuildMI(MBB, MBBI, DL, get(Inst.Opc), DstReg)
295 .addReg(SrcReg, RegState::Kill)
296 .addImm(Inst.Imm)
297 .setMIFlag(Flag);
298 break;
299 case LoongArch::BSTRINS_D:
300 BuildMI(MBB, MBBI, DL, get(Inst.Opc), DstReg)
301 .addReg(SrcReg, RegState::Kill)
302 .addReg(SrcReg, RegState::Kill)
303 .addImm(Inst.Imm >> 32)
304 .addImm(Inst.Imm & 0xFF)
305 .setMIFlag(Flag);
306 break;
307 default:
308 assert(false && "Unknown insn emitted by LoongArchMatInt");
309 }
310
311 // Only the first instruction has $zero as its source.
312 SrcReg = DstReg;
313 }
314}
315
317 unsigned Opcode = MI.getOpcode();
318
319 if (Opcode == TargetOpcode::INLINEASM ||
320 Opcode == TargetOpcode::INLINEASM_BR) {
321 const MachineFunction *MF = MI.getParent()->getParent();
322 const MCAsmInfo &MAI = MF->getTarget().getMCAsmInfo();
323 return getInlineAsmLength(MI.getOperand(0).getSymbolName(), MAI);
324 }
325
326 unsigned NumBytes = 0;
327 const MCInstrDesc &Desc = MI.getDesc();
328
329 // Size should be preferably set in
330 // llvm/lib/Target/LoongArch/LoongArch*InstrInfo.td (default case).
331 // Specific cases handle instructions of variable sizes.
332 switch (Desc.getOpcode()) {
333 default:
334 return Desc.getSize();
335 case TargetOpcode::STATEPOINT:
336 NumBytes = StatepointOpers(&MI).getNumPatchBytes();
337 assert(NumBytes % 4 == 0 && "Invalid number of NOP bytes requested!");
338 // No patch bytes means a normal call inst (i.e. `bl`) is emitted.
339 if (NumBytes == 0)
340 NumBytes = 4;
341 break;
342 case TargetOpcode::PATCHABLE_FUNCTION_ENTER: {
343 const MachineFunction *MF = MI.getParent()->getParent();
344 const Function &F = MF->getFunction();
345 if (F.hasFnAttribute("patchable-function-entry")) {
346 unsigned Num =
347 F.getFnAttributeAsParsedInteger("patchable-function-entry");
348 return Num * 4;
349 }
350 [[fallthrough]];
351 }
352 case TargetOpcode::PATCHABLE_FUNCTION_EXIT:
353 case TargetOpcode::PATCHABLE_TAIL_CALL:
354 // Size of xray sled (branch + 11 nops).
355 return 12 * 4;
356 case TargetOpcode::BUNDLE:
357 return getInstBundleSize(MI);
358 }
359 return NumBytes;
360}
361
363 const unsigned Opcode = MI.getOpcode();
364 switch (Opcode) {
365 default:
366 break;
367 case LoongArch::ADDI_D:
368 case LoongArch::ORI:
369 case LoongArch::XORI:
370 return (MI.getOperand(1).isReg() &&
371 MI.getOperand(1).getReg() == LoongArch::R0) ||
372 (MI.getOperand(2).isImm() && MI.getOperand(2).getImm() == 0);
373 }
374 return MI.isAsCheapAsAMove();
375}
376
377static bool isJumpTableLoad(const MachineInstr &MI) {
378 return any_of(MI.memoperands(), [](const MachineMemOperand *MMO) {
379 const PseudoSourceValue *PSV = MMO->getPseudoValue();
380 return PSV && PSV->isJumpTable();
381 });
382}
383
384// Return the index of the jump table whose address
385// (or an entry loaded from it) is held in Reg, or -1.
387 Register Reg) {
388 if (!Reg.isVirtual())
389 return -1;
390 const MachineInstr *MI = MRI.getUniqueVRegDef(Reg);
391 if (!MI)
392 return -1;
393
394 int JTI;
395 switch (MI->getOpcode()) {
396 case LoongArch::ADDI_D:
397 case LoongArch::ADDI_W:
398 case LoongArch::PseudoLA_PCREL:
399 for (const MachineOperand &MO : MI->operands())
400 if (MO.isJTI())
401 return MO.getIndex();
402 return -1;
403 case LoongArch::LDX_D:
404 case LoongArch::LDX_W:
405 // Normally, NonFIBaseAddr is corresponding to register $rj.
406 JTI = getJumpTableIndexFromReg(MRI, MI->getOperand(1).getReg());
407 if (JTI >= 0)
408 return JTI;
409 JTI = getJumpTableIndexFromReg(MRI, MI->getOperand(2).getReg());
410 if (JTI >= 0)
411 return JTI;
412 break;
413 default:
414 return -1;
415 }
416
417 return -1;
418}
419
420// LA32 do not support register offset load instrunctions (LDX),
421// so add another layer to get jump table address.
423 Register Reg) {
424 if (!Reg.isVirtual())
425 return -1;
426 const MachineInstr *MI = MRI.getUniqueVRegDef(Reg);
427 if (!MI)
428 return -1;
429
430 int JTI;
431 switch (MI->getOpcode()) {
432 case LoongArch::ADD_W:
433 JTI = getJumpTableIndexFromReg(MRI, MI->getOperand(1).getReg());
434 if (JTI >= 0)
435 return JTI;
436 JTI = getJumpTableIndexFromReg(MRI, MI->getOperand(2).getReg());
437 if (JTI >= 0)
438 return JTI;
439 break;
440 case LoongArch::ALSL_W:
441 // For la32s, address could only stores in register $rk.
442 return getJumpTableIndexFromReg(MRI, MI->getOperand(2).getReg());
443 }
444
445 return -1;
446}
447
448// Recursively search for %jump-table.N starting from PseudoBRIND,
449// and return the index of &jump-table.N
450//
451// One common jump table:
452//
453// %base = PseudoLA_PCREL %jump-table.N
454// %off = LDX_W %base, %index
455// %tgt = ADD_D %base, %off
456// %PseudoBRIND %tgt, 0
457//
459 if (MI.getOpcode() != LoongArch::PseudoBRIND)
460 return -1;
461
462 Register Reg = MI.getOperand(0).getReg();
463 if (!Reg.isVirtual())
464 return -1;
465
466 const MachineRegisterInfo &MRI = MI.getMF()->getRegInfo();
467 MachineInstr *Def = MRI.getUniqueVRegDef(Reg);
468 if (!Def)
469 return -1;
470
471 int JTI;
472 switch (Def->getOpcode()) {
473 case LoongArch::LD_W:
474 if (!isJumpTableLoad(*Def))
475 return -1;
476
477 JTI = getJumpTableIndexFromLoadAddr(MRI, Def->getOperand(1).getReg());
478 if (JTI >= 0)
479 return JTI;
480 break;
481 case LoongArch::ADD_D:
482 case LoongArch::ADD_W:
483 JTI = getJumpTableIndexFromReg(MRI, Def->getOperand(1).getReg());
484 if (JTI >= 0)
485 return JTI;
486 return getJumpTableIndexFromReg(MRI, Def->getOperand(2).getReg());
487 }
488
489 return getJumpTableIndexFromReg(MRI, Reg);
490}
491
494 assert(MI.getDesc().isBranch() && "Unexpected opcode!");
495 // The branch target is always the last operand.
496 return MI.getOperand(MI.getNumExplicitOperands() - 1).getMBB();
497}
498
501 // Block ends with fall-through condbranch.
502 assert(LastInst.getDesc().isConditionalBranch() &&
503 "Unknown conditional branch");
504 int NumOp = LastInst.getNumExplicitOperands();
505 Target = LastInst.getOperand(NumOp - 1).getMBB();
506
507 Cond.push_back(MachineOperand::CreateImm(LastInst.getOpcode()));
508 for (int i = 0; i < NumOp - 1; i++)
509 Cond.push_back(LastInst.getOperand(i));
510}
511
514 MachineBasicBlock *&FBB,
516 bool AllowModify) const {
517 TBB = FBB = nullptr;
518 Cond.clear();
519
520 // If the block has no terminators, it just falls into the block after it.
521 MachineBasicBlock::iterator I = MBB.getLastNonDebugInstr();
522 if (I == MBB.end() || !isUnpredicatedTerminator(*I))
523 return false;
524
525 // Count the number of terminators and find the first unconditional or
526 // indirect branch.
527 MachineBasicBlock::iterator FirstUncondOrIndirectBr = MBB.end();
528 int NumTerminators = 0;
529 for (auto J = I.getReverse(); J != MBB.rend() && isUnpredicatedTerminator(*J);
530 J++) {
531 NumTerminators++;
532 if (J->getDesc().isUnconditionalBranch() ||
533 J->getDesc().isIndirectBranch()) {
534 FirstUncondOrIndirectBr = J.getReverse();
535 }
536 }
537
538 // If AllowModify is true, we can erase any terminators after
539 // FirstUncondOrIndirectBR.
540 if (AllowModify && FirstUncondOrIndirectBr != MBB.end()) {
541 while (std::next(FirstUncondOrIndirectBr) != MBB.end()) {
542 std::next(FirstUncondOrIndirectBr)->eraseFromParent();
543 NumTerminators--;
544 }
545 I = FirstUncondOrIndirectBr;
546 }
547
548 // Handle a single unconditional branch.
549 if (NumTerminators == 1 && I->getDesc().isUnconditionalBranch()) {
551 return false;
552 }
553
554 // Handle a single conditional branch.
555 if (NumTerminators == 1 && I->getDesc().isConditionalBranch()) {
557 return false;
558 }
559
560 // Handle a conditional branch followed by an unconditional branch.
561 if (NumTerminators == 2 && std::prev(I)->getDesc().isConditionalBranch() &&
562 I->getDesc().isUnconditionalBranch()) {
563 parseCondBranch(*std::prev(I), TBB, Cond);
564 FBB = getBranchDestBlock(*I);
565 return false;
566 }
567
568 // Otherwise, we can't handle this.
569 return true;
570}
571
573 int64_t BrOffset) const {
574 switch (BranchOp) {
575 default:
576 llvm_unreachable("Unknown branch instruction!");
577 case LoongArch::BEQ:
578 case LoongArch::BNE:
579 case LoongArch::BLT:
580 case LoongArch::BGE:
581 case LoongArch::BLTU:
582 case LoongArch::BGEU:
583 return isInt<18>(BrOffset);
584 case LoongArch::BEQZ:
585 case LoongArch::BNEZ:
586 case LoongArch::BCEQZ:
587 case LoongArch::BCNEZ:
588 return isInt<23>(BrOffset);
589 case LoongArch::B:
590 case LoongArch::PseudoBR:
591 return isInt<28>(BrOffset);
592 }
593}
594
596 const MachineBasicBlock *MBB,
597 const MachineFunction &MF) const {
598 if (DisableRelocSched) {
599 for (const MachineOperand &MO : MI.operands())
600 if (MO.getTargetFlags())
601 return false;
602 }
603
604 auto MII = MI.getIterator();
605 auto MIE = MBB->end();
606
607 // According to psABI v2.30:
608 //
609 // https://github.com/loongson/la-abi-specs/releases/tag/v2.30
610 //
611 // The following instruction patterns are prohibited from being reordered:
612 //
613 // * pcalau12i $a0, %pc_hi20(s)
614 // addi.d $a1, $zero, %pc_lo12(s)
615 // lu32i.d $a1, %pc64_lo20(s)
616 // lu52i.d $a1, $a1, %pc64_hi12(s)
617 //
618 // * pcalau12i $a0, %got_pc_hi20(s) | %ld_pc_hi20(s) | %gd_pc_hi20(s)
619 // addi.d $a1, $zero, %got_pc_lo12(s)
620 // lu32i.d $a1, %got64_pc_lo20(s)
621 // lu52i.d $a1, $a1, %got64_pc_hi12(s)
622 //
623 // * pcalau12i $a0, %ie_pc_hi20(s)
624 // addi.d $a1, $zero, %ie_pc_lo12(s)
625 // lu32i.d $a1, %ie64_pc_lo20(s)
626 // lu52i.d $a1, $a1, %ie64_pc_hi12(s)
627 //
628 // * pcalau12i $a0, %desc_pc_hi20(s)
629 // addi.d $a1, $zero, %desc_pc_lo12(s)
630 // lu32i.d $a1, %desc64_pc_lo20(s)
631 // lu52i.d $a1, $a1, %desc64_pc_hi12(s)
632 //
633 // For simplicity, only pcalau12i and lu52i.d are marked as scheduling
634 // boundaries, and the instructions between them are guaranteed to be
635 // ordered according to data dependencies.
636 switch (MI.getOpcode()) {
637 case LoongArch::PCALAU12I: {
638 auto AddI = std::next(MII);
639 if (AddI == MIE || AddI->getOpcode() != LoongArch::ADDI_D)
640 break;
641 auto Lu32I = std::next(AddI);
642 if (Lu32I == MIE || Lu32I->getOpcode() != LoongArch::LU32I_D)
643 break;
644 auto MO0 = MI.getOperand(1).getTargetFlags();
645 auto MO1 = AddI->getOperand(2).getTargetFlags();
646 auto MO2 = Lu32I->getOperand(2).getTargetFlags();
649 return false;
651 MO0 == LoongArchII::MO_GD_PC_HI) &&
653 return false;
656 return false;
657 if (MO0 == LoongArchII::MO_DESC_PC_HI &&
660 return false;
661 break;
662 }
663 case LoongArch::LU52I_D: {
664 auto MO = MI.getOperand(2).getTargetFlags();
667 return false;
668 break;
669 }
670 default:
671 break;
672 }
673
674 const auto &STI = MF.getSubtarget<LoongArchSubtarget>();
675 if (STI.hasFeature(LoongArch::FeatureRelax)) {
676 // When linker relaxation enabled, the following instruction patterns are
677 // prohibited from being reordered:
678 //
679 // * pcalau12i $a0, %pc_hi20(s)
680 // addi.w/d $a0, $a0, %pc_lo12(s)
681 //
682 // * pcalau12i $a0, %got_pc_hi20(s)
683 // ld.w/d $a0, $a0, %got_pc_lo12(s)
684 //
685 // * pcalau12i $a0, %ld_pc_hi20(s) | %gd_pc_hi20(s)
686 // addi.w/d $a0, $a0, %got_pc_lo12(s)
687 //
688 // * pcalau12i $a0, %desc_pc_hi20(s)
689 // addi.w/d $a0, $a0, %desc_pc_lo12(s)
690 // ld.w/d $ra, $a0, %desc_ld(s)
691 // jirl $ra, $ra, %desc_call(s)
692 unsigned AddiOp = STI.is64Bit() ? LoongArch::ADDI_D : LoongArch::ADDI_W;
693 unsigned LdOp = STI.is64Bit() ? LoongArch::LD_D : LoongArch::LD_W;
694 switch (MI.getOpcode()) {
695 case LoongArch::PCALAU12I: {
696 auto MO0 = LoongArchII::getDirectFlags(MI.getOperand(1));
697 auto SecondOp = std::next(MII);
698 if (MO0 == LoongArchII::MO_DESC_PC_HI) {
699 if (SecondOp == MIE || SecondOp->getOpcode() != AddiOp)
700 break;
701 auto Ld = std::next(SecondOp);
702 if (Ld == MIE || Ld->getOpcode() != LdOp)
703 break;
704 auto MO1 = LoongArchII::getDirectFlags(SecondOp->getOperand(2));
705 auto MO2 = LoongArchII::getDirectFlags(Ld->getOperand(2));
707 return false;
708 break;
709 }
710 if (SecondOp == MIE ||
711 (SecondOp->getOpcode() != AddiOp && SecondOp->getOpcode() != LdOp))
712 break;
713 auto MO1 = LoongArchII::getDirectFlags(SecondOp->getOperand(2));
714 if (MO0 == LoongArchII::MO_PCREL_HI && SecondOp->getOpcode() == AddiOp &&
716 return false;
717 if (MO0 == LoongArchII::MO_GOT_PC_HI && SecondOp->getOpcode() == LdOp &&
719 return false;
720 if ((MO0 == LoongArchII::MO_LD_PC_HI ||
721 MO0 == LoongArchII::MO_GD_PC_HI) &&
722 SecondOp->getOpcode() == AddiOp && MO1 == LoongArchII::MO_GOT_PC_LO)
723 return false;
724 break;
725 }
726 case LoongArch::ADDI_W:
727 case LoongArch::ADDI_D: {
728 auto MO = LoongArchII::getDirectFlags(MI.getOperand(2));
730 return false;
731 break;
732 }
733 case LoongArch::LD_W:
734 case LoongArch::LD_D: {
735 auto MO = LoongArchII::getDirectFlags(MI.getOperand(2));
737 return false;
738 break;
739 }
740 case LoongArch::PseudoDESC_CALL: {
741 auto MO = LoongArchII::getDirectFlags(MI.getOperand(2));
743 return false;
744 break;
745 }
746 default:
747 break;
748 }
749 }
750
751 return true;
752}
753
755 const MachineBasicBlock *MBB,
756 const MachineFunction &MF) const {
758 return true;
759
760 if (!isSafeToMove(MI, MBB, MF))
761 return true;
762
763 return false;
764}
765
767 int *BytesRemoved) const {
768 if (BytesRemoved)
769 *BytesRemoved = 0;
770 MachineBasicBlock::iterator I = MBB.getLastNonDebugInstr();
771 if (I == MBB.end())
772 return 0;
773
774 if (!I->getDesc().isBranch())
775 return 0;
776
777 // Remove the branch.
778 if (BytesRemoved)
779 *BytesRemoved += getInstSizeInBytes(*I);
780 I->eraseFromParent();
781
782 I = MBB.end();
783
784 if (I == MBB.begin())
785 return 1;
786 --I;
787 if (!I->getDesc().isConditionalBranch())
788 return 1;
789
790 // Remove the branch.
791 if (BytesRemoved)
792 *BytesRemoved += getInstSizeInBytes(*I);
793 I->eraseFromParent();
794 return 2;
795}
796
797// Inserts a branch into the end of the specific MachineBasicBlock, returning
798// the number of instructions inserted.
801 ArrayRef<MachineOperand> Cond, const DebugLoc &DL, int *BytesAdded) const {
802 if (BytesAdded)
803 *BytesAdded = 0;
804
805 // Shouldn't be a fall through.
806 assert(TBB && "insertBranch must not be told to insert a fallthrough");
807 assert(Cond.size() <= 3 && Cond.size() != 1 &&
808 "LoongArch branch conditions have at most two components!");
809
810 // Unconditional branch.
811 if (Cond.empty()) {
812 MachineInstr &MI = *BuildMI(&MBB, DL, get(LoongArch::PseudoBR)).addMBB(TBB);
813 if (BytesAdded)
814 *BytesAdded += getInstSizeInBytes(MI);
815 return 1;
816 }
817
818 // Either a one or two-way conditional branch.
820 for (unsigned i = 1; i < Cond.size(); ++i)
821 MIB.add(Cond[i]);
822 MIB.addMBB(TBB);
823 if (BytesAdded)
824 *BytesAdded += getInstSizeInBytes(*MIB);
825
826 // One-way conditional branch.
827 if (!FBB)
828 return 1;
829
830 // Two-way conditional branch.
831 MachineInstr &MI = *BuildMI(&MBB, DL, get(LoongArch::PseudoBR)).addMBB(FBB);
832 if (BytesAdded)
833 *BytesAdded += getInstSizeInBytes(MI);
834 return 2;
835}
836
838 MachineBasicBlock &DestBB,
839 MachineBasicBlock &RestoreBB,
840 const DebugLoc &DL,
841 int64_t BrOffset,
842 RegScavenger *RS) const {
843 assert(RS && "RegScavenger required for long branching");
844 assert(MBB.empty() &&
845 "new block should be inserted for expanding unconditional branch");
846 assert(MBB.pred_size() == 1);
847
848 MachineFunction *MF = MBB.getParent();
849 MachineRegisterInfo &MRI = MF->getRegInfo();
853 bool Has32S = STI.hasFeature(LoongArch::Feature32S);
854
855 if (!isInt<32>(BrOffset))
857 "Branch offsets outside of the signed 32-bit range not supported");
858
859 Register ScratchReg = MRI.createVirtualRegister(&LoongArch::GPRRegClass);
860 MachineInstr *PCAI = nullptr;
861 MachineInstr *ADDI = nullptr;
862 auto II = MBB.end();
863 unsigned ADDIOp = STI.is64Bit() ? LoongArch::ADDI_D : LoongArch::ADDI_W;
864
865 if (Has32S) {
866 PCAI = BuildMI(MBB, II, DL, get(LoongArch::PCALAU12I), ScratchReg)
868 ADDI = BuildMI(MBB, II, DL, get(ADDIOp), ScratchReg)
869 .addReg(ScratchReg)
871 } else {
872 MCSymbol *PCAddSymbol = MF->getContext().createNamedTempSymbol("pcadd_hi");
873 PCAI = BuildMI(MBB, II, DL, get(LoongArch::PCADDU12I), ScratchReg)
875 PCAI->setPreInstrSymbol(*MF, PCAddSymbol);
876 ADDI = BuildMI(MBB, II, DL, get(ADDIOp), ScratchReg)
877 .addReg(ScratchReg)
878 .addSym(PCAddSymbol, LoongArchII::MO_PCADD_LO);
879 }
880 BuildMI(MBB, II, DL, get(LoongArch::PseudoBRIND))
881 .addReg(ScratchReg, RegState::Kill)
882 .addImm(0);
883
884 RS->enterBasicBlockEnd(MBB);
885 Register Scav = RS->scavengeRegisterBackwards(
886 LoongArch::GPRRegClass, PCAI->getIterator(), /*RestoreAfter=*/false,
887 /*SPAdj=*/0, /*AllowSpill=*/false);
888 if (Scav != LoongArch::NoRegister)
889 RS->setRegUsed(Scav);
890 else {
891 // When there is no scavenged register, it needs to specify a register.
892 // Specify t8 register because it won't be used too often.
893 Scav = LoongArch::R20;
894 int FrameIndex = LAFI->getBranchRelaxationSpillFrameIndex();
895 if (FrameIndex == -1)
896 report_fatal_error("The function size is incorrectly estimated.");
897 storeRegToStackSlot(MBB, PCAI, Scav, /*IsKill=*/true, FrameIndex,
898 &LoongArch::GPRRegClass, Register());
899 TRI->eliminateFrameIndex(std::prev(PCAI->getIterator()),
900 /*SpAdj=*/0, /*FIOperandNum=*/1);
901 PCAI->getOperand(1).setMBB(&RestoreBB);
902 if (Has32S)
903 ADDI->getOperand(2).setMBB(&RestoreBB);
904 loadRegFromStackSlot(RestoreBB, RestoreBB.end(), Scav, FrameIndex,
905 &LoongArch::GPRRegClass, Register());
906 TRI->eliminateFrameIndex(RestoreBB.back(),
907 /*SpAdj=*/0, /*FIOperandNum=*/1);
908 }
909 MRI.replaceRegWith(ScratchReg, Scav);
910 MRI.clearVirtRegs();
911}
912
913static unsigned getOppositeBranchOpc(unsigned Opc) {
914 switch (Opc) {
915 default:
916 llvm_unreachable("Unrecognized conditional branch");
917 case LoongArch::BEQ:
918 return LoongArch::BNE;
919 case LoongArch::BNE:
920 return LoongArch::BEQ;
921 case LoongArch::BEQZ:
922 return LoongArch::BNEZ;
923 case LoongArch::BNEZ:
924 return LoongArch::BEQZ;
925 case LoongArch::BCEQZ:
926 return LoongArch::BCNEZ;
927 case LoongArch::BCNEZ:
928 return LoongArch::BCEQZ;
929 case LoongArch::BLT:
930 return LoongArch::BGE;
931 case LoongArch::BGE:
932 return LoongArch::BLT;
933 case LoongArch::BLTU:
934 return LoongArch::BGEU;
935 case LoongArch::BGEU:
936 return LoongArch::BLTU;
937 }
938}
939
942 assert((Cond.size() && Cond.size() <= 3) && "Invalid branch condition!");
943 Cond[0].setImm(getOppositeBranchOpc(Cond[0].getImm()));
944 return false;
945}
946
947std::pair<unsigned, unsigned>
949 const unsigned Mask = LoongArchII::MO_DIRECT_FLAG_MASK;
950 return std::make_pair(TF & Mask, TF & ~Mask);
951}
952
955 using namespace LoongArchII;
956 // TODO: Add more target flags.
957 static const std::pair<unsigned, const char *> TargetFlags[] = {
958 {MO_CALL, "loongarch-call"},
959 {MO_CALL_PLT, "loongarch-call-plt"},
960 {MO_PCREL_HI, "loongarch-pcrel-hi"},
961 {MO_PCREL_LO, "loongarch-pcrel-lo"},
962 {MO_PCREL64_LO, "loongarch-pcrel64-lo"},
963 {MO_PCREL64_HI, "loongarch-pcrel64-hi"},
964 {MO_GOT_PC_HI, "loongarch-got-pc-hi"},
965 {MO_GOT_PC_LO, "loongarch-got-pc-lo"},
966 {MO_GOT_PC64_LO, "loongarch-got-pc64-lo"},
967 {MO_GOT_PC64_HI, "loongarch-got-pc64-hi"},
968 {MO_LE_HI, "loongarch-le-hi"},
969 {MO_LE_LO, "loongarch-le-lo"},
970 {MO_LE64_LO, "loongarch-le64-lo"},
971 {MO_LE64_HI, "loongarch-le64-hi"},
972 {MO_IE_PC_HI, "loongarch-ie-pc-hi"},
973 {MO_IE_PC_LO, "loongarch-ie-pc-lo"},
974 {MO_IE_PC64_LO, "loongarch-ie-pc64-lo"},
975 {MO_IE_PC64_HI, "loongarch-ie-pc64-hi"},
976 {MO_LD_PC_HI, "loongarch-ld-pc-hi"},
977 {MO_GD_PC_HI, "loongarch-gd-pc-hi"},
978 {MO_CALL30, "loongarch-call30"},
979 {MO_CALL36, "loongarch-call36"},
980 {MO_DESC_PC_HI, "loongarch-desc-pc-hi"},
981 {MO_DESC_PC_LO, "loongarch-desc-pc-lo"},
982 {MO_DESC64_PC_LO, "loongarch-desc64-pc-lo"},
983 {MO_DESC64_PC_HI, "loongarch-desc64-pc-hi"},
984 {MO_DESC_LD, "loongarch-desc-ld"},
985 {MO_DESC_CALL, "loongarch-desc-call"},
986 {MO_LE_HI_R, "loongarch-le-hi-r"},
987 {MO_LE_ADD_R, "loongarch-le-add-r"},
988 {MO_LE_LO_R, "loongarch-le-lo-r"},
989 {MO_PCADD_HI, "loongarch-pcadd-hi"},
990 {MO_PCADD_LO, "loongarch-pcadd-lo"},
991 {MO_GOT_PCADD_HI, "loongarch-got-pcadd-hi"},
992 {MO_GOT_PCADD_LO, "loongarch-got-pcadd-lo"},
993 {MO_IE_PCADD_HI, "loongarch-ie-pcadd-hi"},
994 {MO_IE_PCADD_LO, "loongarch-ie-pcadd-lo"},
995 {MO_LD_PCADD_HI, "loongarch-ld-pcadd-hi"},
996 {MO_LD_PCADD_LO, "loongarch-ld-pcadd-lo"},
997 {MO_GD_PCADD_HI, "loongarch-gd-pcadd-hi"},
998 {MO_GD_PCADD_LO, "loongarch-gd-pcadd-lo"},
999 {MO_DESC_PCADD_HI, "loongarch-pcadd-desc-hi"},
1000 {MO_DESC_PCADD_LO, "loongarch-pcadd-desc-lo"}};
1001 return ArrayRef(TargetFlags);
1002}
1003
1006 using namespace LoongArchII;
1007 static const std::pair<unsigned, const char *> TargetFlags[] = {
1008 {MO_RELAX, "loongarch-relax"}};
1009 return ArrayRef(TargetFlags);
1010}
1011
1013 Register Reg,
1014 const MachineInstr &AddrI,
1015 ExtAddrMode &AM) const {
1016 enum MemIOffsetType {
1017 Imm14Shift2,
1018 Imm12,
1019 Imm11Shift1,
1020 Imm10Shift2,
1021 Imm9Shift3,
1022 Imm8,
1023 Imm8Shift1,
1024 Imm8Shift2,
1025 Imm8Shift3
1026 };
1027
1028 MemIOffsetType OT;
1029 switch (MemI.getOpcode()) {
1030 default:
1031 return false;
1032 case LoongArch::LDPTR_W:
1033 case LoongArch::LDPTR_D:
1034 case LoongArch::STPTR_W:
1035 case LoongArch::STPTR_D:
1036 OT = Imm14Shift2;
1037 break;
1038 case LoongArch::LD_B:
1039 case LoongArch::LD_H:
1040 case LoongArch::LD_W:
1041 case LoongArch::LD_D:
1042 case LoongArch::LD_BU:
1043 case LoongArch::LD_HU:
1044 case LoongArch::LD_WU:
1045 case LoongArch::ST_B:
1046 case LoongArch::ST_H:
1047 case LoongArch::ST_W:
1048 case LoongArch::ST_D:
1049 case LoongArch::FLD_S:
1050 case LoongArch::FLD_D:
1051 case LoongArch::FST_S:
1052 case LoongArch::FST_D:
1053 case LoongArch::VLD:
1054 case LoongArch::VST:
1055 case LoongArch::XVLD:
1056 case LoongArch::XVST:
1057 case LoongArch::VLDREPL_B:
1058 case LoongArch::XVLDREPL_B:
1059 OT = Imm12;
1060 break;
1061 case LoongArch::VLDREPL_H:
1062 case LoongArch::XVLDREPL_H:
1063 OT = Imm11Shift1;
1064 break;
1065 case LoongArch::VLDREPL_W:
1066 case LoongArch::XVLDREPL_W:
1067 OT = Imm10Shift2;
1068 break;
1069 case LoongArch::VLDREPL_D:
1070 case LoongArch::XVLDREPL_D:
1071 OT = Imm9Shift3;
1072 break;
1073 case LoongArch::VSTELM_B:
1074 case LoongArch::XVSTELM_B:
1075 OT = Imm8;
1076 break;
1077 case LoongArch::VSTELM_H:
1078 case LoongArch::XVSTELM_H:
1079 OT = Imm8Shift1;
1080 break;
1081 case LoongArch::VSTELM_W:
1082 case LoongArch::XVSTELM_W:
1083 OT = Imm8Shift2;
1084 break;
1085 case LoongArch::VSTELM_D:
1086 case LoongArch::XVSTELM_D:
1087 OT = Imm8Shift3;
1088 break;
1089 }
1090
1091 if (MemI.getOperand(0).getReg() == Reg)
1092 return false;
1093
1094 if ((AddrI.getOpcode() != LoongArch::ADDI_W &&
1095 AddrI.getOpcode() != LoongArch::ADDI_D) ||
1096 !AddrI.getOperand(1).isReg() || !AddrI.getOperand(2).isImm())
1097 return false;
1098
1099 int64_t OldOffset = MemI.getOperand(2).getImm();
1100 int64_t Disp = AddrI.getOperand(2).getImm();
1101 int64_t NewOffset = OldOffset + Disp;
1102 if (!STI.is64Bit())
1103 NewOffset = SignExtend64<32>(NewOffset);
1104
1105 if (!(OT == Imm14Shift2 && isShiftedInt<14, 2>(NewOffset) && STI.hasUAL()) &&
1106 !(OT == Imm12 && isInt<12>(NewOffset)) &&
1107 !(OT == Imm11Shift1 && isShiftedInt<11, 1>(NewOffset)) &&
1108 !(OT == Imm10Shift2 && isShiftedInt<10, 2>(NewOffset)) &&
1109 !(OT == Imm9Shift3 && isShiftedInt<9, 3>(NewOffset)) &&
1110 !(OT == Imm8 && isInt<8>(NewOffset)) &&
1111 !(OT == Imm8Shift1 && isShiftedInt<8, 1>(NewOffset)) &&
1112 !(OT == Imm8Shift2 && isShiftedInt<8, 2>(NewOffset)) &&
1113 !(OT == Imm8Shift3 && isShiftedInt<8, 3>(NewOffset)))
1114 return false;
1115
1116 AM.BaseReg = AddrI.getOperand(1).getReg();
1117 AM.ScaledReg = 0;
1118 AM.Scale = 0;
1119 AM.Displacement = NewOffset;
1121 return true;
1122}
1123
1126 const ExtAddrMode &AM) const {
1127 const DebugLoc &DL = MemI.getDebugLoc();
1128 MachineBasicBlock &MBB = *MemI.getParent();
1129
1130 assert(AM.ScaledReg == 0 && AM.Scale == 0 &&
1131 "Addressing mode not supported for folding");
1132
1133 unsigned MemIOp = MemI.getOpcode();
1134 switch (MemIOp) {
1135 default:
1136 return BuildMI(MBB, MemI, DL, get(MemIOp))
1137 .addReg(MemI.getOperand(0).getReg(), getDefRegState(MemI.mayLoad()))
1138 .addReg(AM.BaseReg)
1139 .addImm(AM.Displacement)
1140 .setMemRefs(MemI.memoperands())
1141 .setMIFlags(MemI.getFlags());
1142 case LoongArch::VSTELM_B:
1143 case LoongArch::VSTELM_H:
1144 case LoongArch::VSTELM_W:
1145 case LoongArch::VSTELM_D:
1146 case LoongArch::XVSTELM_B:
1147 case LoongArch::XVSTELM_H:
1148 case LoongArch::XVSTELM_W:
1149 case LoongArch::XVSTELM_D:
1150 return BuildMI(MBB, MemI, DL, get(MemIOp))
1151 .addReg(MemI.getOperand(0).getReg())
1152 .addReg(AM.BaseReg)
1153 .addImm(AM.Displacement)
1154 .addImm(MemI.getOperand(3).getImm())
1155 .setMemRefs(MemI.memoperands())
1156 .setMIFlags(MemI.getFlags());
1157 }
1158}
1159
1160// Returns true if this is the sext.w pattern, addi.w rd, rs, 0.
1162 return MI.getOpcode() == LoongArch::ADDI_W && MI.getOperand(1).isReg() &&
1163 MI.getOperand(2).isImm() && MI.getOperand(2).getImm() == 0;
1164}
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)
static int getJumpTableIndexFromReg(const MachineRegisterInfo &MRI, Register Reg)
static int getJumpTableIndexFromLoadAddr(const MachineRegisterInfo &MRI, Register Reg)
static bool isJumpTableLoad(const MachineInstr &MI)
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
Register Reg
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:484
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:126
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
int getJumpTableIndex(const MachineInstr &MI) 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
Register isLoadFromStackSlot(const MachineInstr &MI, int &FrameIndex) 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
Register isStoreToStackSlot(const MachineInstr &MI, int &FrameIndex) 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:67
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.
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...
MachineMemOperand * getMachineMemOperand(MachinePointerInfo PtrInfo, MachineMemOperand::Flags F, LLT MemTy, Align BaseAlignment, const MMOMetadata &Metadata=MMOMetadata(), SyncScope::ID SSID=SyncScope::System, AtomicOrdering Ordering=AtomicOrdering::NotAtomic, AtomicOrdering FailureOrdering=AtomicOrdering::NotAtomic)
getMachineMemOperand - Allocate a new MachineMemOperand.
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.
LLVM_ABI LLVM_READONLY MachineInstr * getUniqueVRegDef(Register Reg) const
getUniqueVRegDef - Return the unique machine instr that defines the specified virtual register or nul...
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.
static constexpr TypeSize getFixed(ScalarTy ExactSize)
Definition TypeSize.h:339
static constexpr TypeSize getZero()
Definition TypeSize.h:345
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:166
@ Kill
The last use of a register.
constexpr RegState getKillRegState(bool B)
Op::Description Desc
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1762
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:183
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:567
MCRegisterClass TargetRegisterClass
Definition FastISel.h:58
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.