[llvm] r332608 - [llvm-exegesis] Write out inconsistencies to a file.

Clement Courbet via llvm-commits llvm-commits at lists.llvm.org
Thu May 17 06:41:28 PDT 2018


Author: courbet
Date: Thu May 17 06:41:28 2018
New Revision: 332608

URL: http://llvm.org/viewvc/llvm-project?rev=332608&view=rev
Log:
[llvm-exegesis] Write out inconsistencies to a file.

Reviewers: gchatelet

Subscribers: tschuett, llvm-commits

Differential Revision: https://reviews.llvm.org/D47013

Modified:
    llvm/trunk/tools/llvm-exegesis/lib/Analysis.cpp
    llvm/trunk/tools/llvm-exegesis/lib/Analysis.h
    llvm/trunk/tools/llvm-exegesis/llvm-exegesis.cpp

Modified: llvm/trunk/tools/llvm-exegesis/lib/Analysis.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-exegesis/lib/Analysis.cpp?rev=332608&r1=332607&r2=332608&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-exegesis/lib/Analysis.cpp (original)
+++ llvm/trunk/tools/llvm-exegesis/lib/Analysis.cpp Thu May 17 06:41:28 2018
@@ -91,7 +91,9 @@ Analysis::Analysis(const llvm::Target &T
     MnemonicToOpcode_.emplace(InstrInfo_->getName(I), I);
 }
 
-llvm::Error Analysis::printClusters(llvm::raw_ostream &OS) const {
+template <>
+llvm::Error
+Analysis::run<Analysis::PrintClusters>(llvm::raw_ostream &OS) const {
   if (Clustering_.getPoints().empty())
     return llvm::Error::success();
 
@@ -133,8 +135,9 @@ Analysis::makePointsPerSchedClass() cons
   return PointsPerSchedClass;
 }
 
-llvm::Error
-Analysis::printSchedClassInconsistencies(llvm::raw_ostream &OS) const {
+template <>
+llvm::Error Analysis::run<Analysis::PrintSchedClassInconsistencies>(
+    llvm::raw_ostream &OS) const {
   // All the points in a scheduling class should be in the same cluster.
   // Print any scheduling class for which this is not the case.
   for (const auto &SchedClassAndPoints : makePointsPerSchedClass()) {
@@ -167,4 +170,9 @@ Analysis::printSchedClassInconsistencies
   return llvm::Error::success();
 }
 
+template llvm::Error
+Analysis::run<Analysis::PrintClusters>(llvm::raw_ostream &OS) const;
+template llvm::Error Analysis::run<Analysis::PrintSchedClassInconsistencies>(
+    llvm::raw_ostream &OS) const;
+
 } // namespace exegesis

Modified: llvm/trunk/tools/llvm-exegesis/lib/Analysis.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-exegesis/lib/Analysis.h?rev=332608&r1=332607&r2=332608&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-exegesis/lib/Analysis.h (original)
+++ llvm/trunk/tools/llvm-exegesis/lib/Analysis.h Thu May 17 06:41:28 2018
@@ -33,10 +33,11 @@ public:
            const InstructionBenchmarkClustering &Clustering);
 
   // Prints a csv of instructions for each cluster.
-  llvm::Error printClusters(llvm::raw_ostream &OS) const;
-
+  struct PrintClusters {};
   // Find potential errors in the scheduling information given measurements.
-  llvm::Error printSchedClassInconsistencies(llvm::raw_ostream &OS) const;
+  struct PrintSchedClassInconsistencies {};
+
+  template <typename Pass> llvm::Error run(llvm::raw_ostream &OS) const;
 
 private:
   void printInstructionRow(bool PrintSchedClass, size_t PointId,

Modified: llvm/trunk/tools/llvm-exegesis/llvm-exegesis.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-exegesis/llvm-exegesis.cpp?rev=332608&r1=332607&r2=332608&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-exegesis/llvm-exegesis.cpp (original)
+++ llvm/trunk/tools/llvm-exegesis/llvm-exegesis.cpp Thu May 17 06:41:28 2018
@@ -70,9 +70,12 @@ static llvm::cl::opt<float>
                     llvm::cl::desc("dbscan epsilon for analysis clustering"),
                     llvm::cl::init(0.1));
 
-static llvm::cl::opt<std::string> AnalysisClustersFile("analysis-clusters-file",
-                                                       llvm::cl::desc(""),
-                                                       llvm::cl::init("-"));
+static llvm::cl::opt<std::string>
+    AnalysisClustersOutputFile("analysis-clusters-output-file",
+                               llvm::cl::desc(""), llvm::cl::init("-"));
+static llvm::cl::opt<std::string>
+    AnalysisInconsistenciesOutputFile("analysis-inconsistencies-output-file",
+                                      llvm::cl::desc(""), llvm::cl::init("-"));
 
 namespace exegesis {
 
@@ -125,7 +128,27 @@ void benchmarkMain() {
   exegesis::pfm::pfmTerminate();
 }
 
-void analysisMain() {
+// Prints the results of running analysis pass `Pass` to file `OutputFilename`
+// if OutputFilename is non-empty.
+template <typename Pass>
+static void maybeRunAnalysis(const Analysis &Analyzer, const std::string &Name,
+                      const std::string &OutputFilename) {
+  if (OutputFilename.empty())
+    return;
+  if (OutputFilename != "-") {
+    llvm::errs() << "Printing " << Name << " results to file '"
+                 << OutputFilename << "'\n";
+  }
+  std::error_code ErrorCode;
+  llvm::raw_fd_ostream ClustersOS(OutputFilename, ErrorCode,
+                                  llvm::sys::fs::F_RW);
+  if (ErrorCode)
+    llvm::report_fatal_error("cannot open out file: " + OutputFilename);
+  if (auto Err = Analyzer.run<Pass>(ClustersOS))
+    llvm::report_fatal_error(std::move(Err));
+}
+
+static void analysisMain() {
   // Read benchmarks.
   const std::vector<InstructionBenchmark> Points =
       InstructionBenchmark::readYamlsOrDie(BenchmarkFile);
@@ -152,17 +175,11 @@ void analysisMain() {
 
   const Analysis Analyzer(*TheTarget, Clustering);
 
-  std::error_code ErrorCode;
-  llvm::raw_fd_ostream ClustersOS(AnalysisClustersFile, ErrorCode,
-                                  llvm::sys::fs::F_RW);
-  if (ErrorCode)
-    llvm::report_fatal_error("cannot open out file: " + AnalysisClustersFile);
-
-  if (auto Err = Analyzer.printClusters(ClustersOS))
-    llvm::report_fatal_error(std::move(Err));
-
-  if (auto Err = Analyzer.printSchedClassInconsistencies(llvm::outs()))
-    llvm::report_fatal_error(std::move(Err));
+  maybeRunAnalysis<Analysis::PrintClusters>(Analyzer, "analysis clusters",
+                                            AnalysisClustersOutputFile);
+  maybeRunAnalysis<Analysis::PrintSchedClassInconsistencies>(
+      Analyzer, "sched class consistency analysis",
+      AnalysisInconsistenciesOutputFile);
 }
 
 } // namespace exegesis




More information about the llvm-commits mailing list