misched: rename ScheduleDAGILP to ScheduleDFS to prepare for other heuristics.
[oota-llvm.git] / include / llvm / CodeGen / ScheduleDFS.h
1 //===- ScheduleDAGILP.h - ILP metric for ScheduleDAGInstrs ------*- 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 // Definition of an ILP metric for machine level instruction scheduling.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_CODEGEN_SCHEDULEDAGILP_H
15 #define LLVM_CODEGEN_SCHEDULEDAGILP_H
16
17 #include "llvm/Support/DataTypes.h"
18 #include <vector>
19
20 namespace llvm {
21
22 class raw_ostream;
23 class ScheduleDAGInstrs;
24 class SUnit;
25
26 /// \brief Represent the ILP of the subDAG rooted at a DAG node.
27 struct ILPValue {
28   unsigned InstrCount;
29   unsigned Cycles;
30
31   ILPValue(): InstrCount(0), Cycles(0) {}
32
33   ILPValue(unsigned count, unsigned cycles):
34     InstrCount(count), Cycles(cycles) {}
35
36   bool isValid() const { return Cycles > 0; }
37
38   // Order by the ILP metric's value.
39   bool operator<(ILPValue RHS) const {
40     return (uint64_t)InstrCount * RHS.Cycles
41       < (uint64_t)Cycles * RHS.InstrCount;
42   }
43   bool operator>(ILPValue RHS) const {
44     return RHS < *this;
45   }
46   bool operator<=(ILPValue RHS) const {
47     return (uint64_t)InstrCount * RHS.Cycles
48       <= (uint64_t)Cycles * RHS.InstrCount;
49   }
50   bool operator>=(ILPValue RHS) const {
51     return RHS <= *this;
52   }
53
54 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
55   void print(raw_ostream &OS) const;
56
57   void dump() const;
58 #endif
59 };
60
61 /// \brief Compute the values of each DAG node for an ILP metric.
62 ///
63 /// This metric assumes that the DAG is a forest of trees with roots at the
64 /// bottom of the schedule.
65 class ScheduleDAGILP {
66   bool IsBottomUp;
67   std::vector<ILPValue> ILPValues;
68
69 public:
70   ScheduleDAGILP(bool IsBU): IsBottomUp(IsBU) {}
71
72   /// \brief Initialize the result data with the size of the DAG.
73   void resize(unsigned NumSUnits);
74
75   /// \brief Compute the ILP metric for the subDAG at this root.
76   void computeILP(const SUnit *Root);
77
78   /// \brief Get the ILP value for a DAG node.
79   ILPValue getILP(const SUnit *SU);
80 };
81
82 raw_ostream &operator<<(raw_ostream &OS, const ILPValue &Val);
83
84 } // namespace llvm
85
86 #endif