From d10ed7c8d71d86841da1b204f0383037490c4242 Mon Sep 17 00:00:00 2001 From: Andrea Di Biagio Date: Wed, 28 Nov 2018 19:31:19 +0000 Subject: [PATCH] Reapply "[llvm-mca] Return the total number of cycles from method Pipeline::run()." This reapplies r347767 (originally reviewed at: https://reviews.llvm.org/D55000) with a fix for the missing std::move of the Error returned by the call to Pipeline::runCycle(). Below is the original commit message from r347767. If a user only cares about the overall latency, then the best/quickest way is to change method Pipeline::run() so that it returns the total number of cycles to the caller. When the simulation pipeline is run, the number of cycles (or an error) is returned from method Pipeline::run(). The advantage is that no hardware event listener is needed for computing that latency. So, the whole process should be faster (and simpler - at least for that particular use case). llvm-svn: 347795 --- llvm/tools/llvm-mca/include/Pipeline.h | 5 ++++- llvm/tools/llvm-mca/lib/Pipeline.cpp | 6 +++--- llvm/tools/llvm-mca/llvm-mca.cpp | 5 +++-- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/llvm/tools/llvm-mca/include/Pipeline.h b/llvm/tools/llvm-mca/include/Pipeline.h index 47ff07b28828..0fd402645699 100644 --- a/llvm/tools/llvm-mca/include/Pipeline.h +++ b/llvm/tools/llvm-mca/include/Pipeline.h @@ -67,7 +67,10 @@ class Pipeline { public: Pipeline() : Cycles(0) {} void appendStage(std::unique_ptr S); - Error run(); + + /// Returns the total number of simulated cycles. + Expected run(); + void addEventListener(HWEventListener *Listener); }; } // namespace mca diff --git a/llvm/tools/llvm-mca/lib/Pipeline.cpp b/llvm/tools/llvm-mca/lib/Pipeline.cpp index 309f415913d7..0357124bef5b 100644 --- a/llvm/tools/llvm-mca/lib/Pipeline.cpp +++ b/llvm/tools/llvm-mca/lib/Pipeline.cpp @@ -35,18 +35,18 @@ bool Pipeline::hasWorkToProcess() { }); } -Error Pipeline::run() { +Expected Pipeline::run() { assert(!Stages.empty() && "Unexpected empty pipeline found!"); do { notifyCycleBegin(); if (Error Err = runCycle()) - return Err; + return std::move(Err); notifyCycleEnd(); ++Cycles; } while (hasWorkToProcess()); - return ErrorSuccess(); + return Cycles; } Error Pipeline::runCycle() { diff --git a/llvm/tools/llvm-mca/llvm-mca.cpp b/llvm/tools/llvm-mca/llvm-mca.cpp index 8b792be01013..985889677dec 100644 --- a/llvm/tools/llvm-mca/llvm-mca.cpp +++ b/llvm/tools/llvm-mca/llvm-mca.cpp @@ -240,8 +240,9 @@ static void processViewOptions() { // Returns true on success. static bool runPipeline(mca::Pipeline &P) { // Handle pipeline errors here. - if (auto Err = P.run()) { - WithColor::error() << toString(std::move(Err)); + Expected Cycles = P.run(); + if (!Cycles) { + WithColor::error() << toString(Cycles.takeError()); return false; } return true;