diff options
Diffstat (limited to 'llvm/tools/llvm-exegesis/llvm-exegesis.cpp')
-rw-r--r-- | llvm/tools/llvm-exegesis/llvm-exegesis.cpp | 86 |
1 files changed, 18 insertions, 68 deletions
diff --git a/llvm/tools/llvm-exegesis/llvm-exegesis.cpp b/llvm/tools/llvm-exegesis/llvm-exegesis.cpp index 0c8a4173c96..77683572da6 100644 --- a/llvm/tools/llvm-exegesis/llvm-exegesis.cpp +++ b/llvm/tools/llvm-exegesis/llvm-exegesis.cpp @@ -12,10 +12,8 @@ /// //===----------------------------------------------------------------------===// -#include "lib/Analysis.h" #include "lib/BenchmarkResult.h" #include "lib/BenchmarkRunner.h" -#include "lib/Clustering.h" #include "lib/Latency.h" #include "lib/LlvmState.h" #include "lib/PerfHelper.h" @@ -25,11 +23,8 @@ #include "llvm/ADT/Twine.h" #include "llvm/MC/MCInstBuilder.h" #include "llvm/MC/MCRegisterInfo.h" -#include "llvm/MC/MCSubtargetInfo.h" #include "llvm/Support/CommandLine.h" -#include "llvm/Support/Format.h" #include "llvm/Support/Path.h" -#include "llvm/Support/TargetRegistry.h" #include "llvm/Support/TargetSelect.h" #include <algorithm> #include <random> @@ -44,41 +39,26 @@ static llvm::cl::opt<std::string> OpcodeName("opcode-name", llvm::cl::desc("opcode to measure, by name"), llvm::cl::init("")); -static llvm::cl::opt<std::string> - BenchmarkFile("benchmarks-file", llvm::cl::desc(""), llvm::cl::init("-")); - -enum class BenchmarkModeE { Latency, Uops, Analysis }; -static llvm::cl::opt<BenchmarkModeE> BenchmarkMode( - "benchmark-mode", llvm::cl::desc("the benchmark mode to run"), - llvm::cl::values( - clEnumValN(BenchmarkModeE::Latency, "latency", "Instruction Latency"), - clEnumValN(BenchmarkModeE::Uops, "uops", "Uop Decomposition"), - clEnumValN(BenchmarkModeE::Analysis, "analysis", "Analysis"))); +enum class BenchmarkModeE { Latency, Uops }; +static llvm::cl::opt<BenchmarkModeE> + BenchmarkMode("benchmark-mode", llvm::cl::desc("the benchmark mode to run"), + llvm::cl::values(clEnumValN(BenchmarkModeE::Latency, + "latency", "Instruction Latency"), + clEnumValN(BenchmarkModeE::Uops, "uops", + "Uop Decomposition"))); static llvm::cl::opt<unsigned> NumRepetitions("num-repetitions", llvm::cl::desc("number of time to repeat the asm snippet"), llvm::cl::init(10000)); -static llvm::cl::opt<unsigned> AnalysisNumPoints( - "analysis-numpoints", - llvm::cl::desc("minimum number of points in an analysis cluster"), - llvm::cl::init(3)); - -static llvm::cl::opt<float> - AnalysisEpsilon("analysis-epsilon", - llvm::cl::desc("dbscan epsilon for analysis clustering"), - llvm::cl::init(0.1)); - namespace exegesis { -void benchmarkMain() { - if (exegesis::pfm::pfmInitialize()) - llvm::report_fatal_error("cannot initialize libpfm"); - - if (OpcodeName.empty() == (OpcodeIndex == 0)) +void main() { + if (OpcodeName.empty() == (OpcodeIndex == 0)) { llvm::report_fatal_error( "please provide one and only one of 'opcode-index' or 'opcode-name'"); + } llvm::InitializeNativeTarget(); llvm::InitializeNativeTargetAsmPrinter(); @@ -114,43 +94,10 @@ void benchmarkMain() { case BenchmarkModeE::Uops: Runner = llvm::make_unique<UopsBenchmarkRunner>(); break; - case BenchmarkModeE::Analysis: - llvm_unreachable("not a benchmark"); } Runner->run(State, Opcode, NumRepetitions > 0 ? NumRepetitions : 1, Filter) - .writeYamlOrDie(BenchmarkFile); - exegesis::pfm::pfmTerminate(); -} - -void analysisMain() { - // Read benchmarks. - const std::vector<InstructionBenchmark> Points = - InstructionBenchmark::readYamlsOrDie(BenchmarkFile); - llvm::outs() << "Parsed " << Points.size() << " benchmark points\n"; - if (Points.empty()) { - llvm::errs() << "no benchmarks to analyze\n"; - return; - } - // TODO: Merge points from several runs (latency and uops). - - // FIXME: Check that all points have the same triple/cpu. - llvm::InitializeAllTargets(); - std::string Error; - const auto *TheTarget = - llvm::TargetRegistry::lookupTarget(Points[0].LLVMTriple, Error); - if (!TheTarget) { - llvm::errs() << "unknown target '" << Points[0].LLVMTriple << "'\n"; - return; - } - std::unique_ptr<llvm::MCSubtargetInfo> STI(TheTarget->createMCSubtargetInfo( - Points[0].LLVMTriple, Points[0].CpuName, "")); - - const auto Clustering = llvm::cantFail(InstructionBenchmarkClustering::create( - Points, AnalysisNumPoints, AnalysisEpsilon)); - if (auto Err = printAnalysisClusters(Clustering, *STI, llvm::outs())) { - llvm::report_fatal_error(std::move(Err)); - } + .writeYamlOrDie("-"); } } // namespace exegesis @@ -158,10 +105,13 @@ void analysisMain() { int main(int Argc, char **Argv) { llvm::cl::ParseCommandLineOptions(Argc, Argv, ""); - if (BenchmarkMode == BenchmarkModeE::Analysis) { - exegesis::analysisMain(); - } else { - exegesis::benchmarkMain(); + if (exegesis::pfm::pfmInitialize()) { + llvm::errs() << "cannot initialize libpfm\n"; + return EXIT_FAILURE; } + + exegesis::main(); + + exegesis::pfm::pfmTerminate(); return EXIT_SUCCESS; } |