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