LLVM 24.0.0git
SystemZInstrInfo.cpp
Go to the documentation of this file.
1//===-- SystemZInstrInfo.cpp - SystemZ instruction information ------------===//
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// This file contains the SystemZ implementation of the TargetInstrInfo class.
10//
11//===----------------------------------------------------------------------===//
12
13#include "SystemZInstrInfo.h"
15#include "SystemZ.h"
16#include "SystemZInstrBuilder.h"
17#include "SystemZSubtarget.h"
18#include "llvm/ADT/Statistic.h"
35#include "llvm/IR/Module.h"
37#include "llvm/MC/MCInstrDesc.h"
43#include <cassert>
44#include <cstdint>
45#include <iterator>
46
47using namespace llvm;
48
49#define GET_INSTRINFO_CTOR_DTOR
50#define GET_INSTRMAP_INFO
51#include "SystemZGenInstrInfo.inc"
52
53#define DEBUG_TYPE "systemz-II"
54
55// Return a mask with Count low bits set.
56static uint64_t allOnes(unsigned int Count) {
57 return Count == 0 ? 0 : (uint64_t(1) << (Count - 1) << 1) - 1;
58}
59
60// Pin the vtable to this file.
61void SystemZInstrInfo::anchor() {}
62
64 : SystemZGenInstrInfo(sti, RI, -1, -1),
65 RI(sti.getSpecialRegisters()->getReturnFunctionAddressRegister(),
66 sti.getHwMode()),
67 STI(sti) {}
68
69// MI is a 128-bit load or store. Split it into two 64-bit loads or stores,
70// each having the opcode given by NewOpcode.
71void SystemZInstrInfo::splitMove(MachineBasicBlock::iterator MI,
72 unsigned NewOpcode) const {
73 MachineBasicBlock *MBB = MI->getParent();
74 MachineFunction &MF = *MBB->getParent();
75
76 // Get two load or store instructions. Use the original instruction for
77 // one of them and create a clone for the other.
78 MachineInstr *HighPartMI = MF.CloneMachineInstr(&*MI);
79 MachineInstr *LowPartMI = &*MI;
80 MBB->insert(LowPartMI, HighPartMI);
81
82 // Set up the two 64-bit registers and remember super reg and its flags.
83 MachineOperand &HighRegOp = HighPartMI->getOperand(0);
84 MachineOperand &LowRegOp = LowPartMI->getOperand(0);
85 Register Reg128 = LowRegOp.getReg();
86 RegState Reg128Killed = getKillRegState(LowRegOp.isKill());
87 RegState Reg128Undef = getUndefRegState(LowRegOp.isUndef());
88 HighRegOp.setReg(RI.getSubReg(HighRegOp.getReg(), SystemZ::subreg_h64));
89 LowRegOp.setReg(RI.getSubReg(LowRegOp.getReg(), SystemZ::subreg_l64));
90
91 // The address in the first (high) instruction is already correct.
92 // Adjust the offset in the second (low) instruction.
93 MachineOperand &HighOffsetOp = HighPartMI->getOperand(2);
94 MachineOperand &LowOffsetOp = LowPartMI->getOperand(2);
95 LowOffsetOp.setImm(LowOffsetOp.getImm() + 8);
96
97 // Set the opcodes.
98 unsigned HighOpcode = getOpcodeForOffset(NewOpcode, HighOffsetOp.getImm());
99 unsigned LowOpcode = getOpcodeForOffset(NewOpcode, LowOffsetOp.getImm());
100 assert(HighOpcode && LowOpcode && "Both offsets should be in range");
101 HighPartMI->setDesc(get(HighOpcode));
102 LowPartMI->setDesc(get(LowOpcode));
103
104 MachineInstr *FirstMI = HighPartMI;
105 if (MI->mayStore()) {
106 FirstMI->getOperand(0).setIsKill(false);
107 // Add implicit uses of the super register in case one of the subregs is
108 // undefined. We could track liveness and skip storing an undefined
109 // subreg, but this is hopefully rare (discovered with llvm-stress).
110 // If Reg128 was killed, set kill flag on MI.
111 RegState Reg128UndefImpl = (Reg128Undef | RegState::Implicit);
112 MachineInstrBuilder(MF, HighPartMI).addReg(Reg128, Reg128UndefImpl);
113 MachineInstrBuilder(MF, LowPartMI).addReg(Reg128, (Reg128UndefImpl | Reg128Killed));
114 } else {
115 // If HighPartMI clobbers any of the address registers, it needs to come
116 // after LowPartMI.
117 auto overlapsAddressReg = [&](Register Reg) -> bool {
118 return RI.regsOverlap(Reg, MI->getOperand(1).getReg()) ||
119 RI.regsOverlap(Reg, MI->getOperand(3).getReg());
120 };
121 if (overlapsAddressReg(HighRegOp.getReg())) {
122 assert(!overlapsAddressReg(LowRegOp.getReg()) &&
123 "Both loads clobber address!");
124 MBB->splice(HighPartMI, MBB, LowPartMI);
125 FirstMI = LowPartMI;
126 }
127 }
128
129 // Clear the kill flags on the address registers in the first instruction.
130 FirstMI->getOperand(1).setIsKill(false);
131 FirstMI->getOperand(3).setIsKill(false);
132}
133
134// Split ADJDYNALLOC instruction MI.
135void SystemZInstrInfo::splitAdjDynAlloc(MachineBasicBlock::iterator MI) const {
136 MachineBasicBlock *MBB = MI->getParent();
137 MachineFunction &MF = *MBB->getParent();
138 MachineFrameInfo &MFFrame = MF.getFrameInfo();
139 MachineOperand &OffsetMO = MI->getOperand(2);
140 SystemZCallingConventionRegisters *Regs = STI.getSpecialRegisters();
141
142 uint64_t Offset = (MFFrame.getMaxCallFrameSize() +
143 Regs->getCallFrameSize() +
144 Regs->getStackPointerBias() +
145 OffsetMO.getImm());
146 unsigned NewOpcode = getOpcodeForOffset(SystemZ::LA, Offset);
147 assert(NewOpcode && "No support for huge argument lists yet");
148 MI->setDesc(get(NewOpcode));
149 OffsetMO.setImm(Offset);
150}
151
152// MI is an RI-style pseudo instruction. Replace it with LowOpcode
153// if the first operand is a low GR32 and HighOpcode if the first operand
154// is a high GR32. ConvertHigh is true if LowOpcode takes a signed operand
155// and HighOpcode takes an unsigned 32-bit operand. In those cases,
156// MI has the same kind of operand as LowOpcode, so needs to be converted
157// if HighOpcode is used.
158void SystemZInstrInfo::expandRIPseudo(MachineInstr &MI, unsigned LowOpcode,
159 unsigned HighOpcode,
160 bool ConvertHigh) const {
161 Register Reg = MI.getOperand(0).getReg();
162 bool IsHigh = SystemZ::isHighReg(Reg);
163 MI.setDesc(get(IsHigh ? HighOpcode : LowOpcode));
164 if (IsHigh && ConvertHigh)
165 MI.getOperand(1).setImm(uint32_t(MI.getOperand(1).getImm()));
166}
167
168// MI is a three-operand RIE-style pseudo instruction. Replace it with
169// LowOpcodeK if the registers are both low GR32s, otherwise use a move
170// followed by HighOpcode or LowOpcode, depending on whether the target
171// is a high or low GR32.
172void SystemZInstrInfo::expandRIEPseudo(MachineInstr &MI, unsigned LowOpcode,
173 unsigned LowOpcodeK,
174 unsigned HighOpcode) const {
175 Register DestReg = MI.getOperand(0).getReg();
176 Register SrcReg = MI.getOperand(1).getReg();
177 bool DestIsHigh = SystemZ::isHighReg(DestReg);
178 bool SrcIsHigh = SystemZ::isHighReg(SrcReg);
179 if (!DestIsHigh && !SrcIsHigh)
180 MI.setDesc(get(LowOpcodeK));
181 else {
182 if (DestReg != SrcReg) {
183 emitGRX32Move(*MI.getParent(), MI, MI.getDebugLoc(), DestReg, SrcReg,
184 SystemZ::LR, 32, MI.getOperand(1).isKill(),
185 MI.getOperand(1).isUndef());
186 MI.getOperand(1).setReg(DestReg);
187 }
188 MI.setDesc(get(DestIsHigh ? HighOpcode : LowOpcode));
189 MI.tieOperands(0, 1);
190 }
191}
192
193// MI is an RXY-style pseudo instruction. Replace it with LowOpcode
194// if the first operand is a low GR32 and HighOpcode if the first operand
195// is a high GR32.
196void SystemZInstrInfo::expandRXYPseudo(MachineInstr &MI, unsigned LowOpcode,
197 unsigned HighOpcode) const {
198 Register Reg = MI.getOperand(0).getReg();
199 unsigned Opcode = getOpcodeForOffset(
200 SystemZ::isHighReg(Reg) ? HighOpcode : LowOpcode,
201 MI.getOperand(2).getImm());
202 MI.setDesc(get(Opcode));
203}
204
205// MI is a load-on-condition pseudo instruction with a single register
206// (source or destination) operand. Replace it with LowOpcode if the
207// register is a low GR32 and HighOpcode if the register is a high GR32.
208void SystemZInstrInfo::expandLOCPseudo(MachineInstr &MI, unsigned LowOpcode,
209 unsigned HighOpcode) const {
210 Register Reg = MI.getOperand(0).getReg();
211 unsigned Opcode = SystemZ::isHighReg(Reg) ? HighOpcode : LowOpcode;
212 MI.setDesc(get(Opcode));
213}
214
215// MI is an RR-style pseudo instruction that zero-extends the low Size bits
216// of one GRX32 into another. Replace it with LowOpcode if both operands
217// are low registers, otherwise use RISB[LH]G.
218void SystemZInstrInfo::expandZExtPseudo(MachineInstr &MI, unsigned LowOpcode,
219 unsigned Size) const {
220 MachineInstrBuilder MIB =
221 emitGRX32Move(*MI.getParent(), MI, MI.getDebugLoc(),
222 MI.getOperand(0).getReg(), MI.getOperand(1).getReg(), LowOpcode,
223 Size, MI.getOperand(1).isKill(), MI.getOperand(1).isUndef());
224
225 // Keep the remaining operands as-is.
226 for (const MachineOperand &MO : llvm::drop_begin(MI.operands(), 2))
227 MIB.add(MO);
228
229 MI.eraseFromParent();
230}
231
232// Emit a zero-extending move from 32-bit GPR SrcReg to 32-bit GPR
233// DestReg before MBBI in MBB. Use LowLowOpcode when both DestReg and SrcReg
234// are low registers, otherwise use RISB[LH]G. Size is the number of bits
235// taken from the low end of SrcReg (8 for LLCR, 16 for LLHR and 32 for LR).
236// KillSrc is true if this move is the last use of SrcReg.
238SystemZInstrInfo::emitGRX32Move(MachineBasicBlock &MBB,
240 const DebugLoc &DL, unsigned DestReg,
241 unsigned SrcReg, unsigned LowLowOpcode,
242 unsigned Size, bool KillSrc,
243 bool UndefSrc) const {
244 unsigned Opcode;
245 bool DestIsHigh = SystemZ::isHighReg(DestReg);
246 bool SrcIsHigh = SystemZ::isHighReg(SrcReg);
247 if (DestIsHigh && SrcIsHigh)
248 Opcode = SystemZ::RISBHH;
249 else if (DestIsHigh && !SrcIsHigh)
250 Opcode = SystemZ::RISBHL;
251 else if (!DestIsHigh && SrcIsHigh)
252 Opcode = SystemZ::RISBLH;
253 else {
254 return BuildMI(MBB, MBBI, DL, get(LowLowOpcode), DestReg)
255 .addReg(SrcReg, getKillRegState(KillSrc) | getUndefRegState(UndefSrc));
256 }
257 unsigned Rotate = (DestIsHigh != SrcIsHigh ? 32 : 0);
258 return BuildMI(MBB, MBBI, DL, get(Opcode), DestReg)
259 .addReg(DestReg, RegState::Undef)
260 .addReg(SrcReg, getKillRegState(KillSrc) | getUndefRegState(UndefSrc))
261 .addImm(32 - Size).addImm(128 + 31).addImm(Rotate);
262}
263
265 bool NewMI,
266 unsigned OpIdx1,
267 unsigned OpIdx2) const {
268 auto cloneIfNew = [NewMI](MachineInstr &MI) -> MachineInstr & {
269 if (NewMI)
270 return *MI.getParent()->getParent()->CloneMachineInstr(&MI);
271 return MI;
272 };
273
274 switch (MI.getOpcode()) {
275 case SystemZ::SELRMux:
276 case SystemZ::SELFHR:
277 case SystemZ::SELR:
278 case SystemZ::SELGR:
279 case SystemZ::LOCRMux:
280 case SystemZ::LOCFHR:
281 case SystemZ::LOCR:
282 case SystemZ::LOCGR: {
283 auto &WorkingMI = cloneIfNew(MI);
284 // Invert condition.
285 unsigned CCValid = WorkingMI.getOperand(3).getImm();
286 unsigned CCMask = WorkingMI.getOperand(4).getImm();
287 WorkingMI.getOperand(4).setImm(CCMask ^ CCValid);
288 return TargetInstrInfo::commuteInstructionImpl(WorkingMI, /*NewMI=*/false,
289 OpIdx1, OpIdx2);
290 }
291 default:
292 return TargetInstrInfo::commuteInstructionImpl(MI, NewMI, OpIdx1, OpIdx2);
293 }
294}
295
296// If MI is a simple load or store for a frame object, return the register
297// it loads or stores and set FrameIndex to the index of the frame object.
298// Return 0 otherwise.
299//
300// Flag is SimpleBDXLoad for loads and SimpleBDXStore for stores.
301static int isSimpleMove(const MachineInstr &MI, int &FrameIndex,
302 unsigned Flag) {
303 const MCInstrDesc &MCID = MI.getDesc();
304 if ((MCID.TSFlags & Flag) && MI.getOperand(1).isFI() &&
305 MI.getOperand(2).getImm() == 0 && MI.getOperand(3).getReg() == 0) {
306 FrameIndex = MI.getOperand(1).getIndex();
307 return MI.getOperand(0).getReg();
308 }
309 return 0;
310}
311
313 int &FrameIndex) const {
314 return isSimpleMove(MI, FrameIndex, SystemZII::SimpleBDXLoad);
315}
316
318 int &FrameIndex) const {
319 return isSimpleMove(MI, FrameIndex, SystemZII::SimpleBDXStore);
320}
321
323 int &FrameIndex) const {
324 // if this is not a simple load from memory, it's not a load from stack slot
325 // either.
326 const MCInstrDesc &MCID = MI.getDesc();
327 if (!(MCID.TSFlags & SystemZII::SimpleBDXLoad))
328 return 0;
329
330 // This version of isLoadFromStackSlot should only be used post frame-index
331 // elimination.
332 assert(!MI.getOperand(1).isFI());
333
334 // Now attempt to derive frame index from MachineMemOperands.
336 if (hasLoadFromStackSlot(MI, Accesses)) {
337 FrameIndex =
338 cast<FixedStackPseudoSourceValue>(Accesses.front()->getPseudoValue())
339 ->getFrameIndex();
340 return MI.getOperand(0).getReg();
341 }
342 return 0;
343}
344
346 int &FrameIndex) const {
347 // if this is not a simple store to memory, it's not a store to stack slot
348 // either.
349 const MCInstrDesc &MCID = MI.getDesc();
350 if (!(MCID.TSFlags & SystemZII::SimpleBDXStore))
351 return 0;
352
353 // This version of isStoreToStackSlot should only be used post frame-index
354 // elimination.
355 assert(!MI.getOperand(1).isFI());
356
357 // Now attempt to derive frame index from MachineMemOperands.
359 if (hasStoreToStackSlot(MI, Accesses)) {
360 FrameIndex =
361 cast<FixedStackPseudoSourceValue>(Accesses.front()->getPseudoValue())
362 ->getFrameIndex();
363 return MI.getOperand(0).getReg();
364 }
365 return 0;
366}
367
369 int &DestFrameIndex,
370 int &SrcFrameIndex) const {
371 // Check for MVC 0(Length,FI1),0(FI2)
372 const MachineFrameInfo &MFI = MI.getParent()->getParent()->getFrameInfo();
373 if (MI.getOpcode() != SystemZ::MVC || !MI.getOperand(0).isFI() ||
374 MI.getOperand(1).getImm() != 0 || !MI.getOperand(3).isFI() ||
375 MI.getOperand(4).getImm() != 0)
376 return false;
377
378 // Check that Length covers the full slots.
379 int64_t Length = MI.getOperand(2).getImm();
380 unsigned FI1 = MI.getOperand(0).getIndex();
381 unsigned FI2 = MI.getOperand(3).getIndex();
382 if (MFI.getObjectSize(FI1) != Length ||
383 MFI.getObjectSize(FI2) != Length)
384 return false;
385
386 DestFrameIndex = FI1;
387 SrcFrameIndex = FI2;
388 return true;
389}
390
393 MachineBasicBlock *&FBB,
395 bool AllowModify) const {
396 // Most of the code and comments here are boilerplate.
397
398 // Start from the bottom of the block and work up, examining the
399 // terminator instructions.
401 while (I != MBB.begin()) {
402 --I;
403 if (I->isDebugInstr())
404 continue;
405
406 // Working from the bottom, when we see a non-terminator instruction, we're
407 // done.
408 if (!isUnpredicatedTerminator(*I))
409 break;
410
411 // A terminator that isn't a branch can't easily be handled by this
412 // analysis.
413 if (!I->isBranch())
414 return true;
415
416 // Can't handle indirect branches.
418 if (!Branch.hasMBBTarget())
419 return true;
420
421 // Punt on compound branches.
422 if (Branch.Type != SystemZII::BranchNormal)
423 return true;
424
425 if (Branch.CCMask == SystemZ::CCMASK_ANY) {
426 // Handle unconditional branches.
427 if (!AllowModify) {
428 TBB = Branch.getMBBTarget();
429 continue;
430 }
431
432 // If the block has any instructions after a JMP, delete them.
433 MBB.erase(std::next(I), MBB.end());
434
435 Cond.clear();
436 FBB = nullptr;
437
438 // Delete the JMP if it's equivalent to a fall-through.
439 if (MBB.isLayoutSuccessor(Branch.getMBBTarget())) {
440 TBB = nullptr;
441 I->eraseFromParent();
442 I = MBB.end();
443 continue;
444 }
445
446 // TBB is used to indicate the unconditinal destination.
447 TBB = Branch.getMBBTarget();
448 continue;
449 }
450
451 // Working from the bottom, handle the first conditional branch.
452 if (Cond.empty()) {
453 // FIXME: add X86-style branch swap
454 FBB = TBB;
455 TBB = Branch.getMBBTarget();
456 Cond.push_back(MachineOperand::CreateImm(Branch.CCValid));
457 Cond.push_back(MachineOperand::CreateImm(Branch.CCMask));
458 continue;
459 }
460
461 // Handle subsequent conditional branches.
462 assert(Cond.size() == 2 && TBB && "Should have seen a conditional branch");
463
464 // Only handle the case where all conditional branches branch to the same
465 // destination.
466 if (TBB != Branch.getMBBTarget())
467 return true;
468
469 // If the conditions are the same, we can leave them alone.
470 unsigned OldCCValid = Cond[0].getImm();
471 unsigned OldCCMask = Cond[1].getImm();
472 if (OldCCValid == Branch.CCValid && OldCCMask == Branch.CCMask)
473 continue;
474
475 // FIXME: Try combining conditions like X86 does. Should be easy on Z!
476 return false;
477 }
478
479 return false;
480}
481
483 int *BytesRemoved) const {
484 assert(!BytesRemoved && "code size not handled");
485
486 // Most of the code and comments here are boilerplate.
488 unsigned Count = 0;
489
490 while (I != MBB.begin()) {
491 --I;
492 if (I->isDebugInstr())
493 continue;
494 if (!I->isBranch())
495 break;
496 if (!getBranchInfo(*I).hasMBBTarget())
497 break;
498 // Remove the branch.
499 I->eraseFromParent();
500 I = MBB.end();
501 ++Count;
502 }
503
504 return Count;
505}
506
509 assert(Cond.size() == 2 && "Invalid condition");
510 Cond[1].setImm(Cond[1].getImm() ^ Cond[0].getImm());
511 return false;
512}
513
518 const DebugLoc &DL,
519 int *BytesAdded) const {
520 // In this function we output 32-bit branches, which should always
521 // have enough range. They can be shortened and relaxed by later code
522 // in the pipeline, if desired.
523
524 // Shouldn't be a fall through.
525 assert(TBB && "insertBranch must not be told to insert a fallthrough");
526 assert((Cond.size() == 2 || Cond.size() == 0) &&
527 "SystemZ branch conditions have one component!");
528 assert(!BytesAdded && "code size not handled");
529
530 if (Cond.empty()) {
531 // Unconditional branch?
532 assert(!FBB && "Unconditional branch with multiple successors!");
533 BuildMI(&MBB, DL, get(SystemZ::J)).addMBB(TBB);
534 return 1;
535 }
536
537 // Conditional branch.
538 unsigned Count = 0;
539 unsigned CCValid = Cond[0].getImm();
540 unsigned CCMask = Cond[1].getImm();
541 BuildMI(&MBB, DL, get(SystemZ::BRC))
542 .addImm(CCValid).addImm(CCMask).addMBB(TBB);
543 ++Count;
544
545 if (FBB) {
546 // Two-way Conditional branch. Insert the second branch.
547 BuildMI(&MBB, DL, get(SystemZ::J)).addMBB(FBB);
548 ++Count;
549 }
550 return Count;
551}
552
554 Register &SrcReg2, int64_t &Mask,
555 int64_t &Value) const {
556 assert(MI.isCompare() && "Caller should have checked for a comparison");
557
558 if (MI.getNumExplicitOperands() == 2 && MI.getOperand(0).isReg() &&
559 MI.getOperand(1).isImm()) {
560 SrcReg = MI.getOperand(0).getReg();
561 SrcReg2 = 0;
562 Value = MI.getOperand(1).getImm();
563 Mask = ~0;
564 return true;
565 }
566
567 return false;
568}
569
572 Register DstReg, Register TrueReg,
573 Register FalseReg,
574 SelectExpansion &Exp) const {
575 // Not all subtargets have LOCR instructions.
576 if (!STI.hasLoadStoreOnCond())
577 return false;
578 if (Pred.size() != 2)
579 return false;
580
581 // Check register classes.
582 const MachineRegisterInfo &MRI = MBB.getParent()->getRegInfo();
583 const TargetRegisterClass *RC =
584 RI.getCommonSubClass(MRI.getRegClass(TrueReg), MRI.getRegClass(FalseReg));
585 if (!RC)
586 return false;
587
588 // We have LOCR instructions for 32 and 64 bit general purpose registers.
589 if ((STI.hasLoadStoreOnCond2() &&
590 SystemZ::GRX32BitRegClass.hasSubClassEq(RC)) ||
591 SystemZ::GR32BitRegClass.hasSubClassEq(RC) ||
592 SystemZ::GR64BitRegClass.hasSubClassEq(RC)) {
593 Exp.CondCycles = 2;
594 Exp.TrueCycles = 2;
595 Exp.FalseCycles = 2;
596 return true;
597 }
598
599 // Can't do anything else.
600 return false;
601}
602
605 const DebugLoc &DL, Register DstReg,
607 Register TrueReg,
608 Register FalseReg) const {
609 MachineRegisterInfo &MRI = MBB.getParent()->getRegInfo();
610 const TargetRegisterClass *RC = MRI.getRegClass(DstReg);
611
612 assert(Pred.size() == 2 && "Invalid condition");
613 unsigned CCValid = Pred[0].getImm();
614 unsigned CCMask = Pred[1].getImm();
615
616 unsigned Opc;
617 if (SystemZ::GRX32BitRegClass.hasSubClassEq(RC)) {
618 if (STI.hasMiscellaneousExtensions3())
619 Opc = SystemZ::SELRMux;
620 else if (STI.hasLoadStoreOnCond2())
621 Opc = SystemZ::LOCRMux;
622 else {
623 Opc = SystemZ::LOCR;
624 MRI.constrainRegClass(DstReg, &SystemZ::GR32BitRegClass);
625 Register TReg = MRI.createVirtualRegister(&SystemZ::GR32BitRegClass);
626 Register FReg = MRI.createVirtualRegister(&SystemZ::GR32BitRegClass);
627 BuildMI(MBB, I, DL, get(TargetOpcode::COPY), TReg).addReg(TrueReg);
628 BuildMI(MBB, I, DL, get(TargetOpcode::COPY), FReg).addReg(FalseReg);
629 TrueReg = TReg;
630 FalseReg = FReg;
631 }
632 } else if (SystemZ::GR64BitRegClass.hasSubClassEq(RC)) {
633 if (STI.hasMiscellaneousExtensions3())
634 Opc = SystemZ::SELGR;
635 else
636 Opc = SystemZ::LOCGR;
637 } else
638 llvm_unreachable("Invalid register class");
639
640 BuildMI(MBB, I, DL, get(Opc), DstReg)
641 .addReg(FalseReg).addReg(TrueReg)
642 .addImm(CCValid).addImm(CCMask);
643}
644
646 Register Reg,
647 MachineRegisterInfo *MRI) const {
648 unsigned DefOpc = DefMI.getOpcode();
649
650 if (DefOpc == SystemZ::VGBM) {
651 int64_t ImmVal = DefMI.getOperand(1).getImm();
652 if (ImmVal != 0) // TODO: Handle other values
653 return false;
654
655 // Fold gr128 = COPY (vr128 VGBM imm)
656 //
657 // %tmp:gr64 = LGHI 0
658 // to gr128 = REG_SEQUENCE %tmp, %tmp
659 assert(DefMI.getOperand(0).getReg() == Reg);
660
661 if (!UseMI.isCopy())
662 return false;
663
664 Register CopyDstReg = UseMI.getOperand(0).getReg();
665 if (CopyDstReg.isVirtual() &&
666 MRI->getRegClass(CopyDstReg) == &SystemZ::GR128BitRegClass &&
667 MRI->hasOneNonDBGUse(Reg)) {
668 // TODO: Handle physical registers
669 // TODO: Handle gr64 uses with subregister indexes
670 // TODO: Should this multi-use cases?
671 Register TmpReg = MRI->createVirtualRegister(&SystemZ::GR64BitRegClass);
672 MachineBasicBlock &MBB = *UseMI.getParent();
673
674 loadImmediate(MBB, UseMI.getIterator(), TmpReg, ImmVal);
675
676 UseMI.setDesc(get(SystemZ::REG_SEQUENCE));
677 UseMI.getOperand(1).setReg(TmpReg);
678 MachineInstrBuilder(*MBB.getParent(), &UseMI)
679 .addImm(SystemZ::subreg_h64)
680 .addReg(TmpReg)
681 .addImm(SystemZ::subreg_l64);
682
683 if (MRI->use_nodbg_empty(Reg))
684 DefMI.eraseFromParent();
685 return true;
686 }
687
688 return false;
689 }
690
691 if (DefOpc != SystemZ::LHIMux && DefOpc != SystemZ::LHI &&
692 DefOpc != SystemZ::LGHI)
693 return false;
694 if (DefMI.getOperand(0).getReg() != Reg)
695 return false;
696 int32_t ImmVal = (int32_t)DefMI.getOperand(1).getImm();
697
698 unsigned UseOpc = UseMI.getOpcode();
699 unsigned NewUseOpc;
700 unsigned UseIdx;
701 int CommuteIdx = -1;
702 bool TieOps = false;
703 switch (UseOpc) {
704 case SystemZ::SELRMux:
705 TieOps = true;
706 [[fallthrough]];
707 case SystemZ::LOCRMux:
708 if (!STI.hasLoadStoreOnCond2())
709 return false;
710 NewUseOpc = SystemZ::LOCHIMux;
711 if (UseMI.getOperand(2).getReg() == Reg)
712 UseIdx = 2;
713 else if (UseMI.getOperand(1).getReg() == Reg)
714 UseIdx = 2, CommuteIdx = 1;
715 else
716 return false;
717 break;
718 case SystemZ::SELGR:
719 TieOps = true;
720 [[fallthrough]];
721 case SystemZ::LOCGR:
722 if (!STI.hasLoadStoreOnCond2())
723 return false;
724 NewUseOpc = SystemZ::LOCGHI;
725 if (UseMI.getOperand(2).getReg() == Reg)
726 UseIdx = 2;
727 else if (UseMI.getOperand(1).getReg() == Reg)
728 UseIdx = 2, CommuteIdx = 1;
729 else
730 return false;
731 break;
732 default:
733 return false;
734 }
735
736 if (CommuteIdx != -1)
737 if (!commuteInstruction(UseMI, false, CommuteIdx, UseIdx))
738 return false;
739
740 bool DeleteDef = MRI->hasOneNonDBGUse(Reg);
741 UseMI.setDesc(get(NewUseOpc));
742 if (TieOps)
743 UseMI.tieOperands(0, 1);
744 UseMI.getOperand(UseIdx).ChangeToImmediate(ImmVal);
745 if (DeleteDef)
746 DefMI.eraseFromParent();
747
748 return true;
749}
750
752 unsigned Opcode = MI.getOpcode();
753 if (Opcode == SystemZ::Return ||
754 Opcode == SystemZ::Return_XPLINK ||
755 Opcode == SystemZ::Trap ||
756 Opcode == SystemZ::CallJG ||
757 Opcode == SystemZ::CallBR)
758 return true;
759 return false;
760}
761
764 unsigned NumCycles, unsigned ExtraPredCycles,
765 BranchProbability Probability) const {
766 // Avoid using conditional returns at the end of a loop (since then
767 // we'd need to emit an unconditional branch to the beginning anyway,
768 // making the loop body longer). This doesn't apply for low-probability
769 // loops (eg. compare-and-swap retry), so just decide based on branch
770 // probability instead of looping structure.
771 // However, since Compare and Trap instructions cost the same as a regular
772 // Compare instruction, we should allow the if conversion to convert this
773 // into a Conditional Compare regardless of the branch probability.
774 if (MBB.getLastNonDebugInstr()->getOpcode() != SystemZ::Trap &&
775 MBB.succ_empty() && Probability < BranchProbability(1, 8))
776 return false;
777 // For now only convert single instructions.
778 return NumCycles == 1;
779}
780
783 unsigned NumCyclesT, unsigned ExtraPredCyclesT,
784 MachineBasicBlock &FMBB,
785 unsigned NumCyclesF, unsigned ExtraPredCyclesF,
786 BranchProbability Probability) const {
787 // For now avoid converting mutually-exclusive cases.
788 return false;
789}
790
793 BranchProbability Probability) const {
794 // For now only duplicate single instructions.
795 return NumCycles == 1;
796}
797
800 assert(Pred.size() == 2 && "Invalid condition");
801 unsigned CCValid = Pred[0].getImm();
802 unsigned CCMask = Pred[1].getImm();
803 assert(CCMask > 0 && CCMask < 15 && "Invalid predicate");
804 unsigned Opcode = MI.getOpcode();
805 if (Opcode == SystemZ::Trap) {
806 MI.setDesc(get(SystemZ::CondTrap));
807 MachineInstrBuilder(*MI.getParent()->getParent(), MI)
808 .addImm(CCValid).addImm(CCMask)
809 .addReg(SystemZ::CC, RegState::Implicit);
810 return true;
811 }
812 if (Opcode == SystemZ::Return || Opcode == SystemZ::Return_XPLINK) {
813 MI.setDesc(get(Opcode == SystemZ::Return ? SystemZ::CondReturn
814 : SystemZ::CondReturn_XPLINK));
815 MachineInstrBuilder(*MI.getParent()->getParent(), MI)
816 .addImm(CCValid)
817 .addImm(CCMask)
818 .addReg(SystemZ::CC, RegState::Implicit);
819 return true;
820 }
821 if (Opcode == SystemZ::CallJG) {
822 MachineOperand FirstOp = MI.getOperand(0);
823 const uint32_t *RegMask = MI.getOperand(1).getRegMask();
824 MI.removeOperand(1);
825 MI.removeOperand(0);
826 MI.setDesc(get(SystemZ::CallBRCL));
827 MachineInstrBuilder(*MI.getParent()->getParent(), MI)
828 .addImm(CCValid)
829 .addImm(CCMask)
830 .add(FirstOp)
831 .addRegMask(RegMask)
832 .addReg(SystemZ::CC, RegState::Implicit);
833 return true;
834 }
835 if (Opcode == SystemZ::CallBR) {
836 MachineOperand Target = MI.getOperand(0);
837 const uint32_t *RegMask = MI.getOperand(1).getRegMask();
838 MI.removeOperand(1);
839 MI.removeOperand(0);
840 MI.setDesc(get(SystemZ::CallBCR));
841 MachineInstrBuilder(*MI.getParent()->getParent(), MI)
842 .addImm(CCValid).addImm(CCMask)
843 .add(Target)
844 .addRegMask(RegMask)
845 .addReg(SystemZ::CC, RegState::Implicit);
846 return true;
847 }
848 return false;
849}
850
853 const DebugLoc &DL, Register DestReg,
854 Register SrcReg, bool KillSrc,
855 bool RenamableDest,
856 bool RenamableSrc) const {
857 // Split 128-bit GPR moves into two 64-bit moves. Add implicit uses of the
858 // super register in case one of the subregs is undefined.
859 // This handles ADDR128 too.
860 if (SystemZ::GR128BitRegClass.contains(DestReg, SrcReg)) {
861 copyPhysReg(MBB, MBBI, DL, RI.getSubReg(DestReg, SystemZ::subreg_h64),
862 RI.getSubReg(SrcReg, SystemZ::subreg_h64), KillSrc);
863 MachineInstrBuilder(*MBB.getParent(), std::prev(MBBI))
864 .addReg(SrcReg, RegState::Implicit);
865 copyPhysReg(MBB, MBBI, DL, RI.getSubReg(DestReg, SystemZ::subreg_l64),
866 RI.getSubReg(SrcReg, SystemZ::subreg_l64), KillSrc);
867 MachineInstrBuilder(*MBB.getParent(), std::prev(MBBI))
868 .addReg(SrcReg, (getKillRegState(KillSrc) | RegState::Implicit));
869 return;
870 }
871
872 if (SystemZ::GRX32BitRegClass.contains(DestReg, SrcReg)) {
873 emitGRX32Move(MBB, MBBI, DL, DestReg, SrcReg, SystemZ::LR, 32, KillSrc,
874 false);
875 return;
876 }
877
878 // Move 128-bit floating-point values between VR128 and FP128.
879 if (SystemZ::VR128BitRegClass.contains(DestReg) &&
880 SystemZ::FP128BitRegClass.contains(SrcReg)) {
881 MCRegister SrcRegHi =
882 RI.getMatchingSuperReg(RI.getSubReg(SrcReg, SystemZ::subreg_h64),
883 SystemZ::subreg_h64, &SystemZ::VR128BitRegClass);
884 MCRegister SrcRegLo =
885 RI.getMatchingSuperReg(RI.getSubReg(SrcReg, SystemZ::subreg_l64),
886 SystemZ::subreg_h64, &SystemZ::VR128BitRegClass);
887
888 BuildMI(MBB, MBBI, DL, get(SystemZ::VMRHG), DestReg)
889 .addReg(SrcRegHi, getKillRegState(KillSrc))
890 .addReg(SrcRegLo, getKillRegState(KillSrc));
891 return;
892 }
893 if (SystemZ::FP128BitRegClass.contains(DestReg) &&
894 SystemZ::VR128BitRegClass.contains(SrcReg)) {
895 MCRegister DestRegHi =
896 RI.getMatchingSuperReg(RI.getSubReg(DestReg, SystemZ::subreg_h64),
897 SystemZ::subreg_h64, &SystemZ::VR128BitRegClass);
898 MCRegister DestRegLo =
899 RI.getMatchingSuperReg(RI.getSubReg(DestReg, SystemZ::subreg_l64),
900 SystemZ::subreg_h64, &SystemZ::VR128BitRegClass);
901
902 if (DestRegHi != SrcReg.asMCReg())
903 copyPhysReg(MBB, MBBI, DL, DestRegHi, SrcReg, false);
904 BuildMI(MBB, MBBI, DL, get(SystemZ::VREPG), DestRegLo)
905 .addReg(SrcReg, getKillRegState(KillSrc)).addImm(1);
906 return;
907 }
908
909 if (SystemZ::FP128BitRegClass.contains(DestReg) &&
910 SystemZ::GR128BitRegClass.contains(SrcReg)) {
911 MCRegister DestRegHi = RI.getSubReg(DestReg, SystemZ::subreg_h64);
912 MCRegister DestRegLo = RI.getSubReg(DestReg, SystemZ::subreg_l64);
913 MCRegister SrcRegHi = RI.getSubReg(SrcReg, SystemZ::subreg_h64);
914 MCRegister SrcRegLo = RI.getSubReg(SrcReg, SystemZ::subreg_l64);
915
916 BuildMI(MBB, MBBI, DL, get(SystemZ::LDGR), DestRegHi)
917 .addReg(SrcRegHi)
919
920 BuildMI(MBB, MBBI, DL, get(SystemZ::LDGR), DestRegLo)
921 .addReg(SrcRegLo, getKillRegState(KillSrc));
922 return;
923 }
924
925 // Move CC value from a GR32.
926 if (DestReg == SystemZ::CC) {
927 unsigned Opcode =
928 SystemZ::GR32BitRegClass.contains(SrcReg) ? SystemZ::TMLH : SystemZ::TMHH;
929 BuildMI(MBB, MBBI, DL, get(Opcode))
930 .addReg(SrcReg, getKillRegState(KillSrc))
931 .addImm(3 << (SystemZ::IPM_CC - 16));
932 return;
933 }
934
935 if (SystemZ::GR128BitRegClass.contains(DestReg) &&
936 SystemZ::VR128BitRegClass.contains(SrcReg)) {
937 MCRegister DestH64 = RI.getSubReg(DestReg, SystemZ::subreg_h64);
938 MCRegister DestL64 = RI.getSubReg(DestReg, SystemZ::subreg_l64);
939
940 BuildMI(MBB, MBBI, DL, get(SystemZ::VLGVG), DestH64)
941 .addReg(SrcReg)
942 .addReg(SystemZ::NoRegister)
943 .addImm(0)
944 .addDef(DestReg, RegState::Implicit);
945 BuildMI(MBB, MBBI, DL, get(SystemZ::VLGVG), DestL64)
946 .addReg(SrcReg, getKillRegState(KillSrc))
947 .addReg(SystemZ::NoRegister)
948 .addImm(1);
949 return;
950 }
951
952 if (SystemZ::VR128BitRegClass.contains(DestReg) &&
953 SystemZ::GR128BitRegClass.contains(SrcReg)) {
954 BuildMI(MBB, MBBI, DL, get(SystemZ::VLVGP), DestReg)
955 .addReg(RI.getSubReg(SrcReg, SystemZ::subreg_h64))
956 .addReg(RI.getSubReg(SrcReg, SystemZ::subreg_l64));
957 return;
958 }
959
960 // Everything else needs only one instruction.
961 unsigned Opcode;
962 if (SystemZ::GR64BitRegClass.contains(DestReg, SrcReg))
963 Opcode = SystemZ::LGR;
964 else if (SystemZ::FP16BitRegClass.contains(DestReg, SrcReg))
965 Opcode = STI.hasVector() ? SystemZ::LDR16 : SystemZ::LER16;
966 else if (SystemZ::FP32BitRegClass.contains(DestReg, SrcReg))
967 // For z13 we prefer LDR over LER to avoid partial register dependencies.
968 Opcode = STI.hasVector() ? SystemZ::LDR32 : SystemZ::LER;
969 else if (SystemZ::FP64BitRegClass.contains(DestReg, SrcReg))
970 Opcode = SystemZ::LDR;
971 else if (SystemZ::FP128BitRegClass.contains(DestReg, SrcReg))
972 Opcode = SystemZ::LXR;
973 else if (SystemZ::VR16BitRegClass.contains(DestReg, SrcReg))
974 Opcode = SystemZ::VLR16;
975 else if (SystemZ::VR32BitRegClass.contains(DestReg, SrcReg))
976 Opcode = SystemZ::VLR32;
977 else if (SystemZ::VR64BitRegClass.contains(DestReg, SrcReg))
978 Opcode = SystemZ::VLR64;
979 else if (SystemZ::VR128BitRegClass.contains(DestReg, SrcReg))
980 Opcode = SystemZ::VLR;
981 else if (SystemZ::AR32BitRegClass.contains(DestReg, SrcReg))
982 Opcode = SystemZ::CPYA;
983 else if (SystemZ::GR64BitRegClass.contains(DestReg) &&
984 SystemZ::FP64BitRegClass.contains(SrcReg))
985 Opcode = SystemZ::LGDR;
986 else if (SystemZ::FP64BitRegClass.contains(DestReg) &&
987 SystemZ::GR64BitRegClass.contains(SrcReg))
988 Opcode = SystemZ::LDGR;
989 else
990 llvm_unreachable("Impossible reg-to-reg copy");
991
992 BuildMI(MBB, MBBI, DL, get(Opcode), DestReg)
993 .addReg(SrcReg, getKillRegState(KillSrc));
994}
995
998 bool isKill, int FrameIdx, const TargetRegisterClass *RC,
999
1000 Register VReg, MachineInstr::MIFlag Flags) const {
1001 DebugLoc DL = MBBI != MBB.end() ? MBBI->getDebugLoc() : DebugLoc();
1002
1003 // Callers may expect a single instruction, so keep 128-bit moves
1004 // together for now and lower them after register allocation.
1005 unsigned LoadOpcode, StoreOpcode;
1006 getLoadStoreOpcodes(RC, LoadOpcode, StoreOpcode);
1007 addFrameReference(BuildMI(MBB, MBBI, DL, get(StoreOpcode))
1008 .addReg(SrcReg, getKillRegState(isKill)),
1009 FrameIdx);
1010}
1011
1014 Register DestReg, int FrameIdx,
1015 const TargetRegisterClass *RC,
1016 Register VReg, unsigned SubReg,
1017 MachineInstr::MIFlag Flags) const {
1018 DebugLoc DL = MBBI != MBB.end() ? MBBI->getDebugLoc() : DebugLoc();
1019
1020 // Callers may expect a single instruction, so keep 128-bit moves
1021 // together for now and lower them after register allocation.
1022 unsigned LoadOpcode, StoreOpcode;
1023 getLoadStoreOpcodes(RC, LoadOpcode, StoreOpcode);
1024 addFrameReference(BuildMI(MBB, MBBI, DL, get(LoadOpcode), DestReg),
1025 FrameIdx);
1026}
1027
1028// Return true if MI is a simple load or store with a 12-bit displacement
1029// and no index. Flag is SimpleBDXLoad for loads and SimpleBDXStore for stores.
1030static bool isSimpleBD12Move(const MachineInstr *MI, unsigned Flag) {
1031 const MCInstrDesc &MCID = MI->getDesc();
1032 return ((MCID.TSFlags & Flag) &&
1033 isUInt<12>(MI->getOperand(2).getImm()) &&
1034 MI->getOperand(3).getReg() == 0);
1035}
1036
1037namespace {
1038
1039struct LogicOp {
1040 LogicOp() = default;
1041 LogicOp(unsigned regSize, unsigned immLSB, unsigned immSize)
1042 : RegSize(regSize), ImmLSB(immLSB), ImmSize(immSize) {}
1043
1044 explicit operator bool() const { return RegSize; }
1045
1046 unsigned RegSize = 0;
1047 unsigned ImmLSB = 0;
1048 unsigned ImmSize = 0;
1049};
1050
1051} // end anonymous namespace
1052
1053static LogicOp interpretAndImmediate(unsigned Opcode) {
1054 switch (Opcode) {
1055 case SystemZ::NILMux: return LogicOp(32, 0, 16);
1056 case SystemZ::NIHMux: return LogicOp(32, 16, 16);
1057 case SystemZ::NILL64: return LogicOp(64, 0, 16);
1058 case SystemZ::NILH64: return LogicOp(64, 16, 16);
1059 case SystemZ::NIHL64: return LogicOp(64, 32, 16);
1060 case SystemZ::NIHH64: return LogicOp(64, 48, 16);
1061 case SystemZ::NIFMux: return LogicOp(32, 0, 32);
1062 case SystemZ::NILF64: return LogicOp(64, 0, 32);
1063 case SystemZ::NIHF64: return LogicOp(64, 32, 32);
1064 default: return LogicOp();
1065 }
1066}
1067
1068static void transferDeadCC(MachineInstr *OldMI, MachineInstr *NewMI) {
1069 if (OldMI->registerDefIsDead(SystemZ::CC, /*TRI=*/nullptr)) {
1070 MachineOperand *CCDef =
1071 NewMI->findRegisterDefOperand(SystemZ::CC, /*TRI=*/nullptr);
1072 if (CCDef != nullptr)
1073 CCDef->setIsDead(true);
1074 }
1075}
1076
1077static void transferMIFlag(MachineInstr *OldMI, MachineInstr *NewMI,
1078 MachineInstr::MIFlag Flag) {
1079 if (OldMI->getFlag(Flag))
1080 NewMI->setFlag(Flag);
1081}
1082
1085 LiveIntervals *LIS) const {
1086 MachineBasicBlock *MBB = MI.getParent();
1087
1088 // Try to convert an AND into an RISBG-type instruction.
1089 // TODO: It might be beneficial to select RISBG and shorten to AND instead.
1090 if (LogicOp And = interpretAndImmediate(MI.getOpcode())) {
1091 if (!MI.registerDefIsDead(SystemZ::CC, /*TRI=*/nullptr))
1092 return nullptr;
1093 uint64_t Imm = MI.getOperand(2).getImm() << And.ImmLSB;
1094 // AND IMMEDIATE leaves the other bits of the register unchanged.
1095 Imm |= allOnes(And.RegSize) & ~(allOnes(And.ImmSize) << And.ImmLSB);
1096 unsigned Start, End;
1097 if (isRxSBGMask(Imm, And.RegSize, Start, End)) {
1098 unsigned NewOpcode;
1099 if (And.RegSize == 64) {
1100 NewOpcode = SystemZ::RISBG;
1101 // Prefer RISBGN if available, since it does not clobber CC.
1102 if (STI.hasMiscellaneousExtensions())
1103 NewOpcode = SystemZ::RISBGN;
1104 } else {
1105 NewOpcode = SystemZ::RISBMux;
1106 Start &= 31;
1107 End &= 31;
1108 }
1109 MachineOperand &Dest = MI.getOperand(0);
1110 MachineOperand &Src = MI.getOperand(1);
1112 BuildMI(*MBB, MI, MI.getDebugLoc(), get(NewOpcode))
1113 .add(Dest)
1114 .addReg(0)
1115 .addReg(Src.getReg(), getKillRegState(Src.isKill()),
1116 Src.getSubReg())
1117 .addImm(Start)
1118 .addImm(End + 128)
1119 .addImm(0);
1120 if (LIS) {
1121 SlotIndex Idx = LIS->ReplaceMachineInstrInMaps(MI, *MIB);
1122 if (!MIB->definesRegister(SystemZ::CC, /*TRI=*/nullptr))
1123 LIS->removePhysRegDefAt(SystemZ::CC, Idx.getRegSlot());
1124 }
1125 transferDeadCC(&MI, MIB);
1126 return MIB;
1127 }
1128 }
1129 return nullptr;
1130}
1131
1133 bool Invert) const {
1134 unsigned Opc = Inst.getOpcode();
1135 if (Invert) {
1136 auto InverseOpcode = getInverseOpcode(Opc);
1137 if (!InverseOpcode)
1138 return false;
1139 Opc = *InverseOpcode;
1140 }
1141
1142 switch (Opc) {
1143 default:
1144 break;
1145 // Adds and multiplications.
1146 case SystemZ::WFADB:
1147 case SystemZ::WFASB:
1148 case SystemZ::WFAXB:
1149 case SystemZ::VFADB:
1150 case SystemZ::VFASB:
1151 case SystemZ::WFMDB:
1152 case SystemZ::WFMSB:
1153 case SystemZ::WFMXB:
1154 case SystemZ::VFMDB:
1155 case SystemZ::VFMSB:
1158 }
1159
1160 return false;
1161}
1162
1163std::optional<unsigned>
1165 // fadd => fsub
1166 switch (Opcode) {
1167 case SystemZ::WFADB:
1168 return SystemZ::WFSDB;
1169 case SystemZ::WFASB:
1170 return SystemZ::WFSSB;
1171 case SystemZ::WFAXB:
1172 return SystemZ::WFSXB;
1173 case SystemZ::VFADB:
1174 return SystemZ::VFSDB;
1175 case SystemZ::VFASB:
1176 return SystemZ::VFSSB;
1177 // fsub => fadd
1178 case SystemZ::WFSDB:
1179 return SystemZ::WFADB;
1180 case SystemZ::WFSSB:
1181 return SystemZ::WFASB;
1182 case SystemZ::WFSXB:
1183 return SystemZ::WFAXB;
1184 case SystemZ::VFSDB:
1185 return SystemZ::VFADB;
1186 case SystemZ::VFSSB:
1187 return SystemZ::VFASB;
1188 default:
1189 return std::nullopt;
1190 }
1191}
1192
1195 int FrameIndex, MachineInstr *&CopyMI, LiveIntervals *LIS,
1196 VirtRegMap *VRM) const {
1199 MachineRegisterInfo &MRI = MF.getRegInfo();
1200 const MachineFrameInfo &MFI = MF.getFrameInfo();
1201 unsigned Size = MFI.getObjectSize(FrameIndex);
1202 unsigned Opcode = MI.getOpcode();
1203
1204 // Check CC liveness if new instruction introduces a dead def of CC.
1205 SlotIndex MISlot = SlotIndex();
1206 LiveRange *CCLiveRange = nullptr;
1207 bool CCLiveAtMI = true;
1208 if (LIS) {
1209 MISlot = LIS->getSlotIndexes()->getInstructionIndex(MI).getRegSlot();
1210 auto CCUnits = TRI->regunits(MCRegister::from(SystemZ::CC));
1211 assert(range_size(CCUnits) == 1 && "CC only has one reg unit.");
1212 CCLiveRange = &LIS->getRegUnit(*CCUnits.begin());
1213 CCLiveAtMI = CCLiveRange->liveAt(MISlot);
1214 }
1215
1216 if (Ops.size() == 2 && Ops[0] == 0 && Ops[1] == 1) {
1217 if (!CCLiveAtMI && (Opcode == SystemZ::LA || Opcode == SystemZ::LAY) &&
1218 isInt<8>(MI.getOperand(2).getImm()) && !MI.getOperand(3).getReg()) {
1219 // LA(Y) %reg, CONST(%reg) -> AGSI %mem, CONST
1220 MachineInstr *BuiltMI = BuildMI(*InsertPt->getParent(), InsertPt,
1221 MI.getDebugLoc(), get(SystemZ::AGSI))
1222 .addFrameIndex(FrameIndex)
1223 .addImm(0)
1224 .addImm(MI.getOperand(2).getImm());
1225 BuiltMI->findRegisterDefOperand(SystemZ::CC, /*TRI=*/nullptr)
1226 ->setIsDead(true);
1227 CCLiveRange->createDeadDef(MISlot, LIS->getVNInfoAllocator());
1228 return BuiltMI;
1229 }
1230 return nullptr;
1231 }
1232
1233 // All other cases require a single operand.
1234 if (Ops.size() != 1)
1235 return nullptr;
1236
1237 unsigned OpNum = Ops[0];
1238 const TargetRegisterClass *RC =
1239 MF.getRegInfo().getRegClass(MI.getOperand(OpNum).getReg());
1240 assert((Size * 8 == TRI->getRegSizeInBits(*RC) ||
1241 (RC == &SystemZ::FP16BitRegClass && Size == 4 && !STI.hasVector())) &&
1242 "Invalid size combination");
1243 (void)RC;
1244
1245 if ((Opcode == SystemZ::AHI || Opcode == SystemZ::AGHI) && OpNum == 0 &&
1246 isInt<8>(MI.getOperand(2).getImm())) {
1247 // A(G)HI %reg, CONST -> A(G)SI %mem, CONST
1248 Opcode = (Opcode == SystemZ::AHI ? SystemZ::ASI : SystemZ::AGSI);
1249 MachineInstr *BuiltMI =
1250 BuildMI(*InsertPt->getParent(), InsertPt, MI.getDebugLoc(), get(Opcode))
1251 .addFrameIndex(FrameIndex)
1252 .addImm(0)
1253 .addImm(MI.getOperand(2).getImm());
1254 transferDeadCC(&MI, BuiltMI);
1256 return BuiltMI;
1257 }
1258
1259 if ((Opcode == SystemZ::ALFI && OpNum == 0 &&
1260 isInt<8>((int32_t)MI.getOperand(2).getImm())) ||
1261 (Opcode == SystemZ::ALGFI && OpNum == 0 &&
1262 isInt<8>(MI.getOperand(2).getImm()))) {
1263 // AL(G)FI %reg, CONST -> AL(G)SI %mem, CONST
1264 Opcode = (Opcode == SystemZ::ALFI ? SystemZ::ALSI : SystemZ::ALGSI);
1265 MachineInstr *BuiltMI =
1266 BuildMI(*InsertPt->getParent(), InsertPt, MI.getDebugLoc(), get(Opcode))
1267 .addFrameIndex(FrameIndex)
1268 .addImm(0)
1269 .addImm((int8_t)MI.getOperand(2).getImm());
1270 transferDeadCC(&MI, BuiltMI);
1271 return BuiltMI;
1272 }
1273
1274 if ((Opcode == SystemZ::SLFI && OpNum == 0 &&
1275 isInt<8>((int32_t)-MI.getOperand(2).getImm())) ||
1276 (Opcode == SystemZ::SLGFI && OpNum == 0 &&
1277 isInt<8>((-MI.getOperand(2).getImm())))) {
1278 // SL(G)FI %reg, CONST -> AL(G)SI %mem, -CONST
1279 Opcode = (Opcode == SystemZ::SLFI ? SystemZ::ALSI : SystemZ::ALGSI);
1280 MachineInstr *BuiltMI =
1281 BuildMI(*InsertPt->getParent(), InsertPt, MI.getDebugLoc(), get(Opcode))
1282 .addFrameIndex(FrameIndex)
1283 .addImm(0)
1284 .addImm((int8_t)-MI.getOperand(2).getImm());
1285 transferDeadCC(&MI, BuiltMI);
1286 return BuiltMI;
1287 }
1288
1289 unsigned MemImmOpc = 0;
1290 switch (Opcode) {
1291 case SystemZ::LHIMux:
1292 case SystemZ::LHI: MemImmOpc = SystemZ::MVHI; break;
1293 case SystemZ::LGHI: MemImmOpc = SystemZ::MVGHI; break;
1294 case SystemZ::CHIMux:
1295 case SystemZ::CHI: MemImmOpc = SystemZ::CHSI; break;
1296 case SystemZ::CGHI: MemImmOpc = SystemZ::CGHSI; break;
1297 case SystemZ::CLFIMux:
1298 case SystemZ::CLFI:
1299 if (isUInt<16>(MI.getOperand(1).getImm()))
1300 MemImmOpc = SystemZ::CLFHSI;
1301 break;
1302 case SystemZ::CLGFI:
1303 if (isUInt<16>(MI.getOperand(1).getImm()))
1304 MemImmOpc = SystemZ::CLGHSI;
1305 break;
1306 default: break;
1307 }
1308 if (MemImmOpc)
1309 return BuildMI(*InsertPt->getParent(), InsertPt, MI.getDebugLoc(),
1310 get(MemImmOpc))
1311 .addFrameIndex(FrameIndex)
1312 .addImm(0)
1313 .addImm(MI.getOperand(1).getImm());
1314
1315 if (Opcode == SystemZ::LGDR || Opcode == SystemZ::LDGR) {
1316 bool Op0IsGPR = (Opcode == SystemZ::LGDR);
1317 bool Op1IsGPR = (Opcode == SystemZ::LDGR);
1318 // If we're spilling the destination of an LDGR or LGDR, store the
1319 // source register instead.
1320 if (OpNum == 0) {
1321 unsigned StoreOpcode = Op1IsGPR ? SystemZ::STG : SystemZ::STD;
1322 return BuildMI(*InsertPt->getParent(), InsertPt, MI.getDebugLoc(),
1323 get(StoreOpcode))
1324 .add(MI.getOperand(1))
1325 .addFrameIndex(FrameIndex)
1326 .addImm(0)
1327 .addReg(0);
1328 }
1329 // If we're spilling the source of an LDGR or LGDR, load the
1330 // destination register instead.
1331 if (OpNum == 1) {
1332 unsigned LoadOpcode = Op0IsGPR ? SystemZ::LG : SystemZ::LD;
1333 return BuildMI(*InsertPt->getParent(), InsertPt, MI.getDebugLoc(),
1334 get(LoadOpcode))
1335 .add(MI.getOperand(0))
1336 .addFrameIndex(FrameIndex)
1337 .addImm(0)
1338 .addReg(0);
1339 }
1340 }
1341
1342 // Look for cases where the source of a simple store or the destination
1343 // of a simple load is being spilled. Try to use MVC instead.
1344 //
1345 // Although MVC is in practice a fast choice in these cases, it is still
1346 // logically a bytewise copy. This means that we cannot use it if the
1347 // load or store is volatile. We also wouldn't be able to use MVC if
1348 // the two memories partially overlap, but that case cannot occur here,
1349 // because we know that one of the memories is a full frame index.
1350 //
1351 // For performance reasons, we also want to avoid using MVC if the addresses
1352 // might be equal. We don't worry about that case here, because spill slot
1353 // coloring happens later, and because we have special code to remove
1354 // MVCs that turn out to be redundant.
1355 if (OpNum == 0 && MI.hasOneMemOperand()) {
1356 MachineMemOperand *MMO = *MI.memoperands_begin();
1357 if (MMO->getSize() == Size && !MMO->isVolatile() && !MMO->isAtomic()) {
1358 // Handle conversion of loads.
1360 return BuildMI(*InsertPt->getParent(), InsertPt, MI.getDebugLoc(),
1361 get(SystemZ::MVC))
1362 .addFrameIndex(FrameIndex)
1363 .addImm(0)
1364 .addImm(Size)
1365 .add(MI.getOperand(1))
1366 .addImm(MI.getOperand(2).getImm())
1367 .addMemOperand(MMO);
1368 }
1369 // Handle conversion of stores.
1371 return BuildMI(*InsertPt->getParent(), InsertPt, MI.getDebugLoc(),
1372 get(SystemZ::MVC))
1373 .add(MI.getOperand(1))
1374 .addImm(MI.getOperand(2).getImm())
1375 .addImm(Size)
1376 .addFrameIndex(FrameIndex)
1377 .addImm(0)
1378 .addMemOperand(MMO);
1379 }
1380 }
1381 }
1382
1383 // If the spilled operand is the final one or the instruction is
1384 // commutable, try to change <INSN>R into <INSN>. Don't introduce a def of
1385 // CC if it is live and MI does not define it.
1386 unsigned NumOps = MI.getNumExplicitOperands();
1387 int MemOpcode = SystemZ::getMemOpcode(Opcode);
1388 if (MemOpcode == -1 ||
1389 (CCLiveAtMI && !MI.definesRegister(SystemZ::CC, /*TRI=*/nullptr) &&
1390 get(MemOpcode).hasImplicitDefOfPhysReg(SystemZ::CC)))
1391 return nullptr;
1392
1393 // Check if all other vregs have a usable allocation in the case of vector
1394 // to FP conversion.
1395 const MCInstrDesc &MCID = MI.getDesc();
1396 for (unsigned I = 0, E = MCID.getNumOperands(); I != E; ++I) {
1397 const MCOperandInfo &MCOI = MCID.operands()[I];
1398 if (MCOI.OperandType != MCOI::OPERAND_REGISTER || I == OpNum)
1399 continue;
1400 const TargetRegisterClass *RC = TRI->getRegClass(MCOI.RegClass);
1401 if (RC == &SystemZ::VR32BitRegClass || RC == &SystemZ::VR64BitRegClass) {
1402 Register Reg = MI.getOperand(I).getReg();
1403 Register PhysReg = Reg.isVirtual()
1404 ? (VRM ? Register(VRM->getPhys(Reg)) : Register())
1405 : Reg;
1406 if (!PhysReg ||
1407 !(SystemZ::FP32BitRegClass.contains(PhysReg) ||
1408 SystemZ::FP64BitRegClass.contains(PhysReg) ||
1409 SystemZ::VF128BitRegClass.contains(PhysReg)))
1410 return nullptr;
1411 }
1412 }
1413 // Fused multiply and add/sub need to have the same dst and accumulator reg.
1414 bool FusedFPOp = (Opcode == SystemZ::WFMADB || Opcode == SystemZ::WFMASB ||
1415 Opcode == SystemZ::WFMSDB || Opcode == SystemZ::WFMSSB);
1416 if (FusedFPOp) {
1417 Register DstReg = VRM->getPhys(MI.getOperand(0).getReg());
1418 Register AccReg = VRM->getPhys(MI.getOperand(3).getReg());
1419 if (OpNum == 0 || OpNum == 3 || DstReg != AccReg)
1420 return nullptr;
1421 }
1422
1423 // Try to swap compare operands if possible.
1424 bool NeedsCommute = false;
1425 if ((MI.getOpcode() == SystemZ::CR || MI.getOpcode() == SystemZ::CGR ||
1426 MI.getOpcode() == SystemZ::CLR || MI.getOpcode() == SystemZ::CLGR ||
1427 MI.getOpcode() == SystemZ::WFCDB || MI.getOpcode() == SystemZ::WFCSB ||
1428 MI.getOpcode() == SystemZ::WFKDB || MI.getOpcode() == SystemZ::WFKSB) &&
1429 OpNum == 0 && prepareCompareSwapOperands(MI))
1430 NeedsCommute = true;
1431
1432 bool CCOperands = false;
1433 if (MI.getOpcode() == SystemZ::LOCRMux || MI.getOpcode() == SystemZ::LOCGR ||
1434 MI.getOpcode() == SystemZ::SELRMux || MI.getOpcode() == SystemZ::SELGR) {
1435 assert(MI.getNumOperands() == 6 && NumOps == 5 &&
1436 "LOCR/SELR instruction operands corrupt?");
1437 NumOps -= 2;
1438 CCOperands = true;
1439 }
1440
1441 // See if this is a 3-address instruction that is convertible to 2-address
1442 // and suitable for folding below. Only try this with virtual registers
1443 // and a provided VRM (during regalloc).
1444 if (NumOps == 3 && SystemZ::getTargetMemOpcode(MemOpcode) != -1) {
1445 if (VRM == nullptr)
1446 return nullptr;
1447 else {
1448 Register DstReg = MI.getOperand(0).getReg();
1449 Register DstPhys =
1450 (DstReg.isVirtual() ? Register(VRM->getPhys(DstReg)) : DstReg);
1451 Register SrcReg = (OpNum == 2 ? MI.getOperand(1).getReg()
1452 : ((OpNum == 1 && MI.isCommutable())
1453 ? MI.getOperand(2).getReg()
1454 : Register()));
1455 if (DstPhys && !SystemZ::GRH32BitRegClass.contains(DstPhys) && SrcReg &&
1456 SrcReg.isVirtual() && DstPhys == VRM->getPhys(SrcReg))
1457 NeedsCommute = (OpNum == 1);
1458 else
1459 return nullptr;
1460 }
1461 }
1462
1463 if ((OpNum == NumOps - 1) || NeedsCommute || FusedFPOp) {
1464 const MCInstrDesc &MemDesc = get(MemOpcode);
1465 uint64_t AccessBytes = SystemZII::getAccessSize(MemDesc.TSFlags);
1466 assert(AccessBytes != 0 && "Size of access should be known");
1467 assert(AccessBytes <= Size && "Access outside the frame index");
1468 uint64_t Offset = Size - AccessBytes;
1469 MachineInstrBuilder MIB = BuildMI(*InsertPt->getParent(), InsertPt,
1470 MI.getDebugLoc(), get(MemOpcode));
1471 if (MI.isCompare()) {
1472 assert(NumOps == 2 && "Expected 2 register operands for a compare.");
1473 MIB.add(MI.getOperand(NeedsCommute ? 1 : 0));
1474 }
1475 else if (FusedFPOp) {
1476 MIB.add(MI.getOperand(0));
1477 MIB.add(MI.getOperand(3));
1478 MIB.add(MI.getOperand(OpNum == 1 ? 2 : 1));
1479 }
1480 else {
1481 MIB.add(MI.getOperand(0));
1482 if (NeedsCommute)
1483 MIB.add(MI.getOperand(2));
1484 else
1485 for (unsigned I = 1; I < OpNum; ++I)
1486 MIB.add(MI.getOperand(I));
1487 }
1488 MIB.addFrameIndex(FrameIndex).addImm(Offset);
1489 if (MemDesc.TSFlags & SystemZII::HasIndex)
1490 MIB.addReg(0);
1491 if (CCOperands) {
1492 unsigned CCValid = MI.getOperand(NumOps).getImm();
1493 unsigned CCMask = MI.getOperand(NumOps + 1).getImm();
1494 MIB.addImm(CCValid);
1495 MIB.addImm(NeedsCommute ? CCMask ^ CCValid : CCMask);
1496 }
1497 if (MIB->definesRegister(SystemZ::CC, /*TRI=*/nullptr) &&
1498 (!MI.definesRegister(SystemZ::CC, /*TRI=*/nullptr) ||
1499 MI.registerDefIsDead(SystemZ::CC, /*TRI=*/nullptr))) {
1500 MIB->addRegisterDead(SystemZ::CC, TRI);
1501 if (CCLiveRange)
1502 CCLiveRange->createDeadDef(MISlot, LIS->getVNInfoAllocator());
1503 }
1504 // Constrain the register classes if converted from a vector opcode. The
1505 // allocated regs are in an FP reg-class per previous check above.
1506 for (const MachineOperand &MO : MIB->operands())
1507 if (MO.isReg() && MO.getReg().isVirtual()) {
1508 Register Reg = MO.getReg();
1509 if (MRI.getRegClass(Reg) == &SystemZ::VR32BitRegClass)
1510 MRI.setRegClass(Reg, &SystemZ::FP32BitRegClass);
1511 else if (MRI.getRegClass(Reg) == &SystemZ::VR64BitRegClass)
1512 MRI.setRegClass(Reg, &SystemZ::FP64BitRegClass);
1513 else if (MRI.getRegClass(Reg) == &SystemZ::VR128BitRegClass)
1514 MRI.setRegClass(Reg, &SystemZ::VF128BitRegClass);
1515 }
1516
1517 transferDeadCC(&MI, MIB);
1520 return MIB;
1521 }
1522
1523 return nullptr;
1524}
1525
1528 MachineInstr &LoadMI, MachineInstr *&CopyMI, LiveIntervals *LIS,
1529 VirtRegMap *VRM) const {
1531 MachineRegisterInfo *MRI = &MF.getRegInfo();
1532 MachineBasicBlock *MBB = MI.getParent();
1533
1534 // For reassociable FP operations, any loads have been purposefully left
1535 // unfolded so that MachineCombiner can do its work on reg/reg
1536 // opcodes. After that, as many loads as possible are now folded.
1537 // TODO: This may be beneficial with other opcodes as well as machine-sink
1538 // can move loads close to their user in a different MBB, which the isel
1539 // matcher did not see.
1540 unsigned LoadOpc = 0;
1541 unsigned RegMemOpcode = 0;
1542 const TargetRegisterClass *FPRC = nullptr;
1543 RegMemOpcode = MI.getOpcode() == SystemZ::WFADB ? SystemZ::ADB
1544 : MI.getOpcode() == SystemZ::WFSDB ? SystemZ::SDB
1545 : MI.getOpcode() == SystemZ::WFMDB ? SystemZ::MDB
1546 : 0;
1547 if (RegMemOpcode) {
1548 LoadOpc = SystemZ::VL64;
1549 FPRC = &SystemZ::FP64BitRegClass;
1550 } else {
1551 RegMemOpcode = MI.getOpcode() == SystemZ::WFASB ? SystemZ::AEB
1552 : MI.getOpcode() == SystemZ::WFSSB ? SystemZ::SEB
1553 : MI.getOpcode() == SystemZ::WFMSB ? SystemZ::MEEB
1554 : 0;
1555 if (RegMemOpcode) {
1556 LoadOpc = SystemZ::VL32;
1557 FPRC = &SystemZ::FP32BitRegClass;
1558 }
1559 }
1560 if (!RegMemOpcode || LoadMI.getOpcode() != LoadOpc)
1561 return nullptr;
1562
1563 // If RegMemOpcode clobbers CC, first make sure CC is not live at this point.
1564 if (get(RegMemOpcode).hasImplicitDefOfPhysReg(SystemZ::CC)) {
1565 for (MachineBasicBlock::iterator MII = InsertPt;;) {
1566 if (MII == MBB->begin()) {
1567 if (MBB->isLiveIn(SystemZ::CC))
1568 return nullptr;
1569 break;
1570 }
1571 --MII;
1572 if (MII->definesRegister(SystemZ::CC, /*TRI=*/nullptr)) {
1573 if (!MII->registerDefIsDead(SystemZ::CC, /*TRI=*/nullptr))
1574 return nullptr;
1575 break;
1576 }
1577 }
1578 }
1579
1580 Register FoldAsLoadDefReg = LoadMI.getOperand(0).getReg();
1581 if (Ops.size() != 1 || FoldAsLoadDefReg != MI.getOperand(Ops[0]).getReg())
1582 return nullptr;
1583 Register DstReg = MI.getOperand(0).getReg();
1584 MachineOperand LHS = MI.getOperand(1);
1585 MachineOperand RHS = MI.getOperand(2);
1586 MachineOperand &RegMO = RHS.getReg() == FoldAsLoadDefReg ? LHS : RHS;
1587 if ((RegMemOpcode == SystemZ::SDB || RegMemOpcode == SystemZ::SEB) &&
1588 FoldAsLoadDefReg != RHS.getReg())
1589 return nullptr;
1590 if (!MRI->isSSA() && DstReg != RegMO.getReg())
1591 return nullptr;
1592
1593 MachineOperand &Base = LoadMI.getOperand(1);
1594 MachineOperand &Disp = LoadMI.getOperand(2);
1595 MachineOperand &Indx = LoadMI.getOperand(3);
1597 BuildMI(*MI.getParent(), InsertPt, MI.getDebugLoc(), get(RegMemOpcode), DstReg)
1598 .add(RegMO)
1599 .add(Base)
1600 .add(Disp)
1601 .add(Indx);
1602 MIB->addRegisterDead(SystemZ::CC, &RI);
1603 MRI->setRegClass(DstReg, FPRC);
1604 MRI->setRegClass(RegMO.getReg(), FPRC);
1606
1607 return MIB;
1608}
1609
1611 switch (MI.getOpcode()) {
1612 case SystemZ::L128:
1613 splitMove(MI, SystemZ::LG);
1614 return true;
1615
1616 case SystemZ::ST128:
1617 splitMove(MI, SystemZ::STG);
1618 return true;
1619
1620 case SystemZ::LX:
1621 splitMove(MI, SystemZ::LD);
1622 return true;
1623
1624 case SystemZ::STX:
1625 splitMove(MI, SystemZ::STD);
1626 return true;
1627
1628 case SystemZ::LBMux:
1629 expandRXYPseudo(MI, SystemZ::LB, SystemZ::LBH);
1630 return true;
1631
1632 case SystemZ::LHMux:
1633 expandRXYPseudo(MI, SystemZ::LH, SystemZ::LHH);
1634 return true;
1635
1636 case SystemZ::LLCRMux:
1637 expandZExtPseudo(MI, SystemZ::LLCR, 8);
1638 return true;
1639
1640 case SystemZ::LLHRMux:
1641 expandZExtPseudo(MI, SystemZ::LLHR, 16);
1642 return true;
1643
1644 case SystemZ::LLCMux:
1645 expandRXYPseudo(MI, SystemZ::LLC, SystemZ::LLCH);
1646 return true;
1647
1648 case SystemZ::LLHMux:
1649 expandRXYPseudo(MI, SystemZ::LLH, SystemZ::LLHH);
1650 return true;
1651
1652 case SystemZ::LMux:
1653 expandRXYPseudo(MI, SystemZ::L, SystemZ::LFH);
1654 return true;
1655
1656 case SystemZ::LOCMux:
1657 expandLOCPseudo(MI, SystemZ::LOC, SystemZ::LOCFH);
1658 return true;
1659
1660 case SystemZ::LOCHIMux:
1661 expandLOCPseudo(MI, SystemZ::LOCHI, SystemZ::LOCHHI);
1662 return true;
1663
1664 case SystemZ::STCMux:
1665 expandRXYPseudo(MI, SystemZ::STC, SystemZ::STCH);
1666 return true;
1667
1668 case SystemZ::STHMux:
1669 expandRXYPseudo(MI, SystemZ::STH, SystemZ::STHH);
1670 return true;
1671
1672 case SystemZ::STMux:
1673 expandRXYPseudo(MI, SystemZ::ST, SystemZ::STFH);
1674 return true;
1675
1676 case SystemZ::STOCMux:
1677 expandLOCPseudo(MI, SystemZ::STOC, SystemZ::STOCFH);
1678 return true;
1679
1680 case SystemZ::LHIMux:
1681 expandRIPseudo(MI, SystemZ::LHI, SystemZ::IIHF, true);
1682 return true;
1683
1684 case SystemZ::IIFMux:
1685 expandRIPseudo(MI, SystemZ::IILF, SystemZ::IIHF, false);
1686 return true;
1687
1688 case SystemZ::IILMux:
1689 expandRIPseudo(MI, SystemZ::IILL, SystemZ::IIHL, false);
1690 return true;
1691
1692 case SystemZ::IIHMux:
1693 expandRIPseudo(MI, SystemZ::IILH, SystemZ::IIHH, false);
1694 return true;
1695
1696 case SystemZ::NIFMux:
1697 expandRIPseudo(MI, SystemZ::NILF, SystemZ::NIHF, false);
1698 return true;
1699
1700 case SystemZ::NILMux:
1701 expandRIPseudo(MI, SystemZ::NILL, SystemZ::NIHL, false);
1702 return true;
1703
1704 case SystemZ::NIHMux:
1705 expandRIPseudo(MI, SystemZ::NILH, SystemZ::NIHH, false);
1706 return true;
1707
1708 case SystemZ::OIFMux:
1709 expandRIPseudo(MI, SystemZ::OILF, SystemZ::OIHF, false);
1710 return true;
1711
1712 case SystemZ::OILMux:
1713 expandRIPseudo(MI, SystemZ::OILL, SystemZ::OIHL, false);
1714 return true;
1715
1716 case SystemZ::OIHMux:
1717 expandRIPseudo(MI, SystemZ::OILH, SystemZ::OIHH, false);
1718 return true;
1719
1720 case SystemZ::XIFMux:
1721 expandRIPseudo(MI, SystemZ::XILF, SystemZ::XIHF, false);
1722 return true;
1723
1724 case SystemZ::TMLMux:
1725 expandRIPseudo(MI, SystemZ::TMLL, SystemZ::TMHL, false);
1726 return true;
1727
1728 case SystemZ::TMHMux:
1729 expandRIPseudo(MI, SystemZ::TMLH, SystemZ::TMHH, false);
1730 return true;
1731
1732 case SystemZ::AHIMux:
1733 expandRIPseudo(MI, SystemZ::AHI, SystemZ::AIH, false);
1734 return true;
1735
1736 case SystemZ::AHIMuxK:
1737 expandRIEPseudo(MI, SystemZ::AHI, SystemZ::AHIK, SystemZ::AIH);
1738 return true;
1739
1740 case SystemZ::AFIMux:
1741 expandRIPseudo(MI, SystemZ::AFI, SystemZ::AIH, false);
1742 return true;
1743
1744 case SystemZ::CHIMux:
1745 expandRIPseudo(MI, SystemZ::CHI, SystemZ::CIH, false);
1746 return true;
1747
1748 case SystemZ::CFIMux:
1749 expandRIPseudo(MI, SystemZ::CFI, SystemZ::CIH, false);
1750 return true;
1751
1752 case SystemZ::CLFIMux:
1753 expandRIPseudo(MI, SystemZ::CLFI, SystemZ::CLIH, false);
1754 return true;
1755
1756 case SystemZ::CMux:
1757 expandRXYPseudo(MI, SystemZ::C, SystemZ::CHF);
1758 return true;
1759
1760 case SystemZ::CLMux:
1761 expandRXYPseudo(MI, SystemZ::CL, SystemZ::CLHF);
1762 return true;
1763
1764 case SystemZ::RISBMux: {
1765 bool DestIsHigh = SystemZ::isHighReg(MI.getOperand(0).getReg());
1766 bool SrcIsHigh = SystemZ::isHighReg(MI.getOperand(2).getReg());
1767 if (SrcIsHigh == DestIsHigh)
1768 MI.setDesc(get(DestIsHigh ? SystemZ::RISBHH : SystemZ::RISBLL));
1769 else {
1770 MI.setDesc(get(DestIsHigh ? SystemZ::RISBHL : SystemZ::RISBLH));
1771 MI.getOperand(5).setImm(MI.getOperand(5).getImm() ^ 32);
1772 }
1773 return true;
1774 }
1775
1776 case SystemZ::ADJDYNALLOC:
1777 splitAdjDynAlloc(MI);
1778 return true;
1779
1780 case SystemZ::MOV_STACKGUARD:
1781 expandStackGuardPseudo(MI, SystemZ::MVC);
1782 return true;
1783
1784 case SystemZ::CMP_STACKGUARD:
1785 expandStackGuardPseudo(MI, SystemZ::CLC);
1786 return true;
1787
1788 default:
1789 return false;
1790 }
1791}
1792
1793void SystemZInstrInfo::expandStackGuardPseudo(MachineInstr &MI,
1794 unsigned Opcode) const {
1795 MachineBasicBlock &MBB = *(MI.getParent());
1796 const MachineFunction &MF = *(MBB.getParent());
1797 const auto DL = MI.getDebugLoc();
1798 const Module *M = MF.getFunction().getParent();
1799 StringRef GuardType = M->getStackProtectorGuard();
1800 unsigned int Offset = 0;
1801
1802 Register AddrReg = MI.getOperand(0).getReg();
1803
1804 assert(
1805 AddrReg != MI.getOperand(1).getReg() &&
1806 "Scratch register for stack guard address blocked by operand register.");
1807
1808 // Emit an appropriate pseudo for the guard type, which loads the address of
1809 // said guard into the scratch register AddrReg.
1810 if (GuardType.empty() || (GuardType == "tls")) {
1811 if (STI.isTargetzOS()) {
1812 enum { OFFSET_PSALAA = 0x4B8 };
1813 enum { OFFSET_CEELAA_STACK_GUARD = 0x98 };
1814 // Load LAA
1815 // LLGT <reg>,1208
1816 BuildMI(MBB, MI, MI.getDebugLoc(), get(SystemZ::LLGT), AddrReg)
1817 .addReg(0)
1818 .addImm(OFFSET_PSALAA)
1819 .addReg(0);
1820 Offset = OFFSET_CEELAA_STACK_GUARD;
1821 } else {
1822 // Emit a load of the TLS block's address
1823 BuildMI(MBB, MI, DL, get(SystemZ::LOAD_TLS_BLOCK_ADDR), AddrReg);
1824 // Record the appropriate stack guard offset (40 in the tls case).
1825 Offset = 40;
1826 }
1827 } else if (GuardType == "global") {
1828 // Emit a load of the global stack guard's address
1829 BuildMI(MBB, MI, DL, get(SystemZ::LOAD_GLOBAL_STACKGUARD_ADDR), AddrReg);
1830 } else {
1831 report_fatal_error(Twine("unknown stack protector type \"") + GuardType +
1832 "\".");
1833 }
1834
1835 // Construct the appropriate move or compare instruction using the
1836 // scratch register.
1837 BuildMI(*(MI.getParent()), MI, MI.getDebugLoc(), get(Opcode))
1838 .addReg(MI.getOperand(1).getReg())
1839 .addImm(MI.getOperand(2).getImm())
1840 .addImm(8)
1841 .addReg(AddrReg)
1842 .addImm(Offset);
1843
1844 MI.removeFromParent();
1845}
1846
1848 if (MI.isInlineAsm()) {
1849 const MachineFunction *MF = MI.getParent()->getParent();
1850 const char *AsmStr = MI.getOperand(0).getSymbolName();
1851 return getInlineAsmLength(AsmStr, MF->getTarget().getMCAsmInfo());
1852 }
1853 else if (MI.getOpcode() == SystemZ::PATCHPOINT)
1855 else if (MI.getOpcode() == SystemZ::STACKMAP)
1856 return MI.getOperand(1).getImm();
1857 else if (MI.getOpcode() == SystemZ::FENTRY_CALL)
1858 return 6;
1859 if (MI.getOpcode() == TargetOpcode::PATCHABLE_FUNCTION_ENTER)
1860 return 18;
1861 if (MI.getOpcode() == TargetOpcode::PATCHABLE_RET)
1862 return 18 + (MI.getOperand(0).getImm() == SystemZ::CondReturn ? 4 : 0);
1863 if (MI.getOpcode() == TargetOpcode::BUNDLE)
1864 return getInstBundleSize(MI);
1865 if (MI.getOpcode() == SystemZ::LOAD_TLS_BLOCK_ADDR)
1866 // ear (4), sllg (6), ear (4) = 14 bytes
1867 return 14;
1868 if (MI.getOpcode() == SystemZ::LOAD_GLOBAL_STACKGUARD_ADDR)
1869 // Both larl and lgrl are 6 bytes long.
1870 return 6;
1871
1872 return MI.getDesc().getSize();
1873}
1874
1877 switch (MI.getOpcode()) {
1878 case SystemZ::BR:
1879 case SystemZ::BI:
1880 case SystemZ::J:
1881 case SystemZ::JG:
1883 SystemZ::CCMASK_ANY, &MI.getOperand(0));
1884
1885 case SystemZ::BRC:
1886 case SystemZ::BRCL:
1887 return SystemZII::Branch(SystemZII::BranchNormal, MI.getOperand(0).getImm(),
1888 MI.getOperand(1).getImm(), &MI.getOperand(2));
1889
1890 case SystemZ::BRCT:
1891 case SystemZ::BRCTH:
1893 SystemZ::CCMASK_CMP_NE, &MI.getOperand(2));
1894
1895 case SystemZ::BRCTG:
1897 SystemZ::CCMASK_CMP_NE, &MI.getOperand(2));
1898
1899 case SystemZ::CIJ:
1900 case SystemZ::CRJ:
1902 MI.getOperand(2).getImm(), &MI.getOperand(3));
1903
1904 case SystemZ::CLIJ:
1905 case SystemZ::CLRJ:
1907 MI.getOperand(2).getImm(), &MI.getOperand(3));
1908
1909 case SystemZ::CGIJ:
1910 case SystemZ::CGRJ:
1912 MI.getOperand(2).getImm(), &MI.getOperand(3));
1913
1914 case SystemZ::CLGIJ:
1915 case SystemZ::CLGRJ:
1917 MI.getOperand(2).getImm(), &MI.getOperand(3));
1918
1919 case SystemZ::INLINEASM_BR:
1920 // Don't try to analyze asm goto, so pass nullptr as branch target argument.
1921 return SystemZII::Branch(SystemZII::AsmGoto, 0, 0, nullptr);
1922
1923 default:
1924 llvm_unreachable("Unrecognized branch opcode");
1925 }
1926}
1927
1929 unsigned &LoadOpcode,
1930 unsigned &StoreOpcode) const {
1931 if (RC == &SystemZ::GR32BitRegClass || RC == &SystemZ::ADDR32BitRegClass) {
1932 LoadOpcode = SystemZ::L;
1933 StoreOpcode = SystemZ::ST;
1934 } else if (RC == &SystemZ::GRH32BitRegClass) {
1935 LoadOpcode = SystemZ::LFH;
1936 StoreOpcode = SystemZ::STFH;
1937 } else if (RC == &SystemZ::GRX32BitRegClass) {
1938 LoadOpcode = SystemZ::LMux;
1939 StoreOpcode = SystemZ::STMux;
1940 } else if (RC == &SystemZ::GR64BitRegClass ||
1941 RC == &SystemZ::ADDR64BitRegClass) {
1942 LoadOpcode = SystemZ::LG;
1943 StoreOpcode = SystemZ::STG;
1944 } else if (RC == &SystemZ::GR128BitRegClass ||
1945 RC == &SystemZ::ADDR128BitRegClass) {
1946 LoadOpcode = SystemZ::L128;
1947 StoreOpcode = SystemZ::ST128;
1948 } else if (RC == &SystemZ::FP16BitRegClass && !STI.hasVector()) {
1949 LoadOpcode = SystemZ::LE16;
1950 StoreOpcode = SystemZ::STE16;
1951 } else if (RC == &SystemZ::FP32BitRegClass) {
1952 LoadOpcode = SystemZ::LE;
1953 StoreOpcode = SystemZ::STE;
1954 } else if (RC == &SystemZ::FP64BitRegClass) {
1955 LoadOpcode = SystemZ::LD;
1956 StoreOpcode = SystemZ::STD;
1957 } else if (RC == &SystemZ::FP128BitRegClass) {
1958 LoadOpcode = SystemZ::LX;
1959 StoreOpcode = SystemZ::STX;
1960 } else if (RC == &SystemZ::FP16BitRegClass ||
1961 RC == &SystemZ::VR16BitRegClass) {
1962 LoadOpcode = SystemZ::VL16;
1963 StoreOpcode = SystemZ::VST16;
1964 } else if (RC == &SystemZ::VR32BitRegClass) {
1965 LoadOpcode = SystemZ::VL32;
1966 StoreOpcode = SystemZ::VST32;
1967 } else if (RC == &SystemZ::VR64BitRegClass) {
1968 LoadOpcode = SystemZ::VL64;
1969 StoreOpcode = SystemZ::VST64;
1970 } else if (RC == &SystemZ::VF128BitRegClass ||
1971 RC == &SystemZ::VR128BitRegClass) {
1972 LoadOpcode = SystemZ::VL;
1973 StoreOpcode = SystemZ::VST;
1974 } else
1975 llvm_unreachable("Unsupported regclass to load or store");
1976}
1977
1979 int64_t Offset,
1980 const MachineInstr *MI) const {
1981 const MCInstrDesc &MCID = get(Opcode);
1982 int64_t Offset2 = (MCID.TSFlags & SystemZII::Is128Bit ? Offset + 8 : Offset);
1983 if (isUInt<12>(Offset) && isUInt<12>(Offset2)) {
1984 // Get the instruction to use for unsigned 12-bit displacements.
1985 int Disp12Opcode = SystemZ::getDisp12Opcode(Opcode);
1986 if (Disp12Opcode >= 0)
1987 return Disp12Opcode;
1988
1989 // All address-related instructions can use unsigned 12-bit
1990 // displacements.
1991 return Opcode;
1992 }
1993 if (isInt<20>(Offset) && isInt<20>(Offset2)) {
1994 // Get the instruction to use for signed 20-bit displacements.
1995 int Disp20Opcode = SystemZ::getDisp20Opcode(Opcode);
1996 if (Disp20Opcode >= 0)
1997 return Disp20Opcode;
1998
1999 // Check whether Opcode allows signed 20-bit displacements.
2000 if (MCID.TSFlags & SystemZII::Has20BitOffset)
2001 return Opcode;
2002
2003 // If a VR32/VR64 reg ended up in an FP register, use the FP opcode.
2004 if (MI && MI->getOperand(0).isReg()) {
2005 Register Reg = MI->getOperand(0).getReg();
2006 if (Reg.isPhysical() && SystemZMC::getFirstReg(Reg) < 16) {
2007 switch (Opcode) {
2008 case SystemZ::VL32:
2009 return SystemZ::LEY;
2010 case SystemZ::VST32:
2011 return SystemZ::STEY;
2012 case SystemZ::VL64:
2013 return SystemZ::LDY;
2014 case SystemZ::VST64:
2015 return SystemZ::STDY;
2016 default: break;
2017 }
2018 }
2019 }
2020 }
2021 return 0;
2022}
2023
2025 const MCInstrDesc &MCID = get(Opcode);
2026 if (MCID.TSFlags & SystemZII::Has20BitOffset)
2027 return SystemZ::getDisp12Opcode(Opcode) >= 0;
2028 return SystemZ::getDisp20Opcode(Opcode) >= 0;
2029}
2030
2031unsigned SystemZInstrInfo::getLoadAndTest(unsigned Opcode) const {
2032 switch (Opcode) {
2033 case SystemZ::L: return SystemZ::LT;
2034 case SystemZ::LY: return SystemZ::LT;
2035 case SystemZ::LG: return SystemZ::LTG;
2036 case SystemZ::LGF: return SystemZ::LTGF;
2037 case SystemZ::LR: return SystemZ::LTR;
2038 case SystemZ::LGFR: return SystemZ::LTGFR;
2039 case SystemZ::LGR: return SystemZ::LTGR;
2040 case SystemZ::LCDFR: return SystemZ::LCDBR;
2041 case SystemZ::LPDFR: return SystemZ::LPDBR;
2042 case SystemZ::LNDFR: return SystemZ::LNDBR;
2043 case SystemZ::LCDFR_32: return SystemZ::LCEBR;
2044 case SystemZ::LPDFR_32: return SystemZ::LPEBR;
2045 case SystemZ::LNDFR_32: return SystemZ::LNEBR;
2046 // On zEC12 we prefer to use RISBGN. But if there is a chance to
2047 // actually use the condition code, we may turn it back into RISGB.
2048 // Note that RISBG is not really a "load-and-test" instruction,
2049 // but sets the same condition code values, so is OK to use here.
2050 case SystemZ::RISBGN: return SystemZ::RISBG;
2051 default: return 0;
2052 }
2053}
2054
2055bool SystemZInstrInfo::isRxSBGMask(uint64_t Mask, unsigned BitSize,
2056 unsigned &Start, unsigned &End) const {
2057 // Reject trivial all-zero masks.
2058 Mask &= allOnes(BitSize);
2059 if (Mask == 0)
2060 return false;
2061
2062 // Handle the 1+0+ or 0+1+0* cases. Start then specifies the index of
2063 // the msb and End specifies the index of the lsb.
2064 unsigned LSB, Length;
2065 if (isShiftedMask_64(Mask, LSB, Length)) {
2066 Start = 63 - (LSB + Length - 1);
2067 End = 63 - LSB;
2068 return true;
2069 }
2070
2071 // Handle the wrap-around 1+0+1+ cases. Start then specifies the msb
2072 // of the low 1s and End specifies the lsb of the high 1s.
2073 if (isShiftedMask_64(Mask ^ allOnes(BitSize), LSB, Length)) {
2074 assert(LSB > 0 && "Bottom bit must be set");
2075 assert(LSB + Length < BitSize && "Top bit must be set");
2076 Start = 63 - (LSB - 1);
2077 End = 63 - (LSB + Length);
2078 return true;
2079 }
2080
2081 return false;
2082}
2083
2084unsigned SystemZInstrInfo::getFusedCompare(unsigned Opcode,
2086 const MachineInstr *MI) const {
2087 switch (Opcode) {
2088 case SystemZ::CHI:
2089 case SystemZ::CGHI:
2090 if (!(MI && isInt<8>(MI->getOperand(1).getImm())))
2091 return 0;
2092 break;
2093 case SystemZ::CLFI:
2094 case SystemZ::CLGFI:
2095 if (!(MI && isUInt<8>(MI->getOperand(1).getImm())))
2096 return 0;
2097 break;
2098 case SystemZ::CL:
2099 case SystemZ::CLG:
2100 if (!STI.hasMiscellaneousExtensions())
2101 return 0;
2102 if (!(MI && MI->getOperand(3).getReg() == 0))
2103 return 0;
2104 break;
2105 }
2106 switch (Type) {
2108 switch (Opcode) {
2109 case SystemZ::CR:
2110 return SystemZ::CRJ;
2111 case SystemZ::CGR:
2112 return SystemZ::CGRJ;
2113 case SystemZ::CHI:
2114 return SystemZ::CIJ;
2115 case SystemZ::CGHI:
2116 return SystemZ::CGIJ;
2117 case SystemZ::CLR:
2118 return SystemZ::CLRJ;
2119 case SystemZ::CLGR:
2120 return SystemZ::CLGRJ;
2121 case SystemZ::CLFI:
2122 return SystemZ::CLIJ;
2123 case SystemZ::CLGFI:
2124 return SystemZ::CLGIJ;
2125 default:
2126 return 0;
2127 }
2129 switch (Opcode) {
2130 case SystemZ::CR:
2131 return SystemZ::CRBReturn;
2132 case SystemZ::CGR:
2133 return SystemZ::CGRBReturn;
2134 case SystemZ::CHI:
2135 return SystemZ::CIBReturn;
2136 case SystemZ::CGHI:
2137 return SystemZ::CGIBReturn;
2138 case SystemZ::CLR:
2139 return SystemZ::CLRBReturn;
2140 case SystemZ::CLGR:
2141 return SystemZ::CLGRBReturn;
2142 case SystemZ::CLFI:
2143 return SystemZ::CLIBReturn;
2144 case SystemZ::CLGFI:
2145 return SystemZ::CLGIBReturn;
2146 default:
2147 return 0;
2148 }
2150 switch (Opcode) {
2151 case SystemZ::CR:
2152 return SystemZ::CRBCall;
2153 case SystemZ::CGR:
2154 return SystemZ::CGRBCall;
2155 case SystemZ::CHI:
2156 return SystemZ::CIBCall;
2157 case SystemZ::CGHI:
2158 return SystemZ::CGIBCall;
2159 case SystemZ::CLR:
2160 return SystemZ::CLRBCall;
2161 case SystemZ::CLGR:
2162 return SystemZ::CLGRBCall;
2163 case SystemZ::CLFI:
2164 return SystemZ::CLIBCall;
2165 case SystemZ::CLGFI:
2166 return SystemZ::CLGIBCall;
2167 default:
2168 return 0;
2169 }
2171 switch (Opcode) {
2172 case SystemZ::CR:
2173 return SystemZ::CRT;
2174 case SystemZ::CGR:
2175 return SystemZ::CGRT;
2176 case SystemZ::CHI:
2177 return SystemZ::CIT;
2178 case SystemZ::CGHI:
2179 return SystemZ::CGIT;
2180 case SystemZ::CLR:
2181 return SystemZ::CLRT;
2182 case SystemZ::CLGR:
2183 return SystemZ::CLGRT;
2184 case SystemZ::CLFI:
2185 return SystemZ::CLFIT;
2186 case SystemZ::CLGFI:
2187 return SystemZ::CLGIT;
2188 case SystemZ::CL:
2189 return SystemZ::CLT;
2190 case SystemZ::CLG:
2191 return SystemZ::CLGT;
2192 default:
2193 return 0;
2194 }
2195 }
2196 return 0;
2197}
2198
2200 // If we during isel used a load-and-test as a compare with 0, the
2201 // def operand is dead.
2202 return (MI.getOpcode() == SystemZ::LTEBR ||
2203 MI.getOpcode() == SystemZ::LTDBR ||
2204 MI.getOpcode() == SystemZ::LTXBR) &&
2205 MI.getOperand(0).isDead();
2206}
2207
2209 if (isLoadAndTestAsCmp(Compare))
2210 return true;
2211 return Compare.isCompare() && Compare.getNumExplicitOperands() == 2 &&
2212 Compare.getOperand(1).isImm() && Compare.getOperand(1).getImm() == 0;
2213}
2214
2217 assert(isCompareZero(Compare) && "Expected a compare with 0.");
2218 return Compare.getOperand(isLoadAndTestAsCmp(Compare) ? 1 : 0).getReg();
2219}
2220
2223 assert(MBBI->isCompare() && MBBI->getOperand(0).isReg() &&
2224 MBBI->getOperand(1).isReg() && !MBBI->mayLoad() &&
2225 "Not a compare reg/reg.");
2226
2227 MachineBasicBlock *MBB = MBBI->getParent();
2228 bool CCLive = true;
2230 for (MachineInstr &MI : llvm::make_range(std::next(MBBI), MBB->end())) {
2231 if (MI.readsRegister(SystemZ::CC, /*TRI=*/nullptr)) {
2232 unsigned Flags = MI.getDesc().TSFlags;
2233 if ((Flags & SystemZII::CCMaskFirst) || (Flags & SystemZII::CCMaskLast))
2234 CCUsers.push_back(&MI);
2235 else
2236 return false;
2237 }
2238 if (MI.definesRegister(SystemZ::CC, /*TRI=*/nullptr)) {
2239 CCLive = false;
2240 break;
2241 }
2242 }
2243 if (CCLive) {
2244 LiveRegUnits LiveRegs(*MBB->getParent()->getSubtarget().getRegisterInfo());
2245 LiveRegs.addLiveOuts(*MBB);
2246 if (!LiveRegs.available(SystemZ::CC))
2247 return false;
2248 }
2249
2250 // Update all CC users.
2251 for (unsigned Idx = 0; Idx < CCUsers.size(); ++Idx) {
2252 unsigned Flags = CCUsers[Idx]->getDesc().TSFlags;
2253 unsigned FirstOpNum = ((Flags & SystemZII::CCMaskFirst) ?
2254 0 : CCUsers[Idx]->getNumExplicitOperands() - 2);
2255 MachineOperand &CCMaskMO = CCUsers[Idx]->getOperand(FirstOpNum + 1);
2256 unsigned NewCCMask = SystemZ::reverseCCMask(CCMaskMO.getImm());
2257 CCMaskMO.setImm(NewCCMask);
2258 }
2259
2260 return true;
2261}
2262
2263unsigned SystemZ::reverseCCMask(unsigned CCMask) {
2264 return ((CCMask & SystemZ::CCMASK_CMP_EQ) |
2267 (CCMask & SystemZ::CCMASK_CMP_UO));
2268}
2269
2271 MachineFunction &MF = *MBB->getParent();
2272 MachineBasicBlock *NewMBB = MF.CreateMachineBasicBlock(MBB->getBasicBlock());
2273 MF.insert(std::next(MachineFunction::iterator(MBB)), NewMBB);
2274 return NewMBB;
2275}
2276
2285
2293
2294unsigned SystemZInstrInfo::getLoadAndTrap(unsigned Opcode) const {
2295 if (!STI.hasLoadAndTrap())
2296 return 0;
2297 switch (Opcode) {
2298 case SystemZ::L:
2299 case SystemZ::LY:
2300 return SystemZ::LAT;
2301 case SystemZ::LG:
2302 return SystemZ::LGAT;
2303 case SystemZ::LFH:
2304 return SystemZ::LFHAT;
2305 case SystemZ::LLGF:
2306 return SystemZ::LLGFAT;
2307 case SystemZ::LLGT:
2308 return SystemZ::LLGTAT;
2309 }
2310 return 0;
2311}
2312
2315 unsigned Reg, uint64_t Value) const {
2316 DebugLoc DL = MBBI != MBB.end() ? MBBI->getDebugLoc() : DebugLoc();
2317 unsigned Opcode = 0;
2318 if (isInt<16>(Value))
2319 Opcode = SystemZ::LGHI;
2320 else if (SystemZ::isImmLL(Value))
2321 Opcode = SystemZ::LLILL;
2322 else if (SystemZ::isImmLH(Value)) {
2323 Opcode = SystemZ::LLILH;
2324 Value >>= 16;
2325 }
2326 else if (isInt<32>(Value))
2327 Opcode = SystemZ::LGFI;
2328 if (Opcode) {
2329 BuildMI(MBB, MBBI, DL, get(Opcode), Reg).addImm(Value);
2330 return;
2331 }
2332
2333 MachineRegisterInfo &MRI = MBB.getParent()->getRegInfo();
2334 assert (MRI.isSSA() && "Huge values only handled before reg-alloc .");
2335 Register Reg0 = MRI.createVirtualRegister(&SystemZ::GR64BitRegClass);
2336 Register Reg1 = MRI.createVirtualRegister(&SystemZ::GR64BitRegClass);
2337 BuildMI(MBB, MBBI, DL, get(SystemZ::IMPLICIT_DEF), Reg0);
2338 BuildMI(MBB, MBBI, DL, get(SystemZ::IIHF64), Reg1)
2339 .addReg(Reg0).addImm(Value >> 32);
2340 BuildMI(MBB, MBBI, DL, get(SystemZ::IILF64), Reg)
2341 .addReg(Reg1).addImm(Value & ((uint64_t(1) << 32) - 1));
2342}
2343
2345 StringRef &ErrInfo) const {
2346 const MCInstrDesc &MCID = MI.getDesc();
2347 for (unsigned I = 0, E = MI.getNumOperands(); I != E; ++I) {
2348 if (I >= MCID.getNumOperands())
2349 break;
2350 const MachineOperand &Op = MI.getOperand(I);
2351 const MCOperandInfo &MCOI = MCID.operands()[I];
2352 // Addressing modes have register and immediate operands. Op should be a
2353 // register (or frame index) operand if MCOI.RegClass contains a valid
2354 // register class, or an immediate otherwise.
2355 if (MCOI.OperandType == MCOI::OPERAND_MEMORY &&
2356 ((MCOI.RegClass != -1 && !Op.isReg() && !Op.isFI()) ||
2357 (MCOI.RegClass == -1 && !Op.isImm()))) {
2358 ErrInfo = "Addressing mode operands corrupt!";
2359 return false;
2360 }
2361 }
2362
2363 return true;
2364}
2365
2368 const MachineInstr &MIb) const {
2369
2370 if (!MIa.hasOneMemOperand() || !MIb.hasOneMemOperand())
2371 return false;
2372
2373 // If mem-operands show that the same address Value is used by both
2374 // instructions, check for non-overlapping offsets and widths. Not
2375 // sure if a register based analysis would be an improvement...
2376
2377 MachineMemOperand *MMOa = *MIa.memoperands_begin();
2378 MachineMemOperand *MMOb = *MIb.memoperands_begin();
2379 const Value *VALa = MMOa->getValue();
2380 const Value *VALb = MMOb->getValue();
2381 bool SameVal = (VALa && VALb && (VALa == VALb));
2382 if (!SameVal) {
2383 const PseudoSourceValue *PSVa = MMOa->getPseudoValue();
2384 const PseudoSourceValue *PSVb = MMOb->getPseudoValue();
2385 if (PSVa && PSVb && (PSVa == PSVb))
2386 SameVal = true;
2387 }
2388 if (SameVal) {
2389 int OffsetA = MMOa->getOffset(), OffsetB = MMOb->getOffset();
2390 LocationSize WidthA = MMOa->getSize(), WidthB = MMOb->getSize();
2391 int LowOffset = OffsetA < OffsetB ? OffsetA : OffsetB;
2392 int HighOffset = OffsetA < OffsetB ? OffsetB : OffsetA;
2393 LocationSize LowWidth = (LowOffset == OffsetA) ? WidthA : WidthB;
2394 if (LowWidth.hasValue() &&
2395 LowOffset + (int)LowWidth.getValue() <= HighOffset)
2396 return true;
2397 }
2398
2399 return false;
2400}
2401
2403 const Register Reg,
2404 int64_t &ImmVal) const {
2405
2406 if (MI.getOpcode() == SystemZ::VGBM && Reg == MI.getOperand(0).getReg()) {
2407 ImmVal = MI.getOperand(1).getImm();
2408 // TODO: Handle non-0 values
2409 return ImmVal == 0;
2410 }
2411
2412 return false;
2413}
2414
2415std::optional<DestSourcePair>
2417 // if MI is a simple single-register copy operation, return operand pair
2418 if (MI.isMoveReg())
2419 return DestSourcePair(MI.getOperand(0), MI.getOperand(1));
2420
2421 return std::nullopt;
2422}
2423
2424std::pair<unsigned, unsigned>
2426 return std::make_pair(TF, 0u);
2427}
2428
2431 using namespace SystemZII;
2432
2433 static const std::pair<unsigned, const char *> TargetFlags[] = {
2434 {MO_GOT, "systemz-got"},
2435 {MO_INDNTPOFF, "systemz-indntpoff"},
2436 {MO_ADA_DATA_SYMBOL_ADDR, "systemz-ada-datasymboladdr"},
2437 {MO_ADA_INDIRECT_FUNC_DESC, "systemz-ada-indirectfuncdesc"},
2438 {MO_ADA_DIRECT_FUNC_DESC, "systemz-ada-directfuncdesc"}};
2439 return ArrayRef(TargetFlags);
2440}
2441
2443 const MachineBasicBlock *MBB,
2444 const MachineFunction &MF) const {
2446 return true;
2447 return MI.getOpcode() == SystemZ::FENCE ||
2448 MI.getOpcode() == TargetOpcode::PATCHABLE_FUNCTION_ENTER;
2449}
2450
2452 return MCInstBuilder(SystemZ::NOPR).addReg(0);
2453}
MachineInstrBuilder & UseMI
MachineInstrBuilder MachineInstrBuilder & DefMI
unsigned RegSize
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
unsigned Imm
unsigned uint64_t
MachineBasicBlock & MBB
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
MachineBasicBlock MachineBasicBlock::iterator MBBI
DXIL Forward Handle Accesses
IRTranslator LLVM IR MI
Module.h This file contains the declarations for the Module class.
const size_t AbstractManglingParser< Derived, Alloc >::NumOps
const AbstractManglingParser< Derived, Alloc >::OperatorInfo AbstractManglingParser< Derived, Alloc >::Ops[]
A set of register units.
#define I(x, y, z)
Definition MD5.cpp:57
Register Reg
Register const TargetRegisterInfo * TRI
Promote Memory to Register
Definition Mem2Reg.cpp:110
static MCRegister getReg(const MCDisassembler *D, unsigned RC, unsigned RegNo)
const SmallVectorImpl< MachineOperand > MachineBasicBlock * TBB
const SmallVectorImpl< MachineOperand > & Cond
static bool contains(SmallPtrSetImpl< ConstantExpr * > &Cache, ConstantExpr *Expr, Constant *C)
Definition Value.cpp:484
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
static bool isSimpleBD12Move(const MachineInstr *MI, unsigned Flag)
static void transferDeadCC(MachineInstr *OldMI, MachineInstr *NewMI)
static void transferMIFlag(MachineInstr *OldMI, MachineInstr *NewMI, MachineInstr::MIFlag Flag)
static int isSimpleMove(const MachineInstr &MI, int &FrameIndex, unsigned Flag)
static LogicOp interpretAndImmediate(unsigned Opcode)
static uint64_t allOnes(unsigned int Count)
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
A debug info location.
Definition DebugLoc.h:126
Module * getParent()
Get the module that this global value is contained inside of...
SlotIndexes * getSlotIndexes() const
VNInfo::Allocator & getVNInfoAllocator()
LiveRange & getRegUnit(MCRegUnit Unit)
Return the live range for register unit Unit.
LLVM_ABI void removePhysRegDefAt(MCRegister Reg, SlotIndex Pos)
Remove value numbers and related live segments starting at position Pos that are part of any liverang...
SlotIndex ReplaceMachineInstrInMaps(MachineInstr &MI, MachineInstr &NewMI)
This class represents the liveness of a register, stack slot, etc.
bool liveAt(SlotIndex index) const
LLVM_ABI VNInfo * createDeadDef(SlotIndex Def, VNInfo::Allocator &VNIAlloc)
createDeadDef - Make sure the range has a value defined at Def.
A set of register units used to track register liveness.
bool hasValue() const
TypeSize getValue() const
MCInstBuilder & addReg(MCRegister Reg)
Add a new register operand.
Instances of this class represent a single low-level machine instruction.
Definition MCInst.h:188
Describe properties that are true of each instruction in the target description file.
This holds information about one operand of a machine instruction, indicating the register class for ...
Definition MCInstrDesc.h:88
Wrapper class representing physical registers. Should be passed by value.
Definition MCRegister.h:41
static MCRegister from(unsigned Val)
Check the provided unsigned value is a valid MCRegister.
Definition MCRegister.h:77
LLVM_ABI void transferSuccessorsAndUpdatePHIs(MachineBasicBlock *FromMBB)
Transfers all the successors, as in transferSuccessors, and update PHI operands in the successor bloc...
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
void splice(iterator Where, MachineBasicBlock *Other, iterator From)
Take an instruction from MBB 'Other' at the position From, and insert it into this MBB right before '...
MachineInstrBundleIterator< MachineInstr > iterator
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted.
uint64_t getMaxCallFrameSize() const
Return the maximum size of a call frame that must be allocated for an outgoing function call.
int64_t getObjectSize(int ObjectIdx) const
Return the size of the specified object.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
Function & getFunction()
Return the LLVM function that this machine code represents.
BasicBlockListType::iterator iterator
MachineBasicBlock * CreateMachineBasicBlock(const BasicBlock *BB=nullptr, std::optional< UniqueBBID > BBID=std::nullopt)
CreateMachineInstr - Allocate a new MachineInstr.
void insert(iterator MBBI, MachineBasicBlock *MBB)
const TargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
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 & addFrameIndex(int Idx) const
const MachineInstrBuilder & addRegMask(const uint32_t *Mask) const
const MachineInstrBuilder & addMBB(MachineBasicBlock *MBB, unsigned TargetFlags=0) const
const MachineInstrBuilder & addDef(Register RegNo, RegState Flags={}, unsigned SubReg=0) const
Add a virtual register definition operand.
const MachineInstrBuilder & addMemOperand(MachineMemOperand *MMO) const
Representation of each machine instruction.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
bool getFlag(MIFlag Flag) const
Return whether an MI flag is set.
mop_range operands()
bool registerDefIsDead(Register Reg, const TargetRegisterInfo *TRI) const
Returns true if the register is dead in this machine instruction.
bool definesRegister(Register Reg, const TargetRegisterInfo *TRI) const
Return true if the MachineInstr fully defines the specified register.
LLVM_ABI void setDesc(const MCInstrDesc &TID)
Replace the instruction descriptor (thus opcode) of the current instruction with a new one.
bool hasOneMemOperand() const
Return true if this instruction has exactly one MachineMemOperand.
mmo_iterator memoperands_begin() const
Access to memory operands of the instruction.
void setFlag(MIFlag Flag)
Set a MI flag.
const MachineOperand & getOperand(unsigned i) const
MachineOperand * findRegisterDefOperand(Register Reg, const TargetRegisterInfo *TRI, bool isDead=false, bool Overlap=false)
Wrapper for findRegisterDefOperandIdx, it returns a pointer to the MachineOperand rather than an inde...
LLVM_ABI bool addRegisterDead(Register Reg, const TargetRegisterInfo *RegInfo, bool AddIfNotFound=false)
We have determined MI defined a register without a use.
A description of a memory reference used in the backend.
LocationSize getSize() const
Return the size in bytes of the memory reference.
const PseudoSourceValue * getPseudoValue() const
bool isAtomic() const
Returns true if this operation has an atomic ordering requirement of unordered or higher,...
const Value * getValue() const
Return the base address of the memory access.
int64_t getOffset() const
For normal values, this is a byte offset added to the base address.
MachineOperand class - Representation of each machine instruction operand.
void setImm(int64_t immVal)
int64_t getImm() const
void setIsDead(bool Val=true)
LLVM_ABI void setReg(Register Reg)
Change the register this operand corresponds to.
void setIsKill(bool Val=true)
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 hasOneNonDBGUse(Register RegNo) const
hasOneNonDBGUse - Return true if there is exactly one non-Debug use of the specified register.
const TargetRegisterClass * getRegClass(Register Reg) const
Return the register class of the specified virtual register.
bool use_nodbg_empty(Register RegNo) const
use_nodbg_empty - Return true if there are no non-Debug instructions using the specified register.
LLVM_ABI Register createVirtualRegister(const TargetRegisterClass *RegClass, StringRef Name="")
createVirtualRegister - Create and return a new virtual register in the function with the specified r...
LLVM_ABI void setRegClass(Register Reg, const TargetRegisterClass *RC)
setRegClass - Set the register class of the specified virtual register.
LLVM_ABI const TargetRegisterClass * constrainRegClass(Register Reg, const TargetRegisterClass *RC, unsigned MinNumRegs=0)
constrainRegClass - Constrain the register class of the specified virtual register to be a common sub...
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:68
MI-level patchpoint operands.
Definition StackMaps.h:77
uint32_t getNumPatchBytes() const
Return the number of patchable bytes the given patchpoint should emit.
Definition StackMaps.h:105
Special value supplied for machine level alias analysis.
Wrapper class representing virtual and physical registers.
Definition Register.h:20
MCRegister asMCReg() const
Utility to check-convert this value to a MCRegister.
Definition Register.h:107
constexpr bool isVirtual() const
Return true if the specified register number is in the virtual register namespace.
Definition Register.h:79
SlotIndex - An opaque wrapper around machine indexes.
Definition SlotIndexes.h:66
SlotIndex getRegSlot(bool EC=false) const
Returns the register use/def slot in the current instruction for a normal or early-clobber def.
SlotIndex getInstructionIndex(const MachineInstr &MI, bool IgnoreBundle=false) const
Returns the base index for the given instruction.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
constexpr bool empty() const
Check if the string is empty.
Definition StringRef.h:141
MachineInstr * convertToThreeAddress(MachineInstr &MI, LiveIntervals *LIS) const override
unsigned getLoadAndTrap(unsigned Opcode) const
void storeRegToStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, Register SrcReg, bool isKill, int FrameIndex, const TargetRegisterClass *RC, Register VReg, MachineInstr::MIFlag Flags=MachineInstr::NoFlags) const override
Register isLoadFromStackSlotPostFE(const MachineInstr &MI, int &FrameIndex) const override
unsigned insertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB, MachineBasicBlock *FBB, ArrayRef< MachineOperand > Cond, const DebugLoc &DL, int *BytesAdded=nullptr) const override
bool isProfitableToIfCvt(MachineBasicBlock &MBB, unsigned NumCycles, unsigned ExtraPredCycles, BranchProbability Probability) const override
unsigned getLoadAndTest(unsigned Opcode) const
MCInst getNop() const override
bool canInsertSelect(const MachineBasicBlock &, ArrayRef< MachineOperand > Cond, Register, Register, Register, SelectExpansion &) const override
bool isPredicable(const MachineInstr &MI) const override
Register isStoreToStackSlotPostFE(const MachineInstr &MI, int &FrameIndex) const override
bool isSchedulingBoundary(const MachineInstr &MI, const MachineBasicBlock *MBB, const MachineFunction &MF) const override
bool isStackSlotCopy(const MachineInstr &MI, int &DestFrameIndex, int &SrcFrameIndex) const override
unsigned getOpcodeForOffset(unsigned Opcode, int64_t Offset, const MachineInstr *MI=nullptr) const
unsigned getInstSizeInBytes(const MachineInstr &MI) const override
unsigned removeBranch(MachineBasicBlock &MBB, int *BytesRemoved=nullptr) const override
Register isStoreToStackSlot(const MachineInstr &MI, int &FrameIndex) const override
bool getConstValDefinedInReg(const MachineInstr &MI, const Register Reg, int64_t &ImmVal) const override
bool isAssociativeAndCommutative(const MachineInstr &Inst, bool Invert) const override
MachineInstr * foldMemoryOperandImpl(MachineFunction &MF, MachineInstr &MI, ArrayRef< unsigned > Ops, int FrameIndex, MachineInstr *&CopyMI, LiveIntervals *LIS=nullptr, VirtRegMap *VRM=nullptr) const override
bool hasDisplacementPairInsn(unsigned Opcode) const
MachineInstr * commuteInstructionImpl(MachineInstr &MI, bool NewMI, unsigned CommuteOpIdx1, unsigned CommuteOpIdx2) const override
Commutes the operands in the given instruction by changing the operands order and/or changing the ins...
void loadRegFromStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, Register DestReg, int FrameIdx, const TargetRegisterClass *RC, Register VReg, unsigned SubReg=0, MachineInstr::MIFlag Flags=MachineInstr::NoFlags) const override
ArrayRef< std::pair< unsigned, const char * > > getSerializableDirectMachineOperandTargetFlags() const override
void insertSelect(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, const DebugLoc &DL, Register DstReg, ArrayRef< MachineOperand > Cond, Register TrueReg, Register FalseReg) const override
std::optional< unsigned > getInverseOpcode(unsigned Opcode) const override
bool isProfitableToDupForIfCvt(MachineBasicBlock &MBB, unsigned NumCycles, BranchProbability Probability) const override
bool isCompareZero(const MachineInstr &Compare) const
SystemZII::Branch getBranchInfo(const MachineInstr &MI) const
void copyPhysReg(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, const DebugLoc &DL, Register DestReg, Register SrcReg, bool KillSrc, bool RenamableDest=false, bool RenamableSrc=false) const override
bool areMemAccessesTriviallyDisjoint(const MachineInstr &MIa, const MachineInstr &MIb) const override
bool reverseBranchCondition(SmallVectorImpl< MachineOperand > &Cond) const override
bool isLoadAndTestAsCmp(const MachineInstr &MI) const
unsigned getFusedCompare(unsigned Opcode, SystemZII::FusedCompareType Type, const MachineInstr *MI=nullptr) const
bool expandPostRAPseudo(MachineInstr &MBBI) const override
bool analyzeCompare(const MachineInstr &MI, Register &SrcReg, Register &SrcReg2, int64_t &Mask, int64_t &Value) const override
bool verifyInstruction(const MachineInstr &MI, StringRef &ErrInfo) const override
void getLoadStoreOpcodes(const TargetRegisterClass *RC, unsigned &LoadOpcode, unsigned &StoreOpcode) const
bool isRxSBGMask(uint64_t Mask, unsigned BitSize, unsigned &Start, unsigned &End) const
bool foldImmediate(MachineInstr &UseMI, MachineInstr &DefMI, Register Reg, MachineRegisterInfo *MRI) const override
std::optional< DestSourcePair > isCopyInstrImpl(const MachineInstr &MI) const override
Register getCompareSourceReg(const MachineInstr &Compare) const
std::pair< unsigned, unsigned > decomposeMachineOperandsTargetFlags(unsigned TF) const override
bool prepareCompareSwapOperands(MachineBasicBlock::iterator MBBI) const
Register isLoadFromStackSlot(const MachineInstr &MI, int &FrameIndex) const override
SystemZInstrInfo(const SystemZSubtarget &STI)
bool analyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB, MachineBasicBlock *&FBB, SmallVectorImpl< MachineOperand > &Cond, bool AllowModify) const override
void loadImmediate(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, unsigned Reg, uint64_t Value) const
bool PredicateInstruction(MachineInstr &MI, ArrayRef< MachineOperand > Pred) const override
virtual bool isSchedulingBoundary(const MachineInstr &MI, const MachineBasicBlock *MBB, const MachineFunction &MF) const
Test if the given instruction should be considered a scheduling boundary.
virtual MachineInstr * commuteInstructionImpl(MachineInstr &MI, bool NewMI, unsigned OpIdx1, unsigned OpIdx2) const
This method commutes the operands of the given machine instruction MI.
const MCAsmInfo & getMCAsmInfo() const
Return target specific asm information.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
virtual const TargetRegisterInfo * getRegisterInfo() const =0
Return the target's register information.
Target - Wrapper for Target specific information.
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
LLVM Value Representation.
Definition Value.h:75
MCRegister getPhys(Register virtReg) const
returns the physical register mapped to the specified virtual register
Definition VirtRegMap.h:91
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
static unsigned getAccessSize(unsigned int Flags)
unsigned getFirstReg(unsigned Reg)
MachineBasicBlock * splitBlockBefore(MachineBasicBlock::iterator MI, MachineBasicBlock *MBB)
const unsigned CCMASK_CMP_GT
Definition SystemZ.h:39
const unsigned CCMASK_ANY
Definition SystemZ.h:33
static bool isImmLL(uint64_t Val)
Definition SystemZ.h:163
static bool isImmLH(uint64_t Val)
Definition SystemZ.h:168
MachineBasicBlock * emitBlockAfter(MachineBasicBlock *MBB)
unsigned reverseCCMask(unsigned CCMask)
const unsigned IPM_CC
Definition SystemZ.h:114
const unsigned CCMASK_CMP_EQ
Definition SystemZ.h:37
const unsigned CCMASK_ICMP
Definition SystemZ.h:49
MachineBasicBlock * splitBlockAfter(MachineBasicBlock::iterator MI, MachineBasicBlock *MBB)
int32_t getTargetMemOpcode(uint32_t Opcode)
const unsigned CCMASK_CMP_LT
Definition SystemZ.h:38
const unsigned CCMASK_CMP_NE
Definition SystemZ.h:40
bool isHighReg(unsigned int Reg)
const unsigned CCMASK_CMP_UO
Definition SystemZ.h:45
This is an optimization pass for GlobalISel generic memory operations.
auto drop_begin(T &&RangeOrContainer, size_t N=1)
Return a range covering RangeOrContainer with the first N elements excluded.
Definition STLExtras.h:316
@ Offset
Definition DWP.cpp:577
@ Length
Definition DWP.cpp:577
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
constexpr bool isInt(int64_t x)
Checks if an integer fits into the given bit width.
Definition MathExtras.h:166
RegState
Flags to represent properties of register accesses.
@ Implicit
Not emitted register (e.g. carry, or temporary result).
@ Undef
Value of the register doesn't matter.
constexpr RegState getKillRegState(bool B)
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
static const MachineInstrBuilder & addFrameReference(const MachineInstrBuilder &MIB, int FI, int Offset=0, bool mem=true)
addFrameReference - This function is used to add a reference to the base of an abstract object on the...
constexpr bool isShiftedMask_64(uint64_t Value)
Return true if the argument contains a non-empty sequence of ones with the remainder zero (64 bit ver...
Definition MathExtras.h:274
constexpr size_t range_size(R &&Range)
Returns the size of the Range, i.e., the number of elements.
Definition STLExtras.h:1710
MachineInstr * getImm(const MachineOperand &MO, const MachineRegisterInfo *MRI)
decltype(auto) get(const PointerIntPair< PointerTy, IntBits, IntType, PtrTraits, Info > &Pair)
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
Definition Error.cpp:163
constexpr bool isUInt(uint64_t x)
Checks if an unsigned integer fits into the given bit width.
Definition MathExtras.h:190
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Count
Definition InstrProf.h:145
DWARFExpression::Operation Op
ArrayRef(const T &OneElt) -> ArrayRef< T >
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
@ End
Run the machine verifier once, at the end of the pipeline.
Definition CodeGen.h:267
constexpr RegState getUndefRegState(bool B)
MCRegisterClass TargetRegisterClass
Definition FastISel.h:58
Matching combinators.