summaryrefslogtreecommitdiff
path: root/include/llvm/CodeGen/ScheduleDAGILP.h
blob: 1aa4058421734a2a020ab514333cd43bc11818d4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
//===- ScheduleDAGILP.h - ILP metric for ScheduleDAGInstrs ------*- C++ -*-===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// Definition of an ILP metric for machine level instruction scheduling.
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_CODEGEN_SCHEDULEDAGILP_H
#define LLVM_CODEGEN_SCHEDULEDAGILP_H

#include "llvm/Support/DataTypes.h"
#include <vector>

namespace llvm {

class raw_ostream;
class ScheduleDAGInstrs;
class SUnit;

/// \brief Represent the ILP of the subDAG rooted at a DAG node.
struct ILPValue {
  unsigned InstrCount;
  unsigned Cycles;

  ILPValue(): InstrCount(0), Cycles(0) {}

  ILPValue(unsigned count, unsigned cycles):
    InstrCount(count), Cycles(cycles) {}

  bool isValid() const { return Cycles > 0; }

  // Order by the ILP metric's value.
  bool operator<(ILPValue RHS) const {
    return (uint64_t)InstrCount * RHS.Cycles
      < (uint64_t)Cycles * RHS.InstrCount;
  }
  bool operator>(ILPValue RHS) const {
    return RHS < *this;
  }
  bool operator<=(ILPValue RHS) const {
    return (uint64_t)InstrCount * RHS.Cycles
      <= (uint64_t)Cycles * RHS.InstrCount;
  }
  bool operator>=(ILPValue RHS) const {
    return RHS <= *this;
  }

#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
  void print(raw_ostream &OS) const;

  void dump() const;
#endif
};

/// \brief Compute the values of each DAG node for an ILP metric.
///
/// This metric assumes that the DAG is a forest of trees with roots at the
/// bottom of the schedule.
class ScheduleDAGILP {
  bool IsBottomUp;
  std::vector<ILPValue> ILPValues;

public:
  ScheduleDAGILP(bool IsBU): IsBottomUp(IsBU) {}

  /// \brief Initialize the result data with the size of the DAG.
  void resize(unsigned NumSUnits);

  /// \brief Compute the ILP metric for the subDAG at this root.
  void computeILP(const SUnit *Root);

  /// \brief Get the ILP value for a DAG node.
  ILPValue getILP(const SUnit *SU);
};

raw_ostream &operator<<(raw_ostream &OS, const ILPValue &Val);

} // namespace llvm

#endif