[llvm] r327406 - [MC] Move the instruction latency computation from TargetSchedModel to MCSchedModel.
Andrea Di Biagio via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 13 08:22:13 PDT 2018
Author: adibiagio
Date: Tue Mar 13 08:22:13 2018
New Revision: 327406
URL: http://llvm.org/viewvc/llvm-project?rev=327406&view=rev
Log:
[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
Modified:
llvm/trunk/include/llvm/MC/MCSchedule.h
llvm/trunk/lib/CodeGen/TargetSchedule.cpp
llvm/trunk/lib/MC/MCSchedule.cpp
Modified: llvm/trunk/include/llvm/MC/MCSchedule.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCSchedule.h?rev=327406&r1=327405&r2=327406&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCSchedule.h (original)
+++ llvm/trunk/include/llvm/MC/MCSchedule.h Tue Mar 13 08:22:13 2018
@@ -21,6 +21,7 @@
namespace llvm {
struct InstrItinerary;
+class MCSubtargetInfo;
/// Define a kind of processor resource that will be modeled by the scheduler.
struct MCProcResourceDesc {
@@ -226,6 +227,10 @@ struct MCSchedModel {
return &SchedClassTable[SchedClassIdx];
}
+ /// Returns the latency value for the scheduling class.
+ static int computeInstrLatency(const MCSubtargetInfo &STI,
+ const MCSchedClassDesc &SCDesc);
+
/// Returns the default initialized model.
static const MCSchedModel &GetDefaultSchedModel() { return Default; }
static const MCSchedModel Default;
Modified: llvm/trunk/lib/CodeGen/TargetSchedule.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/TargetSchedule.cpp?rev=327406&r1=327405&r2=327406&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/TargetSchedule.cpp (original)
+++ llvm/trunk/lib/CodeGen/TargetSchedule.cpp Tue Mar 13 08:22:13 2018
@@ -257,15 +257,7 @@ unsigned TargetSchedModel::computeOperan
unsigned
TargetSchedModel::computeInstrLatency(const MCSchedClassDesc &SCDesc) const {
- unsigned Latency = 0;
- for (unsigned DefIdx = 0, DefEnd = SCDesc.NumWriteLatencyEntries;
- DefIdx != DefEnd; ++DefIdx) {
- // Lookup the definition's write latency in SubtargetInfo.
- const MCWriteLatencyEntry *WLEntry =
- STI->getWriteLatencyEntry(&SCDesc, DefIdx);
- Latency = std::max(Latency, capLatency(WLEntry->Cycles));
- }
- return Latency;
+ return capLatency(MCSchedModel::computeInstrLatency(*STI, SCDesc));
}
unsigned TargetSchedModel::computeInstrLatency(unsigned Opcode) const {
Modified: llvm/trunk/lib/MC/MCSchedule.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCSchedule.cpp?rev=327406&r1=327405&r2=327406&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCSchedule.cpp (original)
+++ llvm/trunk/lib/MC/MCSchedule.cpp Tue Mar 13 08:22:13 2018
@@ -12,6 +12,7 @@
//===----------------------------------------------------------------------===//
#include "llvm/MC/MCSchedule.h"
+#include "llvm/MC/MCSubtargetInfo.h"
#include <type_traits>
using namespace llvm;
@@ -32,3 +33,19 @@ const MCSchedModel MCSchedModel::Default
0,
0,
nullptr};
+
+int MCSchedModel::computeInstrLatency(const MCSubtargetInfo &STI,
+ const MCSchedClassDesc &SCDesc) {
+ int Latency = 0;
+ for (unsigned DefIdx = 0, DefEnd = SCDesc.NumWriteLatencyEntries;
+ DefIdx != DefEnd; ++DefIdx) {
+ // Lookup the definition's write latency in SubtargetInfo.
+ const MCWriteLatencyEntry *WLEntry =
+ STI.getWriteLatencyEntry(&SCDesc, DefIdx);
+ // Early exit if we found an invalid latency.
+ if (WLEntry->Cycles < 0)
+ return WLEntry->Cycles;
+ Latency = std::max(Latency, static_cast<int>(WLEntry->Cycles));
+ }
+ return Latency;
+}
More information about the llvm-commits
mailing list