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