Path: blob/main/contrib/llvm-project/llvm/lib/Target/PowerPC/PPCInstrInfo.h
35267 views
//===-- PPCInstrInfo.h - PowerPC Instruction Information --------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// This file contains the PowerPC implementation of the TargetInstrInfo class.9//10//===----------------------------------------------------------------------===//1112#ifndef LLVM_LIB_TARGET_POWERPC_PPCINSTRINFO_H13#define LLVM_LIB_TARGET_POWERPC_PPCINSTRINFO_H1415#include "MCTargetDesc/PPCMCTargetDesc.h"16#include "PPC.h"17#include "PPCRegisterInfo.h"18#include "llvm/ADT/SmallSet.h"19#include "llvm/CodeGen/TargetInstrInfo.h"2021#define GET_INSTRINFO_HEADER22#include "PPCGenInstrInfo.inc"2324namespace llvm {2526// Instructions that have an immediate form might be convertible to that27// form if the correct input is a result of a load immediate. In order to28// know whether the transformation is special, we might need to know some29// of the details of the two forms.30struct ImmInstrInfo {31// Is the immediate field in the immediate form signed or unsigned?32uint64_t SignedImm : 1;33// Does the immediate need to be a multiple of some value?34uint64_t ImmMustBeMultipleOf : 5;35// Is R0/X0 treated specially by the original r+r instruction?36// If so, in which operand?37uint64_t ZeroIsSpecialOrig : 3;38// Is R0/X0 treated specially by the new r+i instruction?39// If so, in which operand?40uint64_t ZeroIsSpecialNew : 3;41// Is the operation commutative?42uint64_t IsCommutative : 1;43// The operand number to check for add-immediate def.44uint64_t OpNoForForwarding : 3;45// The operand number for the immediate.46uint64_t ImmOpNo : 3;47// The opcode of the new instruction.48uint64_t ImmOpcode : 16;49// The size of the immediate.50uint64_t ImmWidth : 5;51// The immediate should be truncated to N bits.52uint64_t TruncateImmTo : 5;53// Is the instruction summing the operand54uint64_t IsSummingOperands : 1;55};5657// Information required to convert an instruction to just a materialized58// immediate.59struct LoadImmediateInfo {60unsigned Imm : 16;61unsigned Is64Bit : 1;62unsigned SetCR : 1;63};6465// Index into the OpcodesForSpill array.66enum SpillOpcodeKey {67SOK_Int4Spill,68SOK_Int8Spill,69SOK_Float8Spill,70SOK_Float4Spill,71SOK_CRSpill,72SOK_CRBitSpill,73SOK_VRVectorSpill,74SOK_VSXVectorSpill,75SOK_VectorFloat8Spill,76SOK_VectorFloat4Spill,77SOK_SpillToVSR,78SOK_PairedVecSpill,79SOK_AccumulatorSpill,80SOK_UAccumulatorSpill,81SOK_WAccumulatorSpill,82SOK_SPESpill,83SOK_PairedG8Spill,84SOK_LastOpcodeSpill // This must be last on the enum.85};8687// PPC MachineCombiner patterns88enum PPCMachineCombinerPattern : unsigned {89// These are patterns matched by the PowerPC to reassociate FMA chains.90REASSOC_XY_AMM_BMM = MachineCombinerPattern::TARGET_PATTERN_START,91REASSOC_XMM_AMM_BMM,9293// These are patterns matched by the PowerPC to reassociate FMA and FSUB to94// reduce register pressure.95REASSOC_XY_BCA,96REASSOC_XY_BAC,9798};99100// Define list of load and store spill opcodes.101#define NoInstr PPC::INSTRUCTION_LIST_END102#define Pwr8LoadOpcodes \103{ \104PPC::LWZ, PPC::LD, PPC::LFD, PPC::LFS, PPC::RESTORE_CR, \105PPC::RESTORE_CRBIT, PPC::LVX, PPC::LXVD2X, PPC::LXSDX, PPC::LXSSPX, \106PPC::SPILLTOVSR_LD, NoInstr, NoInstr, NoInstr, NoInstr, PPC::EVLDD, \107PPC::RESTORE_QUADWORD \108}109110#define Pwr9LoadOpcodes \111{ \112PPC::LWZ, PPC::LD, PPC::LFD, PPC::LFS, PPC::RESTORE_CR, \113PPC::RESTORE_CRBIT, PPC::LVX, PPC::LXV, PPC::DFLOADf64, \114PPC::DFLOADf32, PPC::SPILLTOVSR_LD, NoInstr, NoInstr, NoInstr, \115NoInstr, NoInstr, PPC::RESTORE_QUADWORD \116}117118#define Pwr10LoadOpcodes \119{ \120PPC::LWZ, PPC::LD, PPC::LFD, PPC::LFS, PPC::RESTORE_CR, \121PPC::RESTORE_CRBIT, PPC::LVX, PPC::LXV, PPC::DFLOADf64, \122PPC::DFLOADf32, PPC::SPILLTOVSR_LD, PPC::LXVP, PPC::RESTORE_ACC, \123PPC::RESTORE_UACC, NoInstr, NoInstr, PPC::RESTORE_QUADWORD \124}125126#define FutureLoadOpcodes \127{ \128PPC::LWZ, PPC::LD, PPC::LFD, PPC::LFS, PPC::RESTORE_CR, \129PPC::RESTORE_CRBIT, PPC::LVX, PPC::LXV, PPC::DFLOADf64, \130PPC::DFLOADf32, PPC::SPILLTOVSR_LD, PPC::LXVP, PPC::RESTORE_ACC, \131PPC::RESTORE_UACC, PPC::RESTORE_WACC, NoInstr, PPC::RESTORE_QUADWORD \132}133134#define Pwr8StoreOpcodes \135{ \136PPC::STW, PPC::STD, PPC::STFD, PPC::STFS, PPC::SPILL_CR, PPC::SPILL_CRBIT, \137PPC::STVX, PPC::STXVD2X, PPC::STXSDX, PPC::STXSSPX, \138PPC::SPILLTOVSR_ST, NoInstr, NoInstr, NoInstr, NoInstr, PPC::EVSTDD, \139PPC::SPILL_QUADWORD \140}141142#define Pwr9StoreOpcodes \143{ \144PPC::STW, PPC::STD, PPC::STFD, PPC::STFS, PPC::SPILL_CR, PPC::SPILL_CRBIT, \145PPC::STVX, PPC::STXV, PPC::DFSTOREf64, PPC::DFSTOREf32, \146PPC::SPILLTOVSR_ST, NoInstr, NoInstr, NoInstr, NoInstr, NoInstr, \147PPC::SPILL_QUADWORD \148}149150#define Pwr10StoreOpcodes \151{ \152PPC::STW, PPC::STD, PPC::STFD, PPC::STFS, PPC::SPILL_CR, PPC::SPILL_CRBIT, \153PPC::STVX, PPC::STXV, PPC::DFSTOREf64, PPC::DFSTOREf32, \154PPC::SPILLTOVSR_ST, PPC::STXVP, PPC::SPILL_ACC, PPC::SPILL_UACC, \155NoInstr, NoInstr, PPC::SPILL_QUADWORD \156}157158#define FutureStoreOpcodes \159{ \160PPC::STW, PPC::STD, PPC::STFD, PPC::STFS, PPC::SPILL_CR, PPC::SPILL_CRBIT, \161PPC::STVX, PPC::STXV, PPC::DFSTOREf64, PPC::DFSTOREf32, \162PPC::SPILLTOVSR_ST, PPC::STXVP, PPC::SPILL_ACC, PPC::SPILL_UACC, \163PPC::SPILL_WACC, NoInstr, PPC::SPILL_QUADWORD \164}165166// Initialize arrays for load and store spill opcodes on supported subtargets.167#define StoreOpcodesForSpill \168{ Pwr8StoreOpcodes, Pwr9StoreOpcodes, Pwr10StoreOpcodes, FutureStoreOpcodes }169#define LoadOpcodesForSpill \170{ Pwr8LoadOpcodes, Pwr9LoadOpcodes, Pwr10LoadOpcodes, FutureLoadOpcodes }171172class PPCSubtarget;173class PPCInstrInfo : public PPCGenInstrInfo {174PPCSubtarget &Subtarget;175const PPCRegisterInfo RI;176const unsigned StoreSpillOpcodesArray[4][SOK_LastOpcodeSpill] =177StoreOpcodesForSpill;178const unsigned LoadSpillOpcodesArray[4][SOK_LastOpcodeSpill] =179LoadOpcodesForSpill;180181void StoreRegToStackSlot(MachineFunction &MF, unsigned SrcReg, bool isKill,182int FrameIdx, const TargetRegisterClass *RC,183SmallVectorImpl<MachineInstr *> &NewMIs) const;184void LoadRegFromStackSlot(MachineFunction &MF, const DebugLoc &DL,185unsigned DestReg, int FrameIdx,186const TargetRegisterClass *RC,187SmallVectorImpl<MachineInstr *> &NewMIs) const;188189// Replace the instruction with single LI if possible. \p DefMI must be LI or190// LI8.191bool simplifyToLI(MachineInstr &MI, MachineInstr &DefMI,192unsigned OpNoForForwarding, MachineInstr **KilledDef) const;193// If the inst is imm-form and its register operand is produced by a ADDI, put194// the imm into the inst directly and remove the ADDI if possible.195bool transformToNewImmFormFedByAdd(MachineInstr &MI, MachineInstr &DefMI,196unsigned OpNoForForwarding) const;197// If the inst is x-form and has imm-form and one of its operand is produced198// by a LI, put the imm into the inst directly and remove the LI if possible.199bool transformToImmFormFedByLI(MachineInstr &MI, const ImmInstrInfo &III,200unsigned ConstantOpNo,201MachineInstr &DefMI) const;202// If the inst is x-form and has imm-form and one of its operand is produced203// by an add-immediate, try to transform it when possible.204bool transformToImmFormFedByAdd(MachineInstr &MI, const ImmInstrInfo &III,205unsigned ConstantOpNo, MachineInstr &DefMI,206bool KillDefMI) const;207// Try to find that, if the instruction 'MI' contains any operand that208// could be forwarded from some inst that feeds it. If yes, return the209// Def of that operand. And OpNoForForwarding is the operand index in210// the 'MI' for that 'Def'. If we see another use of this Def between211// the Def and the MI, SeenIntermediateUse becomes 'true'.212MachineInstr *getForwardingDefMI(MachineInstr &MI,213unsigned &OpNoForForwarding,214bool &SeenIntermediateUse) const;215216// Can the user MI have it's source at index \p OpNoForForwarding217// forwarded from an add-immediate that feeds it?218bool isUseMIElgibleForForwarding(MachineInstr &MI, const ImmInstrInfo &III,219unsigned OpNoForForwarding) const;220bool isDefMIElgibleForForwarding(MachineInstr &DefMI,221const ImmInstrInfo &III,222MachineOperand *&ImmMO,223MachineOperand *&RegMO) const;224bool isImmElgibleForForwarding(const MachineOperand &ImmMO,225const MachineInstr &DefMI,226const ImmInstrInfo &III,227int64_t &Imm,228int64_t BaseImm = 0) const;229bool isRegElgibleForForwarding(const MachineOperand &RegMO,230const MachineInstr &DefMI,231const MachineInstr &MI, bool KillDefMI,232bool &IsFwdFeederRegKilled,233bool &SeenIntermediateUse) const;234unsigned getSpillTarget() const;235ArrayRef<unsigned> getStoreOpcodesForSpillArray() const;236ArrayRef<unsigned> getLoadOpcodesForSpillArray() const;237unsigned getSpillIndex(const TargetRegisterClass *RC) const;238int16_t getFMAOpIdxInfo(unsigned Opcode) const;239void reassociateFMA(MachineInstr &Root, unsigned Pattern,240SmallVectorImpl<MachineInstr *> &InsInstrs,241SmallVectorImpl<MachineInstr *> &DelInstrs,242DenseMap<unsigned, unsigned> &InstrIdxForVirtReg) const;243Register244generateLoadForNewConst(unsigned Idx, MachineInstr *MI, Type *Ty,245SmallVectorImpl<MachineInstr *> &InsInstrs) const;246virtual void anchor();247248protected:249/// Commutes the operands in the given instruction.250/// The commutable operands are specified by their indices OpIdx1 and OpIdx2.251///252/// Do not call this method for a non-commutable instruction or for253/// non-commutable pair of operand indices OpIdx1 and OpIdx2.254/// Even though the instruction is commutable, the method may still255/// fail to commute the operands, null pointer is returned in such cases.256///257/// For example, we can commute rlwimi instructions, but only if the258/// rotate amt is zero. We also have to munge the immediates a bit.259MachineInstr *commuteInstructionImpl(MachineInstr &MI, bool NewMI,260unsigned OpIdx1,261unsigned OpIdx2) const override;262263public:264explicit PPCInstrInfo(PPCSubtarget &STI);265266bool isLoadFromConstantPool(MachineInstr *I) const;267const Constant *getConstantFromConstantPool(MachineInstr *I) const;268269/// getRegisterInfo - TargetInstrInfo is a superset of MRegister info. As270/// such, whenever a client has an instance of instruction info, it should271/// always be able to get register info as well (through this method).272///273const PPCRegisterInfo &getRegisterInfo() const { return RI; }274275bool isXFormMemOp(unsigned Opcode) const {276return get(Opcode).TSFlags & PPCII::XFormMemOp;277}278bool isPrefixed(unsigned Opcode) const {279return get(Opcode).TSFlags & PPCII::Prefixed;280}281bool isSExt32To64(unsigned Opcode) const {282return get(Opcode).TSFlags & PPCII::SExt32To64;283}284bool isZExt32To64(unsigned Opcode) const {285return get(Opcode).TSFlags & PPCII::ZExt32To64;286}287288static bool isSameClassPhysRegCopy(unsigned Opcode) {289unsigned CopyOpcodes[] = {PPC::OR, PPC::OR8, PPC::FMR,290PPC::VOR, PPC::XXLOR, PPC::XXLORf,291PPC::XSCPSGNDP, PPC::MCRF, PPC::CROR,292PPC::EVOR, -1U};293for (int i = 0; CopyOpcodes[i] != -1U; i++)294if (Opcode == CopyOpcodes[i])295return true;296return false;297}298299static bool hasPCRelFlag(unsigned TF) {300return TF == PPCII::MO_PCREL_FLAG || TF == PPCII::MO_GOT_TLSGD_PCREL_FLAG ||301TF == PPCII::MO_GOT_TLSLD_PCREL_FLAG ||302TF == PPCII::MO_GOT_TPREL_PCREL_FLAG ||303TF == PPCII::MO_TPREL_PCREL_FLAG || TF == PPCII::MO_TLS_PCREL_FLAG ||304TF == PPCII::MO_GOT_PCREL_FLAG;305}306307static bool hasGOTFlag(unsigned TF) {308return TF == PPCII::MO_GOT_FLAG || TF == PPCII::MO_GOT_TLSGD_PCREL_FLAG ||309TF == PPCII::MO_GOT_TLSLD_PCREL_FLAG ||310TF == PPCII::MO_GOT_TPREL_PCREL_FLAG ||311TF == PPCII::MO_GOT_PCREL_FLAG;312}313314static bool hasTLSFlag(unsigned TF) {315return TF == PPCII::MO_TLSGD_FLAG || TF == PPCII::MO_TPREL_FLAG ||316TF == PPCII::MO_TLSLD_FLAG || TF == PPCII::MO_TLSGDM_FLAG ||317TF == PPCII::MO_GOT_TLSGD_PCREL_FLAG ||318TF == PPCII::MO_GOT_TLSLD_PCREL_FLAG ||319TF == PPCII::MO_GOT_TPREL_PCREL_FLAG || TF == PPCII::MO_TPREL_LO ||320TF == PPCII::MO_TPREL_HA || TF == PPCII::MO_DTPREL_LO ||321TF == PPCII::MO_TLSLD_LO || TF == PPCII::MO_TLS ||322TF == PPCII::MO_TPREL_PCREL_FLAG || TF == PPCII::MO_TLS_PCREL_FLAG;323}324325ScheduleHazardRecognizer *326CreateTargetHazardRecognizer(const TargetSubtargetInfo *STI,327const ScheduleDAG *DAG) const override;328ScheduleHazardRecognizer *329CreateTargetPostRAHazardRecognizer(const InstrItineraryData *II,330const ScheduleDAG *DAG) const override;331332unsigned getInstrLatency(const InstrItineraryData *ItinData,333const MachineInstr &MI,334unsigned *PredCost = nullptr) const override;335336std::optional<unsigned> getOperandLatency(const InstrItineraryData *ItinData,337const MachineInstr &DefMI,338unsigned DefIdx,339const MachineInstr &UseMI,340unsigned UseIdx) const override;341std::optional<unsigned> getOperandLatency(const InstrItineraryData *ItinData,342SDNode *DefNode, unsigned DefIdx,343SDNode *UseNode,344unsigned UseIdx) const override {345return PPCGenInstrInfo::getOperandLatency(ItinData, DefNode, DefIdx,346UseNode, UseIdx);347}348349bool hasLowDefLatency(const TargetSchedModel &SchedModel,350const MachineInstr &DefMI,351unsigned DefIdx) const override {352// Machine LICM should hoist all instructions in low-register-pressure353// situations; none are sufficiently free to justify leaving in a loop354// body.355return false;356}357358bool useMachineCombiner() const override {359return true;360}361362/// When getMachineCombinerPatterns() finds patterns, this function generates363/// the instructions that could replace the original code sequence364void genAlternativeCodeSequence(365MachineInstr &Root, unsigned Pattern,366SmallVectorImpl<MachineInstr *> &InsInstrs,367SmallVectorImpl<MachineInstr *> &DelInstrs,368DenseMap<unsigned, unsigned> &InstrIdxForVirtReg) const override;369370/// Return true when there is potentially a faster code sequence for a fma371/// chain ending in \p Root. All potential patterns are output in the \p372/// P array.373bool getFMAPatterns(MachineInstr &Root, SmallVectorImpl<unsigned> &Patterns,374bool DoRegPressureReduce) const;375376CombinerObjective getCombinerObjective(unsigned Pattern) const override;377378/// Return true when there is potentially a faster code sequence379/// for an instruction chain ending in <Root>. All potential patterns are380/// output in the <Pattern> array.381bool getMachineCombinerPatterns(MachineInstr &Root,382SmallVectorImpl<unsigned> &Patterns,383bool DoRegPressureReduce) const override;384385/// On PowerPC, we leverage machine combiner pass to reduce register pressure386/// when the register pressure is high for one BB.387/// Return true if register pressure for \p MBB is high and ABI is supported388/// to reduce register pressure. Otherwise return false.389bool shouldReduceRegisterPressure(390const MachineBasicBlock *MBB,391const RegisterClassInfo *RegClassInfo) const override;392393/// Fixup the placeholders we put in genAlternativeCodeSequence() for394/// MachineCombiner.395void396finalizeInsInstrs(MachineInstr &Root, unsigned &Pattern,397SmallVectorImpl<MachineInstr *> &InsInstrs) const override;398399bool isAssociativeAndCommutative(const MachineInstr &Inst,400bool Invert) const override;401402/// On PowerPC, we try to reassociate FMA chain which will increase403/// instruction size. Set extension resource length limit to 1 for edge case.404/// Resource Length is calculated by scaled resource usage in getCycles().405/// Because of the division in getCycles(), it returns different cycles due to406/// legacy scaled resource usage. So new resource length may be same with407/// legacy or 1 bigger than legacy.408/// We need to execlude the 1 bigger case even the resource length is not409/// perserved for more FMA chain reassociations on PowerPC.410int getExtendResourceLenLimit() const override { return 1; }411412// PowerPC specific version of setSpecialOperandAttr that copies Flags to MI413// and clears nuw, nsw, and exact flags.414using TargetInstrInfo::setSpecialOperandAttr;415void setSpecialOperandAttr(MachineInstr &MI, uint32_t Flags) const;416417bool isCoalescableExtInstr(const MachineInstr &MI,418Register &SrcReg, Register &DstReg,419unsigned &SubIdx) const override;420Register isLoadFromStackSlot(const MachineInstr &MI,421int &FrameIndex) const override;422bool isReallyTriviallyReMaterializable(const MachineInstr &MI) const override;423Register isStoreToStackSlot(const MachineInstr &MI,424int &FrameIndex) const override;425426bool findCommutedOpIndices(const MachineInstr &MI, unsigned &SrcOpIdx1,427unsigned &SrcOpIdx2) const override;428429void insertNoop(MachineBasicBlock &MBB,430MachineBasicBlock::iterator MI) const override;431432433// Branch analysis.434bool analyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB,435MachineBasicBlock *&FBB,436SmallVectorImpl<MachineOperand> &Cond,437bool AllowModify) const override;438unsigned removeBranch(MachineBasicBlock &MBB,439int *BytesRemoved = nullptr) const override;440unsigned insertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB,441MachineBasicBlock *FBB, ArrayRef<MachineOperand> Cond,442const DebugLoc &DL,443int *BytesAdded = nullptr) const override;444445// Select analysis.446bool canInsertSelect(const MachineBasicBlock &, ArrayRef<MachineOperand> Cond,447Register, Register, Register, int &, int &,448int &) const override;449void insertSelect(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI,450const DebugLoc &DL, Register DstReg,451ArrayRef<MachineOperand> Cond, Register TrueReg,452Register FalseReg) const override;453454void copyPhysReg(MachineBasicBlock &MBB, MachineBasicBlock::iterator I,455const DebugLoc &DL, MCRegister DestReg, MCRegister SrcReg,456bool KillSrc) const override;457458void storeRegToStackSlot(MachineBasicBlock &MBB,459MachineBasicBlock::iterator MBBI, Register SrcReg,460bool isKill, int FrameIndex,461const TargetRegisterClass *RC,462const TargetRegisterInfo *TRI,463Register VReg) const override;464465// Emits a register spill without updating the register class for vector466// registers. This ensures that when we spill a vector register the467// element order in the register is the same as it was in memory.468void storeRegToStackSlotNoUpd(MachineBasicBlock &MBB,469MachineBasicBlock::iterator MBBI,470unsigned SrcReg, bool isKill, int FrameIndex,471const TargetRegisterClass *RC,472const TargetRegisterInfo *TRI) const;473474void loadRegFromStackSlot(MachineBasicBlock &MBB,475MachineBasicBlock::iterator MBBI, Register DestReg,476int FrameIndex, const TargetRegisterClass *RC,477const TargetRegisterInfo *TRI,478Register VReg) const override;479480// Emits a register reload without updating the register class for vector481// registers. This ensures that when we reload a vector register the482// element order in the register is the same as it was in memory.483void loadRegFromStackSlotNoUpd(MachineBasicBlock &MBB,484MachineBasicBlock::iterator MBBI,485unsigned DestReg, int FrameIndex,486const TargetRegisterClass *RC,487const TargetRegisterInfo *TRI) const;488489unsigned getStoreOpcodeForSpill(const TargetRegisterClass *RC) const;490491unsigned getLoadOpcodeForSpill(const TargetRegisterClass *RC) const;492493bool494reverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const override;495496bool foldImmediate(MachineInstr &UseMI, MachineInstr &DefMI, Register Reg,497MachineRegisterInfo *MRI) const override;498499bool onlyFoldImmediate(MachineInstr &UseMI, MachineInstr &DefMI,500Register Reg) const;501502// If conversion by predication (only supported by some branch instructions).503// All of the profitability checks always return true; it is always504// profitable to use the predicated branches.505bool isProfitableToIfCvt(MachineBasicBlock &MBB,506unsigned NumCycles, unsigned ExtraPredCycles,507BranchProbability Probability) const override {508return true;509}510511bool isProfitableToIfCvt(MachineBasicBlock &TMBB,512unsigned NumT, unsigned ExtraT,513MachineBasicBlock &FMBB,514unsigned NumF, unsigned ExtraF,515BranchProbability Probability) const override;516517bool isProfitableToDupForIfCvt(MachineBasicBlock &MBB, unsigned NumCycles,518BranchProbability Probability) const override {519return true;520}521522bool isProfitableToUnpredicate(MachineBasicBlock &TMBB,523MachineBasicBlock &FMBB) const override {524return false;525}526527// Predication support.528bool isPredicated(const MachineInstr &MI) const override;529530bool isSchedulingBoundary(const MachineInstr &MI,531const MachineBasicBlock *MBB,532const MachineFunction &MF) const override;533534bool PredicateInstruction(MachineInstr &MI,535ArrayRef<MachineOperand> Pred) const override;536537bool SubsumesPredicate(ArrayRef<MachineOperand> Pred1,538ArrayRef<MachineOperand> Pred2) const override;539540bool ClobbersPredicate(MachineInstr &MI, std::vector<MachineOperand> &Pred,541bool SkipDead) const override;542543// Comparison optimization.544545bool analyzeCompare(const MachineInstr &MI, Register &SrcReg,546Register &SrcReg2, int64_t &Mask,547int64_t &Value) const override;548549bool optimizeCompareInstr(MachineInstr &CmpInstr, Register SrcReg,550Register SrcReg2, int64_t Mask, int64_t Value,551const MachineRegisterInfo *MRI) const override;552553554/// Return true if get the base operand, byte offset of an instruction and555/// the memory width. Width is the size of memory that is being556/// loaded/stored (e.g. 1, 2, 4, 8).557bool getMemOperandWithOffsetWidth(const MachineInstr &LdSt,558const MachineOperand *&BaseOp,559int64_t &Offset, LocationSize &Width,560const TargetRegisterInfo *TRI) const;561562bool optimizeCmpPostRA(MachineInstr &MI) const;563564/// Get the base operand and byte offset of an instruction that reads/writes565/// memory.566bool getMemOperandsWithOffsetWidth(567const MachineInstr &LdSt,568SmallVectorImpl<const MachineOperand *> &BaseOps, int64_t &Offset,569bool &OffsetIsScalable, LocationSize &Width,570const TargetRegisterInfo *TRI) const override;571572/// Returns true if the two given memory operations should be scheduled573/// adjacent.574bool shouldClusterMemOps(ArrayRef<const MachineOperand *> BaseOps1,575int64_t Offset1, bool OffsetIsScalable1,576ArrayRef<const MachineOperand *> BaseOps2,577int64_t Offset2, bool OffsetIsScalable2,578unsigned ClusterSize,579unsigned NumBytes) const override;580581/// Return true if two MIs access different memory addresses and false582/// otherwise583bool584areMemAccessesTriviallyDisjoint(const MachineInstr &MIa,585const MachineInstr &MIb) const override;586587/// GetInstSize - Return the number of bytes of code the specified588/// instruction may be. This returns the maximum number of bytes.589///590unsigned getInstSizeInBytes(const MachineInstr &MI) const override;591592MCInst getNop() const override;593594std::pair<unsigned, unsigned>595decomposeMachineOperandsTargetFlags(unsigned TF) const override;596597ArrayRef<std::pair<unsigned, const char *>>598getSerializableDirectMachineOperandTargetFlags() const override;599600// Expand VSX Memory Pseudo instruction to either a VSX or a FP instruction.601bool expandVSXMemPseudo(MachineInstr &MI) const;602603// Lower pseudo instructions after register allocation.604bool expandPostRAPseudo(MachineInstr &MI) const override;605606const TargetRegisterClass *updatedRC(const TargetRegisterClass *RC) const;607static int getRecordFormOpcode(unsigned Opcode);608609bool isTOCSaveMI(const MachineInstr &MI) const;610611std::pair<bool, bool>612isSignOrZeroExtended(const unsigned Reg, const unsigned BinOpDepth,613const MachineRegisterInfo *MRI) const;614615// Return true if the register is sign-extended from 32 to 64 bits.616bool isSignExtended(const unsigned Reg,617const MachineRegisterInfo *MRI) const {618return isSignOrZeroExtended(Reg, 0, MRI).first;619}620621// Return true if the register is zero-extended from 32 to 64 bits.622bool isZeroExtended(const unsigned Reg,623const MachineRegisterInfo *MRI) const {624return isSignOrZeroExtended(Reg, 0, MRI).second;625}626627bool convertToImmediateForm(MachineInstr &MI,628SmallSet<Register, 4> &RegsToUpdate,629MachineInstr **KilledDef = nullptr) const;630bool foldFrameOffset(MachineInstr &MI) const;631bool combineRLWINM(MachineInstr &MI, MachineInstr **ToErase = nullptr) const;632bool isADDIInstrEligibleForFolding(MachineInstr &ADDIMI, int64_t &Imm) const;633bool isADDInstrEligibleForFolding(MachineInstr &ADDMI) const;634bool isImmInstrEligibleForFolding(MachineInstr &MI, unsigned &BaseReg,635unsigned &XFormOpcode,636int64_t &OffsetOfImmInstr,637ImmInstrInfo &III) const;638bool isValidToBeChangedReg(MachineInstr *ADDMI, unsigned Index,639MachineInstr *&ADDIMI, int64_t &OffsetAddi,640int64_t OffsetImm) const;641642void replaceInstrWithLI(MachineInstr &MI, const LoadImmediateInfo &LII) const;643void replaceInstrOperandWithImm(MachineInstr &MI, unsigned OpNo,644int64_t Imm) const;645646bool instrHasImmForm(unsigned Opc, bool IsVFReg, ImmInstrInfo &III,647bool PostRA) const;648649// In PostRA phase, try to find instruction defines \p Reg before \p MI.650// \p SeenIntermediate is set to true if uses between DefMI and \p MI exist.651MachineInstr *getDefMIPostRA(unsigned Reg, MachineInstr &MI,652bool &SeenIntermediateUse) const;653654// Materialize immediate after RA.655void materializeImmPostRA(MachineBasicBlock &MBB,656MachineBasicBlock::iterator MBBI,657const DebugLoc &DL, Register Reg,658int64_t Imm) const;659660/// Check \p Opcode is BDNZ (Decrement CTR and branch if it is still nonzero).661bool isBDNZ(unsigned Opcode) const;662663/// Find the hardware loop instruction used to set-up the specified loop.664/// On PPC, we have two instructions used to set-up the hardware loop665/// (MTCTRloop, MTCTR8loop) with corresponding endloop (BDNZ, BDNZ8)666/// instructions to indicate the end of a loop.667MachineInstr *668findLoopInstr(MachineBasicBlock &PreHeader,669SmallPtrSet<MachineBasicBlock *, 8> &Visited) const;670671/// Analyze loop L, which must be a single-basic-block loop, and if the672/// conditions can be understood enough produce a PipelinerLoopInfo object.673std::unique_ptr<TargetInstrInfo::PipelinerLoopInfo>674analyzeLoopForPipelining(MachineBasicBlock *LoopBB) const override;675};676677}678679#endif680681682