Skip to content

Commit 7faea7c

Browse files
committedMar 13, 2018
[MC] Move the reciprocal throughput computation from TargetSchedModel to MCSchedModel.
The goal is to make the reciprocal throughput computation accessible through the MCSchedModel interface. This is particularly important for llvm-mca because it can only query the MCSchedModel interface. No functional change intended. Differential Revision: https://reviews.llvm.org/D44392 llvm-svn: 327420
1 parent b9f4b70 commit 7faea7c

File tree

3 files changed

+34
-29
lines changed

3 files changed

+34
-29
lines changed
 

‎llvm/include/llvm/MC/MCSchedule.h

+6
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#ifndef LLVM_MC_MCSCHEDULE_H
1616
#define LLVM_MC_MCSCHEDULE_H
1717

18+
#include "llvm/ADT/Optional.h"
1819
#include "llvm/Support/DataTypes.h"
1920
#include <cassert>
2021

@@ -231,6 +232,11 @@ struct MCSchedModel {
231232
static int computeInstrLatency(const MCSubtargetInfo &STI,
232233
const MCSchedClassDesc &SCDesc);
233234

235+
/// Returns the reciprocal throughput information from a MCSchedClassDesc.
236+
static Optional<double>
237+
getReciprocalThroughput(const MCSubtargetInfo &STI,
238+
const MCSchedClassDesc &SCDesc);
239+
234240
/// Returns the default initialized model.
235241
static const MCSchedModel &GetDefaultSchedModel() { return Default; }
236242
static const MCSchedModel Default;

‎llvm/lib/CodeGen/TargetSchedule.cpp

+4-29
Original file line numberDiff line numberDiff line change
@@ -347,38 +347,13 @@ getRThroughputFromItineraries(unsigned schedClass,
347347
return Throughput;
348348
}
349349

350-
static Optional<double>
351-
getRThroughputFromInstrSchedModel(const MCSchedClassDesc *SCDesc,
352-
const TargetSubtargetInfo *STI,
353-
const MCSchedModel &SchedModel) {
354-
Optional<double> Throughput;
355-
356-
for (const MCWriteProcResEntry *WPR = STI->getWriteProcResBegin(SCDesc),
357-
*WEnd = STI->getWriteProcResEnd(SCDesc);
358-
WPR != WEnd; ++WPR) {
359-
if (WPR->Cycles) {
360-
unsigned NumUnits =
361-
SchedModel.getProcResource(WPR->ProcResourceIdx)->NumUnits;
362-
double Temp = NumUnits * 1.0 / WPR->Cycles;
363-
Throughput = Throughput.hasValue()
364-
? std::min(Throughput.getValue(), Temp)
365-
: Temp;
366-
}
367-
}
368-
if (Throughput.hasValue())
369-
// We need reciprocal throughput that's why we return such value.
370-
return 1 / Throughput.getValue();
371-
return Throughput;
372-
}
373-
374350
Optional<double>
375351
TargetSchedModel::computeInstrRThroughput(const MachineInstr *MI) const {
376352
if (hasInstrItineraries())
377353
return getRThroughputFromItineraries(MI->getDesc().getSchedClass(),
378354
getInstrItineraries());
379355
if (hasInstrSchedModel())
380-
return getRThroughputFromInstrSchedModel(resolveSchedClass(MI), STI,
381-
SchedModel);
356+
return MCSchedModel::getReciprocalThroughput(*STI, *resolveSchedClass(MI));
382357
return Optional<double>();
383358
}
384359

@@ -388,9 +363,9 @@ TargetSchedModel::computeInstrRThroughput(unsigned Opcode) const {
388363
if (hasInstrItineraries())
389364
return getRThroughputFromItineraries(SchedClass, getInstrItineraries());
390365
if (hasInstrSchedModel()) {
391-
const MCSchedClassDesc *SCDesc = SchedModel.getSchedClassDesc(SchedClass);
392-
if (SCDesc->isValid() && !SCDesc->isVariant())
393-
return getRThroughputFromInstrSchedModel(SCDesc, STI, SchedModel);
366+
const MCSchedClassDesc &SCDesc = *SchedModel.getSchedClassDesc(SchedClass);
367+
if (SCDesc.isValid() && !SCDesc.isVariant())
368+
return MCSchedModel::getReciprocalThroughput(*STI, SCDesc);
394369
}
395370
return Optional<double>();
396371
}

‎llvm/lib/MC/MCSchedule.cpp

+24
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,27 @@ int MCSchedModel::computeInstrLatency(const MCSubtargetInfo &STI,
4949
}
5050
return Latency;
5151
}
52+
53+
54+
Optional<double>
55+
MCSchedModel::getReciprocalThroughput(const MCSubtargetInfo &STI,
56+
const MCSchedClassDesc &SCDesc) {
57+
Optional<double> Throughput;
58+
const MCSchedModel &SchedModel = STI.getSchedModel();
59+
60+
for (const MCWriteProcResEntry *WPR = STI.getWriteProcResBegin(&SCDesc),
61+
*WEnd = STI.getWriteProcResEnd(&SCDesc);
62+
WPR != WEnd; ++WPR) {
63+
if (WPR->Cycles) {
64+
unsigned NumUnits =
65+
SchedModel.getProcResource(WPR->ProcResourceIdx)->NumUnits;
66+
double Temp = NumUnits * 1.0 / WPR->Cycles;
67+
Throughput =
68+
Throughput.hasValue() ? std::min(Throughput.getValue(), Temp) : Temp;
69+
}
70+
}
71+
72+
if (Throughput.hasValue())
73+
return 1 / Throughput.getValue();
74+
return Throughput;
75+
}

0 commit comments

Comments
 (0)
Please sign in to comment.