Skip to content

Commit 3303d52

Browse files
[MCA] SchedulingInfoView: consider negative ReadAdvanceCycle and AcquireAtCycle
MR #126703: - Negative ReadAdvance cycles can be negative, so add ForwardingDelayCycles to Latency (computeInstrLatency). - Resource reservation cycles given with ReleaseAtCycle - AcquireAtCycle.
1 parent 6298387 commit 3303d52

File tree

3 files changed

+20
-16
lines changed

3 files changed

+20
-16
lines changed

llvm/include/llvm/MC/MCSchedule.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -402,9 +402,9 @@ struct MCSchedModel {
402402
static unsigned getForwardingDelayCycles(ArrayRef<MCReadAdvanceEntry> Entries,
403403
unsigned WriteResourceIdx = 0);
404404

405-
/// Returns the maximum forwarding delay for maximum write latency.
406-
static unsigned getForwardingDelayCycles(const MCSubtargetInfo &STI,
407-
const MCSchedClassDesc &SCDesc);
405+
/// Returns the bypass delay cycle for the maximum latency write cycle
406+
static unsigned getBypassDelayCycles(const MCSubtargetInfo &STI,
407+
const MCSchedClassDesc &SCDesc);
408408

409409
/// Returns the default initialized model.
410410
static const MCSchedModel Default;

llvm/lib/MC/MCSchedule.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,8 @@ MCSchedModel::getForwardingDelayCycles(ArrayRef<MCReadAdvanceEntry> Entries,
175175
return std::abs(DelayCycles);
176176
}
177177

178-
unsigned
179-
MCSchedModel::getForwardingDelayCycles(const MCSubtargetInfo &STI,
180-
const MCSchedClassDesc &SCDesc) {
178+
unsigned MCSchedModel::getBypassDelayCycles(const MCSubtargetInfo &STI,
179+
const MCSchedClassDesc &SCDesc) {
181180

182181
ArrayRef<MCReadAdvanceEntry> Entries = STI.getReadAdvanceEntries(SCDesc);
183182
if (Entries.empty())
@@ -192,11 +191,11 @@ MCSchedModel::getForwardingDelayCycles(const MCSubtargetInfo &STI,
192191
// Lookup the definition's write latency in SubtargetInfo.
193192
const MCWriteLatencyEntry *WLEntry =
194193
STI.getWriteLatencyEntry(&SCDesc, DefIdx);
195-
// Early exit if we found an invalid latency.
196-
// Consider no bypass
194+
unsigned Cycles = (unsigned)WLEntry->Cycles;
195+
// Invalid latency. Consider 0 cycle latency
197196
if (WLEntry->Cycles < 0)
198-
return 0;
199-
maxLatency = std::max(Latency, static_cast<unsigned>(WLEntry->Cycles));
197+
Cycles = 0;
198+
maxLatency = std::max(Latency, static_cast<unsigned>(Cycles));
200199
if (maxLatency > Latency) {
201200
WriteResourceID = WLEntry->WriteResourceID;
202201
}

llvm/tools/llvm-mca/Views/SchedulingInfoView.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,12 @@ void SchedulingInfoView::collectData(
154154
IIVDEntry.OpcodeName = (std::string)MCII.getName(Inst.getOpcode());
155155
IIVDEntry.NumMicroOpcodes = SCDesc.NumMicroOps;
156156
IIVDEntry.Latency = MCSchedModel::computeInstrLatency(STI, SCDesc);
157+
// Add extra latency due to delays in the forwarding data paths.
158+
IIVDEntry.Latency += MCSchedModel::getForwardingDelayCycles(
159+
STI.getReadAdvanceEntries(SCDesc));
160+
// Get latency with bypass
157161
IIVDEntry.Bypass =
158-
IIVDEntry.Latency - MCSchedModel::getForwardingDelayCycles(STI, SCDesc);
162+
IIVDEntry.Latency - MCSchedModel::getBypassDelayCycles(STI, SCDesc);
159163
IIVDEntry.Throughput =
160164
1.0 / MCSchedModel::getReciprocalThroughput(STI, SCDesc);
161165
raw_string_ostream TempStream(IIVDEntry.Resources);
@@ -164,14 +168,15 @@ void SchedulingInfoView::collectData(
164168
const MCWriteProcResEntry *Last = STI.getWriteProcResEnd(&SCDesc);
165169
auto sep = "";
166170
for (; Index != Last; ++Index) {
167-
if (!Index->ReleaseAtCycle)
171+
if (!Index->ReleaseAtCycle && !Index->AcquireAtCycle)
168172
continue;
169173
const MCProcResourceDesc *MCProc =
170174
SM.getProcResource(Index->ProcResourceIdx);
171-
if (Index->ReleaseAtCycle != 1) {
172-
// Output ReleaseAtCycle between [] if not 1 (default)
173-
TempStream << sep
174-
<< format("%s[%d]", MCProc->Name, Index->ReleaseAtCycle);
175+
unsigned ReservationCycles =
176+
Index->ReleaseAtCycle - Index->AcquireAtCycle;
177+
if (ReservationCycles > 1) {
178+
// Output ReleaseAtCycle - AcquireAtCycle between [] if not 1 (default)
179+
TempStream << sep << format("%s[%d]", MCProc->Name, ReservationCycles);
175180
} else {
176181
TempStream << sep << format("%s", MCProc->Name);
177182
}

0 commit comments

Comments
 (0)