From 8d61ee9e7df8ca3a3194dca4f1d16a5e731c1f07 Mon Sep 17 00:00:00 2001 From: "Duncan P. N. Exon Smith" Date: Wed, 15 Apr 2015 03:14:06 +0000 Subject: [PATCH] uselistorder: Remove the global bits Remove all the global bits to do with preserving use-list order by moving the `cl::opt`s to the individual tools that want them. There's a minor functionality change to `libLTO`, in that you can't send in `-preserve-bc-uselistorder=false`, but making that bit settable (if it's worth doing) should be through explicit LTO API. As a drive-by fix, I removed some includes of `UseListOrder.h` that were made unnecessary by recent commits. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@234973 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/IR/UseListOrder.h | 6 ---- lib/Bitcode/Writer/BitcodeWriterPass.cpp | 1 - lib/IR/CMakeLists.txt | 1 - lib/IR/UseListOrder.cpp | 43 ------------------------ lib/LTO/LTOCodeGenerator.cpp | 7 +--- tools/bugpoint/OptimizerDriver.cpp | 10 ++++-- tools/bugpoint/bugpoint.cpp | 5 --- tools/llvm-as/llvm-as.cpp | 13 ++++--- tools/llvm-dis/llvm-dis.cpp | 8 +++-- tools/llvm-extract/llvm-extract.cpp | 23 +++++++------ tools/llvm-link/llvm-link.cpp | 21 +++++++----- tools/opt/opt.cpp | 30 +++++++++-------- 12 files changed, 61 insertions(+), 107 deletions(-) delete mode 100644 lib/IR/UseListOrder.cpp diff --git a/include/llvm/IR/UseListOrder.h b/include/llvm/IR/UseListOrder.h index 7d8205d15f8..b7c2418d348 100644 --- a/include/llvm/IR/UseListOrder.h +++ b/include/llvm/IR/UseListOrder.h @@ -51,12 +51,6 @@ private: typedef std::vector UseListOrderStack; -/// \brief Whether to preserve use-list ordering. -bool shouldPreserveBitcodeUseListOrder(); -bool shouldPreserveAssemblyUseListOrder(); -void setPreserveBitcodeUseListOrder(bool ShouldPreserve); -void setPreserveAssemblyUseListOrder(bool ShouldPreserve); - } // end namespace llvm #endif diff --git a/lib/Bitcode/Writer/BitcodeWriterPass.cpp b/lib/Bitcode/Writer/BitcodeWriterPass.cpp index ddb121a109a..3165743576e 100644 --- a/lib/Bitcode/Writer/BitcodeWriterPass.cpp +++ b/lib/Bitcode/Writer/BitcodeWriterPass.cpp @@ -15,7 +15,6 @@ #include "llvm/Bitcode/ReaderWriter.h" #include "llvm/IR/Module.h" #include "llvm/IR/PassManager.h" -#include "llvm/IR/UseListOrder.h" #include "llvm/Pass.h" using namespace llvm; diff --git a/lib/IR/CMakeLists.txt b/lib/IR/CMakeLists.txt index 9fef0b292eb..d2e0c383c82 100644 --- a/lib/IR/CMakeLists.txt +++ b/lib/IR/CMakeLists.txt @@ -41,7 +41,6 @@ add_llvm_library(LLVMCore Type.cpp TypeFinder.cpp Use.cpp - UseListOrder.cpp User.cpp Value.cpp ValueSymbolTable.cpp diff --git a/lib/IR/UseListOrder.cpp b/lib/IR/UseListOrder.cpp deleted file mode 100644 index 2bc29f2b95c..00000000000 --- a/lib/IR/UseListOrder.cpp +++ /dev/null @@ -1,43 +0,0 @@ -//===- UseListOrder.cpp - Implement Use List Order ------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -// -// Implement structures and command-line options for preserving use-list order. -// -//===----------------------------------------------------------------------===// - -#include "llvm/IR/UseListOrder.h" -#include "llvm/Support/CommandLine.h" - -using namespace llvm; - -static cl::opt PreserveBitcodeUseListOrder( - "preserve-bc-uselistorder", - cl::desc("Preserve use-list order when writing LLVM bitcode."), - cl::init(false), cl::Hidden); - -static cl::opt PreserveAssemblyUseListOrder( - "preserve-ll-uselistorder", - cl::desc("Preserve use-list order when writing LLVM assembly."), - cl::init(false), cl::Hidden); - -bool llvm::shouldPreserveBitcodeUseListOrder() { - return PreserveBitcodeUseListOrder; -} - -bool llvm::shouldPreserveAssemblyUseListOrder() { - return PreserveAssemblyUseListOrder; -} - -void llvm::setPreserveBitcodeUseListOrder(bool ShouldPreserve) { - PreserveBitcodeUseListOrder = ShouldPreserve; -} - -void llvm::setPreserveAssemblyUseListOrder(bool ShouldPreserve) { - PreserveAssemblyUseListOrder = ShouldPreserve; -} diff --git a/lib/LTO/LTOCodeGenerator.cpp b/lib/LTO/LTOCodeGenerator.cpp index c9ff5b2d019..b4a70119cc2 100644 --- a/lib/LTO/LTOCodeGenerator.cpp +++ b/lib/LTO/LTOCodeGenerator.cpp @@ -29,7 +29,6 @@ #include "llvm/IR/LegacyPassManager.h" #include "llvm/IR/Mangler.h" #include "llvm/IR/Module.h" -#include "llvm/IR/UseListOrder.h" #include "llvm/IR/Verifier.h" #include "llvm/InitializePasses.h" #include "llvm/LTO/LTOModule.h" @@ -216,7 +215,7 @@ bool LTOCodeGenerator::writeMergedModules(const char *path, // write bitcode to it WriteBitcodeToFile(IRLinker.getModule(), Out.os(), - shouldPreserveBitcodeUseListOrder()); + /* ShouldPreserveUseListOrder */ true); Out.os().close(); if (Out.os().has_error()) { @@ -606,10 +605,6 @@ void LTOCodeGenerator::setCodeGenDebugOptions(const char *options) { } void LTOCodeGenerator::parseCodeGenDebugOptions() { - // Turn on -preserve-bc-uselistorder by default, but let the command-line - // override it. - setPreserveBitcodeUseListOrder(true); - // if options were requested, set them if (!CodegenOptions.empty()) cl::ParseCommandLineOptions(CodegenOptions.size(), diff --git a/tools/bugpoint/OptimizerDriver.cpp b/tools/bugpoint/OptimizerDriver.cpp index 3ac263c6de9..344e7b588fb 100644 --- a/tools/bugpoint/OptimizerDriver.cpp +++ b/tools/bugpoint/OptimizerDriver.cpp @@ -20,7 +20,6 @@ #include "llvm/IR/DataLayout.h" #include "llvm/IR/LegacyPassManager.h" #include "llvm/IR/Module.h" -#include "llvm/IR/UseListOrder.h" #include "llvm/IR/Verifier.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/Debug.h" @@ -43,6 +42,11 @@ namespace llvm { extern cl::opt OutputPrefix; } +static cl::opt PreserveBitcodeUseListOrder( + "preserve-bc-uselistorder", + cl::desc("Preserve use-list order when writing LLVM bitcode."), + cl::init(true), cl::Hidden); + namespace { // ChildOutput - This option captures the name of the child output file that // is set up by the parent bugpoint process @@ -56,7 +60,7 @@ namespace { /// file. If an error occurs, true is returned. /// static bool writeProgramToFileAux(tool_output_file &Out, const Module *M) { - WriteBitcodeToFile(M, Out.os(), shouldPreserveBitcodeUseListOrder()); + WriteBitcodeToFile(M, Out.os(), PreserveBitcodeUseListOrder); Out.os().close(); if (!Out.os().has_error()) { Out.keep(); @@ -152,7 +156,7 @@ bool BugDriver::runPasses(Module *Program, tool_output_file InFile(InputFilename, InputFD); - WriteBitcodeToFile(Program, InFile.os(), shouldPreserveBitcodeUseListOrder()); + WriteBitcodeToFile(Program, InFile.os(), PreserveBitcodeUseListOrder); InFile.os().close(); if (InFile.os().has_error()) { errs() << "Error writing bitcode file: " << InputFilename << "\n"; diff --git a/tools/bugpoint/bugpoint.cpp b/tools/bugpoint/bugpoint.cpp index bb790675d75..0ee3784660a 100644 --- a/tools/bugpoint/bugpoint.cpp +++ b/tools/bugpoint/bugpoint.cpp @@ -18,7 +18,6 @@ #include "llvm/IR/LLVMContext.h" #include "llvm/IR/LegacyPassManager.h" #include "llvm/IR/LegacyPassNameParser.h" -#include "llvm/IR/UseListOrder.h" #include "llvm/LinkAllIR.h" #include "llvm/LinkAllPasses.h" #include "llvm/Support/CommandLine.h" @@ -137,10 +136,6 @@ int main(int argc, char **argv) { polly::initializePollyPasses(Registry); #endif - // Turn on -preserve-bc-uselistorder by default, but let the command-line - // override it. - setPreserveBitcodeUseListOrder(true); - cl::ParseCommandLineOptions(argc, argv, "LLVM automatic testcase reducer. See\nhttp://" "llvm.org/cmds/bugpoint.html" diff --git a/tools/llvm-as/llvm-as.cpp b/tools/llvm-as/llvm-as.cpp index 1d48596a24f..c6b3f934202 100644 --- a/tools/llvm-as/llvm-as.cpp +++ b/tools/llvm-as/llvm-as.cpp @@ -19,7 +19,6 @@ #include "llvm/AsmParser/Parser.h" #include "llvm/Bitcode/ReaderWriter.h" #include "llvm/IR/Module.h" -#include "llvm/IR/UseListOrder.h" #include "llvm/IR/Verifier.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/FileSystem.h" @@ -52,6 +51,11 @@ static cl::opt DisableVerify("disable-verify", cl::Hidden, cl::desc("Do not run verifier on input LLVM (dangerous!)")); +static cl::opt PreserveBitcodeUseListOrder( + "preserve-bc-uselistorder", + cl::desc("Preserve use-list order when writing LLVM bitcode."), + cl::init(true), cl::Hidden); + static void WriteOutputFile(const Module *M) { // Infer the output filename if needed. if (OutputFilename.empty()) { @@ -79,7 +83,7 @@ static void WriteOutputFile(const Module *M) { } if (Force || !CheckBitcodeOutputToConsole(Out->os(), true)) - WriteBitcodeToFile(M, Out->os(), shouldPreserveBitcodeUseListOrder()); + WriteBitcodeToFile(M, Out->os(), PreserveBitcodeUseListOrder); // Declare success. Out->keep(); @@ -91,11 +95,6 @@ int main(int argc, char **argv) { PrettyStackTraceProgram X(argc, argv); LLVMContext &Context = getGlobalContext(); llvm_shutdown_obj Y; // Call llvm_shutdown() on exit. - - // Turn on -preserve-bc-uselistorder by default, but let the command-line - // override it. - setPreserveBitcodeUseListOrder(true); - cl::ParseCommandLineOptions(argc, argv, "llvm .ll -> .bc assembler\n"); // Parse the file now... diff --git a/tools/llvm-dis/llvm-dis.cpp b/tools/llvm-dis/llvm-dis.cpp index 106fc18ebf5..1ff23027e16 100644 --- a/tools/llvm-dis/llvm-dis.cpp +++ b/tools/llvm-dis/llvm-dis.cpp @@ -25,7 +25,6 @@ #include "llvm/IR/IntrinsicInst.h" #include "llvm/IR/Module.h" #include "llvm/IR/Type.h" -#include "llvm/IR/UseListOrder.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/DataStream.h" #include "llvm/Support/FileSystem.h" @@ -55,6 +54,11 @@ static cl::opt ShowAnnotations("show-annotations", cl::desc("Add informational comments to the .ll file")); +static cl::opt PreserveAssemblyUseListOrder( + "preserve-ll-uselistorder", + cl::desc("Preserve use-list order when writing LLVM assembly."), + cl::init(false), cl::Hidden); + namespace { static void printDebugLoc(const DebugLoc &DL, formatted_raw_ostream &OS) { @@ -190,7 +194,7 @@ int main(int argc, char **argv) { // All that llvm-dis does is write the assembly to a file. if (!DontPrint) - M->print(Out->os(), Annotator.get(), shouldPreserveAssemblyUseListOrder()); + M->print(Out->os(), Annotator.get(), PreserveAssemblyUseListOrder); // Declare success. Out->keep(); diff --git a/tools/llvm-extract/llvm-extract.cpp b/tools/llvm-extract/llvm-extract.cpp index 1a477934357..936496cd7fe 100644 --- a/tools/llvm-extract/llvm-extract.cpp +++ b/tools/llvm-extract/llvm-extract.cpp @@ -19,7 +19,6 @@ #include "llvm/IR/IRPrintingPasses.h" #include "llvm/IR/LLVMContext.h" #include "llvm/IR/Module.h" -#include "llvm/IR/UseListOrder.h" #include "llvm/IRReader/IRReader.h" #include "llvm/IR/LegacyPassManager.h" #include "llvm/Support/CommandLine.h" @@ -91,6 +90,16 @@ static cl::opt OutputAssembly("S", cl::desc("Write output as LLVM assembly"), cl::Hidden); +static cl::opt PreserveBitcodeUseListOrder( + "preserve-bc-uselistorder", + cl::desc("Preserve use-list order when writing LLVM bitcode."), + cl::init(true), cl::Hidden); + +static cl::opt PreserveAssemblyUseListOrder( + "preserve-ll-uselistorder", + cl::desc("Preserve use-list order when writing LLVM assembly."), + cl::init(false), cl::Hidden); + int main(int argc, char **argv) { // Print a stack trace if we signal out. sys::PrintStackTraceOnErrorSignal(); @@ -98,11 +107,6 @@ int main(int argc, char **argv) { LLVMContext &Context = getGlobalContext(); llvm_shutdown_obj Y; // Call llvm_shutdown() on exit. - - // Turn on -preserve-bc-uselistorder by default, but let the command-line - // override it. - setPreserveBitcodeUseListOrder(true); - cl::ParseCommandLineOptions(argc, argv, "llvm extractor\n"); // Use lazy loading, since we only care about selected global values. @@ -270,11 +274,10 @@ int main(int argc, char **argv) { } if (OutputAssembly) - Passes.add(createPrintModulePass(Out.os(), "", - shouldPreserveAssemblyUseListOrder())); - else if (Force || !CheckBitcodeOutputToConsole(Out.os(), true)) Passes.add( - createBitcodeWriterPass(Out.os(), shouldPreserveBitcodeUseListOrder())); + createPrintModulePass(Out.os(), "", PreserveAssemblyUseListOrder)); + else if (Force || !CheckBitcodeOutputToConsole(Out.os(), true)) + Passes.add(createBitcodeWriterPass(Out.os(), PreserveBitcodeUseListOrder)); Passes.run(*M.get()); diff --git a/tools/llvm-link/llvm-link.cpp b/tools/llvm-link/llvm-link.cpp index 9d5369df66d..bcefc0b507a 100644 --- a/tools/llvm-link/llvm-link.cpp +++ b/tools/llvm-link/llvm-link.cpp @@ -20,7 +20,6 @@ #include "llvm/IR/DiagnosticPrinter.h" #include "llvm/IR/LLVMContext.h" #include "llvm/IR/Module.h" -#include "llvm/IR/UseListOrder.h" #include "llvm/IR/Verifier.h" #include "llvm/IRReader/IRReader.h" #include "llvm/Support/CommandLine.h" @@ -60,6 +59,16 @@ static cl::opt SuppressWarnings("suppress-warnings", cl::desc("Suppress all linking warnings"), cl::init(false)); +static cl::opt PreserveBitcodeUseListOrder( + "preserve-bc-uselistorder", + cl::desc("Preserve use-list order when writing LLVM bitcode."), + cl::init(true), cl::Hidden); + +static cl::opt PreserveAssemblyUseListOrder( + "preserve-ll-uselistorder", + cl::desc("Preserve use-list order when writing LLVM assembly."), + cl::init(false), cl::Hidden); + // Read the specified bitcode file in and return it. This routine searches the // link path for the specified file to try to find it... // @@ -105,11 +114,6 @@ int main(int argc, char **argv) { LLVMContext &Context = getGlobalContext(); llvm_shutdown_obj Y; // Call llvm_shutdown() on exit. - - // Turn on -preserve-bc-uselistorder by default, but let the command-line - // override it. - setPreserveBitcodeUseListOrder(true); - cl::ParseCommandLineOptions(argc, argv, "llvm linker\n"); auto Composite = make_unique("llvm-link", Context); @@ -150,10 +154,9 @@ int main(int argc, char **argv) { if (Verbose) errs() << "Writing bitcode...\n"; if (OutputAssembly) { - Composite->print(Out.os(), nullptr, shouldPreserveAssemblyUseListOrder()); + Composite->print(Out.os(), nullptr, PreserveAssemblyUseListOrder); } else if (Force || !CheckBitcodeOutputToConsole(Out.os(), true)) - WriteBitcodeToFile(Composite.get(), Out.os(), - shouldPreserveBitcodeUseListOrder()); + WriteBitcodeToFile(Composite.get(), Out.os(), PreserveBitcodeUseListOrder); // Declare success. Out.keep(); diff --git a/tools/opt/opt.cpp b/tools/opt/opt.cpp index 28cbe4f1a94..80b1934366a 100644 --- a/tools/opt/opt.cpp +++ b/tools/opt/opt.cpp @@ -30,7 +30,6 @@ #include "llvm/IR/LLVMContext.h" #include "llvm/IR/LegacyPassNameParser.h" #include "llvm/IR/Module.h" -#include "llvm/IR/UseListOrder.h" #include "llvm/IR/Verifier.h" #include "llvm/IRReader/IRReader.h" #include "llvm/InitializePasses.h" @@ -181,7 +180,15 @@ DefaultDataLayout("default-data-layout", cl::desc("data layout string to use if not specified by module"), cl::value_desc("layout-string"), cl::init("")); +static cl::opt PreserveBitcodeUseListOrder( + "preserve-bc-uselistorder", + cl::desc("Preserve use-list order when writing LLVM bitcode."), + cl::init(true), cl::Hidden); +static cl::opt PreserveAssemblyUseListOrder( + "preserve-ll-uselistorder", + cl::desc("Preserve use-list order when writing LLVM assembly."), + cl::init(false), cl::Hidden); static inline void addPass(legacy::PassManagerBase &PM, Pass *P) { // Add the pass to the pass manager... @@ -345,10 +352,6 @@ int main(int argc, char **argv) { polly::initializePollyPasses(Registry); #endif - // Turn on -preserve-bc-uselistorder by default, but let the command-line - // override it. - setPreserveBitcodeUseListOrder(true); - cl::ParseCommandLineOptions(argc, argv, "llvm .bc -> .bc modular optimizer and analysis printer\n"); @@ -431,9 +434,8 @@ int main(int argc, char **argv) { // string. Hand off the rest of the functionality to the new code for that // layer. return runPassPipeline(argv[0], Context, *M, TM.get(), Out.get(), - PassPipeline, OK, VK, - shouldPreserveAssemblyUseListOrder(), - shouldPreserveBitcodeUseListOrder()) + PassPipeline, OK, VK, PreserveAssemblyUseListOrder, + PreserveBitcodeUseListOrder) ? 0 : 1; } @@ -557,8 +559,8 @@ int main(int argc, char **argv) { } if (PrintEachXForm) - Passes.add(createPrintModulePass(errs(), "", - shouldPreserveAssemblyUseListOrder())); + Passes.add( + createPrintModulePass(errs(), "", PreserveAssemblyUseListOrder)); } if (StandardLinkOpts) { @@ -595,11 +597,11 @@ int main(int argc, char **argv) { // Write bitcode or assembly to the output as the last step... if (!NoOutput && !AnalyzeOnly) { if (OutputAssembly) - Passes.add(createPrintModulePass(Out->os(), "", - shouldPreserveAssemblyUseListOrder())); + Passes.add( + createPrintModulePass(Out->os(), "", PreserveAssemblyUseListOrder)); else - Passes.add(createBitcodeWriterPass(Out->os(), - shouldPreserveBitcodeUseListOrder())); + Passes.add( + createBitcodeWriterPass(Out->os(), PreserveBitcodeUseListOrder)); } // Before executing passes, print the final values of the LLVM options. -- 2.34.1