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,31 @@ !eq(mx, "MF8"): [8]); } +// Index values by LMUL. +class index cycles, string mx> { + int value = !cond(!eq(mx, "UpperBound") : cycles[0], + !eq(mx, "M1") : cycles[1], + !eq(mx, "M2") : cycles[2], + !eq(mx, "M4") : cycles[3], + !eq(mx, "M8") : cycles[4], + !eq(mx, "MF2") : cycles[5], + !eq(mx, "MF4") : cycles[6], + !eq(mx, "MF8") : cycles[7]); +} + +class ResourceCycle { + list Cycles; +} +// ResourceCycle whose cycles are fixed. +class FixedResourceCycle : ResourceCycle { + let Cycles = !listsplat(cycles, !size(SchedMxList)); +} + +// Helper class for generating a list of resource cycles of different LMULs. +class ResourceCycles resourceCycles, string mx> { + list value = !foreach(resourceCycle, resourceCycles, index.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 +67,16 @@ def name # "_" # mx : SchedRead; } } -multiclass LMULWriteResImpl resources> { +multiclass LMULWriteResImpl resources, + ResourceCycle latency, list resourceCycles> { if !exists(name # "_WorstCase") then def : WriteRes(name # "_WorstCase"), resources>; foreach mx = SchedMxList in { if !exists(name # "_" # mx) then - def : WriteRes(name # "_" # mx), resources>; + def : WriteRes(name # "_" # mx), resources> { + let Latency = index.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 +157,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;