blob: 36110076a12062ab5b2836bbbdf1d0b23180cc6e [file] [log] [blame]
Clement Courbet37f0ca02018-05-15 12:08:00 +00001//===-- Analysis.h ----------------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9///
10/// \file
11/// Analysis output for benchmark results.
12///
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_TOOLS_LLVM_EXEGESIS_ANALYSIS_H
16#define LLVM_TOOLS_LLVM_EXEGESIS_ANALYSIS_H
17
18#include "Clustering.h"
Clement Courbet6d6c1a92018-05-16 08:47:21 +000019#include "llvm/MC/MCInstrInfo.h"
Clement Courbet37f0ca02018-05-15 12:08:00 +000020#include "llvm/MC/MCSubtargetInfo.h"
21#include "llvm/Support/Error.h"
Clement Courbet448550d2018-05-17 12:25:18 +000022#include "llvm/Support/TargetRegistry.h"
Clement Courbet37f0ca02018-05-15 12:08:00 +000023#include "llvm/Support/raw_ostream.h"
Clement Courbet6d6c1a92018-05-16 08:47:21 +000024#include <string>
25#include <unordered_map>
Clement Courbet37f0ca02018-05-15 12:08:00 +000026
27namespace exegesis {
28
Clement Courbet6d6c1a92018-05-16 08:47:21 +000029// A helper class to analyze benchmark results for a target.
30class Analysis {
31public:
Clement Courbet448550d2018-05-17 12:25:18 +000032 Analysis(const llvm::Target &Target,
33 const InstructionBenchmarkClustering &Clustering);
Clement Courbet6d6c1a92018-05-16 08:47:21 +000034
35 // Prints a csv of instructions for each cluster.
Clement Courbetcf210742018-05-17 13:41:28 +000036 struct PrintClusters {};
Clement Courbet448550d2018-05-17 12:25:18 +000037 // Find potential errors in the scheduling information given measurements.
Clement Courbetcf210742018-05-17 13:41:28 +000038 struct PrintSchedClassInconsistencies {};
39
40 template <typename Pass> llvm::Error run(llvm::raw_ostream &OS) const;
Clement Courbet6d6c1a92018-05-16 08:47:21 +000041
Clement Courbet448550d2018-05-17 12:25:18 +000042private:
Clement Courbet17d3c252018-05-22 13:31:29 +000043 void printInstructionRowCsv(size_t PointId, llvm::raw_ostream &OS) const;
44
Clement Courbet2637e5f2018-05-24 10:47:05 +000045 void printSchedClassClustersHtml(std::vector<size_t> PointIds,
46 llvm::raw_ostream &OS) const;
47 void printSchedClassDescHtml(const llvm::MCSchedClassDesc &SCDesc,
48 llvm::raw_ostream &OS) const;
Clement Courbet448550d2018-05-17 12:25:18 +000049
50 // Builds a map of Sched Class -> indices of points that belong to the sched
51 // class.
52 std::unordered_map<unsigned, std::vector<size_t>>
53 makePointsPerSchedClass() const;
54
55 const InstructionBenchmarkClustering &Clustering_;
56 std::unique_ptr<llvm::MCSubtargetInfo> SubtargetInfo_;
57 std::unique_ptr<llvm::MCInstrInfo> InstrInfo_;
58 std::unordered_map<std::string, unsigned> MnemonicToOpcode_;
Clement Courbet6d6c1a92018-05-16 08:47:21 +000059};
Clement Courbet37f0ca02018-05-15 12:08:00 +000060
Clement Courbetdf79e792018-06-01 14:18:02 +000061// Computes the idealized ProcRes Unit pressure. This is the expected
62// distribution if the CPU scheduler can distribute the load as evenly as
63// possible.
64std::vector<std::pair<uint16_t, float>> computeIdealizedProcResPressure(
65 const llvm::MCSchedModel &SM,
66 llvm::SmallVector<llvm::MCWriteProcResEntry, 8> WPRS);
67
Clement Courbet37f0ca02018-05-15 12:08:00 +000068} // namespace exegesis
69
70#endif // LLVM_TOOLS_LLVM_EXEGESIS_CLUSTERING_H