Index: test/tools/llvm-exegesis/X86/analysis-inconsistencies-uops-backwards.test =================================================================== --- /dev/null +++ test/tools/llvm-exegesis/X86/analysis-inconsistencies-uops-backwards.test @@ -0,0 +1,28 @@ +# This tests backwards-compatibility of the yaml schema (see PR39082). +# RUN: llvm-exegesis -mode=analysis -benchmarks-file=%s -analysis-inconsistencies-output-file=- -analysis-clusters-output-file="" -analysis-numpoints=1 | FileCheck %s + +# CHECK: DOCTYPE + +--- +mode: uops +key: + instructions: + - 'VZEROALL' + config: '' + register_initial_values: +cpu_name: haswell +llvm_triple: x86_64-unknown-linux-gnu +num_repetitions: 10000 +measurements: + - { key: '3', value: 0.0015, per_snippet_value: 0.0015 } + - { key: '4', value: 0.0011, per_snippet_value: 0.0011 } + - { key: '5', value: 0.0006, per_snippet_value: 0.0006 } + - { key: '6', value: 0.0004, per_snippet_value: 0.0004 } + - { key: '7', value: 0.0002, per_snippet_value: 0.0002 } + - { key: '8', value: 1.0008, per_snippet_value: 1.0008 } + - { key: '9', value: 1.0022, per_snippet_value: 1.0022 } + - { key: '10', value: 0.0001, per_snippet_value: 0.0001 } +error: '' +info: '' +assembled_snippet: C5FC77C5FC77C5FC77C5FC77C5FC77C5FC77C5FC77C5FC77C5FC77C5FC77C5FC77C5FC77C5FC77C5FC77C5FC77C5FC77C3 +... Index: test/tools/llvm-exegesis/X86/analysis-inconsistencies-uops.test =================================================================== --- /dev/null +++ test/tools/llvm-exegesis/X86/analysis-inconsistencies-uops.test @@ -0,0 +1,28 @@ +# RUN: llvm-exegesis -mode=analysis -benchmarks-file=%s -analysis-inconsistencies-output-file=- -analysis-clusters-output-file="" -analysis-numpoints=1 | FileCheck %s + +# CHECK: DOCTYPE + +--- +mode: uops +key: + instructions: + - 'VZEROALL' + config: '' + register_initial_values: +cpu_name: haswell +llvm_triple: x86_64-unknown-linux-gnu +num_repetitions: 10000 +measurements: + - { key: HWPort0, value: 0.0015, per_snippet_value: 0.0015 } + - { key: HWPort1, value: 0.0011, per_snippet_value: 0.0011 } + - { key: HWPort2, value: 0.0006, per_snippet_value: 0.0006 } + - { key: HWPort3, value: 0.0004, per_snippet_value: 0.0004 } + - { key: HWPort4, value: 0.0002, per_snippet_value: 0.0002 } + - { key: HWPort5, value: 1.0008, per_snippet_value: 1.0008 } + - { key: HWPort6, value: 1.0022, per_snippet_value: 1.0022 } + - { key: HWPort7, value: 0.0001, per_snippet_value: 0.0001 } + - { key: NumMicroOps, value: 20.0073, per_snippet_value: 20.0073 } +error: '' +info: '' +assembled_snippet: C5FC77C5FC77C5FC77C5FC77C5FC77C5FC77C5FC77C5FC77C5FC77C5FC77C5FC77C5FC77C5FC77C5FC77C5FC77C5FC77C3 +... Index: tools/llvm-exegesis/lib/Analysis.cpp =================================================================== --- tools/llvm-exegesis/lib/Analysis.cpp +++ tools/llvm-exegesis/lib/Analysis.cpp @@ -390,6 +390,22 @@ assert(ClusterId == Clustering.getClusterIdForPoint(PointId)); } +// Returns a ProxResIdx by id or name. +static unsigned findProcResIdx(const llvm::MCSubtargetInfo &STI, + const llvm::StringRef NameOrId) { + // Interpret the key as an ProcResIdx. + unsigned ProcResIdx = 0; + if (llvm::to_integer(NameOrId, ProcResIdx, 10)) + return ProcResIdx; + // Interpret the key as a ProcRes name. + const auto &SchedModel = STI.getSchedModel(); + for (int I = 0, E = SchedModel.getNumProcResourceKinds(); I < E; ++I) { + if (NameOrId == SchedModel.getProcResource(I)->Name) + return I; + } + return 0; +} + bool Analysis::SchedClassCluster::measurementsMatch( const llvm::MCSubtargetInfo &STI, const SchedClass &SC, const InstructionBenchmarkClustering &Clustering) const { @@ -417,23 +433,28 @@ ClusterCenterPoint[0].PerInstructionValue = Representative[0].avg(); } else if (Mode == InstructionBenchmark::Uops) { for (int I = 0, E = Representative.size(); I < E; ++I) { - // Find the pressure on ProcResIdx `Key`. - uint16_t ProcResIdx = 0; - if (!llvm::to_integer(Representative[I].key(), ProcResIdx, 10)) { - llvm::errs() << "expected ProcResIdx key, got " - << Representative[I].key() << "\n"; + const auto Key = Representative[I].key(); + uint16_t ProcResIdx = findProcResIdx(STI, Key); + if (ProcResIdx > 0) { + // Find the pressure on ProcResIdx `Key`. + const auto ProcResPressureIt = + std::find_if(SC.IdealizedProcResPressure.begin(), + SC.IdealizedProcResPressure.end(), + [ProcResIdx](const std::pair &WPR) { + return WPR.first == ProcResIdx; + }); + SchedClassPoint[I].PerInstructionValue = + ProcResPressureIt == SC.IdealizedProcResPressure.end() + ? 0.0 + : ProcResPressureIt->second; + } else if (Key == "NumMicroOps") { + SchedClassPoint[I].PerInstructionValue = SC.SCDesc->NumMicroOps; + } else { + llvm::errs() << "expected `key` to be either a ProcResIdx or a ProcRes " + "name, got " + << Key << "\n"; return false; } - const auto ProcResPressureIt = - std::find_if(SC.IdealizedProcResPressure.begin(), - SC.IdealizedProcResPressure.end(), - [ProcResIdx](const std::pair &WPR) { - return WPR.first == ProcResIdx; - }); - SchedClassPoint[I].PerInstructionValue = - ProcResPressureIt == SC.IdealizedProcResPressure.end() - ? 0.0 - : ProcResPressureIt->second; ClusterCenterPoint[I].PerInstructionValue = Representative[I].avg(); } } else {