summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--examples/BrainF/BrainF.cpp9
-rw-r--r--examples/BrainF/BrainF.h5
-rw-r--r--examples/BrainF/BrainFDriver.cpp4
-rw-r--r--examples/Fibonacci/fibonacci.cpp5
-rw-r--r--examples/HowToUseJIT/HowToUseJIT.cpp5
-rw-r--r--examples/Kaleidoscope/toy.cpp4
-rw-r--r--examples/ModuleMaker/ModuleMaker.cpp5
-rw-r--r--examples/ParallelJIT/ParallelJIT.cpp4
-rw-r--r--include/llvm-c/BitReader.h3
-rw-r--r--include/llvm-c/Core.h10
-rw-r--r--include/llvm/Assembly/Parser.h7
-rw-r--r--include/llvm/Bitcode/Archive.h9
-rw-r--r--include/llvm/Bitcode/ReaderWriter.h5
-rw-r--r--include/llvm/Debugger/Debugger.h3
-rw-r--r--include/llvm/LinkAllVMCore.h2
-rw-r--r--include/llvm/Linker.h3
-rw-r--r--include/llvm/Module.h9
-rw-r--r--include/llvm/Transforms/Utils/Cloning.h1
-rw-r--r--lib/Archive/Archive.cpp10
-rw-r--r--lib/Archive/ArchiveInternals.h4
-rw-r--r--lib/Archive/ArchiveReader.cpp23
-rw-r--r--lib/Archive/ArchiveWriter.cpp7
-rw-r--r--lib/AsmParser/Parser.cpp9
-rw-r--r--lib/Bitcode/Reader/BitReader.cpp9
-rw-r--r--lib/Bitcode/Reader/BitcodeReader.cpp11
-rw-r--r--lib/Bitcode/Reader/BitcodeReader.h6
-rw-r--r--lib/Debugger/Debugger.cpp16
-rw-r--r--lib/Linker/LinkArchives.cpp2
-rw-r--r--lib/Linker/LinkItems.cpp2
-rw-r--r--lib/Linker/Linker.cpp35
-rw-r--r--lib/Transforms/Utils/CloneModule.cpp2
-rw-r--r--lib/VMCore/Core.cpp16
-rw-r--r--lib/VMCore/Module.cpp5
-rw-r--r--tools/bugpoint/BugDriver.cpp18
-rw-r--r--tools/bugpoint/BugDriver.h8
-rw-r--r--tools/bugpoint/CrashDebugger.cpp2
-rw-r--r--tools/bugpoint/Miscompilation.cpp2
-rw-r--r--tools/bugpoint/OptimizerDriver.cpp2
-rw-r--r--tools/bugpoint/bugpoint.cpp6
-rw-r--r--tools/llc/llc.cpp4
-rw-r--r--tools/lli/lli.cpp6
-rw-r--r--tools/llvm-ar/llvm-ar.cpp6
-rw-r--r--tools/llvm-as/llvm-as.cpp4
-rw-r--r--tools/llvm-db/CLIDebugger.cpp5
-rw-r--r--tools/llvm-db/CLIDebugger.h5
-rw-r--r--tools/llvm-db/Commands.cpp4
-rw-r--r--tools/llvm-db/llvm-db.cpp4
-rw-r--r--tools/llvm-dis/llvm-dis.cpp4
-rw-r--r--tools/llvm-extract/llvm-extract.cpp6
-rw-r--r--tools/llvm-ld/llvm-ld.cpp6
-rw-r--r--tools/llvm-link/llvm-link.cpp11
-rw-r--r--tools/llvm-nm/llvm-nm.cpp7
-rw-r--r--tools/llvm-prof/llvm-prof.cpp6
-rw-r--r--tools/llvm-ranlib/llvm-ranlib.cpp6
-rw-r--r--tools/lto/LTOCodeGenerator.cpp3
-rw-r--r--tools/lto/LTOCodeGenerator.h2
-rw-r--r--tools/lto/LTOModule.cpp17
-rw-r--r--tools/lto/LTOModule.h13
-rw-r--r--tools/lto/lto.cpp12
-rw-r--r--tools/opt/opt.cpp4
60 files changed, 277 insertions, 146 deletions
diff --git a/examples/BrainF/BrainF.cpp b/examples/BrainF/BrainF.cpp
index 32a14c4d532..0caff13e81e 100644
--- a/examples/BrainF/BrainF.cpp
+++ b/examples/BrainF/BrainF.cpp
@@ -36,19 +36,20 @@ const char *BrainF::headreg = "head";
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
diff --git a/examples/BrainF/BrainF.h b/examples/BrainF/BrainF.h
index 06c00ae4df2..d0fb1b1de0e 100644
--- a/examples/BrainF/BrainF.h
+++ b/examples/BrainF/BrainF.h
@@ -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 @@ class BrainF {
/// 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 @@ class BrainF {
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 "[]".
diff --git a/examples/BrainF/BrainFDriver.cpp b/examples/BrainF/BrainFDriver.cpp
index 06e77d2e2a3..0868d735066 100644
--- a/examples/BrainF/BrainFDriver.cpp
+++ b/examples/BrainF/BrainFDriver.cpp
@@ -86,6 +86,8 @@ void addMainFunction(Module *mod) {
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 @@ int main(int argc, char **argv) {
//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);
diff --git a/examples/Fibonacci/fibonacci.cpp b/examples/Fibonacci/fibonacci.cpp
index 09f2203c68f..58c0dcdaf5c 100644
--- a/examples/Fibonacci/fibonacci.cpp
+++ b/examples/Fibonacci/fibonacci.cpp
@@ -23,6 +23,7 @@
//
//===----------------------------------------------------------------------===//
+#include "llvm/LLVMContext.h"
#include "llvm/Module.h"
#include "llvm/DerivedTypes.h"
#include "llvm/Constants.h"
@@ -90,8 +91,10 @@ static Function *CreateFibFunction(Module *M) {
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);
diff --git a/examples/HowToUseJIT/HowToUseJIT.cpp b/examples/HowToUseJIT/HowToUseJIT.cpp
index a9f10009e1e..f11c3e256e6 100644
--- a/examples/HowToUseJIT/HowToUseJIT.cpp
+++ b/examples/HowToUseJIT/HowToUseJIT.cpp
@@ -34,6 +34,7 @@
//
//===----------------------------------------------------------------------===//
+#include "llvm/LLVMContext.h"
#include "llvm/Module.h"
#include "llvm/Constants.h"
#include "llvm/DerivedTypes.h"
@@ -50,9 +51,11 @@ using namespace llvm;
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".
diff --git a/examples/Kaleidoscope/toy.cpp b/examples/Kaleidoscope/toy.cpp
index c75014a69ba..9ca6035156c 100644
--- a/examples/Kaleidoscope/toy.cpp
+++ b/examples/Kaleidoscope/toy.cpp
@@ -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 @@ double printd(double X) {
int main() {
InitializeNativeTarget();
+ LLVMContext Context;
// Install standard binary operators.
// 1 is lowest precedence.
@@ -1097,7 +1099,7 @@ int main() {
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);
diff --git a/examples/ModuleMaker/ModuleMaker.cpp b/examples/ModuleMaker/ModuleMaker.cpp
index e2584e7ff34..322835e04f2 100644
--- a/examples/ModuleMaker/ModuleMaker.cpp
+++ b/examples/ModuleMaker/ModuleMaker.cpp
@@ -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);
diff --git a/examples/ParallelJIT/ParallelJIT.cpp b/examples/ParallelJIT/ParallelJIT.cpp
index a6d7dcf7b55..858cd52de6a 100644
--- a/examples/ParallelJIT/ParallelJIT.cpp
+++ b/examples/ParallelJIT/ParallelJIT.cpp
@@ -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 @@ void* callFunc( void* param )
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 );
diff --git a/include/llvm-c/BitReader.h b/include/llvm-c/BitReader.h
index e30b431d887..4284d7d2372 100644
--- a/include/llvm-c/BitReader.h
+++ b/include/llvm-c/BitReader.h
@@ -29,13 +29,14 @@ extern "C" {
/* 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);
diff --git a/include/llvm-c/Core.h b/include/llvm-c/Core.h
index d2d88454d71..7019b4cc660 100644
--- a/include/llvm-c/Core.h
+++ b/include/llvm-c/Core.h
@@ -47,6 +47,11 @@ extern "C" {
/* 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 @@ void LLVMDisposeMessage(char *Message);
/*===-- 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 @@ namespace llvm {
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
diff --git a/include/llvm/Assembly/Parser.h b/include/llvm/Assembly/Parser.h
index e4a38e41b67..2a5bac7a704 100644
--- a/include/llvm/Assembly/Parser.h
+++ b/include/llvm/Assembly/Parser.h
@@ -21,6 +21,7 @@ namespace llvm {
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 @@ class raw_ostream;
/// @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 *ParseAssemblyFile(
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
);
//===------------------------------------------------------------------------===
diff --git a/include/llvm/Bitcode/Archive.h b/include/llvm/Bitcode/Archive.h
index a3631ace545..c188df88241 100644
--- a/include/llvm/Bitcode/Archive.h
+++ b/include/llvm/Bitcode/Archive.h
@@ -32,6 +32,7 @@ class ModuleProvider; // From VMCore
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 @@ class Archive {
/// @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 @@ class Archive {
/// @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 @@ class Archive {
/// @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 @@ class Archive {
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 @@ class Archive {
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
/// @{
diff --git a/include/llvm/Bitcode/ReaderWriter.h b/include/llvm/Bitcode/ReaderWriter.h
index abdd5d3d8b1..a7811876ff6 100644
--- a/include/llvm/Bitcode/ReaderWriter.h
+++ b/include/llvm/Bitcode/ReaderWriter.h
@@ -23,6 +23,7 @@ namespace llvm {
class MemoryBuffer;
class ModulePass;
class BitstreamWriter;
+ class LLVMContext;
class raw_ostream;
/// getBitcodeModuleProvider - Read the header of the specified bitcode buffer
@@ -31,12 +32,14 @@ namespace llvm {
/// 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.
diff --git a/include/llvm/Debugger/Debugger.h b/include/llvm/Debugger/Debugger.h
index 5b0b97addf4..ed04ed533ad 100644
--- a/include/llvm/Debugger/Debugger.h
+++ b/include/llvm/Debugger/Debugger.h
@@ -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 @@ namespace llvm {
/// 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
diff --git a/include/llvm/LinkAllVMCore.h b/include/llvm/LinkAllVMCore.h
index 4c428a00631..3c4b9c447b9 100644
--- a/include/llvm/LinkAllVMCore.h
+++ b/include/llvm/LinkAllVMCore.h
@@ -44,7 +44,7 @@ namespace {
// 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,"");
diff --git a/include/llvm/Linker.h b/include/llvm/Linker.h
index 884e872602b..8389dc770ef 100644
--- a/include/llvm/Linker.h
+++ b/include/llvm/Linker.h
@@ -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 @@ class Linker {
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 @@ class Linker {
/// @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.
diff --git a/include/llvm/Module.h b/include/llvm/Module.h
index 9c8607a188a..8370ffb872c 100644
--- a/include/llvm/Module.h
+++ b/include/llvm/Module.h
@@ -25,6 +25,7 @@ namespace llvm {
class GlobalValueRefMap; // Used by ConstantVals.cpp
class FunctionType;
+class LLVMContext;
template<> struct ilist_traits<Function>
: public SymbolTableListTraits<Function, Module> {
@@ -109,6 +110,8 @@ public:
/// @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 @@ private:
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 @@ public:
/// @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; }
diff --git a/include/llvm/Transforms/Utils/Cloning.h b/include/llvm/Transforms/Utils/Cloning.h
index 1e2bbaa295b..840d9708cba 100644
--- a/include/llvm/Transforms/Utils/Cloning.h
+++ b/include/llvm/Transforms/Utils/Cloning.h
@@ -37,6 +37,7 @@ class Trace;
class CallGraph;
class TargetData;
class LoopInfo;
+class LLVMContext;
template<class N> class LoopBase;
typedef LoopBase<BasicBlock> Loop;
diff --git a/lib/Archive/Archive.cpp b/lib/Archive/Archive.cpp
index c6c89d27dbb..e6903b607fb 100644
--- a/lib/Archive/Archive.cpp
+++ b/lib/Archive/Archive.cpp
@@ -138,9 +138,9 @@ bool ArchiveMember::replaceWith(const sys::Path& newFile, std::string* ErrMsg) {
// 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 @@ static void getSymbols(Module*M, std::vector<std::string>& symbols) {
// 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 @@ bool llvm::GetBitcodeSymbols(const sys::Path& fName,
return true;
}
- ModuleProvider *MP = getBitcodeModuleProvider(Buffer.get(), ErrMsg);
+ ModuleProvider *MP = getBitcodeModuleProvider(Buffer.get(), Context, ErrMsg);
if (!MP)
return true;
@@ -239,13 +240,14 @@ bool llvm::GetBitcodeSymbols(const sys::Path& fName,
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;
diff --git a/lib/Archive/ArchiveInternals.h b/lib/Archive/ArchiveInternals.h
index 7ba30244a21..cdd8e35ca0d 100644
--- a/lib/Archive/ArchiveInternals.h
+++ b/lib/Archive/ArchiveInternals.h
@@ -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 @@ namespace llvm {
// 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);
}
diff --git a/lib/Archive/ArchiveReader.cpp b/lib/Archive/ArchiveReader.cpp
index b07e884b654..4e3e28166ca 100644
--- a/lib/Archive/ArchiveReader.cpp
+++ b/lib/Archive/ArchiveReader.cpp
@@ -327,9 +327,9 @@ Archive::loadArchive(std::string* error) {
// 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 @@ Archive::OpenAndLoad(const sys::Path& file, std::string* ErrorMessage)
// 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 @@ Archive::getAllModules(std::vector<Module*>& Modules, std::string* ErrMessage) {
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 @@ Archive::loadSymbolTable(std::string* ErrorMsg) {
}
// 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 @@ Archive::findModuleDefiningSymbol(const std::string& symbol,
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 @@ Archive::findModulesDefiningSymbols(std::set<std::string>& symbols,
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 @@ bool Archive::isBitcodeArchive() {
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.
diff --git a/lib/Archive/ArchiveWriter.cpp b/lib/Archive/ArchiveWriter.cpp
index cebb0877457..641e3324d63 100644
--- a/lib/Archive/ArchiveWriter.cpp
+++ b/lib/Archive/ArchiveWriter.cpp
@@ -64,9 +64,8 @@ static inline unsigned numVbrBytes(unsigned num) {
}
// 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 @@ Archive::writeMember(
+ ")";
ModuleProvider* MP =
GetBitcodeSymbols((const unsigned char*)data,fSize,
- FullMemberName, symbols, ErrMsg);
+ FullMemberName, Context, symbols, ErrMsg);
// If the bitcode parsed successfully
if ( MP ) {
diff --git a/lib/AsmParser/Parser.cpp b/lib/AsmParser/Parser.cpp
index 759e00e3217..7759c70d73d 100644
--- a/lib/AsmParser/Parser.cpp
+++ b/lib/AsmParser/Parser.cpp
@@ -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 @@ Module *llvm::ParseAssemblyFile(const std::string &Filename, ParseError &Err) {
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 @@ Module *llvm::ParseAssemblyString(const char *AsmString, Module *M,
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();
diff --git a/lib/Bitcode/Reader/BitReader.cpp b/lib/Bitcode/Reader/BitReader.cpp
index 52851cd142d..2baf71bb541 100644
--- a/lib/Bitcode/Reader/BitReader.cpp
+++ b/lib/Bitcode/Reader/BitReader.cpp
@@ -18,11 +18,12 @@ using namespace llvm;
/* 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 @@ int LLVMParseBitcode(LLVMMemoryBufferRef MemBuf,
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());
diff --git a/lib/Bitcode/Reader/BitcodeReader.cpp b/lib/Bitcode/Reader/BitcodeReader.cpp
index 6b9606c5d14..7cf03242990 100644
--- a/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -1087,7 +1087,7 @@ bool BitcodeReader::ParseModule(const std::string &ModuleID) {
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 @@ Module *BitcodeReader::releaseModule(std::string *ErrInfo) {
/// 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 @@ ModuleProvider *llvm::getBitcodeModuleProvider(MemoryBuffer *Buffer,
/// 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.
diff --git a/lib/Bitcode/Reader/BitcodeReader.h b/lib/Bitcode/Reader/BitcodeReader.h
index 0dc470b24a2..498a34ae01b 100644
--- a/lib/Bitcode/Reader/BitcodeReader.h
+++ b/lib/Bitcode/Reader/BitcodeReader.h
@@ -26,6 +26,7 @@
namespace llvm {
class MemoryBuffer;
+ class LLVMContext;
//===----------------------------------------------------------------------===//
// BitcodeReaderValueList Class
@@ -85,6 +86,7 @@ public:
};
class BitcodeReader : public ModuleProvider {
+ LLVMContext* Context;
MemoryBuffer *Buffer;
BitstreamReader StreamFile;
BitstreamCursor Stream;
@@ -123,8 +125,8 @@ class BitcodeReader : public ModuleProvider {
/// 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() {
diff --git a/lib/Debugger/Debugger.cpp b/lib/Debugger/Debugger.cpp
index b12d90ac9db..dbfbbed1dc5 100644
--- a/lib/Debugger/Debugger.cpp
+++ b/lib/Debugger/Debugger.cpp
@@ -46,11 +46,11 @@ std::string Debugger::getProgramPath() const {
}
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 @@ getMaterializedModuleProvider(const std::string &Filename) {
/// 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 @@ void Debugger::loadProgram(const std::string &Filename) {
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, ":");
diff --git a/lib/Linker/LinkArchives.cpp b/lib/Linker/LinkArchives.cpp
index 551cc8c390d..faf01af127e 100644
--- a/lib/Linker/LinkArchives.cpp
+++ b/lib/Linker/LinkArchives.cpp
@@ -115,7 +115,7 @@ Linker::LinkInArchive(const sys::Path &Filename, bool &is_native) {
std::string ErrMsg;
std::auto_ptr<Archive> AutoArch (
- Archive::OpenAndLoadSymbols(Filename,&ErrMsg));
+ Archive::OpenAndLoadSymbols(Filename, Context, &ErrMsg));
Archive* arch = AutoArch.get();
diff --git a/lib/Linker/LinkItems.cpp b/lib/Linker/LinkItems.cpp
index 7c888aa498a..dc0f7c17bf4 100644
--- a/lib/Linker/LinkItems.cpp
+++ b/lib/Linker/LinkItems.cpp
@@ -160,7 +160,7 @@ bool Linker::LinkInFile(const sys::Path &File, bool &is_native) {
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))
diff --git a/lib/Linker/Linker.cpp b/lib/Linker/Linker.cpp
index d6737721d25..d0d69d072c1 100644
--- a/lib/Linker/Linker.cpp
+++ b/lib/Linker/Linker.cpp
@@ -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 @@ Linker::LoadObject(const sys::Path &FN) {
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 + "'";
diff --git a/lib/Transforms/Utils/CloneModule.cpp b/lib/Transforms/Utils/CloneModule.cpp
index 337fa8a44bb..82f5b93a954 100644
--- a/lib/Transforms/Utils/CloneModule.cpp
+++ b/lib/Transforms/Utils/CloneModule.cpp
@@ -35,7 +35,7 @@ Module *llvm::CloneModule(const Module *M) {
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());
diff --git a/lib/VMCore/Core.cpp b/lib/VMCore/Core.cpp
index f85dbe76119..1c0a8f7af25 100644
--- a/lib/VMCore/Core.cpp
+++ b/lib/VMCore/Core.cpp
@@ -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 @@ void LLVMDisposeMessage(char *Message) {
}
+/*===-- 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) {
diff --git a/lib/VMCore/Module.cpp b/lib/VMCore/Module.cpp
index a598005e2a8..96a25a5d0d2 100644
--- a/lib/VMCore/Module.cpp
+++ b/lib/VMCore/Module.cpp
@@ -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 @@ template class SymbolTableListTraits<GlobalAlias, Module>;
// 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();
}
diff --git a/tools/bugpoint/BugDriver.cpp b/tools/bugpoint/BugDriver.cpp
index d050b59ed77..340522a4437 100644
--- a/tools/bugpoint/BugDriver.cpp
+++ b/tools/bugpoint/BugDriver.cpp
@@ -64,24 +64,24 @@ std::string llvm::getPassesString(const std::vector<const PassInfo*> &Passes) {
}
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 @@ bool BugDriver::addSources(const std::vector<std::string> &Filenames) {
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)
diff --git a/tools/bugpoint/BugDriver.h b/tools/bugpoint/BugDriver.h
index 96e9fb98017..4c81cc2a2b6 100644
--- a/tools/bugpoint/BugDriver.h
+++ b/tools/bugpoint/BugDriver.h
@@ -30,6 +30,7 @@ class Function;
class BasicBlock;
class AbstractInterpreter;
class Instruction;
+class LLVMContext;
class DebugCrashes;
@@ -42,6 +43,7 @@ extern bool DisableSimplifyCFG;
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 @@ class BugDriver {
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 @@ 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);
+Module *ParseInputFile(const std::string &InputFilename, LLVMContext* ctxt);
/// getPassesString - Turn a list of passes into a string which indicates the
diff --git a/tools/bugpoint/CrashDebugger.cpp b/tools/bugpoint/CrashDebugger.cpp
index 7daf57c9158..9697b341f3a 100644
--- a/tools/bugpoint/CrashDebugger.cpp
+++ b/tools/bugpoint/CrashDebugger.cpp
@@ -73,7 +73,7 @@ ReducePassList::doTest(std::vector<const PassInfo*> &Prefix,
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";
diff --git a/tools/bugpoint/Miscompilation.cpp b/tools/bugpoint/Miscompilation.cpp
index 7e8ff78a9cf..b3260e13606 100644
--- a/tools/bugpoint/Miscompilation.cpp
+++ b/tools/bugpoint/Miscompilation.cpp
@@ -112,7 +112,7 @@ ReduceMiscompilingPasses::doTest(std::vector<const PassInfo*> &Prefix,
// 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";
diff --git a/tools/bugpoint/OptimizerDriver.cpp b/tools/bugpoint/OptimizerDriver.cpp
index 3ded5e866b3..741be24adef 100644
--- a/tools/bugpoint/OptimizerDriver.cpp
+++ b/tools/bugpoint/OptimizerDriver.cpp
@@ -255,7 +255,7 @@ Module *BugDriver::runPassesOn(Module *M,
// 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";
diff --git a/tools/bugpoint/bugpoint.cpp b/tools/bugpoint/bugpoint.cpp
index 20f0e99a848..57007e035c4 100644
--- a/tools/bugpoint/bugpoint.cpp
+++ b/tools/bugpoint/bugpoint.cpp
@@ -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 @@ int main(int argc, char **argv) {
"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());
diff --git a/tools/llc/llc.cpp b/tools/llc/llc.cpp
index e71b3783236..d0d88c505f7 100644
--- a/tools/llc/llc.cpp
+++ b/tools/llc/llc.cpp
@@ -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 @@ static raw_ostream *GetOutputStream(const char *ProgName) {
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 @@ int main(int argc, char **argv) {
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";
diff --git a/tools/lli/lli.cpp b/tools/lli/lli.cpp
index 25536746dad..10b86382a45 100644
--- a/tools/lli/lli.cpp
+++ b/tools/lli/lli.cpp
@@ -13,6 +13,7 @@
//
//===----------------------------------------------------------------------===//
+#include "llvm/LLVMContext.h"
#include "llvm/Module.h"
#include "llvm/ModuleProvider.h"
#include "llvm/Type.h"
@@ -93,6 +94,7 @@ int main(int argc, char **argv, char * const *envp) {
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 @@ int main(int argc, char **argv, char * const *envp) {
// 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;
}
diff --git a/tools/llvm-ar/llvm-ar.cpp b/tools/llvm-ar/llvm-ar.cpp
index 5d81fc7cf38..960f8e371b8 100644
--- a/tools/llvm-ar/llvm-ar.cpp
+++ b/tools/llvm-ar/llvm-ar.cpp
@@ -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 @@ int main(int argc, char **argv) {
// 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 @@ 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);
+ 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";
diff --git a/tools/llvm-as/llvm-as.cpp b/tools/llvm-as/llvm-as.cpp
index 79ece8f106f..06798cbd28a 100644
--- a/tools/llvm-as/llvm-as.cpp
+++ b/tools/llvm-as/llvm-as.cpp
@@ -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 @@ int main(int argc, char **argv) {
// 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 @@ int main(int argc, char **argv) {
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;
diff --git a/tools/llvm-db/CLIDebugger.cpp b/tools/llvm-db/CLIDebugger.cpp
index 1d2a8387a9c..c7aedd1006e 100644
--- a/tools/llvm-db/CLIDebugger.cpp
+++ b/tools/llvm-db/CLIDebugger.cpp
@@ -22,8 +22,9 @@ using namespace llvm;
/// 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;
diff --git a/tools/llvm-db/CLIDebugger.h b/tools/llvm-db/CLIDebugger.h
index 56ea14dfbcf..b1a31a4d91d 100644
--- a/tools/llvm-db/CLIDebugger.h
+++ b/tools/llvm-db/CLIDebugger.h
@@ -24,10 +24,13 @@ namespace llvm {
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 @@ namespace llvm {
const SourceLanguage *CurrentLanguage;
public:
- CLIDebugger();
+ CLIDebugger(LLVMContext* ctxt);
/// getDebugger - Return the current LLVM debugger implementation being
/// used.
diff --git a/tools/llvm-db/Commands.cpp b/tools/llvm-db/Commands.cpp
index ffebdd5d58f..4c916f42780 100644
--- a/tools/llvm-db/Commands.cpp
+++ b/tools/llvm-db/Commands.cpp
@@ -64,7 +64,7 @@ void CLIDebugger::startProgramRunning() {
TheProgramInfo = 0;
CurrentFile = 0;
- Dbg.loadProgram(Program.toString());
+ Dbg.loadProgram(Program.toString(), Context);
TheProgramInfo = new ProgramInfo(Dbg.getProgram());
}
@@ -244,7 +244,7 @@ void CLIDebugger::fileCommand(std::string &Options) {
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());
diff --git a/tools/llvm-db/llvm-db.cpp b/tools/llvm-db/llvm-db.cpp
index 04e616227b2..62ee325bfd4 100644
--- a/tools/llvm-db/llvm-db.cpp
+++ b/tools/llvm-db/llvm-db.cpp
@@ -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 @@ int main(int argc, char **argv, char * const *envp) {
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 @@ int main(int argc, char **argv, char * const *envp) {
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();
diff --git a/tools/llvm-dis/llvm-dis.cpp b/tools/llvm-dis/llvm-dis.cpp
index 471e5e2f5d2..3460f7e0fb7 100644
--- a/tools/llvm-dis/llvm-dis.cpp
+++ b/tools/llvm-dis/llvm-dis.cpp
@@ -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 @@ int main(int argc, char **argv) {
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 @@ int main(int argc, char **argv) {
if (MemoryBuffer *Buffer
= MemoryBuffer::getFileOrSTDIN(InputFilename, &ErrorMessage)) {
- M.reset(ParseBitcodeFile(Buffer, &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 46840f2e223..a9772116c9f 100644
--- a/tools/llvm-extract/llvm-extract.cpp
+++ b/tools/llvm-extract/llvm-extract.cpp
@@ -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 @@ int main(int argc, char **argv) {
// 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 @@ int main(int argc, char **argv) {
cerr << argv[0] << ": Error reading file '" + InputFilename + "'\n";
return 1;
} else {
- M.reset(ParseBitcodeFile(Buffer));
+ M.reset(ParseBitcodeFile(Buffer, &Context));
}
delete Buffer;
diff --git a/tools/llvm-ld/llvm-ld.cpp b/tools/llvm-ld/llvm-ld.cpp
index fd2e0f7cac2..435de0f4a36 100644
--- a/tools/llvm-ld/llvm-ld.cpp
+++ b/tools/llvm-ld/llvm-ld.cpp
@@ -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 @@ int main(int argc, char **argv, char **envp) {
// 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 @@ 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, 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 15850f4717e..ae5fa40ecba 100644
--- a/tools/llvm-link/llvm-link.cpp
+++ b/tools/llvm-link/llvm-link.cpp
@@ -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 @@ DumpAsm("d", cl::desc("Print assembly as linked"), cl::Hidden);
// 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 @@ static inline std::auto_ptr<Module> LoadFile(const std::string &FN) {
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 @@ 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 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 @@ int main(int argc, char **argv) {
}
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;
diff --git a/tools/llvm-nm/llvm-nm.cpp b/tools/llvm-nm/llvm-nm.cpp
index 324e0f67035..3f19940660e 100644
--- a/tools/llvm-nm/llvm-nm.cpp
+++ b/tools/llvm-nm/llvm-nm.cpp
@@ -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 DumpSymbolNamesFromModule(Module *M) {
}
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 @@ static void DumpSymbolNamesFromFile(std::string &Filename) {
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 @@ static void DumpSymbolNamesFromFile(std::string &Filename) {
} 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;
diff --git a/tools/llvm-prof/llvm-prof.cpp b/tools/llvm-prof/llvm-prof.cpp
index 119dc1a1178..104d879447e 100644
--- a/tools/llvm-prof/llvm-prof.cpp
+++ b/tools/llvm-prof/llvm-prof.cpp
@@ -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 @@ int main(int argc, char **argv) {
// 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 @@ int main(int argc, char **argv) {
Module *M = 0;
if (MemoryBuffer *Buffer = MemoryBuffer::getFileOrSTDIN(BitcodeFile,
&ErrorMessage)) {
- M = ParseBitcodeFile(Buffer, &ErrorMessage);
+ M = ParseBitcodeFile(Buffer, &Context, &ErrorMessage);
delete Buffer;
}
if (M == 0) {
diff --git a/tools/llvm-ranlib/llvm-ranlib.cpp b/tools/llvm-ranlib/llvm-ranlib.cpp
index 72106104c00..7b1b413ecca 100644
--- a/tools/llvm-ranlib/llvm-ranlib.cpp
+++ b/tools/llvm-ranlib/llvm-ranlib.cpp
@@ -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 @@ int main(int argc, char **argv) {
// 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 @@ int main(int argc, char **argv) {
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;
diff --git a/tools/lto/LTOCodeGenerator.cpp b/tools/lto/LTOCodeGenerator.cpp
index 52624ebe910..8ae196fe942 100644
--- a/tools/lto/LTOCodeGenerator.cpp
+++ b/tools/lto/LTOCodeGenerator.cpp
@@ -70,7 +70,8 @@ const char* LTOCodeGenerator::getVersionString()
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)
diff --git a/tools/lto/LTOCodeGenerator.h b/tools/lto/LTOCodeGenerator.h
index e02a7ab1159..d412626fbf4 100644
--- a/tools/lto/LTOCodeGenerator.h
+++ b/tools/lto/LTOCodeGenerator.h
@@ -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 @@ private:
typedef llvm::StringMap<uint8_t> StringSet;
+ llvm::LLVMContext* _context;
llvm::Linker _linker;
llvm::TargetMachine* _target;
bool _emitDwarfDebugInfo;
diff --git a/tools/lto/LTOModule.cpp b/tools/lto/LTOModule.cpp
index 939d0eacd1e..64e79509017 100644
--- a/tools/lto/LTOModule.cpp
+++ b/tools/lto/LTOModule.cpp
@@ -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 @@ bool LTOModule::isBitcodeFileForTarget(const char* path,
// 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(Module* m, TargetMachine* t)
{
}
-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 @@ MemoryBuffer* LTOModule::makeBuffer(const void* mem, size_t length)
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 @@ std::string getFeatureString(const char *TargetTriple) {
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
diff --git a/tools/lto/LTOModule.h b/tools/lto/LTOModule.h
index 9de02a2a4e2..bfdf6e7fd09 100644
--- a/tools/lto/LTOModule.h
+++ b/tools/lto/LTOModule.h
@@ -32,6 +32,7 @@ namespace llvm {
class GlobalValue;
class Value;
class Function;
+ class LLVMContext;
}
@@ -50,9 +51,12 @@ public:
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 @@ private:
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);
diff --git a/tools/lto/lto.cpp b/tools/lto/lto.cpp
index a0f67b44f5f..c25f87c3404 100644
--- a/tools/lto/lto.cpp
+++ b/tools/lto/lto.cpp
@@ -13,6 +13,7 @@
//===----------------------------------------------------------------------===//
#include "llvm-c/lto.h"
+#include "llvm-c/Core.h"
#include "LTOModule.h"
#include "LTOCodeGenerator.h"
@@ -85,9 +86,10 @@ bool lto_module_is_object_file_in_memory_for_target(const void* mem,
// 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 @@ lto_module_t lto_module_create(const char* path)
// 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);
}
diff --git a/tools/opt/opt.cpp b/tools/opt/opt.cpp
index 0c36e21fa58..b46960638d8 100644
--- a/tools/opt/opt.cpp
+++ b/tools/opt/opt.cpp
@@ -12,6 +12,7 @@
//
//===----------------------------------------------------------------------===//
+#include "llvm/LLVMContext.h"
#include "llvm/Module.h"
#include "llvm/ModuleProvider.h"
#include "llvm/PassManager.h"
@@ -310,6 +311,7 @@ void AddStandardCompilePasses(PassManager &PM) {
//
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 @@ int main(int argc, char **argv) {
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;
}