10b57cec5SDimitry Andric //===- HexagonPacketizer.h - VLIW packetizer --------------------*- C++ -*-===// 20b57cec5SDimitry Andric // 30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 60b57cec5SDimitry Andric // 70b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 80b57cec5SDimitry Andric 90b57cec5SDimitry Andric #ifndef LLVM_LIB_TARGET_HEXAGON_HEXAGONVLIWPACKETIZER_H 100b57cec5SDimitry Andric #define LLVM_LIB_TARGET_HEXAGON_HEXAGONVLIWPACKETIZER_H 110b57cec5SDimitry Andric 120b57cec5SDimitry Andric #include "llvm/CodeGen/DFAPacketizer.h" 130b57cec5SDimitry Andric #include "llvm/CodeGen/MachineBasicBlock.h" 140b57cec5SDimitry Andric #include "llvm/CodeGen/ScheduleDAG.h" 150b57cec5SDimitry Andric #include <vector> 160b57cec5SDimitry Andric 170b57cec5SDimitry Andric namespace llvm { 180b57cec5SDimitry Andric 190b57cec5SDimitry Andric class HexagonInstrInfo; 200b57cec5SDimitry Andric class HexagonRegisterInfo; 210b57cec5SDimitry Andric class MachineBranchProbabilityInfo; 220b57cec5SDimitry Andric class MachineFunction; 230b57cec5SDimitry Andric class MachineInstr; 240b57cec5SDimitry Andric class MachineLoopInfo; 250b57cec5SDimitry Andric class TargetRegisterClass; 260b57cec5SDimitry Andric 270b57cec5SDimitry Andric class HexagonPacketizerList : public VLIWPacketizerList { 280b57cec5SDimitry Andric // Vector of instructions assigned to the packet that has just been created. 290b57cec5SDimitry Andric std::vector<MachineInstr *> OldPacketMIs; 300b57cec5SDimitry Andric 310b57cec5SDimitry Andric // Has the instruction been promoted to a dot-new instruction. 320b57cec5SDimitry Andric bool PromotedToDotNew; 330b57cec5SDimitry Andric 340b57cec5SDimitry Andric // Has the instruction been glued to allocframe. 350b57cec5SDimitry Andric bool GlueAllocframeStore; 360b57cec5SDimitry Andric 370b57cec5SDimitry Andric // Has the feeder instruction been glued to new value jump. 380b57cec5SDimitry Andric bool GlueToNewValueJump; 390b57cec5SDimitry Andric 400b57cec5SDimitry Andric // This holds the offset value, when pruning the dependences. 410b57cec5SDimitry Andric int64_t ChangedOffset; 420b57cec5SDimitry Andric 430b57cec5SDimitry Andric // Check if there is a dependence between some instruction already in this 440b57cec5SDimitry Andric // packet and this instruction. 450b57cec5SDimitry Andric bool Dependence; 460b57cec5SDimitry Andric 470b57cec5SDimitry Andric // Only check for dependence if there are resources available to 480b57cec5SDimitry Andric // schedule this instruction. 490b57cec5SDimitry Andric bool FoundSequentialDependence; 500b57cec5SDimitry Andric 510b57cec5SDimitry Andric bool MemShufDisabled = false; 520b57cec5SDimitry Andric 530b57cec5SDimitry Andric // Track MIs with ignored dependence. 540b57cec5SDimitry Andric std::vector<MachineInstr*> IgnoreDepMIs; 550b57cec5SDimitry Andric 560b57cec5SDimitry Andric // Set to true if the packet contains an instruction that stalls with an 570b57cec5SDimitry Andric // instruction from the previous packet. 580b57cec5SDimitry Andric bool PacketStalls = false; 59*04eeddc0SDimitry Andric // Set to the number of cycles of stall a given instruction will incur 60*04eeddc0SDimitry Andric // because of dependence on instruction in previous packet. 61*04eeddc0SDimitry Andric unsigned int PacketStallCycles = 0; 620b57cec5SDimitry Andric 635ffd83dbSDimitry Andric // Set to true if the packet has a duplex pair of sub-instructions. 645ffd83dbSDimitry Andric bool PacketHasDuplex = false; 655ffd83dbSDimitry Andric 665ffd83dbSDimitry Andric // Set to true if the packet has a instruction that can only be executed 675ffd83dbSDimitry Andric // in SLOT0. 685ffd83dbSDimitry Andric bool PacketHasSLOT0OnlyInsn = false; 695ffd83dbSDimitry Andric 700b57cec5SDimitry Andric protected: 710b57cec5SDimitry Andric /// A handle to the branch probability pass. 720b57cec5SDimitry Andric const MachineBranchProbabilityInfo *MBPI; 730b57cec5SDimitry Andric const MachineLoopInfo *MLI; 740b57cec5SDimitry Andric 750b57cec5SDimitry Andric private: 760b57cec5SDimitry Andric const HexagonInstrInfo *HII; 770b57cec5SDimitry Andric const HexagonRegisterInfo *HRI; 780b57cec5SDimitry Andric const bool Minimal; 790b57cec5SDimitry Andric 800b57cec5SDimitry Andric public: 810b57cec5SDimitry Andric HexagonPacketizerList(MachineFunction &MF, MachineLoopInfo &MLI, 828bcb0991SDimitry Andric AAResults *AA, const MachineBranchProbabilityInfo *MBPI, 830b57cec5SDimitry Andric bool Minimal); 840b57cec5SDimitry Andric 850b57cec5SDimitry Andric // initPacketizerState - initialize some internal flags. 860b57cec5SDimitry Andric void initPacketizerState() override; 870b57cec5SDimitry Andric 880b57cec5SDimitry Andric // ignorePseudoInstruction - Ignore bundling of pseudo instructions. 890b57cec5SDimitry Andric bool ignorePseudoInstruction(const MachineInstr &MI, 900b57cec5SDimitry Andric const MachineBasicBlock *MBB) override; 910b57cec5SDimitry Andric 920b57cec5SDimitry Andric // isSoloInstruction - return true if instruction MI can not be packetized 930b57cec5SDimitry Andric // with any other instruction, which means that MI itself is a packet. 940b57cec5SDimitry Andric bool isSoloInstruction(const MachineInstr &MI) override; 950b57cec5SDimitry Andric 960b57cec5SDimitry Andric // isLegalToPacketizeTogether - Is it legal to packetize SUI and SUJ 970b57cec5SDimitry Andric // together. 980b57cec5SDimitry Andric bool isLegalToPacketizeTogether(SUnit *SUI, SUnit *SUJ) override; 990b57cec5SDimitry Andric 1000b57cec5SDimitry Andric // isLegalToPruneDependencies - Is it legal to prune dependece between SUI 1010b57cec5SDimitry Andric // and SUJ. 1020b57cec5SDimitry Andric bool isLegalToPruneDependencies(SUnit *SUI, SUnit *SUJ) override; 1030b57cec5SDimitry Andric 1040b57cec5SDimitry Andric bool foundLSInPacket(); 1050b57cec5SDimitry Andric MachineBasicBlock::iterator addToPacket(MachineInstr &MI) override; 1060b57cec5SDimitry Andric void endPacket(MachineBasicBlock *MBB, 1070b57cec5SDimitry Andric MachineBasicBlock::iterator MI) override; 1080b57cec5SDimitry Andric bool shouldAddToPacket(const MachineInstr &MI) override; 1090b57cec5SDimitry Andric 1100b57cec5SDimitry Andric void unpacketizeSoloInstrs(MachineFunction &MF); 1110b57cec5SDimitry Andric 1120b57cec5SDimitry Andric protected: getmemShufDisabled()1130b57cec5SDimitry Andric bool getmemShufDisabled() { 1140b57cec5SDimitry Andric return MemShufDisabled; 1150b57cec5SDimitry Andric }; setmemShufDisabled(bool val)1160b57cec5SDimitry Andric void setmemShufDisabled(bool val) { 1170b57cec5SDimitry Andric MemShufDisabled = val; 1180b57cec5SDimitry Andric }; 1190b57cec5SDimitry Andric bool isCallDependent(const MachineInstr &MI, SDep::Kind DepType, 1200b57cec5SDimitry Andric unsigned DepReg); 1210b57cec5SDimitry Andric bool promoteToDotCur(MachineInstr &MI, SDep::Kind DepType, 1220b57cec5SDimitry Andric MachineBasicBlock::iterator &MII, 1230b57cec5SDimitry Andric const TargetRegisterClass *RC); 1240b57cec5SDimitry Andric bool canPromoteToDotCur(const MachineInstr &MI, const SUnit *PacketSU, 1250b57cec5SDimitry Andric unsigned DepReg, MachineBasicBlock::iterator &MII, 1260b57cec5SDimitry Andric const TargetRegisterClass *RC); 1270b57cec5SDimitry Andric void cleanUpDotCur(); 1280b57cec5SDimitry Andric 1290b57cec5SDimitry Andric bool promoteToDotNew(MachineInstr &MI, SDep::Kind DepType, 1300b57cec5SDimitry Andric MachineBasicBlock::iterator &MII, 1310b57cec5SDimitry Andric const TargetRegisterClass *RC); 1320b57cec5SDimitry Andric bool canPromoteToDotNew(const MachineInstr &MI, const SUnit *PacketSU, 1330b57cec5SDimitry Andric unsigned DepReg, MachineBasicBlock::iterator &MII, 1340b57cec5SDimitry Andric const TargetRegisterClass *RC); 1350b57cec5SDimitry Andric bool canPromoteToNewValue(const MachineInstr &MI, const SUnit *PacketSU, 1360b57cec5SDimitry Andric unsigned DepReg, MachineBasicBlock::iterator &MII); 1370b57cec5SDimitry Andric bool canPromoteToNewValueStore(const MachineInstr &MI, 1380b57cec5SDimitry Andric const MachineInstr &PacketMI, unsigned DepReg); 1390b57cec5SDimitry Andric bool demoteToDotOld(MachineInstr &MI); 1400b57cec5SDimitry Andric bool useCallersSP(MachineInstr &MI); 1410b57cec5SDimitry Andric void useCalleesSP(MachineInstr &MI); 1420b57cec5SDimitry Andric bool updateOffset(SUnit *SUI, SUnit *SUJ); 1430b57cec5SDimitry Andric void undoChangedOffset(MachineInstr &MI); 1440b57cec5SDimitry Andric bool arePredicatesComplements(MachineInstr &MI1, MachineInstr &MI2); 1450b57cec5SDimitry Andric bool restrictingDepExistInPacket(MachineInstr&, unsigned); 1460b57cec5SDimitry Andric bool isNewifiable(const MachineInstr &MI, const TargetRegisterClass *NewRC); 1470b57cec5SDimitry Andric bool isCurifiable(MachineInstr &MI); 1480b57cec5SDimitry Andric bool cannotCoexist(const MachineInstr &MI, const MachineInstr &MJ); 1490b57cec5SDimitry Andric isPromotedToDotNew()1500b57cec5SDimitry Andric bool isPromotedToDotNew() const { 1510b57cec5SDimitry Andric return PromotedToDotNew; 1520b57cec5SDimitry Andric } 1530b57cec5SDimitry Andric 1540b57cec5SDimitry Andric bool tryAllocateResourcesForConstExt(bool Reserve); 1550b57cec5SDimitry Andric bool canReserveResourcesForConstExt(); 1560b57cec5SDimitry Andric void reserveResourcesForConstExt(); 1570b57cec5SDimitry Andric bool hasDeadDependence(const MachineInstr &I, const MachineInstr &J); 1580b57cec5SDimitry Andric bool hasControlDependence(const MachineInstr &I, const MachineInstr &J); 1590b57cec5SDimitry Andric bool hasRegMaskDependence(const MachineInstr &I, const MachineInstr &J); 1600b57cec5SDimitry Andric bool hasDualStoreDependence(const MachineInstr &I, const MachineInstr &J); 1610b57cec5SDimitry Andric bool producesStall(const MachineInstr &MI); 162*04eeddc0SDimitry Andric unsigned int calcStall(const MachineInstr &MI); 1630b57cec5SDimitry Andric }; 1640b57cec5SDimitry Andric 1650b57cec5SDimitry Andric } // end namespace llvm 1660b57cec5SDimitry Andric 1670b57cec5SDimitry Andric #endif // LLVM_LIB_TARGET_HEXAGON_HEXAGONVLIWPACKETIZER_H 168