xref: /minix3/external/bsd/llvm/dist/llvm/lib/CodeGen/CriticalAntiDepBreaker.h (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1f4a2713aSLionel Sambuc //=- llvm/CodeGen/CriticalAntiDepBreaker.h - Anti-Dep Support -*- C++ -*-=//
2f4a2713aSLionel Sambuc //
3f4a2713aSLionel Sambuc //                     The LLVM Compiler Infrastructure
4f4a2713aSLionel Sambuc //
5f4a2713aSLionel Sambuc // This file is distributed under the University of Illinois Open Source
6f4a2713aSLionel Sambuc // License. See LICENSE.TXT for details.
7f4a2713aSLionel Sambuc //
8f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
9f4a2713aSLionel Sambuc //
10f4a2713aSLionel Sambuc // This file implements the CriticalAntiDepBreaker class, which
11f4a2713aSLionel Sambuc // implements register anti-dependence breaking along a blocks
12f4a2713aSLionel Sambuc // critical path during post-RA scheduler.
13f4a2713aSLionel Sambuc //
14f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
15f4a2713aSLionel Sambuc 
16*0a6a1f1dSLionel Sambuc #ifndef LLVM_LIB_CODEGEN_CRITICALANTIDEPBREAKER_H
17*0a6a1f1dSLionel Sambuc #define LLVM_LIB_CODEGEN_CRITICALANTIDEPBREAKER_H
18f4a2713aSLionel Sambuc 
19f4a2713aSLionel Sambuc #include "AntiDepBreaker.h"
20f4a2713aSLionel Sambuc #include "llvm/ADT/BitVector.h"
21f4a2713aSLionel Sambuc #include "llvm/CodeGen/MachineBasicBlock.h"
22f4a2713aSLionel Sambuc #include "llvm/CodeGen/MachineFrameInfo.h"
23f4a2713aSLionel Sambuc #include "llvm/CodeGen/MachineFunction.h"
24f4a2713aSLionel Sambuc #include "llvm/CodeGen/MachineRegisterInfo.h"
25f4a2713aSLionel Sambuc #include "llvm/CodeGen/RegisterClassInfo.h"
26f4a2713aSLionel Sambuc #include "llvm/CodeGen/ScheduleDAG.h"
27f4a2713aSLionel Sambuc #include <map>
28f4a2713aSLionel Sambuc 
29f4a2713aSLionel Sambuc namespace llvm {
30f4a2713aSLionel Sambuc class RegisterClassInfo;
31f4a2713aSLionel Sambuc class TargetInstrInfo;
32f4a2713aSLionel Sambuc class TargetRegisterInfo;
33f4a2713aSLionel Sambuc 
34f4a2713aSLionel Sambuc   class CriticalAntiDepBreaker : public AntiDepBreaker {
35f4a2713aSLionel Sambuc     MachineFunction& MF;
36f4a2713aSLionel Sambuc     MachineRegisterInfo &MRI;
37f4a2713aSLionel Sambuc     const TargetInstrInfo *TII;
38f4a2713aSLionel Sambuc     const TargetRegisterInfo *TRI;
39f4a2713aSLionel Sambuc     const RegisterClassInfo &RegClassInfo;
40f4a2713aSLionel Sambuc 
41*0a6a1f1dSLionel Sambuc     /// The set of allocatable registers.
42f4a2713aSLionel Sambuc     /// We'll be ignoring anti-dependencies on non-allocatable registers,
43f4a2713aSLionel Sambuc     /// because they may not be safe to break.
44f4a2713aSLionel Sambuc     const BitVector AllocatableSet;
45f4a2713aSLionel Sambuc 
46*0a6a1f1dSLionel Sambuc     /// For live regs that are only used in one register class in a
47f4a2713aSLionel Sambuc     /// live range, the register class. If the register is not live, the
48f4a2713aSLionel Sambuc     /// corresponding value is null. If the register is live but used in
49f4a2713aSLionel Sambuc     /// multiple register classes, the corresponding value is -1 casted to a
50f4a2713aSLionel Sambuc     /// pointer.
51f4a2713aSLionel Sambuc     std::vector<const TargetRegisterClass*> Classes;
52f4a2713aSLionel Sambuc 
53*0a6a1f1dSLionel Sambuc     /// Map registers to all their references within a live range.
54f4a2713aSLionel Sambuc     std::multimap<unsigned, MachineOperand *> RegRefs;
55f4a2713aSLionel Sambuc     typedef std::multimap<unsigned, MachineOperand *>::const_iterator
56f4a2713aSLionel Sambuc       RegRefIter;
57f4a2713aSLionel Sambuc 
58*0a6a1f1dSLionel Sambuc     /// The index of the most recent kill (proceeding bottom-up),
59f4a2713aSLionel Sambuc     /// or ~0u if the register is not live.
60f4a2713aSLionel Sambuc     std::vector<unsigned> KillIndices;
61f4a2713aSLionel Sambuc 
62*0a6a1f1dSLionel Sambuc     /// The index of the most recent complete def (proceeding
63*0a6a1f1dSLionel Sambuc     /// bottom up), or ~0u if the register is live.
64f4a2713aSLionel Sambuc     std::vector<unsigned> DefIndices;
65f4a2713aSLionel Sambuc 
66*0a6a1f1dSLionel Sambuc     /// A set of registers which are live and cannot be changed to
67f4a2713aSLionel Sambuc     /// break anti-dependencies.
68f4a2713aSLionel Sambuc     BitVector KeepRegs;
69f4a2713aSLionel Sambuc 
70f4a2713aSLionel Sambuc   public:
71f4a2713aSLionel Sambuc     CriticalAntiDepBreaker(MachineFunction& MFi, const RegisterClassInfo&);
72f4a2713aSLionel Sambuc     ~CriticalAntiDepBreaker();
73f4a2713aSLionel Sambuc 
74*0a6a1f1dSLionel Sambuc     /// Initialize anti-dep breaking for a new basic block.
75*0a6a1f1dSLionel Sambuc     void StartBlock(MachineBasicBlock *BB) override;
76f4a2713aSLionel Sambuc 
77*0a6a1f1dSLionel Sambuc     /// Identifiy anti-dependencies along the critical path
78f4a2713aSLionel Sambuc     /// of the ScheduleDAG and break them by renaming registers.
79f4a2713aSLionel Sambuc     unsigned BreakAntiDependencies(const std::vector<SUnit>& SUnits,
80f4a2713aSLionel Sambuc                                    MachineBasicBlock::iterator Begin,
81f4a2713aSLionel Sambuc                                    MachineBasicBlock::iterator End,
82f4a2713aSLionel Sambuc                                    unsigned InsertPosIndex,
83*0a6a1f1dSLionel Sambuc                                    DbgValueVector &DbgValues) override;
84f4a2713aSLionel Sambuc 
85*0a6a1f1dSLionel Sambuc     /// Update liveness information to account for the current
86f4a2713aSLionel Sambuc     /// instruction, which will not be scheduled.
87*0a6a1f1dSLionel Sambuc     void Observe(MachineInstr *MI, unsigned Count,
88*0a6a1f1dSLionel Sambuc                  unsigned InsertPosIndex) override;
89f4a2713aSLionel Sambuc 
90*0a6a1f1dSLionel Sambuc     /// Finish anti-dep breaking for a basic block.
91*0a6a1f1dSLionel Sambuc     void FinishBlock() override;
92f4a2713aSLionel Sambuc 
93f4a2713aSLionel Sambuc   private:
94f4a2713aSLionel Sambuc     void PrescanInstruction(MachineInstr *MI);
95f4a2713aSLionel Sambuc     void ScanInstruction(MachineInstr *MI, unsigned Count);
96f4a2713aSLionel Sambuc     bool isNewRegClobberedByRefs(RegRefIter RegRefBegin,
97f4a2713aSLionel Sambuc                                  RegRefIter RegRefEnd,
98f4a2713aSLionel Sambuc                                  unsigned NewReg);
99f4a2713aSLionel Sambuc     unsigned findSuitableFreeRegister(RegRefIter RegRefBegin,
100f4a2713aSLionel Sambuc                                       RegRefIter RegRefEnd,
101f4a2713aSLionel Sambuc                                       unsigned AntiDepReg,
102f4a2713aSLionel Sambuc                                       unsigned LastNewReg,
103f4a2713aSLionel Sambuc                                       const TargetRegisterClass *RC,
104f4a2713aSLionel Sambuc                                       SmallVectorImpl<unsigned> &Forbid);
105f4a2713aSLionel Sambuc   };
106f4a2713aSLionel Sambuc }
107f4a2713aSLionel Sambuc 
108f4a2713aSLionel Sambuc #endif
109