Skip to content

Commit

Permalink
Merge pull request #17401 from JuliaLang/jn/split-codegen-jitlayers
Browse files Browse the repository at this point in the history
split JIT out of codegen
  • Loading branch information
vtjnash authored Jul 14, 2016
2 parents edb112a + 5218dc6 commit bc9b765
Show file tree
Hide file tree
Showing 7 changed files with 654 additions and 494 deletions.
5 changes: 3 additions & 2 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ endif
LLVMLINK :=

ifeq ($(JULIACODEGEN),LLVM)
SRCS += codegen disasm debuginfo llvm-simdloop llvm-gcroot cgmemmgr
SRCS += codegen jitlayers disasm debuginfo llvm-simdloop llvm-gcroot cgmemmgr
FLAGS += -I$(shell $(LLVM_CONFIG_HOST) --includedir)
LLVM_LIBS := all
ifeq ($(USE_POLLY),1)
Expand Down Expand Up @@ -139,10 +139,11 @@ $(BUILDDIR)/julia_flisp.boot: $(addprefix $(SRCDIR)/,jlfrontend.scm \

# additional dependency links
$(BUILDDIR)/ast.o $(BUILDDIR)/ast.dbg.obj: $(BUILDDIR)/julia_flisp.boot.inc $(SRCDIR)/flisp/*.h
$(BUILDDIR)/codegen.o $(BUILDDIR)/codegen.dbg.obj: $(addprefix $(SRCDIR)/,intrinsics.cpp jitlayers.cpp intrinsics.h codegen_internal.h cgutils.cpp ccall.cpp abi_*.cpp)
$(BUILDDIR)/codegen.o $(BUILDDIR)/codegen.dbg.obj: $(addprefix $(SRCDIR)/,intrinsics.cpp jitlayers.h intrinsics.h codegen_internal.h cgutils.cpp ccall.cpp abi_*.cpp)
$(BUILDDIR)/anticodegen.o $(BUILDDIR)/anticodegen.dbg.obj: $(SRCDIR)/intrinsics.h
$(BUILDDIR)/debuginfo.o $(BUILDDIR)/debuginfo.dbg.obj: $(SRCDIR)/codegen_internal.h
$(BUILDDIR)/disasm.o $(BUILDDIR)/disasm.dbg.obj: $(SRCDIR)/codegen_internal.h
$(BUILDDIR)/jitlayers.o $(BUILDDIR)/jitlayers.dbg.obj: $(SRCDIR)/jitlayers.h
$(BUILDDIR)/builtins.o $(BUILDDIR)/builtins.dbg.obj: $(SRCDIR)/table.c
$(BUILDDIR)/gc.o $(BUILDDIR)/gc.dbg.obj: $(SRCDIR)/gc.h
$(BUILDDIR)/gc-debug.o $(BUILDDIR)/gc-debug.dbg.obj: $(SRCDIR)/gc.h
Expand Down
2 changes: 1 addition & 1 deletion src/ccall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ static Value *emit_plt(FunctionType *functype, const AttributeSet &attrs,
}
builder.SetInsertPoint(old);
builder.SetCurrentDebugLocation(olddl);
jl_finalize_module(std::unique_ptr<Module>(M), true);
jl_finalize_module(M, true);
auto shadowgot =
cast<GlobalVariable>(shadow_output->getNamedValue(gname));
auto shadowplt = cast<Function>(shadow_output->getNamedValue(fname));
Expand Down
28 changes: 1 addition & 27 deletions src/cgutils.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// This file is a part of Julia. License is MIT: http://julialang.org/license

#include <iostream>

// utility procedures used in code generation

static Instruction *tbaa_decorate(MDNode *md, Instruction *load_or_store)
Expand All @@ -10,17 +8,6 @@ static Instruction *tbaa_decorate(MDNode *md, Instruction *load_or_store)
return load_or_store;
}

static GlobalVariable *prepare_global(GlobalVariable *G, Module *M)
{
if (G->getParent() == M)
return G;
GlobalValue *local = M->getNamedValue(G->getName());
if (!local) {
local = global_proto(G, M);
}
return cast<GlobalVariable>(local);
}

static llvm::Value *prepare_call(llvm::Value *Callee)
{
if (Function *F = dyn_cast<Function>(Callee)) {
Expand Down Expand Up @@ -189,20 +176,7 @@ static Value *literal_static_pointer_val(const void *p, Type *t)
static Value *julia_gv(const char *cname, void *addr)
{
// emit a GlobalVariable for a jl_value_t named "cname"
std::map<void*, jl_value_llvm>::iterator it;
// first see if there already is a GlobalVariable for this address
it = jl_value_to_llvm.find(addr);
if (it != jl_value_to_llvm.end())
return tbaa_decorate(tbaa_const, builder.CreateLoad(prepare_global((llvm::GlobalVariable*)it->second.gv)));

std::stringstream gvname;
gvname << cname << globalUnique++;
// no existing GlobalVariable, create one and store it
GlobalVariable *gv = new GlobalVariable(*jl_builderModule, T_pjlvalue,
false, GlobalVariable::ExternalLinkage,
NULL, gvname.str());
addComdat(gv);
*(void**)jl_emit_and_add_to_shadow(gv, addr) = addr;
GlobalVariable *gv = jl_get_global_for(cname, addr, jl_builderModule);
return tbaa_decorate(tbaa_const, builder.CreateLoad(gv));
}

Expand Down
Loading

0 comments on commit bc9b765

Please sign in to comment.