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 extention 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
693/// Expand a single-def pseudo instruction to a two-addr
694/// instruction with two undef reads of the register being defined.
695/// This is used for mapping:
696/// %d0 = SETCS_C32d
697/// to:
698/// %d0 = SUBX32dd %d0<undef>, %d0<undef>
699///
701 const MCInstrDesc &Desc) {
702 assert(Desc.getNumOperands() == 3 && "Expected two-addr instruction.");
703 Register Reg = MIB->getOperand(0).getReg();
704 MIB->setDesc(Desc);
705
706 // MachineInstr::addOperand() will insert explicit operands before any
707 // implicit operands.
709 // But we don't trust that.
710 assert(MIB->getOperand(1).getReg() == Reg &&
711 MIB->getOperand(2).getReg() == Reg && "Misplaced operand");
712 return true;
713}
714
716 MachineInstrBuilder MIB(*MI.getParent()->getParent(), MI);
717 switch (MI.getOpcode()) {
718 case M68k::PUSH8d:
719 return ExpandPUSH_POP(MIB, get(M68k::MOV8ed), true);
720 case M68k::PUSH16d:
721 return ExpandPUSH_POP(MIB, get(M68k::MOV16er), true);
722 case M68k::PUSH32r:
723 return ExpandPUSH_POP(MIB, get(M68k::MOV32er), true);
724
725 case M68k::POP8d:
726 return ExpandPUSH_POP(MIB, get(M68k::MOV8do), false);
727 case M68k::POP16d:
728 return ExpandPUSH_POP(MIB, get(M68k::MOV16ro), false);
729 case M68k::POP32r:
730 return ExpandPUSH_POP(MIB, get(M68k::MOV32ro), false);
731
732 case M68k::SETCS_C8d:
733 return Expand2AddrUndef(MIB, get(M68k::SUBX8dd));
734 case M68k::SETCS_C16d:
735 return Expand2AddrUndef(MIB, get(M68k::SUBX16dd));
736 case M68k::SETCS_C32d:
737 return Expand2AddrUndef(MIB, get(M68k::SUBX32dd));
738 }
739 return false;
740}
741
743 unsigned OpIdx) const {
744 assert(MI.getOperand(OpIdx).isReg());
745
746 // Check whether this operand belongs to an instruction with addressing mode
747 // 'k', Refer to TargetInstrInfo.h for more information about this function.
748
749 const unsigned NameIndices = M68kInstrNameIndices[MI.getOpcode()];
750 StringRef InstrName(&M68kInstrNameData[NameIndices]);
751
752 // If this machine operand is the 2nd operand, then check
753 // whether the instruction has destination addressing mode 'k'.
754 if (OpIdx == 1)
755 return Regex("[A-Z]+(8|16|32)k[a-z](_TC)?$").match(InstrName);
756
757 // If this machine operand is the last one, then check
758 // whether the instruction has source addressing mode 'k'.
759 if (OpIdx == MI.getNumExplicitOperands() - 1)
760 return Regex("[A-Z]+(8|16|32)[a-z]k(_TC)?$").match(InstrName);
761
762 return false;
763}
764
767 const DebugLoc &DL, Register DstReg,
768 Register SrcReg, bool KillSrc,
769 bool RenamableDest, bool RenamableSrc) const {
770 unsigned Opc = 0;
771 MachineFunction &MF = *MBB.getParent();
772 const M68kSubtarget &STI = MF.getSubtarget<M68kSubtarget>();
773
774 // Symmetric register copies
775 if (M68k::XR32RegClass.contains(DstReg, SrcReg)) {
776 Opc = M68k::MOV32rr;
777 } else if (M68k::XR16RegClass.contains(DstReg, SrcReg)) {
778 Opc = M68k::MOV16rr;
779 } else if (M68k::DR8RegClass.contains(DstReg, SrcReg)) {
780 Opc = M68k::MOV8dd;
781 }
782
783 // Asymmetric register copies
784 // NOTE: There is no implicit sext/zext occurring during these moves, so the
785 // upper bits will be undefined.
786 // 8 -> 16
787 else if (M68k::DR8RegClass.contains(SrcReg) &&
788 M68k::DR16RegClass.contains(DstReg)) {
789 Opc = M68k::MOVXd16d8;
790 // 8 -> 32
791 } else if (M68k::DR8RegClass.contains(SrcReg) &&
792 M68k::DR32RegClass.contains(DstReg)) {
793 Opc = M68k::MOVXd32d8;
794 // 16 -> 32
795 } else if (M68k::XR16RegClass.contains(SrcReg) &&
796 M68k::XR32RegClass.contains(DstReg)) {
797 Opc = M68k::MOVXr32r16;
798 }
799
800 // Copy from CCR
801 // NOTE: M68000 uses MOVE from SR to copy from CCR, all other variants use
802 // MOVE from CCR.
803 else if (SrcReg == M68k::CCR) {
804 if (M68k::DR8RegClass.contains(DstReg) ||
805 M68k::DR16RegClass.contains(DstReg) ||
806 M68k::DR32RegClass.contains(DstReg)) {
807 Opc = STI.isM68000() ? M68k::MOV16ds : M68k::MOV16dc;
808 } else {
809 LLVM_DEBUG(dbgs() << "Cannot copy CCR to " << RI.getName(DstReg) << '\n');
810 llvm_unreachable("Invalid register for MOVE from CCR");
811 }
812 }
813
814 // Copy to CCR
815 else if (DstReg == M68k::CCR) {
816 if (M68k::DR8RegClass.contains(SrcReg) ||
817 M68k::DR16RegClass.contains(SrcReg) ||
818 M68k::DR32RegClass.contains(SrcReg)) {
819 Opc = M68k::MOV16cd;
820 } else {
821 LLVM_DEBUG(dbgs() << "Cannot copy " << RI.getName(SrcReg) << " to CCR\n");
822 llvm_unreachable("Invalid register for MOVE to CCR");
823 }
824 }
825
826 // SR should never be a valid register for copying
827 else if (SrcReg == M68k::SR || DstReg == M68k::SR)
828 llvm_unreachable("Cannot explicitly copy to/from SR");
829
830 // We should now have our opcode
831 if (!Opc) {
832 LLVM_DEBUG(dbgs() << "Cannot copy " << RI.getName(SrcReg) << " to "
833 << RI.getName(DstReg) << '\n');
834 llvm_unreachable("Cannot emit physreg copy instruction");
835 }
836
837 // FIXME
838 // Below is a workaround to prevent a live CCR from being killed by the COPY
839 // instruction. LLVM sometimes inserts a COPY pseudo instruction between
840 // compare and branch during MIR generation (e.g. during PHI node elimination)
841 // without any idea that on M68k, this is extremely likely to implicitly kill
842 // the CCR.
843 // The workaround checks whether CCR is live during this copy, and if so,
844 // backs up CCR and restores it after the copy. It's inefficient and prevents
845 // M68000-targeted builds from running on 010+ (because 000 uses MOVE from SR
846 // and 010+ uses MOVE from CCR).
847 // The fix condition is to prevent COPY from ever being inserted while CCR is
848 // live (which would also stop this workaround from ever triggering).
849
850 unsigned CCRSrcReg = STI.isM68000() ? M68k::SR : M68k::CCR;
851
852 // Get the live registers right before the COPY instruction. If CCR is
853 // live, the MOVE is going to kill it, so we will need to preserve it.
854 LiveRegUnits UsedRegs(RI);
855 UsedRegs.addLiveOuts(MBB);
856 auto InstUpToI = MBB.end();
857 while (InstUpToI != MI) {
858 UsedRegs.stepBackward(*--InstUpToI);
859 }
860
861 if (SrcReg == M68k::CCR) {
862 BuildMI(MBB, MI, DL, get(Opc), DstReg).addReg(CCRSrcReg);
863 return;
864 }
865 if (DstReg == M68k::CCR) {
866 BuildMI(MBB, MI, DL, get(Opc), M68k::CCR)
867 .addReg(SrcReg, getKillRegState(KillSrc));
868 return;
869 }
870 if (UsedRegs.available(M68k::CCR)) {
871 BuildMI(MBB, MI, DL, get(Opc), DstReg)
872 .addReg(SrcReg, getKillRegState(KillSrc));
873 return;
874 }
875
876 // CCR is live, so we must restore it after the copy. Prepare push/pop ops.
877 // 68000 must use MOVE from SR, 68010+ must use MOVE from CCR. In either
878 // case, upon moving back, MOVE to CCR will mask out the upper byte anyway.
879
880 // Look for an available data register for the CCR, or push to stack if
881 // there are none
882 BitVector Allocatable =
883 RI.getAllocatableSet(MF, RI.getRegClass(M68k::DR16RegClassID));
884 for (Register Reg : Allocatable.set_bits()) {
885 if (!RI.regsOverlap(DstReg, Reg) && (UsedRegs.available(Reg))) {
886 unsigned CCRPushOp = STI.isM68000() ? M68k::MOV16ds : M68k::MOV16dc;
887 unsigned CCRPopOp = M68k::MOV16cd;
888 BuildMI(MBB, MI, DL, get(CCRPushOp), Reg).addReg(CCRSrcReg);
889 BuildMI(MBB, MI, DL, get(Opc), DstReg)
890 .addReg(SrcReg, getKillRegState(KillSrc));
891 BuildMI(MBB, MI, DL, get(CCRPopOp), M68k::CCR).addReg(Reg);
892 return;
893 }
894 }
895
896 unsigned CCRPushOp = STI.isM68000() ? M68k::MOV16es : M68k::MOV16ec;
897 unsigned CCRPopOp = M68k::MOV16co;
898
899 BuildMI(MBB, MI, DL, get(CCRPushOp))
900 .addReg(RI.getStackRegister())
901 .addReg(CCRSrcReg);
902 BuildMI(MBB, MI, DL, get(Opc), DstReg)
903 .addReg(SrcReg, getKillRegState(KillSrc));
904 BuildMI(MBB, MI, DL, get(CCRPopOp), M68k::CCR).addReg(RI.getStackRegister());
905 return;
906}
907
908namespace {
909unsigned getLoadStoreRegOpcode(unsigned Reg, const TargetRegisterClass *RC,
910 const TargetRegisterInfo *TRI,
911 const M68kSubtarget &STI, bool load) {
912 switch (TRI->getSpillSize(*RC)) {
913 default:
915 dbgs() << "Cannot determine appropriate opcode for load/store to/from "
916 << TRI->getName(Reg) << " of class " << TRI->getRegClassName(RC)
917 << " with spill size " << TRI->getSpillSize(*RC) << '\n');
918 llvm_unreachable("Unknown spill size");
919 case 2:
920 if (M68k::XR16RegClass.hasSubClassEq(RC))
921 return load ? M68k::MOVM16mp_P : M68k::MOVM16pm_P;
922 if (M68k::DR8RegClass.hasSubClassEq(RC))
923 return load ? M68k::MOVM8mp_P : M68k::MOVM8pm_P;
924 if (M68k::CCRCRegClass.hasSubClassEq(RC))
925 return load ? M68k::MOVM16mp_P : M68k::MOVM16pm_P;
926 llvm_unreachable("Unknown 2-byte regclass");
927 case 4:
928 if (M68k::XR32RegClass.hasSubClassEq(RC))
929 return load ? M68k::MOVM32mp_P : M68k::MOVM32pm_P;
930 llvm_unreachable("Unknown 4-byte regclass");
931 }
932}
933
934unsigned getStoreRegOpcode(unsigned SrcReg, const TargetRegisterClass *RC,
935 const TargetRegisterInfo *TRI,
936 const M68kSubtarget &STI) {
937 return getLoadStoreRegOpcode(SrcReg, RC, TRI, STI, false);
938}
939
940unsigned getLoadRegOpcode(unsigned DstReg, const TargetRegisterClass *RC,
941 const TargetRegisterInfo *TRI,
942 const M68kSubtarget &STI) {
943 return getLoadStoreRegOpcode(DstReg, RC, TRI, STI, true);
944}
945} // end anonymous namespace
946
948 unsigned SubIdx, unsigned &Size,
949 unsigned &Offset,
950 const MachineFunction &MF) const {
951 // The slot size must be the maximum size so we can easily use MOVEM.L
952 Size = 4;
953 Offset = 0;
954 return true;
955}
956
959 bool IsKill, int FrameIndex, const TargetRegisterClass *RC, Register VReg,
960 MachineInstr::MIFlag Flags) const {
961 const MachineFrameInfo &MFI = MBB.getParent()->getFrameInfo();
962 assert(MFI.getObjectSize(FrameIndex) >= TRI.getSpillSize(*RC) &&
963 "Stack slot is too small to store");
964 (void)MFI;
965
966 unsigned Opc = getStoreRegOpcode(SrcReg, RC, &TRI, Subtarget);
967 DebugLoc DL = MBB.findDebugLoc(MI);
968 // (0,FrameIndex) <- $reg
969 M68k::addFrameReference(BuildMI(MBB, MI, DL, get(Opc)), FrameIndex)
970 .addReg(SrcReg, getKillRegState(IsKill));
971}
972
975 Register DstReg, int FrameIndex,
976 const TargetRegisterClass *RC,
977 Register VReg, unsigned SubReg,
978 MachineInstr::MIFlag Flags) const {
979 const MachineFrameInfo &MFI = MBB.getParent()->getFrameInfo();
980 assert(MFI.getObjectSize(FrameIndex) >= TRI.getSpillSize(*RC) &&
981 "Stack slot is too small to load");
982 (void)MFI;
983
984 unsigned Opc = getLoadRegOpcode(DstReg, RC, &TRI, Subtarget);
985 DebugLoc DL = MBB.findDebugLoc(MI);
986 M68k::addFrameReference(BuildMI(MBB, MI, DL, get(Opc), DstReg), FrameIndex);
987}
988
989/// Return a virtual register initialized with the global base register
990/// value. Output instructions required to initialize the register in the
991/// function entry block, if necessary.
992///
993/// TODO Move this function to M68kMachineFunctionInfo.
996 unsigned GlobalBaseReg = MxFI->getGlobalBaseReg();
997 if (GlobalBaseReg != 0)
998 return GlobalBaseReg;
999
1000 // Create the register. The code to initialize it is inserted later,
1001 // by the M68kGlobalBaseReg pass (below).
1002 //
1003 // NOTE
1004 // Normally M68k uses A5 register as global base pointer but this will
1005 // create unnecessary spill if we use less then 4 registers in code; since A5
1006 // is callee-save anyway we could try to allocate caller-save first and if
1007 // lucky get one, otherwise it does not really matter which callee-save to
1008 // use.
1009 MachineRegisterInfo &RegInfo = MF->getRegInfo();
1010 GlobalBaseReg = RegInfo.createVirtualRegister(&M68k::AR32_NOSPRegClass);
1011 MxFI->setGlobalBaseReg(GlobalBaseReg);
1012 return GlobalBaseReg;
1013}
1014
1015std::pair<unsigned, unsigned>
1017 return std::make_pair(TF, 0u);
1018}
1019
1022 using namespace M68kII;
1023 static const std::pair<unsigned, const char *> TargetFlags[] = {
1024 {MO_ABSOLUTE_ADDRESS, "m68k-absolute"},
1025 {MO_PC_RELATIVE_ADDRESS, "m68k-pcrel"},
1026 {MO_GOT, "m68k-got"},
1027 {MO_GOTOFF, "m68k-gotoff"},
1028 {MO_GOTPCREL, "m68k-gotpcrel"},
1029 {MO_PLT, "m68k-plt"},
1030 {MO_TLSGD, "m68k-tlsgd"},
1031 {MO_TLSLD, "m68k-tlsld"},
1032 {MO_TLSLDM, "m68k-tlsldm"},
1033 {MO_TLSIE, "m68k-tlsie"},
1034 {MO_TLSLE, "m68k-tlsle"}};
1035 return ArrayRef(TargetFlags);
1036}
1037
1038#undef DEBUG_TYPE
1039#define DEBUG_TYPE "m68k-create-global-base-reg"
1040
1041#define PASS_NAME "M68k PIC Global Base Reg Initialization"
1042
1043namespace {
1044/// This initializes the PIC global base register
1045struct M68kGlobalBaseReg : public MachineFunctionPass {
1046 static char ID;
1047 M68kGlobalBaseReg() : MachineFunctionPass(ID) {}
1048
1049 bool runOnMachineFunction(MachineFunction &MF) override {
1050 const M68kSubtarget &STI = MF.getSubtarget<M68kSubtarget>();
1052
1053 unsigned GlobalBaseReg = MxFI->getGlobalBaseReg();
1054
1055 // If we didn't need a GlobalBaseReg, don't insert code.
1056 if (GlobalBaseReg == 0)
1057 return false;
1058
1059 // Insert the set of GlobalBaseReg into the first MBB of the function
1060 MachineBasicBlock &FirstMBB = MF.front();
1062 DebugLoc DL = FirstMBB.findDebugLoc(MBBI);
1063 const M68kInstrInfo *TII = STI.getInstrInfo();
1064
1065 // Generate lea (__GLOBAL_OFFSET_TABLE_,%PC), %A5
1066 BuildMI(FirstMBB, MBBI, DL, TII->get(M68k::LEA32q), GlobalBaseReg)
1067 .addExternalSymbol("_GLOBAL_OFFSET_TABLE_", M68kII::MO_GOTPCREL);
1068
1069 return true;
1070 }
1071
1072 void getAnalysisUsage(AnalysisUsage &AU) const override {
1073 AU.setPreservesCFG();
1075 }
1076};
1077char M68kGlobalBaseReg::ID = 0;
1078} // namespace
1079
1080INITIALIZE_PASS(M68kGlobalBaseReg, DEBUG_TYPE, PASS_NAME, false, false)
1081
1083 return new M68kGlobalBaseReg();
1084}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
unsigned 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)
static bool Expand2AddrUndef(MachineInstrBuilder &MIB, const MCInstrDesc &Desc)
Expand a single-def pseudo instruction to a two-addr instruction with two undef reads of the register...
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 Reg
Register const TargetRegisterInfo * TRI
Promote Memory to Register
Definition Mem2Reg.cpp:110
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
Definition PassSupport.h:56
const SmallVectorImpl< MachineOperand > MachineBasicBlock * TBB
const SmallVectorImpl< MachineOperand > & Cond
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:484
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:278
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:314
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.