Get rid of static constructors for pass registration. Instead, every pass exposes...
[oota-llvm.git] / include / llvm / CodeGen / CalcSpillWeights.h
1 //===---------------- lib/CodeGen/CalcSpillWeights.h ------------*- 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
11 #ifndef LLVM_CODEGEN_CALCSPILLWEIGHTS_H
12 #define LLVM_CODEGEN_CALCSPILLWEIGHTS_H
13
14 #include "llvm/CodeGen/MachineFunctionPass.h"
15 #include "llvm/ADT/DenseMap.h"
16
17 namespace llvm {
18
19   class LiveInterval;
20   class LiveIntervals;
21   class MachineLoopInfo;
22
23   /// VirtRegAuxInfo - Calculate auxiliary information for a virtual
24   /// register such as its spill weight and allocation hint.
25   class VirtRegAuxInfo {
26     MachineFunction &mf_;
27     LiveIntervals &lis_;
28     const MachineLoopInfo &loops_;
29     DenseMap<unsigned, float> hint_;
30   public:
31     VirtRegAuxInfo(MachineFunction &mf, LiveIntervals &lis,
32                    const MachineLoopInfo &loops) :
33       mf_(mf), lis_(lis), loops_(loops) {}
34
35     /// CalculateRegClass - recompute the register class for reg from its uses.
36     /// Since the register class can affect the allocation hint, this function
37     /// should be called before CalculateWeightAndHint if both are called.
38     void CalculateRegClass(unsigned reg);
39
40     /// CalculateWeightAndHint - (re)compute li's spill weight and allocation
41     /// hint.
42     void CalculateWeightAndHint(LiveInterval &li);
43   };
44
45   /// CalculateSpillWeights - Compute spill weights for all virtual register
46   /// live intervals.
47   class CalculateSpillWeights : public MachineFunctionPass {
48   public:
49     static char ID;
50
51     CalculateSpillWeights() : MachineFunctionPass(ID) {
52       initializeCalculateSpillWeightsPass(*PassRegistry::getPassRegistry());
53     }
54
55     virtual void getAnalysisUsage(AnalysisUsage &au) const;
56
57     virtual bool runOnMachineFunction(MachineFunction &fn);
58
59   private:
60     /// Returns true if the given live interval is zero length.
61     bool isZeroLengthInterval(LiveInterval *li) const;
62   };
63
64 }
65
66 #endif // LLVM_CODEGEN_CALCSPILLWEIGHTS_H