LLVM 24.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"
21
22#define GET_INSTRINFO_HEADER
23#include "PPCGenInstrInfo.inc"
24
25namespace llvm {
26
27// Instructions that have an immediate form might be convertible to that
28// form if the correct input is a result of a load immediate. In order to
29// know whether the transformation is special, we might need to know some
30// of the details of the two forms.
32 // Is the immediate field in the immediate form signed or unsigned?
34 // Does the immediate need to be a multiple of some value?
36 // Is R0/X0 treated specially by the original r+r instruction?
37 // If so, in which operand?
39 // Is R0/X0 treated specially by the new r+i instruction?
40 // If so, in which operand?
42 // Is the operation commutative?
44 // The operand number to check for add-immediate def.
46 // The operand number for the immediate.
48 // The opcode of the new instruction.
50 // The size of the immediate.
52 // The immediate should be truncated to N bits.
54 // Is the instruction summing the operand
56};
57
58// Information required to convert an instruction to just a materialized
59// immediate.
61 unsigned Imm : 16;
62 unsigned Is64Bit : 1;
63 unsigned SetCR : 1;
64};
65
66// Index into the OpcodesForSpill array.
89
90// PPC MachineCombiner patterns
92 // These are patterns matched by the PowerPC to reassociate FMA chains.
95
96 // These are patterns matched by the PowerPC to reassociate FMA and FSUB to
97 // reduce register pressure.
100
101};
102
103// Define list of load and store spill opcodes.
104#define NoInstr PPC::INSTRUCTION_LIST_END
105#define Pwr8LoadOpcodes \
106 {PPC::LWZ, \
107 PPC::LD, \
108 PPC::LFD, \
109 PPC::LFS, \
110 PPC::RESTORE_CR, \
111 PPC::RESTORE_CRBIT, \
112 PPC::LVX, \
113 PPC::LXVD2X, \
114 PPC::LXSDX, \
115 PPC::LXSSPX, \
116 PPC::SPILLTOVSR_LD, \
117 NoInstr, \
118 NoInstr, \
119 NoInstr, \
120 NoInstr, \
121 NoInstr, \
122 NoInstr, \
123 PPC::EVLDD, \
124 PPC::RESTORE_QUADWORD}
125
126#define Pwr9LoadOpcodes \
127 {PPC::LWZ, \
128 PPC::LD, \
129 PPC::LFD, \
130 PPC::LFS, \
131 PPC::RESTORE_CR, \
132 PPC::RESTORE_CRBIT, \
133 PPC::LVX, \
134 PPC::LXV, \
135 PPC::DFLOADf64, \
136 PPC::DFLOADf32, \
137 PPC::SPILLTOVSR_LD, \
138 NoInstr, \
139 NoInstr, \
140 NoInstr, \
141 NoInstr, \
142 NoInstr, \
143 NoInstr, \
144 NoInstr, \
145 PPC::RESTORE_QUADWORD}
146
147#define Pwr10LoadOpcodes \
148 {PPC::LWZ, \
149 PPC::LD, \
150 PPC::LFD, \
151 PPC::LFS, \
152 PPC::RESTORE_CR, \
153 PPC::RESTORE_CRBIT, \
154 PPC::LVX, \
155 PPC::LXV, \
156 PPC::DFLOADf64, \
157 PPC::DFLOADf32, \
158 PPC::SPILLTOVSR_LD, \
159 PPC::LXVP, \
160 PPC::RESTORE_ACC, \
161 PPC::RESTORE_UACC, \
162 NoInstr, \
163 NoInstr, \
164 NoInstr, \
165 NoInstr, \
166 PPC::RESTORE_QUADWORD}
167
168#define FutureLoadOpcodes \
169 {PPC::LWZ, \
170 PPC::LD, \
171 PPC::LFD, \
172 PPC::LFS, \
173 PPC::RESTORE_CR, \
174 PPC::RESTORE_CRBIT, \
175 PPC::LVX, \
176 PPC::LXV, \
177 PPC::DFLOADf64, \
178 PPC::DFLOADf32, \
179 PPC::SPILLTOVSR_LD, \
180 PPC::LXVP, \
181 PPC::RESTORE_ACC, \
182 PPC::RESTORE_UACC, \
183 PPC::RESTORE_WACC, \
184 PPC::RESTORE_DMRP, \
185 PPC::RESTORE_DMR, \
186 NoInstr, \
187 PPC::RESTORE_QUADWORD}
188
189#define Pwr8StoreOpcodes \
190 {PPC::STW, \
191 PPC::STD, \
192 PPC::STFD, \
193 PPC::STFS, \
194 PPC::SPILL_CR, \
195 PPC::SPILL_CRBIT, \
196 PPC::STVX, \
197 PPC::STXVD2X, \
198 PPC::STXSDX, \
199 PPC::STXSSPX, \
200 PPC::SPILLTOVSR_ST, \
201 NoInstr, \
202 NoInstr, \
203 NoInstr, \
204 NoInstr, \
205 NoInstr, \
206 NoInstr, \
207 PPC::EVSTDD, \
208 PPC::SPILL_QUADWORD}
209
210#define Pwr9StoreOpcodes \
211 {PPC::STW, \
212 PPC::STD, \
213 PPC::STFD, \
214 PPC::STFS, \
215 PPC::SPILL_CR, \
216 PPC::SPILL_CRBIT, \
217 PPC::STVX, \
218 PPC::STXV, \
219 PPC::DFSTOREf64, \
220 PPC::DFSTOREf32, \
221 PPC::SPILLTOVSR_ST, \
222 NoInstr, \
223 NoInstr, \
224 NoInstr, \
225 NoInstr, \
226 NoInstr, \
227 NoInstr, \
228 NoInstr, \
229 PPC::SPILL_QUADWORD}
230
231#define Pwr10StoreOpcodes \
232 {PPC::STW, \
233 PPC::STD, \
234 PPC::STFD, \
235 PPC::STFS, \
236 PPC::SPILL_CR, \
237 PPC::SPILL_CRBIT, \
238 PPC::STVX, \
239 PPC::STXV, \
240 PPC::DFSTOREf64, \
241 PPC::DFSTOREf32, \
242 PPC::SPILLTOVSR_ST, \
243 PPC::STXVP, \
244 PPC::SPILL_ACC, \
245 PPC::SPILL_UACC, \
246 NoInstr, \
247 NoInstr, \
248 NoInstr, \
249 NoInstr, \
250 PPC::SPILL_QUADWORD}
251
252#define FutureStoreOpcodes \
253 {PPC::STW, \
254 PPC::STD, \
255 PPC::STFD, \
256 PPC::STFS, \
257 PPC::SPILL_CR, \
258 PPC::SPILL_CRBIT, \
259 PPC::STVX, \
260 PPC::STXV, \
261 PPC::DFSTOREf64, \
262 PPC::DFSTOREf32, \
263 PPC::SPILLTOVSR_ST, \
264 PPC::STXVP, \
265 PPC::SPILL_ACC, \
266 PPC::SPILL_UACC, \
267 PPC::SPILL_WACC, \
268 PPC::SPILL_DMRP, \
269 PPC::SPILL_DMR, \
270 NoInstr, \
271 PPC::SPILL_QUADWORD}
272
273// Initialize arrays for load and store spill opcodes on supported subtargets.
274#define StoreOpcodesForSpill \
275 { Pwr8StoreOpcodes, Pwr9StoreOpcodes, Pwr10StoreOpcodes, FutureStoreOpcodes }
276#define LoadOpcodesForSpill \
277 { Pwr8LoadOpcodes, Pwr9LoadOpcodes, Pwr10LoadOpcodes, FutureLoadOpcodes }
278
279class PPCSubtarget;
281 const PPCSubtarget &Subtarget;
282 const PPCRegisterInfo RI;
283 const unsigned StoreSpillOpcodesArray[4][SOK_LastOpcodeSpill] =
285 const unsigned LoadSpillOpcodesArray[4][SOK_LastOpcodeSpill] =
287
288 void StoreRegToStackSlot(MachineFunction &MF, unsigned SrcReg, bool isKill,
289 int FrameIdx, const TargetRegisterClass *RC,
290 SmallVectorImpl<MachineInstr *> &NewMIs) const;
291 void LoadRegFromStackSlot(MachineFunction &MF, const DebugLoc &DL,
292 unsigned DestReg, int FrameIdx,
293 const TargetRegisterClass *RC,
294 SmallVectorImpl<MachineInstr *> &NewMIs) const;
295
296 // Replace the instruction with single LI if possible. \p DefMI must be LI or
297 // LI8.
298 bool simplifyToLI(MachineInstr &MI, MachineInstr &DefMI,
299 unsigned OpNoForForwarding, MachineInstr **KilledDef,
300 SmallSet<Register, 4> *RegsToUpdate = nullptr) const;
301 // If the inst is imm-form and its register operand is produced by a ADDI, put
302 // the imm into the inst directly and remove the ADDI if possible.
303 bool transformToNewImmFormFedByAdd(MachineInstr &MI, MachineInstr &DefMI,
304 unsigned OpNoForForwarding) const;
305 // If the inst is x-form and has imm-form and one of its operand is produced
306 // by a LI, put the imm into the inst directly and remove the LI if possible.
307 bool transformToImmFormFedByLI(MachineInstr &MI, const ImmInstrInfo &III,
308 unsigned ConstantOpNo,
309 MachineInstr &DefMI) const;
310 // If the inst is x-form and has imm-form and one of its operand is produced
311 // by an add-immediate, try to transform it when possible.
312 bool transformToImmFormFedByAdd(MachineInstr &MI, const ImmInstrInfo &III,
313 unsigned ConstantOpNo, MachineInstr &DefMI,
314 bool KillDefMI) const;
315 // Try to find that, if the instruction 'MI' contains any operand that
316 // could be forwarded from some inst that feeds it. If yes, return the
317 // Def of that operand. And OpNoForForwarding is the operand index in
318 // the 'MI' for that 'Def'. If we see another use of this Def between
319 // the Def and the MI, SeenIntermediateUse becomes 'true'.
320 MachineInstr *getForwardingDefMI(MachineInstr &MI,
321 unsigned &OpNoForForwarding,
322 bool &SeenIntermediateUse) const;
323
324 // Can the user MI have it's source at index \p OpNoForForwarding
325 // forwarded from an add-immediate that feeds it?
326 bool isUseMIElgibleForForwarding(MachineInstr &MI, const ImmInstrInfo &III,
327 unsigned OpNoForForwarding) const;
328 bool isDefMIElgibleForForwarding(MachineInstr &DefMI,
329 const ImmInstrInfo &III,
330 MachineOperand *&ImmMO,
331 MachineOperand *&RegMO) const;
332 bool isImmElgibleForForwarding(const MachineOperand &ImmMO,
333 const MachineInstr &DefMI,
334 const ImmInstrInfo &III,
335 int64_t &Imm,
336 int64_t BaseImm = 0) const;
337 bool isRegElgibleForForwarding(const MachineOperand &RegMO,
338 const MachineInstr &DefMI,
339 const MachineInstr &MI, bool KillDefMI,
340 bool &IsFwdFeederRegKilled,
341 bool &SeenIntermediateUse) const;
342 unsigned getSpillTarget() const;
343 ArrayRef<unsigned> getStoreOpcodesForSpillArray() const;
344 ArrayRef<unsigned> getLoadOpcodesForSpillArray() const;
345 unsigned getSpillIndex(const TargetRegisterClass *RC) const;
346 int16_t getFMAOpIdxInfo(unsigned Opcode) const;
347 void reassociateFMA(MachineInstr &Root, unsigned Pattern,
350 DenseMap<Register, unsigned> &InstrIdxForVirtReg) const;
352 generateLoadForNewConst(unsigned Idx, MachineInstr *MI, Type *Ty,
353 SmallVectorImpl<MachineInstr *> &InsInstrs) const;
354 virtual void anchor();
355
356protected:
357 /// Commutes the operands in the given instruction.
358 /// The commutable operands are specified by their indices OpIdx1 and OpIdx2.
359 ///
360 /// Do not call this method for a non-commutable instruction or for
361 /// non-commutable pair of operand indices OpIdx1 and OpIdx2.
362 /// Even though the instruction is commutable, the method may still
363 /// fail to commute the operands, null pointer is returned in such cases.
364 ///
365 /// For example, we can commute rlwimi instructions, but only if the
366 /// rotate amt is zero. We also have to munge the immediates a bit.
368 unsigned OpIdx1,
369 unsigned OpIdx2) const override;
370
371public:
372 explicit PPCInstrInfo(const PPCSubtarget &STI);
373
376
377 /// getRegisterInfo - TargetInstrInfo is a superset of MRegister info. As
378 /// such, whenever a client has an instance of instruction info, it should
379 /// always be able to get register info as well (through this method).
380 ///
381 const PPCRegisterInfo &getRegisterInfo() const { return RI; }
382
383 const TargetRegisterClass *
385
386 bool isXFormMemOp(unsigned Opcode) const {
387 return get(Opcode).TSFlags & PPCII::XFormMemOp;
388 }
389 bool isPrefixed(unsigned Opcode) const {
390 return get(Opcode).TSFlags & PPCII::Prefixed;
391 }
392 bool isSExt32To64(unsigned Opcode) const {
393 return get(Opcode).TSFlags & PPCII::SExt32To64;
394 }
395 bool isZExt32To64(unsigned Opcode) const {
396 return get(Opcode).TSFlags & PPCII::ZExt32To64;
397 }
398 bool isMemriOp(unsigned Opcode) const {
399 return get(Opcode).TSFlags & PPCII::MemriOp;
400 }
401
402 static bool isSameClassPhysRegCopy(unsigned Opcode) {
403 unsigned CopyOpcodes[] = {PPC::OR, PPC::OR8, PPC::FMR,
404 PPC::VOR, PPC::XXLOR, PPC::XXLORf,
405 PPC::XSCPSGNDP, PPC::MCRF, PPC::CROR,
406 PPC::EVOR, -1U};
407 for (int i = 0; CopyOpcodes[i] != -1U; i++)
408 if (Opcode == CopyOpcodes[i])
409 return true;
410 return false;
411 }
412
420
421 static bool hasGOTFlag(unsigned TF) {
426 }
427
438
441 const ScheduleDAG *DAG) const override;
444 const ScheduleDAG *DAG) const override;
445
446 unsigned getInstrLatency(const InstrItineraryData *ItinData,
447 const MachineInstr &MI,
448 unsigned *PredCost = nullptr) const override;
449
450 std::optional<unsigned> getOperandLatency(const InstrItineraryData *ItinData,
451 const MachineInstr &DefMI,
452 unsigned DefIdx,
453 const MachineInstr &UseMI,
454 unsigned UseIdx) const override;
455 std::optional<unsigned> getOperandLatency(const InstrItineraryData *ItinData,
456 SDNode *DefNode, unsigned DefIdx,
457 SDNode *UseNode,
458 unsigned UseIdx) const override {
459 return PPCGenInstrInfo::getOperandLatency(ItinData, DefNode, DefIdx,
460 UseNode, UseIdx);
461 }
462
463 bool hasLowDefLatency(const TargetSchedModel &SchedModel,
464 const MachineInstr &DefMI,
465 unsigned DefIdx) const override {
466 // Machine LICM should hoist all instructions in low-register-pressure
467 // situations; none are sufficiently free to justify leaving in a loop
468 // body.
469 return false;
470 }
471
472 bool useMachineCombiner() const override {
473 return true;
474 }
475
476 /// When getMachineCombinerPatterns() finds patterns, this function generates
477 /// the instructions that could replace the original code sequence
479 MachineInstr &Root, unsigned Pattern,
482 DenseMap<Register, unsigned> &InstrIdxForVirtReg) const override;
483
484 /// Return true when there is potentially a faster code sequence for a fma
485 /// chain ending in \p Root. All potential patterns are output in the \p
486 /// P array.
488 bool DoRegPressureReduce) const;
489
490 CombinerObjective getCombinerObjective(unsigned Pattern) const override;
491
492 /// Return true when there is potentially a faster code sequence
493 /// for an instruction chain ending in <Root>. All potential patterns are
494 /// output in the <Pattern> array.
497 bool DoRegPressureReduce) const override;
498
499 /// On PowerPC, we leverage machine combiner pass to reduce register pressure
500 /// when the register pressure is high for one BB.
501 /// Return true if register pressure for \p MBB is high and ABI is supported
502 /// to reduce register pressure. Otherwise return false.
504 const MachineBasicBlock *MBB,
505 const RegisterClassInfo *RegClassInfo) const override;
506
507 /// Fixup the placeholders we put in genAlternativeCodeSequence() for
508 /// MachineCombiner.
509 void
510 finalizeInsInstrs(MachineInstr &Root, unsigned &Pattern,
511 SmallVectorImpl<MachineInstr *> &InsInstrs) const override;
512
514 bool Invert) const override;
515
516 /// On PowerPC, we try to reassociate FMA chain which will increase
517 /// instruction size. Set extension resource length limit to 1 for edge case.
518 /// Resource Length is calculated by scaled resource usage in getCycles().
519 /// Because of the division in getCycles(), it returns different cycles due to
520 /// legacy scaled resource usage. So new resource length may be same with
521 /// legacy or 1 bigger than legacy.
522 /// We need to execlude the 1 bigger case even the resource length is not
523 /// perserved for more FMA chain reassociations on PowerPC.
524 int getExtendResourceLenLimit() const override { return 1; }
525
526 // PowerPC specific version of setSpecialOperandAttr that copies Flags to MI
527 // and clears nuw, nsw, and exact flags.
529 void setSpecialOperandAttr(MachineInstr &MI, uint32_t Flags) const;
530
532 Register &SrcReg, Register &DstReg,
533 unsigned &SubIdx) const override;
535 int &FrameIndex) const override;
536 bool isReMaterializableImpl(const MachineInstr &MI) const override;
538 int &FrameIndex) const override;
539
540 bool findCommutedOpIndices(const MachineInstr &MI, unsigned &SrcOpIdx1,
541 unsigned &SrcOpIdx2) const override;
542
544 MachineBasicBlock::iterator MI) const override;
545
546
547 // Branch analysis.
549 MachineBasicBlock *&FBB,
551 bool AllowModify) const override;
553 int *BytesRemoved = nullptr) const override;
556 const DebugLoc &DL,
557 int *BytesAdded = nullptr) const override;
558
559 // Select analysis.
561 Register, Register, Register, int &, int &,
562 int &) const override;
564 const DebugLoc &DL, Register DstReg,
566 Register FalseReg) const override;
567
569 const DebugLoc &DL, Register DestReg, Register SrcReg,
570 bool KillSrc, bool RenamableDest = false,
571 bool RenamableSrc = false) const override;
572
575 bool isKill, int FrameIndex, const TargetRegisterClass *RC,
576
577 Register VReg,
578 MachineInstr::MIFlag Flags = MachineInstr::NoFlags) const override;
579
580 // Emits a register spill without updating the register class for vector
581 // registers. This ensures that when we spill a vector register the
582 // element order in the register is the same as it was in memory.
585 unsigned SrcReg, bool isKill, int FrameIndex,
586 const TargetRegisterClass *RC) const;
587
590 Register DestReg, int FrameIndex, const TargetRegisterClass *RC,
591 Register VReg, unsigned SubReg = 0,
592 MachineInstr::MIFlag Flags = MachineInstr::NoFlags) const override;
593
594 // Emits a register reload without updating the register class for vector
595 // registers. This ensures that when we reload a vector register the
596 // element order in the register is the same as it was in memory.
599 unsigned DestReg, int FrameIndex,
600 const TargetRegisterClass *RC) const;
601
602 unsigned getStoreOpcodeForSpill(const TargetRegisterClass *RC) const;
603
604 unsigned getLoadOpcodeForSpill(const TargetRegisterClass *RC) const;
605
606 bool
608
610 MachineRegisterInfo *MRI) const override;
611
613 Register Reg) const;
614
615 // If conversion by predication (only supported by some branch instructions).
616 // All of the profitability checks always return true; it is always
617 // profitable to use the predicated branches.
619 unsigned NumCycles, unsigned ExtraPredCycles,
620 BranchProbability Probability) const override {
621 return true;
622 }
623
625 unsigned NumT, unsigned ExtraT,
626 MachineBasicBlock &FMBB,
627 unsigned NumF, unsigned ExtraF,
628 BranchProbability Probability) const override;
629
631 BranchProbability Probability) const override {
632 return true;
633 }
634
636 MachineBasicBlock &FMBB) const override {
637 return false;
638 }
639
640 // Predication support.
641 bool isPredicated(const MachineInstr &MI) const override;
642
644 const MachineBasicBlock *MBB,
645 const MachineFunction &MF) const override;
646
648 ArrayRef<MachineOperand> Pred) const override;
649
651 ArrayRef<MachineOperand> Pred2) const override;
652
653 bool ClobbersPredicate(MachineInstr &MI, std::vector<MachineOperand> &Pred,
654 bool SkipDead) const override;
655
656 // Comparison optimization.
657
658 bool analyzeCompare(const MachineInstr &MI, Register &SrcReg,
659 Register &SrcReg2, int64_t &Mask,
660 int64_t &Value) const override;
661
662 bool optimizeCompareInstr(MachineInstr &CmpInstr, Register SrcReg,
663 Register SrcReg2, int64_t Mask, int64_t Value,
664 const MachineRegisterInfo *MRI) const override;
665
666
667 /// Return true if get the base operand, byte offset of an instruction and
668 /// the memory width. Width is the size of memory that is being
669 /// loaded/stored (e.g. 1, 2, 4, 8).
671 const MachineOperand *&BaseOp,
672 int64_t &Offset, LocationSize &Width,
673 const TargetRegisterInfo *TRI) const;
674
675 bool optimizeCmpPostRA(MachineInstr &MI) const;
676
677 /// Get the base operand and byte offset of an instruction that reads/writes
678 /// memory.
680 const MachineInstr &LdSt,
682 bool &OffsetIsScalable, LocationSize &Width,
683 const TargetRegisterInfo *TRI) const override;
684
685 /// Returns true if the two given memory operations should be scheduled
686 /// adjacent.
688 int64_t Offset1, bool OffsetIsScalable1,
690 int64_t Offset2, bool OffsetIsScalable2,
691 unsigned ClusterSize,
692 unsigned NumBytes) const override;
693
694 /// Return true if two MIs access different memory addresses and false
695 /// otherwise
696 bool
698 const MachineInstr &MIb) const override;
699
700 /// GetInstSize - Return the number of bytes of code the specified
701 /// instruction may be. This returns the maximum number of bytes.
702 ///
703 unsigned getInstSizeInBytes(const MachineInstr &MI) const override;
704
705 InstSizeVerifyMode
706 getInstSizeVerifyMode(const MachineInstr &MI) const override;
707
708 MCInst getNop() const override;
709
710 std::pair<unsigned, unsigned>
711 decomposeMachineOperandsTargetFlags(unsigned TF) const override;
712
715
716 // Expand VSX Memory Pseudo instruction to either a VSX or a FP instruction.
718
719 // Lower pseudo instructions after register allocation.
720 bool expandPostRAPseudo(MachineInstr &MI) const override;
722
723 const TargetRegisterClass *updatedRC(const TargetRegisterClass *RC) const;
724 static int getRecordFormOpcode(unsigned Opcode);
725
726 bool isTOCSaveMI(const MachineInstr &MI) const;
727
728 std::pair<bool, bool>
729 isSignOrZeroExtended(const unsigned Reg, const unsigned BinOpDepth,
730 const MachineRegisterInfo *MRI) const;
731
732 // Return true if the register is sign-extended from 32 to 64 bits.
733 bool isSignExtended(const unsigned Reg,
734 const MachineRegisterInfo *MRI) const {
735 return isSignOrZeroExtended(Reg, 0, MRI).first;
736 }
737
738 // Return true if the register is zero-extended from 32 to 64 bits.
739 bool isZeroExtended(const unsigned Reg,
740 const MachineRegisterInfo *MRI) const {
741 return isSignOrZeroExtended(Reg, 0, MRI).second;
742 }
745 unsigned BinOpDepth) const;
746
748 SmallSet<Register, 4> &RegsToUpdate,
749 MachineInstr **KilledDef = nullptr) const;
750 bool foldFrameOffset(MachineInstr &MI) const;
751 bool combineRLWINM(MachineInstr &MI, MachineInstr **ToErase = nullptr) const;
752 bool isADDIInstrEligibleForFolding(MachineInstr &ADDIMI, int64_t &Imm) const;
754 bool isImmInstrEligibleForFolding(MachineInstr &MI, unsigned &BaseReg,
755 unsigned &XFormOpcode,
756 int64_t &OffsetOfImmInstr,
757 ImmInstrInfo &III) const;
758 bool isValidToBeChangedReg(MachineInstr *ADDMI, unsigned Index,
759 MachineInstr *&ADDIMI, int64_t &OffsetAddi,
760 int64_t OffsetImm) const;
761
762 void replaceInstrWithLI(MachineInstr &MI, const LoadImmediateInfo &LII) const;
763 void replaceInstrOperandWithImm(MachineInstr &MI, unsigned OpNo,
764 int64_t Imm) const;
765
766 bool instrHasImmForm(unsigned Opc, bool IsVFReg, ImmInstrInfo &III,
767 bool PostRA) const;
768
769 // In PostRA phase, try to find instruction defines \p Reg before \p MI.
770 // \p SeenIntermediate is set to true if uses between DefMI and \p MI exist.
772 bool &SeenIntermediateUse) const;
773
774 // Materialize immediate after RA.
777 const DebugLoc &DL, Register Reg,
778 int64_t Imm) const;
779
780 /// Check \p Opcode is BDNZ (Decrement CTR and branch if it is still nonzero).
781 bool isBDNZ(unsigned Opcode) const;
782
783 /// Find the hardware loop instruction used to set-up the specified loop.
784 /// On PPC, we have two instructions used to set-up the hardware loop
785 /// (MTCTRloop, MTCTR8loop) with corresponding endloop (BDNZ, BDNZ8)
786 /// instructions to indicate the end of a loop.
790
791 /// Analyze loop L, which must be a single-basic-block loop, and if the
792 /// conditions can be understood enough produce a PipelinerLoopInfo object.
793 std::unique_ptr<TargetInstrInfo::PipelinerLoopInfo>
794 analyzeLoopForPipelining(MachineBasicBlock *LoopBB) const override;
795};
796
797}
798
799#endif
MachineInstrBuilder & UseMI
MachineInstrBuilder MachineInstrBuilder & DefMI
unsigned Imm
unsigned uint64_t
MachineBasicBlock & MBB
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
MachineBasicBlock MachineBasicBlock::iterator MBBI
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
IRTranslator LLVM IR MI
#define I(x, y, z)
Definition MD5.cpp:57
Register Reg
Register const TargetRegisterInfo * TRI
uint64_t IntrinsicInst * II
#define LoadOpcodesForSpill
#define StoreOpcodesForSpill
const SmallVectorImpl< MachineOperand > MachineBasicBlock * TBB
const SmallVectorImpl< MachineOperand > & Cond
This file defines the SmallSet class.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
This is an important base class in LLVM.
Definition Constant.h:43
A debug info location.
Definition DebugLoc.h:126
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:188
MachineInstrBundleIterator< MachineInstr > iterator
Representation of each machine instruction.
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 isReMaterializableImpl(const MachineInstr &MI) const override
PPCInstrInfo(const PPCSubtarget &STI)
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.
bool isPrefixed(unsigned Opcode) const
void copyPhysReg(MachineBasicBlock &MBB, MachineBasicBlock::iterator I, const DebugLoc &DL, Register DestReg, Register SrcReg, bool KillSrc, bool RenamableDest=false, bool RenamableSrc=false) const override
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.
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
static int getRecordFormOpcode(unsigned Opcode)
MachineInstr * commuteInstructionImpl(MachineInstr &MI, bool NewMI, unsigned OpIdx1, unsigned OpIdx2) const override
Commutes the operands in the given instruction.
bool isXFormMemOp(unsigned Opcode) const
const PPCRegisterInfo & getRegisterInfo() const
getRegisterInfo - TargetInstrInfo is a superset of MRegister info.
CombinerObjective getCombinerObjective(unsigned Pattern) const override
void loadRegFromStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, Register DestReg, int FrameIndex, const TargetRegisterClass *RC, Register VReg, unsigned SubReg=0, MachineInstr::MIFlag Flags=MachineInstr::NoFlags) const override
unsigned getStoreOpcodeForSpill(const TargetRegisterClass *RC) const
unsigned getLoadOpcodeForSpill(const TargetRegisterClass *RC) const
bool expandAMOCSNEPseudo(MachineInstr &MI) 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
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
bool reverseBranchCondition(SmallVectorImpl< MachineOperand > &Cond) const override
bool isZeroExtended(const unsigned Reg, const MachineRegisterInfo *MRI) const
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
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
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)
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
void loadRegFromStackSlotNoUpd(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, unsigned DestReg, int FrameIndex, const TargetRegisterClass *RC) 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
void storeRegToStackSlotNoUpd(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, unsigned SrcReg, bool isKill, int FrameIndex, const TargetRegisterClass *RC) const
bool isProfitableToUnpredicate(MachineBasicBlock &TMBB, MachineBasicBlock &FMBB) const override
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
bool hasLowDefLatency(const TargetSchedModel &SchedModel, const MachineInstr &DefMI, unsigned DefIdx) const override
bool isProfitableToDupForIfCvt(MachineBasicBlock &MBB, unsigned NumCycles, BranchProbability Probability) const override
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
unsigned insertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB, MachineBasicBlock *FBB, ArrayRef< MachineOperand > Cond, const DebugLoc &DL, int *BytesAdded=nullptr) const override
static bool hasTLSFlag(unsigned TF)
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 ...
const TargetRegisterClass * getInlineAsmMemoryOperandRegClass(InlineAsm::ConstraintCode C) const override
void genAlternativeCodeSequence(MachineInstr &Root, unsigned Pattern, SmallVectorImpl< MachineInstr * > &InsInstrs, SmallVectorImpl< MachineInstr * > &DelInstrs, DenseMap< Register, unsigned > &InstrIdxForVirtReg) const override
When getMachineCombinerPatterns() finds patterns, this function generates the instructions that could...
InstSizeVerifyMode getInstSizeVerifyMode(const MachineInstr &MI) const override
bool isSignExtended(const unsigned Reg, const MachineRegisterInfo *MRI) const
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)
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)
void insertSelect(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, const DebugLoc &DL, Register DstReg, ArrayRef< MachineOperand > Cond, Register TrueReg, Register FalseReg) const override
void promoteInstr32To64ForElimEXTSW(const Register &Reg, MachineRegisterInfo *MRI, unsigned BinOpDepth) const
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:20
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.
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
Definition SmallSet.h:134
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
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:46
LLVM Value Representation.
Definition Value.h:75
@ 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:196
@ MO_TPREL_PCREL_FLAG
MO_TPREL_PCREL_FLAG = MO_PCREL_FLAG | MO_TPREL_FLAG.
Definition PPC.h:209
@ 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:184
@ MO_GOT_PCREL_FLAG
MO_GOT_PCREL_FLAG = MO_PCREL_FLAG | MO_GOT_FLAG.
Definition PPC.h:215
@ 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:166
@ MO_PCREL_FLAG
MO_PCREL_FLAG - If this bit is set, the symbol reference is relative to the current instruction addre...
Definition PPC.h:133
@ MO_TLSLD_FLAG
MO_TLSLD_FLAG - If this bit is set the symbol reference is relative to TLS Local Dynamic model.
Definition PPC.h:162
@ MO_TLS_PCREL_FLAG
MO_TPREL_PCREL_FLAG = MO_PCREL_FLAG | MO_TLS.
Definition PPC.h:212
@ MO_GOT_FLAG
MO_GOT_FLAG - If this bit is set the symbol reference is to be computed via the GOT.
Definition PPC.h:138
@ MO_TPREL_HA
Definition PPC.h:191
@ MO_DTPREL_LO
These values identify relocations on immediates folded into memory operations.
Definition PPC.h:195
@ MO_TLS
Symbol for VK_TLS fixup attached to an ADD instruction.
Definition PPC.h:200
@ 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:152
@ MO_TPREL_LO
Definition PPC.h:190
@ 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:178
@ 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:147
@ 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:172
This is an optimization pass for GlobalISel generic memory operations.
@ Offset
Definition DWP.cpp:577
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
@ REASSOC_XY_BCA
@ REASSOC_XY_BAC
@ REASSOC_XY_AMM_BMM
@ REASSOC_XMM_AMM_BMM
SpillOpcodeKey
@ SOK_CRBitSpill
@ SOK_VSXVectorSpill
@ SOK_SpillToVSR
@ SOK_Int4Spill
@ SOK_PairedVecSpill
@ SOK_VectorFloat8Spill
@ SOK_UAccumulatorSpill
@ SOK_PairedG8Spill
@ SOK_DMRSpill
@ SOK_VectorFloat4Spill
@ SOK_Float8Spill
@ SOK_Float4Spill
@ SOK_VRVectorSpill
@ SOK_WAccumulatorSpill
@ SOK_SPESpill
@ SOK_CRSpill
@ SOK_AccumulatorSpill
@ SOK_Int8Spill
@ SOK_LastOpcodeSpill
@ SOK_DMRpSpill
MCRegisterClass TargetRegisterClass
Definition FastISel.h:58
uint64_t IsSummingOperands
uint64_t OpNoForForwarding
uint64_t ImmMustBeMultipleOf
uint64_t ZeroIsSpecialNew
uint64_t ZeroIsSpecialOrig