Add Module functions in place of module providers.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@97608 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Erick Tryzelaar
2010-03-02 23:58:54 +00:00
parent fb444af5c9
commit df7df075b7
6 changed files with 139 additions and 39 deletions

View File

@ -36,18 +36,28 @@ LLVMBool LLVMParseBitcodeInContext(LLVMContextRef ContextRef,
LLVMMemoryBufferRef MemBuf, LLVMMemoryBufferRef MemBuf,
LLVMModuleRef *OutModule, char **OutMessage); LLVMModuleRef *OutModule, char **OutMessage);
/* Reads a module from the specified path, returning via the OutMP parameter /** Reads a module from the specified path, returning via the OutMP parameter
a module provider which performs lazy deserialization. Returns 0 on success. a module provider which performs lazy deserialization. Returns 0 on success.
Optionally returns a human-readable error message via OutMessage. */ Optionally returns a human-readable error message via OutMessage. */
LLVMBool LLVMGetBitcodeModuleProvider(LLVMMemoryBufferRef MemBuf, LLVMBool LLVMGetBitcodeModuleInContext(LLVMContextRef ContextRef,
LLVMModuleProviderRef *OutMP, LLVMMemoryBufferRef MemBuf,
char **OutMessage); LLVMModuleRef *OutM,
char **OutMessage);
LLVMBool LLVMGetBitcodeModule(LLVMMemoryBufferRef MemBuf, LLVMModuleRef *OutM,
char **OutMessage);
/** Deprecated: Use LLVMGetBitcodeModuleInContext instead. */
LLVMBool LLVMGetBitcodeModuleProviderInContext(LLVMContextRef ContextRef, LLVMBool LLVMGetBitcodeModuleProviderInContext(LLVMContextRef ContextRef,
LLVMMemoryBufferRef MemBuf, LLVMMemoryBufferRef MemBuf,
LLVMModuleProviderRef *OutMP, LLVMModuleProviderRef *OutMP,
char **OutMessage); char **OutMessage);
/** Deprecated: Use LLVMGetBitcodeModule instead. */
LLVMBool LLVMGetBitcodeModuleProvider(LLVMMemoryBufferRef MemBuf,
LLVMModuleProviderRef *OutMP,
char **OutMessage);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -1022,6 +1022,9 @@ LLVMPassManagerRef LLVMCreatePassManager(void);
provider. It does not take ownership of the module provider. This type of provider. It does not take ownership of the module provider. This type of
pipeline is suitable for code generation and JIT compilation tasks. pipeline is suitable for code generation and JIT compilation tasks.
See llvm::FunctionPassManager::FunctionPassManager. */ See llvm::FunctionPassManager::FunctionPassManager. */
LLVMPassManagerRef LLVMCreateFunctionPassManagerForModule(LLVMModuleRef M);
/** Deprecated: Use LLVMCreateFunctionPassManagerForModule instead. */
LLVMPassManagerRef LLVMCreateFunctionPassManager(LLVMModuleProviderRef MP); LLVMPassManagerRef LLVMCreateFunctionPassManager(LLVMModuleProviderRef MP);
/** Initializes, executes on the provided module, and finalizes all of the /** Initializes, executes on the provided module, and finalizes all of the

View File

@ -55,14 +55,30 @@ void LLVMDisposeGenericValue(LLVMGenericValueRef GenVal);
/*===-- Operations on execution engines -----------------------------------===*/ /*===-- Operations on execution engines -----------------------------------===*/
LLVMBool LLVMCreateExecutionEngineForModule(LLVMExecutionEngineRef *OutEE,
LLVMModuleRef M,
char **OutError);
LLVMBool LLVMCreateInterpreterForModule(LLVMExecutionEngineRef *OutInterp,
LLVMModuleRef M,
char **OutError);
LLVMBool LLVMCreateJITCompilerForModule(LLVMExecutionEngineRef *OutJIT,
LLVMModuleRef M,
unsigned OptLevel,
char **OutError);
/** Deprecated: Use LLVMCreateExecutionEngineForModule instead. */
LLVMBool LLVMCreateExecutionEngine(LLVMExecutionEngineRef *OutEE, LLVMBool LLVMCreateExecutionEngine(LLVMExecutionEngineRef *OutEE,
LLVMModuleProviderRef MP, LLVMModuleProviderRef MP,
char **OutError); char **OutError);
/** Deprecated: Use LLVMCreateInterpreterForModule instead. */
LLVMBool LLVMCreateInterpreter(LLVMExecutionEngineRef *OutInterp, LLVMBool LLVMCreateInterpreter(LLVMExecutionEngineRef *OutInterp,
LLVMModuleProviderRef MP, LLVMModuleProviderRef MP,
char **OutError); char **OutError);
/** Deprecated: Use LLVMCreateJITCompilerForModule instead. */
LLVMBool LLVMCreateJITCompiler(LLVMExecutionEngineRef *OutJIT, LLVMBool LLVMCreateJITCompiler(LLVMExecutionEngineRef *OutJIT,
LLVMModuleProviderRef MP, LLVMModuleProviderRef MP,
unsigned OptLevel, unsigned OptLevel,
@ -84,8 +100,15 @@ LLVMGenericValueRef LLVMRunFunction(LLVMExecutionEngineRef EE, LLVMValueRef F,
void LLVMFreeMachineCodeForFunction(LLVMExecutionEngineRef EE, LLVMValueRef F); void LLVMFreeMachineCodeForFunction(LLVMExecutionEngineRef EE, LLVMValueRef F);
void LLVMAddModule(LLVMExecutionEngineRef EE, LLVMModuleRef M);
/** Deprecated: Use LLVMAddModule instead. */
void LLVMAddModuleProvider(LLVMExecutionEngineRef EE, LLVMModuleProviderRef MP); void LLVMAddModuleProvider(LLVMExecutionEngineRef EE, LLVMModuleProviderRef MP);
LLVMBool LLVMRemoveModule(LLVMExecutionEngineRef EE, LLVMModuleRef M,
LLVMModuleRef *OutMod, char **OutError);
/** Deprecated: Use LLVMRemoveModule instead. */
LLVMBool LLVMRemoveModuleProvider(LLVMExecutionEngineRef EE, LLVMBool LLVMRemoveModuleProvider(LLVMExecutionEngineRef EE,
LLVMModuleProviderRef MP, LLVMModuleProviderRef MP,
LLVMModuleRef *OutMod, char **OutError); LLVMModuleRef *OutMod, char **OutError);

View File

@ -45,26 +45,44 @@ LLVMBool LLVMParseBitcodeInContext(LLVMContextRef ContextRef,
/* Reads a module from the specified path, returning via the OutModule parameter /* Reads a module from the specified path, returning via the OutModule parameter
a module provider which performs lazy deserialization. Returns 0 on success. a module provider which performs lazy deserialization. Returns 0 on success.
Optionally returns a human-readable error message via OutMessage. */ Optionally returns a human-readable error message via OutMessage. */
LLVMBool LLVMGetBitcodeModuleProvider(LLVMMemoryBufferRef MemBuf, LLVMBool LLVMGetBitcodeModuleInContext(LLVMContextRef ContextRef,
LLVMModuleProviderRef *OutMP, LLVMMemoryBufferRef MemBuf,
char **OutMessage) { LLVMModuleRef *OutM,
return LLVMGetBitcodeModuleProviderInContext(wrap(&getGlobalContext()), char **OutMessage) {
MemBuf, OutMP, OutMessage);
}
LLVMBool LLVMGetBitcodeModuleProviderInContext(LLVMContextRef ContextRef,
LLVMMemoryBufferRef MemBuf,
LLVMModuleProviderRef *OutMP,
char **OutMessage) {
std::string Message; std::string Message;
*OutMP = reinterpret_cast<LLVMModuleProviderRef>( *OutM = wrap(getLazyBitcodeModule(unwrap(MemBuf), *unwrap(ContextRef),
getLazyBitcodeModule(unwrap(MemBuf), *unwrap(ContextRef), &Message)); &Message));
if (!*OutMP) { if (!*OutM) {
if (OutMessage) if (OutMessage)
*OutMessage = strdup(Message.c_str()); *OutMessage = strdup(Message.c_str());
return 1; return 1;
} }
return 0; return 0;
}
LLVMBool LLVMGetBitcodeModule(LLVMMemoryBufferRef MemBuf, LLVMModuleRef *OutM,
char **OutMessage) {
return LLVMGetBitcodeModuleInContext(LLVMGetGlobalContext(), MemBuf, OutM,
OutMessage);
}
/* Deprecated: Use LLVMGetBitcodeModuleInContext instead. */
LLVMBool LLVMGetBitcodeModuleProviderInContext(LLVMContextRef ContextRef,
LLVMMemoryBufferRef MemBuf,
LLVMModuleProviderRef *OutMP,
char **OutMessage) {
return LLVMGetBitcodeModuleInContext(ContextRef, MemBuf,
reinterpret_cast<LLVMModuleRef*>(OutMP),
OutMessage);
}
/* Deprecated: Use LLVMGetBitcodeModule instead. */
LLVMBool LLVMGetBitcodeModuleProvider(LLVMMemoryBufferRef MemBuf,
LLVMModuleProviderRef *OutMP,
char **OutMessage) {
return LLVMGetBitcodeModuleProviderInContext(LLVMGetGlobalContext(), MemBuf,
OutMP, OutMessage);
} }

View File

@ -87,11 +87,11 @@ void LLVMDisposeGenericValue(LLVMGenericValueRef GenVal) {
/*===-- Operations on execution engines -----------------------------------===*/ /*===-- Operations on execution engines -----------------------------------===*/
LLVMBool LLVMCreateExecutionEngine(LLVMExecutionEngineRef *OutEE, LLVMBool LLVMCreateExecutionEngineForModule(LLVMExecutionEngineRef *OutEE,
LLVMModuleProviderRef MP, LLVMModuleRef M,
char **OutError) { char **OutError) {
std::string Error; std::string Error;
EngineBuilder builder(unwrap(MP)); EngineBuilder builder(unwrap(M));
builder.setEngineKind(EngineKind::Either) builder.setEngineKind(EngineKind::Either)
.setErrorStr(&Error); .setErrorStr(&Error);
if (ExecutionEngine *EE = builder.create()){ if (ExecutionEngine *EE = builder.create()){
@ -102,11 +102,11 @@ LLVMBool LLVMCreateExecutionEngine(LLVMExecutionEngineRef *OutEE,
return 1; return 1;
} }
LLVMBool LLVMCreateInterpreter(LLVMExecutionEngineRef *OutInterp, LLVMBool LLVMCreateInterpreterForModule(LLVMExecutionEngineRef *OutInterp,
LLVMModuleProviderRef MP, LLVMModuleRef M,
char **OutError) { char **OutError) {
std::string Error; std::string Error;
EngineBuilder builder(unwrap(MP)); EngineBuilder builder(unwrap(M));
builder.setEngineKind(EngineKind::Interpreter) builder.setEngineKind(EngineKind::Interpreter)
.setErrorStr(&Error); .setErrorStr(&Error);
if (ExecutionEngine *Interp = builder.create()) { if (ExecutionEngine *Interp = builder.create()) {
@ -117,12 +117,12 @@ LLVMBool LLVMCreateInterpreter(LLVMExecutionEngineRef *OutInterp,
return 1; return 1;
} }
LLVMBool LLVMCreateJITCompiler(LLVMExecutionEngineRef *OutJIT, LLVMBool LLVMCreateJITCompilerForModule(LLVMExecutionEngineRef *OutJIT,
LLVMModuleProviderRef MP, LLVMModuleRef M,
unsigned OptLevel, unsigned OptLevel,
char **OutError) { char **OutError) {
std::string Error; std::string Error;
EngineBuilder builder(unwrap(MP)); EngineBuilder builder(unwrap(M));
builder.setEngineKind(EngineKind::JIT) builder.setEngineKind(EngineKind::JIT)
.setErrorStr(&Error) .setErrorStr(&Error)
.setOptLevel((CodeGenOpt::Level)OptLevel); .setOptLevel((CodeGenOpt::Level)OptLevel);
@ -134,6 +134,35 @@ LLVMBool LLVMCreateJITCompiler(LLVMExecutionEngineRef *OutJIT,
return 1; return 1;
} }
LLVMBool LLVMCreateExecutionEngine(LLVMExecutionEngineRef *OutEE,
LLVMModuleProviderRef MP,
char **OutError) {
/* The module provider is now actually a module. */
return LLVMCreateExecutionEngineForModule(OutEE,
reinterpret_cast<LLVMModuleRef>(MP),
OutError);
}
LLVMBool LLVMCreateInterpreter(LLVMExecutionEngineRef *OutInterp,
LLVMModuleProviderRef MP,
char **OutError) {
/* The module provider is now actually a module. */
return LLVMCreateInterpreterForModule(OutInterp,
reinterpret_cast<LLVMModuleRef>(MP),
OutError);
}
LLVMBool LLVMCreateJITCompiler(LLVMExecutionEngineRef *OutJIT,
LLVMModuleProviderRef MP,
unsigned OptLevel,
char **OutError) {
/* The module provider is now actually a module. */
return LLVMCreateJITCompilerForModule(OutJIT,
reinterpret_cast<LLVMModuleRef>(MP),
OptLevel, OutError);
}
void LLVMDisposeExecutionEngine(LLVMExecutionEngineRef EE) { void LLVMDisposeExecutionEngine(LLVMExecutionEngineRef EE) {
delete unwrap(EE); delete unwrap(EE);
} }
@ -173,17 +202,29 @@ void LLVMFreeMachineCodeForFunction(LLVMExecutionEngineRef EE, LLVMValueRef F) {
unwrap(EE)->freeMachineCodeForFunction(unwrap<Function>(F)); unwrap(EE)->freeMachineCodeForFunction(unwrap<Function>(F));
} }
void LLVMAddModule(LLVMExecutionEngineRef EE, LLVMModuleRef M){
unwrap(EE)->addModule(unwrap(M));
}
void LLVMAddModuleProvider(LLVMExecutionEngineRef EE, LLVMModuleProviderRef MP){ void LLVMAddModuleProvider(LLVMExecutionEngineRef EE, LLVMModuleProviderRef MP){
unwrap(EE)->addModule(unwrap(MP)); /* The module provider is now actually a module. */
LLVMAddModule(EE, reinterpret_cast<LLVMModuleRef>(MP));
}
LLVMBool LLVMRemoveModule(LLVMExecutionEngineRef EE, LLVMModuleRef M,
LLVMModuleRef *OutMod, char **OutError) {
Module *Mod = unwrap(M);
unwrap(EE)->removeModule(Mod);
*OutMod = wrap(Mod);
return 0;
} }
LLVMBool LLVMRemoveModuleProvider(LLVMExecutionEngineRef EE, LLVMBool LLVMRemoveModuleProvider(LLVMExecutionEngineRef EE,
LLVMModuleProviderRef MP, LLVMModuleProviderRef MP,
LLVMModuleRef *OutMod, char **OutError) { LLVMModuleRef *OutMod, char **OutError) {
Module *M = unwrap(MP); /* The module provider is now actually a module. */
unwrap(EE)->removeModule(M); return LLVMRemoveModule(EE, reinterpret_cast<LLVMModuleRef>(MP), OutMod,
*OutMod = wrap(M); OutError);
return 0;
} }
LLVMBool LLVMFindFunction(LLVMExecutionEngineRef EE, const char *Name, LLVMBool LLVMFindFunction(LLVMExecutionEngineRef EE, const char *Name,

View File

@ -1712,8 +1712,13 @@ LLVMPassManagerRef LLVMCreatePassManager() {
return wrap(new PassManager()); return wrap(new PassManager());
} }
LLVMPassManagerRef LLVMCreateFunctionPassManagerForModule(LLVMModuleRef M) {
return wrap(new FunctionPassManager(unwrap(M)));
}
LLVMPassManagerRef LLVMCreateFunctionPassManager(LLVMModuleProviderRef P) { LLVMPassManagerRef LLVMCreateFunctionPassManager(LLVMModuleProviderRef P) {
return wrap(new FunctionPassManager(unwrap(P))); return LLVMCreateFunctionPassManagerForModule(
reinterpret_cast<LLVMModuleRef>(P));
} }
LLVMBool LLVMRunPassManager(LLVMPassManagerRef PM, LLVMModuleRef M) { LLVMBool LLVMRunPassManager(LLVMPassManagerRef PM, LLVMModuleRef M) {