LLVM 24.0.0git
M68kInstrInfo.cpp
Go to the documentation of this file.
1//===-- M68kInstrInfo.cpp - M68k 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/// \file
10/// This file contains the M68k declaration of the TargetInstrInfo class.
11///
12//===----------------------------------------------------------------------===//
13
14#include "M68kInstrInfo.h"
15
16#include "M68kInstrBuilder.h"
17#include "M68kMachineFunction.h"
18#include "M68kRegisterInfo.h"
19#include "M68kTargetMachine.h"
22
23#include "llvm/ADT/STLExtras.h"
24#include "llvm/ADT/ScopeExit.h"
32#include "llvm/Support/Regex.h"
33
34#include <functional>
35
36using namespace llvm;
37
38#define DEBUG_TYPE "M68k-instr-info"
39
40#define GET_INSTRINFO_CTOR_DTOR
41#include "M68kGenInstrInfo.inc"
42
43// Pin the vtable to this file.
44void M68kInstrInfo::anchor() {}
45
47 : M68kGenInstrInfo(STI, RI, M68k::ADJCALLSTACKDOWN, M68k::ADJCALLSTACKUP, 0,
48 M68k::RET),
49 Subtarget(STI), RI(STI) {}
50
51static M68k::CondCode getCondFromBranchOpc(unsigned BrOpc) {
52 switch (BrOpc) {
53 default:
54 return M68k::COND_INVALID;
55 case M68k::Beq8:
56 return M68k::COND_EQ;
57 case M68k::Bne8:
58 return M68k::COND_NE;
59 case M68k::Blt8:
60 return M68k::COND_LT;
61 case M68k::Ble8:
62 return M68k::COND_LE;
63 case M68k::Bgt8:
64 return M68k::COND_GT;
65 case M68k::Bge8:
66 return M68k::COND_GE;
67 case M68k::Bcs8:
68 return M68k::COND_CS;
69 case M68k::Bls8:
70 return M68k::COND_LS;
71 case M68k::Bhi8:
72 return M68k::COND_HI;
73 case M68k::Bcc8:
74 return M68k::COND_CC;
75 case M68k::Bmi8:
76 return M68k::COND_MI;
77 case M68k::Bpl8:
78 return M68k::COND_PL;
79 case M68k::Bvs8:
80 return M68k::COND_VS;
81 case M68k::Bvc8:
82 return M68k::COND_VC;
83 }
84}
85
90 bool AllowModify) const {
91
92 auto UncondBranch =
93 std::pair<MachineBasicBlock::reverse_iterator, MachineBasicBlock *>{
94 MBB.rend(), nullptr};
95
96 // Erase any instructions if allowed at the end of the scope.
97 std::vector<std::reference_wrapper<llvm::MachineInstr>> EraseList;
98 llvm::scope_exit FinalizeOnReturn([&EraseList] {
99 for (auto &Ref : EraseList)
100 Ref.get().eraseFromParent();
101 });
102
103 // Start from the bottom of the block and work up, examining the
104 // terminator instructions.
105 for (auto iter = MBB.rbegin(); iter != MBB.rend(); iter = std::next(iter)) {
106
107 unsigned Opcode = iter->getOpcode();
108
109 if (iter->isDebugInstr())
110 continue;
111
112 // Working from the bottom, when we see a non-terminator instruction, we're
113 // done.
114 if (!isUnpredicatedTerminator(*iter))
115 break;
116
117 // A terminator that isn't a branch can't easily be handled by this
118 // analysis.
119 if (!iter->isBranch())
120 return true;
121
122 // Handle unconditional branches.
123 if (Opcode == M68k::BRA8 || Opcode == M68k::BRA16) {
124 if (!iter->getOperand(0).isMBB())
125 return true;
126 UncondBranch = {iter, iter->getOperand(0).getMBB()};
127
128 // TBB is used to indicate the unconditional destination.
129 TBB = UncondBranch.second;
130
131 if (!AllowModify)
132 continue;
133
134 // If the block has any instructions after a JMP, erase them.
135 EraseList.insert(EraseList.begin(), MBB.rbegin(), iter);
136
137 Cond.clear();
138 FBB = nullptr;
139
140 // Erase the JMP if it's equivalent to a fall-through.
141 if (MBB.isLayoutSuccessor(UncondBranch.second)) {
142 TBB = nullptr;
143 EraseList.push_back(*iter);
144 UncondBranch = {MBB.rend(), nullptr};
145 }
146
147 continue;
148 }
149
150 // Handle conditional branches.
151 auto BranchCode = M68k::GetCondFromBranchOpc(Opcode);
152
153 // Can't handle indirect branch.
154 if (BranchCode == M68k::COND_INVALID)
155 return true;
156
157 // In practice we should never have an undef CCR operand, if we do
158 // abort here as we are not prepared to preserve the flag.
159 // ??? Is this required?
160 // if (iter->getOperand(1).isUndef())
161 // return true;
162
163 // Working from the bottom, handle the first conditional branch.
164 if (Cond.empty()) {
165 if (!iter->getOperand(0).isMBB())
166 return true;
167 MachineBasicBlock *CondBranchTarget = iter->getOperand(0).getMBB();
168
169 // If we see something like this:
170 //
171 // bcc l1
172 // bra l2
173 // ...
174 // l1:
175 // ...
176 // l2:
177 if (UncondBranch.first != MBB.rend()) {
178
179 assert(std::next(UncondBranch.first) == iter && "Wrong block layout.");
180
181 // And we are allowed to modify the block and the target block of the
182 // conditional branch is the direct successor of this block:
183 //
184 // bcc l1
185 // bra l2
186 // l1:
187 // ...
188 // l2:
189 //
190 // we change it to this if allowed:
191 //
192 // bncc l2
193 // l1:
194 // ...
195 // l2:
196 //
197 // Which is a bit more efficient.
198 if (AllowModify && MBB.isLayoutSuccessor(CondBranchTarget)) {
199
200 BranchCode = GetOppositeBranchCondition(BranchCode);
201 unsigned BNCC = GetCondBranchFromCond(BranchCode);
202
203 BuildMI(MBB, *UncondBranch.first, MBB.rfindDebugLoc(iter), get(BNCC))
204 .addMBB(UncondBranch.second);
205
206 EraseList.push_back(*iter);
207 EraseList.push_back(*UncondBranch.first);
208
209 TBB = UncondBranch.second;
210 FBB = nullptr;
211 Cond.push_back(MachineOperand::CreateImm(BranchCode));
212
213 // Otherwise preserve TBB, FBB and Cond as requested
214 } else {
215 TBB = CondBranchTarget;
216 FBB = UncondBranch.second;
217 Cond.push_back(MachineOperand::CreateImm(BranchCode));
218 }
219
220 UncondBranch = {MBB.rend(), nullptr};
221 continue;
222 }
223
224 TBB = CondBranchTarget;
225 FBB = nullptr;
226 Cond.push_back(MachineOperand::CreateImm(BranchCode));
227
228 continue;
229 }
230
231 // Handle subsequent conditional branches. Only handle the case where all
232 // conditional branches branch to the same destination and their condition
233 // opcodes fit one of the special multi-branch idioms.
234 assert(Cond.size() == 1);
235 assert(TBB);
236
237 // If the conditions are the same, we can leave them alone.
238 auto OldBranchCode = static_cast<M68k::CondCode>(Cond[0].getImm());
239 if (!iter->getOperand(0).isMBB())
240 return true;
241 auto NewTBB = iter->getOperand(0).getMBB();
242 if (OldBranchCode == BranchCode && TBB == NewTBB)
243 continue;
244
245 // If they differ we cannot do much here.
246 return true;
247 }
248
249 return false;
250}
251
254 MachineBasicBlock *&FBB,
256 bool AllowModify) const {
257 return AnalyzeBranchImpl(MBB, TBB, FBB, Cond, AllowModify);
258}
259
261 int *BytesRemoved) const {
262 assert(!BytesRemoved && "code size not handled");
263
265 unsigned Count = 0;
266
267 while (I != MBB.begin()) {
268 --I;
269 if (I->isDebugValue())
270 continue;
271 if (I->getOpcode() != M68k::BRA8 &&
273 break;
274 // Remove the branch.
275 I->eraseFromParent();
276 I = MBB.end();
277 ++Count;
278 }
279
280 return Count;
281}
282
285 ArrayRef<MachineOperand> Cond, const DebugLoc &DL, int *BytesAdded) const {
286 // Shouldn't be a fall through.
287 assert(TBB && "InsertBranch must not be told to insert a fallthrough");
288 assert((Cond.size() == 1 || Cond.size() == 0) &&
289 "M68k branch conditions have one component!");
290 assert(!BytesAdded && "code size not handled");
291
292 if (Cond.empty()) {
293 // Unconditional branch?
294 assert(!FBB && "Unconditional branch with multiple successors!");
295 BuildMI(&MBB, DL, get(M68k::BRA8)).addMBB(TBB);
296 return 1;
297 }
298
299 // If FBB is null, it is implied to be a fall-through block.
300 bool FallThru = FBB == nullptr;
301
302 // Conditional branch.
303 unsigned Count = 0;
305 unsigned Opc = GetCondBranchFromCond(CC);
306 BuildMI(&MBB, DL, get(Opc)).addMBB(TBB);
307 ++Count;
308 if (!FallThru) {
309 // Two-way Conditional branch. Insert the second branch.
310 BuildMI(&MBB, DL, get(M68k::BRA8)).addMBB(FBB);
311 ++Count;
312 }
313 return Count;
314}
315
318 unsigned Reg, MVT From, MVT To) const {
319 if (From == MVT::i8) {
320 unsigned R = Reg;
321 // EXT16 requires i16 register
322 if (To == MVT::i32) {
323 R = RI.getSubReg(Reg, M68k::MxSubRegIndex16Lo);
324 assert(R && "No viable SUB register available");
325 }
326 BuildMI(MBB, I, DL, get(M68k::EXT16), R).addReg(R);
327 }
328
329 if (To == MVT::i32)
330 BuildMI(MBB, I, DL, get(M68k::EXT32), Reg).addReg(Reg);
331}
332
335 unsigned Reg, MVT From, MVT To) const {
336
337 // On pre-020 (16-bit bus) CPUs, SWAP -> CLR -> SWAP is faster than AND with
338 // mask.
339 if (!Subtarget.atLeastM68020() && From == MVT::i16 && To == MVT::i32 &&
340 M68k::DR32RegClass.contains(Reg)) {
341 unsigned SubReg = RI.getSubReg(Reg, M68k::MxSubRegIndex16Lo);
342 BuildMI(MBB, I, DL, get(M68k::SWAP), Reg).addReg(Reg);
343 BuildMI(MBB, I, DL, get(M68k::CLR16d), SubReg);
344 BuildMI(MBB, I, DL, get(M68k::SWAP), Reg).addReg(Reg);
345 return;
346 }
347
348 unsigned Mask, And;
349 if (From == MVT::i8)
350 Mask = 0xFF;
351 else
352 Mask = 0xFFFF;
353
354 if (To == MVT::i16)
355 And = M68k::AND16di;
356 else // i32
357 And = M68k::AND32di;
358
359 // TODO use xor r,r to decrease size
360 BuildMI(MBB, I, DL, get(And), Reg).addReg(Reg).addImm(Mask);
361}
362
363// Convert MOVI to the appropriate instruction (sequence) for setting
364// the register to an immediate value.
366 Register Reg = MIB->getOperand(0).getReg();
367 int64_t Imm = MIB->getOperand(1).getImm();
368
369 const auto *DR32 = RI.getRegClass(M68k::DR32RegClassID);
370 const auto *AR32 = RI.getRegClass(M68k::AR32RegClassID);
371 const auto *AR16 = RI.getRegClass(M68k::AR16RegClassID);
372 bool IsAddressReg = AR16->contains(Reg) || AR32->contains(Reg);
373
375 DebugLoc DL = MIB->getDebugLoc();
376
377 // We need to assign to the full register to make IV happy
378 Register SReg =
379 MVTSize == MVT::i32
380 ? Reg
381 : Register(RI.getMatchingMegaReg(Reg, IsAddressReg ? AR32 : DR32));
382 assert(SReg && "No viable MEGA register available");
383
384 LLVM_DEBUG(dbgs() << "Expand " << *MIB.getInstr() << " to ");
385
386 if (Imm == 0) {
387 buildClearRegister(Reg, MBB, MIB, DL);
388 MachineInstr &NewMI = *std::prev((MachineBasicBlock::iterator)MIB);
389 LLVM_DEBUG(dbgs() << NewMI << "\n");
390 MIB->removeFromParent();
391
392 // Sign extension doesn't matter if we only use the bottom 8 bits.
393 } else if (MVTSize == MVT::i8 ||
394 (!IsAddressReg && Imm >= -128 && Imm <= 127)) {
395 LLVM_DEBUG(dbgs() << "MOVEQ\n");
396
397 MIB->setDesc(get(M68k::MOVQ));
398 MIB->getOperand(0).setReg(SReg);
399
400 // Counter the effects of sign-extension with a bitwise not.
401 // This is only faster and smaller for 32 bit values.
402 } else if (DR32->contains(Reg) && isUInt<8>(Imm)) {
403 LLVM_DEBUG(dbgs() << "MOVEQ and NOT\n");
404
405 unsigned SubReg = RI.getSubReg(Reg, M68k::MxSubRegIndex8Lo);
406 assert(SubReg && "No viable SUB register available");
407
408 BuildMI(MBB, MIB.getInstr(), DL, get(M68k::MOVQ), SReg).addImm(~Imm & 0xFF);
409 BuildMI(MBB, MIB.getInstr(), DL, get(M68k::NOT8d), SubReg).addReg(SubReg);
410
411 MIB->removeFromParent();
412
413 // movea.w implicitly sign extends to the full register width,
414 // so exploit that if the immediate fits in the correct range.
415 //
416 // TODO: use lea imm.w, %an for further constants when 16-bit
417 // absolute addressing is implemented.
418 } else if (AR32->contains(Reg) && isUInt<16>(Imm)) {
419 LLVM_DEBUG(dbgs() << "MOVEA w/ implicit extend\n");
420
421 unsigned SubReg = RI.getSubReg(Reg, M68k::MxSubRegIndex16Lo);
422 assert(SubReg && "No viable SUB register available");
423
424 MIB->setDesc(get(M68k::MOV16ai));
425 MIB->getOperand(0).setReg(SubReg);
426
427 // Fall back to a move with immediate
428 } else {
429 LLVM_DEBUG(dbgs() << "MOVE\n");
430 MIB->setDesc(get(MVTSize == MVT::i16 ? M68k::MOV16ri : M68k::MOV32ri));
431 }
432
433 return true;
434}
435
437 MVT MVTSrc) const {
438 unsigned Move = MVTSrc == MVT::i8 ? M68k::MOV8dd : M68k::MOV16rr;
439 Register Dst = MIB->getOperand(0).getReg();
440 Register Src = MIB->getOperand(1).getReg();
441
442 assert(Dst != Src && "You cannot use the same Regs with MOVX_RR");
443
444 const auto &TRI = getRegisterInfo();
445
446 const auto *RCDst = TRI.getMaximalPhysRegClass(Dst, MVTDst);
447 const auto *RCSrc = TRI.getMaximalPhysRegClass(Src, MVTSrc);
448
449 assert(RCDst && RCSrc && "Wrong use of MOVX_RR");
450 assert(RCDst != RCSrc && "You cannot use the same Reg Classes with MOVX_RR");
451 (void)RCSrc;
452
453 unsigned SubDst =
454 RI.getSubReg(Dst, MVTSrc == MVT::i8 ? M68k::MxSubRegIndex8Lo
455 : M68k::MxSubRegIndex16Lo);
456 assert(SubDst && "No viable SUB register available");
457
458 // If source is a subregister of destination, we do nothing
459 if (SubDst == Src) {
460 LLVM_DEBUG(dbgs() << "Remove " << *MIB.getInstr() << '\n');
461 MIB->eraseFromParent();
462 } else { // otherwise we need to MOV
463 LLVM_DEBUG(dbgs() << "Expand " << *MIB.getInstr() << " to MOV\n");
464 MIB->setDesc(get(Move));
465 MIB->getOperand(0).setReg(SubDst);
466 }
467
468 return true;
469}
470
471/// Expand SExt MOVE pseudos into a MOV and a EXT if the operands are two
472/// different registers or just EXT if it is the same register
474 MVT MVTDst, MVT MVTSrc) const {
475 LLVM_DEBUG(dbgs() << "Expand " << *MIB.getInstr() << " to ");
476
477 Register Dst = MIB->getOperand(0).getReg();
478 Register Src = MIB->getOperand(1).getReg();
479
480 assert(Dst != Src && "You cannot use the same Regs with MOVSX_RR");
481
482 const auto &TRI = getRegisterInfo();
483
484 const auto *RCDst = TRI.getMaximalPhysRegClass(Dst, MVTDst);
485 const auto *RCSrc = TRI.getMaximalPhysRegClass(Src, MVTSrc);
486
487 assert(RCDst && RCSrc && "Wrong use of MOVSX_RR");
488 assert(RCDst != RCSrc && "You cannot use the same Reg Classes with MOVSX_RR");
489 (void)RCSrc;
490
491 // Move source into subreg of the destination.
492 unsigned SubDst =
493 RI.getSubReg(Dst, MVTSrc == MVT::i8 ? M68k::MxSubRegIndex8Lo
494 : M68k::MxSubRegIndex16Lo);
495 assert(SubDst && "No viable SUB register available");
496
498 DebugLoc DL = MIB->getDebugLoc();
499
500 unsigned Move;
501 if (MVTSrc == MVT::i8)
502 Move = M68k::MOV8dd;
503 else
504 Move = M68k::MOV16rr;
505
506 // It's more efficient to clear the destination and *then* move, rather than
507 // move and zext.
508 if (SubDst != Src && !IsSigned) {
509 LLVM_DEBUG(dbgs() << "Clear and Move" << '\n');
510
511 buildClearRegister(Dst, MBB, MIB.getInstr(), DL);
512
513 MIB->setDesc(get(Move));
514 MIB->getOperand(0).setReg(SubDst);
515 return true;
516 }
517
518 // Special case where move to AR16 automatically sign-extends to 32 bits.
519 // Even an in-place move (move.w a0,a0) will do so.
520 if (M68k::AR32RegClass.contains(Dst) && IsSigned) {
521 LLVM_DEBUG(dbgs() << "Move (implicit Sign Extend)" << '\n');
522 MIB->setDesc(get(M68k::MOV16ar));
523 MIB->getOperand(0).setReg(SubDst);
524 return true;
525 }
526
527 if (SubDst != Src) {
528 LLVM_DEBUG(dbgs() << "Move and " << '\n');
529 BuildMI(MBB, MIB.getInstr(), DL, get(Move), SubDst).addReg(Src);
530 }
531
532 if (IsSigned) {
533 LLVM_DEBUG(dbgs() << "Sign Extend" << '\n');
534 AddSExt(MBB, MIB.getInstr(), DL, Dst, MVTSrc, MVTDst);
535 } else {
536 LLVM_DEBUG(dbgs() << "Zero Extend" << '\n');
537 AddZExt(MBB, MIB.getInstr(), DL, Dst, MVTSrc, MVTDst);
538 }
539
540 MIB->eraseFromParent();
541
542 return true;
543}
544
546 MVT MVTDst, MVT MVTSrc) const {
547 LLVM_DEBUG(dbgs() << "Expand " << *MIB.getInstr() << " to LOAD" << '\n');
548
549 const MCInstrDesc &Desc = get(Opc);
550 Register Dst = MIB->getOperand(0).getReg();
551
552 // Load source into subreg of the destination.
553 unsigned SubDst =
554 RI.getSubReg(Dst, MVTSrc == MVT::i8 ? M68k::MxSubRegIndex8Lo
555 : M68k::MxSubRegIndex16Lo);
556 assert(SubDst && "No viable SUB register available");
557
558 // Make this a plain move
559 MIB->setDesc(Desc);
560 MIB->getOperand(0).setReg(SubDst);
561
562 return true;
563}
564
566 unsigned Opc, MVT MVTDst,
567 MVT MVTSrc) const {
568 LLVM_DEBUG(dbgs() << "Expand " << *MIB.getInstr() << " to ");
569
570 const MCInstrDesc &Desc = get(Opc);
571 Register Dst = MIB->getOperand(0).getReg();
572
573 // Load source into subreg of the destination.
574 unsigned SubDst =
575 RI.getSubReg(Dst, MVTSrc == MVT::i8 ? M68k::MxSubRegIndex8Lo
576 : M68k::MxSubRegIndex16Lo);
577 assert(SubDst && "No viable SUB register available");
578
579 // Make this a plain move
580 MIB->setDesc(Desc);
581 MIB->getOperand(0).setReg(SubDst);
582
583 // Special case where move to AR16 automatically sign-extends to 32 bits. In
584 // that case, we're already done.
585 if (M68k::AR32RegClass.contains(Dst) && IsSigned) {
586 LLVM_DEBUG(dbgs() << "LOAD (implicit Sign Extend)" << '\n');
587 return true;
588 }
589
592 DebugLoc DL = MIB->getDebugLoc();
593
594 // We can only clear before loading if the destination register isn't being
595 // used as an index for the load.
596 if (!IsSigned && !MIB->readsRegister(Dst, &RI)) {
597 LLVM_DEBUG(dbgs() << "Clear and LOAD" << '\n');
598 buildClearRegister(Dst, MBB, I, DL);
599
600 // Extend after load
601 } else {
602 I++;
603 if (IsSigned) {
604 LLVM_DEBUG(dbgs() << "LOAD and Sign Extend" << '\n');
605 AddSExt(MBB, I, DL, Dst, MVTSrc, MVTDst);
606 } else {
607 LLVM_DEBUG(dbgs() << "Zero Extend" << '\n');
608 AddZExt(MBB, I, DL, Dst, MVTSrc, MVTDst);
609 }
610 }
611
612 return true;
613}
614
616 const MCInstrDesc &Desc, bool IsPush) const {
618 I++;
620 MachineOperand MO = MIB->getOperand(0);
621 DebugLoc DL = MIB->getDebugLoc();
622 if (IsPush)
623 BuildMI(MBB, I, DL, Desc).addReg(RI.getStackRegister()).add(MO);
624 else
625 BuildMI(MBB, I, DL, Desc, MO.getReg()).addReg(RI.getStackRegister());
626
627 MIB->eraseFromParent();
628 return true;
629}
630
632 const MCInstrDesc &Desc, bool IsRM) const {
633 int Reg = 0, Offset = 0, Base = 0;
634 auto DL = MIB->getDebugLoc();
635 auto MI = MIB.getInstr();
636 auto &MBB = *MIB->getParent();
637
638 if (IsRM) {
639 Reg = MIB->getOperand(0).getReg();
640 Offset = MIB->getOperand(1).getImm();
641 Base = MIB->getOperand(2).getReg();
642 } else {
643 Offset = MIB->getOperand(0).getImm();
644 Base = MIB->getOperand(1).getReg();
645 Reg = MIB->getOperand(2).getReg();
646 }
647
648 unsigned Mask = 1 << RI.getSpillRegisterOrder(Reg);
649 if (IsRM) {
650 BuildMI(MBB, MI, DL, Desc)
651 .addImm(Mask)
652 .addImm(Offset)
653 .addReg(Base)
655 .copyImplicitOps(*MIB);
656 } else {
657 BuildMI(MBB, MI, DL, Desc)
658 .addImm(Offset)
659 .addReg(Base)
660 .addImm(Mask)
662 .copyImplicitOps(*MIB);
663 }
664
665 MIB->eraseFromParent();
666
667 return true;
668}
669
672 DebugLoc &DL,
673 bool AllowSideEffects) const {
674 // Clear an address register by subtracting it from itself.
675 if (M68k::AR32RegClass.contains(Reg)) {
676 BuildMI(MBB, Iter, DL, get(M68k::SUB32ar), Reg)
678 .addReg(Reg, RegState::Undef);
679 return;
680 }
681
682 if (M68k::DR8RegClass.contains(Reg))
683 BuildMI(MBB, Iter, DL, get(M68k::CLR8d), Reg);
684 else if (M68k::DR16RegClass.contains(Reg))
685 BuildMI(MBB, Iter, DL, get(M68k::CLR16d), Reg);
686 else if (M68k::DR32RegClass.contains(Reg))
687 BuildMI(MBB, Iter, DL, get(M68k::MOVQ), Reg).addImm(0);
688 else
690 "buildClearRegister is not implemented for " + RI.getRegAsmName(Reg));
691}
692
694 MachineInstrBuilder MIB(*MI.getParent()->getParent(), MI);
695 switch (MI.getOpcode()) {
696 case M68k::PUSH8d:
697 return ExpandPUSH_POP(MIB, get(M68k::MOV8ed), true);
698 case M68k::PUSH16d:
699 return ExpandPUSH_POP(MIB, get(M68k::MOV16er), true);
700 case M68k::PUSH32r:
701 return ExpandPUSH_POP(MIB, get(M68k::MOV32er), true);
702
703 case M68k::POP8d:
704 return ExpandPUSH_POP(MIB, get(M68k::MOV8do), false);
705 case M68k::POP16d:
706 return ExpandPUSH_POP(MIB, get(M68k::MOV16ro), false);
707 case M68k::POP32r:
708 return ExpandPUSH_POP(MIB, get(M68k::MOV32ro), false);
709 }
710 return false;
711}
712
714 unsigned OpIdx) const {
715 assert(MI.getOperand(OpIdx).isReg());
716
717 // Check whether this operand belongs to an instruction with addressing mode
718 // 'k', Refer to TargetInstrInfo.h for more information about this function.
719
720 const unsigned NameIndices = M68kInstrNameIndices[MI.getOpcode()];
721 StringRef InstrName(&M68kInstrNameData[NameIndices]);
722
723 // If this machine operand is the 2nd operand, then check
724 // whether the instruction has destination addressing mode 'k'.
725 if (OpIdx == 1)
726 return Regex("[A-Z]+(8|16|32)k[a-z](_TC)?$").match(InstrName);
727
728 // If this machine operand is the last one, then check
729 // whether the instruction has source addressing mode 'k'.
730 if (OpIdx == MI.getNumExplicitOperands() - 1)
731 return Regex("[A-Z]+(8|16|32)[a-z]k(_TC)?$").match(InstrName);
732
733 return false;
734}
735
738 const DebugLoc &DL, Register DstReg,
739 Register SrcReg, bool KillSrc,
740 bool RenamableDest, bool RenamableSrc) const {
741 unsigned Opc = 0;
742 MachineFunction &MF = *MBB.getParent();
743 const M68kSubtarget &STI = MF.getSubtarget<M68kSubtarget>();
744
745 // Symmetric register copies
746 if (M68k::XR32RegClass.contains(DstReg, SrcReg)) {
747 Opc = M68k::MOV32rr;
748 } else if (M68k::XR16RegClass.contains(DstReg, SrcReg)) {
749 Opc = M68k::MOV16rr;
750 } else if (M68k::DR8RegClass.contains(DstReg, SrcReg)) {
751 Opc = M68k::MOV8dd;
752 }
753
754 // Asymmetric register copies
755 // NOTE: There is no implicit sext/zext occurring during these moves, so the
756 // upper bits will be undefined.
757 // 8 -> 16
758 else if (M68k::DR8RegClass.contains(SrcReg) &&
759 M68k::DR16RegClass.contains(DstReg)) {
760 Opc = M68k::MOVXd16d8;
761 // 8 -> 32
762 } else if (M68k::DR8RegClass.contains(SrcReg) &&
763 M68k::DR32RegClass.contains(DstReg)) {
764 Opc = M68k::MOVXd32d8;
765 // 16 -> 32
766 } else if (M68k::XR16RegClass.contains(SrcReg) &&
767 M68k::XR32RegClass.contains(DstReg)) {
768 Opc = M68k::MOVXr32r16;
769 }
770
771 // Copy from CCR
772 // NOTE: M68000 uses MOVE from SR to copy from CCR, all other variants use
773 // MOVE from CCR.
774 else if (SrcReg == M68k::CCR) {
775 if (M68k::DR8RegClass.contains(DstReg) ||
776 M68k::DR16RegClass.contains(DstReg) ||
777 M68k::DR32RegClass.contains(DstReg)) {
778 Opc = STI.isM68000() ? M68k::MOV16ds : M68k::MOV16dc;
779 } else {
780 LLVM_DEBUG(dbgs() << "Cannot copy CCR to " << RI.getName(DstReg) << '\n');
781 llvm_unreachable("Invalid register for MOVE from CCR");
782 }
783 }
784
785 // Copy to CCR
786 else if (DstReg == M68k::CCR) {
787 if (M68k::DR8RegClass.contains(SrcReg) ||
788 M68k::DR16RegClass.contains(SrcReg) ||
789 M68k::DR32RegClass.contains(SrcReg)) {
790 Opc = M68k::MOV16cd;
791 } else {
792 LLVM_DEBUG(dbgs() << "Cannot copy " << RI.getName(SrcReg) << " to CCR\n");
793 llvm_unreachable("Invalid register for MOVE to CCR");
794 }
795 }
796
797 // SR should never be a valid register for copying
798 else if (SrcReg == M68k::SR || DstReg == M68k::SR)
799 llvm_unreachable("Cannot explicitly copy to/from SR");
800
801 // We should now have our opcode
802 if (!Opc) {
803 LLVM_DEBUG(dbgs() << "Cannot copy " << RI.getName(SrcReg) << " to "
804 << RI.getName(DstReg) << '\n');
805 llvm_unreachable("Cannot emit physreg copy instruction");
806 }
807
808 // FIXME
809 // Below is a workaround to prevent a live CCR from being killed by the COPY
810 // instruction. LLVM sometimes inserts a COPY pseudo instruction between
811 // compare and branch during MIR generation (e.g. during PHI node elimination)
812 // without any idea that on M68k, this is extremely likely to implicitly kill
813 // the CCR.
814 // The workaround checks whether CCR is live during this copy, and if so,
815 // backs up CCR and restores it after the copy. It's inefficient and prevents
816 // M68000-targeted builds from running on 010+ (because 000 uses MOVE from SR
817 // and 010+ uses MOVE from CCR).
818 // The fix condition is to prevent COPY from ever being inserted while CCR is
819 // live (which would also stop this workaround from ever triggering).
820
821 unsigned CCRSrcReg = STI.isM68000() ? M68k::SR : M68k::CCR;
822
823 // Get the live registers right before the COPY instruction. If CCR is
824 // live, the MOVE is going to kill it, so we will need to preserve it.
825 LiveRegUnits UsedRegs(RI);
826 UsedRegs.addLiveOuts(MBB);
827 auto InstUpToI = MBB.end();
828 while (InstUpToI != MI) {
829 UsedRegs.stepBackward(*--InstUpToI);
830 }
831
832 if (SrcReg == M68k::CCR) {
833 BuildMI(MBB, MI, DL, get(Opc), DstReg).addReg(CCRSrcReg);
834 return;
835 }
836 if (DstReg == M68k::CCR) {
837 BuildMI(MBB, MI, DL, get(Opc), M68k::CCR)
838 .addReg(SrcReg, getKillRegState(KillSrc));
839 return;
840 }
841 if (UsedRegs.available(M68k::CCR)) {
842 BuildMI(MBB, MI, DL, get(Opc), DstReg)
843 .addReg(SrcReg, getKillRegState(KillSrc));
844 return;
845 }
846
847 // CCR is live, so we must restore it after the copy. Prepare push/pop ops.
848 // 68000 must use MOVE from SR, 68010+ must use MOVE from CCR. In either
849 // case, upon moving back, MOVE to CCR will mask out the upper byte anyway.
850
851 // Look for an available data register for the CCR, or push to stack if
852 // there are none
853 BitVector Allocatable =
854 RI.getAllocatableSet(MF, RI.getRegClass(M68k::DR16RegClassID));
855 for (Register Reg : Allocatable.set_bits()) {
856 if (!RI.regsOverlap(DstReg, Reg) && (UsedRegs.available(Reg))) {
857 unsigned CCRPushOp = STI.isM68000() ? M68k::MOV16ds : M68k::MOV16dc;
858 unsigned CCRPopOp = M68k::MOV16cd;
859 BuildMI(MBB, MI, DL, get(CCRPushOp), Reg).addReg(CCRSrcReg);
860 BuildMI(MBB, MI, DL, get(Opc), DstReg)
861 .addReg(SrcReg, getKillRegState(KillSrc));
862 BuildMI(MBB, MI, DL, get(CCRPopOp), M68k::CCR).addReg(Reg);
863 return;
864 }
865 }
866
867 unsigned CCRPushOp = STI.isM68000() ? M68k::MOV16es : M68k::MOV16ec;
868 unsigned CCRPopOp = M68k::MOV16co;
869
870 BuildMI(MBB, MI, DL, get(CCRPushOp))
871 .addReg(RI.getStackRegister())
872 .addReg(CCRSrcReg);
873 BuildMI(MBB, MI, DL, get(Opc), DstReg)
874 .addReg(SrcReg, getKillRegState(KillSrc));
875 BuildMI(MBB, MI, DL, get(CCRPopOp), M68k::CCR).addReg(RI.getStackRegister());
876 return;
877}
878
879namespace {
880unsigned getLoadStoreRegOpcode(unsigned Reg, const TargetRegisterClass *RC,
881 const TargetRegisterInfo *TRI,
882 const M68kSubtarget &STI, bool load) {
883 switch (TRI->getSpillSize(*RC)) {
884 default:
886 dbgs() << "Cannot determine appropriate opcode for load/store to/from "
887 << TRI->getName(Reg) << " of class " << TRI->getRegClassName(RC)
888 << " with spill size " << TRI->getSpillSize(*RC) << '\n');
889 llvm_unreachable("Unknown spill size");
890 case 2:
891 if (M68k::XR16RegClass.hasSubClassEq(RC))
892 return load ? M68k::MOVM16mp_P : M68k::MOVM16pm_P;
893 if (M68k::DR8RegClass.hasSubClassEq(RC))
894 return load ? M68k::MOVM8mp_P : M68k::MOVM8pm_P;
895 if (M68k::CCRCRegClass.hasSubClassEq(RC))
896 return load ? M68k::MOVM16mp_P : M68k::MOVM16pm_P;
897 llvm_unreachable("Unknown 2-byte regclass");
898 case 4:
899 if (M68k::XR32RegClass.hasSubClassEq(RC))
900 return load ? M68k::MOVM32mp_P : M68k::MOVM32pm_P;
901 llvm_unreachable("Unknown 4-byte regclass");
902 }
903}
904
905unsigned getStoreRegOpcode(unsigned SrcReg, const TargetRegisterClass *RC,
906 const TargetRegisterInfo *TRI,
907 const M68kSubtarget &STI) {
908 return getLoadStoreRegOpcode(SrcReg, RC, TRI, STI, false);
909}
910
911unsigned getLoadRegOpcode(unsigned DstReg, const TargetRegisterClass *RC,
912 const TargetRegisterInfo *TRI,
913 const M68kSubtarget &STI) {
914 return getLoadStoreRegOpcode(DstReg, RC, TRI, STI, true);
915}
916} // end anonymous namespace
917
919 unsigned SubIdx, unsigned &Size,
920 unsigned &Offset,
921 const MachineFunction &MF) const {
922 // The slot size must be the maximum size so we can easily use MOVEM.L
923 Size = 4;
924 Offset = 0;
925 return true;
926}
927
930 bool IsKill, int FrameIndex, const TargetRegisterClass *RC, Register VReg,
931 MachineInstr::MIFlag Flags) const {
932 const MachineFrameInfo &MFI = MBB.getParent()->getFrameInfo();
933 assert(MFI.getObjectSize(FrameIndex) >= TRI.getSpillSize(*RC) &&
934 "Stack slot is too small to store");
935 (void)MFI;
936
937 unsigned Opc = getStoreRegOpcode(SrcReg, RC, &TRI, Subtarget);
938 DebugLoc DL = MBB.findDebugLoc(MI);
939 // (0,FrameIndex) <- $reg
940 M68k::addFrameReference(BuildMI(MBB, MI, DL, get(Opc)), FrameIndex)
941 .addReg(SrcReg, getKillRegState(IsKill));
942}
943
946 Register DstReg, int FrameIndex,
947 const TargetRegisterClass *RC,
948 Register VReg, unsigned SubReg,
949 MachineInstr::MIFlag Flags) const {
950 const MachineFrameInfo &MFI = MBB.getParent()->getFrameInfo();
951 assert(MFI.getObjectSize(FrameIndex) >= TRI.getSpillSize(*RC) &&
952 "Stack slot is too small to load");
953 (void)MFI;
954
955 unsigned Opc = getLoadRegOpcode(DstReg, RC, &TRI, Subtarget);
956 DebugLoc DL = MBB.findDebugLoc(MI);
957 M68k::addFrameReference(BuildMI(MBB, MI, DL, get(Opc), DstReg), FrameIndex);
958}
959
960/// Return a virtual register initialized with the global base register
961/// value. Output instructions required to initialize the register in the
962/// function entry block, if necessary.
963///
964/// TODO Move this function to M68kMachineFunctionInfo.
967 unsigned GlobalBaseReg = MxFI->getGlobalBaseReg();
968 if (GlobalBaseReg != 0)
969 return GlobalBaseReg;
970
971 // Create the register. The code to initialize it is inserted later,
972 // by the M68kGlobalBaseReg pass (below).
973 //
974 // NOTE
975 // Normally M68k uses A5 register as global base pointer but this will
976 // create unnecessary spill if we use less then 4 registers in code; since A5
977 // is callee-save anyway we could try to allocate caller-save first and if
978 // lucky get one, otherwise it does not really matter which callee-save to
979 // use.
980 MachineRegisterInfo &RegInfo = MF->getRegInfo();
981 GlobalBaseReg = RegInfo.createVirtualRegister(&M68k::AR32_NOSPRegClass);
982 MxFI->setGlobalBaseReg(GlobalBaseReg);
983 return GlobalBaseReg;
984}
985
986std::pair<unsigned, unsigned>
988 return std::make_pair(TF, 0u);
989}
990
993 using namespace M68kII;
994 static const std::pair<unsigned, const char *> TargetFlags[] = {
995 {MO_ABSOLUTE_ADDRESS, "m68k-absolute"},
996 {MO_PC_RELATIVE_ADDRESS, "m68k-pcrel"},
997 {MO_GOT, "m68k-got"},
998 {MO_GOTOFF, "m68k-gotoff"},
999 {MO_GOTPCREL, "m68k-gotpcrel"},
1000 {MO_PLT, "m68k-plt"},
1001 {MO_TLSGD, "m68k-tlsgd"},
1002 {MO_TLSLD, "m68k-tlsld"},
1003 {MO_TLSLDM, "m68k-tlsldm"},
1004 {MO_TLSIE, "m68k-tlsie"},
1005 {MO_TLSLE, "m68k-tlsle"}};
1006 return ArrayRef(TargetFlags);
1007}
1008
1009#undef DEBUG_TYPE
1010#define DEBUG_TYPE "m68k-create-global-base-reg"
1011
1012#define PASS_NAME "M68k PIC Global Base Reg Initialization"
1013
1014namespace {
1015/// This initializes the PIC global base register
1016struct M68kGlobalBaseReg : public MachineFunctionPass {
1017 static char ID;
1018 M68kGlobalBaseReg() : MachineFunctionPass(ID) {}
1019
1020 bool runOnMachineFunction(MachineFunction &MF) override {
1021 const M68kSubtarget &STI = MF.getSubtarget<M68kSubtarget>();
1023
1024 unsigned GlobalBaseReg = MxFI->getGlobalBaseReg();
1025
1026 // If we didn't need a GlobalBaseReg, don't insert code.
1027 if (GlobalBaseReg == 0)
1028 return false;
1029
1030 // Insert the set of GlobalBaseReg into the first MBB of the function
1031 MachineBasicBlock &FirstMBB = MF.front();
1033 DebugLoc DL = FirstMBB.findDebugLoc(MBBI);
1034 const M68kInstrInfo *TII = STI.getInstrInfo();
1035
1036 // Generate lea (__GLOBAL_OFFSET_TABLE_,%PC), %A5
1037 BuildMI(FirstMBB, MBBI, DL, TII->get(M68k::LEA32q), GlobalBaseReg)
1038 .addExternalSymbol("_GLOBAL_OFFSET_TABLE_", M68kII::MO_GOTPCREL);
1039
1040 return true;
1041 }
1042
1043 void getAnalysisUsage(AnalysisUsage &AU) const override {
1044 AU.setPreservesCFG();
1046 }
1047};
1048char M68kGlobalBaseReg::ID = 0;
1049} // namespace
1050
1051INITIALIZE_PASS(M68kGlobalBaseReg, DEBUG_TYPE, PASS_NAME, false, false)
1052
1054 return new M68kGlobalBaseReg();
1055}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
uint64_t Imm
AMDGPU Mark last scratch load
MachineBasicBlock & MBB
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
MachineBasicBlock MachineBasicBlock::iterator MBBI
#define DEBUG_TYPE
const HexagonInstrInfo * TII
IRTranslator LLVM IR MI
This file implements the LivePhysRegs utility for tracking liveness of physical registers.
This file exposes functions that may be used with BuildMI from the MachineInstrBuilder....
static M68k::CondCode getCondFromBranchOpc(unsigned BrOpc)
This file contains the M68k implementation of the TargetInstrInfo class.
This file contains the declarations for the code emitter which are useful outside of the emitter itse...
This file provides M68k specific target descriptions.
This file declares the M68k specific subclass of MachineFunctionInfo.
This file contains the M68k implementation of the TargetRegisterInfo class.
This file declares the M68k specific subclass of TargetMachine.
#define I(x, y, z)
Definition MD5.cpp:57
Register const TargetRegisterInfo * TRI
Promote Memory to Register
Definition Mem2Reg.cpp:110
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
Definition PassSupport.h:56
SmallVector< MachineOperand, 4 > Cond
RISCVCC::CondCode CC
const SmallVectorImpl< MachineOperand > MachineBasicBlock * TBB
This file contains some templates that are useful if you are working with the STL at all.
static bool contains(SmallPtrSetImpl< ConstantExpr * > &Cache, ConstantExpr *Expr, Constant *C)
Definition Value.cpp:480
This file defines the scope_exit class, which executes user-defined cleanup logic at scope exit.
static SPCC::CondCodes GetOppositeBranchCondition(SPCC::CondCodes CC)
#define LLVM_DEBUG(...)
Definition Debug.h:119
#define PASS_NAME
static unsigned getStoreRegOpcode(Register SrcReg, const TargetRegisterClass *RC, bool IsStackAligned, const X86Subtarget &STI)
static unsigned getLoadRegOpcode(Register DestReg, const TargetRegisterClass *RC, bool IsStackAligned, const X86Subtarget &STI)
static unsigned getLoadStoreRegOpcode(Register Reg, const TargetRegisterClass *RC, bool IsStackAligned, const X86Subtarget &STI, bool Load)
static unsigned GetCondBranchFromCond(XCore::CondCode CC)
GetCondBranchFromCond - Return the Branch instruction opcode that matches the cc.
Represent the analysis usage information of a pass.
LLVM_ABI void setPreservesCFG()
This function should be called by the pass, iff they do not:
Definition Pass.cpp:280
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
iterator_range< const_set_bits_iterator > set_bits() const
Definition BitVector.h:159
A debug info location.
Definition DebugLoc.h:126
FunctionPass class - This class is used to implement most global optimizations.
Definition Pass.h:312
A set of register units used to track register liveness.
bool available(MCRegister Reg) const
Returns true if no part of physical register Reg is live.
LLVM_ABI void stepBackward(const MachineInstr &MI)
Updates liveness when stepping backwards over the instruction MI.
LLVM_ABI void addLiveOuts(const MachineBasicBlock &MBB)
Adds registers living out of block MBB.
unsigned getGlobalBaseReg(MachineFunction *MF) const
Return a virtual register initialized with the global base register value.
const M68kSubtarget & Subtarget
bool ExpandMOVI(MachineInstrBuilder &MIB, MVT MVTSize) const
Move immediate to register.
bool ExpandMOVSZX_RR(MachineInstrBuilder &MIB, bool IsSigned, MVT MVTDst, MVT MVTSrc) const
Move from register and extend.
void buildClearRegister(Register Reg, MachineBasicBlock &MBB, MachineBasicBlock::iterator Iter, DebugLoc &DL, bool AllowSideEffects=true) const override
const M68kRegisterInfo & getRegisterInfo() const
TargetInstrInfo is a superset of MRegister info.
const M68kRegisterInfo RI
bool analyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB, MachineBasicBlock *&FBB, SmallVectorImpl< MachineOperand > &Cond, bool AllowModify) const override
ArrayRef< std::pair< unsigned, const char * > > getSerializableDirectMachineOperandTargetFlags() const override
bool expandPostRAPseudo(MachineInstr &MI) const override
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 MI, const DebugLoc &DL, Register DestReg, Register SrcReg, bool KillSrc, bool RenamableDest=false, bool RenamableSrc=false) const override
std::pair< unsigned, unsigned > decomposeMachineOperandsTargetFlags(unsigned TF) const override
bool AnalyzeBranchImpl(MachineBasicBlock &MBB, MachineBasicBlock *&TBB, MachineBasicBlock *&FBB, SmallVectorImpl< MachineOperand > &Cond, bool AllowModify) const
bool ExpandMOVX_RR(MachineInstrBuilder &MIB, MVT MVTDst, MVT MVTSrc) const
Move across register classes without extension.
void storeRegToStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, Register SrcReg, bool IsKill, int FrameIndex, const TargetRegisterClass *RC, Register VReg, MachineInstr::MIFlag Flags=MachineInstr::NoFlags) const override
void loadRegFromStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, Register DestReg, int FrameIndex, const TargetRegisterClass *RC, Register VReg, unsigned SubReg=0, MachineInstr::MIFlag Flags=MachineInstr::NoFlags) const override
bool isPCRelRegisterOperandLegal(const MachineInstr &MI, unsigned OpIdx) const override
bool ExpandMOVSZX_RM(MachineInstrBuilder &MIB, bool IsSigned, unsigned Opc, MVT MVTDst, MVT MVTSrc) const
Move from memory and extend.
bool ExpandMOVEM(MachineInstrBuilder &MIB, const MCInstrDesc &Desc, bool IsRM) const
Expand all MOVEM pseudos into real MOVEMs.
unsigned removeBranch(MachineBasicBlock &MBB, int *BytesRemoved=nullptr) const override
bool ExpandPUSH_POP(MachineInstrBuilder &MIB, const MCInstrDesc &Desc, bool IsPush) const
Push/Pop to/from stack.
M68kInstrInfo(const M68kSubtarget &STI)
void AddZExt(MachineBasicBlock &MBB, MachineBasicBlock::iterator I, DebugLoc DL, unsigned Reg, MVT From, MVT To) const
Add appropriate ZExt nodes.
bool ExpandMOVX_RM(MachineInstrBuilder &MIB, unsigned Opc, MVT MVTDst, MVT MVTSrc) const
Move from memory and expand register class without extension.
bool getStackSlotRange(const TargetRegisterClass *RC, unsigned SubIdx, unsigned &Size, unsigned &Offset, const MachineFunction &MF) const override
void AddSExt(MachineBasicBlock &MBB, MachineBasicBlock::iterator I, DebugLoc DL, unsigned Reg, MVT From, MVT To) const
Add appropriate SExt nodes.
bool isM68000() const
const M68kInstrInfo * getInstrInfo() const override
Describe properties that are true of each instruction in the target description file.
Machine Value Type.
LLVM_ABI DebugLoc findDebugLoc(instr_iterator MBBI)
Find the next valid DebugLoc starting at MBBI, skipping any debug instructions.
MachineInstrBundleIterator< MachineInstr > iterator
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted.
int64_t getObjectSize(int ObjectIdx) const
Return the size of the specified object.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
const MachineBasicBlock & front() const
const MachineInstrBuilder & addExternalSymbol(const char *FnName, unsigned TargetFlags=0) const
const MachineInstrBuilder & addReg(Register RegNo, RegState Flags={}, unsigned SubReg=0) const
Add a new virtual register operand.
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
const MachineInstrBuilder & add(const MachineOperand &MO) const
const MachineInstrBuilder & addMBB(MachineBasicBlock *MBB, unsigned TargetFlags=0) const
const MachineInstrBuilder & copyImplicitOps(const MachineInstr &OtherMI) const
Copy all the implicit operands from OtherMI onto this one.
MachineInstr * getInstr() const
If conversion operators fail, use this method to get the MachineInstr explicitly.
Representation of each machine instruction.
LLVM_ABI MachineInstr * removeFromParent()
Unlink 'this' from the containing basic block, and return it without deleting it.
const MachineBasicBlock * getParent() const
bool readsRegister(Register Reg, const TargetRegisterInfo *TRI) const
Return true if the MachineInstr reads the specified register.
LLVM_ABI void setDesc(const MCInstrDesc &TID)
Replace the instruction descriptor (thus opcode) of the current instruction with a new one.
const DebugLoc & getDebugLoc() const
Returns the debug location id of this MachineInstr.
const MachineOperand & getOperand(unsigned i) const
LLVM_ABI MachineInstrBundleIterator< MachineInstr > eraseFromParent()
Unlink 'this' from the containing basic block and delete it.
MachineOperand class - Representation of each machine instruction operand.
int64_t getImm() const
LLVM_ABI void setReg(Register Reg)
Change the register this operand corresponds to.
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 bool match(StringRef String, SmallVectorImpl< StringRef > *Matches=nullptr, std::string *Error=nullptr) const
matches - Match the regex against a given String.
Definition Regex.cpp:84
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...
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
This namespace holds all of the target specific flags that instruction info tracks.
@ MO_GOTPCREL
On a symbol operand this indicates that the immediate is offset to the GOT entry for the symbol name ...
Define some predicates that are used for node matching.
static const MachineInstrBuilder & addFrameReference(const MachineInstrBuilder &MIB, int FI, int Offset=0)
addFrameReference - This function is used to add a reference to the base of an abstract object on the...
static M68k::CondCode GetCondFromBranchOpc(unsigned Opcode)
This is an optimization pass for GlobalISel generic memory operations.
@ Offset
Definition DWP.cpp:577
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
@ Implicit
Not emitted register (e.g. carry, or temporary result).
@ Undef
Value of the register doesn't matter.
constexpr RegState getKillRegState(bool B)
LLVM_ABI void reportFatalInternalError(Error Err)
Report a fatal error that indicates a bug in LLVM.
Definition Error.cpp:173
Op::Description Desc
FunctionPass * createM68kGlobalBaseRegPass()
This pass initializes a global base register for PIC on M68k.
MachineInstr * getImm(const MachineOperand &MO, const MachineRegisterInfo *MRI)
decltype(auto) get(const PointerIntPair< PointerTy, IntBits, IntType, PtrTraits, Info > &Pair)
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition Debug.cpp:209
constexpr bool isUInt(uint64_t x)
Checks if an unsigned integer fits into the given bit width.
Definition MathExtras.h:190
@ Ref
The access may reference the value stored in memory.
Definition ModRef.h:32
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Count
Definition InstrProf.h:145
ArrayRef(const T &OneElt) -> ArrayRef< T >
MCRegisterClass TargetRegisterClass
Definition FastISel.h:58
Matching combinators.