15f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#ifndef HEXAGONVLIWPACKETIZER_H
25f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#define HEXAGONVLIWPACKETIZER_H
35f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
45f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "llvm/CodeGen/DFAPacketizer.h"
50bc735ffcfb223c0186419547abaa5c84482663eChris Lattner#include "llvm/CodeGen/MachineBranchProbabilityInfo.h"
60bc735ffcfb223c0186419547abaa5c84482663eChris Lattner#include "llvm/CodeGen/ScheduleDAG.h"
75f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "llvm/CodeGen/ScheduleDAGInstrs.h"
85f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
95f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace llvm {
105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass HexagonPacketizerList : public VLIWPacketizerList {
115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // Vector of instructions assigned to the packet that has just been created.
125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  std::vector<MachineInstr*> OldPacketMIs;
135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
14c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar  // Has the instruction been promoted to a dot-new instruction.
150979c805475d1ba49b5d6ef93c4d2ce6d2eab6edDouglas Gregor  bool PromotedToDotNew;
16a4d55d89c8076b402bb168e3edeef0c2cd2a78c3Chris Lattner
172eadfb638eb1bb6ccfd6fd0453e764d47e27eed9Chris Lattner  // Has the instruction been glued to allocframe.
18a4d55d89c8076b402bb168e3edeef0c2cd2a78c3Chris Lattner  bool GlueAllocframeStore;
1998cd599ee8a9b259ed7388ee2921a20d97658864Douglas Gregor
20aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor  // Has the feeder instruction been glued to new value jump.
2119cc4abea06a9b49e0e16a50d335c064cd723572Anders Carlsson  bool GlueToNewValueJump;
225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2308f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner  // Check if there is a dependence between some instruction already in this
2408f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner  // packet and this instruction.
257a614d8380297fcd2bc23986241905d97222948cRichard Smith  bool Dependence;
261b63e4f732dbc73d90abf886b4d21f8e3a165f6dChris Lattner
2708f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner  // Only check for dependence if there are resources available to
28da5a6b6d9fd52899499d5b7b46273ec844dcaa6eChris Lattner  // schedule this instruction.
29cf3293eaeb3853d12cff47e648bbe835004e929fDouglas Gregor  bool FoundSequentialDependence;
303a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson
31ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  // Track MIs with ignored dependence.
325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  std::vector<MachineInstr*> IgnoreDepMIs;
335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
342b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattnerprotected:
352b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner  /// \brief A handle to the branch probability pass.
362b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner  const MachineBranchProbabilityInfo *MBPI;
372b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner  const MachineLoopInfo *MLI;
382b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner
39f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourneprivate:
40f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne  const HexagonInstrInfo *HII;
412b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner  const HexagonRegisterInfo *HRI;
42f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne
43c302113179a1c2b1254224ea9b6f5316ceeb375cSean Huntpublic:
44f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne  // Ctor.
45c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  HexagonPacketizerList(MachineFunction &MF, MachineLoopInfo &MLI,
46f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne                        AliasAnalysis *AA,
472b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner                        const MachineBranchProbabilityInfo *MBPI);
482de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall
492b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner  // initPacketizerState - initialize some internal flags.
502b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner  void initPacketizerState() override;
512b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner
522b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner  // ignorePseudoInstruction - Ignore bundling of pseudo instructions.
532b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner  bool ignorePseudoInstruction(const MachineInstr *MI,
54c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt                               const MachineBasicBlock *MBB) override;
556907fbe758d23e1aec4c0a67e7b633d1d855feb4John McCall
566907fbe758d23e1aec4c0a67e7b633d1d855feb4John McCall  // isSoloInstruction - return true if instruction MI can not be packetized
57f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne  // with any other instruction, which means that MI itself is a packet.
582b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner  bool isSoloInstruction(const MachineInstr *MI) override;
59c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
60f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne  // isLegalToPacketizeTogether - Is it legal to packetize SUI and SUJ
612b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner  // together.
622b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner  bool isLegalToPacketizeTogether(SUnit *SUI, SUnit *SUJ) override;
632de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall
642de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  // isLegalToPruneDependencies - Is it legal to prune dependece between SUI
652de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  // and SUJ.
662de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  bool isLegalToPruneDependencies(SUnit *SUI, SUnit *SUJ) override;
672de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall
682de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  MachineBasicBlock::iterator addToPacket(MachineInstr *MI) override;
692de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  void endPacket(MachineBasicBlock *MBB, MachineInstr *MI) override;
702de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  bool shouldAddToPacket(const MachineInstr *MI) override;
712b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner
72c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  void unpacketizeSoloInstrs(MachineFunction &MF);
732de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall
742de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCallprotected:
752de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  bool isCallDependent(const MachineInstr* MI, SDep::Kind DepType,
762b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner                       unsigned DepReg);
772b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner  bool promoteToDotCur(MachineInstr* MI, SDep::Kind DepType,
782b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner                       MachineBasicBlock::iterator &MII,
79c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt                       const TargetRegisterClass* RC);
802de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  bool canPromoteToDotCur(const MachineInstr* MI, const SUnit* PacketSU,
812de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall                          unsigned DepReg, MachineBasicBlock::iterator &MII,
822b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner                          const TargetRegisterClass* RC);
832b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner  void cleanUpDotCur();
842b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner
85c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  bool promoteToDotNew(MachineInstr* MI, SDep::Kind DepType,
86f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne                       MachineBasicBlock::iterator &MII,
872b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner                       const TargetRegisterClass* RC);
882b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner  bool canPromoteToDotNew(const MachineInstr* MI, const SUnit* PacketSU,
89c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt                          unsigned DepReg, MachineBasicBlock::iterator &MII,
902b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner                          const TargetRegisterClass* RC);
912b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner  bool canPromoteToNewValue(const MachineInstr* MI, const SUnit* PacketSU,
922b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner                            unsigned DepReg, MachineBasicBlock::iterator &MII);
9363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  bool canPromoteToNewValueStore(const MachineInstr* MI,
9463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall                                 const MachineInstr* PacketMI, unsigned DepReg);
9563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  bool demoteToDotOld(MachineInstr* MI);
9663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  bool arePredicatesComplements(MachineInstr* MI1, MachineInstr* MI2);
9763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  bool restrictingDepExistInPacket(MachineInstr*, unsigned);
9863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  bool isNewifiable(const MachineInstr *MI);
9963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  bool isCurifiable(MachineInstr* MI);
10063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  bool cannotCoexist(const MachineInstr *MI, const MachineInstr *MJ);
10163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  inline bool isPromotedToDotNew() const {
10263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return PromotedToDotNew;
10363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
10463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  bool tryAllocateResourcesForConstExt(bool Reserve);
10563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  bool canReserveResourcesForConstExt();
10663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  void reserveResourcesForConstExt();
10763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  bool hasDeadDependence(const MachineInstr *I, const MachineInstr *J);
10863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  bool hasControlDependence(const MachineInstr *I, const MachineInstr *J);
10963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  bool hasV4SpecificDependence(const MachineInstr *I, const MachineInstr *J);
11063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  bool producesStall(const MachineInstr *MI);
11163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall};
11263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall} // namespace llvm
11363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall#endif // HEXAGONVLIWPACKETIZER_H
11463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall
11563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall