]> granicus.if.org Git - llvm/commitdiff
[lib/LTO] Initial support for optimization remarks in the new API.
authorDavide Italiano <davide@freebsd.org>
Sun, 12 Feb 2017 03:31:30 +0000 (03:31 +0000)
committerDavide Italiano <davide@freebsd.org>
Sun, 12 Feb 2017 03:31:30 +0000 (03:31 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@294882 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/LTO/Config.h
lib/LTO/LTOBackend.cpp
test/LTO/Resolution/X86/diagnostic-handler-remarks.ll [new file with mode: 0644]
tools/llvm-lto2/llvm-lto2.cpp

index 3aa48c9f7c2868f0a8f5caf8ea3f0c9e03d68ae0..06bfdbcecd564c5a682ccf7d3ee07796e1d4840f 100644 (file)
@@ -68,6 +68,12 @@ struct Config {
   /// Sample PGO profile path.
   std::string SampleProfile;
 
+  /// Optimization remarks file path.
+  std::string RemarksFilename = "";
+
+  /// Whether to emit optimization remarks with hotness informations.
+  bool RemarksWithHotness = false;
+
   bool ShouldDiscardValueNames = true;
   DiagnosticHandlerFunction DiagHandler;
 
index 5c3e442faa9a1ed480913c45b5e3a831182fb152..1afdc13045bc2cb28b485afd4322a52d6b675693 100644 (file)
@@ -366,6 +366,12 @@ Error lto::backend(Config &C, AddStreamFn AddStream,
 
   handleAsmUndefinedRefs(*Mod, *TM);
 
+  // Setup optimization remarks.
+  auto DiagFileOrErr = lto::setupOptimizationRemarks(
+      Mod->getContext(), C.RemarksFilename, C.RemarksWithHotness);
+  if (!DiagFileOrErr)
+    return DiagFileOrErr.takeError();
+
   if (!C.CodeGenOnly)
     if (!opt(C, TM.get(), 0, *Mod, /*IsThinLTO=*/false, CombinedIndex))
       return Error::success();
diff --git a/test/LTO/Resolution/X86/diagnostic-handler-remarks.ll b/test/LTO/Resolution/X86/diagnostic-handler-remarks.ll
new file mode 100644 (file)
index 0000000..6e5f923
--- /dev/null
@@ -0,0 +1,33 @@
+; RUN: llvm-as < %s >%t.bc
+
+; RUN: rm -f %t.yaml
+; RUN: llvm-lto2 -pass-remarks-output=%t.yaml \
+; RUN:           -r %t.bc,tinkywinky,p \
+; RUN:           -r %t.bc,patatino,px \
+; RUN:           -r %t.bc,main,px -o %t.o %t.bc 2>&1
+; RUN: cat %t.yaml | FileCheck %s -check-prefix=YAML
+
+; YAML:      --- !Passed
+; YAML-NEXT: Pass:            inline
+; YAML-NEXT: Name:            Inlined
+; YAML-NEXT: Function:        main
+; YAML-NEXT: Args:
+; YAML-NEXT:   - Callee:          tinkywinky
+; YAML-NEXT:   - String:          ' inlined into '
+; YAML-NEXT:   - Caller:          main
+; YAML-NEXT: ...
+
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-scei-ps4"
+
+declare i32 @patatino()
+
+define i32 @tinkywinky() {
+  %a = call i32 @patatino()
+  ret i32 %a
+}
+
+define i32 @main() {
+  %i = call i32 @tinkywinky()
+  ret i32 %i
+}
index c09311a05b90dcbe5f105bc66a448033f05f385d..b2fe21643627aa1e67fbc1b6cb878ab792ecc79b 100644 (file)
@@ -90,6 +90,10 @@ static cl::opt<std::string> DefaultTriple(
     cl::desc(
         "Replace unspecified target triples in input files with this triple"));
 
+static cl::opt<std::string>
+    OptRemarksOutput("pass-remarks-output",
+                     cl::desc("YAML output file for optimization remarks"));
+
 static void check(Error E, std::string Msg) {
   if (!E)
     return;
@@ -176,6 +180,9 @@ int main(int argc, char **argv) {
     check(Conf.addSaveTemps(OutputFilename + "."),
           "Config::addSaveTemps failed");
 
+  // Optimization remarks.
+  Conf.RemarksFilename = OptRemarksOutput;
+
   // Run a custom pipeline, if asked for.
   Conf.OptPipeline = OptPipeline;
   Conf.AAPipeline = AAPipeline;