[llvm-commits] [llvm] r74614 - in /llvm/trunk: examples/BrainF/ examples/Fibonacci/ examples/HowToUseJIT/ examples/Kaleidoscope/ examples/ModuleMaker/ examples/ParallelJIT/ include/llvm-c/ include/llvm/ include/llvm/Assembly/ include/llvm/Bitcode/ include/llvm/Debugger/ include/llvm/Transforms/Utils/ lib/Archive/ lib/AsmParser/ lib/Bitcode/Reader/ lib/Debugger/ lib/Linker/ lib/Transforms/Utils/ lib/VMCore/ tools/bugpoint/ tools/llc/ tools/lli/ tools/llvm-ar/ tools/llvm-as/ tools/llvm-db/ tools/llvm-dis/ tools/llvm-extr...

Owen Anderson resistor at mac.com
Wed Jul 1 09:58:41 PDT 2009


Author: resistor
Date: Wed Jul  1 11:58:40 2009
New Revision: 74614

URL: http://llvm.org/viewvc/llvm-project?rev=74614&view=rev
Log:
Add a pointer to the owning LLVMContext to Module.  This requires threading LLVMContext through a lot
of the bitcode reader and ASM parser APIs, as well as supporting it in all of the tools.

Patches for Clang and LLVM-GCC to follow.

Modified:
    llvm/trunk/examples/BrainF/BrainF.cpp
    llvm/trunk/examples/BrainF/BrainF.h
    llvm/trunk/examples/BrainF/BrainFDriver.cpp
    llvm/trunk/examples/Fibonacci/fibonacci.cpp
    llvm/trunk/examples/HowToUseJIT/HowToUseJIT.cpp
    llvm/trunk/examples/Kaleidoscope/toy.cpp
    llvm/trunk/examples/ModuleMaker/ModuleMaker.cpp
    llvm/trunk/examples/ParallelJIT/ParallelJIT.cpp
    llvm/trunk/include/llvm-c/BitReader.h
    llvm/trunk/include/llvm-c/Core.h
    llvm/trunk/include/llvm/Assembly/Parser.h
    llvm/trunk/include/llvm/Bitcode/Archive.h
    llvm/trunk/include/llvm/Bitcode/ReaderWriter.h
    llvm/trunk/include/llvm/Debugger/Debugger.h
    llvm/trunk/include/llvm/LinkAllVMCore.h
    llvm/trunk/include/llvm/Linker.h
    llvm/trunk/include/llvm/Module.h
    llvm/trunk/include/llvm/Transforms/Utils/Cloning.h
    llvm/trunk/lib/Archive/Archive.cpp
    llvm/trunk/lib/Archive/ArchiveInternals.h
    llvm/trunk/lib/Archive/ArchiveReader.cpp
    llvm/trunk/lib/Archive/ArchiveWriter.cpp
    llvm/trunk/lib/AsmParser/Parser.cpp
    llvm/trunk/lib/Bitcode/Reader/BitReader.cpp
    llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp
    llvm/trunk/lib/Bitcode/Reader/BitcodeReader.h
    llvm/trunk/lib/Debugger/Debugger.cpp
    llvm/trunk/lib/Linker/LinkArchives.cpp
    llvm/trunk/lib/Linker/LinkItems.cpp
    llvm/trunk/lib/Linker/Linker.cpp
    llvm/trunk/lib/Transforms/Utils/CloneModule.cpp
    llvm/trunk/lib/VMCore/Core.cpp
    llvm/trunk/lib/VMCore/Module.cpp
    llvm/trunk/tools/bugpoint/BugDriver.cpp
    llvm/trunk/tools/bugpoint/BugDriver.h
    llvm/trunk/tools/bugpoint/CrashDebugger.cpp
    llvm/trunk/tools/bugpoint/Miscompilation.cpp
    llvm/trunk/tools/bugpoint/OptimizerDriver.cpp
    llvm/trunk/tools/bugpoint/bugpoint.cpp
    llvm/trunk/tools/llc/llc.cpp
    llvm/trunk/tools/lli/lli.cpp
    llvm/trunk/tools/llvm-ar/llvm-ar.cpp
    llvm/trunk/tools/llvm-as/llvm-as.cpp
    llvm/trunk/tools/llvm-db/CLIDebugger.cpp
    llvm/trunk/tools/llvm-db/CLIDebugger.h
    llvm/trunk/tools/llvm-db/Commands.cpp
    llvm/trunk/tools/llvm-db/llvm-db.cpp
    llvm/trunk/tools/llvm-dis/llvm-dis.cpp
    llvm/trunk/tools/llvm-extract/llvm-extract.cpp
    llvm/trunk/tools/llvm-ld/llvm-ld.cpp
    llvm/trunk/tools/llvm-link/llvm-link.cpp
    llvm/trunk/tools/llvm-nm/llvm-nm.cpp
    llvm/trunk/tools/llvm-prof/llvm-prof.cpp
    llvm/trunk/tools/llvm-ranlib/llvm-ranlib.cpp
    llvm/trunk/tools/lto/LTOCodeGenerator.cpp
    llvm/trunk/tools/lto/LTOCodeGenerator.h
    llvm/trunk/tools/lto/LTOModule.cpp
    llvm/trunk/tools/lto/LTOModule.h
    llvm/trunk/tools/lto/lto.cpp
    llvm/trunk/tools/opt/opt.cpp

Modified: llvm/trunk/examples/BrainF/BrainF.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/examples/BrainF/BrainF.cpp?rev=74614&r1=74613&r2=74614&view=diff

==============================================================================
--- llvm/trunk/examples/BrainF/BrainF.cpp (original)
+++ llvm/trunk/examples/BrainF/BrainF.cpp Wed Jul  1 11:58:40 2009
@@ -36,19 +36,20 @@
 const char *BrainF::label   = "brainf";
 const char *BrainF::testreg = "test";
 
-Module *BrainF::parse(std::istream *in1, int mem, CompileFlags cf) {
+Module *BrainF::parse(std::istream *in1, int mem, CompileFlags cf,
+                      LLVMContext* Context) {
   in       = in1;
   memtotal = mem;
   comflag  = cf;
 
-  header();
+  header(Context);
   readloop(0, 0, 0);
   delete builder;
   return module;
 }
 
-void BrainF::header() {
-  module = new Module("BrainF");
+void BrainF::header(LLVMContext* C) {
+  module = new Module("BrainF", C);
 
   //Function prototypes
 

Modified: llvm/trunk/examples/BrainF/BrainF.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/examples/BrainF/BrainF.h?rev=74614&r1=74613&r2=74614&view=diff

==============================================================================
--- llvm/trunk/examples/BrainF/BrainF.h (original)
+++ llvm/trunk/examples/BrainF/BrainF.h Wed Jul  1 11:58:40 2009
@@ -15,6 +15,7 @@
 #ifndef BRAINF_H
 #define BRAINF_H
 
+#include "llvm/LLVMContext.h"
 #include "llvm/Module.h"
 #include "llvm/Support/IRBuilder.h"
 
@@ -38,7 +39,7 @@
     /// containing the resulting code.
     /// On error, it calls abort.
     /// The caller must delete the returned module.
-    Module *parse(std::istream *in1, int mem, CompileFlags cf);
+    Module *parse(std::istream *in1, int mem, CompileFlags cf, LLVMContext* C);
 
   protected:
     /// The different symbols in the BrainF language
@@ -64,7 +65,7 @@
     static const char *testreg;
 
     /// Put the brainf function preamble and other fixed pieces of code
-    void header();
+    void header(LLVMContext* C);
 
     /// The main loop for parsing.  It calls itself recursively
     /// to handle the depth of nesting of "[]".

Modified: llvm/trunk/examples/BrainF/BrainFDriver.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/examples/BrainF/BrainFDriver.cpp?rev=74614&r1=74613&r2=74614&view=diff

==============================================================================
--- llvm/trunk/examples/BrainF/BrainFDriver.cpp (original)
+++ llvm/trunk/examples/BrainF/BrainFDriver.cpp Wed Jul  1 11:58:40 2009
@@ -86,6 +86,8 @@
 int main(int argc, char **argv) {
   cl::ParseCommandLineOptions(argc, argv, " BrainF compiler\n");
 
+  LLVMContext Context;
+
   if (InputFilename == "") {
     std::cerr<<"Error: You must specify the filename of the program to "
     "be compiled.  Use --help to see the options.\n";
@@ -124,7 +126,7 @@
 
   //Read the BrainF program
   BrainF bf;
-  Module *mod = bf.parse(in, 65536, cf); //64 KiB
+  Module *mod = bf.parse(in, 65536, cf, &Context); //64 KiB
   if (in != &std::cin) {delete in;}
   addMainFunction(mod);
 

Modified: llvm/trunk/examples/Fibonacci/fibonacci.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/examples/Fibonacci/fibonacci.cpp?rev=74614&r1=74613&r2=74614&view=diff

==============================================================================
--- llvm/trunk/examples/Fibonacci/fibonacci.cpp (original)
+++ llvm/trunk/examples/Fibonacci/fibonacci.cpp Wed Jul  1 11:58:40 2009
@@ -23,6 +23,7 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "llvm/LLVMContext.h"
 #include "llvm/Module.h"
 #include "llvm/DerivedTypes.h"
 #include "llvm/Constants.h"
@@ -90,8 +91,10 @@
 int main(int argc, char **argv) {
   int n = argc > 1 ? atol(argv[1]) : 24;
 
+  LLVMContext Context;
+  
   // Create some module to put our function into it.
-  Module *M = new Module("test");
+  Module *M = new Module("test", &Context);
 
   // We are about to create the "fib" function:
   Function *FibF = CreateFibFunction(M);

Modified: llvm/trunk/examples/HowToUseJIT/HowToUseJIT.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/examples/HowToUseJIT/HowToUseJIT.cpp?rev=74614&r1=74613&r2=74614&view=diff

==============================================================================
--- llvm/trunk/examples/HowToUseJIT/HowToUseJIT.cpp (original)
+++ llvm/trunk/examples/HowToUseJIT/HowToUseJIT.cpp Wed Jul  1 11:58:40 2009
@@ -34,6 +34,7 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "llvm/LLVMContext.h"
 #include "llvm/Module.h"
 #include "llvm/Constants.h"
 #include "llvm/DerivedTypes.h"
@@ -50,9 +51,11 @@
 int main() {
   
   InitializeNativeTarget();
+
+  LLVMContext Context;
   
   // Create some module to put our function into it.
-  Module *M = new Module("test");
+  Module *M = new Module("test", &Context);
 
   // Create the add1 function entry and insert this entry into module M.  The
   // function will have a return type of "int" and take an argument of "int".

Modified: llvm/trunk/examples/Kaleidoscope/toy.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/examples/Kaleidoscope/toy.cpp?rev=74614&r1=74613&r2=74614&view=diff

==============================================================================
--- llvm/trunk/examples/Kaleidoscope/toy.cpp (original)
+++ llvm/trunk/examples/Kaleidoscope/toy.cpp Wed Jul  1 11:58:40 2009
@@ -1,5 +1,6 @@
 #include "llvm/DerivedTypes.h"
 #include "llvm/ExecutionEngine/ExecutionEngine.h"
+#include "llvm/LLVMContext.h"
 #include "llvm/Module.h"
 #include "llvm/ModuleProvider.h"
 #include "llvm/PassManager.h"
@@ -1083,6 +1084,7 @@
 
 int main() {
   InitializeNativeTarget();
+  LLVMContext Context;
   
   // Install standard binary operators.
   // 1 is lowest precedence.
@@ -1097,7 +1099,7 @@
   getNextToken();
 
   // Make the module, which holds all the code.
-  TheModule = new Module("my cool jit");
+  TheModule = new Module("my cool jit", &Context);
   
   // Create the JIT.
   TheExecutionEngine = ExecutionEngine::create(TheModule);

Modified: llvm/trunk/examples/ModuleMaker/ModuleMaker.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/examples/ModuleMaker/ModuleMaker.cpp?rev=74614&r1=74613&r2=74614&view=diff

==============================================================================
--- llvm/trunk/examples/ModuleMaker/ModuleMaker.cpp (original)
+++ llvm/trunk/examples/ModuleMaker/ModuleMaker.cpp Wed Jul  1 11:58:40 2009
@@ -13,6 +13,7 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "llvm/LLVMContext.h"
 #include "llvm/Module.h"
 #include "llvm/DerivedTypes.h"
 #include "llvm/Constants.h"
@@ -22,9 +23,11 @@
 using namespace llvm;
 
 int main() {
+  LLVMContext Context;
+
   // Create the "module" or "program" or "translation unit" to hold the
   // function
-  Module *M = new Module("test");
+  Module *M = new Module("test", &Context);
 
   // Create the main function: first create the type 'int ()'
   FunctionType *FT = FunctionType::get(Type::Int32Ty, /*not vararg*/false);

Modified: llvm/trunk/examples/ParallelJIT/ParallelJIT.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/examples/ParallelJIT/ParallelJIT.cpp?rev=74614&r1=74613&r2=74614&view=diff

==============================================================================
--- llvm/trunk/examples/ParallelJIT/ParallelJIT.cpp (original)
+++ llvm/trunk/examples/ParallelJIT/ParallelJIT.cpp Wed Jul  1 11:58:40 2009
@@ -18,6 +18,7 @@
 // same time). This test had assertion errors until I got the locking right.
 
 #include <pthread.h>
+#include "llvm/LLVMContext.h"
 #include "llvm/Module.h"
 #include "llvm/Constants.h"
 #include "llvm/DerivedTypes.h"
@@ -232,9 +233,10 @@
 
 int main() {
   InitializeNativeTarget();
+  LLVMContext Context;
 
   // Create some module to put our function into it.
-  Module *M = new Module("test");
+  Module *M = new Module("test", &Context);
 
   Function* add1F = createAdd1( M );
   Function* fibF = CreateFibFunction( M );

Modified: llvm/trunk/include/llvm-c/BitReader.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm-c/BitReader.h?rev=74614&r1=74613&r2=74614&view=diff

==============================================================================
--- llvm/trunk/include/llvm-c/BitReader.h (original)
+++ llvm/trunk/include/llvm-c/BitReader.h Wed Jul  1 11:58:40 2009
@@ -29,13 +29,14 @@
 /* Builds a module from the bitcode in the specified memory buffer, returning a
    reference to the module via the OutModule parameter. Returns 0 on success.
    Optionally returns a human-readable error message via OutMessage. */ 
-int LLVMParseBitcode(LLVMMemoryBufferRef MemBuf,
+int LLVMParseBitcode(LLVMMemoryBufferRef MemBuf, LLVMContextRef ContextRef,
                      LLVMModuleRef *OutModule, char **OutMessage);
 
 /* Reads a module from the specified path, returning via the OutMP parameter
    a module provider which performs lazy deserialization. Returns 0 on success.
    Optionally returns a human-readable error message via OutMessage. */ 
 int LLVMGetBitcodeModuleProvider(LLVMMemoryBufferRef MemBuf,
+                                 LLVMContextRef ContextRef,
                                  LLVMModuleProviderRef *OutMP,
                                  char **OutMessage);
 

Modified: llvm/trunk/include/llvm-c/Core.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm-c/Core.h?rev=74614&r1=74613&r2=74614&view=diff

==============================================================================
--- llvm/trunk/include/llvm-c/Core.h (original)
+++ llvm/trunk/include/llvm-c/Core.h Wed Jul  1 11:58:40 2009
@@ -47,6 +47,11 @@
 /* Opaque types. */
 
 /**
+ * The top-level container for all LLVM global data.  See the LLVMContext class.
+ */
+typedef struct LLVMCtxt *LLVMContextRef;
+
+/**
  * The top-level container for all other LLVM Intermediate Representation (IR)
  * objects. See the llvm::Module class.
  */
@@ -188,6 +193,10 @@
 
 /*===-- Modules -----------------------------------------------------------===*/
 
+/* Create and destroy contexts. */
+LLVMContextRef LLVMContextCreate();
+void LLVMContextDispose(LLVMContextRef C);
+
 /* Create and destroy modules. */ 
 /** See llvm::Module::Module. */
 LLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID);
@@ -815,6 +824,7 @@
   DEFINE_SIMPLE_CONVERSION_FUNCTIONS(PATypeHolder,       LLVMTypeHandleRef    )
   DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ModuleProvider,     LLVMModuleProviderRef)
   DEFINE_SIMPLE_CONVERSION_FUNCTIONS(MemoryBuffer,       LLVMMemoryBufferRef  )
+  DEFINE_SIMPLE_CONVERSION_FUNCTIONS(LLVMContext,        LLVMContextRef       )
   DEFINE_STDCXX_CONVERSION_FUNCTIONS(PassManagerBase,    LLVMPassManagerRef   )
   
   #undef DEFINE_STDCXX_CONVERSION_FUNCTIONS

Modified: llvm/trunk/include/llvm/Assembly/Parser.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Assembly/Parser.h?rev=74614&r1=74613&r2=74614&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Assembly/Parser.h (original)
+++ llvm/trunk/include/llvm/Assembly/Parser.h Wed Jul  1 11:58:40 2009
@@ -21,6 +21,7 @@
 class Module;
 class ParseError;
 class raw_ostream;
+class LLVMContext;
 
 /// This function is the main interface to the LLVM Assembly Parser. It parses
 /// an ASCII file that (presumably) contains LLVM Assembly code. It returns a
@@ -30,7 +31,8 @@
 /// @brief Parse LLVM Assembly from a file
 Module *ParseAssemblyFile(
   const std::string &Filename, ///< The name of the file to parse
-  ParseError &Error            ///< If not null, an object to return errors in.
+  ParseError &Error,           ///< If not null, an object to return errors in.
+  LLVMContext* Context         ///< Context in which to allocate globals info.
 );
 
 /// The function is a secondary interface to the LLVM Assembly Parser. It parses
@@ -42,7 +44,8 @@
 Module *ParseAssemblyString(
   const char *AsmString, ///< The string containing assembly
   Module *M,             ///< A module to add the assembly too.
-  ParseError &Error      ///< If not null, an object to return errors in.
+  ParseError &Error,     ///< If not null, an object to return errors in.
+  LLVMContext* Context
 );
 
 //===------------------------------------------------------------------------===

Modified: llvm/trunk/include/llvm/Bitcode/Archive.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Bitcode/Archive.h?rev=74614&r1=74613&r2=74614&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Bitcode/Archive.h (original)
+++ llvm/trunk/include/llvm/Bitcode/Archive.h Wed Jul  1 11:58:40 2009
@@ -32,6 +32,7 @@
 class Module;              // From VMCore
 class Archive;             // Declared below
 class ArchiveMemberHeader; // Internal implementation class
+class LLVMContext;         // Global data
 
 /// This class is the main class manipulated by users of the Archive class. It
 /// holds information about one member of the Archive. It is also the element
@@ -278,7 +279,8 @@
     /// @returns An Archive* that represents the new archive file.
     /// @brief Create an empty Archive.
     static Archive* CreateEmpty(
-      const sys::Path& Filename ///< Name of the archive to (eventually) create.
+      const sys::Path& Filename,///< Name of the archive to (eventually) create.
+      LLVMContext* C            ///< Context to use for global information
     );
 
     /// Open an existing archive and load its contents in preparation for
@@ -289,6 +291,7 @@
     /// @brief Open and load an archive file
     static Archive* OpenAndLoad(
       const sys::Path& filePath,  ///< The file path to open and load
+      LLVMContext* C,             ///< The context to use for global information
       std::string* ErrorMessage   ///< An optional error string
     );
 
@@ -310,6 +313,7 @@
     /// @brief Open an existing archive and load its symbols.
     static Archive* OpenAndLoadSymbols(
       const sys::Path& Filename,   ///< Name of the archive file to open
+      LLVMContext* C,              ///< The context to use for global info
       std::string* ErrorMessage=0  ///< An optional error string
     );
 
@@ -449,7 +453,7 @@
   protected:
     /// @brief Construct an Archive for \p filename and optionally  map it
     /// into memory.
-    explicit Archive(const sys::Path& filename);
+    explicit Archive(const sys::Path& filename, LLVMContext* C);
 
     /// @param data The symbol table data to be parsed
     /// @param len  The length of the symbol table data
@@ -530,6 +534,7 @@
     unsigned firstFileOffset; ///< Offset to first normal file.
     ModuleMap modules;        ///< The modules loaded via symbol lookup.
     ArchiveMember* foreignST; ///< This holds the foreign symbol table.
+    LLVMContext* Context;     ///< This holds global data.
   /// @}
   /// @name Hidden
   /// @{

Modified: llvm/trunk/include/llvm/Bitcode/ReaderWriter.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Bitcode/ReaderWriter.h?rev=74614&r1=74613&r2=74614&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Bitcode/ReaderWriter.h (original)
+++ llvm/trunk/include/llvm/Bitcode/ReaderWriter.h Wed Jul  1 11:58:40 2009
@@ -23,6 +23,7 @@
   class MemoryBuffer;
   class ModulePass;
   class BitstreamWriter;
+  class LLVMContext;
   class raw_ostream;
   
   /// getBitcodeModuleProvider - Read the header of the specified bitcode buffer
@@ -31,12 +32,14 @@
   /// error, this returns null, *does not* take ownership of Buffer, and fills
   /// in *ErrMsg with an error description if ErrMsg is non-null.
   ModuleProvider *getBitcodeModuleProvider(MemoryBuffer *Buffer,
+                                           LLVMContext* Context,
                                            std::string *ErrMsg = 0);
 
   /// ParseBitcodeFile - Read the specified bitcode file, returning the module.
   /// If an error occurs, this returns null and fills in *ErrMsg if it is
   /// non-null.  This method *never* takes ownership of Buffer.
-  Module *ParseBitcodeFile(MemoryBuffer *Buffer, std::string *ErrMsg = 0);
+  Module *ParseBitcodeFile(MemoryBuffer *Buffer, LLVMContext* Context,
+                           std::string *ErrMsg = 0);
 
   /// WriteBitcodeToFile - Write the specified module to the specified output
   /// stream.

Modified: llvm/trunk/include/llvm/Debugger/Debugger.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Debugger/Debugger.h?rev=74614&r1=74613&r2=74614&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Debugger/Debugger.h (original)
+++ llvm/trunk/include/llvm/Debugger/Debugger.h Wed Jul  1 11:58:40 2009
@@ -20,6 +20,7 @@
 namespace llvm {
   class Module;
   class InferiorProcess;
+  class LLVMContext;
 
   /// Debugger class - This class implements the LLVM source-level debugger.
   /// This allows clients to handle the user IO processing without having to
@@ -95,7 +96,7 @@
     /// the PATH for the specified program, loading it when found.  If the
     /// specified program cannot be found, an exception is thrown to indicate
     /// the error.
-    void loadProgram(const std::string &Path);
+    void loadProgram(const std::string &Path, LLVMContext* Context);
 
     /// unloadProgram - If a program is running, kill it, then unload all traces
     /// of the current program.  If no program is loaded, this method silently

Modified: llvm/trunk/include/llvm/LinkAllVMCore.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/LinkAllVMCore.h?rev=74614&r1=74613&r2=74614&view=diff

==============================================================================
--- llvm/trunk/include/llvm/LinkAllVMCore.h (original)
+++ llvm/trunk/include/llvm/LinkAllVMCore.h Wed Jul  1 11:58:40 2009
@@ -44,7 +44,7 @@
       // to know that getenv() never returns -1, this will do the job.
       if (std::getenv("bar") != (char*) -1)
         return;
-      llvm::Module* M = new llvm::Module("");
+      llvm::Module* M = new llvm::Module("", 0);
       (void)new llvm::UnreachableInst();
       (void)    llvm::createVerifierPass(); 
       (void) new llvm::Mangler(*M,"");

Modified: llvm/trunk/include/llvm/Linker.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Linker.h?rev=74614&r1=74613&r2=74614&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Linker.h (original)
+++ llvm/trunk/include/llvm/Linker.h Wed Jul  1 11:58:40 2009
@@ -21,6 +21,7 @@
 namespace llvm {
 
 class Module;
+class LLVMContext;
 
 /// This class provides the core functionality of linking in LLVM. It retains a
 /// Module object which is the composite of the modules and libraries linked
@@ -66,6 +67,7 @@
     Linker(
         const std::string& progname, ///< name of tool running linker
         const std::string& modulename, ///< name of linker's end-result module
+        LLVMContext* C, ///< Context for global info
         unsigned Flags = 0  ///< ControlFlags (one or more |'d together)
     );
 
@@ -283,6 +285,7 @@
   /// @name Data
   /// @{
   private:
+    LLVMContext* Context; ///< The context for global information
     Module* Composite; ///< The composite module linked together
     std::vector<sys::Path> LibPaths; ///< The library search paths
     unsigned Flags;    ///< Flags to control optional behavior.

Modified: llvm/trunk/include/llvm/Module.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Module.h?rev=74614&r1=74613&r2=74614&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Module.h (original)
+++ llvm/trunk/include/llvm/Module.h Wed Jul  1 11:58:40 2009
@@ -25,6 +25,7 @@
 
 class GlobalValueRefMap;   // Used by ConstantVals.cpp
 class FunctionType;
+class LLVMContext;
 
 template<> struct ilist_traits<Function>
   : public SymbolTableListTraits<Function, Module> {
@@ -109,6 +110,8 @@
 /// @name Member Variables
 /// @{
 private:
+  LLVMContext* Context;          ///< The LLVMContext from which types and
+                                 ///< constants are allocated.
   GlobalListType GlobalList;     ///< The Global Variables in the module
   FunctionListType FunctionList; ///< The Functions in the module
   AliasListType AliasList;       ///< The Aliases in the module
@@ -128,7 +131,7 @@
 public:
   /// The Module constructor. Note that there is no default constructor. You
   /// must provide a name for the module upon construction.
-  explicit Module(const std::string &ModuleID);
+  explicit Module(const std::string &ModuleID, LLVMContext* C);
   /// The module destructor. This will dropAllReferences.
   ~Module();
 
@@ -157,6 +160,10 @@
   /// @returns PointerSize - an enumeration for the size of the target's pointer
   PointerSize getPointerSize() const;
 
+  /// Get the global data context.
+  /// @returns LLVMContext - a container for LLVM's global information
+  LLVMContext* getContext() const { return Context; }
+
   /// Get any module-scope inline assembly blocks.
   /// @returns a string containing the module-scope inline assembly blocks.
   const std::string &getModuleInlineAsm() const { return GlobalScopeAsm; }

Modified: llvm/trunk/include/llvm/Transforms/Utils/Cloning.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Transforms/Utils/Cloning.h?rev=74614&r1=74613&r2=74614&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Transforms/Utils/Cloning.h (original)
+++ llvm/trunk/include/llvm/Transforms/Utils/Cloning.h Wed Jul  1 11:58:40 2009
@@ -37,6 +37,7 @@
 class CallGraph;
 class TargetData;
 class LoopInfo;
+class LLVMContext;
 template<class N> class LoopBase;
 typedef LoopBase<BasicBlock> Loop;
 

Modified: llvm/trunk/lib/Archive/Archive.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Archive/Archive.cpp?rev=74614&r1=74613&r2=74614&view=diff

==============================================================================
--- llvm/trunk/lib/Archive/Archive.cpp (original)
+++ llvm/trunk/lib/Archive/Archive.cpp Wed Jul  1 11:58:40 2009
@@ -138,9 +138,9 @@
 // Archive constructor - this is the only constructor that gets used for the
 // Archive class. Everything else (default,copy) is deprecated. This just
 // initializes and maps the file into memory, if requested.
-Archive::Archive(const sys::Path& filename)
+Archive::Archive(const sys::Path& filename, LLVMContext* C)
   : archPath(filename), members(), mapfile(0), base(0), symTab(), strtab(),
-    symTabSize(0), firstFileOffset(0), modules(), foreignST(0) {
+    symTabSize(0), firstFileOffset(0), modules(), foreignST(0), Context(C) {
 }
 
 bool
@@ -208,6 +208,7 @@
 
 // Get just the externally visible defined symbols from the bitcode
 bool llvm::GetBitcodeSymbols(const sys::Path& fName,
+                             LLVMContext* Context,
                              std::vector<std::string>& symbols,
                              std::string* ErrMsg) {
   std::auto_ptr<MemoryBuffer> Buffer(
@@ -217,7 +218,7 @@
     return true;
   }
   
-  ModuleProvider *MP = getBitcodeModuleProvider(Buffer.get(), ErrMsg);
+  ModuleProvider *MP = getBitcodeModuleProvider(Buffer.get(), Context, ErrMsg);
   if (!MP)
     return true;
   
@@ -239,13 +240,14 @@
 ModuleProvider*
 llvm::GetBitcodeSymbols(const unsigned char *BufPtr, unsigned Length,
                         const std::string& ModuleID,
+                        LLVMContext* Context,
                         std::vector<std::string>& symbols,
                         std::string* ErrMsg) {
   // Get the module provider
   MemoryBuffer *Buffer =MemoryBuffer::getNewMemBuffer(Length, ModuleID.c_str());
   memcpy((char*)Buffer->getBufferStart(), BufPtr, Length);
   
-  ModuleProvider *MP = getBitcodeModuleProvider(Buffer, ErrMsg);
+  ModuleProvider *MP = getBitcodeModuleProvider(Buffer, Context, ErrMsg);
   if (!MP)
     return 0;
   

Modified: llvm/trunk/lib/Archive/ArchiveInternals.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Archive/ArchiveInternals.h?rev=74614&r1=74613&r2=74614&view=diff

==============================================================================
--- llvm/trunk/lib/Archive/ArchiveInternals.h (original)
+++ llvm/trunk/lib/Archive/ArchiveInternals.h Wed Jul  1 11:58:40 2009
@@ -31,6 +31,8 @@
 
 namespace llvm {
 
+  class LLVMContext;
+
   /// The ArchiveMemberHeader structure is used internally for bitcode
   /// archives.
   /// The header precedes each file member in the archive. This structure is
@@ -71,11 +73,13 @@
   
   // Get just the externally visible defined symbols from the bitcode
   bool GetBitcodeSymbols(const sys::Path& fName,
+                          LLVMContext* Context,
                           std::vector<std::string>& symbols,
                           std::string* ErrMsg);
   
   ModuleProvider* GetBitcodeSymbols(const unsigned char*Buffer,unsigned Length,
                                     const std::string& ModuleID,
+                                    LLVMContext* Context,
                                     std::vector<std::string>& symbols,
                                     std::string* ErrMsg);
 }

Modified: llvm/trunk/lib/Archive/ArchiveReader.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Archive/ArchiveReader.cpp?rev=74614&r1=74613&r2=74614&view=diff

==============================================================================
--- llvm/trunk/lib/Archive/ArchiveReader.cpp (original)
+++ llvm/trunk/lib/Archive/ArchiveReader.cpp Wed Jul  1 11:58:40 2009
@@ -327,9 +327,9 @@
 
 // Open and completely load the archive file.
 Archive*
-Archive::OpenAndLoad(const sys::Path& file, std::string* ErrorMessage) 
-{
-  std::auto_ptr<Archive> result ( new Archive(file));
+Archive::OpenAndLoad(const sys::Path& file, LLVMContext* C, 
+                     std::string* ErrorMessage) {
+  std::auto_ptr<Archive> result ( new Archive(file, C));
   if (result->mapToMemory(ErrorMessage))
     return 0;
   if (!result->loadArchive(ErrorMessage))
@@ -339,7 +339,8 @@
 
 // Get all the bitcode modules from the archive
 bool
-Archive::getAllModules(std::vector<Module*>& Modules, std::string* ErrMessage) {
+Archive::getAllModules(std::vector<Module*>& Modules,
+                       std::string* ErrMessage) {
 
   for (iterator I=begin(), E=end(); I != E; ++I) {
     if (I->isBitcode()) {
@@ -349,7 +350,7 @@
         MemoryBuffer::getNewMemBuffer(I->getSize(), FullMemberName.c_str());
       memcpy((char*)Buffer->getBufferStart(), I->getData(), I->getSize());
       
-      Module *M = ParseBitcodeFile(Buffer, ErrMessage);
+      Module *M = ParseBitcodeFile(Buffer, Context, ErrMessage);
       delete Buffer;
       if (!M)
         return true;
@@ -440,9 +441,9 @@
 }
 
 // Open the archive and load just the symbol tables
-Archive*
-Archive::OpenAndLoadSymbols(const sys::Path& file, std::string* ErrorMessage) {
-  std::auto_ptr<Archive> result ( new Archive(file) );
+Archive* Archive::OpenAndLoadSymbols(const sys::Path& file, LLVMContext* C,
+                                     std::string* ErrorMessage) {
+  std::auto_ptr<Archive> result ( new Archive(file, C) );
   if (result->mapToMemory(ErrorMessage))
     return 0;
   if (!result->loadSymbolTable(ErrorMessage))
@@ -488,7 +489,7 @@
                                                       FullMemberName.c_str());
   memcpy((char*)Buffer->getBufferStart(), mbr->getData(), mbr->getSize());
   
-  ModuleProvider *mp = getBitcodeModuleProvider(Buffer, ErrMsg);
+  ModuleProvider *mp = getBitcodeModuleProvider(Buffer, Context, ErrMsg);
   if (!mp)
     return 0;
 
@@ -536,7 +537,7 @@
           mbr->getPath().toString() + ")";
         ModuleProvider* MP = 
           GetBitcodeSymbols((const unsigned char*)At, mbr->getSize(),
-                            FullMemberName, symbols, error);
+                            FullMemberName, Context, symbols, error);
 
         if (MP) {
           // Insert the module's symbols into the symbol table
@@ -615,7 +616,7 @@
     MemoryBuffer *Buffer =
       MemoryBuffer::getNewMemBuffer(I->getSize(), FullMemberName.c_str());
     memcpy((char*)Buffer->getBufferStart(), I->getData(), I->getSize());
-    Module *M = ParseBitcodeFile(Buffer);
+    Module *M = ParseBitcodeFile(Buffer, Context);
     delete Buffer;
     if (!M)
       return false;  // Couldn't parse bitcode, not a bitcode archive.

Modified: llvm/trunk/lib/Archive/ArchiveWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Archive/ArchiveWriter.cpp?rev=74614&r1=74613&r2=74614&view=diff

==============================================================================
--- llvm/trunk/lib/Archive/ArchiveWriter.cpp (original)
+++ llvm/trunk/lib/Archive/ArchiveWriter.cpp Wed Jul  1 11:58:40 2009
@@ -64,9 +64,8 @@
 }
 
 // Create an empty archive.
-Archive*
-Archive::CreateEmpty(const sys::Path& FilePath ) {
-  Archive* result = new Archive(FilePath);
+Archive* Archive::CreateEmpty(const sys::Path& FilePath, LLVMContext* C) {
+  Archive* result = new Archive(FilePath, C);
   return result;
 }
 
@@ -229,7 +228,7 @@
       + ")";
     ModuleProvider* MP = 
       GetBitcodeSymbols((const unsigned char*)data,fSize,
-                        FullMemberName, symbols, ErrMsg);
+                        FullMemberName, Context, symbols, ErrMsg);
 
     // If the bitcode parsed successfully
     if ( MP ) {

Modified: llvm/trunk/lib/AsmParser/Parser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/AsmParser/Parser.cpp?rev=74614&r1=74613&r2=74614&view=diff

==============================================================================
--- llvm/trunk/lib/AsmParser/Parser.cpp (original)
+++ llvm/trunk/lib/AsmParser/Parser.cpp Wed Jul  1 11:58:40 2009
@@ -20,7 +20,8 @@
 #include <cstring>
 using namespace llvm;
 
-Module *llvm::ParseAssemblyFile(const std::string &Filename, ParseError &Err) {
+Module *llvm::ParseAssemblyFile(const std::string &Filename, ParseError &Err,
+                                LLVMContext* Context) {
   Err.setFilename(Filename);
 
   std::string ErrorStr;
@@ -31,14 +32,14 @@
     return 0;
   }
 
-  OwningPtr<Module> M(new Module(Filename));
+  OwningPtr<Module> M(new Module(Filename, Context));
   if (LLParser(F.get(), Err, M.get()).Run())
     return 0;
   return M.take();
 }
 
 Module *llvm::ParseAssemblyString(const char *AsmString, Module *M,
-                                  ParseError &Err) {
+                                  ParseError &Err, LLVMContext* Context) {
   Err.setFilename("<string>");
 
   OwningPtr<MemoryBuffer>
@@ -50,7 +51,7 @@
     return LLParser(F.get(), Err, M).Run() ? 0 : M;
 
   // Otherwise create a new module.
-  OwningPtr<Module> M2(new Module("<string>"));
+  OwningPtr<Module> M2(new Module("<string>", Context));
   if (LLParser(F.get(), Err, M2.get()).Run())
     return 0;
   return M2.take();

Modified: llvm/trunk/lib/Bitcode/Reader/BitReader.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Bitcode/Reader/BitReader.cpp?rev=74614&r1=74613&r2=74614&view=diff

==============================================================================
--- llvm/trunk/lib/Bitcode/Reader/BitReader.cpp (original)
+++ llvm/trunk/lib/Bitcode/Reader/BitReader.cpp Wed Jul  1 11:58:40 2009
@@ -18,11 +18,12 @@
 /* Builds a module from the bitcode in the specified memory buffer, returning a
    reference to the module via the OutModule parameter. Returns 0 on success.
    Optionally returns a human-readable error message via OutMessage. */ 
-int LLVMParseBitcode(LLVMMemoryBufferRef MemBuf,
+int LLVMParseBitcode(LLVMMemoryBufferRef MemBuf, LLVMContextRef ContextRef,
                      LLVMModuleRef *OutModule, char **OutMessage) {
   std::string Message;
   
-  *OutModule = wrap(ParseBitcodeFile(unwrap(MemBuf), &Message));
+  *OutModule = wrap(ParseBitcodeFile(unwrap(MemBuf), unwrap(ContextRef),  
+                                     &Message));
   if (!*OutModule) {
     if (OutMessage)
       *OutMessage = strdup(Message.c_str());
@@ -36,11 +37,13 @@
    a module provider which performs lazy deserialization. Returns 0 on success.
    Optionally returns a human-readable error message via OutMessage. */ 
 int LLVMGetBitcodeModuleProvider(LLVMMemoryBufferRef MemBuf,
+                                 LLVMContextRef ContextRef,
                                  LLVMModuleProviderRef *OutMP,
                                  char **OutMessage) {
   std::string Message;
   
-  *OutMP = wrap(getBitcodeModuleProvider(unwrap(MemBuf), &Message));
+  *OutMP = wrap(getBitcodeModuleProvider(unwrap(MemBuf), unwrap(ContextRef), 
+                                         &Message));
   if (!*OutMP) {
     if (OutMessage)
       *OutMessage = strdup(Message.c_str());

Modified: llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp?rev=74614&r1=74613&r2=74614&view=diff

==============================================================================
--- llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp (original)
+++ llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp Wed Jul  1 11:58:40 2009
@@ -1087,7 +1087,7 @@
     return Error("Malformed block record");
 
   // Otherwise, create the module.
-  TheModule = new Module(ModuleID);
+  TheModule = new Module(ModuleID, Context);
   
   SmallVector<uint64_t, 64> Record;
   std::vector<std::string> SectionTable;
@@ -2090,8 +2090,9 @@
 /// getBitcodeModuleProvider - lazy function-at-a-time loading from a file.
 ///
 ModuleProvider *llvm::getBitcodeModuleProvider(MemoryBuffer *Buffer,
+                                               LLVMContext* Context,
                                                std::string *ErrMsg) {
-  BitcodeReader *R = new BitcodeReader(Buffer);
+  BitcodeReader *R = new BitcodeReader(Buffer, Context);
   if (R->ParseBitcode()) {
     if (ErrMsg)
       *ErrMsg = R->getErrorString();
@@ -2106,9 +2107,11 @@
 
 /// ParseBitcodeFile - Read the specified bitcode file, returning the module.
 /// If an error occurs, return null and fill in *ErrMsg if non-null.
-Module *llvm::ParseBitcodeFile(MemoryBuffer *Buffer, std::string *ErrMsg){
+Module *llvm::ParseBitcodeFile(MemoryBuffer *Buffer, LLVMContext* Context, 
+                               std::string *ErrMsg){
   BitcodeReader *R;
-  R = static_cast<BitcodeReader*>(getBitcodeModuleProvider(Buffer, ErrMsg));
+  R = static_cast<BitcodeReader*>(getBitcodeModuleProvider(Buffer, Context, 
+                                                           ErrMsg));
   if (!R) return 0;
   
   // Read in the entire module.

Modified: llvm/trunk/lib/Bitcode/Reader/BitcodeReader.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Bitcode/Reader/BitcodeReader.h?rev=74614&r1=74613&r2=74614&view=diff

==============================================================================
--- llvm/trunk/lib/Bitcode/Reader/BitcodeReader.h (original)
+++ llvm/trunk/lib/Bitcode/Reader/BitcodeReader.h Wed Jul  1 11:58:40 2009
@@ -26,6 +26,7 @@
 
 namespace llvm {
   class MemoryBuffer;
+  class LLVMContext;
   
 //===----------------------------------------------------------------------===//
 //                          BitcodeReaderValueList Class
@@ -85,6 +86,7 @@
 };
 
 class BitcodeReader : public ModuleProvider {
+  LLVMContext* Context;
   MemoryBuffer *Buffer;
   BitstreamReader StreamFile;
   BitstreamCursor Stream;
@@ -123,8 +125,8 @@
   /// stream) and what linkage the original function had.
   DenseMap<Function*, std::pair<uint64_t, unsigned> > DeferredFunctionInfo;
 public:
-  explicit BitcodeReader(MemoryBuffer *buffer)
-      : Buffer(buffer), ErrorString(0) {
+  explicit BitcodeReader(MemoryBuffer *buffer, LLVMContext* C)
+      : Context(C), Buffer(buffer), ErrorString(0) {
     HasReversedFunctionsWithBodies = false;
   }
   ~BitcodeReader() {

Modified: llvm/trunk/lib/Debugger/Debugger.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Debugger/Debugger.cpp?rev=74614&r1=74613&r2=74614&view=diff

==============================================================================
--- llvm/trunk/lib/Debugger/Debugger.cpp (original)
+++ llvm/trunk/lib/Debugger/Debugger.cpp Wed Jul  1 11:58:40 2009
@@ -46,11 +46,11 @@
 }
 
 static Module *
-getMaterializedModuleProvider(const std::string &Filename) {
+getMaterializedModuleProvider(const std::string &Filename, LLVMContext* C) {
   std::auto_ptr<MemoryBuffer> Buffer;
   Buffer.reset(MemoryBuffer::getFileOrSTDIN(Filename.c_str()));
   if (Buffer.get())
-    return ParseBitcodeFile(Buffer.get());
+    return ParseBitcodeFile(Buffer.get(), C);
   return 0;
 }
 
@@ -58,9 +58,9 @@
 /// the PATH for the specified program, loading it when found.  If the
 /// specified program cannot be found, an exception is thrown to indicate the
 /// error.
-void Debugger::loadProgram(const std::string &Filename) {
-  if ((Program = getMaterializedModuleProvider(Filename)) ||
-      (Program = getMaterializedModuleProvider(Filename+".bc")))
+void Debugger::loadProgram(const std::string &Filename, LLVMContext* C) {
+  if ((Program = getMaterializedModuleProvider(Filename, C)) ||
+      (Program = getMaterializedModuleProvider(Filename+".bc", C)))
     return;   // Successfully loaded the program.
 
   // Search the program path for the file...
@@ -69,9 +69,9 @@
 
     std::string Directory = getToken(Path, ":");
     while (!Directory.empty()) {
-      if ((Program = getMaterializedModuleProvider(Directory +"/"+ Filename)) ||
-          (Program = getMaterializedModuleProvider(Directory +"/"+ Filename
-                                                                      + ".bc")))
+      if ((Program = getMaterializedModuleProvider(Directory +"/"+ Filename, C))
+       || (Program = getMaterializedModuleProvider(Directory +"/"+ Filename
+                                                                   + ".bc", C)))
         return;   // Successfully loaded the program.
 
       Directory = getToken(Path, ":");

Modified: llvm/trunk/lib/Linker/LinkArchives.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Linker/LinkArchives.cpp?rev=74614&r1=74613&r2=74614&view=diff

==============================================================================
--- llvm/trunk/lib/Linker/LinkArchives.cpp (original)
+++ llvm/trunk/lib/Linker/LinkArchives.cpp Wed Jul  1 11:58:40 2009
@@ -115,7 +115,7 @@
 
   std::string ErrMsg;
   std::auto_ptr<Archive> AutoArch (
-    Archive::OpenAndLoadSymbols(Filename,&ErrMsg));
+    Archive::OpenAndLoadSymbols(Filename, Context, &ErrMsg));
 
   Archive* arch = AutoArch.get();
 

Modified: llvm/trunk/lib/Linker/LinkItems.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Linker/LinkItems.cpp?rev=74614&r1=74613&r2=74614&view=diff

==============================================================================
--- llvm/trunk/lib/Linker/LinkItems.cpp (original)
+++ llvm/trunk/lib/Linker/LinkItems.cpp Wed Jul  1 11:58:40 2009
@@ -160,7 +160,7 @@
   if (File.toString() == "-") {
     std::auto_ptr<Module> M;
     if (MemoryBuffer *Buffer = MemoryBuffer::getSTDIN()) {
-      M.reset(ParseBitcodeFile(Buffer, &Error));
+      M.reset(ParseBitcodeFile(Buffer, Context, &Error));
       delete Buffer;
       if (M.get())
         if (!LinkInModule(M.get(), &Error))

Modified: llvm/trunk/lib/Linker/Linker.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Linker/Linker.cpp?rev=74614&r1=74613&r2=74614&view=diff

==============================================================================
--- llvm/trunk/lib/Linker/Linker.cpp (original)
+++ llvm/trunk/lib/Linker/Linker.cpp Wed Jul  1 11:58:40 2009
@@ -20,24 +20,21 @@
 using namespace llvm;
 
 Linker::Linker(const std::string& progname, const std::string& modname,
-               unsigned flags)
-  : Composite(0)
-  , LibPaths()
-  , Flags(flags)
-  , Error()
-  , ProgramName(progname)
-{
-  Composite = new Module(modname);
-}
-
-Linker::Linker(const std::string& progname, Module* aModule, unsigned flags)
-  : Composite(aModule)
-  , LibPaths()
-  , Flags(flags)
-  , Error()
-  , ProgramName(progname)
-{
-}
+               LLVMContext* C, unsigned flags): 
+  Context(C),
+  Composite(new Module(modname, C)),
+  LibPaths(),
+  Flags(flags),
+  Error(),
+  ProgramName(progname) { }
+
+Linker::Linker(const std::string& progname, Module* aModule, unsigned flags) : 
+  Context(aModule->getContext()),
+  Composite(aModule),
+  LibPaths(),
+  Flags(flags),
+  Error(),
+  ProgramName(progname) { }
 
 Linker::~Linker() {
   delete Composite;
@@ -106,7 +103,7 @@
   const std::string &FNS = FN.toString();
   std::auto_ptr<MemoryBuffer> Buffer(MemoryBuffer::getFileOrSTDIN(FNS.c_str()));
   if (Buffer.get())
-    Result = ParseBitcodeFile(Buffer.get(), &ParseErrorMessage);
+    Result = ParseBitcodeFile(Buffer.get(), Context, &ParseErrorMessage);
   else
     ParseErrorMessage = "Error reading file '" + FNS + "'";
     

Modified: llvm/trunk/lib/Transforms/Utils/CloneModule.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/CloneModule.cpp?rev=74614&r1=74613&r2=74614&view=diff

==============================================================================
--- llvm/trunk/lib/Transforms/Utils/CloneModule.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/CloneModule.cpp Wed Jul  1 11:58:40 2009
@@ -35,7 +35,7 @@
 Module *llvm::CloneModule(const Module *M,
                           DenseMap<const Value*, Value*> &ValueMap) {
   // First off, we need to create the new module...
-  Module *New = new Module(M->getModuleIdentifier());
+  Module *New = new Module(M->getModuleIdentifier(), M->getContext());
   New->setDataLayout(M->getDataLayout());
   New->setTargetTriple(M->getTargetTriple());
   New->setModuleInlineAsm(M->getModuleInlineAsm());

Modified: llvm/trunk/lib/VMCore/Core.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Core.cpp?rev=74614&r1=74613&r2=74614&view=diff

==============================================================================
--- llvm/trunk/lib/VMCore/Core.cpp (original)
+++ llvm/trunk/lib/VMCore/Core.cpp Wed Jul  1 11:58:40 2009
@@ -18,6 +18,7 @@
 #include "llvm/DerivedTypes.h"
 #include "llvm/GlobalVariable.h"
 #include "llvm/GlobalAlias.h"
+#include "llvm/LLVMContext.h"
 #include "llvm/TypeSymbolTable.h"
 #include "llvm/ModuleProvider.h"
 #include "llvm/InlineAsm.h"
@@ -38,10 +39,21 @@
 }
 
 
+/*===-- Operations on contexts --------------------------------------------===*/
+
+LLVMContextRef LLVMContextCreate() {
+  return wrap(new LLVMContext());
+}
+
+void LLVMContextDispose(LLVMContextRef C) {
+  delete unwrap(C);
+}
+
+
 /*===-- Operations on modules ---------------------------------------------===*/
 
-LLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID) {
-  return wrap(new Module(ModuleID));
+LLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID, LLVMContextRef C) {
+  return wrap(new Module(ModuleID, unwrap(C)));
 }
 
 void LLVMDisposeModule(LLVMModuleRef M) {

Modified: llvm/trunk/lib/VMCore/Module.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Module.cpp?rev=74614&r1=74613&r2=74614&view=diff

==============================================================================
--- llvm/trunk/lib/VMCore/Module.cpp (original)
+++ llvm/trunk/lib/VMCore/Module.cpp Wed Jul  1 11:58:40 2009
@@ -15,6 +15,7 @@
 #include "llvm/InstrTypes.h"
 #include "llvm/Constants.h"
 #include "llvm/DerivedTypes.h"
+#include "llvm/LLVMContext.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/Support/LeakDetector.h"
@@ -54,8 +55,8 @@
 // Primitive Module methods.
 //
 
-Module::Module(const std::string &MID)
-  : ModuleID(MID), DataLayout("") {
+Module::Module(const std::string &MID, LLVMContext* C)
+  : Context(C), ModuleID(MID), DataLayout("")  {
   ValSymTab = new ValueSymbolTable();
   TypeSymTab = new TypeSymbolTable();
 }

Modified: llvm/trunk/tools/bugpoint/BugDriver.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/bugpoint/BugDriver.cpp?rev=74614&r1=74613&r2=74614&view=diff

==============================================================================
--- llvm/trunk/tools/bugpoint/BugDriver.cpp (original)
+++ llvm/trunk/tools/bugpoint/BugDriver.cpp Wed Jul  1 11:58:40 2009
@@ -64,24 +64,24 @@
 }
 
 BugDriver::BugDriver(const char *toolname, bool as_child, bool find_bugs,
-                     unsigned timeout, unsigned memlimit)
-  : ToolName(toolname), ReferenceOutputFile(OutputFile),
+                     unsigned timeout, unsigned memlimit, 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), MemoryLimit(memlimit) {}
+    run_as_child(as_child), run_find_bugs(find_bugs), Timeout(timeout), 
+    MemoryLimit(memlimit)  {}
 
 
 /// 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) {
+Module *llvm::ParseInputFile(const std::string &Filename, LLVMContext* Ctxt) {
   std::auto_ptr<MemoryBuffer> Buffer(MemoryBuffer::getFileOrSTDIN(Filename));
   Module *Result = 0;
   if (Buffer.get())
-    Result = ParseBitcodeFile(Buffer.get());
+    Result = ParseBitcodeFile(Buffer.get(), Ctxt);
   
   ParseError Err;
-  if (!Result && !(Result = ParseAssemblyFile(Filename, Err))) {
+  if (!Result && !(Result = ParseAssemblyFile(Filename, Err, Ctxt))) {
     Err.PrintError("bugpoint", errs()); 
     Result = 0;
   }
@@ -100,14 +100,14 @@
 
   try {
     // Load the first input file.
-    Program = ParseInputFile(Filenames[0]);
+    Program = ParseInputFile(Filenames[0], Context);
     if (Program == 0) return true;
     
     if (!run_as_child)
       std::cout << "Read input file      : '" << Filenames[0] << "'\n";
 
     for (unsigned i = 1, e = Filenames.size(); i != e; ++i) {
-      std::auto_ptr<Module> M(ParseInputFile(Filenames[i]));
+      std::auto_ptr<Module> M(ParseInputFile(Filenames[i], Context));
       if (M.get() == 0) return true;
 
       if (!run_as_child)

Modified: llvm/trunk/tools/bugpoint/BugDriver.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/bugpoint/BugDriver.h?rev=74614&r1=74613&r2=74614&view=diff

==============================================================================
--- llvm/trunk/tools/bugpoint/BugDriver.h (original)
+++ llvm/trunk/tools/bugpoint/BugDriver.h Wed Jul  1 11:58:40 2009
@@ -30,6 +30,7 @@
 class BasicBlock;
 class AbstractInterpreter;
 class Instruction;
+class LLVMContext;
 
 class DebugCrashes;
 
@@ -42,6 +43,7 @@
 extern bool BugpointIsInterrupted;
 
 class BugDriver {
+  LLVMContext* Context;
   const std::string ToolName;  // Name of bugpoint
   std::string ReferenceOutputFile; // Name of `good' output file
   Module *Program;             // The raw program, linked together
@@ -60,10 +62,12 @@
 
 public:
   BugDriver(const char *toolname, bool as_child, bool find_bugs,
-            unsigned timeout, unsigned memlimit);
+            unsigned timeout, unsigned memlimit, LLVMContext* ctxt);
 
   const std::string &getToolName() const { return ToolName; }
 
+  LLVMContext* getContext() { return Context; }
+
   // Set up methods... these methods are used to copy information about the
   // command line arguments into instance variables of BugDriver.
   //
@@ -290,7 +294,7 @@
 /// ParseInputFile - Given a bitcode or assembly input filename, parse and
 /// return it, or return null if not possible.
 ///
-Module *ParseInputFile(const std::string &InputFilename);
+Module *ParseInputFile(const std::string &InputFilename, LLVMContext* ctxt);
 
 
 /// getPassesString - Turn a list of passes into a string which indicates the

Modified: llvm/trunk/tools/bugpoint/CrashDebugger.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/bugpoint/CrashDebugger.cpp?rev=74614&r1=74613&r2=74614&view=diff

==============================================================================
--- llvm/trunk/tools/bugpoint/CrashDebugger.cpp (original)
+++ llvm/trunk/tools/bugpoint/CrashDebugger.cpp Wed Jul  1 11:58:40 2009
@@ -73,7 +73,7 @@
     PrefixOutput.set(PfxOutput);
     OrigProgram = BD.Program;
 
-    BD.Program = ParseInputFile(PrefixOutput.toString());
+    BD.Program = ParseInputFile(PrefixOutput.toString(), BD.getContext());
     if (BD.Program == 0) {
       std::cerr << BD.getToolName() << ": Error reading bitcode file '"
                 << PrefixOutput << "'!\n";

Modified: llvm/trunk/tools/bugpoint/Miscompilation.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/bugpoint/Miscompilation.cpp?rev=74614&r1=74613&r2=74614&view=diff

==============================================================================
--- llvm/trunk/tools/bugpoint/Miscompilation.cpp (original)
+++ llvm/trunk/tools/bugpoint/Miscompilation.cpp Wed Jul  1 11:58:40 2009
@@ -112,7 +112,7 @@
   // Ok, so now we know that the prefix passes work, try running the suffix
   // passes on the result of the prefix passes.
   //
-  Module *PrefixOutput = ParseInputFile(BitcodeResult);
+  Module *PrefixOutput = ParseInputFile(BitcodeResult, BD.getContext());
   if (PrefixOutput == 0) {
     std::cerr << BD.getToolName() << ": Error reading bitcode file '"
               << BitcodeResult << "'!\n";

Modified: llvm/trunk/tools/bugpoint/OptimizerDriver.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/bugpoint/OptimizerDriver.cpp?rev=74614&r1=74613&r2=74614&view=diff

==============================================================================
--- llvm/trunk/tools/bugpoint/OptimizerDriver.cpp (original)
+++ llvm/trunk/tools/bugpoint/OptimizerDriver.cpp Wed Jul  1 11:58:40 2009
@@ -255,7 +255,7 @@
   // Restore the current program.
   swapProgramIn(OldProgram);
 
-  Module *Ret = ParseInputFile(BitcodeResult);
+  Module *Ret = ParseInputFile(BitcodeResult, Context);
   if (Ret == 0) {
     cerr << getToolName() << ": Error reading bitcode file '"
          << BitcodeResult << "'!\n";

Modified: llvm/trunk/tools/bugpoint/bugpoint.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/bugpoint/bugpoint.cpp?rev=74614&r1=74613&r2=74614&view=diff

==============================================================================
--- llvm/trunk/tools/bugpoint/bugpoint.cpp (original)
+++ llvm/trunk/tools/bugpoint/bugpoint.cpp Wed Jul  1 11:58:40 2009
@@ -16,6 +16,7 @@
 #include "BugDriver.h"
 #include "ToolRunner.h"
 #include "llvm/LinkAllPasses.h"
+#include "llvm/LLVMContext.h"
 #include "llvm/Support/PassNameParser.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/ManagedStatic.h"
@@ -73,8 +74,9 @@
                               "llvm.org/cmds/bugpoint.html"
                               " for more information.\n");
   sys::SetInterruptFunction(BugpointInterruptFunction);
-  
-  BugDriver D(argv[0], AsChild, FindBugs, TimeoutValue, MemoryLimit);
+
+  LLVMContext Context;
+  BugDriver D(argv[0], AsChild, FindBugs, TimeoutValue, MemoryLimit, &Context);
   if (D.addSources(InputFilenames)) return 1;
   D.addPasses(PassList.begin(), PassList.end());
 

Modified: llvm/trunk/tools/llc/llc.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llc/llc.cpp?rev=74614&r1=74613&r2=74614&view=diff

==============================================================================
--- llvm/trunk/tools/llc/llc.cpp (original)
+++ llvm/trunk/tools/llc/llc.cpp Wed Jul  1 11:58:40 2009
@@ -22,6 +22,7 @@
 #include "llvm/Target/TargetMachine.h"
 #include "llvm/Target/TargetMachineRegistry.h"
 #include "llvm/Transforms/Scalar.h"
+#include "llvm/LLVMContext.h"
 #include "llvm/Module.h"
 #include "llvm/ModuleProvider.h"
 #include "llvm/PassManager.h"
@@ -212,6 +213,7 @@
 int main(int argc, char **argv) {
   sys::PrintStackTraceOnErrorSignal();
   PrettyStackTraceProgram X(argc, argv);
+  LLVMContext Context;
   llvm_shutdown_obj Y;  // Call llvm_shutdown() on exit.
   cl::ParseCommandLineOptions(argc, argv, "llvm system compiler\n");
 
@@ -225,7 +227,7 @@
   std::auto_ptr<MemoryBuffer> Buffer(
                    MemoryBuffer::getFileOrSTDIN(InputFilename, &ErrorMessage));
   if (Buffer.get())
-    M.reset(ParseBitcodeFile(Buffer.get(), &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";

Modified: llvm/trunk/tools/lli/lli.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/lli/lli.cpp?rev=74614&r1=74613&r2=74614&view=diff

==============================================================================
--- llvm/trunk/tools/lli/lli.cpp (original)
+++ llvm/trunk/tools/lli/lli.cpp Wed Jul  1 11:58:40 2009
@@ -13,6 +13,7 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "llvm/LLVMContext.h"
 #include "llvm/Module.h"
 #include "llvm/ModuleProvider.h"
 #include "llvm/Type.h"
@@ -93,6 +94,7 @@
   sys::PrintStackTraceOnErrorSignal();
   PrettyStackTraceProgram X(argc, argv);
   
+  LLVMContext Context;
   atexit(do_shutdown);  // Call llvm_shutdown() on exit.
   cl::ParseCommandLineOptions(argc, argv,
                               "llvm interpreter & dynamic compiler\n");
@@ -104,8 +106,8 @@
   // Load the bitcode...
   std::string ErrorMsg;
   ModuleProvider *MP = NULL;
-  if (MemoryBuffer *Buffer = MemoryBuffer::getFileOrSTDIN(InputFile,&ErrorMsg)) {
-    MP = getBitcodeModuleProvider(Buffer, &ErrorMsg);
+  if (MemoryBuffer *Buffer = MemoryBuffer::getFileOrSTDIN(InputFile,&ErrorMsg)){
+    MP = getBitcodeModuleProvider(Buffer, &Context, &ErrorMsg);
     if (!MP) delete Buffer;
   }
   

Modified: llvm/trunk/tools/llvm-ar/llvm-ar.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-ar/llvm-ar.cpp?rev=74614&r1=74613&r2=74614&view=diff

==============================================================================
--- llvm/trunk/tools/llvm-ar/llvm-ar.cpp (original)
+++ llvm/trunk/tools/llvm-ar/llvm-ar.cpp Wed Jul  1 11:58:40 2009
@@ -12,6 +12,7 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "llvm/LLVMContext.h"
 #include "llvm/Module.h"
 #include "llvm/Bitcode/Archive.h"
 #include "llvm/Support/CommandLine.h"
@@ -690,6 +691,7 @@
   // Print a stack trace if we signal out.
   sys::PrintStackTraceOnErrorSignal();
   PrettyStackTraceProgram X(argc, argv);
+  LLVMContext Context;
   llvm_shutdown_obj Y;  // Call llvm_shutdown() on exit.
 
   // Have the command line options parsed and handle things
@@ -717,11 +719,11 @@
       // 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);
+      TheArchive = Archive::CreateEmpty(ArchivePath, &Context);
       TheArchive->writeToDisk();
     } else {
       std::string Error;
-      TheArchive = Archive::OpenAndLoad(ArchivePath, &Error);
+      TheArchive = Archive::OpenAndLoad(ArchivePath, &Context, &Error);
       if (TheArchive == 0) {
         std::cerr << argv[0] << ": error loading '" << ArchivePath << "': "
                   << Error << "!\n";

Modified: llvm/trunk/tools/llvm-as/llvm-as.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-as/llvm-as.cpp?rev=74614&r1=74613&r2=74614&view=diff

==============================================================================
--- llvm/trunk/tools/llvm-as/llvm-as.cpp (original)
+++ llvm/trunk/tools/llvm-as/llvm-as.cpp Wed Jul  1 11:58:40 2009
@@ -15,6 +15,7 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "llvm/LLVMContext.h"
 #include "llvm/Module.h"
 #include "llvm/Assembly/Parser.h"
 #include "llvm/Analysis/Verifier.h"
@@ -55,6 +56,7 @@
   // Print a stack trace if we signal out.
   sys::PrintStackTraceOnErrorSignal();
   PrettyStackTraceProgram X(argc, argv);
+  LLVMContext Context;
   llvm_shutdown_obj Y;  // Call llvm_shutdown() on exit.
   cl::ParseCommandLineOptions(argc, argv, "llvm .ll -> .bc assembler\n");
 
@@ -63,7 +65,7 @@
   try {
     // Parse the file now...
     ParseError Err;
-    std::auto_ptr<Module> M(ParseAssemblyFile(InputFilename, Err));
+    std::auto_ptr<Module> M(ParseAssemblyFile(InputFilename, Err, &Context));
     if (M.get() == 0) {
       Err.PrintError(argv[0], errs());
       return 1;

Modified: llvm/trunk/tools/llvm-db/CLIDebugger.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-db/CLIDebugger.cpp?rev=74614&r1=74613&r2=74614&view=diff

==============================================================================
--- llvm/trunk/tools/llvm-db/CLIDebugger.cpp (original)
+++ llvm/trunk/tools/llvm-db/CLIDebugger.cpp Wed Jul  1 11:58:40 2009
@@ -22,8 +22,9 @@
 /// CLIDebugger constructor - This initializes the debugger to its default
 /// state, and initializes the command table.
 ///
-CLIDebugger::CLIDebugger()
-  : TheProgramInfo(0), TheRuntimeInfo(0), Prompt("(llvm-db) "), ListSize(10) {
+CLIDebugger::CLIDebugger(LLVMContext* ctxt)
+  : Context(ctxt), TheProgramInfo(0), TheRuntimeInfo(0),
+    Prompt("(llvm-db) "), ListSize(10) {
   // Initialize instance variables
   CurrentFile = 0;
   LineListedStart = 1;

Modified: llvm/trunk/tools/llvm-db/CLIDebugger.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-db/CLIDebugger.h?rev=74614&r1=74613&r2=74614&view=diff

==============================================================================
--- llvm/trunk/tools/llvm-db/CLIDebugger.h (original)
+++ llvm/trunk/tools/llvm-db/CLIDebugger.h Wed Jul  1 11:58:40 2009
@@ -24,10 +24,13 @@
   class SourceLanguage;
   class ProgramInfo;
   class RuntimeInfo;
+  class LLVMContext;
 
   /// CLIDebugger - This class implements the command line interface for the
   /// LLVM debugger.
   class CLIDebugger {
+    LLVMContext* Context;
+    
     /// Dbg - The low-level LLVM debugger object that we use to do our dirty
     /// work.
     Debugger Dbg;
@@ -79,7 +82,7 @@
     const SourceLanguage *CurrentLanguage;
 
   public:
-    CLIDebugger();
+    CLIDebugger(LLVMContext* ctxt);
 
     /// getDebugger - Return the current LLVM debugger implementation being
     /// used.

Modified: llvm/trunk/tools/llvm-db/Commands.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-db/Commands.cpp?rev=74614&r1=74613&r2=74614&view=diff

==============================================================================
--- llvm/trunk/tools/llvm-db/Commands.cpp (original)
+++ llvm/trunk/tools/llvm-db/Commands.cpp Wed Jul  1 11:58:40 2009
@@ -64,7 +64,7 @@
     TheProgramInfo = 0;
     CurrentFile = 0;
 
-    Dbg.loadProgram(Program.toString());
+    Dbg.loadProgram(Program.toString(), Context);
     TheProgramInfo = new ProgramInfo(Dbg.getProgram());
   }
 
@@ -244,7 +244,7 @@
     std::cout << "Unloaded program.\n";
   } else {
     std::cout << "Loading program... " << std::flush;
-    Dbg.loadProgram(Prog);
+    Dbg.loadProgram(Prog, Context);
     assert(Dbg.isProgramLoaded() &&
            "loadProgram succeeded, but not program loaded!");
     TheProgramInfo = new ProgramInfo(Dbg.getProgram());

Modified: llvm/trunk/tools/llvm-db/llvm-db.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-db/llvm-db.cpp?rev=74614&r1=74613&r2=74614&view=diff

==============================================================================
--- llvm/trunk/tools/llvm-db/llvm-db.cpp (original)
+++ llvm/trunk/tools/llvm-db/llvm-db.cpp Wed Jul  1 11:58:40 2009
@@ -13,6 +13,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "CLIDebugger.h"
+#include "llvm/LLVMContext.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/ManagedStatic.h"
 #include "llvm/Support/PrettyStackTrace.h"
@@ -54,6 +55,7 @@
   sys::PrintStackTraceOnErrorSignal();
   PrettyStackTraceProgram X(argc, argv);
   
+  LLVMContext Context;
   llvm_shutdown_obj Y;  // Call llvm_shutdown() on exit.
   std::cout << "NOTE: llvm-db is known useless right now.\n";
   try {
@@ -68,7 +70,7 @@
       InputArgs.push_back(InputFile);
 
     // Create the CLI debugger...
-    CLIDebugger D;
+    CLIDebugger D(&Context);
 
     // Initialize the debugger with the command line options we read...
     Debugger &Dbg = D.getDebugger();

Modified: llvm/trunk/tools/llvm-dis/llvm-dis.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-dis/llvm-dis.cpp?rev=74614&r1=74613&r2=74614&view=diff

==============================================================================
--- llvm/trunk/tools/llvm-dis/llvm-dis.cpp (original)
+++ llvm/trunk/tools/llvm-dis/llvm-dis.cpp Wed Jul  1 11:58:40 2009
@@ -16,6 +16,7 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "llvm/LLVMContext.h"
 #include "llvm/Module.h"
 #include "llvm/PassManager.h"
 #include "llvm/Bitcode/ReaderWriter.h"
@@ -50,6 +51,7 @@
   sys::PrintStackTraceOnErrorSignal();
   PrettyStackTraceProgram X(argc, argv);
   
+  LLVMContext Context;
   llvm_shutdown_obj Y;  // Call llvm_shutdown() on exit.
   try {
     cl::ParseCommandLineOptions(argc, argv, "llvm .bc -> .ll disassembler\n");
@@ -61,7 +63,7 @@
    
     if (MemoryBuffer *Buffer
            = MemoryBuffer::getFileOrSTDIN(InputFilename, &ErrorMessage)) {
-      M.reset(ParseBitcodeFile(Buffer, &ErrorMessage));
+      M.reset(ParseBitcodeFile(Buffer, &Context, &ErrorMessage));
       delete Buffer;
     }
 

Modified: llvm/trunk/tools/llvm-extract/llvm-extract.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-extract/llvm-extract.cpp?rev=74614&r1=74613&r2=74614&view=diff

==============================================================================
--- llvm/trunk/tools/llvm-extract/llvm-extract.cpp (original)
+++ llvm/trunk/tools/llvm-extract/llvm-extract.cpp Wed Jul  1 11:58:40 2009
@@ -12,6 +12,7 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "llvm/LLVMContext.h"
 #include "llvm/Module.h"
 #include "llvm/PassManager.h"
 #include "llvm/Bitcode/ReaderWriter.h"
@@ -60,7 +61,8 @@
   // Print a stack trace if we signal out.
   sys::PrintStackTraceOnErrorSignal();
   PrettyStackTraceProgram X(argc, argv);
-  
+
+  LLVMContext Context;
   llvm_shutdown_obj Y;  // Call llvm_shutdown() on exit.
   cl::ParseCommandLineOptions(argc, argv, "llvm extractor\n");
 
@@ -71,7 +73,7 @@
     cerr << argv[0] << ": Error reading file '" + InputFilename + "'\n";
     return 1;
   } else {
-    M.reset(ParseBitcodeFile(Buffer));
+    M.reset(ParseBitcodeFile(Buffer, &Context));
   }
   delete Buffer;
   

Modified: llvm/trunk/tools/llvm-ld/llvm-ld.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-ld/llvm-ld.cpp?rev=74614&r1=74613&r2=74614&view=diff

==============================================================================
--- llvm/trunk/tools/llvm-ld/llvm-ld.cpp (original)
+++ llvm/trunk/tools/llvm-ld/llvm-ld.cpp Wed Jul  1 11:58:40 2009
@@ -22,6 +22,7 @@
 
 #include "llvm/LinkAllVMCore.h"
 #include "llvm/Linker.h"
+#include "llvm/LLVMContext.h"
 #include "llvm/System/Program.h"
 #include "llvm/Module.h"
 #include "llvm/PassManager.h"
@@ -505,7 +506,8 @@
   // Print a stack trace if we signal out.
   sys::PrintStackTraceOnErrorSignal();
   PrettyStackTraceProgram X(argc, argv);
-  
+
+  LLVMContext Context;
   llvm_shutdown_obj Y;  // Call llvm_shutdown() on exit.
   try {
     // Initial global variable above for convenience printing of program name.
@@ -515,7 +517,7 @@
     cl::ParseCommandLineOptions(argc, argv, "llvm linker\n");
 
     // Construct a Linker (now that Verbose is set)
-    Linker TheLinker(progname, OutputFilename, Verbose);
+    Linker TheLinker(progname, OutputFilename, &Context, Verbose);
 
     // Keep track of the native link items (versus the bitcode items)
     Linker::ItemList NativeLinkItems;

Modified: llvm/trunk/tools/llvm-link/llvm-link.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-link/llvm-link.cpp?rev=74614&r1=74613&r2=74614&view=diff

==============================================================================
--- llvm/trunk/tools/llvm-link/llvm-link.cpp (original)
+++ llvm/trunk/tools/llvm-link/llvm-link.cpp Wed Jul  1 11:58:40 2009
@@ -13,6 +13,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "llvm/Linker.h"
+#include "llvm/LLVMContext.h"
 #include "llvm/Module.h"
 #include "llvm/Analysis/Verifier.h"
 #include "llvm/Bitcode/ReaderWriter.h"
@@ -47,7 +48,8 @@
 // LoadFile - Read the specified bitcode file in and return it.  This routine
 // searches the link path for the specified file to try to find it...
 //
-static inline std::auto_ptr<Module> LoadFile(const std::string &FN) {
+static inline std::auto_ptr<Module> LoadFile(const std::string &FN, 
+                                             LLVMContext* Context) {
   sys::Path Filename;
   if (!Filename.set(FN)) {
     cerr << "Invalid file name: '" << FN << "'\n";
@@ -62,7 +64,7 @@
     const std::string &FNStr = Filename.toString();
     if (MemoryBuffer *Buffer = MemoryBuffer::getFileOrSTDIN(FNStr,
                                                             &ErrorMessage)) {
-      Result = ParseBitcodeFile(Buffer, &ErrorMessage);
+      Result = ParseBitcodeFile(Buffer, Context, &ErrorMessage);
       delete Buffer;
     }
     if (Result) return std::auto_ptr<Module>(Result);   // Load successful!
@@ -84,13 +86,14 @@
   sys::PrintStackTraceOnErrorSignal();
   PrettyStackTraceProgram X(argc, argv);
   
+  LLVMContext Context;
   llvm_shutdown_obj Y;  // Call llvm_shutdown() on exit.
   cl::ParseCommandLineOptions(argc, argv, "llvm linker\n");
 
   unsigned BaseArg = 0;
   std::string ErrorMessage;
 
-  std::auto_ptr<Module> Composite(LoadFile(InputFilenames[BaseArg]));
+  std::auto_ptr<Module> Composite(LoadFile(InputFilenames[BaseArg], &Context));
   if (Composite.get() == 0) {
     cerr << argv[0] << ": error loading file '"
          << InputFilenames[BaseArg] << "'\n";
@@ -98,7 +101,7 @@
   }
 
   for (unsigned i = BaseArg+1; i < InputFilenames.size(); ++i) {
-    std::auto_ptr<Module> M(LoadFile(InputFilenames[i]));
+    std::auto_ptr<Module> M(LoadFile(InputFilenames[i], &Context));
     if (M.get() == 0) {
       cerr << argv[0] << ": error loading file '" <<InputFilenames[i]<< "'\n";
       return 1;

Modified: llvm/trunk/tools/llvm-nm/llvm-nm.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-nm/llvm-nm.cpp?rev=74614&r1=74613&r2=74614&view=diff

==============================================================================
--- llvm/trunk/tools/llvm-nm/llvm-nm.cpp (original)
+++ llvm/trunk/tools/llvm-nm/llvm-nm.cpp Wed Jul  1 11:58:40 2009
@@ -16,6 +16,7 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "llvm/LLVMContext.h"
 #include "llvm/Module.h"
 #include "llvm/Bitcode/ReaderWriter.h"
 #include "llvm/Bitcode/Archive.h"
@@ -132,6 +133,7 @@
 }
 
 static void DumpSymbolNamesFromFile(std::string &Filename) {
+  LLVMContext Context;
   std::string ErrorMessage;
   sys::Path aPath(Filename);
   // Note: Currently we do not support reading an archive from stdin.
@@ -140,7 +142,7 @@
                    MemoryBuffer::getFileOrSTDIN(Filename, &ErrorMessage));
     Module *Result = 0;
     if (Buffer.get())
-      Result = ParseBitcodeFile(Buffer.get(), &ErrorMessage);
+      Result = ParseBitcodeFile(Buffer.get(), &Context, &ErrorMessage);
     
     if (Result)
       DumpSymbolNamesFromModule(Result);
@@ -151,7 +153,8 @@
     
   } else if (aPath.isArchive()) {
     std::string ErrMsg;
-    Archive* archive = Archive::OpenAndLoad(sys::Path(Filename), &ErrorMessage);
+    Archive* archive = Archive::OpenAndLoad(sys::Path(Filename), &Context,
+                                            &ErrorMessage);
     if (!archive)
       std::cerr << ToolName << ": " << Filename << ": " << ErrorMessage << "\n";
     std::vector<Module *> Modules;

Modified: llvm/trunk/tools/llvm-prof/llvm-prof.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-prof/llvm-prof.cpp?rev=74614&r1=74613&r2=74614&view=diff

==============================================================================
--- llvm/trunk/tools/llvm-prof/llvm-prof.cpp (original)
+++ llvm/trunk/tools/llvm-prof/llvm-prof.cpp Wed Jul  1 11:58:40 2009
@@ -14,6 +14,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "llvm/InstrTypes.h"
+#include "llvm/LLVMContext.h"
 #include "llvm/Module.h"
 #include "llvm/Assembly/AsmAnnotationWriter.h"
 #include "llvm/Analysis/ProfileInfoLoader.h"
@@ -115,7 +116,8 @@
   // Print a stack trace if we signal out.
   sys::PrintStackTraceOnErrorSignal();
   PrettyStackTraceProgram X(argc, argv);
-  
+
+  LLVMContext Context;
   llvm_shutdown_obj Y;  // Call llvm_shutdown() on exit.
   try {
     cl::ParseCommandLineOptions(argc, argv, "llvm profile dump decoder\n");
@@ -125,7 +127,7 @@
     Module *M = 0;
     if (MemoryBuffer *Buffer = MemoryBuffer::getFileOrSTDIN(BitcodeFile,
                                                             &ErrorMessage)) {
-      M = ParseBitcodeFile(Buffer, &ErrorMessage);
+      M = ParseBitcodeFile(Buffer, &Context, &ErrorMessage);
       delete Buffer;
     }
     if (M == 0) {

Modified: llvm/trunk/tools/llvm-ranlib/llvm-ranlib.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-ranlib/llvm-ranlib.cpp?rev=74614&r1=74613&r2=74614&view=diff

==============================================================================
--- llvm/trunk/tools/llvm-ranlib/llvm-ranlib.cpp (original)
+++ llvm/trunk/tools/llvm-ranlib/llvm-ranlib.cpp Wed Jul  1 11:58:40 2009
@@ -11,6 +11,7 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "llvm/LLVMContext.h"
 #include "llvm/Module.h"
 #include "llvm/Bitcode/Archive.h"
 #include "llvm/Support/CommandLine.h"
@@ -46,7 +47,8 @@
   // Print a stack trace if we signal out.
   llvm::sys::PrintStackTraceOnErrorSignal();
   llvm::PrettyStackTraceProgram X(argc, argv);
-  
+
+  LLVMContext Context;
   llvm_shutdown_obj Y;  // Call llvm_shutdown() on exit.
 
   // Have the command line options parsed and handle things
@@ -73,7 +75,7 @@
 
     std::string err_msg;
     std::auto_ptr<Archive>
-      AutoArchive(Archive::OpenAndLoad(ArchivePath,&err_msg));
+      AutoArchive(Archive::OpenAndLoad(ArchivePath, &Context, &err_msg));
     Archive* TheArchive = AutoArchive.get();
     if (!TheArchive)
       throw err_msg;

Modified: llvm/trunk/tools/lto/LTOCodeGenerator.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/lto/LTOCodeGenerator.cpp?rev=74614&r1=74613&r2=74614&view=diff

==============================================================================
--- llvm/trunk/tools/lto/LTOCodeGenerator.cpp (original)
+++ llvm/trunk/tools/lto/LTOCodeGenerator.cpp Wed Jul  1 11:58:40 2009
@@ -70,7 +70,8 @@
 
 
 LTOCodeGenerator::LTOCodeGenerator() 
-    : _linker("LinkTimeOptimizer", "ld-temp.o"), _target(NULL),
+    : _context(new LLVMContext()),
+      _linker("LinkTimeOptimizer", "ld-temp.o", _context), _target(NULL),
       _emitDwarfDebugInfo(false), _scopeRestrictionsDone(false),
       _codeModel(LTO_CODEGEN_PIC_MODEL_DYNAMIC),
       _nativeObjectFile(NULL), _gccPath(NULL), _assemblerPath(NULL)

Modified: llvm/trunk/tools/lto/LTOCodeGenerator.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/lto/LTOCodeGenerator.h?rev=74614&r1=74613&r2=74614&view=diff

==============================================================================
--- llvm/trunk/tools/lto/LTOCodeGenerator.h (original)
+++ llvm/trunk/tools/lto/LTOCodeGenerator.h Wed Jul  1 11:58:40 2009
@@ -16,6 +16,7 @@
 #define LTO_CODE_GENERATOR_H
 
 #include "llvm/Linker.h"
+#include "llvm/LLVMContext.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/SmallVector.h"
 
@@ -53,6 +54,7 @@
     
     typedef llvm::StringMap<uint8_t> StringSet;
 
+    llvm::LLVMContext*          _context;
     llvm::Linker                _linker;
     llvm::TargetMachine*        _target;
     bool                        _emitDwarfDebugInfo;

Modified: llvm/trunk/tools/lto/LTOModule.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/lto/LTOModule.cpp?rev=74614&r1=74613&r2=74614&view=diff

==============================================================================
--- llvm/trunk/tools/lto/LTOModule.cpp (original)
+++ llvm/trunk/tools/lto/LTOModule.cpp Wed Jul  1 11:58:40 2009
@@ -15,6 +15,7 @@
 #include "LTOModule.h"
 
 #include "llvm/Constants.h"
+#include "llvm/LLVMContext.h"
 #include "llvm/Module.h"
 #include "llvm/ModuleProvider.h"
 #include "llvm/ADT/OwningPtr.h"
@@ -67,7 +68,8 @@
 // takes ownership of buffer
 bool LTOModule::isTargetMatch(MemoryBuffer* buffer, const char* triplePrefix)
 {
-    OwningPtr<ModuleProvider> mp(getBitcodeModuleProvider(buffer));
+    OwningPtr<ModuleProvider> mp(getBitcodeModuleProvider(buffer,
+                                                          new LLVMContext()));
     // on success, mp owns buffer and both are deleted at end of this method
     if ( !mp ) {
         delete buffer;
@@ -84,12 +86,13 @@
 {
 }
 
-LTOModule* LTOModule::makeLTOModule(const char* path, std::string& errMsg)
+LTOModule* LTOModule::makeLTOModule(const char* path, LLVMContext* Context,
+                                    std::string& errMsg)
 {
     OwningPtr<MemoryBuffer> buffer(MemoryBuffer::getFile(path, &errMsg));
     if ( !buffer )
         return NULL;
-    return makeLTOModule(buffer.get(), errMsg);
+    return makeLTOModule(buffer.get(), Context, errMsg);
 }
 
 /// makeBuffer - create a MemoryBuffer from a memory range.
@@ -109,12 +112,13 @@
 
 
 LTOModule* LTOModule::makeLTOModule(const void* mem, size_t length, 
+                                    LLVMContext* Context,
                                     std::string& errMsg)
 {
     OwningPtr<MemoryBuffer> buffer(makeBuffer(mem, length));
     if ( !buffer )
         return NULL;
-    return makeLTOModule(buffer.get(), errMsg);
+    return makeLTOModule(buffer.get(), Context, errMsg);
 }
 
 /// getFeatureString - Return a string listing the features associated with the
@@ -136,10 +140,11 @@
   return Features.getString();
 }
 
-LTOModule* LTOModule::makeLTOModule(MemoryBuffer* buffer, std::string& errMsg)
+LTOModule* LTOModule::makeLTOModule(MemoryBuffer* buffer, LLVMContext* Context,
+                                    std::string& errMsg)
 {
     // parse bitcode buffer
-    OwningPtr<Module> m(ParseBitcodeFile(buffer, &errMsg));
+    OwningPtr<Module> m(ParseBitcodeFile(buffer, Context, &errMsg));
     if ( !m )
         return NULL;
     // find machine architecture for this module

Modified: llvm/trunk/tools/lto/LTOModule.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/lto/LTOModule.h?rev=74614&r1=74613&r2=74614&view=diff

==============================================================================
--- llvm/trunk/tools/lto/LTOModule.h (original)
+++ llvm/trunk/tools/lto/LTOModule.h Wed Jul  1 11:58:40 2009
@@ -32,6 +32,7 @@
     class GlobalValue;
     class Value;
     class Function;
+    class LLVMContext;
 }
 
 
@@ -50,9 +51,12 @@
     static bool              isBitcodeFileForTarget(const char* path, 
                                                     const char* triplePrefix);
 
-    static LTOModule*        makeLTOModule(const char* path, std::string& errMsg);
+    static LTOModule*        makeLTOModule(const char* path,
+                                          llvm::LLVMContext* Context,
+                                          std::string& errMsg);
     static LTOModule*        makeLTOModule(const void* mem, size_t length,
-                                                            std::string& errMsg);
+                                           llvm::LLVMContext* Context,
+                                           std::string& errMsg);
 
     const char*              getTargetTriple();
     uint32_t                 getSymbolCount();
@@ -83,10 +87,11 @@
     bool                    objcClassNameFromExpression(llvm::Constant* c, 
                                                     std::string& name);
 
-    static bool             isTargetMatch(llvm::MemoryBuffer* memBuffer, 
+    static bool             isTargetMatch(llvm::MemoryBuffer* memBuffer,
                                                     const char* triplePrefix);
 
-    static LTOModule*       makeLTOModule(llvm::MemoryBuffer* buffer, 
+    static LTOModule*       makeLTOModule(llvm::MemoryBuffer* buffer,
+                                          llvm::LLVMContext* Context,
                                                         std::string& errMsg);
     static llvm::MemoryBuffer* makeBuffer(const void* mem, size_t length);
 

Modified: llvm/trunk/tools/lto/lto.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/lto/lto.cpp?rev=74614&r1=74613&r2=74614&view=diff

==============================================================================
--- llvm/trunk/tools/lto/lto.cpp (original)
+++ llvm/trunk/tools/lto/lto.cpp Wed Jul  1 11:58:40 2009
@@ -13,6 +13,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "llvm-c/lto.h"
+#include "llvm-c/Core.h"
 
 #include "LTOModule.h"
 #include "LTOCodeGenerator.h"
@@ -85,9 +86,10 @@
 // loads an object file from disk  
 // returns NULL on error (check lto_get_error_message() for details)
 //
-lto_module_t lto_module_create(const char* path)
+lto_module_t lto_module_create(const char* path, LLVMContextRef Ctxt)
 {
-     return LTOModule::makeLTOModule(path, sLastErrorString);
+     return LTOModule::makeLTOModule(path, llvm::unwrap(Ctxt), 
+                                     sLastErrorString);
 }
 
 
@@ -95,9 +97,11 @@
 // loads an object file from memory 
 // returns NULL on error (check lto_get_error_message() for details)
 //
-lto_module_t lto_module_create_from_memory(const void* mem, size_t length)
+lto_module_t lto_module_create_from_memory(const void* mem, size_t length,
+                                           LLVMContextRef Ctxt)
 {
-     return LTOModule::makeLTOModule(mem, length, sLastErrorString);
+     return LTOModule::makeLTOModule(mem, length, llvm::unwrap(Ctxt),
+                                     sLastErrorString);
 }
 
 

Modified: llvm/trunk/tools/opt/opt.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/opt/opt.cpp?rev=74614&r1=74613&r2=74614&view=diff

==============================================================================
--- llvm/trunk/tools/opt/opt.cpp (original)
+++ llvm/trunk/tools/opt/opt.cpp Wed Jul  1 11:58:40 2009
@@ -12,6 +12,7 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "llvm/LLVMContext.h"
 #include "llvm/Module.h"
 #include "llvm/ModuleProvider.h"
 #include "llvm/PassManager.h"
@@ -310,6 +311,7 @@
 //
 int main(int argc, char **argv) {
   llvm_shutdown_obj X;  // Call llvm_shutdown() on exit.
+  LLVMContext Context;
   try {
     cl::ParseCommandLineOptions(argc, argv,
       "llvm .bc -> .bc modular optimizer and analysis printer\n");
@@ -325,7 +327,7 @@
     std::auto_ptr<Module> M;
     if (MemoryBuffer *Buffer
           = MemoryBuffer::getFileOrSTDIN(InputFilename, &ErrorMessage)) {
-      M.reset(ParseBitcodeFile(Buffer, &ErrorMessage));
+      M.reset(ParseBitcodeFile(Buffer, &Context, &ErrorMessage));
       delete Buffer;
     }
     





More information about the llvm-commits mailing list