Index: include/llvm/LTO/LTOCodeGenerator.h =================================================================== --- include/llvm/LTO/LTOCodeGenerator.h +++ include/llvm/LTO/LTOCodeGenerator.h @@ -106,6 +106,7 @@ bool disableInline, bool disableGVNLoadPRE, bool disableVectorization, + bool lowerbitsets, std::string &errMsg); // As with compile_to_file(), this function compiles the merged module into @@ -118,6 +119,7 @@ bool disableInline, bool disableGVNLoadPRE, bool disableVectorization, + bool lowerbitsets, std::string &errMsg); // Optimizes the merged module. Returns true on success. @@ -125,6 +127,7 @@ bool disableInline, bool disableGVNLoadPRE, bool disableVectorization, + bool lowerbitsets, std::string &errMsg); // Compiles the merged optimized module into a single object file. It brings Index: include/llvm/Transforms/IPO/PassManagerBuilder.h =================================================================== --- include/llvm/Transforms/IPO/PassManagerBuilder.h +++ include/llvm/Transforms/IPO/PassManagerBuilder.h @@ -123,6 +123,9 @@ bool StripDebug; bool MergeFunctions; + /// Whether to lower bit sets at link time. + bool LowerBitSets; + private: /// ExtensionList - This is list of all of the extensions that are registered. std::vector > Extensions; Index: lib/LTO/LTOCodeGenerator.cpp =================================================================== --- lib/LTO/LTOCodeGenerator.cpp +++ lib/LTO/LTOCodeGenerator.cpp @@ -295,9 +295,10 @@ bool disableInline, bool disableGVNLoadPRE, bool disableVectorization, + bool lowerbitsets, std::string &errMsg) { if (!optimize(disableOpt, disableInline, disableGVNLoadPRE, - disableVectorization, errMsg)) + disableVectorization, lowerbitsets, errMsg)) return false; return compileOptimizedToFile(name, errMsg); @@ -308,9 +309,10 @@ bool disableInline, bool disableGVNLoadPRE, bool disableVectorization, + bool lowerbitsets, std::string &errMsg) { if (!optimize(disableOpt, disableInline, disableGVNLoadPRE, - disableVectorization, errMsg)) + disableVectorization, lowerbitsets, errMsg)) return nullptr; return compileOptimized(length, errMsg); @@ -516,6 +518,7 @@ bool DisableInline, bool DisableGVNLoadPRE, bool DisableVectorization, + bool LowerBitSets, std::string &errMsg) { if (!this->determineTarget(errMsg)) return false; @@ -544,6 +547,7 @@ PMB.LibraryInfo = new TargetLibraryInfoImpl(TargetTriple); if (DisableOpt) PMB.OptLevel = 0; + PMB.LowerBitSets = LowerBitSets; PMB.VerifyInput = true; PMB.VerifyOutput = true; Index: lib/Transforms/IPO/PassManagerBuilder.cpp =================================================================== --- lib/Transforms/IPO/PassManagerBuilder.cpp +++ lib/Transforms/IPO/PassManagerBuilder.cpp @@ -99,6 +99,7 @@ VerifyOutput = false; StripDebug = false; MergeFunctions = false; + LowerBitSets = false; } PassManagerBuilder::~PassManagerBuilder() { @@ -493,9 +494,6 @@ PM.add(createJumpThreadingPass()); - // Lower bitset metadata to bitsets. - PM.add(createLowerBitSetsPass()); - // Delete basic blocks, which optimization passes may have killed. PM.add(createCFGSimplificationPass()); @@ -524,6 +522,18 @@ if (OptLevel != 0) addLTOOptimizationPasses(PM); + if (LowerBitSets) { + // Lower bitset metadata to bitsets. + PM.add(createLowerBitSetsPass()); + + // Clean up after the bit set lowering pass. + PM.add(createCFGSimplificationPass()); + + // Discard unused entities if we haven't already done so. + if (OptLevel == 0) + PM.add(createGlobalDCEPass()); + } + if (VerifyOutput) { PM.add(createVerifierPass()); PM.add(createDebugInfoVerifierPass()); Index: test/tools/gold/disable-opt.ll =================================================================== --- /dev/null +++ test/tools/gold/disable-opt.ll @@ -0,0 +1,14 @@ +; RUN: llvm-as -o %t.bc %s +; RUN: %gold -plugin %llvmshlibdir/LLVMgold.so -plugin-opt=save-temps \ +; RUN: -plugin-opt=disable-opt -r -o %t.o %t.bc +; RUN: llvm-dis < %t.o.opt.bc -o - | FileCheck %s + +; CHECK: define internal void @foo( +define internal void @foo() { + ret void +} + +define void @bar() { + call void @foo() + ret void +} Index: test/tools/gold/lowerbitsets.ll =================================================================== --- /dev/null +++ test/tools/gold/lowerbitsets.ll @@ -0,0 +1,11 @@ +; RUN: llvm-as -o %t.bc %s +; RUN: %gold -plugin %llvmshlibdir/LLVMgold.so -plugin-opt=save-temps \ +; RUN: -plugin-opt=lowerbitsets -r -o %t.o %t.bc +; RUN: llvm-dis < %t.o.opt.bc -o - | FileCheck %s + +@a = constant i32 1 + +!0 = !{!"bitset1", i32* @a, i32 0} + +; CHECK-NOT: llvm.bitsets +!llvm.bitsets = !{ !0 } Index: tools/gold/gold-plugin.cpp =================================================================== --- tools/gold/gold-plugin.cpp +++ tools/gold/gold-plugin.cpp @@ -95,6 +95,8 @@ static std::string extra_library_path; static std::string triple; static std::string mcpu; + static bool DisableOpt = false; + static bool LowerBitSets = false; // Additional options to pass into the code generator. // Note: This array will contain all plugin options which are not claimed // as plugin exclusive to pass to the code generator. @@ -124,6 +126,10 @@ TheOutputType = OT_SAVE_TEMPS; } else if (opt == "disable-output") { TheOutputType = OT_DISABLE; + } else if (opt == "disable-opt") { + DisableOpt = true; + } else if (opt == "lowerbitsets") { + LowerBitSets = true; } else { // Save this option to pass to the code generator. // ParseCommandLineOptions() expects argv[0] to be program name. Lazily @@ -724,6 +730,9 @@ PMB.VerifyOutput = true; PMB.LoopVectorize = true; PMB.SLPVectorize = true; + if (options::DisableOpt) + PMB.OptLevel = 0; + PMB.LowerBitSets = options::LowerBitSets; PMB.populateLTOPassManager(passes); passes.run(M); } Index: tools/llvm-lto/llvm-lto.cpp =================================================================== --- tools/llvm-lto/llvm-lto.cpp +++ tools/llvm-lto/llvm-lto.cpp @@ -43,6 +43,10 @@ cl::desc("Do not run loop or slp vectorization during LTO")); static cl::opt +LowerBitSets("lowerbitsets", cl::init(false), + cl::desc("Run the lowerbitsets pass")); + +static cl::opt UseDiagnosticHandler("use-diagnostic-handler", cl::init(false), cl::desc("Use a diagnostic handler to test the handler interface")); @@ -246,7 +250,7 @@ std::string ErrorInfo; const void *Code = CodeGen.compile(&len, DisableOpt, DisableInline, DisableGVNLoadPRE, - DisableLTOVectorization, ErrorInfo); + DisableLTOVectorization, LowerBitSets, ErrorInfo); if (!Code) { errs() << argv[0] << ": error compiling the code: " << ErrorInfo << "\n"; @@ -267,7 +271,7 @@ const char *OutputName = nullptr; if (!CodeGen.compile_to_file(&OutputName, DisableOpt, DisableInline, DisableGVNLoadPRE, DisableLTOVectorization, - ErrorInfo)) { + LowerBitSets, ErrorInfo)) { errs() << argv[0] << ": error compiling the code: " << ErrorInfo << "\n"; Index: tools/lto/lto.cpp =================================================================== --- tools/lto/lto.cpp +++ tools/lto/lto.cpp @@ -39,6 +39,10 @@ DisableLTOVectorization("disable-lto-vectorization", cl::init(false), cl::desc("Do not run loop or slp vectorization during LTO")); +static cl::opt +LowerBitSets("lowerbitsets", cl::init(false), + cl::desc("Run the lowerbitsets pass")); + // Holds most recent error string. // *** Not thread safe *** static std::string sLastErrorString; @@ -298,7 +302,7 @@ } return unwrap(cg)->compile(length, DisableOpt, DisableInline, DisableGVNLoadPRE, DisableLTOVectorization, - sLastErrorString); + LowerBitSets, sLastErrorString); } bool lto_codegen_optimize(lto_code_gen_t cg) { @@ -309,7 +313,7 @@ } return !unwrap(cg)->optimize(DisableOpt, DisableInline, DisableGVNLoadPRE, DisableLTOVectorization, - sLastErrorString); + LowerBitSets, sLastErrorString); } const void *lto_codegen_compile_optimized(lto_code_gen_t cg, size_t *length) { @@ -329,7 +333,7 @@ } return !unwrap(cg)->compile_to_file( name, DisableOpt, DisableInline, DisableGVNLoadPRE, - DisableLTOVectorization, sLastErrorString); + DisableLTOVectorization, LowerBitSets, sLastErrorString); } void lto_codegen_debug_options(lto_code_gen_t cg, const char *opt) {