| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
#ifndef LLVM_CODEGEN_TARGETSCHEDULE_H |
| 16 |
#define LLVM_CODEGEN_TARGETSCHEDULE_H |
| 17 |
|
| 18 |
#include "llvm/ADT/SmallVector.h" |
| 19 |
#include "llvm/CodeGen/TargetSubtargetInfo.h" |
| 20 |
#include "llvm/Config/llvm-config.h" |
| 21 |
#include "llvm/MC/MCInstrItineraries.h" |
| 22 |
#include "llvm/MC/MCSchedule.h" |
| 23 |
|
| 24 |
namespace llvm { |
| 25 |
|
| 26 |
class MachineInstr; |
| 27 |
class TargetInstrInfo; |
| 28 |
|
| 29 |
|
| 30 |
class TargetSchedModel { |
| 31 |
|
| 32 |
|
| 33 |
MCSchedModel SchedModel; |
| 34 |
InstrItineraryData InstrItins; |
| 35 |
const TargetSubtargetInfo *STI = nullptr; |
| 36 |
const TargetInstrInfo *TII = nullptr; |
| 37 |
|
| 38 |
SmallVector<unsigned, 16> ResourceFactors; |
| 39 |
|
| 40 |
|
| 41 |
unsigned MicroOpFactor = 0; |
| 42 |
|
| 43 |
|
| 44 |
unsigned ResourceLCM = 0; |
| 45 |
|
| 46 |
unsigned computeInstrLatency(const MCSchedClassDesc &SCDesc) const; |
| 47 |
|
| 48 |
public: |
| 49 |
TargetSchedModel() : SchedModel(MCSchedModel::GetDefaultSchedModel()) {} |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
void init(const TargetSubtargetInfo *TSInfo); |
| 57 |
|
| 58 |
|
| 59 |
const MCSchedClassDesc *resolveSchedClass(const MachineInstr *MI) const; |
| 60 |
|
| 61 |
|
| 62 |
const TargetSubtargetInfo *getSubtargetInfo() const { return STI; } |
| 63 |
|
| 64 |
|
| 65 |
const TargetInstrInfo *getInstrInfo() const { return TII; } |
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
bool hasInstrSchedModel() const; |
| 73 |
|
| 74 |
const MCSchedModel *getMCSchedModel() const { return &SchedModel; } |
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
bool hasInstrItineraries() const; |
| 81 |
|
| 82 |
const InstrItineraryData *getInstrItineraries() const { |
| 83 |
if (hasInstrItineraries()) |
| 84 |
return &InstrItins; |
| 85 |
return nullptr; |
| 86 |
} |
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
bool hasInstrSchedModelOrItineraries() const { |
| 91 |
return hasInstrSchedModel() || hasInstrItineraries(); |
| 92 |
} |
| 93 |
|
| 94 |
|
| 95 |
unsigned getProcessorID() const { return SchedModel.getProcessorID(); } |
| 96 |
|
| 97 |
|
| 98 |
unsigned getIssueWidth() const { return SchedModel.IssueWidth; } |
| 99 |
|
| 100 |
|
| 101 |
bool mustBeginGroup(const MachineInstr *MI, |
| 102 |
const MCSchedClassDesc *SC = nullptr) const; |
| 103 |
|
| 104 |
bool mustEndGroup(const MachineInstr *MI, |
| 105 |
const MCSchedClassDesc *SC = nullptr) const; |
| 106 |
|
| 107 |
|
| 108 |
unsigned getNumMicroOps(const MachineInstr *MI, |
| 109 |
const MCSchedClassDesc *SC = nullptr) const; |
| 110 |
|
| 111 |
|
| 112 |
unsigned getNumProcResourceKinds() const { |
| 113 |
return SchedModel.getNumProcResourceKinds(); |
| 114 |
} |
| 115 |
|
| 116 |
|
| 117 |
const MCProcResourceDesc *getProcResource(unsigned PIdx) const { |
| 118 |
return SchedModel.getProcResource(PIdx); |
| 119 |
} |
| 120 |
|
| 121 |
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) |
| 122 |
const char *getResourceName(unsigned PIdx) const { |
| 123 |
if (!PIdx) |
| 124 |
return "MOps"; |
| 125 |
return SchedModel.getProcResource(PIdx)->Name; |
| 126 |
} |
| 127 |
#endif |
| 128 |
|
| 129 |
using ProcResIter = const MCWriteProcResEntry *; |
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
ProcResIter getWriteProcResBegin(const MCSchedClassDesc *SC) const { |
| 134 |
|
| 135 |
return STI->getWriteProcResBegin(SC); |
| 136 |
} |
| 137 |
ProcResIter getWriteProcResEnd(const MCSchedClassDesc *SC) const { |
| 138 |
return STI->getWriteProcResEnd(SC); |
| 139 |
} |
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
unsigned getResourceFactor(unsigned ResIdx) const { |
| 144 |
return ResourceFactors[ResIdx]; |
| 145 |
} |
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
unsigned getMicroOpFactor() const { |
| 150 |
return MicroOpFactor; |
| 151 |
} |
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
unsigned getLatencyFactor() const { |
| 156 |
return ResourceLCM; |
| 157 |
} |
| 158 |
|
| 159 |
|
| 160 |
unsigned getMicroOpBufferSize() const { return SchedModel.MicroOpBufferSize; } |
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
int getResourceBufferSize(unsigned PIdx) const { |
| 165 |
return SchedModel.getProcResource(PIdx)->BufferSize; |
| 166 |
} |
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
unsigned computeOperandLatency(const MachineInstr *DefMI, unsigned DefOperIdx, |
| 174 |
const MachineInstr *UseMI, unsigned UseOperIdx) |
| 175 |
const; |
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
unsigned computeInstrLatency(const MachineInstr *MI, |
| 189 |
bool UseDefaultDefLatency = true) const; |
| 190 |
unsigned computeInstrLatency(const MCInst &Inst) const; |
| 191 |
unsigned computeInstrLatency(unsigned Opcode) const; |
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
unsigned computeOutputLatency(const MachineInstr *DefMI, unsigned DefOperIdx, |
| 198 |
const MachineInstr *DepMI) const; |
| 199 |
|
| 200 |
|
| 201 |
double computeReciprocalThroughput(const MachineInstr *MI) const; |
| 202 |
double computeReciprocalThroughput(const MCInst &MI) const; |
| 203 |
double computeReciprocalThroughput(unsigned Opcode) const; |
| 204 |
}; |
| 205 |
|
| 206 |
} |
| 207 |
|
| 208 |
#endif |