//===-- SchedClassResolution.cpp --------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// #include "SchedClassResolution.h" #include "BenchmarkResult.h" #include "llvm/ADT/STLExtras.h" #include "llvm/MC/MCAsmInfo.h" #include "llvm/MCA/Support.h" #include "llvm/Support/FormatVariadic.h" #include <vector> namespace llvm { namespace exegesis { // Return the non-redundant list of WriteProcRes used by the given sched class. // The scheduling model for LLVM is such that each instruction has a certain // number of uops which consume resources which are described by WriteProcRes // entries. Each entry describe how many cycles are spent on a specific ProcRes // kind. // For example, an instruction might have 3 uOps, one dispatching on P0 // (ProcResIdx=1) and two on P06 (ProcResIdx = 7). // Note that LLVM additionally denormalizes resource consumption to include // usage of super resources by subresources. So in practice if there exists a // P016 (ProcResIdx=10), then the cycles consumed by P0 are also consumed by // P06 (ProcResIdx = 7) and P016 (ProcResIdx = 10), and the resources consumed // by P06 are also consumed by P016. In the figure below, parenthesized cycles // denote implied usage of superresources by subresources: // P0 P06 P016 // uOp1 1 (1) (1) // uOp2 1 (1) // uOp3 1 (1) // ============================= // 1 3 3 // Eventually we end up with three entries for the WriteProcRes of the // instruction: // {ProcResIdx=1, Cycles=1} // P0 // {ProcResIdx=7, Cycles=3} // P06 // {ProcResIdx=10, Cycles=3} // P016 // // Note that in this case, P016 does not contribute any cycles, so it would // be removed by this function. // FIXME: Merge this with the equivalent in llvm-mca. static SmallVector<MCWriteProcResEntry, 8> getNonRedundantWriteProcRes(const MCSchedClassDesc &SCDesc, const MCSubtargetInfo &STI) { … } // Distributes a pressure budget as evenly as possible on the provided subunits // given the already existing port pressure distribution. // // The algorithm is as follows: while there is remaining pressure to // distribute, find the subunits with minimal pressure, and distribute // remaining pressure equally up to the pressure of the unit with // second-to-minimal pressure. // For example, let's assume we want to distribute 2*P1256 // (Subunits = [P1,P2,P5,P6]), and the starting DensePressure is: // DensePressure = P0 P1 P2 P3 P4 P5 P6 P7 // 0.1 0.3 0.2 0.0 0.0 0.5 0.5 0.5 // RemainingPressure = 2.0 // We sort the subunits by pressure: // Subunits = [(P2,p=0.2), (P1,p=0.3), (P5,p=0.5), (P6, p=0.5)] // We'll first start by the subunits with minimal pressure, which are at // the beginning of the sorted array. In this example there is one (P2). // The subunit with second-to-minimal pressure is the next one in the // array (P1). So we distribute 0.1 pressure to P2, and remove 0.1 cycles // from the budget. // Subunits = [(P2,p=0.3), (P1,p=0.3), (P5,p=0.5), (P5,p=0.5)] // RemainingPressure = 1.9 // We repeat this process: distribute 0.2 pressure on each of the minimal // P2 and P1, decrease budget by 2*0.2: // Subunits = [(P2,p=0.5), (P1,p=0.5), (P5,p=0.5), (P5,p=0.5)] // RemainingPressure = 1.5 // There are no second-to-minimal subunits so we just share the remaining // budget (1.5 cycles) equally: // Subunits = [(P2,p=0.875), (P1,p=0.875), (P5,p=0.875), (P5,p=0.875)] // RemainingPressure = 0.0 // We stop as there is no remaining budget to distribute. static void distributePressure(float RemainingPressure, SmallVector<uint16_t, 32> Subunits, SmallVector<float, 32> &DensePressure) { … } std::vector<std::pair<uint16_t, float>> computeIdealizedProcResPressure(const MCSchedModel &SM, SmallVector<MCWriteProcResEntry, 8> WPRS) { … } ResolvedSchedClass::ResolvedSchedClass(const MCSubtargetInfo &STI, unsigned ResolvedSchedClassId, bool WasVariant) : … { … } static unsigned ResolveVariantSchedClassId(const MCSubtargetInfo &STI, const MCInstrInfo &InstrInfo, unsigned SchedClassId, const MCInst &MCI) { … } std::pair<unsigned /*SchedClassId*/, bool /*WasVariant*/> ResolvedSchedClass::resolveSchedClassId(const MCSubtargetInfo &SubtargetInfo, const MCInstrInfo &InstrInfo, const MCInst &MCI) { … } // Returns a ProxResIdx by id or name. static unsigned findProcResIdx(const MCSubtargetInfo &STI, const StringRef NameOrId) { … } std::vector<BenchmarkMeasure> ResolvedSchedClass::getAsPoint( Benchmark::ModeE Mode, const MCSubtargetInfo &STI, ArrayRef<PerInstructionStats> Representative) const { … } } // namespace exegesis } // namespace llvm