From 31895e73591d3c9ceae731a1274c8f56194b9616 Mon Sep 17 00:00:00 2001 From: Owen Anderson Date: Wed, 1 Jul 2009 21:22:36 +0000 Subject: Hold the LLVMContext by reference rather than by pointer. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@74640 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/bugpoint/BugDriver.cpp | 6 ++++-- tools/bugpoint/BugDriver.h | 9 +++++---- tools/bugpoint/bugpoint.cpp | 2 +- tools/llc/llc.cpp | 2 +- tools/lli/lli.cpp | 2 +- tools/llvm-ar/llvm-ar.cpp | 4 ++-- tools/llvm-as/llvm-as.cpp | 2 +- tools/llvm-db/CLIDebugger.cpp | 2 +- tools/llvm-db/CLIDebugger.h | 4 ++-- tools/llvm-db/llvm-db.cpp | 2 +- tools/llvm-dis/llvm-dis.cpp | 2 +- tools/llvm-extract/llvm-extract.cpp | 2 +- tools/llvm-ld/llvm-ld.cpp | 2 +- tools/llvm-link/llvm-link.cpp | 6 +++--- tools/llvm-nm/llvm-nm.cpp | 4 ++-- tools/llvm-prof/llvm-prof.cpp | 2 +- tools/llvm-ranlib/llvm-ranlib.cpp | 2 +- tools/lto/LTOCodeGenerator.cpp | 4 ++-- tools/lto/LTOCodeGenerator.h | 4 ++-- tools/lto/LTOModule.cpp | 10 ++++++---- tools/lto/LTOModule.h | 6 +++--- tools/lto/lto.cpp | 10 +++++----- tools/opt/opt.cpp | 2 +- 23 files changed, 48 insertions(+), 43 deletions(-) (limited to 'tools') diff --git a/tools/bugpoint/BugDriver.cpp b/tools/bugpoint/BugDriver.cpp index 340522a..93b09fb 100644 --- a/tools/bugpoint/BugDriver.cpp +++ b/tools/bugpoint/BugDriver.cpp @@ -64,7 +64,8 @@ std::string llvm::getPassesString(const std::vector &Passes) { } BugDriver::BugDriver(const char *toolname, bool as_child, bool find_bugs, - unsigned timeout, unsigned memlimit, LLVMContext* ctxt) + unsigned timeout, unsigned memlimit, + const LLVMContext& ctxt) : Context(ctxt), ToolName(toolname), ReferenceOutputFile(OutputFile), Program(0), Interpreter(0), SafeInterpreter(0), gcc(0), run_as_child(as_child), run_find_bugs(find_bugs), Timeout(timeout), @@ -74,7 +75,8 @@ BugDriver::BugDriver(const char *toolname, bool as_child, bool find_bugs, /// ParseInputFile - Given a bitcode or assembly input filename, parse and /// return it, or return null if not possible. /// -Module *llvm::ParseInputFile(const std::string &Filename, LLVMContext* Ctxt) { +Module *llvm::ParseInputFile(const std::string &Filename, + const LLVMContext& Ctxt) { std::auto_ptr Buffer(MemoryBuffer::getFileOrSTDIN(Filename)); Module *Result = 0; if (Buffer.get()) diff --git a/tools/bugpoint/BugDriver.h b/tools/bugpoint/BugDriver.h index 4c81cc2..34267d5 100644 --- a/tools/bugpoint/BugDriver.h +++ b/tools/bugpoint/BugDriver.h @@ -43,7 +43,7 @@ extern bool DisableSimplifyCFG; extern bool BugpointIsInterrupted; class BugDriver { - LLVMContext* Context; + const LLVMContext& Context; const std::string ToolName; // Name of bugpoint std::string ReferenceOutputFile; // Name of `good' output file Module *Program; // The raw program, linked together @@ -62,11 +62,11 @@ class BugDriver { public: BugDriver(const char *toolname, bool as_child, bool find_bugs, - unsigned timeout, unsigned memlimit, LLVMContext* ctxt); + unsigned timeout, unsigned memlimit, const LLVMContext& ctxt); const std::string &getToolName() const { return ToolName; } - LLVMContext* getContext() { return Context; } + const LLVMContext& getContext() { return Context; } // Set up methods... these methods are used to copy information about the // command line arguments into instance variables of BugDriver. @@ -294,7 +294,8 @@ private: /// ParseInputFile - Given a bitcode or assembly input filename, parse and /// return it, or return null if not possible. /// -Module *ParseInputFile(const std::string &InputFilename, LLVMContext* ctxt); +Module *ParseInputFile(const std::string &InputFilename, + const LLVMContext& ctxt); /// getPassesString - Turn a list of passes into a string which indicates the diff --git a/tools/bugpoint/bugpoint.cpp b/tools/bugpoint/bugpoint.cpp index 57007e0..3365b22 100644 --- a/tools/bugpoint/bugpoint.cpp +++ b/tools/bugpoint/bugpoint.cpp @@ -76,7 +76,7 @@ int main(int argc, char **argv) { sys::SetInterruptFunction(BugpointInterruptFunction); LLVMContext Context; - BugDriver D(argv[0], AsChild, FindBugs, TimeoutValue, MemoryLimit, &Context); + BugDriver D(argv[0], AsChild, FindBugs, TimeoutValue, MemoryLimit, Context); if (D.addSources(InputFilenames)) return 1; D.addPasses(PassList.begin(), PassList.end()); diff --git a/tools/llc/llc.cpp b/tools/llc/llc.cpp index d0d88c5..ae03c1e 100644 --- a/tools/llc/llc.cpp +++ b/tools/llc/llc.cpp @@ -227,7 +227,7 @@ int main(int argc, char **argv) { std::auto_ptr Buffer( MemoryBuffer::getFileOrSTDIN(InputFilename, &ErrorMessage)); if (Buffer.get()) - M.reset(ParseBitcodeFile(Buffer.get(), &Context, &ErrorMessage)); + M.reset(ParseBitcodeFile(Buffer.get(), Context, &ErrorMessage)); if (M.get() == 0) { std::cerr << argv[0] << ": bitcode didn't read correctly.\n"; std::cerr << "Reason: " << ErrorMessage << "\n"; diff --git a/tools/lli/lli.cpp b/tools/lli/lli.cpp index 10b8638..e7c449e 100644 --- a/tools/lli/lli.cpp +++ b/tools/lli/lli.cpp @@ -107,7 +107,7 @@ int main(int argc, char **argv, char * const *envp) { std::string ErrorMsg; ModuleProvider *MP = NULL; if (MemoryBuffer *Buffer = MemoryBuffer::getFileOrSTDIN(InputFile,&ErrorMsg)){ - MP = getBitcodeModuleProvider(Buffer, &Context, &ErrorMsg); + MP = getBitcodeModuleProvider(Buffer, Context, &ErrorMsg); if (!MP) delete Buffer; } diff --git a/tools/llvm-ar/llvm-ar.cpp b/tools/llvm-ar/llvm-ar.cpp index 960f8e3..fe58db1 100644 --- a/tools/llvm-ar/llvm-ar.cpp +++ b/tools/llvm-ar/llvm-ar.cpp @@ -719,11 +719,11 @@ int main(int argc, char **argv) { // Produce a warning if we should and we're creating the archive if (!Create) std::cerr << argv[0] << ": creating " << ArchivePath.toString() << "\n"; - TheArchive = Archive::CreateEmpty(ArchivePath, &Context); + TheArchive = Archive::CreateEmpty(ArchivePath, Context); TheArchive->writeToDisk(); } else { std::string Error; - TheArchive = Archive::OpenAndLoad(ArchivePath, &Context, &Error); + TheArchive = Archive::OpenAndLoad(ArchivePath, Context, &Error); if (TheArchive == 0) { std::cerr << argv[0] << ": error loading '" << ArchivePath << "': " << Error << "!\n"; diff --git a/tools/llvm-as/llvm-as.cpp b/tools/llvm-as/llvm-as.cpp index 06798cb..53731b6 100644 --- a/tools/llvm-as/llvm-as.cpp +++ b/tools/llvm-as/llvm-as.cpp @@ -65,7 +65,7 @@ int main(int argc, char **argv) { try { // Parse the file now... ParseError Err; - std::auto_ptr M(ParseAssemblyFile(InputFilename, Err, &Context)); + std::auto_ptr M(ParseAssemblyFile(InputFilename, Err, Context)); if (M.get() == 0) { Err.PrintError(argv[0], errs()); return 1; diff --git a/tools/llvm-db/CLIDebugger.cpp b/tools/llvm-db/CLIDebugger.cpp index c7aedd1..3caa2e6 100644 --- a/tools/llvm-db/CLIDebugger.cpp +++ b/tools/llvm-db/CLIDebugger.cpp @@ -22,7 +22,7 @@ using namespace llvm; /// CLIDebugger constructor - This initializes the debugger to its default /// state, and initializes the command table. /// -CLIDebugger::CLIDebugger(LLVMContext* ctxt) +CLIDebugger::CLIDebugger(const LLVMContext& ctxt) : Context(ctxt), TheProgramInfo(0), TheRuntimeInfo(0), Prompt("(llvm-db) "), ListSize(10) { // Initialize instance variables diff --git a/tools/llvm-db/CLIDebugger.h b/tools/llvm-db/CLIDebugger.h index b1a31a4..a5c73bd 100644 --- a/tools/llvm-db/CLIDebugger.h +++ b/tools/llvm-db/CLIDebugger.h @@ -29,7 +29,7 @@ namespace llvm { /// CLIDebugger - This class implements the command line interface for the /// LLVM debugger. class CLIDebugger { - LLVMContext* Context; + const LLVMContext& Context; /// Dbg - The low-level LLVM debugger object that we use to do our dirty /// work. @@ -82,7 +82,7 @@ namespace llvm { const SourceLanguage *CurrentLanguage; public: - CLIDebugger(LLVMContext* ctxt); + CLIDebugger(const LLVMContext& ctxt); /// getDebugger - Return the current LLVM debugger implementation being /// used. diff --git a/tools/llvm-db/llvm-db.cpp b/tools/llvm-db/llvm-db.cpp index 62ee325..78dbf71 100644 --- a/tools/llvm-db/llvm-db.cpp +++ b/tools/llvm-db/llvm-db.cpp @@ -70,7 +70,7 @@ int main(int argc, char **argv, char * const *envp) { InputArgs.push_back(InputFile); // Create the CLI debugger... - CLIDebugger D(&Context); + CLIDebugger D(Context); // Initialize the debugger with the command line options we read... Debugger &Dbg = D.getDebugger(); diff --git a/tools/llvm-dis/llvm-dis.cpp b/tools/llvm-dis/llvm-dis.cpp index 3460f7e..901c8e9 100644 --- a/tools/llvm-dis/llvm-dis.cpp +++ b/tools/llvm-dis/llvm-dis.cpp @@ -63,7 +63,7 @@ int main(int argc, char **argv) { if (MemoryBuffer *Buffer = MemoryBuffer::getFileOrSTDIN(InputFilename, &ErrorMessage)) { - M.reset(ParseBitcodeFile(Buffer, &Context, &ErrorMessage)); + M.reset(ParseBitcodeFile(Buffer, Context, &ErrorMessage)); delete Buffer; } diff --git a/tools/llvm-extract/llvm-extract.cpp b/tools/llvm-extract/llvm-extract.cpp index a977211..af0cf07 100644 --- a/tools/llvm-extract/llvm-extract.cpp +++ b/tools/llvm-extract/llvm-extract.cpp @@ -73,7 +73,7 @@ int main(int argc, char **argv) { cerr << argv[0] << ": Error reading file '" + InputFilename + "'\n"; return 1; } else { - M.reset(ParseBitcodeFile(Buffer, &Context)); + M.reset(ParseBitcodeFile(Buffer, Context)); } delete Buffer; diff --git a/tools/llvm-ld/llvm-ld.cpp b/tools/llvm-ld/llvm-ld.cpp index 435de0f..2b9d255 100644 --- a/tools/llvm-ld/llvm-ld.cpp +++ b/tools/llvm-ld/llvm-ld.cpp @@ -517,7 +517,7 @@ int main(int argc, char **argv, char **envp) { cl::ParseCommandLineOptions(argc, argv, "llvm linker\n"); // Construct a Linker (now that Verbose is set) - Linker TheLinker(progname, OutputFilename, &Context, Verbose); + Linker TheLinker(progname, OutputFilename, Context, Verbose); // Keep track of the native link items (versus the bitcode items) Linker::ItemList NativeLinkItems; diff --git a/tools/llvm-link/llvm-link.cpp b/tools/llvm-link/llvm-link.cpp index ae5fa40..818df14 100644 --- a/tools/llvm-link/llvm-link.cpp +++ b/tools/llvm-link/llvm-link.cpp @@ -49,7 +49,7 @@ DumpAsm("d", cl::desc("Print assembly as linked"), cl::Hidden); // searches the link path for the specified file to try to find it... // static inline std::auto_ptr LoadFile(const std::string &FN, - LLVMContext* Context) { + const LLVMContext& Context) { sys::Path Filename; if (!Filename.set(FN)) { cerr << "Invalid file name: '" << FN << "'\n"; @@ -93,7 +93,7 @@ int main(int argc, char **argv) { unsigned BaseArg = 0; std::string ErrorMessage; - std::auto_ptr Composite(LoadFile(InputFilenames[BaseArg], &Context)); + std::auto_ptr Composite(LoadFile(InputFilenames[BaseArg], Context)); if (Composite.get() == 0) { cerr << argv[0] << ": error loading file '" << InputFilenames[BaseArg] << "'\n"; @@ -101,7 +101,7 @@ int main(int argc, char **argv) { } for (unsigned i = BaseArg+1; i < InputFilenames.size(); ++i) { - std::auto_ptr M(LoadFile(InputFilenames[i], &Context)); + std::auto_ptr M(LoadFile(InputFilenames[i], Context)); if (M.get() == 0) { cerr << argv[0] << ": error loading file '" < - AutoArchive(Archive::OpenAndLoad(ArchivePath, &Context, &err_msg)); + AutoArchive(Archive::OpenAndLoad(ArchivePath, Context, &err_msg)); Archive* TheArchive = AutoArchive.get(); if (!TheArchive) throw err_msg; diff --git a/tools/lto/LTOCodeGenerator.cpp b/tools/lto/LTOCodeGenerator.cpp index 8ae196f..faac33b 100644 --- a/tools/lto/LTOCodeGenerator.cpp +++ b/tools/lto/LTOCodeGenerator.cpp @@ -69,8 +69,8 @@ const char* LTOCodeGenerator::getVersionString() } -LTOCodeGenerator::LTOCodeGenerator() - : _context(new LLVMContext()), +LTOCodeGenerator::LTOCodeGenerator(const LLVMContext& Context) + : _context(Context), _linker("LinkTimeOptimizer", "ld-temp.o", _context), _target(NULL), _emitDwarfDebugInfo(false), _scopeRestrictionsDone(false), _codeModel(LTO_CODEGEN_PIC_MODEL_DYNAMIC), diff --git a/tools/lto/LTOCodeGenerator.h b/tools/lto/LTOCodeGenerator.h index d412626..4603c35 100644 --- a/tools/lto/LTOCodeGenerator.h +++ b/tools/lto/LTOCodeGenerator.h @@ -31,7 +31,7 @@ class LTOCodeGenerator { public: static const char* getVersionString(); - LTOCodeGenerator(); + LTOCodeGenerator(const llvm::LLVMContext& Context); ~LTOCodeGenerator(); bool addModule(class LTOModule*, std::string& errMsg); @@ -54,7 +54,7 @@ private: typedef llvm::StringMap StringSet; - llvm::LLVMContext* _context; + const llvm::LLVMContext& _context; llvm::Linker _linker; llvm::TargetMachine* _target; bool _emitDwarfDebugInfo; diff --git a/tools/lto/LTOModule.cpp b/tools/lto/LTOModule.cpp index 64e7950..3da095d 100644 --- a/tools/lto/LTOModule.cpp +++ b/tools/lto/LTOModule.cpp @@ -69,7 +69,7 @@ bool LTOModule::isBitcodeFileForTarget(const char* path, bool LTOModule::isTargetMatch(MemoryBuffer* buffer, const char* triplePrefix) { OwningPtr mp(getBitcodeModuleProvider(buffer, - new LLVMContext())); + *new LLVMContext())); // on success, mp owns buffer and both are deleted at end of this method if ( !mp ) { delete buffer; @@ -86,7 +86,8 @@ LTOModule::LTOModule(Module* m, TargetMachine* t) { } -LTOModule* LTOModule::makeLTOModule(const char* path, LLVMContext* Context, +LTOModule* LTOModule::makeLTOModule(const char* path, + const LLVMContext& Context, std::string& errMsg) { OwningPtr buffer(MemoryBuffer::getFile(path, &errMsg)); @@ -112,7 +113,7 @@ MemoryBuffer* LTOModule::makeBuffer(const void* mem, size_t length) LTOModule* LTOModule::makeLTOModule(const void* mem, size_t length, - LLVMContext* Context, + const LLVMContext& Context, std::string& errMsg) { OwningPtr buffer(makeBuffer(mem, length)); @@ -140,7 +141,8 @@ std::string getFeatureString(const char *TargetTriple) { return Features.getString(); } -LTOModule* LTOModule::makeLTOModule(MemoryBuffer* buffer, LLVMContext* Context, +LTOModule* LTOModule::makeLTOModule(MemoryBuffer* buffer, + const LLVMContext& Context, std::string& errMsg) { // parse bitcode buffer diff --git a/tools/lto/LTOModule.h b/tools/lto/LTOModule.h index bfdf6e7..d7b992f 100644 --- a/tools/lto/LTOModule.h +++ b/tools/lto/LTOModule.h @@ -52,10 +52,10 @@ public: const char* triplePrefix); static LTOModule* makeLTOModule(const char* path, - llvm::LLVMContext* Context, + const llvm::LLVMContext& Context, std::string& errMsg); static LTOModule* makeLTOModule(const void* mem, size_t length, - llvm::LLVMContext* Context, + const llvm::LLVMContext& Context, std::string& errMsg); const char* getTargetTriple(); @@ -91,7 +91,7 @@ private: const char* triplePrefix); static LTOModule* makeLTOModule(llvm::MemoryBuffer* buffer, - llvm::LLVMContext* Context, + const llvm::LLVMContext& Context, std::string& errMsg); static llvm::MemoryBuffer* makeBuffer(const void* mem, size_t length); diff --git a/tools/lto/lto.cpp b/tools/lto/lto.cpp index c25f87c..02034bb 100644 --- a/tools/lto/lto.cpp +++ b/tools/lto/lto.cpp @@ -88,7 +88,7 @@ bool lto_module_is_object_file_in_memory_for_target(const void* mem, // lto_module_t lto_module_create(const char* path, LLVMContextRef Ctxt) { - return LTOModule::makeLTOModule(path, llvm::unwrap(Ctxt), + return LTOModule::makeLTOModule(path, *llvm::unwrap(Ctxt), sLastErrorString); } @@ -100,7 +100,7 @@ lto_module_t lto_module_create(const char* path, LLVMContextRef Ctxt) lto_module_t lto_module_create_from_memory(const void* mem, size_t length, LLVMContextRef Ctxt) { - return LTOModule::makeLTOModule(mem, length, llvm::unwrap(Ctxt), + return LTOModule::makeLTOModule(mem, length, *llvm::unwrap(Ctxt), sLastErrorString); } @@ -158,9 +158,9 @@ lto_symbol_attributes lto_module_get_symbol_attribute(lto_module_t mod, // instantiates a code generator // returns NULL if there is an error // -lto_code_gen_t lto_codegen_create() +lto_code_gen_t lto_codegen_create(LLVMContextRef ContextRef) { - return new LTOCodeGenerator(); + return new LTOCodeGenerator(*llvm::unwrap(ContextRef)); } @@ -265,4 +265,4 @@ extern void lto_codegen_debug_options(lto_code_gen_t cg, const char * opt) { cg->setCodeGenDebugOptions(opt); -} +} \ No newline at end of file diff --git a/tools/opt/opt.cpp b/tools/opt/opt.cpp index b469606..6891619 100644 --- a/tools/opt/opt.cpp +++ b/tools/opt/opt.cpp @@ -327,7 +327,7 @@ int main(int argc, char **argv) { std::auto_ptr M; if (MemoryBuffer *Buffer = MemoryBuffer::getFileOrSTDIN(InputFilename, &ErrorMessage)) { - M.reset(ParseBitcodeFile(Buffer, &Context, &ErrorMessage)); + M.reset(ParseBitcodeFile(Buffer, Context, &ErrorMessage)); delete Buffer; } -- cgit v1.1