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 = MVTDst == MVT::i16 ? M68k::MOV16rr : M68k::MOV32rr;
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 // We need to find the super source register that matches the size of Dst
454 unsigned SSrc = RI.getMatchingMegaReg(Src, RCDst);
455 assert(SSrc && "No viable MEGA register available");
456
457 // If it happens to that super source register is the destination register
458 // we do nothing
459 if (Dst == SSrc) {
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(1).setReg(SSrc);
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 // We need to find the super source register that matches the size of Dst
492 unsigned SSrc = RI.getMatchingMegaReg(Src, RCDst);
493 assert(SSrc && "No viable MEGA register available");
494
496 DebugLoc DL = MIB->getDebugLoc();
497
498 // It's more efficient to clear the destination and *then* move, rather than
499 // move and zext.
500 if (Dst != SSrc && !IsSigned) {
501 LLVM_DEBUG(dbgs() << "Clear and Move" << '\n');
502
503 buildClearRegister(Dst, MBB, MIB.getInstr(), DL);
504
505 if (MVTSrc == MVT::i8) {
506 unsigned SubDst = RI.getSubReg(Dst, M68k::MxSubRegIndex8Lo);
507 BuildMI(MBB, MIB.getInstr(), DL, get(M68k::MOV8dd), SubDst).addReg(Src);
508 } else { // i16
509 unsigned SubDst = RI.getSubReg(Dst, M68k::MxSubRegIndex16Lo);
510 BuildMI(MBB, MIB.getInstr(), DL, get(M68k::MOV16dd), SubDst).addReg(Src);
511 }
512 } else {
513
514 unsigned Move;
515 if (MVTDst == MVT::i16)
516 Move = M68k::MOV16dd;
517 else // i32
518 Move = M68k::MOV32dd;
519
520 if (Dst != SSrc) {
521 LLVM_DEBUG(dbgs() << "Move and " << '\n');
522 BuildMI(MBB, MIB.getInstr(), DL, get(Move), Dst).addReg(SSrc);
523 }
524
525 if (IsSigned) {
526 LLVM_DEBUG(dbgs() << "Sign Extend" << '\n');
527 AddSExt(MBB, MIB.getInstr(), DL, Dst, MVTSrc, MVTDst);
528 } else {
529 LLVM_DEBUG(dbgs() << "Zero Extend" << '\n');
530 AddZExt(MBB, MIB.getInstr(), DL, Dst, MVTSrc, MVTDst);
531 }
532 }
533
534 MIB->eraseFromParent();
535
536 return true;
537}
538
540 const MCInstrDesc &Desc, MVT MVTDst,
541 MVT MVTSrc) const {
542 LLVM_DEBUG(dbgs() << "Expand " << *MIB.getInstr() << " to ");
543
544 Register Dst = MIB->getOperand(0).getReg();
545
546 // We need the subreg of Dst to make instruction verifier happy because the
547 // real machine instruction consumes and produces values of the same size and
548 // the registers the will be used here fall into different classes and this
549 // makes IV cry. We could use a bigger operation, but this will put some
550 // pressure on cache and memory, so no.
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
562 DebugLoc DL = MIB->getDebugLoc();
563
564 // We can only clear before loading if the destination register isn't being
565 // used as an index for the load.
566 if (!IsSigned && !MIB->readsRegister(Dst, &RI)) {
567 LLVM_DEBUG(dbgs() << "Clear and LOAD" << '\n');
568 buildClearRegister(Dst, MBB, I, DL);
569
570 // Extend after load
571 } else {
572 I++;
573 if (IsSigned) {
574 LLVM_DEBUG(dbgs() << "LOAD and Sign Extend" << '\n');
575 AddSExt(MBB, I, DL, Dst, MVTSrc, MVTDst);
576 } else {
577 LLVM_DEBUG(dbgs() << "Zero Extend" << '\n');
578 AddZExt(MBB, I, DL, Dst, MVTSrc, MVTDst);
579 }
580 }
581
582 return true;
583}
584
586 const MCInstrDesc &Desc, bool IsPush) const {
588 I++;
590 MachineOperand MO = MIB->getOperand(0);
591 DebugLoc DL = MIB->getDebugLoc();
592 if (IsPush)
593 BuildMI(MBB, I, DL, Desc).addReg(RI.getStackRegister()).add(MO);
594 else
595 BuildMI(MBB, I, DL, Desc, MO.getReg()).addReg(RI.getStackRegister());
596
597 MIB->eraseFromParent();
598 return true;
599}
600
602 const MCInstrDesc &Desc, bool IsRM) const {
603 int Reg = 0, Offset = 0, Base = 0;
604 auto DL = MIB->getDebugLoc();
605 auto MI = MIB.getInstr();
606 auto &MBB = *MIB->getParent();
607
608 if (IsRM) {
609 Reg = MIB->getOperand(0).getReg();
610 Offset = MIB->getOperand(1).getImm();
611 Base = MIB->getOperand(2).getReg();
612 } else {
613 Offset = MIB->getOperand(0).getImm();
614 Base = MIB->getOperand(1).getReg();
615 Reg = MIB->getOperand(2).getReg();
616 }
617
618 unsigned Mask = 1 << RI.getSpillRegisterOrder(Reg);
619 if (IsRM) {
620 BuildMI(MBB, MI, DL, Desc)
621 .addImm(Mask)
622 .addImm(Offset)
623 .addReg(Base)
625 .copyImplicitOps(*MIB);
626 } else {
627 BuildMI(MBB, MI, DL, Desc)
628 .addImm(Offset)
629 .addReg(Base)
630 .addImm(Mask)
632 .copyImplicitOps(*MIB);
633 }
634
635 MIB->eraseFromParent();
636
637 return true;
638}
639
642 DebugLoc &DL,
643 bool AllowSideEffects) const {
644 // Clear an address register by subtracting it from itself.
645 if (M68k::AR32RegClass.contains(Reg)) {
646 BuildMI(MBB, Iter, DL, get(M68k::SUB32ar), Reg)
648 .addReg(Reg, RegState::Undef);
649 return;
650 }
651
652 if (M68k::DR8RegClass.contains(Reg))
653 BuildMI(MBB, Iter, DL, get(M68k::CLR8d), Reg);
654 else if (M68k::DR16RegClass.contains(Reg))
655 BuildMI(MBB, Iter, DL, get(M68k::CLR16d), Reg);
656 else if (M68k::DR32RegClass.contains(Reg))
657 BuildMI(MBB, Iter, DL, get(M68k::MOVQ), Reg).addImm(0);
658 else
660 "buildClearRegister is not implemented for " + RI.getRegAsmName(Reg));
661}
662
663/// Expand a single-def pseudo instruction to a two-addr
664/// instruction with two undef reads of the register being defined.
665/// This is used for mapping:
666/// %d0 = SETCS_C32d
667/// to:
668/// %d0 = SUBX32dd %d0<undef>, %d0<undef>
669///
671 const MCInstrDesc &Desc) {
672 assert(Desc.getNumOperands() == 3 && "Expected two-addr instruction.");
673 Register Reg = MIB->getOperand(0).getReg();
674 MIB->setDesc(Desc);
675
676 // MachineInstr::addOperand() will insert explicit operands before any
677 // implicit operands.
679 // But we don't trust that.
680 assert(MIB->getOperand(1).getReg() == Reg &&
681 MIB->getOperand(2).getReg() == Reg && "Misplaced operand");
682 return true;
683}
684
686 MachineInstrBuilder MIB(*MI.getParent()->getParent(), MI);
687 switch (MI.getOpcode()) {
688 case M68k::PUSH8d:
689 return ExpandPUSH_POP(MIB, get(M68k::MOV8ed), true);
690 case M68k::PUSH16d:
691 return ExpandPUSH_POP(MIB, get(M68k::MOV16er), true);
692 case M68k::PUSH32r:
693 return ExpandPUSH_POP(MIB, get(M68k::MOV32er), true);
694
695 case M68k::POP8d:
696 return ExpandPUSH_POP(MIB, get(M68k::MOV8do), false);
697 case M68k::POP16d:
698 return ExpandPUSH_POP(MIB, get(M68k::MOV16ro), false);
699 case M68k::POP32r:
700 return ExpandPUSH_POP(MIB, get(M68k::MOV32ro), false);
701
702 case M68k::SETCS_C8d:
703 return Expand2AddrUndef(MIB, get(M68k::SUBX8dd));
704 case M68k::SETCS_C16d:
705 return Expand2AddrUndef(MIB, get(M68k::SUBX16dd));
706 case M68k::SETCS_C32d:
707 return Expand2AddrUndef(MIB, get(M68k::SUBX32dd));
708 }
709 return false;
710}
711
713 unsigned OpIdx) const {
714 assert(MI.getOperand(OpIdx).isReg());
715
716 // Check whether this operand belongs to an instruction with addressing mode
717 // 'k', Refer to TargetInstrInfo.h for more information about this function.
718
719 const unsigned NameIndices = M68kInstrNameIndices[MI.getOpcode()];
720 StringRef InstrName(&M68kInstrNameData[NameIndices]);
721
722 // If this machine operand is the 2nd operand, then check
723 // whether the instruction has destination addressing mode 'k'.
724 if (OpIdx == 1)
725 return Regex("[A-Z]+(8|16|32)k[a-z](_TC)?$").match(InstrName);
726
727 // If this machine operand is the last one, then check
728 // whether the instruction has source addressing mode 'k'.
729 if (OpIdx == MI.getNumExplicitOperands() - 1)
730 return Regex("[A-Z]+(8|16|32)[a-z]k(_TC)?$").match(InstrName);
731
732 return false;
733}
734
737 const DebugLoc &DL, Register DstReg,
738 Register SrcReg, bool KillSrc,
739 bool RenamableDest, bool RenamableSrc) const {
740 unsigned Opc = 0;
741 MachineFunction &MF = *MBB.getParent();
742 const M68kSubtarget &STI = MF.getSubtarget<M68kSubtarget>();
743
744 // Symmetric register copies
745 if (M68k::XR32RegClass.contains(DstReg, SrcReg)) {
746 Opc = M68k::MOV32rr;
747 } else if (M68k::XR16RegClass.contains(DstReg, SrcReg)) {
748 Opc = M68k::MOV16rr;
749 } else if (M68k::DR8RegClass.contains(DstReg, SrcReg)) {
750 Opc = M68k::MOV8dd;
751 }
752
753 // Asymmetric register copies
754 // NOTE: There is no implicit sext/zext occurring during these moves, so the
755 // upper bits will be undefined.
756 // 8 -> 16
757 else if (M68k::DR8RegClass.contains(SrcReg) &&
758 M68k::XR16RegClass.contains(DstReg)) {
759 Opc = M68k::MOVXd16d8;
760 // 8 -> 32
761 } else if (M68k::DR8RegClass.contains(SrcReg) &&
762 M68k::XR32RegClass.contains(DstReg)) {
763 Opc = M68k::MOVXd32d8;
764 // 16 -> 32
765 } else if (M68k::XR16RegClass.contains(SrcReg) &&
766 M68k::XR32RegClass.contains(DstReg)) {
767 Opc = M68k::MOVXd32d16;
768 }
769
770 // Copy from CCR
771 // NOTE: M68000 uses MOVE from SR to copy from CCR, all other variants use
772 // MOVE from CCR.
773 else if (SrcReg == M68k::CCR) {
774 if (M68k::DR8RegClass.contains(DstReg) ||
775 M68k::DR16RegClass.contains(DstReg) ||
776 M68k::DR32RegClass.contains(DstReg)) {
777 Opc = STI.isM68000() ? M68k::MOV16ds : M68k::MOV16dc;
778 } else {
779 LLVM_DEBUG(dbgs() << "Cannot copy CCR to " << RI.getName(DstReg) << '\n');
780 llvm_unreachable("Invalid register for MOVE from CCR");
781 }
782 }
783
784 // Copy to CCR
785 else if (DstReg == M68k::CCR) {
786 if (M68k::DR8RegClass.contains(SrcReg) ||
787 M68k::DR16RegClass.contains(SrcReg) ||
788 M68k::DR32RegClass.contains(SrcReg)) {
789 Opc = M68k::MOV16cd;
790 } else {
791 LLVM_DEBUG(dbgs() << "Cannot copy " << RI.getName(SrcReg) << " to CCR\n");
792 llvm_unreachable("Invalid register for MOVE to CCR");
793 }
794 }
795
796 // SR should never be a valid register for copying
797 else if (SrcReg == M68k::SR || DstReg == M68k::SR)
798 llvm_unreachable("Cannot explicitly copy to/from SR");
799
800 // We should now have our opcode
801 if (!Opc) {
802 LLVM_DEBUG(dbgs() << "Cannot copy " << RI.getName(SrcReg) << " to "
803 << RI.getName(DstReg) << '\n');
804 llvm_unreachable("Cannot emit physreg copy instruction");
805 }
806
807 // FIXME
808 // Below is a workaround to prevent a live CCR from being killed by the COPY
809 // instruction. LLVM sometimes inserts a COPY pseudo instruction between
810 // compare and branch during MIR generation (e.g. during PHI node elimination)
811 // without any idea that on M68k, this is extremely likely to implicitly kill
812 // the CCR.
813 // The workaround checks whether CCR is live during this copy, and if so,
814 // backs up CCR and restores it after the copy. It's inefficient and prevents
815 // M68000-targeted builds from running on 010+ (because 000 uses MOVE from SR
816 // and 010+ uses MOVE from CCR).
817 // The fix condition is to prevent COPY from ever being inserted while CCR is
818 // live (which would also stop this workaround from ever triggering).
819
820 unsigned CCRSrcReg = STI.isM68000() ? M68k::SR : M68k::CCR;
821
822 // Get the live registers right before the COPY instruction. If CCR is
823 // live, the MOVE is going to kill it, so we will need to preserve it.
824 LiveRegUnits UsedRegs(RI);
825 UsedRegs.addLiveOuts(MBB);
826 auto InstUpToI = MBB.end();
827 while (InstUpToI != MI) {
828 UsedRegs.stepBackward(*--InstUpToI);
829 }
830
831 if (SrcReg == M68k::CCR) {
832 BuildMI(MBB, MI, DL, get(Opc), DstReg).addReg(CCRSrcReg);
833 return;
834 }
835 if (DstReg == M68k::CCR) {
836 BuildMI(MBB, MI, DL, get(Opc), M68k::CCR)
837 .addReg(SrcReg, getKillRegState(KillSrc));
838 return;
839 }
840 if (UsedRegs.available(M68k::CCR)) {
841 BuildMI(MBB, MI, DL, get(Opc), DstReg)
842 .addReg(SrcReg, getKillRegState(KillSrc));
843 return;
844 }
845
846 // CCR is live, so we must restore it after the copy. Prepare push/pop ops.
847 // 68000 must use MOVE from SR, 68010+ must use MOVE from CCR. In either
848 // case, upon moving back, MOVE to CCR will mask out the upper byte anyway.
849
850 // Look for an available data register for the CCR, or push to stack if
851 // there are none
852 BitVector Allocatable =
853 RI.getAllocatableSet(MF, RI.getRegClass(M68k::DR16RegClassID));
854 for (Register Reg : Allocatable.set_bits()) {
855 if (!RI.regsOverlap(DstReg, Reg) && (UsedRegs.available(Reg))) {
856 unsigned CCRPushOp = STI.isM68000() ? M68k::MOV16ds : M68k::MOV16dc;
857 unsigned CCRPopOp = M68k::MOV16cd;
858 BuildMI(MBB, MI, DL, get(CCRPushOp), Reg).addReg(CCRSrcReg);
859 BuildMI(MBB, MI, DL, get(Opc), DstReg)
860 .addReg(SrcReg, getKillRegState(KillSrc));
861 BuildMI(MBB, MI, DL, get(CCRPopOp), M68k::CCR).addReg(Reg);
862 return;
863 }
864 }
865
866 unsigned CCRPushOp = STI.isM68000() ? M68k::MOV16es : M68k::MOV16ec;
867 unsigned CCRPopOp = M68k::MOV16co;
868
869 BuildMI(MBB, MI, DL, get(CCRPushOp))
870 .addReg(RI.getStackRegister())
871 .addReg(CCRSrcReg);
872 BuildMI(MBB, MI, DL, get(Opc), DstReg)
873 .addReg(SrcReg, getKillRegState(KillSrc));
874 BuildMI(MBB, MI, DL, get(CCRPopOp), M68k::CCR).addReg(RI.getStackRegister());
875 return;
876}
877
878namespace {
879unsigned getLoadStoreRegOpcode(unsigned Reg, const TargetRegisterClass *RC,
880 const TargetRegisterInfo *TRI,
881 const M68kSubtarget &STI, bool load) {
882 switch (TRI->getSpillSize(*RC)) {
883 default:
885 dbgs() << "Cannot determine appropriate opcode for load/store to/from "
886 << TRI->getName(Reg) << " of class " << TRI->getRegClassName(RC)
887 << " with spill size " << TRI->getSpillSize(*RC) << '\n');
888 llvm_unreachable("Unknown spill size");
889 case 2:
890 if (M68k::XR16RegClass.hasSubClassEq(RC))
891 return load ? M68k::MOVM16mp_P : M68k::MOVM16pm_P;
892 if (M68k::DR8RegClass.hasSubClassEq(RC))
893 return load ? M68k::MOVM8mp_P : M68k::MOVM8pm_P;
894 if (M68k::CCRCRegClass.hasSubClassEq(RC))
895 return load ? M68k::MOVM16mp_P : M68k::MOVM16pm_P;
896 llvm_unreachable("Unknown 2-byte regclass");
897 case 4:
898 if (M68k::XR32RegClass.hasSubClassEq(RC))
899 return load ? M68k::MOVM32mp_P : M68k::MOVM32pm_P;
900 llvm_unreachable("Unknown 4-byte regclass");
901 }
902}
903
904unsigned getStoreRegOpcode(unsigned SrcReg, const TargetRegisterClass *RC,
905 const TargetRegisterInfo *TRI,
906 const M68kSubtarget &STI) {
907 return getLoadStoreRegOpcode(SrcReg, RC, TRI, STI, false);
908}
909
910unsigned getLoadRegOpcode(unsigned DstReg, const TargetRegisterClass *RC,
911 const TargetRegisterInfo *TRI,
912 const M68kSubtarget &STI) {
913 return getLoadStoreRegOpcode(DstReg, RC, TRI, STI, true);
914}
915} // end anonymous namespace
916
918 unsigned SubIdx, unsigned &Size,
919 unsigned &Offset,
920 const MachineFunction &MF) const {
921 // The slot size must be the maximum size so we can easily use MOVEM.L
922 Size = 4;
923 Offset = 0;
924 return true;
925}
926
929 bool IsKill, int FrameIndex, const TargetRegisterClass *RC, Register VReg,
930 MachineInstr::MIFlag Flags) const {
931 const MachineFrameInfo &MFI = MBB.getParent()->getFrameInfo();
932 assert(MFI.getObjectSize(FrameIndex) >= TRI.getSpillSize(*RC) &&
933 "Stack slot is too small to store");
934 (void)MFI;
935
936 unsigned Opc = getStoreRegOpcode(SrcReg, RC, &TRI, Subtarget);
937 DebugLoc DL = MBB.findDebugLoc(MI);
938 // (0,FrameIndex) <- $reg
939 M68k::addFrameReference(BuildMI(MBB, MI, DL, get(Opc)), FrameIndex)
940 .addReg(SrcReg, getKillRegState(IsKill));
941}
942
945 Register DstReg, int FrameIndex,
946 const TargetRegisterClass *RC,
947 Register VReg, unsigned SubReg,
948 MachineInstr::MIFlag Flags) const {
949 const MachineFrameInfo &MFI = MBB.getParent()->getFrameInfo();
950 assert(MFI.getObjectSize(FrameIndex) >= TRI.getSpillSize(*RC) &&
951 "Stack slot is too small to load");
952 (void)MFI;
953
954 unsigned Opc = getLoadRegOpcode(DstReg, RC, &TRI, Subtarget);
955 DebugLoc DL = MBB.findDebugLoc(MI);
956 M68k::addFrameReference(BuildMI(MBB, MI, DL, get(Opc), DstReg), FrameIndex);
957}
958
959/// Return a virtual register initialized with the global base register
960/// value. Output instructions required to initialize the register in the
961/// function entry block, if necessary.
962///
963/// TODO Move this function to M68kMachineFunctionInfo.
966 unsigned GlobalBaseReg = MxFI->getGlobalBaseReg();
967 if (GlobalBaseReg != 0)
968 return GlobalBaseReg;
969
970 // Create the register. The code to initialize it is inserted later,
971 // by the M68kGlobalBaseReg pass (below).
972 //
973 // NOTE
974 // Normally M68k uses A5 register as global base pointer but this will
975 // create unnecessary spill if we use less then 4 registers in code; since A5
976 // is callee-save anyway we could try to allocate caller-save first and if
977 // lucky get one, otherwise it does not really matter which callee-save to
978 // use.
979 MachineRegisterInfo &RegInfo = MF->getRegInfo();
980 GlobalBaseReg = RegInfo.createVirtualRegister(&M68k::AR32_NOSPRegClass);
981 MxFI->setGlobalBaseReg(GlobalBaseReg);
982 return GlobalBaseReg;
983}
984
985std::pair<unsigned, unsigned>
987 return std::make_pair(TF, 0u);
988}
989
992 using namespace M68kII;
993 static const std::pair<unsigned, const char *> TargetFlags[] = {
994 {MO_ABSOLUTE_ADDRESS, "m68k-absolute"},
995 {MO_PC_RELATIVE_ADDRESS, "m68k-pcrel"},
996 {MO_GOT, "m68k-got"},
997 {MO_GOTOFF, "m68k-gotoff"},
998 {MO_GOTPCREL, "m68k-gotpcrel"},
999 {MO_PLT, "m68k-plt"},
1000 {MO_TLSGD, "m68k-tlsgd"},
1001 {MO_TLSLD, "m68k-tlsld"},
1002 {MO_TLSLDM, "m68k-tlsldm"},
1003 {MO_TLSIE, "m68k-tlsie"},
1004 {MO_TLSLE, "m68k-tlsle"}};
1005 return ArrayRef(TargetFlags);
1006}
1007
1008#undef DEBUG_TYPE
1009#define DEBUG_TYPE "m68k-create-global-base-reg"
1010
1011#define PASS_NAME "M68k PIC Global Base Reg Initialization"
1012
1013namespace {
1014/// This initializes the PIC global base register
1015struct M68kGlobalBaseReg : public MachineFunctionPass {
1016 static char ID;
1017 M68kGlobalBaseReg() : MachineFunctionPass(ID) {}
1018
1019 bool runOnMachineFunction(MachineFunction &MF) override {
1020 const M68kSubtarget &STI = MF.getSubtarget<M68kSubtarget>();
1022
1023 unsigned GlobalBaseReg = MxFI->getGlobalBaseReg();
1024
1025 // If we didn't need a GlobalBaseReg, don't insert code.
1026 if (GlobalBaseReg == 0)
1027 return false;
1028
1029 // Insert the set of GlobalBaseReg into the first MBB of the function
1030 MachineBasicBlock &FirstMBB = MF.front();
1032 DebugLoc DL = FirstMBB.findDebugLoc(MBBI);
1033 const M68kInstrInfo *TII = STI.getInstrInfo();
1034
1035 // Generate lea (__GLOBAL_OFFSET_TABLE_,%PC), %A5
1036 BuildMI(FirstMBB, MBBI, DL, TII->get(M68k::LEA32q), GlobalBaseReg)
1037 .addExternalSymbol("_GLOBAL_OFFSET_TABLE_", M68kII::MO_GOTPCREL);
1038
1039 return true;
1040 }
1041
1042 void getAnalysisUsage(AnalysisUsage &AU) const override {
1043 AU.setPreservesCFG();
1045 }
1046};
1047char M68kGlobalBaseReg::ID = 0;
1048} // namespace
1049
1050INITIALIZE_PASS(M68kGlobalBaseReg, DEBUG_TYPE, PASS_NAME, false, false)
1051
1053 return new M68kGlobalBaseReg();
1054}
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 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.
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: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: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.