[llvm] r287356 - [LTO] Add option to generate optimization records

Hahnfeld, Jonas via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 21 01:44:02 PST 2016


Hi,

either this one or r287450 is giving me problems: I use LLVM_LINK_LLVM_DYLIB 
and therefore opt now has two options with the same name:
: CommandLine Error: Option 'pass-remarks-output' registered more than once!
LLVM ERROR: inconsistency in registered CommandLine options

Could this one be renamed or otherwise ensured that there is no duplicate?

Thanks,
Jonas

> -----Original Message-----
> From: llvm-commits [mailto:llvm-commits-bounces at lists.llvm.org] On Behalf
> Of Adam Nemet via llvm-commits
> Sent: Friday, November 18, 2016 7:06 PM
> To: llvm-commits at lists.llvm.org
> Subject: [llvm] r287356 - [LTO] Add option to generate optimization records
>
> Author: anemet
> Date: Fri Nov 18 12:06:28 2016
> New Revision: 287356
>
> URL: http://llvm.org/viewvc/llvm-project?rev=287356&view=rev
> Log:
> [LTO] Add option to generate optimization records
>
> It is used to drive this from the clang driver via -mllvm.
>
> Same option name is used as in opt.
>
> Differential Revision: https://reviews.llvm.org/D26832
>
> Modified:
>     llvm/trunk/include/llvm/LTO/legacy/LTOCodeGenerator.h
>     llvm/trunk/lib/LTO/LTOCodeGenerator.cpp
>     llvm/trunk/test/LTO/X86/diagnostic-handler-remarks.ll
>
> Modified: llvm/trunk/include/llvm/LTO/legacy/LTOCodeGenerator.h
> URL: http://llvm.org/viewvc/llvm-
> project/llvm/trunk/include/llvm/LTO/legacy/LTOCodeGenerator.h?rev=2873
> 56&r1=287355&r2=287356&view=diff
> ==========================================================
> ====================
> --- llvm/trunk/include/llvm/LTO/legacy/LTOCodeGenerator.h (original)
> +++ llvm/trunk/include/llvm/LTO/legacy/LTOCodeGenerator.h Fri Nov 18
> +++ 12:06:28 2016
> @@ -41,6 +41,7 @@
>  #include "llvm/ADT/StringSet.h"
>  #include "llvm/IR/GlobalValue.h"
>  #include "llvm/IR/Module.h"
> +#include "llvm/Support/ToolOutputFile.h"
>  #include "llvm/Target/TargetMachine.h"
>  #include "llvm/Target/TargetOptions.h"
>  #include <string>
> @@ -205,6 +206,9 @@ private:
>    void emitError(const std::string &ErrMsg);
>    void emitWarning(const std::string &ErrMsg);
>
> +  bool setupOptimizationRemarks();
> +  void finishOptimizationRemarks();
> +
>    LLVMContext &Context;
>    std::unique_ptr<Module> MergedModule;
>    std::unique_ptr<Linker> TheLinker;
> @@ -232,6 +236,7 @@ private:
>    bool ShouldEmbedUselists = false;
>    bool ShouldRestoreGlobalsLinkage = false;
>    TargetMachine::CodeGenFileType FileType =
> TargetMachine::CGFT_ObjectFile;
> +  std::unique_ptr<tool_output_file> DiagnosticOutputFile;
>  };
>  }
>  #endif
>
> Modified: llvm/trunk/lib/LTO/LTOCodeGenerator.cpp
> URL: http://llvm.org/viewvc/llvm-
> project/llvm/trunk/lib/LTO/LTOCodeGenerator.cpp?rev=287356&r1=287355
> &r2=287356&view=diff
> ==========================================================
> ====================
> --- llvm/trunk/lib/LTO/LTOCodeGenerator.cpp (original)
> +++ llvm/trunk/lib/LTO/LTOCodeGenerator.cpp Fri Nov 18 12:06:28 2016
> @@ -49,6 +49,7 @@
>  #include "llvm/Support/TargetRegistry.h"
>  #include "llvm/Support/TargetSelect.h"
>  #include "llvm/Support/ToolOutputFile.h"
> +#include "llvm/Support/YAMLTraits.h"
>  #include "llvm/Support/raw_ostream.h"
>  #include "llvm/Target/TargetLowering.h"
>  #include "llvm/Target/TargetOptions.h"
> @@ -92,6 +93,11 @@ cl::opt<bool> LTOStripInvalidDebugInfo(
>      cl::Hidden);
>  }
>
> +static cl::opt<std::string>
> +    RemarksFilename("pass-remarks-output",
> +                    cl::desc("Output filename for pass remarks"),
> +                    cl::value_desc("filename"));
> +
>  LTOCodeGenerator::LTOCodeGenerator(LLVMContext &Context)
>      : Context(Context), MergedModule(new Module("ld-temp.o", Context)),
>        TheLinker(new Linker(*MergedModule)) { @@ -495,6 +501,29 @@ void
> LTOCodeGenerator::verifyMergedModul
>      report_fatal_error("Broken module found, compilation aborted!");  }
>
> +bool LTOCodeGenerator::setupOptimizationRemarks() {
> +  if (RemarksFilename != "") {
> +    std::error_code EC;
> +    DiagnosticOutputFile = llvm::make_unique<tool_output_file>(
> +        RemarksFilename, EC, sys::fs::F_None);
> +    if (EC) {
> +      emitError(EC.message());
> +      return false;
> +    }
> +    Context.setDiagnosticsOutputFile(
> +        new yaml::Output(DiagnosticOutputFile->os()));
> +  }
> +  return true;
> +}
> +
> +void LTOCodeGenerator::finishOptimizationRemarks() {
> +  if (DiagnosticOutputFile) {
> +    DiagnosticOutputFile->keep();
> +    // FIXME: LTOCodeGenerator dtor is not invoked on Darwin
> +    DiagnosticOutputFile->os().flush();
> +  }
> +}
> +
>  /// Optimize merged modules using various IPO passes  bool
> LTOCodeGenerator::optimize(bool DisableVerify, bool DisableInline,
>                                  bool DisableGVNLoadPRE, @@ -502,6 +531,9 @@ 
> bool
> LTOCodeGenerator::optimize(bool Dis
>    if (!this->determineTarget())
>      return false;
>
> +  if (!setupOptimizationRemarks())
> +    return false;
> +
>    // We always run the verifier once on the merged module, the
> `DisableVerify`
>    // parameter only applies to subsequent verify.
>    verifyMergedModuleOnce();
> @@ -535,6 +567,8 @@ bool LTOCodeGenerator::optimize(bool Dis
>    // Run our queue of passes all at once now, efficiently.
>    passes.run(*MergedModule);
>
> +  finishOptimizationRemarks();
> +
>    return true;
>  }
>
>
> Modified: llvm/trunk/test/LTO/X86/diagnostic-handler-remarks.ll
> URL: http://llvm.org/viewvc/llvm-
> project/llvm/trunk/test/LTO/X86/diagnostic-handler-
> remarks.ll?rev=287356&r1=287355&r2=287356&view=diff
> ==========================================================
> ====================
> --- llvm/trunk/test/LTO/X86/diagnostic-handler-remarks.ll (original)
> +++ llvm/trunk/test/LTO/X86/diagnostic-handler-remarks.ll Fri Nov 18
> +++ 12:06:28 2016
> @@ -27,6 +27,13 @@
>  ; RUN:     FileCheck %s -allow-empty
>  ; RUN: llvm-nm %t.o | FileCheck %s -check-prefix NM
>
> +; Optimization records are collected regardless of the diagnostic
> +handler ; RUN: llvm-lto -pass-remarks-output=%t.yaml \
> +; RUN:          -exported-symbol _func2 \
> +; RUN:          -exported-symbol _main -o %t.o %t.bc 2>&1 | \
> +; RUN:     FileCheck %s -allow-empty
> +; RUN: cat %t.yaml | FileCheck %s -check-prefix=YAML
> +
>  ; REMARKS: remark: {{.*}} foo inlined into main  ; REMARKS: remark: {{.*}}
> loop not vectorized: cannot prove it is safe to reorder memory operations  ;
> REMARKS_DH: llvm-lto: remark: {{.*}} foo inlined into main @@ -37,6 +44,16
> @@  ; NM: func2  ; NM: main
>
> +; YAML: --- !Passed
> +; YAML: Pass:            inline
> +; YAML: Name:            Inlined
> +; YAML: Function:        main
> +; YAML: Args:
> +; YAML:   - Callee:          foo
> +; YAML:   - String:          ' inlined into '
> +; YAML:   - Caller:          main
> +; YAML: ...
> +
>  target triple = "x86_64-apple-darwin"
>
>  declare i32 @bar()
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 5868 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161121/02a4300a/attachment.bin>


More information about the llvm-commits mailing list