[vmkit-commits] [vmkit] r199816 - Add an inlining pass in vmkit, which is able to inline functions from foreign modules.

Gael Thomas gael.thomas at lip6.fr
Wed Jan 22 08:51:04 PST 2014


Author: gthomas
Date: Wed Jan 22 10:51:04 2014
New Revision: 199816

URL: http://llvm.org/viewvc/llvm-project?rev=199816&view=rev
Log:
Add an inlining pass in vmkit, which is able to inline functions from foreign modules.
As we can inline anything, we have to be sure that all the functions generated during the compilation of VMKit are externally visible. For that purpose, vmkit-prepare-code changes the linkonce_odr linkage into a weak_odr linkage and a linkonce into a weak linkage.




Added:
    vmkit/branches/mcjit/include/vmkit/inliner.h
    vmkit/branches/mcjit/lib/vmkit-prepare-code/   (with props)
    vmkit/branches/mcjit/lib/vmkit-prepare-code/Makefile
    vmkit/branches/mcjit/lib/vmkit-prepare-code/adapt-linkage.cc
    vmkit/branches/mcjit/lib/vmkit/inliner.cc
Modified:
    vmkit/branches/mcjit/Makefile
    vmkit/branches/mcjit/Makefile.rules
    vmkit/branches/mcjit/include/j3/j3codegen.h
    vmkit/branches/mcjit/include/j3/j3meta.def
    vmkit/branches/mcjit/include/j3/j3method.h
    vmkit/branches/mcjit/include/j3/j3options.h
    vmkit/branches/mcjit/include/vmkit/compiler.h
    vmkit/branches/mcjit/include/vmkit/system.h
    vmkit/branches/mcjit/lib/j3/vm/j3.cc
    vmkit/branches/mcjit/lib/j3/vm/j3classloader.cc
    vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc
    vmkit/branches/mcjit/lib/j3/vm/j3method.cc
    vmkit/branches/mcjit/lib/j3/vm/j3options.cc
    vmkit/branches/mcjit/lib/vmkit/compiler.cc
    vmkit/branches/mcjit/lib/vmkit/safpoint.cc
    vmkit/branches/mcjit/tools/vmkit-extract/Makefile

Modified: vmkit/branches/mcjit/Makefile
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/Makefile?rev=199816&r1=199815&r2=199816&view=diff
==============================================================================
--- vmkit/branches/mcjit/Makefile (original)
+++ vmkit/branches/mcjit/Makefile Wed Jan 22 10:51:04 2014
@@ -5,6 +5,6 @@
 
 LEVEL := .
 
-DIRS := tools/vmkit-extract lib tools/j3 # lib/mmtk/
+DIRS := lib/vmkit-prepare-code tools/vmkit-extract lib tools/j3 # lib/mmtk/
 
 include $(LEVEL)/Makefile.rules

Modified: vmkit/branches/mcjit/Makefile.rules
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/Makefile.rules?rev=199816&r1=199815&r2=199816&view=diff
==============================================================================
--- vmkit/branches/mcjit/Makefile.rules (original)
+++ vmkit/branches/mcjit/Makefile.rules Wed Jan 22 10:51:04 2014
@@ -72,20 +72,20 @@ RECURSIVE_TARGETS=all clean
 define do_parallel_subdirs
 $1-parallel-recursive::
   #$(Echo) "Entering directory $$(PROF)/$2"
-	$(Verb) +$(MAKE) $(SUB_OPT) -C $2 $1 PROF=$(PROF)/$2; \
+	$(Verb) +$(MAKE) $(SUB_OPT) -C $2 $1 PROF=$(PROF)/$2 VERBOSE=$(VERBOSE); \
 		if [ $$$$? != 0 ]; then echo "$$(EchoMsg) abort with errors in $$(PROF)/$2"; exit 1; fi
 endef
 
 define do_recursive_target
 $1:
 	$(Verb) for f in $$(DIRS); do \
-					$(MAKE) $(SUB_OPT) -C $$$$f $1 PROF=$(PROF)/$$$$f; \
+					$(MAKE) $(SUB_OPT) -C $$$$f $1 PROF=$(PROF)/$$$$f VERBOSE=$(VERBOSE); \
 							if [ $$$$? != 0 ]; then echo "$$(EchoMsg) abort with errors in $$(PROF)/$$$$f"; exit 1; fi; \
 					done
-	$(Verb) +$(MAKE) -s $1-parallel-recursive
+	$(Verb) +$(MAKE) $(SUB_OPT) $1-parallel-recursive VERBOSE=$(VERBOSE)
 
 $1-parallel-recursive::
-	$(Verb) +$(MAKE) -s $1-local
+	$(Verb) +$(MAKE) $(SUB_OPT) $1-local VERBOSE=$(VERBOSE)
 
 $1-local::
 
@@ -291,17 +291,11 @@ SO_FILES=$(OBJ_FILES)
 endif
 
 ###############################################################################
-#   GC Managment
+#   Prepare the code
 ###############################################################################
-STATIC_GC_PASS_LIB=$(LIB_DIR)/static-gc-pass$(SHLIBEXT)
-STATIC_GC_PRINTER_LIB=$(LIB_DIR)/static-gc-printer$(SHLIBEXT)
-
-NO_GC=1
-ifdef NO_GC
-GC_OBJ_FILES=$(OBJ_FILES)
-else
-GC_OBJ_FILES=$(patsubst %.o,%-gc.o,$(OBJ_FILES))
-GC_LLCFLAGS:=-load=$(STATIC_GC_PRINTER_LIB)
+ifndef NO_PREPARE_CODE
+DO_PREPARE_CODE_LIB=$(LIB_DIR)/vmkit-prepare-code$(SHLIBEXT)
+DO_PREPARE_CODE=-load=$(DO_PREPARE_CODE_LIB) -VMKitAdaptLinkage
 endif
 
 ###############################################################################
@@ -311,29 +305,25 @@ DEPEND_OPTIONS=-MMD -MP -MF "$(BUILD_DIR
 DOM=then mv -f "$(BUILD_DIR)/$$*.d.tmp" "$(BUILD_DIR)/$$*.d"; else rm -f "$(BUILD_DIR)/$$*.d.tmp"; exit 1; fi
 
 $(SONAME)$(SHLIBEXT): $(SO_FILES)
-	$(Echo) "Linking shared library '$(notdir $@)'"
-	$(Verb) $(CLANGXX) -shared $(LLVM_LDFLAGS) $(SHFLAGS) -o $@ $(SHALL) $^ $(SHNOALL) $(SO_LIBS)
+	$(Echo) "Linking shared library '$(notdir $@)'" 
+	$(Verb) $(CLANGXX) -shared $(LLVM_LDFLAGS) $(SHFLAGS)  -o $@ $(SHALL) $^ $(SHNOALL) $(SO_LIBS)
 
 $(GEN_MODULE).bc: $(BC_FILES)
 	$(Echo) "Linking bc module '$(notdir $@)'"
 	$(Verb) $(LLLINK) $^ -o $@
 
-$(GEN_MODULE).a: $(GC_OBJ_FILES)
+$(GEN_MODULE).a: $(OBJ_FILES)
 	$(Echo) "Linking module '$(notdir $@)'"
 	$(Verb) ar cru $@ $^ && ranlib $@
 
-%.o: %.bc
+%.o: %.bc $(DO_PREPARE_CODE_LIB)
 	$(Echo) "Assembling '$(notdir $<)'"
-	$(Verb) $(LLC) $(LLCFLAGS) $(GC_LLCFLAGS) -filetype=obj $< -o $@
+	$(Verb) $(LLOPT) $(DO_PREPARE_CODE) $(OPTFLAGS) $< -o - | $(LLC) $(LLCFLAGS) -filetype=obj -o $@
 
 $(BUILD_DIR)/%.o: %.s $(SELF) $(BUILD_DIR)/.dir
 	$(Echo) "Assembling '$(notdir $<)'"
 	$(Verb) if $(CLANGXX) $(CXXFLAGS) $(DEPEND_OPTIONS) -c "$<" -o $@; $(DOM)
 
-%-gc.bc: %.bc
-	$(Echo) "Preparing GC '$(notdir $<)'"
-	$(Verb) $(LLOPT) -load=$(STATIC_GC_PASS_LIB) $(OPTFLAGS) -StaticGCPass $< -o $@
-
 define define_compile_rule
 $(BUILD_DIR)/%.bc: $4%$1 $(SELF) $(BUILD_DIR)/.dir
 	$(Echo) "Compiling '$$(notdir $$<)'"

Modified: vmkit/branches/mcjit/include/j3/j3codegen.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3codegen.h?rev=199816&r1=199815&r2=199816&view=diff
==============================================================================
--- vmkit/branches/mcjit/include/j3/j3codegen.h (original)
+++ vmkit/branches/mcjit/include/j3/j3codegen.h Wed Jan 22 10:51:04 2014
@@ -198,7 +198,7 @@ namespace j3 {
 		void                genDebugOpcode();
 		void                genDebugEnterLeave(bool isLeave);
 
-#define _x(name, id, isLocal)										\
+#define _x(name, id, forceInline)								\
 		llvm::Function* name;
 #include "j3/j3meta.def"
 #undef _x

Modified: vmkit/branches/mcjit/include/j3/j3meta.def
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3meta.def?rev=199816&r1=199815&r2=199816&view=diff
==============================================================================
--- vmkit/branches/mcjit/include/j3/j3meta.def (original)
+++ vmkit/branches/mcjit/include/j3/j3meta.def Wed Jan 22 10:51:04 2014
@@ -1,25 +1,25 @@
-_x(funcJ3ObjectTypeResolve,         "j3::J3Type::resolve()", 1)
-_x(funcJ3ObjectTypeInitialise,      "j3::J3Type::initialise()", 1)
-_x(funcJ3TypeJavaClass,             "j3::J3Type::javaClass(bool, j3::J3ObjectHandle*)", 1)
+_x(funcJ3ObjectTypeResolve,         "j3::J3Type::resolve()", 0)
+_x(funcJ3ObjectTypeInitialise,      "j3::J3Type::initialise()", 0)
+_x(funcJ3TypeJavaClass,             "j3::J3Type::javaClass(bool, j3::J3ObjectHandle*)", 0)
 _x(funcJniEnv,                      "j3::J3::jniEnv()", 1)
-_x(funcJ3ArrayObjectMultianewArray, "j3::J3ArrayObject::multianewArray(j3::J3ArrayClass*, unsigned int, unsigned int*)", 1)
-_x(funcJ3ObjectAllocate,            "j3::J3Object::allocate(j3::J3VirtualTable*, unsigned long)", 1)
-_x(funcJ3ObjectMonitorEnter,        "j3::J3Object::monitorEnter(j3::J3Object*)", 1)
-_x(funcJ3ObjectMonitorExit,         "j3::J3Object::monitorExit(j3::J3Object*)", 1)
-_x(funcThrowException,              "vmkit::VMKit::throwException(void*)", 1)
-_x(funcReplayException,             "j3::J3Thread::replayException()", 1)
-_x(funcClassCastException,          "j3::J3::classCastException()", 1)
-_x(funcNullPointerException,        "j3::J3::nullPointerException()", 1)
+_x(funcJ3ArrayObjectMultianewArray, "j3::J3ArrayObject::multianewArray(j3::J3ArrayClass*, unsigned int, unsigned int*)", 0)
+_x(funcJ3ObjectAllocate,            "j3::J3Object::allocate(j3::J3VirtualTable*, unsigned long)", 0)
+_x(funcJ3ObjectMonitorEnter,        "j3::J3Object::monitorEnter(j3::J3Object*)", 0)
+_x(funcJ3ObjectMonitorExit,         "j3::J3Object::monitorExit(j3::J3Object*)", 0)
+_x(funcThrowException,              "vmkit::VMKit::throwException(void*)", 0)
+_x(funcReplayException,             "j3::J3Thread::replayException()", 0)
+_x(funcClassCastException,          "j3::J3::classCastException()", 0)
+_x(funcNullPointerException,        "j3::J3::nullPointerException()", 0)
 _x(funcJ3ThreadPushHandle,          "j3::J3Thread::push(j3::J3ObjectHandle*)", 1)
 _x(funcJ3ThreadPush,                "j3::J3Thread::push(j3::J3Object*)", 1)
 _x(funcJ3ThreadTell,                "j3::J3Thread::tell()", 1)
 _x(funcJ3ThreadRestore,             "j3::J3Thread::restore(j3::J3ObjectHandle*)", 1)
-_x(funcEchoDebugEnter,              "j3::J3CodeGen::echoDebugEnter(unsigned int, char const*, ...)", 1)
-_x(funcEchoDebugExecute,            "j3::J3CodeGen::echoDebugExecute(unsigned int, char const*, ...)", 1)
-_x(funcEchoElement,                 "j3::J3CodeGen::echoElement(unsigned int, unsigned int, unsigned long)", 1)
-_x(funcFastIsAssignableToPrimaryChecker, "j3::J3VirtualTable::fastIsAssignableToPrimaryChecker(j3::J3VirtualTable*, unsigned int)", 0)
+_x(funcEchoDebugEnter,              "j3::J3CodeGen::echoDebugEnter(unsigned int, char const*, ...)", 0)
+_x(funcEchoDebugExecute,            "j3::J3CodeGen::echoDebugExecute(unsigned int, char const*, ...)", 0)
+_x(funcEchoElement,                 "j3::J3CodeGen::echoElement(unsigned int, unsigned int, unsigned long)", 0)
+_x(funcFastIsAssignableToPrimaryChecker, "j3::J3VirtualTable::fastIsAssignableToPrimaryChecker(j3::J3VirtualTable*, unsigned int)", 1)
 _x(funcFastIsAssignableToNonPrimaryChecker, "j3::J3VirtualTable::fastIsAssignableToNonPrimaryChecker(j3::J3VirtualTable*)", 0)
-_x(funcGXXPersonality,              "__gxx_personality_v0", 1)
-_x(funcCXABeginCatch,               "__cxa_begin_catch", 1)
-_x(funcCXAEndCatch,                 "__cxa_end_catch", 1)
-_x(funcFake,                        "j3::J3::forceSymbolDefinition()", 1)
+_x(funcGXXPersonality,              "__gxx_personality_v0", 0)
+_x(funcCXABeginCatch,               "__cxa_begin_catch", 0)
+_x(funcCXAEndCatch,                 "__cxa_end_catch", 0)
+_x(funcFake,                        "j3::J3::forceSymbolDefinition()", 0)

Modified: vmkit/branches/mcjit/include/j3/j3method.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3method.h?rev=199816&r1=199815&r2=199816&view=diff
==============================================================================
--- vmkit/branches/mcjit/include/j3/j3method.h (original)
+++ vmkit/branches/mcjit/include/j3/j3method.h Wed Jan 22 10:51:04 2014
@@ -96,7 +96,8 @@ namespace j3 {
 		void                ensureCompiled(uint32_t mode);
 		J3Signature::function_t cxxCaller();
 		void*               fnPtr();
-		llvm::Function*     llvmFunction() { return _llvmFunction; }
+		llvm::Function*     llvmFunction() { return _llvmFunction; } /* overwrite vmkit::Symbol */
+		bool                isInlinable();
 		void*               functionPointerOrStaticTrampoline();
 		void*               functionPointerOrVirtualTrampoline();
 

Modified: vmkit/branches/mcjit/include/j3/j3options.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3options.h?rev=199816&r1=199815&r2=199816&view=diff
==============================================================================
--- vmkit/branches/mcjit/include/j3/j3options.h (original)
+++ vmkit/branches/mcjit/include/j3/j3options.h Wed Jan 22 10:51:04 2014
@@ -53,6 +53,7 @@ namespace j3 {
 
 		bool           isAOT;
 		const char*    aotFile;
+		bool           enableInlining;
 
 		J3Options();
 

Modified: vmkit/branches/mcjit/include/vmkit/compiler.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/vmkit/compiler.h?rev=199816&r1=199815&r2=199816&view=diff
==============================================================================
--- vmkit/branches/mcjit/include/vmkit/compiler.h (original)
+++ vmkit/branches/mcjit/include/vmkit/compiler.h Wed Jan 22 10:51:04 2014
@@ -10,6 +10,7 @@ namespace llvm {
 	class Module;
 	class ExecutionEngine;
 	class GlobalValue;
+	class Function;
 
 	namespace legacy {
 		class PassManager;
@@ -23,15 +24,20 @@ namespace vmkit {
 
 	class Symbol : public PermanentObject {
 	public:
-		virtual void* getSymbolAddress();
+		virtual void*           getSymbolAddress();
+		virtual llvm::Function* llvmFunction() { return 0; }
+		virtual bool            isInlinable() { return 0; }
 	};
 
 	class NativeSymbol : public Symbol {
-		void* addr;
+		llvm::Function* original;
+		void*           addr;
 	public:
-		NativeSymbol(void* _addr) { addr = _addr; }
+		NativeSymbol(llvm::Function* _original, void* _addr) { original = _original; addr = _addr; }
 
-		void* getSymbolAddress() { return addr; }
+		llvm::Function* llvmFunction() { return original; }
+		void*           getSymbolAddress() { return addr; }
+		virtual bool    isInlinable() { return 1; }
 	};
 
 	class CompilationUnit  : public llvm::SectionMemoryManager {
@@ -55,7 +61,7 @@ namespace vmkit {
 		static void destroy(CompilationUnit* unit);
 
 		void                    addSymbol(const char* id, vmkit::Symbol* symbol);
-		Symbol*                 getSymbol(const char* id);
+		Symbol*                 getSymbol(const char* id, bool error=1);
 		uint64_t                getSymbolAddress(const std::string &Name);
 
 		BumpAllocator*          allocator() { return _allocator; }

Added: vmkit/branches/mcjit/include/vmkit/inliner.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/vmkit/inliner.h?rev=199816&view=auto
==============================================================================
--- vmkit/branches/mcjit/include/vmkit/inliner.h (added)
+++ vmkit/branches/mcjit/include/vmkit/inliner.h Wed Jan 22 10:51:04 2014
@@ -0,0 +1,12 @@
+#ifndef _INLINER_H_
+#define _INLINER_H_
+
+#include "llvm/Pass.h"
+
+namespace vmkit {
+	class CompilationUnit;
+
+	llvm::FunctionPass* createFunctionInlinerPass(CompilationUnit* compiler);
+}
+
+#endif

Modified: vmkit/branches/mcjit/include/vmkit/system.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/vmkit/system.h?rev=199816&r1=199815&r2=199816&view=diff
==============================================================================
--- vmkit/branches/mcjit/include/vmkit/system.h (original)
+++ vmkit/branches/mcjit/include/vmkit/system.h Wed Jan 22 10:51:04 2014
@@ -24,11 +24,11 @@
 namespace vmkit {
 	class System {
 	public:
-		static const char* mcjitSymbol(const std::string &Name) {
+		static const char* mcjitSymbol(const char* name) {
 #if defined(MACOS_OS)
-			return Name.c_str() + 1;
+			return name + 1;
 #elif defined(LINUX_OS)
-			return Name.c_str();
+			return name;
 #else
 #error "what is the correct symbol for your os?"
 #endif

Modified: vmkit/branches/mcjit/lib/j3/vm/j3.cc
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3.cc?rev=199816&r1=199815&r2=199816&view=diff
==============================================================================
--- vmkit/branches/mcjit/lib/j3/vm/j3.cc (original)
+++ vmkit/branches/mcjit/lib/j3/vm/j3.cc Wed Jan 22 10:51:04 2014
@@ -90,13 +90,19 @@ void J3::start(int argc, char** argv) {
 }
 
 void J3::run() {
-#define defJavaConstantName(name, id) \
+#define defJavaConstantName(name, id)						\
 	name = names()->get(id);
 	onJavaConstantNames(defJavaConstantName)
 #undef defJavaConstantName
 
 	introspect();
 
+#define _x(name, id, forceInline)																				\
+	if(forceInline)																												\
+		introspectFunction(0, id)->addFnAttr(llvm::Attribute::AlwaysInline);
+#include "j3/j3meta.def"
+#undef _x
+
 	vmkit::BumpAllocator* loaderAllocator = vmkit::BumpAllocator::create();
 	initialClassLoader = new(loaderAllocator) J3InitialClassLoader(loaderAllocator);
 

Modified: vmkit/branches/mcjit/lib/j3/vm/j3classloader.cc
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3classloader.cc?rev=199816&r1=199815&r2=199816&view=diff
==============================================================================
--- vmkit/branches/mcjit/lib/j3/vm/j3classloader.cc (original)
+++ vmkit/branches/mcjit/lib/j3/vm/j3classloader.cc Wed Jan 22 10:51:04 2014
@@ -5,6 +5,7 @@
 #include "llvm/ExecutionEngine/ExecutionEngine.h"
 
 #include "vmkit/allocator.h"
+#include "vmkit/system.h"
 
 #include "j3/j3classloader.h"
 #include "j3/j3.h"
@@ -38,6 +39,16 @@ J3ClassLoader::J3ClassLoader(J3ObjectHan
 	pthread_mutex_init(&_mutexNativeLibraries, 0);
 
 	_javaClassLoader = globalReferences()->add(javaClassLoader);
+
+	J3* vm = J3Thread::get()->vm();
+#define _x(name, id, forceInline)																				\
+	{																																			\
+		llvm::Function* function = vm->introspectFunction(0, id);						\
+		void* addr = dlsym(SELF_HANDLE, function->getName().data());				\
+		addSymbol(function->getName().data(), new(allocator) vmkit::NativeSymbol(function, addr)); \
+	}
+#include "j3/j3meta.def"
+#undef _x
 }
 
 J3StringSymbol* J3ClassLoader::newStringSymbol(J3ObjectHandle* handle) {

Modified: vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc?rev=199816&r1=199815&r2=199816&view=diff
==============================================================================
--- vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc (original)
+++ vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc Wed Jan 22 10:51:04 2014
@@ -72,8 +72,8 @@ J3CodeGen::J3CodeGen(vmkit::BumpAllocato
 	uintPtrTy = vm->dataLayout()->getIntPtrType(module->getContext());
 	nullValue = llvm::ConstantPointerNull::get((llvm::PointerType*)vm->typeJ3ObjectPtr);
 
-#define _x(name, id, isLocal)											\
-	name = vm->introspectFunction(isLocal ? module : 0, id);
+#define _x(name, id, forceInline)											\
+	name = vm->introspectFunction(forceInline ? 0 : module, id);
 #include "j3/j3meta.def"
 #undef _x
 
@@ -609,7 +609,7 @@ void J3CodeGen::newObject(J3Class* cl) {
 }
 
 llvm::CallInst* J3CodeGen::isAssignableTo(llvm::Value* obj, J3ObjectType* type) {
-	llvm::Value* vtType = vt(type); /* force the resolution of type */
+	llvm::Value* vtType = vt(type); /* force the type resolution */
 	llvm::Value* vtObj = vt(obj);
 
 	if(type->vt()->isPrimaryChecker())
@@ -624,8 +624,8 @@ llvm::CallInst* J3CodeGen::isAssignableT
 }
 
 void J3CodeGen::inlineCall(llvm::CallInst* call) {
-	llvm::InlineFunctionInfo ifi;
-	llvm::InlineFunction(call, ifi, 0);
+	//llvm::InlineFunctionInfo ifi;
+	//llvm::InlineFunction(call, ifi, 0);
 }
 
 void J3CodeGen::instanceof(llvm::Value* obj, J3ObjectType* type) {
@@ -1820,7 +1820,7 @@ llvm::Function* J3CodeGen::lookupNative(
 																							 buf,
 																							 module);
 
-	loader->addSymbol(buf, new(loader->allocator()) vmkit::NativeSymbol(fnPtr));
+	loader->addSymbol(buf, new(loader->allocator()) vmkit::NativeSymbol(0, fnPtr));
 
 	return res;
 }

Modified: vmkit/branches/mcjit/lib/j3/vm/j3method.cc
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3method.cc?rev=199816&r1=199815&r2=199816&view=diff
==============================================================================
--- vmkit/branches/mcjit/lib/j3/vm/j3method.cc (original)
+++ vmkit/branches/mcjit/lib/j3/vm/j3method.cc Wed Jan 22 10:51:04 2014
@@ -31,6 +31,10 @@ J3Method::J3Method(uint16_t access, J3Cl
 	_index = -1;
 }
 
+bool J3Method::isInlinable() {
+	return J3Thread::get()->vm()->options()->enableInlining;
+}
+
 uint32_t J3Method::interfaceIndex() {
 	return cl()->loader()->interfaceIndex(this);
 }

Modified: vmkit/branches/mcjit/lib/j3/vm/j3options.cc
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3options.cc?rev=199816&r1=199815&r2=199816&view=diff
==============================================================================
--- vmkit/branches/mcjit/lib/j3/vm/j3options.cc (original)
+++ vmkit/branches/mcjit/lib/j3/vm/j3options.cc Wed Jan 22 10:51:04 2014
@@ -29,6 +29,7 @@ J3Options::J3Options() {
 	stackSize = 0x80*0x1000;
 
 	isAOT = 0;
+	enableInlining = 1;
 }
 
 #define nyi(cmd) ({ fprintf(stderr, "option '%s' not yet implemented\n", cmd); })
@@ -77,6 +78,7 @@ void J3CmdLineParser::process() {
 		else if(opteq("-Xaot")) {
 			options->isAOT = 1;
 			options->aotFile = argv[++cur];
+			options->enableInlining = 0;
 		} else if(opteq("-Xno-aot"))
 			options->isAOT = 0;
 		else if(optbeg("-X"))

Propchange: vmkit/branches/mcjit/lib/vmkit-prepare-code/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Wed Jan 22 10:51:04 2014
@@ -0,0 +1 @@
+Debug+Asserts

Added: vmkit/branches/mcjit/lib/vmkit-prepare-code/Makefile
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/vmkit-prepare-code/Makefile?rev=199816&view=auto
==============================================================================
--- vmkit/branches/mcjit/lib/vmkit-prepare-code/Makefile (added)
+++ vmkit/branches/mcjit/lib/vmkit-prepare-code/Makefile Wed Jan 22 10:51:04 2014
@@ -0,0 +1,16 @@
+##===- lib/vmkit/StaticGCPass/Makefile -----------------------*- Makefile -*-===##
+#
+#                            The VMKit project
+#
+# This file is distributed under the University of Illinois Open Source
+# License. See LICENSE.TXT for details.
+#
+##===----------------------------------------------------------------------===##
+
+LEVEL = ../..
+
+NO_PREPARE_CODE=1
+LIBRARY=vmkit-prepare-code
+
+include $(LEVEL)/Makefile.rules
+

Added: vmkit/branches/mcjit/lib/vmkit-prepare-code/adapt-linkage.cc
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/vmkit-prepare-code/adapt-linkage.cc?rev=199816&view=auto
==============================================================================
--- vmkit/branches/mcjit/lib/vmkit-prepare-code/adapt-linkage.cc (added)
+++ vmkit/branches/mcjit/lib/vmkit-prepare-code/adapt-linkage.cc Wed Jan 22 10:51:04 2014
@@ -0,0 +1,42 @@
+//===---- StaticGCPass.cpp - Put GC information in functions compiled --------//
+//===----------------------- with llvm-gcc --------------------------------===//
+//
+//                     The VMKit project
+//
+// This file is distributed under the University of Illinois Open Source 
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+
+#include "llvm/IR/Intrinsics.h"
+#include "llvm/IR/Module.h"
+#include "llvm/Pass.h"
+#include "llvm/Support/raw_ostream.h"
+
+#include <cstdio>
+
+namespace vmkit {
+  class VMKitAdaptLinkage : public llvm::FunctionPass {
+  public:
+    static char ID;
+    
+    VMKitAdaptLinkage() : llvm::FunctionPass(ID) {}
+
+    virtual bool runOnFunction(llvm::Function& function) { 
+			llvm::Function::LinkageTypes linkage = function.getLinkage();
+
+			if(linkage == llvm::GlobalValue::LinkOnceODRLinkage)
+				function.setLinkage(llvm::GlobalValue::WeakODRLinkage);
+			if(linkage == llvm::GlobalValue::LinkOnceAnyLinkage)
+				function.setLinkage(llvm::GlobalValue::WeakAnyLinkage);
+			//if(linkage
+			//fprintf(stderr, "run on function: %s\n", function.getName().data());
+			return 0;
+		}
+  };
+
+  char VMKitAdaptLinkage::ID = 0;
+	llvm::RegisterPass<VMKitAdaptLinkage> X("VMKitAdaptLinkage",
+																					"Adapt the linkage for vmkit");
+}

Modified: vmkit/branches/mcjit/lib/vmkit/compiler.cc
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/vmkit/compiler.cc?rev=199816&r1=199815&r2=199816&view=diff
==============================================================================
--- vmkit/branches/mcjit/lib/vmkit/compiler.cc (original)
+++ vmkit/branches/mcjit/lib/vmkit/compiler.cc Wed Jan 22 10:51:04 2014
@@ -5,6 +5,7 @@
 #include "vmkit/thread.h"
 #include "vmkit/vmkit.h"
 #include "vmkit/safepoint.h"
+#include "vmkit/inliner.h"
 
 #include "llvm/LinkAllPasses.h"
 #include "llvm/PassManager.h"
@@ -62,7 +63,8 @@ CompilationUnit::CompilationUnit(BumpAll
 #if 0
 	pm->add(llvm::createBasicAliasAnalysisPass());
 #endif
-	
+
+	pm->add(vmkit::createFunctionInlinerPass(this));
 	pm->add(llvm::createCFGSimplificationPass());      // Clean up disgusting code
 
 #if 0
@@ -114,21 +116,25 @@ void CompilationUnit::addSymbol(const ch
 	pthread_mutex_unlock(&_mutexSymbolTable);
 }
 
-Symbol* CompilationUnit::getSymbol(const char* id) {
+Symbol* CompilationUnit::getSymbol(const char* id, bool error) {
 	pthread_mutex_lock(&_mutexSymbolTable);
 
 	std::map<const char*, vmkit::Symbol*>::iterator it = _symbolTable.find(id);
-	vmkit::Symbol* res;
+	vmkit::Symbol* res = 0;
 
 	if(it == _symbolTable.end()) {
 		uint8_t* addr = (uint8_t*)dlsym(SELF_HANDLE, id);
-		if(!addr)
-			Thread::get()->vm()->internalError("unable to resolve native symbol: %s", id);
-		res = new(allocator()) vmkit::NativeSymbol(addr);
-		size_t len = strlen(id);
-		char* buf = (char*)allocator()->allocate(len+1);
-		memcpy(buf, id, len+1);
-		_symbolTable[buf] = res;
+		//fprintf(stderr, "lookup: %s => %p\n", id, addr);
+		if(!addr) {
+			if(error)
+				Thread::get()->vm()->internalError("unable to resolve native symbol: %s", id);
+		} else {
+			res = new(allocator()) vmkit::NativeSymbol(0, addr);
+			size_t len = strlen(id);
+			char* buf = (char*)allocator()->allocate(len+1);
+			memcpy(buf, id, len+1);
+			_symbolTable[buf] = res;
+		}
 	} else
 		res = it->second;
 
@@ -137,7 +143,7 @@ Symbol* CompilationUnit::getSymbol(const
 }
 
 uint64_t CompilationUnit::getSymbolAddress(const std::string &Name) {
-	return (uint64_t)(uintptr_t)getSymbol(System::mcjitSymbol(Name))->getSymbolAddress();
+	return (uint64_t)(uintptr_t)getSymbol(System::mcjitSymbol(Name.c_str()))->getSymbolAddress();
 }
 
 void CompilationUnit::compileModule(llvm::Module* module) {

Added: vmkit/branches/mcjit/lib/vmkit/inliner.cc
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/vmkit/inliner.cc?rev=199816&view=auto
==============================================================================
--- vmkit/branches/mcjit/lib/vmkit/inliner.cc (added)
+++ vmkit/branches/mcjit/lib/vmkit/inliner.cc Wed Jan 22 10:51:04 2014
@@ -0,0 +1,105 @@
+#include "llvm/IR/Function.h"
+#include "llvm/IR/Instructions.h"
+#include "llvm/IR/Module.h"
+#include "llvm/Pass.h"
+#include "llvm/Support/CallSite.h"
+//#include "llvm/Target/TargetData.h"
+#include "llvm/Analysis/InlineCost.h"
+#include "llvm/ADT/SmallPtrSet.h"
+#include "llvm/Transforms/Utils/Cloning.h"
+
+#include "vmkit/compiler.h"
+
+namespace vmkit {
+  class FunctionInliner : public llvm::FunctionPass {
+  public:
+    static char ID;
+
+		CompilationUnit*                             compiler;
+		llvm::InlineCostAnalysis                     costAnalysis;
+		unsigned int                                 inlineThreshold;
+
+		//FunctionInliner() : FunctionPass(ID) {}
+    FunctionInliner(CompilationUnit* _compiler, unsigned int _inlineThreshold=225) : FunctionPass(ID) { 
+			compiler = _compiler;
+			inlineThreshold = _inlineThreshold; 
+		}
+
+    virtual const char* getPassName() const {
+      return "Simple inliner";
+    }
+
+		llvm::InlineCost getInlineCost(llvm::CallSite callSite, llvm::Function* callee) {
+			return costAnalysis.getInlineCost(callSite, inlineThreshold);
+		}
+
+    virtual bool runOnFunction(llvm::Function &function);
+  private:
+  };
+
+  char FunctionInliner::ID = 0;
+
+#if 0
+	llvm::RegisterPass<FunctionInliner> X("FunctionInliner",
+																				"Inlining Pass that inlines evaluator's functions.");
+#endif
+
+	bool FunctionInliner::runOnFunction(llvm::Function& function) {
+		bool Changed = false;
+
+		for (llvm::Function::iterator bit=function.begin(); bit!=function.end(); bit++) { 
+			llvm::BasicBlock* bb = bit; 
+
+			for(llvm::BasicBlock::iterator it=bb->begin(); it!=bb->end();) {
+				llvm::Instruction *insn = it++;
+
+				if (insn->getOpcode() != llvm::Instruction::Call &&
+						insn->getOpcode() != llvm::Instruction::Invoke) {
+					continue;
+				}
+
+				llvm::CallSite  call(insn);
+				llvm::Function* original = call.getCalledFunction();
+				llvm::Function* callee = original;
+
+				if(!callee)
+					continue;
+
+				if(callee->isDeclaration()) { /* ok, resolve */
+					Symbol* s = compiler->getSymbol(callee->getName().data(), 0);
+					
+					if(s && s->isInlinable())
+						callee = s->llvmFunction();
+				}
+
+				if(callee && !callee->isDeclaration()) {
+					llvm::InlineCost cost = getInlineCost(call, callee);
+					if(cost.isAlways()) {// || (!cost.isNever() && (cost))) {
+						//fprintf(stderr, "----   Inlining: %s\n", callee->getName().data());
+
+						llvm::InlineFunctionInfo ifi(0);
+						bool isInlined = llvm::InlineFunction(call, ifi, false);
+						Changed |= isInlined;
+
+						if(isInlined){
+							it = bb->begin();
+							continue;
+						}
+					}
+				}
+
+				if(original->getParent() != function.getParent()) {
+					callee = (llvm::Function*)function.getParent()->getOrInsertFunction(original->getName(), original->getFunctionType());
+					original->replaceAllUsesWith(callee);
+					Changed = 1;
+				}
+			}
+		}
+
+		return Changed;
+	}
+
+	llvm::FunctionPass* createFunctionInlinerPass(CompilationUnit* compiler) {
+		return new FunctionInliner(compiler);
+	}
+}

Modified: vmkit/branches/mcjit/lib/vmkit/safpoint.cc
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/vmkit/safpoint.cc?rev=199816&r1=199815&r2=199816&view=diff
==============================================================================
--- vmkit/branches/mcjit/lib/vmkit/safpoint.cc (original)
+++ vmkit/branches/mcjit/lib/vmkit/safpoint.cc Wed Jan 22 10:51:04 2014
@@ -189,7 +189,7 @@ Safepoint* Safepoint::get(CompilationUni
 	symName += '_';
 	symName += module->getModuleIdentifier();
 	symName += "__frametable";
-	return (vmkit::Safepoint*)unit->ee()->getGlobalValueAddress(System::mcjitSymbol(symName));
+	return (vmkit::Safepoint*)unit->ee()->getGlobalValueAddress(System::mcjitSymbol(symName.c_str()));
 }
 
 void Safepoint::dump() {

Modified: vmkit/branches/mcjit/tools/vmkit-extract/Makefile
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/tools/vmkit-extract/Makefile?rev=199816&r1=199815&r2=199816&view=diff
==============================================================================
--- vmkit/branches/mcjit/tools/vmkit-extract/Makefile (original)
+++ vmkit/branches/mcjit/tools/vmkit-extract/Makefile Wed Jan 22 10:51:04 2014
@@ -5,6 +5,7 @@
 
 LEVEL := ../..
 
+NO_PREPARE_CODE=1
 LIBS := 
 TOOL := vmkit-extract
 





More information about the vmkit-commits mailing list