diff --git a/llvm/lib/Target/RISCV/RISCVScheduleV.td b/llvm/lib/Target/RISCV/RISCVScheduleV.td --- a/llvm/lib/Target/RISCV/RISCVScheduleV.td +++ b/llvm/lib/Target/RISCV/RISCVScheduleV.td @@ -26,6 +26,32 @@ !eq(mx, "MF8"): [8]); } +// Index values by LMUL. +class IndexByLMUL cycles, string mx> { + int value = !cond(!eq(mx, "M1") : cycles[0], + !eq(mx, "M2") : cycles[1], + !eq(mx, "M4") : cycles[2], + !eq(mx, "M8") : cycles[3], + !eq(mx, "MF2") : cycles[4], + !eq(mx, "MF4") : cycles[5], + !eq(mx, "MF8") : cycles[6], + !eq(mx, "WorstCase") : cycles[7],); +} + +class ResourceCycle { + list Cycles; +} +// ResourceCycle whose cycles are fixed. +class FixedResourceCycle : ResourceCycle { + let Cycles = !listsplat(cycles, !add(!size(SchedMxList), 1)); +} + +// Helper class for generating a list of resource cycles of different LMULs. +class ResourceCycles resourceCycles, string mx> { + list value = !foreach(resourceCycle, resourceCycles, + IndexByLMUL.value); +} + // Define multiclasses to define SchedWrite, SchedRead, WriteRes, and // ReadAdvance for each (name, LMUL) pair and for each LMUL in each of the // SchedMxList variants above. Each multiclass is responsible for defining @@ -42,12 +68,19 @@ def name # "_" # mx : SchedRead; } } -multiclass LMULWriteResImpl resources> { +multiclass LMULWriteResImpl resources, + ResourceCycle latency, list resourceCycles> { if !exists(name # "_WorstCase") then - def : WriteRes(name # "_WorstCase"), resources>; + def : WriteRes(name # "_WorstCase"), resources> { + let Latency = IndexByLMUL.value; + let ResourceCycles = ResourceCycles.value; + } foreach mx = SchedMxList in { if !exists(name # "_" # mx) then - def : WriteRes(name # "_" # mx), resources>; + def : WriteRes(name # "_" # mx), resources> { + let Latency = IndexByLMUL.value; + let ResourceCycles = ResourceCycles.value; + } } } multiclass LMULReadAdvanceImpl : LMULSchedWritesImpl; multiclass LMULSchedReads : LMULSchedReadsImpl; -multiclass LMULWriteRes resources> - : LMULWriteResImpl; +multiclass LMULWriteRes resources, + ResourceCycle latency = FixedResourceCycle<1>, + list resourceCycles = []> + : LMULWriteResImpl; multiclass LMULReadAdvance writes = []> : LMULReadAdvanceImpl; class LMULSchedWriteList names> : LMULSchedWriteListImpl; @@ -126,23 +161,29 @@ multiclass LMULSchedWritesW : LMULSchedWritesImpl; multiclass LMULSchedReadsW : LMULSchedReadsImpl; -multiclass LMULWriteResW resources> - : LMULWriteResImpl; +multiclass LMULWriteResW resources, + ResourceCycle latency = FixedResourceCycle<1>, + list resourceCycles = []> + : LMULWriteResImpl; multiclass LMULReadAdvanceW writes = []> : LMULReadAdvanceImpl; class LMULSchedWriteListW names> : LMULSchedWriteListImpl; multiclass LMULSchedWritesFW : LMULSchedWritesImpl; multiclass LMULSchedReadsFW : LMULSchedReadsImpl; -multiclass LMULWriteResFW resources> - : LMULWriteResImpl; +multiclass LMULWriteResFW resources, + ResourceCycle latency = FixedResourceCycle<1>, + list resourceCycles = []> + : LMULWriteResImpl; multiclass LMULReadAdvanceFW writes = []> : LMULReadAdvanceImpl; class LMULSchedWriteListFW names> : LMULSchedWriteListImpl; multiclass LMULSchedWritesFWRed : LMULSchedWritesImpl; -multiclass LMULWriteResFWRed resources> - : LMULWriteResImpl; +multiclass LMULWriteResFWRed resources, + ResourceCycle latency = FixedResourceCycle<1>, + list resourceCycles = []> + : LMULWriteResImpl; class LMULSchedWriteListFWRed names> : LMULSchedWriteListImpl;