[PATCH] D47013: [llvm-exegesis] Write out inconsistencies to a file.

Clement Courbet via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu May 17 05:45:01 PDT 2018


courbet created this revision.
courbet added a reviewer: gchatelet.
Herald added a subscriber: tschuett.

Repository:
  rL LLVM

https://reviews.llvm.org/D47013

Files:
  tools/llvm-exegesis/llvm-exegesis.cpp


Index: tools/llvm-exegesis/llvm-exegesis.cpp
===================================================================
--- tools/llvm-exegesis/llvm-exegesis.cpp
+++ tools/llvm-exegesis/llvm-exegesis.cpp
@@ -73,6 +73,9 @@
 static llvm::cl::opt<std::string> AnalysisClustersFile("analysis-clusters-file",
                                                        llvm::cl::desc(""),
                                                        llvm::cl::init("-"));
+static llvm::cl::opt<std::string>
+    AnalysisInconsistenciesFile("analysis-inconsistencies-file",
+                                llvm::cl::desc(""), llvm::cl::init("-"));
 
 namespace exegesis {
 
@@ -125,6 +128,26 @@
   exegesis::pfm::pfmTerminate();
 }
 
+// Prints the results of running analysis printer `Print` to file `Filename` if
+// Filename is non-empty.
+void maybePrintAnalysis(const Analysis &Analyzer, const std::string &Name,
+                        const std::string &Filename,
+                        llvm::Error (Analysis::*Print)(llvm::raw_ostream &)
+                            const) {
+  if (!Filename.empty()) {
+    if (Filename != "-") {
+      llvm::errs() << "Printing " << Name << " results to file '" << Filename
+                   << "'\n";
+    }
+    std::error_code ErrorCode;
+    llvm::raw_fd_ostream ClustersOS(Filename, ErrorCode, llvm::sys::fs::F_RW);
+    if (ErrorCode)
+      llvm::report_fatal_error("cannot open out file: " + Filename);
+    if (auto Err = (Analyzer.*Print)(ClustersOS))
+      llvm::report_fatal_error(std::move(Err));
+  }
+}
+
 void analysisMain() {
   // Read benchmarks.
   const std::vector<InstructionBenchmark> Points =
@@ -152,17 +175,11 @@
 
   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));
+  maybePrintAnalysis(Analyzer, "analysis clusters", AnalysisClustersFile,
+                     &Analysis::printClusters);
+  maybePrintAnalysis(Analyzer, "sched class consistency analysis",
+                     AnalysisInconsistenciesFile,
+                     &Analysis::printSchedClassInconsistencies);
 }
 
 } // namespace exegesis


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D47013.147300.patch
Type: text/x-patch
Size: 2543 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180517/9bef941c/attachment.bin>


More information about the llvm-commits mailing list