diff options
3 files changed, 93 insertions, 16 deletions
diff --git a/llvm/test/tools/llvm-exegesis/X86/analysis-inconsistencies-uops-backwards.test b/llvm/test/tools/llvm-exegesis/X86/analysis-inconsistencies-uops-backwards.test new file mode 100644 index 00000000000..32a1c87964f --- /dev/null +++ b/llvm/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 +... diff --git a/llvm/test/tools/llvm-exegesis/X86/analysis-inconsistencies-uops.test b/llvm/test/tools/llvm-exegesis/X86/analysis-inconsistencies-uops.test new file mode 100644 index 00000000000..18654e5cb18 --- /dev/null +++ b/llvm/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 +... diff --git a/llvm/tools/llvm-exegesis/lib/Analysis.cpp b/llvm/tools/llvm-exegesis/lib/Analysis.cpp index 805bd52daf1..d852f24be33 100644 --- a/llvm/tools/llvm-exegesis/lib/Analysis.cpp +++ b/llvm/tools/llvm-exegesis/lib/Analysis.cpp @@ -390,6 +390,22 @@ void Analysis::SchedClassCluster::addPoint(    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 @@ bool Analysis::SchedClassCluster::measurementsMatch(      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<uint16_t, float> &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<uint16_t, float> &WPR) { -                         return WPR.first == ProcResIdx; -                       }); -      SchedClassPoint[I].PerInstructionValue = -          ProcResPressureIt == SC.IdealizedProcResPressure.end() -              ? 0.0 -              : ProcResPressureIt->second;        ClusterCenterPoint[I].PerInstructionValue = Representative[I].avg();      }    } else { @@ -447,7 +468,7 @@ bool Analysis::SchedClassCluster::measurementsMatch(  void Analysis::printSchedClassDescHtml(const SchedClass &SC,                                         llvm::raw_ostream &OS) const {    OS << "<table class=\"sched-class-desc\">"; -  OS << "<tr><th>Valid</th><th>Variant</th><th>uOps</th><th>Latency</" +  OS << "<tr><th>Valid</th><th>Variant</th><th>NumMicroOps</th><th>Latency</"          "th><th>WriteProcRes</th><th title=\"This is the idealized unit "          "resource (port) pressure assuming ideal distribution\">Idealized "          "Resource Pressure</th></tr>";  | 

