| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
#ifndef LLVM_CODEGEN_SCHEDULEDFS_H |
| 14 |
#define LLVM_CODEGEN_SCHEDULEDFS_H |
| 15 |
|
| 16 |
#include "llvm/ADT/SmallVector.h" |
| 17 |
#include "llvm/CodeGen/ScheduleDAG.h" |
| 18 |
#include <cassert> |
| 19 |
#include <cstdint> |
| 20 |
#include <vector> |
| 21 |
|
| 22 |
namespace llvm { |
| 23 |
|
| 24 |
template <typename T> class ArrayRef; |
| 25 |
class raw_ostream; |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
struct ILPValue { |
| 35 |
unsigned InstrCount; |
| 36 |
|
| 37 |
|
| 38 |
unsigned Length; |
| 39 |
|
| 40 |
ILPValue(unsigned count, unsigned length): |
| 41 |
InstrCount(count), Length(length) {} |
| 42 |
|
| 43 |
|
| 44 |
bool operator<(ILPValue RHS) const { |
| 45 |
return (uint64_t)InstrCount * RHS.Length |
| 46 |
< (uint64_t)Length * RHS.InstrCount; |
| 47 |
} |
| 48 |
bool operator>(ILPValue RHS) const { |
| 49 |
return RHS < *this; |
| 50 |
} |
| 51 |
bool operator<=(ILPValue RHS) const { |
| 52 |
return (uint64_t)InstrCount * RHS.Length |
| 53 |
<= (uint64_t)Length * RHS.InstrCount; |
| 54 |
} |
| 55 |
bool operator>=(ILPValue RHS) const { |
| 56 |
return RHS <= *this; |
| 57 |
} |
| 58 |
|
| 59 |
void print(raw_ostream &OS) const; |
| 60 |
|
| 61 |
void dump() const; |
| 62 |
}; |
| 63 |
|
| 64 |
|
| 65 |
class SchedDFSResult { |
| 66 |
friend class SchedDFSImpl; |
| 67 |
|
| 68 |
static const unsigned InvalidSubtreeID = ~0u; |
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
struct NodeData { |
| 77 |
unsigned InstrCount = 0; |
| 78 |
unsigned SubtreeID = InvalidSubtreeID; |
| 79 |
|
| 80 |
NodeData() = default; |
| 81 |
}; |
| 82 |
|
| 83 |
|
| 84 |
struct TreeData { |
| 85 |
unsigned ParentTreeID = InvalidSubtreeID; |
| 86 |
unsigned SubInstrCount = 0; |
| 87 |
|
| 88 |
TreeData() = default; |
| 89 |
}; |
| 90 |
|
| 91 |
|
| 92 |
struct Connection { |
| 93 |
unsigned TreeID; |
| 94 |
unsigned Level; |
| 95 |
|
| 96 |
Connection(unsigned tree, unsigned level): TreeID(tree), Level(level) {} |
| 97 |
}; |
| 98 |
|
| 99 |
bool IsBottomUp; |
| 100 |
unsigned SubtreeLimit; |
| 101 |
|
| 102 |
std::vector<NodeData> DFSNodeData; |
| 103 |
|
| 104 |
|
| 105 |
SmallVector<TreeData, 16> DFSTreeData; |
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
std::vector<SmallVector<Connection, 4>> SubtreeConnections; |
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
std::vector<unsigned> SubtreeConnectLevels; |
| 114 |
|
| 115 |
public: |
| 116 |
SchedDFSResult(bool IsBU, unsigned lim) |
| 117 |
: IsBottomUp(IsBU), SubtreeLimit(lim) {} |
| 118 |
|
| 119 |
|
| 120 |
unsigned getSubtreeLimit() const { return SubtreeLimit; } |
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
bool empty() const { return DFSNodeData.empty(); } |
| 126 |
|
| 127 |
|
| 128 |
void clear() { |
| 129 |
DFSNodeData.clear(); |
| 130 |
DFSTreeData.clear(); |
| 131 |
SubtreeConnections.clear(); |
| 132 |
SubtreeConnectLevels.clear(); |
| 133 |
} |
| 134 |
|
| 135 |
|
| 136 |
void resize(unsigned NumSUnits) { |
| 137 |
DFSNodeData.resize(NumSUnits); |
| 138 |
} |
| 139 |
|
| 140 |
|
| 141 |
void compute(ArrayRef<SUnit> SUnits); |
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
unsigned getNumInstrs(const SUnit *SU) const { |
| 146 |
return DFSNodeData[SU->NodeNum].InstrCount; |
| 147 |
} |
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
unsigned getNumSubInstrs(unsigned SubtreeID) const { |
| 152 |
return DFSTreeData[SubtreeID].SubInstrCount; |
| 153 |
} |
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
ILPValue getILP(const SUnit *SU) const { |
| 159 |
return ILPValue(DFSNodeData[SU->NodeNum].InstrCount, 1 + SU->getDepth()); |
| 160 |
} |
| 161 |
|
| 162 |
|
| 163 |
unsigned getNumSubtrees() const { return SubtreeConnectLevels.size(); } |
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
unsigned getSubtreeID(const SUnit *SU) const { |
| 170 |
if (empty()) |
| 171 |
return 0; |
| 172 |
assert(SU->NodeNum < DFSNodeData.size() && "New Node"); |
| 173 |
return DFSNodeData[SU->NodeNum].SubtreeID; |
| 174 |
} |
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
unsigned getSubtreeLevel(unsigned SubtreeID) const { |
| 181 |
return SubtreeConnectLevels[SubtreeID]; |
| 182 |
} |
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
void scheduleTree(unsigned SubtreeID); |
| 187 |
}; |
| 188 |
|
| 189 |
raw_ostream &operator<<(raw_ostream &OS, const ILPValue &Val); |
| 190 |
|
| 191 |
} |
| 192 |
|
| 193 |
#endif |