D dynamic compilation support

This commit is contained in:
Ivan 2016-12-03 21:14:42 +03:00
parent 1c2271d00d
commit 42f283c221
41 changed files with 2058 additions and 9 deletions

View file

@ -39,6 +39,7 @@
#include "gen/pgo.h"
#include "gen/pragma.h"
#include "gen/runtime.h"
#include "gen/runtimecompile.h"
#include "gen/scope_exit.h"
#include "gen/tollvm.h"
#include "gen/uda.h"
@ -463,6 +464,18 @@ void applyTargetMachineAttributes(llvm::Function &func,
opts::disableFpElim ? "true" : "false");
}
LLFunction* getFunction(llvm::Module& module, LLFunctionType *functype, const std::string& name) {
assert(nullptr != functype);
LLFunction* func = module.getFunction(name);
if (!func) {
// All function declarations are "external" - any other linkage type
// is set when actually defining the function.
func = LLFunction::Create(functype, llvm::GlobalValue::ExternalLinkage,
name, &module);
}
return func;
}
} // anonymous namespace
////////////////////////////////////////////////////////////////////////////////
@ -522,7 +535,7 @@ void DtoDeclareFunction(FuncDeclaration *fdecl) {
const auto link = forceC ? LINKc : f->linkage;
// mangled name
std::string mangledName = getMangledName(fdecl, link);
const std::string mangledName = getMangledName(fdecl, link);
// construct function
LLFunctionType *functype = DtoFunctionType(fdecl);
@ -566,6 +579,10 @@ void DtoDeclareFunction(FuncDeclaration *fdecl) {
applyTargetMachineAttributes(*func, *gTargetMachine);
applyFuncDeclUDAs(fdecl, irFunc);
if(irFunc->runtimeCompile) {
declareRuntimeCompiledFunction(gIR, irFunc);
}
// main
if (fdecl->isMain()) {
// Detect multiple main functions, which is disallowed. DMD checks this
@ -909,14 +926,20 @@ void DtoDefineFunction(FuncDeclaration *fd, bool linkageAvailableExternally) {
}
}
IrFunction *irFunc = getIrFunc(fd);
SCOPE_EXIT {
if (irFunc->runtimeCompile) {
defineRuntimeCompiledFunction(gIR, irFunc);
}
};
// if this function is naked, we take over right away! no standard processing!
if (fd->naked) {
DtoDefineNakedFunction(fd);
return;
}
IrFunction *irFunc = getIrFunc(fd);
// debug info
irFunc->diSubprogram = gIR->DBuilder.EmitSubProgram(fd);