LLVM 20.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
22using namespace llvm;
23
24#define GET_INSTRINFO_CTOR_DTOR
25#include "LoongArchGenInstrInfo.inc"
26
28 : LoongArchGenInstrInfo(LoongArch::ADJCALLSTACKDOWN,
29 LoongArch::ADJCALLSTACKUP),
30 STI(STI) {}
31
33 return MCInstBuilder(LoongArch::ANDI)
34 .addReg(LoongArch::R0)
35 .addReg(LoongArch::R0)
36 .addImm(0);
37}
38
41 const DebugLoc &DL, MCRegister DstReg,
42 MCRegister SrcReg, bool KillSrc) const {
43 if (LoongArch::GPRRegClass.contains(DstReg, SrcReg)) {
44 BuildMI(MBB, MBBI, DL, get(LoongArch::OR), DstReg)
45 .addReg(SrcReg, getKillRegState(KillSrc))
46 .addReg(LoongArch::R0);
47 return;
48 }
49
50 // VR->VR copies.
51 if (LoongArch::LSX128RegClass.contains(DstReg, SrcReg)) {
52 BuildMI(MBB, MBBI, DL, get(LoongArch::VORI_B), DstReg)
53 .addReg(SrcReg, getKillRegState(KillSrc))
54 .addImm(0);
55 return;
56 }
57
58 // XR->XR copies.
59 if (LoongArch::LASX256RegClass.contains(DstReg, SrcReg)) {
60 BuildMI(MBB, MBBI, DL, get(LoongArch::XVORI_B), DstReg)
61 .addReg(SrcReg, getKillRegState(KillSrc))
62 .addImm(0);
63 return;
64 }
65
66 // GPR->CFR copy.
67 if (LoongArch::CFRRegClass.contains(DstReg) &&
68 LoongArch::GPRRegClass.contains(SrcReg)) {
69 BuildMI(MBB, MBBI, DL, get(LoongArch::MOVGR2CF), DstReg)
70 .addReg(SrcReg, getKillRegState(KillSrc));
71 return;
72 }
73 // CFR->GPR copy.
74 if (LoongArch::GPRRegClass.contains(DstReg) &&
75 LoongArch::CFRRegClass.contains(SrcReg)) {
76 BuildMI(MBB, MBBI, DL, get(LoongArch::MOVCF2GR), DstReg)
77 .addReg(SrcReg, getKillRegState(KillSrc));
78 return;
79 }
80 // CFR->CFR copy.
81 if (LoongArch::CFRRegClass.contains(DstReg, SrcReg)) {
82 BuildMI(MBB, MBBI, DL, get(LoongArch::PseudoCopyCFR), DstReg)
83 .addReg(SrcReg, getKillRegState(KillSrc));
84 return;
85 }
86
87 // FPR->FPR copies.
88 unsigned Opc;
89 if (LoongArch::FPR32RegClass.contains(DstReg, SrcReg)) {
90 Opc = LoongArch::FMOV_S;
91 } else if (LoongArch::FPR64RegClass.contains(DstReg, SrcReg)) {
92 Opc = LoongArch::FMOV_D;
93 } else if (LoongArch::GPRRegClass.contains(DstReg) &&
94 LoongArch::FPR32RegClass.contains(SrcReg)) {
95 // FPR32 -> GPR copies
96 Opc = LoongArch::MOVFR2GR_S;
97 } else if (LoongArch::GPRRegClass.contains(DstReg) &&
98 LoongArch::FPR64RegClass.contains(SrcReg)) {
99 // FPR64 -> GPR copies
100 Opc = LoongArch::MOVFR2GR_D;
101 } else {
102 // TODO: support other copies.
103 llvm_unreachable("Impossible reg-to-reg copy");
104 }
105
106 BuildMI(MBB, MBBI, DL, get(Opc), DstReg)
107 .addReg(SrcReg, getKillRegState(KillSrc));
108}
109
112 bool IsKill, int FI, const TargetRegisterClass *RC,
113 const TargetRegisterInfo *TRI, Register VReg) const {
115 MachineFrameInfo &MFI = MF->getFrameInfo();
116
117 unsigned Opcode;
118 if (LoongArch::GPRRegClass.hasSubClassEq(RC))
119 Opcode = TRI->getRegSizeInBits(LoongArch::GPRRegClass) == 32
120 ? LoongArch::ST_W
121 : LoongArch::ST_D;
122 else if (LoongArch::FPR32RegClass.hasSubClassEq(RC))
123 Opcode = LoongArch::FST_S;
124 else if (LoongArch::FPR64RegClass.hasSubClassEq(RC))
125 Opcode = LoongArch::FST_D;
126 else if (LoongArch::LSX128RegClass.hasSubClassEq(RC))
127 Opcode = LoongArch::VST;
128 else if (LoongArch::LASX256RegClass.hasSubClassEq(RC))
129 Opcode = LoongArch::XVST;
130 else if (LoongArch::CFRRegClass.hasSubClassEq(RC))
131 Opcode = LoongArch::PseudoST_CFR;
132 else
133 llvm_unreachable("Can't store this register to stack slot");
134
137 MFI.getObjectSize(FI), MFI.getObjectAlign(FI));
138
139 BuildMI(MBB, I, DebugLoc(), get(Opcode))
140 .addReg(SrcReg, getKillRegState(IsKill))
141 .addFrameIndex(FI)
142 .addImm(0)
143 .addMemOperand(MMO);
144}
145
148 Register DstReg, int FI,
149 const TargetRegisterClass *RC,
150 const TargetRegisterInfo *TRI,
151 Register VReg) const {
153 MachineFrameInfo &MFI = MF->getFrameInfo();
154
155 unsigned Opcode;
156 if (LoongArch::GPRRegClass.hasSubClassEq(RC))
157 Opcode = TRI->getRegSizeInBits(LoongArch::GPRRegClass) == 32
158 ? LoongArch::LD_W
159 : LoongArch::LD_D;
160 else if (LoongArch::FPR32RegClass.hasSubClassEq(RC))
161 Opcode = LoongArch::FLD_S;
162 else if (LoongArch::FPR64RegClass.hasSubClassEq(RC))
163 Opcode = LoongArch::FLD_D;
164 else if (LoongArch::LSX128RegClass.hasSubClassEq(RC))
165 Opcode = LoongArch::VLD;
166 else if (LoongArch::LASX256RegClass.hasSubClassEq(RC))
167 Opcode = LoongArch::XVLD;
168 else if (LoongArch::CFRRegClass.hasSubClassEq(RC))
169 Opcode = LoongArch::PseudoLD_CFR;
170 else
171 llvm_unreachable("Can't load this register from stack slot");
172
175 MFI.getObjectSize(FI), MFI.getObjectAlign(FI));
176
177 BuildMI(MBB, I, DebugLoc(), get(Opcode), DstReg)
178 .addFrameIndex(FI)
179 .addImm(0)
180 .addMemOperand(MMO);
181}
182
185 const DebugLoc &DL, Register DstReg,
186 uint64_t Val, MachineInstr::MIFlag Flag) const {
187 Register SrcReg = LoongArch::R0;
188
189 if (!STI.is64Bit() && !isInt<32>(Val))
190 report_fatal_error("Should only materialize 32-bit constants for LA32");
191
192 auto Seq = LoongArchMatInt::generateInstSeq(Val);
193 assert(!Seq.empty());
194
195 for (auto &Inst : Seq) {
196 switch (Inst.Opc) {
197 case LoongArch::LU12I_W:
198 BuildMI(MBB, MBBI, DL, get(Inst.Opc), DstReg)
199 .addImm(Inst.Imm)
200 .setMIFlag(Flag);
201 break;
202 case LoongArch::ADDI_W:
203 case LoongArch::ORI:
204 case LoongArch::LU32I_D: // "rj" is needed due to InstrInfo pattern
205 case LoongArch::LU52I_D:
206 BuildMI(MBB, MBBI, DL, get(Inst.Opc), DstReg)
207 .addReg(SrcReg, RegState::Kill)
208 .addImm(Inst.Imm)
209 .setMIFlag(Flag);
210 break;
211 default:
212 assert(false && "Unknown insn emitted by LoongArchMatInt");
213 }
214
215 // Only the first instruction has $zero as its source.
216 SrcReg = DstReg;
217 }
218}
219
221 unsigned Opcode = MI.getOpcode();
222
223 if (Opcode == TargetOpcode::INLINEASM ||
224 Opcode == TargetOpcode::INLINEASM_BR) {
225 const MachineFunction *MF = MI.getParent()->getParent();
226 const MCAsmInfo *MAI = MF->getTarget().getMCAsmInfo();
227 return getInlineAsmLength(MI.getOperand(0).getSymbolName(), *MAI);
228 }
229 return MI.getDesc().getSize();
230}
231
233 const unsigned Opcode = MI.getOpcode();
234 switch (Opcode) {
235 default:
236 break;
237 case LoongArch::ADDI_D:
238 case LoongArch::ORI:
239 case LoongArch::XORI:
240 return (MI.getOperand(1).isReg() &&
241 MI.getOperand(1).getReg() == LoongArch::R0) ||
242 (MI.getOperand(2).isImm() && MI.getOperand(2).getImm() == 0);
243 }
244 return MI.isAsCheapAsAMove();
245}
246
249 assert(MI.getDesc().isBranch() && "Unexpected opcode!");
250 // The branch target is always the last operand.
251 return MI.getOperand(MI.getNumExplicitOperands() - 1).getMBB();
252}
253
256 // Block ends with fall-through condbranch.
257 assert(LastInst.getDesc().isConditionalBranch() &&
258 "Unknown conditional branch");
259 int NumOp = LastInst.getNumExplicitOperands();
260 Target = LastInst.getOperand(NumOp - 1).getMBB();
261
262 Cond.push_back(MachineOperand::CreateImm(LastInst.getOpcode()));
263 for (int i = 0; i < NumOp - 1; i++)
264 Cond.push_back(LastInst.getOperand(i));
265}
266
269 MachineBasicBlock *&FBB,
271 bool AllowModify) const {
272 TBB = FBB = nullptr;
273 Cond.clear();
274
275 // If the block has no terminators, it just falls into the block after it.
277 if (I == MBB.end() || !isUnpredicatedTerminator(*I))
278 return false;
279
280 // Count the number of terminators and find the first unconditional or
281 // indirect branch.
282 MachineBasicBlock::iterator FirstUncondOrIndirectBr = MBB.end();
283 int NumTerminators = 0;
284 for (auto J = I.getReverse(); J != MBB.rend() && isUnpredicatedTerminator(*J);
285 J++) {
286 NumTerminators++;
287 if (J->getDesc().isUnconditionalBranch() ||
288 J->getDesc().isIndirectBranch()) {
289 FirstUncondOrIndirectBr = J.getReverse();
290 }
291 }
292
293 // If AllowModify is true, we can erase any terminators after
294 // FirstUncondOrIndirectBR.
295 if (AllowModify && FirstUncondOrIndirectBr != MBB.end()) {
296 while (std::next(FirstUncondOrIndirectBr) != MBB.end()) {
297 std::next(FirstUncondOrIndirectBr)->eraseFromParent();
298 NumTerminators--;
299 }
300 I = FirstUncondOrIndirectBr;
301 }
302
303 // Handle a single unconditional branch.
304 if (NumTerminators == 1 && I->getDesc().isUnconditionalBranch()) {
306 return false;
307 }
308
309 // Handle a single conditional branch.
310 if (NumTerminators == 1 && I->getDesc().isConditionalBranch()) {
312 return false;
313 }
314
315 // Handle a conditional branch followed by an unconditional branch.
316 if (NumTerminators == 2 && std::prev(I)->getDesc().isConditionalBranch() &&
317 I->getDesc().isUnconditionalBranch()) {
318 parseCondBranch(*std::prev(I), TBB, Cond);
319 FBB = getBranchDestBlock(*I);
320 return false;
321 }
322
323 // Otherwise, we can't handle this.
324 return true;
325}
326
328 int64_t BrOffset) const {
329 switch (BranchOp) {
330 default:
331 llvm_unreachable("Unknown branch instruction!");
332 case LoongArch::BEQ:
333 case LoongArch::BNE:
334 case LoongArch::BLT:
335 case LoongArch::BGE:
336 case LoongArch::BLTU:
337 case LoongArch::BGEU:
338 return isInt<18>(BrOffset);
339 case LoongArch::BEQZ:
340 case LoongArch::BNEZ:
341 case LoongArch::BCEQZ:
342 case LoongArch::BCNEZ:
343 return isInt<23>(BrOffset);
344 case LoongArch::B:
345 case LoongArch::PseudoBR:
346 return isInt<28>(BrOffset);
347 }
348}
349
351 const MachineBasicBlock *MBB,
352 const MachineFunction &MF) const {
354 return true;
355
356 auto MII = MI.getIterator();
357 auto MIE = MBB->end();
358
359 // According to psABI v2.30:
360 //
361 // https://github.com/loongson/la-abi-specs/releases/tag/v2.30
362 //
363 // The following instruction patterns are prohibited from being reordered:
364 //
365 // * pcaddu18 $ra, %call36(s)
366 // jirl $ra, $ra, 0
367 //
368 // * pcalau12i $a0, %pc_hi20(s)
369 // addi.d $a1, $zero, %pc_lo12(s)
370 // lu32i.d $a1, %pc64_lo20(s)
371 // lu52i.d $a1, $a1, %pc64_hi12(s)
372 //
373 // * pcalau12i $a0, %got_pc_hi20(s) | %ld_pc_hi20(s) | %gd_pc_hi20(s)
374 // addi.d $a1, $zero, %got_pc_lo12(s)
375 // lu32i.d $a1, %got64_pc_lo20(s)
376 // lu52i.d $a1, $a1, %got64_pc_hi12(s)
377 //
378 // * pcalau12i $a0, %ie_pc_hi20(s)
379 // addi.d $a1, $zero, %ie_pc_lo12(s)
380 // lu32i.d $a1, %ie64_pc_lo20(s)
381 // lu52i.d $a1, $a1, %ie64_pc_hi12(s)
382 //
383 // For simplicity, only pcalau12i and lu52i.d are marked as scheduling
384 // boundaries, and the instructions between them are guaranteed to be
385 // ordered according to data dependencies.
386 switch (MI.getOpcode()) {
387 case LoongArch::PCADDU18I:
388 if (MI.getOperand(1).getTargetFlags() == LoongArchII::MO_CALL36)
389 return true;
390 break;
391 case LoongArch::PCALAU12I: {
392 auto AddI = std::next(MII);
393 if (AddI == MIE || AddI->getOpcode() != LoongArch::ADDI_D)
394 break;
395 auto Lu32I = std::next(AddI);
396 if (Lu32I == MIE || Lu32I->getOpcode() != LoongArch::LU32I_D)
397 break;
398 auto MO0 = MI.getOperand(1).getTargetFlags();
399 auto MO1 = AddI->getOperand(2).getTargetFlags();
400 auto MO2 = Lu32I->getOperand(2).getTargetFlags();
403 return true;
405 MO0 == LoongArchII::MO_GD_PC_HI) &&
407 return true;
410 return true;
411 break;
412 }
413 case LoongArch::LU52I_D: {
414 auto MO = MI.getOperand(2).getTargetFlags();
417 return true;
418 break;
419 }
420 default:
421 break;
422 }
423
424 return false;
425}
426
428 int *BytesRemoved) const {
429 if (BytesRemoved)
430 *BytesRemoved = 0;
432 if (I == MBB.end())
433 return 0;
434
435 if (!I->getDesc().isBranch())
436 return 0;
437
438 // Remove the branch.
439 if (BytesRemoved)
440 *BytesRemoved += getInstSizeInBytes(*I);
441 I->eraseFromParent();
442
443 I = MBB.end();
444
445 if (I == MBB.begin())
446 return 1;
447 --I;
448 if (!I->getDesc().isConditionalBranch())
449 return 1;
450
451 // Remove the branch.
452 if (BytesRemoved)
453 *BytesRemoved += getInstSizeInBytes(*I);
454 I->eraseFromParent();
455 return 2;
456}
457
458// Inserts a branch into the end of the specific MachineBasicBlock, returning
459// the number of instructions inserted.
462 ArrayRef<MachineOperand> Cond, const DebugLoc &DL, int *BytesAdded) const {
463 if (BytesAdded)
464 *BytesAdded = 0;
465
466 // Shouldn't be a fall through.
467 assert(TBB && "insertBranch must not be told to insert a fallthrough");
468 assert(Cond.size() <= 3 && Cond.size() != 1 &&
469 "LoongArch branch conditions have at most two components!");
470
471 // Unconditional branch.
472 if (Cond.empty()) {
473 MachineInstr &MI = *BuildMI(&MBB, DL, get(LoongArch::PseudoBR)).addMBB(TBB);
474 if (BytesAdded)
475 *BytesAdded += getInstSizeInBytes(MI);
476 return 1;
477 }
478
479 // Either a one or two-way conditional branch.
480 MachineInstrBuilder MIB = BuildMI(&MBB, DL, get(Cond[0].getImm()));
481 for (unsigned i = 1; i < Cond.size(); ++i)
482 MIB.add(Cond[i]);
483 MIB.addMBB(TBB);
484 if (BytesAdded)
485 *BytesAdded += getInstSizeInBytes(*MIB);
486
487 // One-way conditional branch.
488 if (!FBB)
489 return 1;
490
491 // Two-way conditional branch.
492 MachineInstr &MI = *BuildMI(&MBB, DL, get(LoongArch::PseudoBR)).addMBB(FBB);
493 if (BytesAdded)
494 *BytesAdded += getInstSizeInBytes(MI);
495 return 2;
496}
497
499 MachineBasicBlock &DestBB,
500 MachineBasicBlock &RestoreBB,
501 const DebugLoc &DL,
502 int64_t BrOffset,
503 RegScavenger *RS) const {
504 assert(RS && "RegScavenger required for long branching");
505 assert(MBB.empty() &&
506 "new block should be inserted for expanding unconditional branch");
507 assert(MBB.pred_size() == 1);
508
514
515 if (!isInt<32>(BrOffset))
517 "Branch offsets outside of the signed 32-bit range not supported");
518
519 Register ScratchReg = MRI.createVirtualRegister(&LoongArch::GPRRegClass);
520 auto II = MBB.end();
521
522 MachineInstr &PCALAU12I =
523 *BuildMI(MBB, II, DL, get(LoongArch::PCALAU12I), ScratchReg)
525 MachineInstr &ADDI =
526 *BuildMI(MBB, II, DL,
527 get(STI.is64Bit() ? LoongArch::ADDI_D : LoongArch::ADDI_W),
528 ScratchReg)
529 .addReg(ScratchReg)
531 BuildMI(MBB, II, DL, get(LoongArch::PseudoBRIND))
532 .addReg(ScratchReg, RegState::Kill)
533 .addImm(0);
534
537 LoongArch::GPRRegClass, PCALAU12I.getIterator(), /*RestoreAfter=*/false,
538 /*SPAdj=*/0, /*AllowSpill=*/false);
539 if (Scav != LoongArch::NoRegister)
540 RS->setRegUsed(Scav);
541 else {
542 // When there is no scavenged register, it needs to specify a register.
543 // Specify t8 register because it won't be used too often.
544 Scav = LoongArch::R20;
545 int FrameIndex = LAFI->getBranchRelaxationSpillFrameIndex();
546 if (FrameIndex == -1)
547 report_fatal_error("The function size is incorrectly estimated.");
548 storeRegToStackSlot(MBB, PCALAU12I, Scav, /*IsKill=*/true, FrameIndex,
549 &LoongArch::GPRRegClass, TRI, Register());
550 TRI->eliminateFrameIndex(std::prev(PCALAU12I.getIterator()),
551 /*SpAdj=*/0, /*FIOperandNum=*/1);
552 PCALAU12I.getOperand(1).setMBB(&RestoreBB);
553 ADDI.getOperand(2).setMBB(&RestoreBB);
554 loadRegFromStackSlot(RestoreBB, RestoreBB.end(), Scav, FrameIndex,
555 &LoongArch::GPRRegClass, TRI, Register());
556 TRI->eliminateFrameIndex(RestoreBB.back(),
557 /*SpAdj=*/0, /*FIOperandNum=*/1);
558 }
559 MRI.replaceRegWith(ScratchReg, Scav);
560 MRI.clearVirtRegs();
561}
562
563static unsigned getOppositeBranchOpc(unsigned Opc) {
564 switch (Opc) {
565 default:
566 llvm_unreachable("Unrecognized conditional branch");
567 case LoongArch::BEQ:
568 return LoongArch::BNE;
569 case LoongArch::BNE:
570 return LoongArch::BEQ;
571 case LoongArch::BEQZ:
572 return LoongArch::BNEZ;
573 case LoongArch::BNEZ:
574 return LoongArch::BEQZ;
575 case LoongArch::BCEQZ:
576 return LoongArch::BCNEZ;
577 case LoongArch::BCNEZ:
578 return LoongArch::BCEQZ;
579 case LoongArch::BLT:
580 return LoongArch::BGE;
581 case LoongArch::BGE:
582 return LoongArch::BLT;
583 case LoongArch::BLTU:
584 return LoongArch::BGEU;
585 case LoongArch::BGEU:
586 return LoongArch::BLTU;
587 }
588}
589
592 assert((Cond.size() && Cond.size() <= 3) && "Invalid branch condition!");
593 Cond[0].setImm(getOppositeBranchOpc(Cond[0].getImm()));
594 return false;
595}
596
597std::pair<unsigned, unsigned>
599 return std::make_pair(TF, 0u);
600}
601
604 using namespace LoongArchII;
605 // TODO: Add more target flags.
606 static const std::pair<unsigned, const char *> TargetFlags[] = {
607 {MO_CALL, "loongarch-call"},
608 {MO_CALL_PLT, "loongarch-call-plt"},
609 {MO_PCREL_HI, "loongarch-pcrel-hi"},
610 {MO_PCREL_LO, "loongarch-pcrel-lo"},
611 {MO_PCREL64_LO, "loongarch-pcrel64-lo"},
612 {MO_PCREL64_HI, "loongarch-pcrel64-hi"},
613 {MO_GOT_PC_HI, "loongarch-got-pc-hi"},
614 {MO_GOT_PC_LO, "loongarch-got-pc-lo"},
615 {MO_GOT_PC64_LO, "loongarch-got-pc64-lo"},
616 {MO_GOT_PC64_HI, "loongarch-got-pc64-hi"},
617 {MO_LE_HI, "loongarch-le-hi"},
618 {MO_LE_LO, "loongarch-le-lo"},
619 {MO_LE64_LO, "loongarch-le64-lo"},
620 {MO_LE64_HI, "loongarch-le64-hi"},
621 {MO_IE_PC_HI, "loongarch-ie-pc-hi"},
622 {MO_IE_PC_LO, "loongarch-ie-pc-lo"},
623 {MO_IE_PC64_LO, "loongarch-ie-pc64-lo"},
624 {MO_IE_PC64_HI, "loongarch-ie-pc64-hi"},
625 {MO_DESC_PC_HI, "loongarch-desc-pc-hi"},
626 {MO_DESC_PC_LO, "loongarch-desc-pc-lo"},
627 {MO_DESC64_PC_LO, "loongarch-desc64-pc-lo"},
628 {MO_DESC64_PC_HI, "loongarch-desc64-pc-hi"},
629 {MO_DESC_LD, "loongarch-desc-ld"},
630 {MO_DESC_CALL, "loongarch-desc-call"},
631 {MO_LD_PC_HI, "loongarch-ld-pc-hi"},
632 {MO_GD_PC_HI, "loongarch-gd-pc-hi"}};
633 return ArrayRef(TargetFlags);
634}
635
636// Returns true if this is the sext.w pattern, addi.w rd, rs, 0.
638 return MI.getOpcode() == LoongArch::ADDI_W && MI.getOperand(1).isReg() &&
639 MI.getOperand(2).isImm() && MI.getOperand(2).getImm() == 0;
640}
unsigned const MachineRegisterInfo * MRI
static void parseCondBranch(MachineInstr *LastInst, MachineBasicBlock *&Target, SmallVectorImpl< MachineOperand > &Cond)
MachineBasicBlock & MBB
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
MachineBasicBlock MachineBasicBlock::iterator MBBI
static unsigned getOppositeBranchOpc(unsigned Opcode)
IRTranslator LLVM IR MI
#define I(x, y, z)
Definition: MD5.cpp:58
unsigned const TargetRegisterInfo * TRI
uint64_t IntrinsicInst * II
const SmallVectorImpl< MachineOperand > MachineBasicBlock * TBB
const SmallVectorImpl< MachineOperand > & Cond
This file declares the machine register scavenger class.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static bool contains(SmallPtrSetImpl< ConstantExpr * > &Cache, ConstantExpr *Expr, Constant *C)
Definition: Value.cpp:469
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
A debug info location.
Definition: DebugLoc.h:33
void loadRegFromStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, Register DstReg, int FrameIndex, const TargetRegisterClass *RC, const TargetRegisterInfo *TRI, Register VReg) const override
const LoongArchSubtarget & STI
bool reverseBranchCondition(SmallVectorImpl< MachineOperand > &Cond) const override
bool analyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB, MachineBasicBlock *&FBB, SmallVectorImpl< MachineOperand > &Cond, bool AllowModify) const override
std::pair< unsigned, unsigned > decomposeMachineOperandsTargetFlags(unsigned TF) const override
bool isAsCheapAsAMove(const MachineInstr &MI) const override
LoongArchInstrInfo(LoongArchSubtarget &STI)
MCInst getNop() const override
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 copyPhysReg(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, const DebugLoc &DL, MCRegister DstReg, MCRegister SrcReg, bool KillSrc) const override
void insertIndirectBranch(MachineBasicBlock &MBB, MachineBasicBlock &NewDestBB, MachineBasicBlock &RestoreBB, const DebugLoc &DL, int64_t BrOffset, RegScavenger *RS) const override
void storeRegToStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, Register SrcReg, bool IsKill, int FrameIndex, const TargetRegisterClass *RC, const TargetRegisterInfo *TRI, Register VReg) const override
bool isSchedulingBoundary(const MachineInstr &MI, const MachineBasicBlock *MBB, const MachineFunction &MF) const override
bool isBranchOffsetInRange(unsigned BranchOpc, int64_t BrOffset) const override
unsigned getInstSizeInBytes(const MachineInstr &MI) const override
MachineBasicBlock * getBranchDestBlock(const MachineInstr &MI) 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:56
MCInstBuilder & addReg(unsigned Reg)
Add a new register operand.
Definition: MCInstBuilder.h:37
MCInstBuilder & addImm(int64_t Val)
Add a new integer immediate operand.
Definition: MCInstBuilder.h:43
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:184
bool isConditionalBranch() const
Return true if this is a branch which may fall through to the next instruction or may transfer contro...
Definition: MCInstrDesc.h:317
Wrapper class representing physical registers. Should be passed by value.
Definition: MCRegister.h:33
unsigned pred_size() const
reverse_iterator rend()
iterator getLastNonDebugInstr(bool SkipPseudoOp=true)
Returns an iterator to the last non-debug instruction in the basic block, or end().
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
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.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
const LLVMTargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
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 & addFrameIndex(int Idx) const
const MachineInstrBuilder & addReg(Register RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
const MachineInstrBuilder & addMBB(MachineBasicBlock *MBB, unsigned TargetFlags=0) const
const MachineInstrBuilder & addMemOperand(MachineMemOperand *MMO) const
reverse_iterator getReverse() const
Get a reverse iterator to the same node.
Representation of each machine instruction.
Definition: MachineInstr.h:69
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
Definition: MachineInstr.h:569
unsigned getNumExplicitOperands() const
Returns the number of non-implicit operands.
const MCInstrDesc & getDesc() const
Returns the target instruction descriptor of this MachineInstr.
Definition: MachineInstr.h:566
const MachineOperand & getOperand(unsigned i) const
Definition: MachineInstr.h:579
A description of a memory reference used in the backend.
@ MOLoad
The memory access reads data.
@ MOStore
The memory access writes data.
MachineBasicBlock * getMBB() const
void setMBB(MachineBasicBlock *MBB)
static MachineOperand CreateImm(int64_t Val)
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
void enterBasicBlockEnd(MachineBasicBlock &MBB)
Start tracking liveness from the end of basic block MBB.
void setRegUsed(Register Reg, LaneBitmask LaneMask=LaneBitmask::getAll())
Tell the scavenger a register is used.
Register scavengeRegisterBackwards(const TargetRegisterClass &RC, MachineBasicBlock::iterator To, bool RestoreAfter, int SPAdj, bool AllowSpill=true)
Make a register of the specific register class available from the current position backwards to the p...
Wrapper class representing virtual and physical registers.
Definition: Register.h:19
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:586
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
getRegisterInfo - If register information is available, return it.
Target - Wrapper for Target specific information.
self_iterator getIterator()
Definition: ilist_node.h:132
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
InstSeq generateInstSeq(int64_t Val)
bool isSEXT_W(const MachineInstr &MI)
@ Kill
The last use of a register.
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
decltype(auto) get(const PointerIntPair< PointerTy, IntBits, IntType, PtrTraits, Info > &Pair)
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition: Error.cpp:167
unsigned getKillRegState(bool B)
static MachinePointerInfo getFixedStack(MachineFunction &MF, int FI, int64_t Offset=0)
Return a MachinePointerInfo record that refers to the specified FrameIndex.