Skip to content

Commit 30c1ba4

Browse files
committedMar 13, 2018
[MC] Move the instruction latency computation from TargetSchedModel to MCSchedModel.
The goal is to make the latency information accessible through the MCSchedModel interface. This is particularly important for tools like llvm-mca that only have access to the MCSchedModel API. This partially fixes PR36676. No functional change intended. Differential Revision: https://reviews.llvm.org/D44383 llvm-svn: 327406
1 parent 8150810 commit 30c1ba4

File tree

3 files changed

+23
-9
lines changed

3 files changed

+23
-9
lines changed
 

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

+5
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
namespace llvm {
2222

2323
struct InstrItinerary;
24+
class MCSubtargetInfo;
2425

2526
/// Define a kind of processor resource that will be modeled by the scheduler.
2627
struct MCProcResourceDesc {
@@ -226,6 +227,10 @@ struct MCSchedModel {
226227
return &SchedClassTable[SchedClassIdx];
227228
}
228229

230+
/// Returns the latency value for the scheduling class.
231+
static int computeInstrLatency(const MCSubtargetInfo &STI,
232+
const MCSchedClassDesc &SCDesc);
233+
229234
/// Returns the default initialized model.
230235
static const MCSchedModel &GetDefaultSchedModel() { return Default; }
231236
static const MCSchedModel Default;

‎llvm/lib/CodeGen/TargetSchedule.cpp

+1-9
Original file line numberDiff line numberDiff line change
@@ -257,15 +257,7 @@ unsigned TargetSchedModel::computeOperandLatency(
257257

258258
unsigned
259259
TargetSchedModel::computeInstrLatency(const MCSchedClassDesc &SCDesc) const {
260-
unsigned Latency = 0;
261-
for (unsigned DefIdx = 0, DefEnd = SCDesc.NumWriteLatencyEntries;
262-
DefIdx != DefEnd; ++DefIdx) {
263-
// Lookup the definition's write latency in SubtargetInfo.
264-
const MCWriteLatencyEntry *WLEntry =
265-
STI->getWriteLatencyEntry(&SCDesc, DefIdx);
266-
Latency = std::max(Latency, capLatency(WLEntry->Cycles));
267-
}
268-
return Latency;
260+
return capLatency(MCSchedModel::computeInstrLatency(*STI, SCDesc));
269261
}
270262

271263
unsigned TargetSchedModel::computeInstrLatency(unsigned Opcode) const {

‎llvm/lib/MC/MCSchedule.cpp

+17
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
//===----------------------------------------------------------------------===//
1313

1414
#include "llvm/MC/MCSchedule.h"
15+
#include "llvm/MC/MCSubtargetInfo.h"
1516
#include <type_traits>
1617

1718
using namespace llvm;
@@ -32,3 +33,19 @@ const MCSchedModel MCSchedModel::Default = {DefaultIssueWidth,
3233
0,
3334
0,
3435
nullptr};
36+
37+
int MCSchedModel::computeInstrLatency(const MCSubtargetInfo &STI,
38+
const MCSchedClassDesc &SCDesc) {
39+
int Latency = 0;
40+
for (unsigned DefIdx = 0, DefEnd = SCDesc.NumWriteLatencyEntries;
41+
DefIdx != DefEnd; ++DefIdx) {
42+
// Lookup the definition's write latency in SubtargetInfo.
43+
const MCWriteLatencyEntry *WLEntry =
44+
STI.getWriteLatencyEntry(&SCDesc, DefIdx);
45+
// Early exit if we found an invalid latency.
46+
if (WLEntry->Cycles < 0)
47+
return WLEntry->Cycles;
48+
Latency = std::max(Latency, static_cast<int>(WLEntry->Cycles));
49+
}
50+
return Latency;
51+
}

0 commit comments

Comments
 (0)
Please sign in to comment.