2018-05-15 20:08:00 +08:00
|
|
|
//===-- Analysis.h ----------------------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
///
|
|
|
|
/// \file
|
|
|
|
/// Analysis output for benchmark results.
|
|
|
|
///
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_TOOLS_LLVM_EXEGESIS_ANALYSIS_H
|
|
|
|
#define LLVM_TOOLS_LLVM_EXEGESIS_ANALYSIS_H
|
|
|
|
|
|
|
|
#include "Clustering.h"
|
2018-05-16 16:47:21 +08:00
|
|
|
#include "llvm/MC/MCInstrInfo.h"
|
2018-05-15 20:08:00 +08:00
|
|
|
#include "llvm/MC/MCSubtargetInfo.h"
|
|
|
|
#include "llvm/Support/Error.h"
|
2018-05-17 20:25:18 +08:00
|
|
|
#include "llvm/Support/TargetRegistry.h"
|
2018-05-15 20:08:00 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2018-06-04 19:11:55 +08:00
|
|
|
#include <set>
|
2018-05-16 16:47:21 +08:00
|
|
|
#include <string>
|
|
|
|
#include <unordered_map>
|
2018-05-15 20:08:00 +08:00
|
|
|
|
|
|
|
namespace exegesis {
|
|
|
|
|
2018-05-16 16:47:21 +08:00
|
|
|
// A helper class to analyze benchmark results for a target.
|
|
|
|
class Analysis {
|
|
|
|
public:
|
2018-05-17 20:25:18 +08:00
|
|
|
Analysis(const llvm::Target &Target,
|
|
|
|
const InstructionBenchmarkClustering &Clustering);
|
2018-05-16 16:47:21 +08:00
|
|
|
|
|
|
|
// Prints a csv of instructions for each cluster.
|
2018-05-17 21:41:28 +08:00
|
|
|
struct PrintClusters {};
|
2018-05-17 20:25:18 +08:00
|
|
|
// Find potential errors in the scheduling information given measurements.
|
2018-05-17 21:41:28 +08:00
|
|
|
struct PrintSchedClassInconsistencies {};
|
|
|
|
|
|
|
|
template <typename Pass> llvm::Error run(llvm::raw_ostream &OS) const;
|
2018-05-17 20:25:18 +08:00
|
|
|
|
|
|
|
private:
|
2018-06-04 19:11:55 +08:00
|
|
|
using ClusterId = InstructionBenchmarkClustering::ClusterId;
|
|
|
|
|
|
|
|
// An llvm::MCSchedClassDesc augmented with some additional data.
|
|
|
|
struct SchedClass {
|
|
|
|
SchedClass(const llvm::MCSchedClassDesc &SD,
|
|
|
|
const llvm::MCSubtargetInfo &STI);
|
|
|
|
|
|
|
|
const llvm::MCSchedClassDesc &SCDesc;
|
|
|
|
const llvm::SmallVector<llvm::MCWriteProcResEntry, 8>
|
|
|
|
NonRedundantWriteProcRes;
|
|
|
|
const std::vector<std::pair<uint16_t, float>> IdealizedProcResPressure;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Represents the intersection of a sched class and a cluster.
|
|
|
|
class SchedClassCluster {
|
|
|
|
public:
|
|
|
|
const InstructionBenchmarkClustering::ClusterId &id() const {
|
|
|
|
return ClusterId;
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::vector<size_t> &getPointIds() const { return PointIds; }
|
|
|
|
|
|
|
|
// Return the cluster centroid.
|
|
|
|
const std::vector<BenchmarkMeasureStats> &getRepresentative() const {
|
|
|
|
return Representative;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns true if the cluster representative measurements match that of SC.
|
|
|
|
bool
|
|
|
|
measurementsMatch(const llvm::MCSubtargetInfo &STI, const SchedClass &SC,
|
|
|
|
const InstructionBenchmarkClustering &Clustering) const;
|
|
|
|
|
|
|
|
void addPoint(size_t PointId,
|
|
|
|
const InstructionBenchmarkClustering &Clustering);
|
|
|
|
|
|
|
|
private:
|
|
|
|
InstructionBenchmarkClustering::ClusterId ClusterId;
|
|
|
|
std::vector<size_t> PointIds;
|
|
|
|
// Measurement stats for the points in the SchedClassCluster.
|
|
|
|
std::vector<BenchmarkMeasureStats> Representative;
|
|
|
|
};
|
|
|
|
|
2018-05-22 21:31:29 +08:00
|
|
|
void printInstructionRowCsv(size_t PointId, llvm::raw_ostream &OS) const;
|
|
|
|
|
2018-06-04 19:11:55 +08:00
|
|
|
void
|
|
|
|
printSchedClassClustersHtml(const std::vector<SchedClassCluster> &Clusters,
|
|
|
|
const SchedClass &SC,
|
|
|
|
llvm::raw_ostream &OS) const;
|
|
|
|
void printSchedClassDescHtml(const SchedClass &SC,
|
2018-05-24 18:47:05 +08:00
|
|
|
llvm::raw_ostream &OS) const;
|
2018-05-17 20:25:18 +08:00
|
|
|
|
|
|
|
// Builds a map of Sched Class -> indices of points that belong to the sched
|
|
|
|
// class.
|
|
|
|
std::unordered_map<unsigned, std::vector<size_t>>
|
|
|
|
makePointsPerSchedClass() const;
|
2018-05-16 16:47:21 +08:00
|
|
|
|
2018-05-17 20:25:18 +08:00
|
|
|
const InstructionBenchmarkClustering &Clustering_;
|
|
|
|
std::unique_ptr<llvm::MCSubtargetInfo> SubtargetInfo_;
|
|
|
|
std::unique_ptr<llvm::MCInstrInfo> InstrInfo_;
|
|
|
|
std::unordered_map<std::string, unsigned> MnemonicToOpcode_;
|
2018-05-16 16:47:21 +08:00
|
|
|
};
|
2018-05-15 20:08:00 +08:00
|
|
|
|
2018-06-01 22:18:02 +08:00
|
|
|
// Computes the idealized ProcRes Unit pressure. This is the expected
|
|
|
|
// distribution if the CPU scheduler can distribute the load as evenly as
|
|
|
|
// possible.
|
|
|
|
std::vector<std::pair<uint16_t, float>> computeIdealizedProcResPressure(
|
|
|
|
const llvm::MCSchedModel &SM,
|
|
|
|
llvm::SmallVector<llvm::MCWriteProcResEntry, 8> WPRS);
|
|
|
|
|
2018-05-15 20:08:00 +08:00
|
|
|
} // namespace exegesis
|
|
|
|
|
|
|
|
#endif // LLVM_TOOLS_LLVM_EXEGESIS_CLUSTERING_H
|