File indexing completed on 2026-05-10 08:43:38
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #ifndef LLVM_CODEGEN_TARGETSCHEDULE_H
0016 #define LLVM_CODEGEN_TARGETSCHEDULE_H
0017
0018 #include "llvm/ADT/SmallVector.h"
0019 #include "llvm/CodeGen/TargetSubtargetInfo.h"
0020 #include "llvm/Config/llvm-config.h"
0021 #include "llvm/MC/MCInstrItineraries.h"
0022 #include "llvm/MC/MCSchedule.h"
0023
0024 namespace llvm {
0025
0026 class MachineInstr;
0027 class TargetInstrInfo;
0028
0029
0030 class TargetSchedModel {
0031
0032
0033 MCSchedModel SchedModel;
0034 InstrItineraryData InstrItins;
0035 const TargetSubtargetInfo *STI = nullptr;
0036 const TargetInstrInfo *TII = nullptr;
0037
0038 SmallVector<unsigned, 16> ResourceFactors;
0039
0040
0041 unsigned MicroOpFactor = 0;
0042
0043
0044 unsigned ResourceLCM = 0;
0045
0046 unsigned computeInstrLatency(const MCSchedClassDesc &SCDesc) const;
0047
0048 public:
0049 TargetSchedModel() : SchedModel(MCSchedModel::Default) {}
0050
0051
0052
0053
0054
0055
0056 void init(const TargetSubtargetInfo *TSInfo);
0057
0058
0059 const MCSchedClassDesc *resolveSchedClass(const MachineInstr *MI) const;
0060
0061
0062 const TargetSubtargetInfo *getSubtargetInfo() const { return STI; }
0063
0064
0065 const TargetInstrInfo *getInstrInfo() const { return TII; }
0066
0067
0068
0069
0070
0071
0072 bool hasInstrSchedModel() const;
0073
0074 const MCSchedModel *getMCSchedModel() const { return &SchedModel; }
0075
0076
0077
0078
0079
0080 bool hasInstrItineraries() const;
0081
0082 const InstrItineraryData *getInstrItineraries() const {
0083 if (hasInstrItineraries())
0084 return &InstrItins;
0085 return nullptr;
0086 }
0087
0088
0089
0090 bool hasInstrSchedModelOrItineraries() const {
0091 return hasInstrSchedModel() || hasInstrItineraries();
0092 }
0093 bool enableIntervals() const;
0094
0095 unsigned getProcessorID() const { return SchedModel.getProcessorID(); }
0096
0097
0098 unsigned getIssueWidth() const { return SchedModel.IssueWidth; }
0099
0100
0101 bool mustBeginGroup(const MachineInstr *MI,
0102 const MCSchedClassDesc *SC = nullptr) const;
0103
0104 bool mustEndGroup(const MachineInstr *MI,
0105 const MCSchedClassDesc *SC = nullptr) const;
0106
0107
0108 unsigned getNumMicroOps(const MachineInstr *MI,
0109 const MCSchedClassDesc *SC = nullptr) const;
0110
0111
0112 unsigned getNumProcResourceKinds() const {
0113 return SchedModel.getNumProcResourceKinds();
0114 }
0115
0116
0117 const MCProcResourceDesc *getProcResource(unsigned PIdx) const {
0118 return SchedModel.getProcResource(PIdx);
0119 }
0120
0121 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
0122 const char *getResourceName(unsigned PIdx) const {
0123 if (!PIdx)
0124 return "MOps";
0125 return SchedModel.getProcResource(PIdx)->Name;
0126 }
0127 #endif
0128
0129 using ProcResIter = const MCWriteProcResEntry *;
0130
0131
0132
0133 ProcResIter getWriteProcResBegin(const MCSchedClassDesc *SC) const {
0134
0135 return STI->getWriteProcResBegin(SC);
0136 }
0137 ProcResIter getWriteProcResEnd(const MCSchedClassDesc *SC) const {
0138 return STI->getWriteProcResEnd(SC);
0139 }
0140
0141
0142
0143 unsigned getResourceFactor(unsigned ResIdx) const {
0144 return ResourceFactors[ResIdx];
0145 }
0146
0147
0148
0149 unsigned getMicroOpFactor() const {
0150 return MicroOpFactor;
0151 }
0152
0153
0154
0155 unsigned getLatencyFactor() const {
0156 return ResourceLCM;
0157 }
0158
0159
0160 unsigned getMicroOpBufferSize() const { return SchedModel.MicroOpBufferSize; }
0161
0162
0163
0164 int getResourceBufferSize(unsigned PIdx) const {
0165 return SchedModel.getProcResource(PIdx)->BufferSize;
0166 }
0167
0168
0169
0170
0171
0172
0173 unsigned computeOperandLatency(const MachineInstr *DefMI, unsigned DefOperIdx,
0174 const MachineInstr *UseMI, unsigned UseOperIdx)
0175 const;
0176
0177
0178
0179
0180
0181
0182
0183
0184
0185
0186
0187
0188 unsigned computeInstrLatency(const MachineInstr *MI,
0189 bool UseDefaultDefLatency = true) const;
0190 unsigned computeInstrLatency(const MCInst &Inst) const;
0191 unsigned computeInstrLatency(unsigned Opcode) const;
0192
0193
0194
0195
0196
0197 unsigned computeOutputLatency(const MachineInstr *DefMI, unsigned DefOperIdx,
0198 const MachineInstr *DepMI) const;
0199
0200
0201 double computeReciprocalThroughput(const MachineInstr *MI) const;
0202 double computeReciprocalThroughput(const MCInst &MI) const;
0203 double computeReciprocalThroughput(unsigned Opcode) const;
0204 };
0205
0206 }
0207
0208 #endif