From f5599efb002906859e3f1dfbc76f458a43398e75 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sun, 6 May 2007 09:32:02 +0000 Subject: [PATCH] switch tools to bitcode from bytecode llvm-svn: 36872 --- llvm/tools/bugpoint/BugDriver.cpp | 17 ++++------- llvm/tools/bugpoint/Makefile | 2 +- llvm/tools/bugpoint/OptimizerDriver.cpp | 20 +++---------- llvm/tools/llc/Makefile | 2 +- llvm/tools/llc/llc.cpp | 24 +++++---------- llvm/tools/lli/Makefile | 2 +- llvm/tools/lli/lli.cpp | 24 +++++---------- llvm/tools/lto/Makefile | 2 +- llvm/tools/lto/lto.cpp | 25 +++------------- llvm/tools/opt/Makefile | 2 +- llvm/tools/opt/opt.cpp | 40 +++++++------------------ 11 files changed, 45 insertions(+), 115 deletions(-) diff --git a/llvm/tools/bugpoint/BugDriver.cpp b/llvm/tools/bugpoint/BugDriver.cpp index fe290805e4b1..00dfc32774a5 100644 --- a/llvm/tools/bugpoint/BugDriver.cpp +++ b/llvm/tools/bugpoint/BugDriver.cpp @@ -20,9 +20,7 @@ #include "llvm/Pass.h" #include "llvm/Assembly/Parser.h" #include "llvm/Bitcode/ReaderWriter.h" -#include "llvm/Bytecode/Reader.h" #include "llvm/Support/CommandLine.h" -#include "llvm/Support/Compressor.h" #include "llvm/Support/FileUtilities.h" #include "llvm/Support/MemoryBuffer.h" #include @@ -75,16 +73,13 @@ BugDriver::BugDriver(const char *toolname, bool as_child, bool find_bugs, /// return it, or return null if not possible. /// Module *llvm::ParseInputFile(const std::string &InputFilename) { - ParseError Err; - Module *Result = ParseBytecodeFile(InputFilename, - Compressor::decompressToNewBuffer); - if (!Result) { - std::auto_ptr Buffer( - MemoryBuffer::getFileOrSTDIN(&InputFilename[0], InputFilename.size())); - if (Buffer.get()) - Result = ParseBitcodeFile(Buffer.get()); - } + std::auto_ptr Buffer( + MemoryBuffer::getFileOrSTDIN(&InputFilename[0], InputFilename.size())); + Module *Result = 0; + if (Buffer.get()) + Result = ParseBitcodeFile(Buffer.get()); + ParseError Err; if (!Result && !(Result = ParseAssemblyFile(InputFilename,&Err))) { std::cerr << "bugpoint: " << Err.getMessage() << "\n"; Result = 0; diff --git a/llvm/tools/bugpoint/Makefile b/llvm/tools/bugpoint/Makefile index 11741480dd5a..6d8d7a0f7ebc 100644 --- a/llvm/tools/bugpoint/Makefile +++ b/llvm/tools/bugpoint/Makefile @@ -10,7 +10,7 @@ LEVEL = ../.. TOOLNAME = bugpoint -LINK_COMPONENTS := bcreader bcwriter asmparser instrumentation scalaropts ipo \ +LINK_COMPONENTS := asmparser instrumentation scalaropts ipo \ linker bitreader bitwriter REQUIRES_EH := 1 diff --git a/llvm/tools/bugpoint/OptimizerDriver.cpp b/llvm/tools/bugpoint/OptimizerDriver.cpp index e5435ed1bc0c..5f031dc14ce4 100644 --- a/llvm/tools/bugpoint/OptimizerDriver.cpp +++ b/llvm/tools/bugpoint/OptimizerDriver.cpp @@ -23,7 +23,6 @@ #include "llvm/Module.h" #include "llvm/PassManager.h" #include "llvm/Analysis/Verifier.h" -#include "llvm/Bytecode/WriteBytecodePass.h" #include "llvm/Bitcode/ReaderWriter.h" #include "llvm/Target/TargetData.h" #include "llvm/Support/FileUtilities.h" @@ -39,8 +38,6 @@ #include using namespace llvm; -static bool Bitcode = false; - namespace { // ChildOutput - This option captures the name of the child output file that @@ -59,12 +56,8 @@ bool BugDriver::writeProgramToFile(const std::string &Filename, std::ios::binary; std::ofstream Out(Filename.c_str(), io_mode); if (!Out.good()) return true; - try { - OStream L(Out); - WriteBytecodeToFile(M ? M : Program, L, /*compression=*/false); - } catch (...) { - return true; - } + + WriteBitcodeToFile(M, Out); return false; } @@ -113,11 +106,7 @@ int BugDriver::runPassesAsChild(const std::vector &Passes) { PM.add(createVerifierPass()); // Write bytecode out to disk as the last step... - OStream L(OutFile); - if (Bitcode) - PM.add(CreateBitcodeWriterPass(OutFile)); - else - PM.add(new WriteBytecodePass(&L)); + PM.add(CreateBitcodeWriterPass(OutFile)); // Run all queued passes. PM.run(*Program); @@ -161,8 +150,7 @@ bool BugDriver::runPasses(const std::vector &Passes, cerr << "Error opening bytecode file: " << inputFilename << "\n"; return(1); } - OStream L(InFile); - WriteBytecodeToFile(Program,L,false); + WriteBitcodeToFile(Program, InFile); InFile.close(); // setup the child process' arguments diff --git a/llvm/tools/llc/Makefile b/llvm/tools/llc/Makefile index fa7a1b482fcb..aa767ae7a967 100644 --- a/llvm/tools/llc/Makefile +++ b/llvm/tools/llc/Makefile @@ -15,7 +15,7 @@ TOOLNAME = llc # early so we can set up LINK_COMPONENTS before including Makefile.rules include $(LEVEL)/Makefile.config -LINK_COMPONENTS := $(TARGETS_TO_BUILD) bcreader bitreader +LINK_COMPONENTS := $(TARGETS_TO_BUILD) bitreader include $(LLVM_SRC_ROOT)/Makefile.rules diff --git a/llvm/tools/llc/llc.cpp b/llvm/tools/llc/llc.cpp index d96d164e54f1..052242054c40 100644 --- a/llvm/tools/llc/llc.cpp +++ b/llvm/tools/llc/llc.cpp @@ -14,7 +14,6 @@ //===----------------------------------------------------------------------===// #include "llvm/Bitcode/ReaderWriter.h" -#include "llvm/Bytecode/Reader.h" #include "llvm/CodeGen/FileWriters.h" #include "llvm/CodeGen/LinkAllCodegenComponents.h" #include "llvm/Target/SubtargetFeature.h" @@ -23,10 +22,10 @@ #include "llvm/Target/TargetMachineRegistry.h" #include "llvm/Transforms/Scalar.h" #include "llvm/Module.h" +#include "llvm/ModuleProvider.h" #include "llvm/PassManager.h" #include "llvm/Pass.h" #include "llvm/Support/CommandLine.h" -#include "llvm/Support/Compressor.h" #include "llvm/Support/ManagedStatic.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/PluginLoader.h" @@ -40,9 +39,6 @@ #include using namespace llvm; -cl::opt Bitcode("bitcode"); - - // General options for llc. Other pass-specific options are specified // within the corresponding llc passes, and target-specific options // and back-end code generation options are specified with the target machine. @@ -183,17 +179,13 @@ int main(int argc, char **argv) { std::string ErrorMessage; std::auto_ptr M; - if (Bitcode) { - std::auto_ptr Buffer( - MemoryBuffer::getFileOrSTDIN(&InputFilename[0], InputFilename.size())); - if (Buffer.get()) - M.reset(ParseBitcodeFile(Buffer.get(), &ErrorMessage)); - else - ErrorMessage = "Error reading file '" + InputFilename + "'"; - } else { - M.reset(ParseBytecodeFile(InputFilename, - Compressor::decompressToNewBuffer, - &ErrorMessage)); + { + std::auto_ptr Buffer( + MemoryBuffer::getFileOrSTDIN(&InputFilename[0], InputFilename.size())); + if (Buffer.get()) + M.reset(ParseBitcodeFile(Buffer.get(), &ErrorMessage)); + else + ErrorMessage = "Error reading file '" + InputFilename + "'"; } if (M.get() == 0) { std::cerr << argv[0] << ": bytecode didn't read correctly.\n"; diff --git a/llvm/tools/lli/Makefile b/llvm/tools/lli/Makefile index f5383d3b519d..d443b159b624 100644 --- a/llvm/tools/lli/Makefile +++ b/llvm/tools/lli/Makefile @@ -9,7 +9,7 @@ LEVEL := ../.. TOOLNAME := lli -LINK_COMPONENTS := jit interpreter native bcreader bitreader selectiondag +LINK_COMPONENTS := jit interpreter native bitreader selectiondag # Enable JIT support include $(LEVEL)/Makefile.common diff --git a/llvm/tools/lli/lli.cpp b/llvm/tools/lli/lli.cpp index e3809538a573..a1caf1172dbd 100644 --- a/llvm/tools/lli/lli.cpp +++ b/llvm/tools/lli/lli.cpp @@ -17,13 +17,11 @@ #include "llvm/ModuleProvider.h" #include "llvm/Type.h" #include "llvm/Bitcode/ReaderWriter.h" -#include "llvm/Bytecode/Reader.h" #include "llvm/CodeGen/LinkAllCodegenComponents.h" #include "llvm/ExecutionEngine/JIT.h" #include "llvm/ExecutionEngine/Interpreter.h" #include "llvm/ExecutionEngine/GenericValue.h" #include "llvm/Support/CommandLine.h" -#include "llvm/Support/Compressor.h" #include "llvm/Support/ManagedStatic.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/PluginLoader.h" @@ -34,8 +32,6 @@ using namespace llvm; namespace { - cl::opt Bitcode("bitcode"); - cl::opt InputFile(cl::desc(""), cl::Positional, cl::init("-")); @@ -81,19 +77,13 @@ int main(int argc, char **argv, char * const *envp) { // Load the bytecode... std::string ErrorMsg; ModuleProvider *MP = 0; - if (Bitcode) { - MemoryBuffer *Buffer = MemoryBuffer::getFileOrSTDIN(&InputFile[0], - InputFile.size()); - if (Buffer == 0) - ErrorMsg = "Error reading file '" + InputFile + "'"; - else { - MP = getBitcodeModuleProvider(Buffer, &ErrorMsg); - if (!MP) delete Buffer; - } - } else { - MP = getBytecodeModuleProvider(InputFile, - Compressor::decompressToNewBuffer, - &ErrorMsg); + MemoryBuffer *Buffer = MemoryBuffer::getFileOrSTDIN(&InputFile[0], + InputFile.size()); + if (Buffer == 0) + ErrorMsg = "Error reading file '" + InputFile + "'"; + else { + MP = getBitcodeModuleProvider(Buffer, &ErrorMsg); + if (!MP) delete Buffer; } if (!MP) { diff --git a/llvm/tools/lto/Makefile b/llvm/tools/lto/Makefile index 6cb1a7b5aaa1..1b349f72b4d1 100644 --- a/llvm/tools/lto/Makefile +++ b/llvm/tools/lto/Makefile @@ -24,7 +24,7 @@ else BUILD_ARCHIVE = 1 endif -LINK_COMPONENTS := $(TARGETS_TO_BUILD) ipo scalaropts linker bcreader bcwriter bitreader bitwriter +LINK_COMPONENTS := $(TARGETS_TO_BUILD) ipo scalaropts linker bitreader bitwriter include $(LEVEL)/Makefile.common diff --git a/llvm/tools/lto/lto.cpp b/llvm/tools/lto/lto.cpp index f7ea310578dd..3420cdf67b74 100644 --- a/llvm/tools/lto/lto.cpp +++ b/llvm/tools/lto/lto.cpp @@ -17,9 +17,8 @@ #include "llvm/Linker.h" #include "llvm/Constants.h" #include "llvm/DerivedTypes.h" +#include "llvm/ModuleProvider.h" #include "llvm/Bitcode/ReaderWriter.h" -#include "llvm/Bytecode/Reader.h" -#include "llvm/Bytecode/Writer.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/FileUtilities.h" #include "llvm/Support/SystemUtils.h" @@ -40,7 +39,6 @@ #include "llvm/Transforms/Scalar.h" #include "llvm/Analysis/LoadValueNumbering.h" #include "llvm/Support/MathExtras.h" -#include "llvm/Support/Streams.h" #include "llvm/LinkTimeOptimizer.h" #include #include @@ -53,8 +51,6 @@ llvm::LinkTimeOptimizer *createLLVMOptimizer() return l; } -static bool Bitcode = false; - /// If symbol is not used then make it internal and let optimizer takes /// care of it. void LLVMSymbol::mayBeNotUsed() { @@ -121,16 +117,13 @@ LTO::getModule(const std::string &InputFilename) NameToModuleMap::iterator pos = allModules.find(InputFilename.c_str()); if (pos != allModules.end()) m = allModules[InputFilename.c_str()]; - else if (Bitcode) { + else { if (MemoryBuffer *Buffer = MemoryBuffer::getFile(&InputFilename[0], InputFilename.size())) { m = ParseBitcodeFile(Buffer); delete Buffer; } allModules[InputFilename.c_str()] = m; - } else { - m = ParseBytecodeFile(InputFilename); - allModules[InputFilename.c_str()] = m; } return m; } @@ -385,12 +378,7 @@ LTO::optimizeModules(const std::string &OutputFilename, std::string tempFileName(FinalOutputPath.c_str()); tempFileName += "0.bc"; std::ofstream Out(tempFileName.c_str(), io_mode); - if (Bitcode) { - WriteBitcodeToFile(bigOne, Out); - } else { - OStream L(Out); - WriteBytecodeToFile(bigOne, L); - } + WriteBitcodeToFile(bigOne, Out); } // Strip leading underscore because it was added to match names @@ -443,12 +431,7 @@ LTO::optimizeModules(const std::string &OutputFilename, std::string tempFileName(FinalOutputPath.c_str()); tempFileName += "1.bc"; std::ofstream Out(tempFileName.c_str(), io_mode); - if (Bitcode) { - WriteBitcodeToFile(bigOne, Out); - } else { - OStream L(Out); - WriteBytecodeToFile(bigOne, L); - } + WriteBitcodeToFile(bigOne, Out); } targetTriple = bigOne->getTargetTriple(); diff --git a/llvm/tools/opt/Makefile b/llvm/tools/opt/Makefile index 76cb5b127214..f444fe338bb5 100644 --- a/llvm/tools/opt/Makefile +++ b/llvm/tools/opt/Makefile @@ -10,6 +10,6 @@ LEVEL = ../.. TOOLNAME = opt REQUIRES_EH := 1 -LINK_COMPONENTS := bcreader bcwriter bitreader bitwriter instrumentation scalaropts ipo +LINK_COMPONENTS := bitreader bitwriter instrumentation scalaropts ipo include $(LEVEL)/Makefile.common diff --git a/llvm/tools/opt/opt.cpp b/llvm/tools/opt/opt.cpp index 218e5f0b1dec..99249b9442cf 100644 --- a/llvm/tools/opt/opt.cpp +++ b/llvm/tools/opt/opt.cpp @@ -14,8 +14,6 @@ #include "llvm/Module.h" #include "llvm/PassManager.h" -#include "llvm/Bytecode/Reader.h" -#include "llvm/Bytecode/WriteBytecodePass.h" #include "llvm/Bitcode/ReaderWriter.h" #include "llvm/Assembly/PrintModulePass.h" #include "llvm/Analysis/Verifier.h" @@ -37,17 +35,12 @@ #include using namespace llvm; -static cl::opt Bitcode("bitcode"); - // The OptimizationList is automatically populated with registered Passes by the // PassNameParser. // static cl::list PassList(cl::desc("Optimizations available:")); -static cl::opt NoCompress("disable-compression", cl::init(true), - cl::desc("Don't compress the generated bytecode")); - // Other command line options... // static cl::opt @@ -267,21 +260,15 @@ int main(int argc, char **argv) { // Load the input module... std::auto_ptr M; - if (Bitcode) { - MemoryBuffer *Buffer - = MemoryBuffer::getFileOrSTDIN(&InputFilename[0], InputFilename.size()); - - if (Buffer == 0) - ErrorMessage = "Error reading file '" + InputFilename + "'"; - else - M.reset(ParseBitcodeFile(Buffer, &ErrorMessage)); - - delete Buffer; - } else { - M.reset(ParseBytecodeFile(InputFilename, - Compressor::decompressToNewBuffer, - &ErrorMessage)); - } + MemoryBuffer *Buffer + = MemoryBuffer::getFileOrSTDIN(&InputFilename[0], InputFilename.size()); + + if (Buffer == 0) + ErrorMessage = "Error reading file '" + InputFilename + "'"; + else + M.reset(ParseBitcodeFile(Buffer, &ErrorMessage)); + + delete Buffer; if (M.get() == 0) { cerr << argv[0] << ": "; if (ErrorMessage.size()) @@ -372,13 +359,8 @@ int main(int argc, char **argv) { Passes.add(createVerifierPass()); // Write bytecode out to disk or cout as the last step... - OStream L(*Out); - if (!NoOutput && !AnalyzeOnly) { - if (Bitcode) - Passes.add(CreateBitcodeWriterPass(*Out)); - else - Passes.add(new WriteBytecodePass(&L, false, !NoCompress)); - } + if (!NoOutput && !AnalyzeOnly) + Passes.add(CreateBitcodeWriterPass(*Out)); // Now that we have all of the passes ready, run them. Passes.run(*M.get());