summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorJeffrey Yasskin <jyasskin@google.com>2010-01-27 20:34:15 +0000
committerJeffrey Yasskin <jyasskin@google.com>2010-01-27 20:34:15 +0000
commitf0356fe140af1a30587b9a86bcfb1b2c51b8ce20 (patch)
treeb93c54de2473a5a87afd13ebccdd234b509b6b72 /include
parent5deb57c68552a85094b786dfdbd16e3744716733 (diff)
downloadllvm-f0356fe140af1a30587b9a86bcfb1b2c51b8ce20.tar.gz
llvm-f0356fe140af1a30587b9a86bcfb1b2c51b8ce20.tar.bz2
llvm-f0356fe140af1a30587b9a86bcfb1b2c51b8ce20.tar.xz
Kill ModuleProvider and ghost linkage by inverting the relationship between
Modules and ModuleProviders. Because the "ModuleProvider" simply materializes GlobalValues now, and doesn't provide modules, it's renamed to "GVMaterializer". Code that used to need a ModuleProvider to materialize Functions can now materialize the Functions directly. Functions no longer use a magic linkage to record that they're materializable; they simply ask the GVMaterializer. Because the C ABI must never change, we can't remove LLVMModuleProviderRef or the functions that refer to it. Instead, because Module now exposes the same functionality ModuleProvider used to, we store a Module* in any LLVMModuleProviderRef and translate in the wrapper methods. The bindings to other languages still use the ModuleProvider concept. It would probably be worth some time to update them to follow the C++ more closely, but I don't intend to do it. Fixes http://llvm.org/PR5737 and http://llvm.org/PR5735. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@94686 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include')
-rw-r--r--include/llvm-c/Core.h26
-rw-r--r--include/llvm/Bitcode/Archive.h21
-rw-r--r--include/llvm/Bitcode/ReaderWriter.h9
-rw-r--r--include/llvm/ExecutionEngine/ExecutionEngine.h55
-rw-r--r--include/llvm/GVMaterializer.h66
-rw-r--r--include/llvm/GlobalValue.h35
-rw-r--r--include/llvm/Module.h47
-rw-r--r--include/llvm/ModuleProvider.h88
-rw-r--r--include/llvm/PassManager.h13
-rw-r--r--include/llvm/Support/IRReader.h39
10 files changed, 209 insertions, 190 deletions
diff --git a/include/llvm-c/Core.h b/include/llvm-c/Core.h
index d57c250fcb..674dde509d 100644
--- a/include/llvm-c/Core.h
+++ b/include/llvm-c/Core.h
@@ -78,8 +78,9 @@ typedef struct LLVMOpaqueValue *LLVMValueRef;
typedef struct LLVMOpaqueBasicBlock *LLVMBasicBlockRef;
typedef struct LLVMOpaqueBuilder *LLVMBuilderRef;
-/* Used to provide a module to JIT or interpreter.
- * See the llvm::ModuleProvider class.
+/* Interface used to provide a module to JIT or interpreter. This is now just a
+ * synonym for llvm::Module, but we have to keep using the different type to
+ * keep binary compatibility.
*/
typedef struct LLVMOpaqueModuleProvider *LLVMModuleProviderRef;
@@ -210,8 +211,7 @@ typedef enum {
LLVMDLLImportLinkage, /**< Function to be imported from DLL */
LLVMDLLExportLinkage, /**< Function to be accessible from DLL */
LLVMExternalWeakLinkage,/**< ExternalWeak linkage description */
- LLVMGhostLinkage, /**< Stand-in functions for streaming fns from
- bitcode */
+ LLVMGhostLinkage, /**< Obsolete */
LLVMCommonLinkage, /**< Tentative definitions */
LLVMLinkerPrivateLinkage /**< Like Private, but linker removes. */
} LLVMLinkage;
@@ -914,17 +914,15 @@ LLVMValueRef LLVMBuildPtrDiff(LLVMBuilderRef, LLVMValueRef LHS,
/*===-- Module providers --------------------------------------------------===*/
-/* Encapsulates the module M in a module provider, taking ownership of the
- * module.
- * See the constructor llvm::ExistingModuleProvider::ExistingModuleProvider.
+/* Changes the type of M so it can be passed to FunctionPassManagers and the
+ * JIT. They take ModuleProviders for historical reasons.
*/
LLVMModuleProviderRef
LLVMCreateModuleProviderForExistingModule(LLVMModuleRef M);
-/* Destroys the module provider MP as well as the contained module.
- * See the destructor llvm::ModuleProvider::~ModuleProvider.
+/* Destroys the module M.
*/
-void LLVMDisposeModuleProvider(LLVMModuleProviderRef MP);
+void LLVMDisposeModuleProvider(LLVMModuleProviderRef M);
/*===-- Memory buffers ----------------------------------------------------===*/
@@ -981,7 +979,6 @@ void LLVMDisposePassManager(LLVMPassManagerRef PM);
}
namespace llvm {
- class ModuleProvider;
class MemoryBuffer;
class PassManagerBase;
@@ -1018,11 +1015,16 @@ namespace llvm {
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(BasicBlock, LLVMBasicBlockRef )
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(IRBuilder<>, LLVMBuilderRef )
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_SIMPLE_CONVERSION_FUNCTIONS(Use, LLVMUseIteratorRef )
DEFINE_STDCXX_CONVERSION_FUNCTIONS(PassManagerBase, LLVMPassManagerRef )
+ /* LLVMModuleProviderRef exists for historical reasons, but now just holds a
+ * Module.
+ */
+ inline Module *unwrap(LLVMModuleProviderRef MP) {
+ return reinterpret_cast<Module*>(MP);
+ }
#undef DEFINE_STDCXX_CONVERSION_FUNCTIONS
#undef DEFINE_ISA_CONVERSION_FUNCTIONS
diff --git a/include/llvm/Bitcode/Archive.h b/include/llvm/Bitcode/Archive.h
index e19e4c09ce..67f2a4a999 100644
--- a/include/llvm/Bitcode/Archive.h
+++ b/include/llvm/Bitcode/Archive.h
@@ -27,7 +27,6 @@ namespace llvm {
class MemoryBuffer;
// Forward declare classes
-class ModuleProvider; // From VMCore
class Module; // From VMCore
class Archive; // Declared below
class ArchiveMemberHeader; // Internal implementation class
@@ -374,14 +373,14 @@ class Archive {
/// returns the associated module that defines that symbol. This method can
/// be called as many times as necessary. This is handy for linking the
/// archive into another module based on unresolved symbols. Note that the
- /// ModuleProvider returned by this accessor should not be deleted by the
- /// caller. It is managed internally by the Archive class. It is possible
- /// that multiple calls to this accessor will return the same ModuleProvider
- /// instance because the associated module defines multiple symbols.
- /// @returns The ModuleProvider* found or null if the archive does not
- /// contain a module that defines the \p symbol.
+ /// Module returned by this accessor should not be deleted by the caller. It
+ /// is managed internally by the Archive class. It is possible that multiple
+ /// calls to this accessor will return the same Module instance because the
+ /// associated module defines multiple symbols.
+ /// @returns The Module* found or null if the archive does not contain a
+ /// module that defines the \p symbol.
/// @brief Look up a module by symbol name.
- ModuleProvider* findModuleDefiningSymbol(
+ Module* findModuleDefiningSymbol(
const std::string& symbol, ///< Symbol to be sought
std::string* ErrMessage ///< Error message storage, if non-zero
);
@@ -397,7 +396,7 @@ class Archive {
/// @brief Look up multiple symbols in the archive.
bool findModulesDefiningSymbols(
std::set<std::string>& symbols, ///< Symbols to be sought
- std::set<ModuleProvider*>& modules, ///< The modules matching \p symbols
+ std::set<Module*>& modules, ///< The modules matching \p symbols
std::string* ErrMessage ///< Error msg storage, if non-zero
);
@@ -513,9 +512,9 @@ class Archive {
/// This type is used to keep track of bitcode modules loaded from the
/// symbol table. It maps the file offset to a pair that consists of the
- /// associated ArchiveMember and the ModuleProvider.
+ /// associated ArchiveMember and the Module.
/// @brief Module mapping type
- typedef std::map<unsigned,std::pair<ModuleProvider*,ArchiveMember*> >
+ typedef std::map<unsigned,std::pair<Module*,ArchiveMember*> >
ModuleMap;
diff --git a/include/llvm/Bitcode/ReaderWriter.h b/include/llvm/Bitcode/ReaderWriter.h
index 7b74bdf76b..45eb801a8c 100644
--- a/include/llvm/Bitcode/ReaderWriter.h
+++ b/include/llvm/Bitcode/ReaderWriter.h
@@ -18,21 +18,20 @@
namespace llvm {
class Module;
- class ModuleProvider;
class MemoryBuffer;
class ModulePass;
class BitstreamWriter;
class LLVMContext;
class raw_ostream;
- /// getBitcodeModuleProvider - Read the header of the specified bitcode buffer
+ /// getLazyBitcodeModule - Read the header of the specified bitcode buffer
/// and prepare for lazy deserialization of function bodies. If successful,
/// this takes ownership of 'buffer' and returns a non-null pointer. On
/// 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);
+ Module *getLazyBitcodeModule(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
diff --git a/include/llvm/ExecutionEngine/ExecutionEngine.h b/include/llvm/ExecutionEngine/ExecutionEngine.h
index d2c547dcf1..ce6a2e9af0 100644
--- a/include/llvm/ExecutionEngine/ExecutionEngine.h
+++ b/include/llvm/ExecutionEngine/ExecutionEngine.h
@@ -36,7 +36,6 @@ class JITEventListener;
class JITMemoryManager;
class MachineCodeInfo;
class Module;
-class ModuleProvider;
class MutexGuard;
class TargetData;
class Type;
@@ -95,9 +94,9 @@ class ExecutionEngine {
friend class EngineBuilder; // To allow access to JITCtor and InterpCtor.
protected:
- /// Modules - This is a list of ModuleProvider's that we are JIT'ing from. We
- /// use a smallvector to optimize for the case where there is only one module.
- SmallVector<ModuleProvider*, 1> Modules;
+ /// Modules - This is a list of Modules that we are JIT'ing from. We use a
+ /// smallvector to optimize for the case where there is only one module.
+ SmallVector<Module*, 1> Modules;
void setTargetData(const TargetData *td) {
TD = td;
@@ -109,13 +108,13 @@ protected:
// To avoid having libexecutionengine depend on the JIT and interpreter
// libraries, the JIT and Interpreter set these functions to ctor pointers
// at startup time if they are linked in.
- static ExecutionEngine *(*JITCtor)(ModuleProvider *MP,
+ static ExecutionEngine *(*JITCtor)(Module *M,
std::string *ErrorStr,
JITMemoryManager *JMM,
CodeGenOpt::Level OptLevel,
bool GVsWithCode,
CodeModel::Model CMM);
- static ExecutionEngine *(*InterpCtor)(ModuleProvider *MP,
+ static ExecutionEngine *(*InterpCtor)(Module *M,
std::string *ErrorStr);
/// LazyFunctionCreator - If an unknown function is needed, this function
@@ -141,8 +140,8 @@ public:
/// create - This is the factory method for creating an execution engine which
/// is appropriate for the current machine. This takes ownership of the
- /// module provider.
- static ExecutionEngine *create(ModuleProvider *MP,
+ /// module.
+ static ExecutionEngine *create(Module *M,
bool ForceInterpreter = false,
std::string *ErrorStr = 0,
CodeGenOpt::Level OptLevel =
@@ -165,11 +164,11 @@ public:
/// createJIT - This is the factory method for creating a JIT for the current
/// machine, it does not fall back to the interpreter. This takes ownership
- /// of the ModuleProvider and JITMemoryManager if successful.
+ /// of the Module and JITMemoryManager if successful.
///
/// Clients should make sure to initialize targets prior to calling this
/// function.
- static ExecutionEngine *createJIT(ModuleProvider *MP,
+ static ExecutionEngine *createJIT(Module *M,
std::string *ErrorStr = 0,
JITMemoryManager *JMM = 0,
CodeGenOpt::Level OptLevel =
@@ -178,11 +177,11 @@ public:
CodeModel::Model CMM =
CodeModel::Default);
- /// addModuleProvider - Add a ModuleProvider to the list of modules that we
- /// can JIT from. Note that this takes ownership of the ModuleProvider: when
- /// the ExecutionEngine is destroyed, it destroys the MP as well.
- virtual void addModuleProvider(ModuleProvider *P) {
- Modules.push_back(P);
+ /// addModule - Add a Module to the list of modules that we can JIT from.
+ /// Note that this takes ownership of the Module: when the ExecutionEngine is
+ /// destroyed, it destroys the Module as well.
+ virtual void addModule(Module *M) {
+ Modules.push_back(M);
}
//===----------------------------------------------------------------------===//
@@ -190,16 +189,9 @@ public:
const TargetData *getTargetData() const { return TD; }
- /// removeModuleProvider - Remove a ModuleProvider from the list of modules.
- /// Relases the Module from the ModuleProvider, materializing it in the
- /// process, and returns the materialized Module.
- virtual Module* removeModuleProvider(ModuleProvider *P,
- std::string *ErrInfo = 0);
-
- /// deleteModuleProvider - Remove a ModuleProvider from the list of modules,
- /// and deletes the ModuleProvider and owned Module. Avoids materializing
- /// the underlying module.
- virtual void deleteModuleProvider(ModuleProvider *P,std::string *ErrInfo = 0);
+ /// removeModule - Remove a Module from the list of modules. Returns true if
+ /// M is found.
+ virtual bool removeModule(Module *M);
/// FindFunctionNamed - Search all of the active modules to find the one that
/// defines FnName. This is very slow operation and shouldn't be used for
@@ -393,7 +385,7 @@ public:
}
protected:
- explicit ExecutionEngine(ModuleProvider *P);
+ explicit ExecutionEngine(Module *M);
void emitGlobals();
@@ -422,7 +414,7 @@ namespace EngineKind {
class EngineBuilder {
private:
- ModuleProvider *MP;
+ Module *M;
EngineKind::Kind WhichEngine;
std::string *ErrorStr;
CodeGenOpt::Level OptLevel;
@@ -443,16 +435,11 @@ class EngineBuilder {
public:
/// EngineBuilder - Constructor for EngineBuilder. If create() is called and
- /// is successful, the created engine takes ownership of the module
- /// provider.
- EngineBuilder(ModuleProvider *mp) : MP(mp) {
+ /// is successful, the created engine takes ownership of the module.
+ EngineBuilder(Module *m) : M(m) {
InitEngine();
}
- /// EngineBuilder - Overloaded constructor that automatically creates an
- /// ExistingModuleProvider for an existing module.
- EngineBuilder(Module *m);
-
/// setEngineKind - Controls whether the user wants the interpreter, the JIT,
/// or whichever engine works. This option defaults to EngineKind::Either.
EngineBuilder &setEngineKind(EngineKind::Kind w) {
diff --git a/include/llvm/GVMaterializer.h b/include/llvm/GVMaterializer.h
new file mode 100644
index 0000000000..c143552388
--- /dev/null
+++ b/include/llvm/GVMaterializer.h
@@ -0,0 +1,66 @@
+//===-- llvm/GVMaterializer.h - Interface for GV materializers --*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file provides an abstract interface for loading a module from some
+// place. This interface allows incremental or random access loading of
+// functions from the file. This is useful for applications like JIT compilers
+// or interprocedural optimizers that do not need the entire program in memory
+// at the same time.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef GVMATERIALIZER_H
+#define GVMATERIALIZER_H
+
+#include <string>
+
+namespace llvm {
+
+class Function;
+class GlobalValue;
+class Module;
+
+class GVMaterializer {
+protected:
+ GVMaterializer() {}
+
+public:
+ virtual ~GVMaterializer();
+
+ /// isMaterializable - True if GV can be materialized from whatever backing
+ /// store this GVMaterializer uses and has not been materialized yet.
+ virtual bool isMaterializable(const GlobalValue *GV) const = 0;
+
+ /// isDematerializable - True if GV has been materialized and can be
+ /// dematerialized back to whatever backing store this GVMaterializer uses.
+ virtual bool isDematerializable(const GlobalValue *GV) const = 0;
+
+ /// Materialize - make sure the given GlobalValue is fully read. If the
+ /// module is corrupt, this returns true and fills in the optional string with
+ /// information about the problem. If successful, this returns false.
+ ///
+ virtual bool Materialize(GlobalValue *GV, std::string *ErrInfo = 0) = 0;
+
+ /// Dematerialize - If the given GlobalValue is read in, and if the
+ /// GVMaterializer supports it, release the memory for the GV, and set it up
+ /// to be materialized lazily. If the Materializer doesn't support this
+ /// capability, this method is a noop.
+ ///
+ virtual void Dematerialize(GlobalValue *) {}
+
+ /// MaterializeModule - make sure the entire Module has been completely read.
+ /// On error, this returns true and fills in the optional string with
+ /// information about the problem. If successful, this returns false.
+ ///
+ virtual bool MaterializeModule(Module *M, std::string *ErrInfo = 0) = 0;
+};
+
+} // End llvm namespace
+
+#endif
diff --git a/include/llvm/GlobalValue.h b/include/llvm/GlobalValue.h
index 9875a83310..1ac7eeea33 100644
--- a/include/llvm/GlobalValue.h
+++ b/include/llvm/GlobalValue.h
@@ -43,7 +43,6 @@ public:
DLLImportLinkage, ///< Function to be imported from DLL
DLLExportLinkage, ///< Function to be accessible from DLL.
ExternalWeakLinkage,///< ExternalWeak linkage description.
- GhostLinkage, ///< Stand-in functions for streaming fns from BC files.
CommonLinkage ///< Tentative definitions.
};
@@ -132,7 +131,6 @@ public:
bool hasDLLImportLinkage() const { return Linkage == DLLImportLinkage; }
bool hasDLLExportLinkage() const { return Linkage == DLLExportLinkage; }
bool hasExternalWeakLinkage() const { return Linkage == ExternalWeakLinkage; }
- bool hasGhostLinkage() const { return Linkage == GhostLinkage; }
bool hasCommonLinkage() const { return Linkage == CommonLinkage; }
void setLinkage(LinkageTypes LT) { Linkage = LT; }
@@ -164,12 +162,33 @@ public:
/// create a GlobalValue) from the GlobalValue Src to this one.
virtual void copyAttributesFrom(const GlobalValue *Src);
- /// hasNotBeenReadFromBitcode - If a module provider is being used to lazily
- /// stream in functions from disk, this method can be used to check to see if
- /// the function has been read in yet or not. Unless you are working on the
- /// JIT or something else that streams stuff in lazily, you don't need to
- /// worry about this.
- bool hasNotBeenReadFromBitcode() const { return Linkage == GhostLinkage; }
+/// @name Materialization
+/// Materialization is used to construct functions only as they're needed. This
+/// is useful to reduce memory usage in LLVM or parsing work done by the
+/// BitcodeReader to load the Module.
+/// @{
+
+ /// isMaterializable - If this function's Module is being lazily streamed in
+ /// functions from disk or some other source, this method can be used to check
+ /// to see if the function has been read in yet or not.
+ bool isMaterializable() const;
+
+ /// isDematerializable - Returns true if this function was loaded from a
+ /// GVMaterializer that's still attached to its Module and that knows how to
+ /// dematerialize the function.
+ bool isDematerializable() const;
+
+ /// Materialize - make sure this GlobalValue is fully read. If the module is
+ /// corrupt, this returns true and fills in the optional string with
+ /// information about the problem. If successful, this returns false.
+ bool Materialize(std::string *ErrInfo = 0);
+
+ /// Dematerialize - If this GlobalValue is read in, and if the GVMaterializer
+ /// supports it, release the memory for the function, and set it up to be
+ /// materialized lazily. If !isDematerializable(), this method is a noop.
+ void Dematerialize();
+
+/// @}
/// Override from Constant class. No GlobalValue's are null values so this
/// always returns false.
diff --git a/include/llvm/Module.h b/include/llvm/Module.h
index 8dfb5089ea..901fada3eb 100644
--- a/include/llvm/Module.h
+++ b/include/llvm/Module.h
@@ -19,12 +19,14 @@
#include "llvm/GlobalVariable.h"
#include "llvm/GlobalAlias.h"
#include "llvm/Metadata.h"
+#include "llvm/ADT/OwningPtr.h"
#include "llvm/System/DataTypes.h"
#include <vector>
namespace llvm {
class FunctionType;
+class GVMaterializer;
class LLVMContext;
class MDSymbolTable;
@@ -145,6 +147,7 @@ private:
std::string GlobalScopeAsm; ///< Inline Asm at global scope.
ValueSymbolTable *ValSymTab; ///< Symbol table for values
TypeSymbolTable *TypeSymTab; ///< Symbol table for types
+ OwningPtr<GVMaterializer> Materializer; ///< Used to materialize GlobalValues
std::string ModuleID; ///< Human readable identifier for the module
std::string TargetTriple; ///< Platform target triple Module compiled on
std::string DataLayout; ///< Target data description
@@ -347,6 +350,50 @@ public:
const Type *getTypeByName(StringRef Name) const;
/// @}
+/// @name Materialization
+/// @{
+
+ /// setMaterializer - Sets the GVMaterializer to GVM. This module must not
+ /// yet have a Materializer. To reset the materializer for a module that
+ /// already has one, call MaterializeAllPermanently first. Destroying this
+ /// module will destroy its materializer without materializing any more
+ /// GlobalValues. Without destroying the Module, there is no way to detach or
+ /// destroy a materializer without materializing all the GVs it controls, to
+ /// avoid leaving orphan unmaterialized GVs.
+ void setMaterializer(GVMaterializer *GVM);
+ /// getMaterializer - Retrieves the GVMaterializer, if any, for this Module.
+ GVMaterializer *getMaterializer() const { return Materializer.get(); }
+
+ /// isMaterializable - True if the definition of GV has yet to be materialized
+ /// from the GVMaterializer.
+ bool isMaterializable(const GlobalValue *GV) const;
+ /// isDematerializable - Returns true if this GV was loaded from this Module's
+ /// GVMaterializer and the GVMaterializer knows how to dematerialize the GV.
+ bool isDematerializable(const GlobalValue *GV) const;
+
+ /// Materialize - Make sure the GlobalValue is fully read. If the module is
+ /// corrupt, this returns true and fills in the optional string with
+ /// information about the problem. If successful, this returns false.
+ bool Materialize(GlobalValue *GV, std::string *ErrInfo = 0);
+ /// Dematerialize - If the GlobalValue is read in, and if the GVMaterializer
+ /// supports it, release the memory for the function, and set it up to be
+ /// materialized lazily. If !isDematerializable(), this method is a noop.
+ void Dematerialize(GlobalValue *GV);
+
+ /// MaterializeAll - Make sure all GlobalValues in this Module are fully read.
+ /// If the module is corrupt, this returns true and fills in the optional
+ /// string with information about the problem. If successful, this returns
+ /// false.
+ bool MaterializeAll(std::string *ErrInfo = 0);
+
+ /// MaterializeAllPermanently - Make sure all GlobalValues in this Module are
+ /// fully read and clear the Materializer. If the module is corrupt, this
+ /// returns true, fills in the optional string with information about the
+ /// problem, and DOES NOT clear the old Materializer. If successful, this
+ /// returns false.
+ bool MaterializeAllPermanently(std::string *ErrInfo = 0);
+
+/// @}
/// @name Direct access to the globals list, functions list, and symbol table
/// @{
diff --git a/include/llvm/ModuleProvider.h b/include/llvm/ModuleProvider.h
deleted file mode 100644
index 8a0a20c0ef..0000000000
--- a/include/llvm/ModuleProvider.h
+++ /dev/null
@@ -1,88 +0,0 @@
-//===-- llvm/ModuleProvider.h - Interface for module providers --*- C++ -*-===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-//
-// This file provides an abstract interface for loading a module from some
-// place. This interface allows incremental or random access loading of
-// functions from the file. This is useful for applications like JIT compilers
-// or interprocedural optimizers that do not need the entire program in memory
-// at the same time.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef MODULEPROVIDER_H
-#define MODULEPROVIDER_H
-
-#include <string>
-
-namespace llvm {
-
-class Function;
-class Module;
-
-class ModuleProvider {
-protected:
- Module *TheModule;
- ModuleProvider();
-
-public:
- virtual ~ModuleProvider();
-
- /// getModule - returns the module this provider is encapsulating.
- ///
- Module* getModule() { return TheModule; }
-
- /// materializeFunction - make sure the given function is fully read. If the
- /// module is corrupt, this returns true and fills in the optional string
- /// with information about the problem. If successful, this returns false.
- ///
- virtual bool materializeFunction(Function *F, std::string *ErrInfo = 0) = 0;
-
- /// dematerializeFunction - If the given function is read in, and if the
- /// module provider supports it, release the memory for the function, and set
- /// it up to be materialized lazily. If the provider doesn't support this
- /// capability, this method is a noop.
- ///
- virtual void dematerializeFunction(Function *) {}
-
- /// materializeModule - make sure the entire Module has been completely read.
- /// On error, return null and fill in the error string if specified.
- ///
- virtual Module* materializeModule(std::string *ErrInfo = 0) = 0;
-
- /// releaseModule - no longer delete the Module* when provider is destroyed.
- /// On error, return null and fill in the error string if specified.
- ///
- virtual Module* releaseModule(std::string *ErrInfo = 0) {
- // Since we're losing control of this Module, we must hand it back complete
- if (!materializeModule(ErrInfo))
- return 0;
- Module *tempM = TheModule;
- TheModule = 0;
- return tempM;
- }
-};
-
-
-/// ExistingModuleProvider - Allow conversion from a fully materialized Module
-/// into a ModuleProvider, allowing code that expects a ModuleProvider to work
-/// if we just have a Module. Note that the ModuleProvider takes ownership of
-/// the Module specified.
-struct ExistingModuleProvider : public ModuleProvider {
- explicit ExistingModuleProvider(Module *M) {
- TheModule = M;
- }
- bool materializeFunction(Function *, std::string * = 0) {
- return false;
- }
- Module* materializeModule(std::string * = 0) { return TheModule; }
-};
-
-} // End llvm namespace
-
-#endif
diff --git a/include/llvm/PassManager.h b/include/llvm/PassManager.h
index a6703fd586..4d9116311a 100644
--- a/include/llvm/PassManager.h
+++ b/include/llvm/PassManager.h
@@ -24,7 +24,6 @@ namespace llvm {
class Pass;
class ModulePass;
class Module;
-class ModuleProvider;
class PassManagerImpl;
class FunctionPassManagerImpl;
@@ -71,8 +70,8 @@ private:
class FunctionPassManager : public PassManagerBase {
public:
/// FunctionPassManager ctor - This initializes the pass manager. It needs,
- /// but does not take ownership of, the specified module provider.
- explicit FunctionPassManager(ModuleProvider *P);
+ /// but does not take ownership of, the specified Module.
+ explicit FunctionPassManager(Module *M);
~FunctionPassManager();
/// add - Add a pass to the queue of passes to run. This passes
@@ -96,15 +95,9 @@ public:
///
bool doFinalization();
- /// getModuleProvider - Return the module provider that this passmanager is
- /// currently using. This is the module provider that it uses when a function
- /// is optimized that is non-resident in the module.
- ModuleProvider *getModuleProvider() const { return MP; }
- void setModuleProvider(ModuleProvider *NewMP) { MP = NewMP; }
-
private:
FunctionPassManagerImpl *FPM;
- ModuleProvider *MP;
+ Module *M;
};
} // End llvm namespace
diff --git a/include/llvm/Support/IRReader.h b/include/llvm/Support/IRReader.h
index e7780b05d5..50de73803c 100644
--- a/include/llvm/Support/IRReader.h
+++ b/include/llvm/Support/IRReader.h
@@ -23,44 +23,39 @@
#include "llvm/Bitcode/ReaderWriter.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/SourceMgr.h"
-#include "llvm/ModuleProvider.h"
namespace llvm {
- /// If the given MemoryBuffer holds a bitcode image, return a ModuleProvider
- /// for it which does lazy deserialization of function bodies. Otherwise,
- /// attempt to parse it as LLVM Assembly and return a fully populated
- /// ModuleProvider. This function *always* takes ownership of the given
- /// MemoryBuffer.
- inline ModuleProvider *getIRModuleProvider(MemoryBuffer *Buffer,
- SMDiagnostic &Err,
- LLVMContext &Context) {
+ /// If the given MemoryBuffer holds a bitcode image, return a Module for it
+ /// which does lazy deserialization of function bodies. Otherwise, attempt to
+ /// parse it as LLVM Assembly and return a fully populated Module. This
+ /// function *always* takes ownership of the given MemoryBuffer.
+ inline Module *getIRModule(MemoryBuffer *Buffer,
+ SMDiagnostic &Err,
+ LLVMContext &Context) {
if (isBitcode((const unsigned char *)Buffer->getBufferStart(),
(const unsigned char *)Buffer->getBufferEnd())) {
std::string ErrMsg;
- ModuleProvider *MP = getBitcodeModuleProvider(Buffer, Context, &ErrMsg);
- if (MP == 0) {
+ Module *M = getLazyBitcodeModule(Buffer, Context, &ErrMsg);
+ if (M == 0) {
Err = SMDiagnostic(Buffer->getBufferIdentifier(), -1, -1, ErrMsg, "");
// ParseBitcodeFile does not take ownership of the Buffer in the
// case of an error.
delete Buffer;
}
- return MP;
+ return M;
}
- Module *M = ParseAssembly(Buffer, 0, Err, Context);
- if (M == 0)
- return 0;
- return new ExistingModuleProvider(M);
+ return ParseAssembly(Buffer, 0, Err, Context);
}
- /// If the given file holds a bitcode image, return a ModuleProvider
+ /// If the given file holds a bitcode image, return a Module
/// for it which does lazy deserialization of function bodies. Otherwise,
/// attempt to parse it as LLVM Assembly and return a fully populated
- /// ModuleProvider.
- inline ModuleProvider *getIRFileModuleProvider(const std::string &Filename,
- SMDiagnostic &Err,
- LLVMContext &Context) {
+ /// Module.
+ inline Module *getIRFileModule(const std::string &Filename,
+ SMDiagnostic &Err,
+ LLVMContext &Context) {
std::string ErrMsg;
MemoryBuffer *F = MemoryBuffer::getFileOrSTDIN(Filename.c_str(), &ErrMsg);
if (F == 0) {
@@ -69,7 +64,7 @@ namespace llvm {
return 0;
}
- return getIRModuleProvider(F, Err, Context);
+ return getIRModule(F, Err, Context);
}
/// If the given MemoryBuffer holds a bitcode image, return a Module