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 MIB->removeFromParent();
389
390 // Sign extension doesn't matter if we only use the bottom 8 bits.
391 } else if (MVTSize == MVT::i8 ||
392 (!IsAddressReg && Imm >= -128 && Imm <= 127)) {
393 LLVM_DEBUG(dbgs() << "MOVEQ\n");
394
395 MIB->setDesc(get(M68k::MOVQ));
396 MIB->getOperand(0).setReg(SReg);
397
398 // Counter the effects of sign-extension with a bitwise not.
399 // This is only faster and smaller for 32 bit values.
400 } else if (DR32->contains(Reg) && isUInt<8>(Imm)) {
401 LLVM_DEBUG(dbgs() << "MOVEQ and NOT\n");
402
403 unsigned SubReg = RI.getSubReg(Reg, M68k::MxSubRegIndex8Lo);
404 assert(SubReg && "No viable SUB register available");
405
406 BuildMI(MBB, MIB.getInstr(), DL, get(M68k::MOVQ), SReg).addImm(~Imm & 0xFF);
407 BuildMI(MBB, MIB.getInstr(), DL, get(M68k::NOT8d), SubReg).addReg(SubReg);
408
409 MIB->removeFromParent();
410
411 // movea.w implicitly sign extends to the full register width,
412 // so exploit that if the immediate fits in the correct range.
413 //
414 // TODO: use lea imm.w, %an for further constants when 16-bit
415 // absolute addressing is implemented.
416 } else if (AR32->contains(Reg) && isUInt<16>(Imm)) {
417 LLVM_DEBUG(dbgs() << "MOVEA w/ implicit extend\n");
418
419 unsigned SubReg = RI.getSubReg(Reg, M68k::MxSubRegIndex16Lo);
420 assert(SubReg && "No viable SUB register available");
421
422 MIB->setDesc(get(M68k::MOV16ai));
423 MIB->getOperand(0).setReg(SubReg);
424
425 // Fall back to a move with immediate
426 } else {
427 LLVM_DEBUG(dbgs() << "MOVE\n");
428 MIB->setDesc(get(MVTSize == MVT::i16 ? M68k::MOV16ri : M68k::MOV32ri));
429 }
430
431 return true;
432}
433
435 MVT MVTSrc) const {
436 unsigned Move = MVTSrc == MVT::i8 ? M68k::MOV8dd : M68k::MOV16rr;
437 Register Dst = MIB->getOperand(0).getReg();
438 Register Src = MIB->getOperand(1).getReg();
439
440 assert(Dst != Src && "You cannot use the same Regs with MOVX_RR");
441
442 const auto &TRI = getRegisterInfo();
443
444 const auto *RCDst = TRI.getMaximalPhysRegClass(Dst, MVTDst);
445 const auto *RCSrc = TRI.getMaximalPhysRegClass(Src, MVTSrc);
446
447 assert(RCDst && RCSrc && "Wrong use of MOVX_RR");
448 assert(RCDst != RCSrc && "You cannot use the same Reg Classes with MOVX_RR");
449 (void)RCSrc;
450
451 unsigned SubDst =
452 RI.getSubReg(Dst, MVTSrc == MVT::i8 ? M68k::MxSubRegIndex8Lo
453 : M68k::MxSubRegIndex16Lo);
454 assert(SubDst && "No viable SUB register available");
455
456 // If source is a subregister of destination, we do nothing
457 if (SubDst == Src) {
458 LLVM_DEBUG(dbgs() << "Remove " << *MIB.getInstr() << '\n');
459 MIB->eraseFromParent();
460 } else { // otherwise we need to MOV
461 LLVM_DEBUG(dbgs() << "Expand " << *MIB.getInstr() << " to MOV\n");
462 MIB->setDesc(get(Move));
463 MIB->getOperand(0).setReg(SubDst);
464 }
465
466 return true;
467}
468
469/// Expand SExt MOVE pseudos into a MOV and a EXT if the operands are two
470/// different registers or just EXT if it is the same register
472 MVT MVTDst, MVT MVTSrc) const {
473 LLVM_DEBUG(dbgs() << "Expand " << *MIB.getInstr() << " to ");
474
475 Register Dst = MIB->getOperand(0).getReg();
476 Register Src = MIB->getOperand(1).getReg();
477
478 assert(Dst != Src && "You cannot use the same Regs with MOVSX_RR");
479
480 const auto &TRI = getRegisterInfo();
481
482 const auto *RCDst = TRI.getMaximalPhysRegClass(Dst, MVTDst);
483 const auto *RCSrc = TRI.getMaximalPhysRegClass(Src, MVTSrc);
484
485 assert(RCDst && RCSrc && "Wrong use of MOVSX_RR");
486 assert(RCDst != RCSrc && "You cannot use the same Reg Classes with MOVSX_RR");
487 (void)RCSrc;
488
489 // Move source into subreg of the destination.
490 unsigned SubDst =
491 RI.getSubReg(Dst, MVTSrc == MVT::i8 ? M68k::MxSubRegIndex8Lo
492 : M68k::MxSubRegIndex16Lo);
493 assert(SubDst && "No viable SUB register available");
494
496 DebugLoc DL = MIB->getDebugLoc();
497
498 unsigned Move;
499 if (MVTSrc == MVT::i8)
500 Move = M68k::MOV8dd;
501 else
502 Move = M68k::MOV16rr;
503
504 // It's more efficient to clear the destination and *then* move, rather than
505 // move and zext.
506 if (SubDst != Src && !IsSigned) {
507 LLVM_DEBUG(dbgs() << "Clear and Move" << '\n');
508
509 buildClearRegister(Dst, MBB, MIB.getInstr(), DL);
510
511 MIB->setDesc(get(Move));
512 MIB->getOperand(0).setReg(SubDst);
513 return true;
514 }
515
516 // Special case where move to AR16 automatically sign-extends to 32 bits.
517 // Even an in-place move (move.w a0,a0) will do so.
518 if (M68k::AR32RegClass.contains(Dst) && IsSigned) {
519 LLVM_DEBUG(dbgs() << "Move (implicit Sign Extend)" << '\n');
520 MIB->setDesc(get(M68k::MOV16ar));
521 MIB->getOperand(0).setReg(SubDst);
522 return true;
523 }
524
525 if (SubDst != Src) {
526 LLVM_DEBUG(dbgs() << "Move and " << '\n');
527 BuildMI(MBB, MIB.getInstr(), DL, get(Move), SubDst).addReg(Src);
528 }
529
530 if (IsSigned) {
531 LLVM_DEBUG(dbgs() << "Sign Extend" << '\n');
532 AddSExt(MBB, MIB.getInstr(), DL, Dst, MVTSrc, MVTDst);
533 } else {
534 LLVM_DEBUG(dbgs() << "Zero Extend" << '\n');
535 AddZExt(MBB, MIB.getInstr(), DL, Dst, MVTSrc, MVTDst);
536 }
537
538 MIB->eraseFromParent();
539
540 return true;
541}
542
544 MVT MVTDst, MVT MVTSrc) const {
545 LLVM_DEBUG(dbgs() << "Expand " << *MIB.getInstr() << " to LOAD" << '\n');
546
547 const MCInstrDesc &Desc = get(Opc);
548 Register Dst = MIB->getOperand(0).getReg();
549
550 // Load source into subreg of the destination.
551 unsigned SubDst =
552 RI.getSubReg(Dst, MVTSrc == MVT::i8 ? M68k::MxSubRegIndex8Lo
553 : M68k::MxSubRegIndex16Lo);
554 assert(SubDst && "No viable SUB register available");
555
556 // Make this a plain move
557 MIB->setDesc(Desc);
558 MIB->getOperand(0).setReg(SubDst);
559
560 return true;
561}
562
564 unsigned Opc, MVT MVTDst,
565 MVT MVTSrc) const {
566 LLVM_DEBUG(dbgs() << "Expand " << *MIB.getInstr() << " to ");
567
568 const MCInstrDesc &Desc = get(Opc);
569 Register Dst = MIB->getOperand(0).getReg();
570
571 // Load source into subreg of the destination.
572 unsigned SubDst =
573 RI.getSubReg(Dst, MVTSrc == MVT::i8 ? M68k::MxSubRegIndex8Lo
574 : M68k::MxSubRegIndex16Lo);
575 assert(SubDst && "No viable SUB register available");
576
577 // Make this a plain move
578 MIB->setDesc(Desc);
579 MIB->getOperand(0).setReg(SubDst);
580
581 // Special case where move to AR16 automatically sign-extends to 32 bits. In
582 // that case, we're already done.
583 if (M68k::AR32RegClass.contains(Dst) && IsSigned) {
584 LLVM_DEBUG(dbgs() << "LOAD (implicit Sign Extend)" << '\n');
585 return true;
586 }
587
590 DebugLoc DL = MIB->getDebugLoc();
591
592 // We can only clear before loading if the destination register isn't being
593 // used as an index for the load.
594 if (!IsSigned && !MIB->readsRegister(Dst, &RI)) {
595 LLVM_DEBUG(dbgs() << "Clear and LOAD" << '\n');
596 buildClearRegister(Dst, MBB, I, DL);
597
598 // Extend after load
599 } else {
600 I++;
601 if (IsSigned) {
602 LLVM_DEBUG(dbgs() << "LOAD and Sign Extend" << '\n');
603 AddSExt(MBB, I, DL, Dst, MVTSrc, MVTDst);
604 } else {
605 LLVM_DEBUG(dbgs() << "Zero Extend" << '\n');
606 AddZExt(MBB, I, DL, Dst, MVTSrc, MVTDst);
607 }
608 }
609
610 return true;
611}
612
614 const MCInstrDesc &Desc, bool IsPush) const {
616 I++;
618 MachineOperand MO = MIB->getOperand(0);
619 DebugLoc DL = MIB->getDebugLoc();
620 if (IsPush)
621 BuildMI(MBB, I, DL, Desc).addReg(RI.getStackRegister()).add(MO);
622 else
623 BuildMI(MBB, I, DL, Desc, MO.getReg()).addReg(RI.getStackRegister());
624
625 MIB->eraseFromParent();
626 return true;
627}
628
630 const MCInstrDesc &Desc, bool IsRM) const {
631 int Reg = 0, Offset = 0, Base = 0;
632 auto DL = MIB->getDebugLoc();
633 auto MI = MIB.getInstr();
634 auto &MBB = *MIB->getParent();
635
636 if (IsRM) {
637 Reg = MIB->getOperand(0).getReg();
638 Offset = MIB->getOperand(1).getImm();
639 Base = MIB->getOperand(2).getReg();
640 } else {
641 Offset = MIB->getOperand(0).getImm();
642 Base = MIB->getOperand(1).getReg();
643 Reg = MIB->getOperand(2).getReg();
644 }
645
646 unsigned Mask = 1 << RI.getSpillRegisterOrder(Reg);
647 if (IsRM) {
648 BuildMI(MBB, MI, DL, Desc)
649 .addImm(Mask)
650 .addImm(Offset)
651 .addReg(Base)
653 .copyImplicitOps(*MIB);
654 } else {
655 BuildMI(MBB, MI, DL, Desc)
656 .addImm(Offset)
657 .addReg(Base)
658 .addImm(Mask)
660 .copyImplicitOps(*MIB);
661 }
662
663 MIB->eraseFromParent();
664
665 return true;
666}
667
670 DebugLoc &DL,
671 bool AllowSideEffects) const {
672 // Clear an address register by subtracting it from itself.
673 if (M68k::AR32RegClass.contains(Reg)) {
674 BuildMI(MBB, Iter, DL, get(M68k::SUB32ar), Reg)
676 .addReg(Reg, RegState::Undef);
677 return;
678 }
679
680 if (M68k::DR8RegClass.contains(Reg))
681 BuildMI(MBB, Iter, DL, get(M68k::CLR8d), Reg);
682 else if (M68k::DR16RegClass.contains(Reg))
683 BuildMI(MBB, Iter, DL, get(M68k::CLR16d), Reg);
684 else if (M68k::DR32RegClass.contains(Reg))
685 BuildMI(MBB, Iter, DL, get(M68k::MOVQ), Reg).addImm(0);
686 else
688 "buildClearRegister is not implemented for " + RI.getRegAsmName(Reg));
689}
690
692 MachineInstrBuilder MIB(*MI.getParent()->getParent(), MI);
693 switch (MI.getOpcode()) {
694 case M68k::PUSH8d:
695 return ExpandPUSH_POP(MIB, get(M68k::MOV8ed), true);
696 case M68k::PUSH16d:
697 return ExpandPUSH_POP(MIB, get(M68k::MOV16er), true);
698 case M68k::PUSH32r:
699 return ExpandPUSH_POP(MIB, get(M68k::MOV32er), true);
700
701 case M68k::POP8d:
702 return ExpandPUSH_POP(MIB, get(M68k::MOV8do), false);
703 case M68k::POP16d:
704 return ExpandPUSH_POP(MIB, get(M68k::MOV16ro), false);
705 case M68k::POP32r:
706 return ExpandPUSH_POP(MIB, get(M68k::MOV32ro), false);
707 }
708 return false;
709}
710
712 unsigned OpIdx) const {
713 assert(MI.getOperand(OpIdx).isReg());
714
715 // Check whether this operand belongs to an instruction with addressing mode
716 // 'k', Refer to TargetInstrInfo.h for more information about this function.
717
718 const unsigned NameIndices = M68kInstrNameIndices[MI.getOpcode()];
719 StringRef InstrName(&M68kInstrNameData[NameIndices]);
720
721 // If this machine operand is the 2nd operand, then check
722 // whether the instruction has destination addressing mode 'k'.
723 if (OpIdx == 1)
724 return Regex("[A-Z]+(8|16|32)k[a-z](_TC)?$").match(InstrName);
725
726 // If this machine operand is the last one, then check
727 // whether the instruction has source addressing mode 'k'.
728 if (OpIdx == MI.getNumExplicitOperands() - 1)
729 return Regex("[A-Z]+(8|16|32)[a-z]k(_TC)?$").match(InstrName);
730
731 return false;
732}
733
736 const DebugLoc &DL, Register DstReg,
737 Register SrcReg, bool KillSrc,
738 bool RenamableDest, bool RenamableSrc) const {
739 unsigned Opc = 0;
740 MachineFunction &MF = *MBB.getParent();
741 const M68kSubtarget &STI = MF.getSubtarget<M68kSubtarget>();
742
743 // Symmetric register copies
744 if (M68k::XR32RegClass.contains(DstReg, SrcReg)) {
745 Opc = M68k::MOV32rr;
746 } else if (M68k::XR16RegClass.contains(DstReg, SrcReg)) {
747 Opc = M68k::MOV16rr;
748 } else if (M68k::DR8RegClass.contains(DstReg, SrcReg)) {
749 Opc = M68k::MOV8dd;
750 }
751
752 // Asymmetric register copies
753 // NOTE: There is no implicit sext/zext occurring during these moves, so the
754 // upper bits will be undefined.
755 // 8 -> 16
756 else if (M68k::DR8RegClass.contains(SrcReg) &&
757 M68k::DR16RegClass.contains(DstReg)) {
758 Opc = M68k::MOVXd16d8;
759 // 8 -> 32
760 } else if (M68k::DR8RegClass.contains(SrcReg) &&
761 M68k::DR32RegClass.contains(DstReg)) {
762 Opc = M68k::MOVXd32d8;
763 // 16 -> 32
764 } else if (M68k::XR16RegClass.contains(SrcReg) &&
765 M68k::XR32RegClass.contains(DstReg)) {
766 Opc = M68k::MOVXr32r16;
767 }
768
769 // Copy from CCR
770 // NOTE: M68000 uses MOVE from SR to copy from CCR, all other variants use
771 // MOVE from CCR.
772 else if (SrcReg == M68k::CCR) {
773 if (M68k::DR8RegClass.contains(DstReg) ||
774 M68k::DR16RegClass.contains(DstReg) ||
775 M68k::DR32RegClass.contains(DstReg)) {
776 Opc = STI.isM68000() ? M68k::MOV16ds : M68k::MOV16dc;
777 } else {
778 LLVM_DEBUG(dbgs() << "Cannot copy CCR to " << RI.getName(DstReg) << '\n');
779 llvm_unreachable("Invalid register for MOVE from CCR");
780 }
781 }
782
783 // Copy to CCR
784 else if (DstReg == M68k::CCR) {
785 if (M68k::DR8RegClass.contains(SrcReg) ||
786 M68k::DR16RegClass.contains(SrcReg) ||
787 M68k::DR32RegClass.contains(SrcReg)) {
788 Opc = M68k::MOV16cd;
789 } else {
790 LLVM_DEBUG(dbgs() << "Cannot copy " << RI.getName(SrcReg) << " to CCR\n");
791 llvm_unreachable("Invalid register for MOVE to CCR");
792 }
793 }
794
795 // SR should never be a valid register for copying
796 else if (SrcReg == M68k::SR || DstReg == M68k::SR)
797 llvm_unreachable("Cannot explicitly copy to/from SR");
798
799 // We should now have our opcode
800 if (!Opc) {
801 LLVM_DEBUG(dbgs() << "Cannot copy " << RI.getName(SrcReg) << " to "
802 << RI.getName(DstReg) << '\n');
803 llvm_unreachable("Cannot emit physreg copy instruction");
804 }
805
806 // FIXME
807 // Below is a workaround to prevent a live CCR from being killed by the COPY
808 // instruction. LLVM sometimes inserts a COPY pseudo instruction between
809 // compare and branch during MIR generation (e.g. during PHI node elimination)
810 // without any idea that on M68k, this is extremely likely to implicitly kill
811 // the CCR.
812 // The workaround checks whether CCR is live during this copy, and if so,
813 // backs up CCR and restores it after the copy. It's inefficient and prevents
814 // M68000-targeted builds from running on 010+ (because 000 uses MOVE from SR
815 // and 010+ uses MOVE from CCR).
816 // The fix condition is to prevent COPY from ever being inserted while CCR is
817 // live (which would also stop this workaround from ever triggering).
818
819 unsigned CCRSrcReg = STI.isM68000() ? M68k::SR : M68k::CCR;
820
821 // Get the live registers right before the COPY instruction. If CCR is
822 // live, the MOVE is going to kill it, so we will need to preserve it.
823 LiveRegUnits UsedRegs(RI);
824 UsedRegs.addLiveOuts(MBB);
825 auto InstUpToI = MBB.end();
826 while (InstUpToI != MI) {
827 UsedRegs.stepBackward(*--InstUpToI);
828 }
829
830 if (SrcReg == M68k::CCR) {
831 BuildMI(MBB, MI, DL, get(Opc), DstReg).addReg(CCRSrcReg);
832 return;
833 }
834 if (DstReg == M68k::CCR) {
835 BuildMI(MBB, MI, DL, get(Opc), M68k::CCR)
836 .addReg(SrcReg, getKillRegState(KillSrc));
837 return;
838 }
839 if (UsedRegs.available(M68k::CCR)) {
840 BuildMI(MBB, MI, DL, get(Opc), DstReg)
841 .addReg(SrcReg, getKillRegState(KillSrc));
842 return;
843 }
844
845 // CCR is live, so we must restore it after the copy. Prepare push/pop ops.
846 // 68000 must use MOVE from SR, 68010+ must use MOVE from CCR. In either
847 // case, upon moving back, MOVE to CCR will mask out the upper byte anyway.
848
849 // Look for an available data register for the CCR, or push to stack if
850 // there are none
851 BitVector Allocatable =
852 RI.getAllocatableSet(MF, RI.getRegClass(M68k::DR16RegClassID));
853 for (Register Reg : Allocatable.set_bits()) {
854 if (!RI.regsOverlap(DstReg, Reg) && (UsedRegs.available(Reg))) {
855 unsigned CCRPushOp = STI.isM68000() ? M68k::MOV16ds : M68k::MOV16dc;
856 unsigned CCRPopOp = M68k::MOV16cd;
857 BuildMI(MBB, MI, DL, get(CCRPushOp), Reg).addReg(CCRSrcReg);
858 BuildMI(MBB, MI, DL, get(Opc), DstReg)
859 .addReg(SrcReg, getKillRegState(KillSrc));
860 BuildMI(MBB, MI, DL, get(CCRPopOp), M68k::CCR).addReg(Reg);
861 return;
862 }
863 }
864
865 unsigned CCRPushOp = STI.isM68000() ? M68k::MOV16es : M68k::MOV16ec;
866 unsigned CCRPopOp = M68k::MOV16co;
867
868 BuildMI(MBB, MI, DL, get(CCRPushOp))
869 .addReg(RI.getStackRegister())
870 .addReg(CCRSrcReg);
871 BuildMI(MBB, MI, DL, get(Opc), DstReg)
872 .addReg(SrcReg, getKillRegState(KillSrc));
873 BuildMI(MBB, MI, DL, get(CCRPopOp), M68k::CCR).addReg(RI.getStackRegister());
874 return;
875}
876
877namespace {
878unsigned getLoadStoreRegOpcode(unsigned Reg, const TargetRegisterClass *RC,
879 const TargetRegisterInfo *TRI,
880 const M68kSubtarget &STI, bool load) {
881 switch (TRI->getSpillSize(*RC)) {
882 default:
884 dbgs() << "Cannot determine appropriate opcode for load/store to/from "
885 << TRI->getName(Reg) << " of class " << TRI->getRegClassName(RC)
886 << " with spill size " << TRI->getSpillSize(*RC) << '\n');
887 llvm_unreachable("Unknown spill size");
888 case 2:
889 if (M68k::XR16RegClass.hasSubClassEq(RC))
890 return load ? M68k::MOVM16mp_P : M68k::MOVM16pm_P;
891 if (M68k::DR8RegClass.hasSubClassEq(RC))
892 return load ? M68k::MOVM8mp_P : M68k::MOVM8pm_P;
893 if (M68k::CCRCRegClass.hasSubClassEq(RC))
894 return load ? M68k::MOVM16mp_P : M68k::MOVM16pm_P;
895 llvm_unreachable("Unknown 2-byte regclass");
896 case 4:
897 if (M68k::XR32RegClass.hasSubClassEq(RC))
898 return load ? M68k::MOVM32mp_P : M68k::MOVM32pm_P;
899 llvm_unreachable("Unknown 4-byte regclass");
900 }
901}
902
903unsigned getStoreRegOpcode(unsigned SrcReg, const TargetRegisterClass *RC,
904 const TargetRegisterInfo *TRI,
905 const M68kSubtarget &STI) {
906 return getLoadStoreRegOpcode(SrcReg, RC, TRI, STI, false);
907}
908
909unsigned getLoadRegOpcode(unsigned DstReg, const TargetRegisterClass *RC,
910 const TargetRegisterInfo *TRI,
911 const M68kSubtarget &STI) {
912 return getLoadStoreRegOpcode(DstReg, RC, TRI, STI, true);
913}
914} // end anonymous namespace
915
917 unsigned SubIdx, unsigned &Size,
918 unsigned &Offset,
919 const MachineFunction &MF) const {
920 // The slot size must be the maximum size so we can easily use MOVEM.L
921 Size = 4;
922 Offset = 0;
923 return true;
924}
925
928 bool IsKill, int FrameIndex, const TargetRegisterClass *RC, Register VReg,
929 MachineInstr::MIFlag Flags) const {
930 const MachineFrameInfo &MFI = MBB.getParent()->getFrameInfo();
931 assert(MFI.getObjectSize(FrameIndex) >= TRI.getSpillSize(*RC) &&
932 "Stack slot is too small to store");
933 (void)MFI;
934
935 unsigned Opc = getStoreRegOpcode(SrcReg, RC, &TRI, Subtarget);
936 DebugLoc DL = MBB.findDebugLoc(MI);
937 // (0,FrameIndex) <- $reg
938 M68k::addFrameReference(BuildMI(MBB, MI, DL, get(Opc)), FrameIndex)
939 .addReg(SrcReg, getKillRegState(IsKill));
940}
941
944 Register DstReg, int FrameIndex,
945 const TargetRegisterClass *RC,
946 Register VReg, unsigned SubReg,
947 MachineInstr::MIFlag Flags) const {
948 const MachineFrameInfo &MFI = MBB.getParent()->getFrameInfo();
949 assert(MFI.getObjectSize(FrameIndex) >= TRI.getSpillSize(*RC) &&
950 "Stack slot is too small to load");
951 (void)MFI;
952
953 unsigned Opc = getLoadRegOpcode(DstReg, RC, &TRI, Subtarget);
954 DebugLoc DL = MBB.findDebugLoc(MI);
955 M68k::addFrameReference(BuildMI(MBB, MI, DL, get(Opc), DstReg), FrameIndex);
956}
957
958/// Return a virtual register initialized with the global base register
959/// value. Output instructions required to initialize the register in the
960/// function entry block, if necessary.
961///
962/// TODO Move this function to M68kMachineFunctionInfo.
965 unsigned GlobalBaseReg = MxFI->getGlobalBaseReg();
966 if (GlobalBaseReg != 0)
967 return GlobalBaseReg;
968
969 // Create the register. The code to initialize it is inserted later,
970 // by the M68kGlobalBaseReg pass (below).
971 //
972 // NOTE
973 // Normally M68k uses A5 register as global base pointer but this will
974 // create unnecessary spill if we use less then 4 registers in code; since A5
975 // is callee-save anyway we could try to allocate caller-save first and if
976 // lucky get one, otherwise it does not really matter which callee-save to
977 // use.
978 MachineRegisterInfo &RegInfo = MF->getRegInfo();
979 GlobalBaseReg = RegInfo.createVirtualRegister(&M68k::AR32_NOSPRegClass);
980 MxFI->setGlobalBaseReg(GlobalBaseReg);
981 return GlobalBaseReg;
982}
983
984std::pair<unsigned, unsigned>
986 return std::make_pair(TF, 0u);
987}
988
991 using namespace M68kII;
992 static const std::pair<unsigned, const char *> TargetFlags[] = {
993 {MO_ABSOLUTE_ADDRESS, "m68k-absolute"},
994 {MO_PC_RELATIVE_ADDRESS, "m68k-pcrel"},
995 {MO_GOT, "m68k-got"},
996 {MO_GOTOFF, "m68k-gotoff"},
997 {MO_GOTPCREL, "m68k-gotpcrel"},
998 {MO_PLT, "m68k-plt"},
999 {MO_TLSGD, "m68k-tlsgd"},
1000 {MO_TLSLD, "m68k-tlsld"},
1001 {MO_TLSLDM, "m68k-tlsldm"},
1002 {MO_TLSIE, "m68k-tlsie"},
1003 {MO_TLSLE, "m68k-tlsle"}};
1004 return ArrayRef(TargetFlags);
1005}
1006
1007#undef DEBUG_TYPE
1008#define DEBUG_TYPE "m68k-create-global-base-reg"
1009
1010#define PASS_NAME "M68k PIC Global Base Reg Initialization"
1011
1012namespace {
1013/// This initializes the PIC global base register
1014struct M68kGlobalBaseReg : public MachineFunctionPass {
1015 static char ID;
1016 M68kGlobalBaseReg() : MachineFunctionPass(ID) {}
1017
1018 bool runOnMachineFunction(MachineFunction &MF) override {
1019 const M68kSubtarget &STI = MF.getSubtarget<M68kSubtarget>();
1021
1022 unsigned GlobalBaseReg = MxFI->getGlobalBaseReg();
1023
1024 // If we didn't need a GlobalBaseReg, don't insert code.
1025 if (GlobalBaseReg == 0)
1026 return false;
1027
1028 // Insert the set of GlobalBaseReg into the first MBB of the function
1029 MachineBasicBlock &FirstMBB = MF.front();
1031 DebugLoc DL = FirstMBB.findDebugLoc(MBBI);
1032 const M68kInstrInfo *TII = STI.getInstrInfo();
1033
1034 // Generate lea (__GLOBAL_OFFSET_TABLE_,%PC), %A5
1035 BuildMI(FirstMBB, MBBI, DL, TII->get(M68k::LEA32q), GlobalBaseReg)
1036 .addExternalSymbol("_GLOBAL_OFFSET_TABLE_", M68kII::MO_GOTPCREL);
1037
1038 return true;
1039 }
1040
1041 void getAnalysisUsage(AnalysisUsage &AU) const override {
1042 AU.setPreservesCFG();
1044 }
1045};
1046char M68kGlobalBaseReg::ID = 0;
1047} // namespace
1048
1049INITIALIZE_PASS(M68kGlobalBaseReg, DEBUG_TYPE, PASS_NAME, false, false)
1050
1052 return new M68kGlobalBaseReg();
1053}
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.
SmallVector< MachineOperand, 4 > Cond
unsigned Opc
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
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:479
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:160
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.