[llvm] r247729 - LTO: Disable extra verify runs in release builds

Duncan P. N. Exon Smith via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 16 10:52:18 PDT 2015


> On 2015-Sep-16, at 09:40, David Blaikie <dblaikie at gmail.com> wrote:
> 
> 
> 
> On Tue, Sep 15, 2015 at 3:26 PM, Duncan P. N. Exon Smith via llvm-commits <llvm-commits at lists.llvm.org> wrote:
> Author: dexonsmith
> Date: Tue Sep 15 17:26:11 2015
> New Revision: 247729
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=247729&view=rev
> Log:
> LTO: Disable extra verify runs in release builds
> 
> The verifier currently runs three times in LTO: (1) after parsing, (2)
> at the beginning of the optimization pipeline, and (3) at the end of it.
> 
> The first run is important, since we're not sure where the bitcode comes
> from and it's nice to validate it, but in release builds the extra runs
> aren't appropriate.
> 
> This commit:
>   - Allows these runs to be disabled in LTOCodeGenerator.
>   - Adds command-line options to llvm-lto.
>   - Adds command-line options to libLTO.dylib, and disables the verifier
>     by default in release builds (based on NDEBUG).
> 
> Disables the extra runs, but not the input verification, I take it?

Yes.  Somehow with all that text I still managed to be ambiguous :/.

>  
> 
> This shaves about 3.5% off the runtime of ld64 when linking
> verify-uselistorder with -flto -g.
> 
> rdar://22509081
> 
> Added:
>     llvm/trunk/test/LTO/X86/disable-verify.ll
> Modified:
>     llvm/trunk/include/llvm/LTO/LTOCodeGenerator.h
>     llvm/trunk/lib/LTO/LTOCodeGenerator.cpp
>     llvm/trunk/tools/llvm-lto/llvm-lto.cpp
>     llvm/trunk/tools/lto/lto.cpp
> 
> Modified: llvm/trunk/include/llvm/LTO/LTOCodeGenerator.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/LTO/LTOCodeGenerator.h?rev=247729&r1=247728&r2=247729&view=diff
> ==============================================================================
> --- llvm/trunk/include/llvm/LTO/LTOCodeGenerator.h (original)
> +++ llvm/trunk/include/llvm/LTO/LTOCodeGenerator.h Tue Sep 15 17:26:11 2015
> @@ -110,9 +110,9 @@ struct LTOCodeGenerator {
>    /// \note It is up to the linker to remove the intermediate object file.  Do
>    /// not try to remove the object file in LTOCodeGenerator's destructor as we
>    /// don't who (LTOCodeGenerator or the obj file) will last longer.
> -  bool compile_to_file(const char **Name, bool DisableInline,
> -                       bool DisableGVNLoadPRE, bool DisableVectorization,
> -                       std::string &ErrMsg);
> +  bool compile_to_file(const char **Name, bool DisableVerify,
> +                       bool DisableInline, bool DisableGVNLoadPRE,
> +                       bool DisableVectorization, std::string &ErrMsg);
> 
>    /// As with compile_to_file(), this function compiles the merged module into
>    /// single object file. Instead of returning the object-file-path to the
> @@ -120,13 +120,13 @@ struct LTOCodeGenerator {
>    /// to the caller. This function should delete intermediate object file once
>    /// its content is brought to memory. Return NULL if the compilation was not
>    /// successful.
> -  std::unique_ptr<MemoryBuffer> compile(bool DisableInline,
> +  std::unique_ptr<MemoryBuffer> compile(bool DisableVerify, bool DisableInline,
>                                          bool DisableGVNLoadPRE,
>                                          bool DisableVectorization,
>                                          std::string &errMsg);
> 
>    /// Optimizes the merged module.  Returns true on success.
> -  bool optimize(bool DisableInline, bool DisableGVNLoadPRE,
> +  bool optimize(bool DisableVerify, bool DisableInline, bool DisableGVNLoadPRE,
>                  bool DisableVectorization, std::string &ErrMsg);
> 
>    /// Compiles the merged optimized module into a single object file. It brings
> 
> Modified: llvm/trunk/lib/LTO/LTOCodeGenerator.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/LTO/LTOCodeGenerator.cpp?rev=247729&r1=247728&r2=247729&view=diff
> ==============================================================================
> --- llvm/trunk/lib/LTO/LTOCodeGenerator.cpp (original)
> +++ llvm/trunk/lib/LTO/LTOCodeGenerator.cpp Tue Sep 15 17:26:11 2015
> @@ -265,20 +265,24 @@ LTOCodeGenerator::compileOptimized(std::
>    return std::move(*BufferOrErr);
>  }
> 
> -bool LTOCodeGenerator::compile_to_file(const char **Name, bool DisableInline,
> +bool LTOCodeGenerator::compile_to_file(const char **Name, bool DisableVerify,
> +                                       bool DisableInline,
>                                         bool DisableGVNLoadPRE,
>                                         bool DisableVectorization,
>                                         std::string &ErrMsg) {
> -  if (!optimize(DisableInline, DisableGVNLoadPRE, DisableVectorization, ErrMsg))
> +  if (!optimize(DisableVerify, DisableInline, DisableGVNLoadPRE,
> +                DisableVectorization, ErrMsg))
>      return false;
> 
>    return compileOptimizedToFile(Name, ErrMsg);
>  }
> 
>  std::unique_ptr<MemoryBuffer>
> -LTOCodeGenerator::compile(bool DisableInline, bool DisableGVNLoadPRE,
> -                          bool DisableVectorization, std::string &ErrMsg) {
> -  if (!optimize(DisableInline, DisableGVNLoadPRE, DisableVectorization, ErrMsg))
> +LTOCodeGenerator::compile(bool DisableVerify, bool DisableInline,
> +                          bool DisableGVNLoadPRE, bool DisableVectorization,
> +                          std::string &ErrMsg) {
> +  if (!optimize(DisableVerify, DisableInline, DisableGVNLoadPRE,
> +                DisableVectorization, ErrMsg))
>      return nullptr;
> 
>    return compileOptimized(ErrMsg);
> @@ -459,7 +463,8 @@ void LTOCodeGenerator::applyScopeRestric
>  }
> 
>  /// Optimize merged modules using various IPO passes
> -bool LTOCodeGenerator::optimize(bool DisableInline, bool DisableGVNLoadPRE,
> +bool LTOCodeGenerator::optimize(bool DisableVerify, bool DisableInline,
> +                                bool DisableGVNLoadPRE,
>                                  bool DisableVectorization,
>                                  std::string &ErrMsg) {
>    if (!this->determineTarget(ErrMsg))
> @@ -486,8 +491,8 @@ bool LTOCodeGenerator::optimize(bool Dis
>      PMB.Inliner = createFunctionInliningPass();
>    PMB.LibraryInfo = new TargetLibraryInfoImpl(TargetTriple);
>    PMB.OptLevel = OptLevel;
> -  PMB.VerifyInput = true;
> -  PMB.VerifyOutput = true;
> +  PMB.VerifyInput = !DisableVerify;
> +  PMB.VerifyOutput = !DisableVerify;
> 
>    PMB.populateLTOPassManager(passes);
> 
> 
> Added: llvm/trunk/test/LTO/X86/disable-verify.ll
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/LTO/X86/disable-verify.ll?rev=247729&view=auto
> ==============================================================================
> --- llvm/trunk/test/LTO/X86/disable-verify.ll (added)
> +++ llvm/trunk/test/LTO/X86/disable-verify.ll Tue Sep 15 17:26:11 2015
> @@ -0,0 +1,18 @@
> +; RUN: llvm-as < %s >%t.bc
> +; RUN: llvm-lto -debug-pass=Arguments -exported-symbol=_f -o /dev/null %t.bc 2>&1 -disable-verify | FileCheck %s
> +; RUN: llvm-lto -debug-pass=Arguments -exported-symbol=_f -o /dev/null %t.bc 2>&1 | FileCheck %s -check-prefix=VERIFY
> +
> +target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
> +target triple = "x86_64-apple-macosx10.10.0"
> +
> +; -disable-verify should disable verification from the optimization pipeline.
> +; CHECK: Pass Arguments: -verify -internalize
> +; CHECK-NOT: -verify
> +
> +; VERIFY: Pass Arguments: -verify -internalize
> +; VERIFY: Pass Arguments: {{.*}} -verify {{.*}} -verify
> +
> +define void @f() {
> +entry:
> +  ret void
> +}
> 
> Modified: llvm/trunk/tools/llvm-lto/llvm-lto.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-lto/llvm-lto.cpp?rev=247729&r1=247728&r2=247729&view=diff
> ==============================================================================
> --- llvm/trunk/tools/llvm-lto/llvm-lto.cpp (original)
> +++ llvm/trunk/tools/llvm-lto/llvm-lto.cpp Tue Sep 15 17:26:11 2015
> @@ -36,6 +36,10 @@ OptLevel("O",
>           cl::ZeroOrMore,
>           cl::init('2'));
> 
> +static cl::opt<bool> DisableVerify(
> +    "disable-verify", cl::init(false),
> +    cl::desc("Do not run the verifier during the optimization pipeline"));
> +
>  static cl::opt<bool>
>  DisableInline("disable-inlining", cl::init(false),
>    cl::desc("Do not run the inliner pass"));
> @@ -248,7 +252,7 @@ int main(int argc, char **argv) {
> 
>    if (!OutputFilename.empty()) {
>      std::string ErrorInfo;
> -    if (!CodeGen.optimize(DisableInline, DisableGVNLoadPRE,
> +    if (!CodeGen.optimize(DisableVerify, DisableInline, DisableGVNLoadPRE,
>                            DisableLTOVectorization, ErrorInfo)) {
>        errs() << argv[0] << ": error optimizing the code: " << ErrorInfo << "\n";
>        return 1;
> @@ -285,7 +289,7 @@ int main(int argc, char **argv) {
> 
>      std::string ErrorInfo;
>      const char *OutputName = nullptr;
> -    if (!CodeGen.compile_to_file(&OutputName, DisableInline,
> +    if (!CodeGen.compile_to_file(&OutputName, DisableVerify, DisableInline,
>                                   DisableGVNLoadPRE, DisableLTOVectorization,
>                                   ErrorInfo)) {
>        errs() << argv[0]
> 
> Modified: llvm/trunk/tools/lto/lto.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/lto/lto.cpp?rev=247729&r1=247728&r2=247729&view=diff
> ==============================================================================
> --- llvm/trunk/tools/lto/lto.cpp (original)
> +++ llvm/trunk/tools/lto/lto.cpp Tue Sep 15 17:26:11 2015
> @@ -43,6 +43,16 @@ static cl::opt<bool>
>  DisableLTOVectorization("disable-lto-vectorization", cl::init(false),
>    cl::desc("Do not run loop or slp vectorization during LTO"));
> 
> +#ifdef NDEBUG
> +static bool VerifyByDefault = false;
> +#else
> +static bool VerifyByDefault = true;
> +#endif
> +
> +static cl::opt<bool> DisableVerify(
> +    "disable-llvm-verifier", cl::init(!VerifyByDefault),
> +    cl::desc("Don't run the LLVM verifier during the optimization pipeline"));
> +
>  // Holds most recent error string.
>  // *** Not thread safe ***
>  static std::string sLastErrorString;
> @@ -321,8 +331,9 @@ bool lto_codegen_write_merged_modules(lt
>  const void *lto_codegen_compile(lto_code_gen_t cg, size_t *length) {
>    maybeParseOptions(cg);
>    LibLTOCodeGenerator *CG = unwrap(cg);
> -  CG->NativeObjectFile = CG->compile(DisableInline, DisableGVNLoadPRE,
> -                                     DisableLTOVectorization, sLastErrorString);
> +  CG->NativeObjectFile =
> +      CG->compile(DisableVerify, DisableInline, DisableGVNLoadPRE,
> +                  DisableLTOVectorization, sLastErrorString);
>    if (!CG->NativeObjectFile)
>      return nullptr;
>    *length = CG->NativeObjectFile->getBufferSize();
> @@ -331,9 +342,8 @@ const void *lto_codegen_compile(lto_code
> 
>  bool lto_codegen_optimize(lto_code_gen_t cg) {
>    maybeParseOptions(cg);
> -  return !unwrap(cg)->optimize(DisableInline,
> -                               DisableGVNLoadPRE, DisableLTOVectorization,
> -                               sLastErrorString);
> +  return !unwrap(cg)->optimize(DisableVerify, DisableInline, DisableGVNLoadPRE,
> +                               DisableLTOVectorization, sLastErrorString);
>  }
> 
>  const void *lto_codegen_compile_optimized(lto_code_gen_t cg, size_t *length) {
> @@ -349,7 +359,7 @@ const void *lto_codegen_compile_optimize
>  bool lto_codegen_compile_to_file(lto_code_gen_t cg, const char **name) {
>    maybeParseOptions(cg);
>    return !unwrap(cg)->compile_to_file(
> -      name, DisableInline, DisableGVNLoadPRE,
> +      name, DisableVerify, DisableInline, DisableGVNLoadPRE,
>        DisableLTOVectorization, sLastErrorString);
>  }
> 
> 
> 
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
> 



More information about the llvm-commits mailing list