LLVM 20.0.0git
PPCInstrInfo.h
Go to the documentation of this file.
1//===-- PPCInstrInfo.h - PowerPC Instruction Information --------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file contains the PowerPC implementation of the TargetInstrInfo class.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_LIB_TARGET_POWERPC_PPCINSTRINFO_H
14#define LLVM_LIB_TARGET_POWERPC_PPCINSTRINFO_H
15
17#include "PPC.h"
18#include "PPCRegisterInfo.h"
19#include "llvm/ADT/SmallSet.h"
22
23#define GET_INSTRINFO_HEADER
24#include "PPCGenInstrInfo.inc"
25
26namespace llvm {
27
28// Instructions that have an immediate form might be convertible to that
29// form if the correct input is a result of a load immediate. In order to
30// know whether the transformation is special, we might need to know some
31// of the details of the two forms.
33 // Is the immediate field in the immediate form signed or unsigned?
35 // Does the immediate need to be a multiple of some value?
37 // Is R0/X0 treated specially by the original r+r instruction?
38 // If so, in which operand?
40 // Is R0/X0 treated specially by the new r+i instruction?
41 // If so, in which operand?
43 // Is the operation commutative?
45 // The operand number to check for add-immediate def.
47 // The operand number for the immediate.
49 // The opcode of the new instruction.
51 // The size of the immediate.
53 // The immediate should be truncated to N bits.
55 // Is the instruction summing the operand
57};
58
59// Information required to convert an instruction to just a materialized
60// immediate.
62 unsigned Imm : 16;
63 unsigned Is64Bit : 1;
64 unsigned SetCR : 1;
65};
66
67// Index into the OpcodesForSpill array.
86 SOK_LastOpcodeSpill // This must be last on the enum.
87};
88
89// PPC MachineCombiner patterns
91 // These are patterns matched by the PowerPC to reassociate FMA chains.
94
95 // These are patterns matched by the PowerPC to reassociate FMA and FSUB to
96 // reduce register pressure.
99
100};
101
102// Define list of load and store spill opcodes.
103#define NoInstr PPC::INSTRUCTION_LIST_END
104#define Pwr8LoadOpcodes \
105 { \
106 PPC::LWZ, PPC::LD, PPC::LFD, PPC::LFS, PPC::RESTORE_CR, \
107 PPC::RESTORE_CRBIT, PPC::LVX, PPC::LXVD2X, PPC::LXSDX, PPC::LXSSPX, \
108 PPC::SPILLTOVSR_LD, NoInstr, NoInstr, NoInstr, NoInstr, PPC::EVLDD, \
109 PPC::RESTORE_QUADWORD \
110 }
111
112#define Pwr9LoadOpcodes \
113 { \
114 PPC::LWZ, PPC::LD, PPC::LFD, PPC::LFS, PPC::RESTORE_CR, \
115 PPC::RESTORE_CRBIT, PPC::LVX, PPC::LXV, PPC::DFLOADf64, \
116 PPC::DFLOADf32, PPC::SPILLTOVSR_LD, NoInstr, NoInstr, NoInstr, \
117 NoInstr, NoInstr, PPC::RESTORE_QUADWORD \
118 }
119
120#define Pwr10LoadOpcodes \
121 { \
122 PPC::LWZ, PPC::LD, PPC::LFD, PPC::LFS, PPC::RESTORE_CR, \
123 PPC::RESTORE_CRBIT, PPC::LVX, PPC::LXV, PPC::DFLOADf64, \
124 PPC::DFLOADf32, PPC::SPILLTOVSR_LD, PPC::LXVP, PPC::RESTORE_ACC, \
125 PPC::RESTORE_UACC, NoInstr, NoInstr, PPC::RESTORE_QUADWORD \
126 }
127
128#define FutureLoadOpcodes \
129 { \
130 PPC::LWZ, PPC::LD, PPC::LFD, PPC::LFS, PPC::RESTORE_CR, \
131 PPC::RESTORE_CRBIT, PPC::LVX, PPC::LXV, PPC::DFLOADf64, \
132 PPC::DFLOADf32, PPC::SPILLTOVSR_LD, PPC::LXVP, PPC::RESTORE_ACC, \
133 PPC::RESTORE_UACC, PPC::RESTORE_WACC, NoInstr, PPC::RESTORE_QUADWORD \
134 }
135
136#define Pwr8StoreOpcodes \
137 { \
138 PPC::STW, PPC::STD, PPC::STFD, PPC::STFS, PPC::SPILL_CR, PPC::SPILL_CRBIT, \
139 PPC::STVX, PPC::STXVD2X, PPC::STXSDX, PPC::STXSSPX, \
140 PPC::SPILLTOVSR_ST, NoInstr, NoInstr, NoInstr, NoInstr, PPC::EVSTDD, \
141 PPC::SPILL_QUADWORD \
142 }
143
144#define Pwr9StoreOpcodes \
145 { \
146 PPC::STW, PPC::STD, PPC::STFD, PPC::STFS, PPC::SPILL_CR, PPC::SPILL_CRBIT, \
147 PPC::STVX, PPC::STXV, PPC::DFSTOREf64, PPC::DFSTOREf32, \
148 PPC::SPILLTOVSR_ST, NoInstr, NoInstr, NoInstr, NoInstr, NoInstr, \
149 PPC::SPILL_QUADWORD \
150 }
151
152#define Pwr10StoreOpcodes \
153 { \
154 PPC::STW, PPC::STD, PPC::STFD, PPC::STFS, PPC::SPILL_CR, PPC::SPILL_CRBIT, \
155 PPC::STVX, PPC::STXV, PPC::DFSTOREf64, PPC::DFSTOREf32, \
156 PPC::SPILLTOVSR_ST, PPC::STXVP, PPC::SPILL_ACC, PPC::SPILL_UACC, \
157 NoInstr, NoInstr, PPC::SPILL_QUADWORD \
158 }
159
160#define FutureStoreOpcodes \
161 { \
162 PPC::STW, PPC::STD, PPC::STFD, PPC::STFS, PPC::SPILL_CR, PPC::SPILL_CRBIT, \
163 PPC::STVX, PPC::STXV, PPC::DFSTOREf64, PPC::DFSTOREf32, \
164 PPC::SPILLTOVSR_ST, PPC::STXVP, PPC::SPILL_ACC, PPC::SPILL_UACC, \
165 PPC::SPILL_WACC, NoInstr, PPC::SPILL_QUADWORD \
166 }
167
168// Initialize arrays for load and store spill opcodes on supported subtargets.
169#define StoreOpcodesForSpill \
170 { Pwr8StoreOpcodes, Pwr9StoreOpcodes, Pwr10StoreOpcodes, FutureStoreOpcodes }
171#define LoadOpcodesForSpill \
172 { Pwr8LoadOpcodes, Pwr9LoadOpcodes, Pwr10LoadOpcodes, FutureLoadOpcodes }
173
174class PPCSubtarget;
176 PPCSubtarget &Subtarget;
177 const PPCRegisterInfo RI;
178 const unsigned StoreSpillOpcodesArray[4][SOK_LastOpcodeSpill] =
180 const unsigned LoadSpillOpcodesArray[4][SOK_LastOpcodeSpill] =
182
183 void StoreRegToStackSlot(MachineFunction &MF, unsigned SrcReg, bool isKill,
184 int FrameIdx, const TargetRegisterClass *RC,
185 SmallVectorImpl<MachineInstr *> &NewMIs) const;
186 void LoadRegFromStackSlot(MachineFunction &MF, const DebugLoc &DL,
187 unsigned DestReg, int FrameIdx,
188 const TargetRegisterClass *RC,
189 SmallVectorImpl<MachineInstr *> &NewMIs) const;
190
191 // Replace the instruction with single LI if possible. \p DefMI must be LI or
192 // LI8.
193 bool simplifyToLI(MachineInstr &MI, MachineInstr &DefMI,
194 unsigned OpNoForForwarding, MachineInstr **KilledDef) const;
195 // If the inst is imm-form and its register operand is produced by a ADDI, put
196 // the imm into the inst directly and remove the ADDI if possible.
197 bool transformToNewImmFormFedByAdd(MachineInstr &MI, MachineInstr &DefMI,
198 unsigned OpNoForForwarding) const;
199 // If the inst is x-form and has imm-form and one of its operand is produced
200 // by a LI, put the imm into the inst directly and remove the LI if possible.
201 bool transformToImmFormFedByLI(MachineInstr &MI, const ImmInstrInfo &III,
202 unsigned ConstantOpNo,
203 MachineInstr &DefMI) const;
204 // If the inst is x-form and has imm-form and one of its operand is produced
205 // by an add-immediate, try to transform it when possible.
206 bool transformToImmFormFedByAdd(MachineInstr &MI, const ImmInstrInfo &III,
207 unsigned ConstantOpNo, MachineInstr &DefMI,
208 bool KillDefMI) const;
209 // Try to find that, if the instruction 'MI' contains any operand that
210 // could be forwarded from some inst that feeds it. If yes, return the
211 // Def of that operand. And OpNoForForwarding is the operand index in
212 // the 'MI' for that 'Def'. If we see another use of this Def between
213 // the Def and the MI, SeenIntermediateUse becomes 'true'.
214 MachineInstr *getForwardingDefMI(MachineInstr &MI,
215 unsigned &OpNoForForwarding,
216 bool &SeenIntermediateUse) const;
217
218 // Can the user MI have it's source at index \p OpNoForForwarding
219 // forwarded from an add-immediate that feeds it?
220 bool isUseMIElgibleForForwarding(MachineInstr &MI, const ImmInstrInfo &III,
221 unsigned OpNoForForwarding) const;
222 bool isDefMIElgibleForForwarding(MachineInstr &DefMI,
223 const ImmInstrInfo &III,
224 MachineOperand *&ImmMO,
225 MachineOperand *&RegMO) const;
226 bool isImmElgibleForForwarding(const MachineOperand &ImmMO,
227 const MachineInstr &DefMI,
228 const ImmInstrInfo &III,
229 int64_t &Imm,
230 int64_t BaseImm = 0) const;
231 bool isRegElgibleForForwarding(const MachineOperand &RegMO,
232 const MachineInstr &DefMI,
233 const MachineInstr &MI, bool KillDefMI,
234 bool &IsFwdFeederRegKilled,
235 bool &SeenIntermediateUse) const;
236 unsigned getSpillTarget() const;
237 ArrayRef<unsigned> getStoreOpcodesForSpillArray() const;
238 ArrayRef<unsigned> getLoadOpcodesForSpillArray() const;
239 unsigned getSpillIndex(const TargetRegisterClass *RC) const;
240 int16_t getFMAOpIdxInfo(unsigned Opcode) const;
241 void reassociateFMA(MachineInstr &Root, unsigned Pattern,
244 DenseMap<unsigned, unsigned> &InstrIdxForVirtReg) const;
246 generateLoadForNewConst(unsigned Idx, MachineInstr *MI, Type *Ty,
247 SmallVectorImpl<MachineInstr *> &InsInstrs) const;
248 virtual void anchor();
249
250protected:
251 /// Commutes the operands in the given instruction.
252 /// The commutable operands are specified by their indices OpIdx1 and OpIdx2.
253 ///
254 /// Do not call this method for a non-commutable instruction or for
255 /// non-commutable pair of operand indices OpIdx1 and OpIdx2.
256 /// Even though the instruction is commutable, the method may still
257 /// fail to commute the operands, null pointer is returned in such cases.
258 ///
259 /// For example, we can commute rlwimi instructions, but only if the
260 /// rotate amt is zero. We also have to munge the immediates a bit.
262 unsigned OpIdx1,
263 unsigned OpIdx2) const override;
264
265public:
266 explicit PPCInstrInfo(PPCSubtarget &STI);
267
270
271 /// getRegisterInfo - TargetInstrInfo is a superset of MRegister info. As
272 /// such, whenever a client has an instance of instruction info, it should
273 /// always be able to get register info as well (through this method).
274 ///
275 const PPCRegisterInfo &getRegisterInfo() const { return RI; }
276
277 bool isXFormMemOp(unsigned Opcode) const {
278 return get(Opcode).TSFlags & PPCII::XFormMemOp;
279 }
280 bool isPrefixed(unsigned Opcode) const {
281 return get(Opcode).TSFlags & PPCII::Prefixed;
282 }
283 bool isSExt32To64(unsigned Opcode) const {
284 return get(Opcode).TSFlags & PPCII::SExt32To64;
285 }
286 bool isZExt32To64(unsigned Opcode) const {
287 return get(Opcode).TSFlags & PPCII::ZExt32To64;
288 }
289 bool isMemriOp(unsigned Opcode) const {
290 return get(Opcode).TSFlags & PPCII::MemriOp;
291 }
292
293 static bool isSameClassPhysRegCopy(unsigned Opcode) {
294 unsigned CopyOpcodes[] = {PPC::OR, PPC::OR8, PPC::FMR,
295 PPC::VOR, PPC::XXLOR, PPC::XXLORf,
296 PPC::XSCPSGNDP, PPC::MCRF, PPC::CROR,
297 PPC::EVOR, -1U};
298 for (int i = 0; CopyOpcodes[i] != -1U; i++)
299 if (Opcode == CopyOpcodes[i])
300 return true;
301 return false;
302 }
303
304 static bool hasPCRelFlag(unsigned TF) {
310 }
311
312 static bool hasGOTFlag(unsigned TF) {
317 }
318
319 static bool hasTLSFlag(unsigned TF) {
320 return TF == PPCII::MO_TLSGD_FLAG || TF == PPCII::MO_TPREL_FLAG ||
326 TF == PPCII::MO_TLSLD_LO || TF == PPCII::MO_TLS ||
328 }
329
332 const ScheduleDAG *DAG) const override;
335 const ScheduleDAG *DAG) const override;
336
337 unsigned getInstrLatency(const InstrItineraryData *ItinData,
338 const MachineInstr &MI,
339 unsigned *PredCost = nullptr) const override;
340
341 std::optional<unsigned> getOperandLatency(const InstrItineraryData *ItinData,
342 const MachineInstr &DefMI,
343 unsigned DefIdx,
344 const MachineInstr &UseMI,
345 unsigned UseIdx) const override;
346 std::optional<unsigned> getOperandLatency(const InstrItineraryData *ItinData,
347 SDNode *DefNode, unsigned DefIdx,
348 SDNode *UseNode,
349 unsigned UseIdx) const override {
350 return PPCGenInstrInfo::getOperandLatency(ItinData, DefNode, DefIdx,
351 UseNode, UseIdx);
352 }
353
354 bool hasLowDefLatency(const TargetSchedModel &SchedModel,
355 const MachineInstr &DefMI,
356 unsigned DefIdx) const override {
357 // Machine LICM should hoist all instructions in low-register-pressure
358 // situations; none are sufficiently free to justify leaving in a loop
359 // body.
360 return false;
361 }
362
363 bool useMachineCombiner() const override {
364 return true;
365 }
366
367 /// When getMachineCombinerPatterns() finds patterns, this function generates
368 /// the instructions that could replace the original code sequence
370 MachineInstr &Root, unsigned Pattern,
373 DenseMap<unsigned, unsigned> &InstrIdxForVirtReg) const override;
374
375 /// Return true when there is potentially a faster code sequence for a fma
376 /// chain ending in \p Root. All potential patterns are output in the \p
377 /// P array.
379 bool DoRegPressureReduce) const;
380
381 CombinerObjective getCombinerObjective(unsigned Pattern) const override;
382
383 /// Return true when there is potentially a faster code sequence
384 /// for an instruction chain ending in <Root>. All potential patterns are
385 /// output in the <Pattern> array.
388 bool DoRegPressureReduce) const override;
389
390 /// On PowerPC, we leverage machine combiner pass to reduce register pressure
391 /// when the register pressure is high for one BB.
392 /// Return true if register pressure for \p MBB is high and ABI is supported
393 /// to reduce register pressure. Otherwise return false.
395 const MachineBasicBlock *MBB,
396 const RegisterClassInfo *RegClassInfo) const override;
397
398 /// Fixup the placeholders we put in genAlternativeCodeSequence() for
399 /// MachineCombiner.
400 void
401 finalizeInsInstrs(MachineInstr &Root, unsigned &Pattern,
402 SmallVectorImpl<MachineInstr *> &InsInstrs) const override;
403
405 bool Invert) const override;
406
407 /// On PowerPC, we try to reassociate FMA chain which will increase
408 /// instruction size. Set extension resource length limit to 1 for edge case.
409 /// Resource Length is calculated by scaled resource usage in getCycles().
410 /// Because of the division in getCycles(), it returns different cycles due to
411 /// legacy scaled resource usage. So new resource length may be same with
412 /// legacy or 1 bigger than legacy.
413 /// We need to execlude the 1 bigger case even the resource length is not
414 /// perserved for more FMA chain reassociations on PowerPC.
415 int getExtendResourceLenLimit() const override { return 1; }
416
417 // PowerPC specific version of setSpecialOperandAttr that copies Flags to MI
418 // and clears nuw, nsw, and exact flags.
420 void setSpecialOperandAttr(MachineInstr &MI, uint32_t Flags) const;
421
423 Register &SrcReg, Register &DstReg,
424 unsigned &SubIdx) const override;
426 int &FrameIndex) const override;
427 bool isReallyTriviallyReMaterializable(const MachineInstr &MI) const override;
429 int &FrameIndex) const override;
430
431 bool findCommutedOpIndices(const MachineInstr &MI, unsigned &SrcOpIdx1,
432 unsigned &SrcOpIdx2) const override;
433
435 MachineBasicBlock::iterator MI) const override;
436
437
438 // Branch analysis.
440 MachineBasicBlock *&FBB,
442 bool AllowModify) const override;
444 int *BytesRemoved = nullptr) const override;
447 const DebugLoc &DL,
448 int *BytesAdded = nullptr) const override;
449
450 // Select analysis.
452 Register, Register, Register, int &, int &,
453 int &) const override;
455 const DebugLoc &DL, Register DstReg,
457 Register FalseReg) const override;
458
460 const DebugLoc &DL, MCRegister DestReg, MCRegister SrcReg,
461 bool KillSrc, bool RenamableDest = false,
462 bool RenamableSrc = false) const override;
463
466 bool isKill, int FrameIndex,
467 const TargetRegisterClass *RC,
468 const TargetRegisterInfo *TRI,
469 Register VReg) const override;
470
471 // Emits a register spill without updating the register class for vector
472 // registers. This ensures that when we spill a vector register the
473 // element order in the register is the same as it was in memory.
476 unsigned SrcReg, bool isKill, int FrameIndex,
477 const TargetRegisterClass *RC,
478 const TargetRegisterInfo *TRI) const;
479
482 int FrameIndex, const TargetRegisterClass *RC,
483 const TargetRegisterInfo *TRI,
484 Register VReg) const override;
485
486 // Emits a register reload without updating the register class for vector
487 // registers. This ensures that when we reload a vector register the
488 // element order in the register is the same as it was in memory.
491 unsigned DestReg, int FrameIndex,
492 const TargetRegisterClass *RC,
493 const TargetRegisterInfo *TRI) const;
494
495 unsigned getStoreOpcodeForSpill(const TargetRegisterClass *RC) const;
496
497 unsigned getLoadOpcodeForSpill(const TargetRegisterClass *RC) const;
498
499 bool
501
503 MachineRegisterInfo *MRI) const override;
504
506 Register Reg) const;
507
508 // If conversion by predication (only supported by some branch instructions).
509 // All of the profitability checks always return true; it is always
510 // profitable to use the predicated branches.
512 unsigned NumCycles, unsigned ExtraPredCycles,
513 BranchProbability Probability) const override {
514 return true;
515 }
516
518 unsigned NumT, unsigned ExtraT,
519 MachineBasicBlock &FMBB,
520 unsigned NumF, unsigned ExtraF,
521 BranchProbability Probability) const override;
522
524 BranchProbability Probability) const override {
525 return true;
526 }
527
529 MachineBasicBlock &FMBB) const override {
530 return false;
531 }
532
533 // Predication support.
534 bool isPredicated(const MachineInstr &MI) const override;
535
537 const MachineBasicBlock *MBB,
538 const MachineFunction &MF) const override;
539
541 ArrayRef<MachineOperand> Pred) const override;
542
544 ArrayRef<MachineOperand> Pred2) const override;
545
546 bool ClobbersPredicate(MachineInstr &MI, std::vector<MachineOperand> &Pred,
547 bool SkipDead) const override;
548
549 // Comparison optimization.
550
551 bool analyzeCompare(const MachineInstr &MI, Register &SrcReg,
552 Register &SrcReg2, int64_t &Mask,
553 int64_t &Value) const override;
554
555 bool optimizeCompareInstr(MachineInstr &CmpInstr, Register SrcReg,
556 Register SrcReg2, int64_t Mask, int64_t Value,
557 const MachineRegisterInfo *MRI) const override;
558
559
560 /// Return true if get the base operand, byte offset of an instruction and
561 /// the memory width. Width is the size of memory that is being
562 /// loaded/stored (e.g. 1, 2, 4, 8).
564 const MachineOperand *&BaseOp,
565 int64_t &Offset, LocationSize &Width,
566 const TargetRegisterInfo *TRI) const;
567
568 bool optimizeCmpPostRA(MachineInstr &MI) const;
569
570 /// Get the base operand and byte offset of an instruction that reads/writes
571 /// memory.
573 const MachineInstr &LdSt,
575 bool &OffsetIsScalable, LocationSize &Width,
576 const TargetRegisterInfo *TRI) const override;
577
578 /// Returns true if the two given memory operations should be scheduled
579 /// adjacent.
581 int64_t Offset1, bool OffsetIsScalable1,
583 int64_t Offset2, bool OffsetIsScalable2,
584 unsigned ClusterSize,
585 unsigned NumBytes) const override;
586
587 /// Return true if two MIs access different memory addresses and false
588 /// otherwise
589 bool
591 const MachineInstr &MIb) const override;
592
593 /// GetInstSize - Return the number of bytes of code the specified
594 /// instruction may be. This returns the maximum number of bytes.
595 ///
596 unsigned getInstSizeInBytes(const MachineInstr &MI) const override;
597
598 MCInst getNop() const override;
599
600 std::pair<unsigned, unsigned>
601 decomposeMachineOperandsTargetFlags(unsigned TF) const override;
602
605
606 // Expand VSX Memory Pseudo instruction to either a VSX or a FP instruction.
608
609 // Lower pseudo instructions after register allocation.
610 bool expandPostRAPseudo(MachineInstr &MI) const override;
611
612 const TargetRegisterClass *updatedRC(const TargetRegisterClass *RC) const;
613 static int getRecordFormOpcode(unsigned Opcode);
614
615 bool isTOCSaveMI(const MachineInstr &MI) const;
616
617 std::pair<bool, bool>
618 isSignOrZeroExtended(const unsigned Reg, const unsigned BinOpDepth,
619 const MachineRegisterInfo *MRI) const;
620
621 // Return true if the register is sign-extended from 32 to 64 bits.
622 bool isSignExtended(const unsigned Reg,
623 const MachineRegisterInfo *MRI) const {
624 return isSignOrZeroExtended(Reg, 0, MRI).first;
625 }
626
627 // Return true if the register is zero-extended from 32 to 64 bits.
628 bool isZeroExtended(const unsigned Reg,
629 const MachineRegisterInfo *MRI) const {
630 return isSignOrZeroExtended(Reg, 0, MRI).second;
631 }
634 unsigned BinOpDepth,
635 LiveVariables *LV) const;
636
638 SmallSet<Register, 4> &RegsToUpdate,
639 MachineInstr **KilledDef = nullptr) const;
640 bool foldFrameOffset(MachineInstr &MI) const;
641 bool combineRLWINM(MachineInstr &MI, MachineInstr **ToErase = nullptr) const;
642 bool isADDIInstrEligibleForFolding(MachineInstr &ADDIMI, int64_t &Imm) const;
644 bool isImmInstrEligibleForFolding(MachineInstr &MI, unsigned &BaseReg,
645 unsigned &XFormOpcode,
646 int64_t &OffsetOfImmInstr,
647 ImmInstrInfo &III) const;
648 bool isValidToBeChangedReg(MachineInstr *ADDMI, unsigned Index,
649 MachineInstr *&ADDIMI, int64_t &OffsetAddi,
650 int64_t OffsetImm) const;
651
652 void replaceInstrWithLI(MachineInstr &MI, const LoadImmediateInfo &LII) const;
653 void replaceInstrOperandWithImm(MachineInstr &MI, unsigned OpNo,
654 int64_t Imm) const;
655
656 bool instrHasImmForm(unsigned Opc, bool IsVFReg, ImmInstrInfo &III,
657 bool PostRA) const;
658
659 // In PostRA phase, try to find instruction defines \p Reg before \p MI.
660 // \p SeenIntermediate is set to true if uses between DefMI and \p MI exist.
662 bool &SeenIntermediateUse) const;
663
664 // Materialize immediate after RA.
667 const DebugLoc &DL, Register Reg,
668 int64_t Imm) const;
669
670 /// Check \p Opcode is BDNZ (Decrement CTR and branch if it is still nonzero).
671 bool isBDNZ(unsigned Opcode) const;
672
673 /// Find the hardware loop instruction used to set-up the specified loop.
674 /// On PPC, we have two instructions used to set-up the hardware loop
675 /// (MTCTRloop, MTCTR8loop) with corresponding endloop (BDNZ, BDNZ8)
676 /// instructions to indicate the end of a loop.
680
681 /// Analyze loop L, which must be a single-basic-block loop, and if the
682 /// conditions can be understood enough produce a PipelinerLoopInfo object.
683 std::unique_ptr<TargetInstrInfo::PipelinerLoopInfo>
684 analyzeLoopForPipelining(MachineBasicBlock *LoopBB) const override;
685};
686
687}
688
689#endif
unsigned const MachineRegisterInfo * MRI
MachineInstrBuilder & UseMI
MachineInstrBuilder MachineInstrBuilder & DefMI
MachineBasicBlock & MBB
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
MachineBasicBlock MachineBasicBlock::iterator MBBI
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
uint32_t Index
IRTranslator LLVM IR MI
#define I(x, y, z)
Definition: MD5.cpp:58
unsigned const TargetRegisterInfo * TRI
unsigned Reg
uint64_t IntrinsicInst * II
#define LoadOpcodesForSpill
Definition: PPCInstrInfo.h:171
#define StoreOpcodesForSpill
Definition: PPCInstrInfo.h:169
const SmallVectorImpl< MachineOperand > MachineBasicBlock * TBB
const SmallVectorImpl< MachineOperand > & Cond
This file defines the SmallSet class.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
This is an important base class in LLVM.
Definition: Constant.h:42
A debug info location.
Definition: DebugLoc.h:33
Itinerary data supplied by a subtarget to be used by a target.
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:185
Wrapper class representing physical registers. Should be passed by value.
Definition: MCRegister.h:33
Representation of each machine instruction.
Definition: MachineInstr.h:69
MachineOperand class - Representation of each machine instruction operand.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
Register isLoadFromStackSlot(const MachineInstr &MI, int &FrameIndex) const override
Register isStoreToStackSlot(const MachineInstr &MI, int &FrameIndex) const override
bool isSchedulingBoundary(const MachineInstr &MI, const MachineBasicBlock *MBB, const MachineFunction &MF) const override
bool getFMAPatterns(MachineInstr &Root, SmallVectorImpl< unsigned > &Patterns, bool DoRegPressureReduce) const
Return true when there is potentially a faster code sequence for a fma chain ending in Root.
bool combineRLWINM(MachineInstr &MI, MachineInstr **ToErase=nullptr) const
bool isReallyTriviallyReMaterializable(const MachineInstr &MI) const override
const TargetRegisterClass * updatedRC(const TargetRegisterClass *RC) const
bool isPredicated(const MachineInstr &MI) const override
bool expandVSXMemPseudo(MachineInstr &MI) const
bool onlyFoldImmediate(MachineInstr &UseMI, MachineInstr &DefMI, Register Reg) const
int getExtendResourceLenLimit() const override
On PowerPC, we try to reassociate FMA chain which will increase instruction size.
Definition: PPCInstrInfo.h:415
bool isPrefixed(unsigned Opcode) const
Definition: PPCInstrInfo.h:280
void finalizeInsInstrs(MachineInstr &Root, unsigned &Pattern, SmallVectorImpl< MachineInstr * > &InsInstrs) const override
Fixup the placeholders we put in genAlternativeCodeSequence() for MachineCombiner.
MCInst getNop() const override
Return the noop instruction to use for a noop.
static int getRecordFormOpcode(unsigned Opcode)
void copyPhysReg(MachineBasicBlock &MBB, MachineBasicBlock::iterator I, const DebugLoc &DL, MCRegister DestReg, MCRegister SrcReg, bool KillSrc, bool RenamableDest=false, bool RenamableSrc=false) const override
MachineInstr * commuteInstructionImpl(MachineInstr &MI, bool NewMI, unsigned OpIdx1, unsigned OpIdx2) const override
Commutes the operands in the given instruction.
bool isXFormMemOp(unsigned Opcode) const
Definition: PPCInstrInfo.h:277
const PPCRegisterInfo & getRegisterInfo() const
getRegisterInfo - TargetInstrInfo is a superset of MRegister info.
Definition: PPCInstrInfo.h:275
CombinerObjective getCombinerObjective(unsigned Pattern) const override
void storeRegToStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, Register SrcReg, bool isKill, int FrameIndex, const TargetRegisterClass *RC, const TargetRegisterInfo *TRI, Register VReg) const override
void genAlternativeCodeSequence(MachineInstr &Root, unsigned Pattern, SmallVectorImpl< MachineInstr * > &InsInstrs, SmallVectorImpl< MachineInstr * > &DelInstrs, DenseMap< unsigned, unsigned > &InstrIdxForVirtReg) const override
When getMachineCombinerPatterns() finds patterns, this function generates the instructions that could...
void loadRegFromStackSlotNoUpd(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, unsigned DestReg, int FrameIndex, const TargetRegisterClass *RC, const TargetRegisterInfo *TRI) const
unsigned getStoreOpcodeForSpill(const TargetRegisterClass *RC) const
unsigned getLoadOpcodeForSpill(const TargetRegisterClass *RC) const
void promoteInstr32To64ForElimEXTSW(const Register &Reg, MachineRegisterInfo *MRI, unsigned BinOpDepth, LiveVariables *LV) const
bool isTOCSaveMI(const MachineInstr &MI) const
ScheduleHazardRecognizer * CreateTargetPostRAHazardRecognizer(const InstrItineraryData *II, const ScheduleDAG *DAG) const override
CreateTargetPostRAHazardRecognizer - Return the postRA hazard recognizer to use for this target when ...
bool isSExt32To64(unsigned Opcode) const
Definition: PPCInstrInfo.h:283
bool foldImmediate(MachineInstr &UseMI, MachineInstr &DefMI, Register Reg, MachineRegisterInfo *MRI) const override
bool isBDNZ(unsigned Opcode) const
Check Opcode is BDNZ (Decrement CTR and branch if it is still nonzero).
std::optional< unsigned > getOperandLatency(const InstrItineraryData *ItinData, SDNode *DefNode, unsigned DefIdx, SDNode *UseNode, unsigned UseIdx) const override
Definition: PPCInstrInfo.h:346
bool reverseBranchCondition(SmallVectorImpl< MachineOperand > &Cond) const override
bool isZeroExtended(const unsigned Reg, const MachineRegisterInfo *MRI) const
Definition: PPCInstrInfo.h:628
std::pair< unsigned, unsigned > decomposeMachineOperandsTargetFlags(unsigned TF) const override
std::pair< bool, bool > isSignOrZeroExtended(const unsigned Reg, const unsigned BinOpDepth, const MachineRegisterInfo *MRI) const
bool expandPostRAPseudo(MachineInstr &MI) const override
bool isProfitableToIfCvt(MachineBasicBlock &MBB, unsigned NumCycles, unsigned ExtraPredCycles, BranchProbability Probability) const override
Definition: PPCInstrInfo.h:511
void insertNoop(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI) const override
bool isValidToBeChangedReg(MachineInstr *ADDMI, unsigned Index, MachineInstr *&ADDIMI, int64_t &OffsetAddi, int64_t OffsetImm) const
bool optimizeCompareInstr(MachineInstr &CmpInstr, Register SrcReg, Register SrcReg2, int64_t Mask, int64_t Value, const MachineRegisterInfo *MRI) const override
ArrayRef< std::pair< unsigned, const char * > > getSerializableDirectMachineOperandTargetFlags() const override
std::optional< unsigned > getOperandLatency(const InstrItineraryData *ItinData, const MachineInstr &DefMI, unsigned DefIdx, const MachineInstr &UseMI, unsigned UseIdx) const override
void materializeImmPostRA(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, const DebugLoc &DL, Register Reg, int64_t Imm) const
bool isADDInstrEligibleForFolding(MachineInstr &ADDMI) const
bool isZExt32To64(unsigned Opcode) const
Definition: PPCInstrInfo.h:286
bool areMemAccessesTriviallyDisjoint(const MachineInstr &MIa, const MachineInstr &MIb) const override
Return true if two MIs access different memory addresses and false otherwise.
bool SubsumesPredicate(ArrayRef< MachineOperand > Pred1, ArrayRef< MachineOperand > Pred2) const override
ScheduleHazardRecognizer * CreateTargetHazardRecognizer(const TargetSubtargetInfo *STI, const ScheduleDAG *DAG) const override
CreateTargetHazardRecognizer - Return the hazard recognizer to use for this target when scheduling th...
static bool isSameClassPhysRegCopy(unsigned Opcode)
Definition: PPCInstrInfo.h:293
bool canInsertSelect(const MachineBasicBlock &, ArrayRef< MachineOperand > Cond, Register, Register, Register, int &, int &, int &) const override
bool getMemOperandsWithOffsetWidth(const MachineInstr &LdSt, SmallVectorImpl< const MachineOperand * > &BaseOps, int64_t &Offset, bool &OffsetIsScalable, LocationSize &Width, const TargetRegisterInfo *TRI) const override
Get the base operand and byte offset of an instruction that reads/writes memory.
void setSpecialOperandAttr(MachineInstr &MI, uint32_t Flags) const
bool isADDIInstrEligibleForFolding(MachineInstr &ADDIMI, int64_t &Imm) const
bool useMachineCombiner() const override
Definition: PPCInstrInfo.h:363
void storeRegToStackSlotNoUpd(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, unsigned SrcReg, bool isKill, int FrameIndex, const TargetRegisterClass *RC, const TargetRegisterInfo *TRI) const
bool foldFrameOffset(MachineInstr &MI) const
bool isLoadFromConstantPool(MachineInstr *I) const
MachineInstr * findLoopInstr(MachineBasicBlock &PreHeader, SmallPtrSet< MachineBasicBlock *, 8 > &Visited) const
Find the hardware loop instruction used to set-up the specified loop.
unsigned removeBranch(MachineBasicBlock &MBB, int *BytesRemoved=nullptr) const override
unsigned getInstrLatency(const InstrItineraryData *ItinData, const MachineInstr &MI, unsigned *PredCost=nullptr) const override
bool isProfitableToUnpredicate(MachineBasicBlock &TMBB, MachineBasicBlock &FMBB) const override
Definition: PPCInstrInfo.h:528
bool isCoalescableExtInstr(const MachineInstr &MI, Register &SrcReg, Register &DstReg, unsigned &SubIdx) const override
bool convertToImmediateForm(MachineInstr &MI, SmallSet< Register, 4 > &RegsToUpdate, MachineInstr **KilledDef=nullptr) const
bool isAssociativeAndCommutative(const MachineInstr &Inst, bool Invert) const override
bool analyzeCompare(const MachineInstr &MI, Register &SrcReg, Register &SrcReg2, int64_t &Mask, int64_t &Value) const override
void loadRegFromStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, Register DestReg, int FrameIndex, const TargetRegisterClass *RC, const TargetRegisterInfo *TRI, Register VReg) const override
bool hasLowDefLatency(const TargetSchedModel &SchedModel, const MachineInstr &DefMI, unsigned DefIdx) const override
Definition: PPCInstrInfo.h:354
bool isProfitableToDupForIfCvt(MachineBasicBlock &MBB, unsigned NumCycles, BranchProbability Probability) const override
Definition: PPCInstrInfo.h:523
bool getMemOperandWithOffsetWidth(const MachineInstr &LdSt, const MachineOperand *&BaseOp, int64_t &Offset, LocationSize &Width, const TargetRegisterInfo *TRI) const
Return true if get the base operand, byte offset of an instruction and the memory width.
bool isMemriOp(unsigned Opcode) const
Definition: PPCInstrInfo.h:289
unsigned insertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB, MachineBasicBlock *FBB, ArrayRef< MachineOperand > Cond, const DebugLoc &DL, int *BytesAdded=nullptr) const override
static bool hasTLSFlag(unsigned TF)
Definition: PPCInstrInfo.h:319
bool shouldReduceRegisterPressure(const MachineBasicBlock *MBB, const RegisterClassInfo *RegClassInfo) const override
On PowerPC, we leverage machine combiner pass to reduce register pressure when the register pressure ...
bool isSignExtended(const unsigned Reg, const MachineRegisterInfo *MRI) const
Definition: PPCInstrInfo.h:622
void replaceInstrOperandWithImm(MachineInstr &MI, unsigned OpNo, int64_t Imm) const
unsigned getInstSizeInBytes(const MachineInstr &MI) const override
GetInstSize - Return the number of bytes of code the specified instruction may be.
std::unique_ptr< TargetInstrInfo::PipelinerLoopInfo > analyzeLoopForPipelining(MachineBasicBlock *LoopBB) const override
Analyze loop L, which must be a single-basic-block loop, and if the conditions can be understood enou...
bool shouldClusterMemOps(ArrayRef< const MachineOperand * > BaseOps1, int64_t Offset1, bool OffsetIsScalable1, ArrayRef< const MachineOperand * > BaseOps2, int64_t Offset2, bool OffsetIsScalable2, unsigned ClusterSize, unsigned NumBytes) const override
Returns true if the two given memory operations should be scheduled adjacent.
static bool hasPCRelFlag(unsigned TF)
Definition: PPCInstrInfo.h:304
void replaceInstrWithLI(MachineInstr &MI, const LoadImmediateInfo &LII) const
bool isImmInstrEligibleForFolding(MachineInstr &MI, unsigned &BaseReg, unsigned &XFormOpcode, int64_t &OffsetOfImmInstr, ImmInstrInfo &III) const
bool PredicateInstruction(MachineInstr &MI, ArrayRef< MachineOperand > Pred) const override
bool getMachineCombinerPatterns(MachineInstr &Root, SmallVectorImpl< unsigned > &Patterns, bool DoRegPressureReduce) const override
Return true when there is potentially a faster code sequence for an instruction chain ending in <Root...
bool optimizeCmpPostRA(MachineInstr &MI) const
bool analyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB, MachineBasicBlock *&FBB, SmallVectorImpl< MachineOperand > &Cond, bool AllowModify) const override
const Constant * getConstantFromConstantPool(MachineInstr *I) const
bool ClobbersPredicate(MachineInstr &MI, std::vector< MachineOperand > &Pred, bool SkipDead) const override
static bool hasGOTFlag(unsigned TF)
Definition: PPCInstrInfo.h:312
void insertSelect(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, const DebugLoc &DL, Register DstReg, ArrayRef< MachineOperand > Cond, Register TrueReg, Register FalseReg) const override
bool findCommutedOpIndices(const MachineInstr &MI, unsigned &SrcOpIdx1, unsigned &SrcOpIdx2) const override
bool instrHasImmForm(unsigned Opc, bool IsVFReg, ImmInstrInfo &III, bool PostRA) const
MachineInstr * getDefMIPostRA(unsigned Reg, MachineInstr &MI, bool &SeenIntermediateUse) const
Wrapper class representing virtual and physical registers.
Definition: Register.h:19
Represents one node in the SelectionDAG.
HazardRecognizer - This determines whether or not an instruction can be issued this cycle,...
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
Definition: SmallPtrSet.h:519
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
Definition: SmallSet.h:132
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:573
virtual void setSpecialOperandAttr(MachineInstr &OldMI1, MachineInstr &OldMI2, MachineInstr &NewMI1, MachineInstr &NewMI2) const
This is an architecture-specific helper function of reassociateOps.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
Provide an instruction scheduling machine model to CodeGen passes.
TargetSubtargetInfo - Generic base class for all target subtargets.
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
LLVM Value Representation.
Definition: Value.h:74
@ ZExt32To64
This instruction produced a zero extended result.
@ SExt32To64
This instruction produced a sign extended result.
@ Prefixed
This instruction is prefixed.
@ MemriOp
This instruction takes a register+immediate memory operand.
@ XFormMemOp
This instruction is an X-Form memory operation.
@ MO_TLSLD_LO
Definition: PPC.h:182
@ MO_TPREL_PCREL_FLAG
MO_TPREL_PCREL_FLAG = MO_PCREL_FLAG | MO_TPREL_FLAG.
Definition: PPC.h:195
@ MO_GOT_TPREL_PCREL_FLAG
MO_GOT_TPREL_PCREL_FLAG - A combintaion of flags, if these bits are set they should produce the reloc...
Definition: PPC.h:170
@ MO_GOT_PCREL_FLAG
MO_GOT_PCREL_FLAG = MO_PCREL_FLAG | MO_GOT_FLAG.
Definition: PPC.h:201
@ MO_TLSGDM_FLAG
MO_TLSGDM_FLAG - If this bit is set the symbol reference is relative to the region handle of TLS Gene...
Definition: PPC.h:152
@ MO_PCREL_FLAG
MO_PCREL_FLAG - If this bit is set, the symbol reference is relative to the current instruction addre...
Definition: PPC.h:119
@ MO_TLSLD_FLAG
MO_TLSLD_FLAG - If this bit is set the symbol reference is relative to TLS Local Dynamic model.
Definition: PPC.h:148
@ MO_TLS_PCREL_FLAG
MO_TPREL_PCREL_FLAG = MO_PCREL_FLAG | MO_TLS.
Definition: PPC.h:198
@ MO_GOT_FLAG
MO_GOT_FLAG - If this bit is set the symbol reference is to be computed via the GOT.
Definition: PPC.h:124
@ MO_TPREL_HA
Definition: PPC.h:177
@ MO_DTPREL_LO
These values identify relocations on immediates folded into memory operations.
Definition: PPC.h:181
@ MO_TLS
Symbol for VK_PPC_TLS fixup attached to an ADD instruction.
Definition: PPC.h:186
@ MO_TPREL_FLAG
MO_TPREL_FLAG - If this bit is set, the symbol reference is relative to the thread pointer and the sy...
Definition: PPC.h:138
@ MO_TPREL_LO
Definition: PPC.h:176
@ MO_GOT_TLSLD_PCREL_FLAG
MO_GOT_TLSLD_PCREL_FLAG - A combintaion of flags, if these bits are set they should produce the reloc...
Definition: PPC.h:164
@ MO_TLSGD_FLAG
MO_TLSGD_FLAG - If this bit is set the symbol reference is relative to TLS General Dynamic model for ...
Definition: PPC.h:133
@ MO_GOT_TLSGD_PCREL_FLAG
MO_GOT_TLSGD_PCREL_FLAG - A combintaion of flags, if these bits are set they should produce the reloc...
Definition: PPC.h:158
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ Offset
Definition: DWP.cpp:480
decltype(auto) get(const PointerIntPair< PointerTy, IntBits, IntType, PtrTraits, Info > &Pair)
CombinerObjective
The combiner's goal may differ based on which pattern it is attempting to optimize.
PPCMachineCombinerPattern
Definition: PPCInstrInfo.h:90
@ REASSOC_XY_BCA
Definition: PPCInstrInfo.h:97
@ REASSOC_XY_BAC
Definition: PPCInstrInfo.h:98
@ REASSOC_XY_AMM_BMM
Definition: PPCInstrInfo.h:92
@ REASSOC_XMM_AMM_BMM
Definition: PPCInstrInfo.h:93
SpillOpcodeKey
Definition: PPCInstrInfo.h:68
@ SOK_CRBitSpill
Definition: PPCInstrInfo.h:74
@ SOK_VSXVectorSpill
Definition: PPCInstrInfo.h:76
@ SOK_SpillToVSR
Definition: PPCInstrInfo.h:79
@ SOK_Int4Spill
Definition: PPCInstrInfo.h:69
@ SOK_PairedVecSpill
Definition: PPCInstrInfo.h:80
@ SOK_VectorFloat8Spill
Definition: PPCInstrInfo.h:77
@ SOK_UAccumulatorSpill
Definition: PPCInstrInfo.h:82
@ SOK_PairedG8Spill
Definition: PPCInstrInfo.h:85
@ SOK_VectorFloat4Spill
Definition: PPCInstrInfo.h:78
@ SOK_Float8Spill
Definition: PPCInstrInfo.h:71
@ SOK_Float4Spill
Definition: PPCInstrInfo.h:72
@ SOK_VRVectorSpill
Definition: PPCInstrInfo.h:75
@ SOK_WAccumulatorSpill
Definition: PPCInstrInfo.h:83
@ SOK_SPESpill
Definition: PPCInstrInfo.h:84
@ SOK_CRSpill
Definition: PPCInstrInfo.h:73
@ SOK_AccumulatorSpill
Definition: PPCInstrInfo.h:81
@ SOK_Int8Spill
Definition: PPCInstrInfo.h:70
@ SOK_LastOpcodeSpill
Definition: PPCInstrInfo.h:86
uint64_t IsSummingOperands
Definition: PPCInstrInfo.h:56
uint64_t OpNoForForwarding
Definition: PPCInstrInfo.h:46
uint64_t ImmMustBeMultipleOf
Definition: PPCInstrInfo.h:36
uint64_t IsCommutative
Definition: PPCInstrInfo.h:44
uint64_t ZeroIsSpecialNew
Definition: PPCInstrInfo.h:42
uint64_t TruncateImmTo
Definition: PPCInstrInfo.h:54
uint64_t ZeroIsSpecialOrig
Definition: PPCInstrInfo.h:39