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