Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

experiment with the LLVM interpreter for #eval (disabled for now)

  • Loading branch information...
commit ab4212c96e63398a4df3bf965759fb6b77bed822 1 parent 4766186
Laurent Sansonetti authored
View
2  eval.c
@@ -195,7 +195,7 @@ ruby_run_node(void *n)
return FIX2INT(n);
}
rb_vm_set_running(true);
- rb_vm_run(RSTRING_PTR(rb_progname), (NODE *)n, NULL);
+ rb_vm_run(RSTRING_PTR(rb_progname), (NODE *)n, NULL, false);
return ruby_cleanup(0);
}
View
2  load.c
@@ -287,7 +287,7 @@ rb_load(VALUE fname, int wrap)
if (node == NULL) {
rb_raise(rb_eSyntaxError, "compile error");
}
- rb_vm_run(fname_str, node, NULL);
+ rb_vm_run(fname_str, node, NULL, false);
}
void
View
4 rakelib/builder.rb
@@ -83,7 +83,7 @@ def do_option(name, default)
INSTALL_NAME = File.join(FRAMEWORK_USR_LIB, 'lib' + RUBY_SO_NAME + '.dylib')
ARCHFLAGS = ARCHS.map { |a| '-arch ' + a }.join(' ')
-LLVM_MODULES = "core jit nativecodegen"
+LLVM_MODULES = "core jit nativecodegen interpreter"
CFLAGS = "-I. -I./include -I/usr/include/libxml2 #{ARCHFLAGS} -fno-common -pipe -O3 -g -Wall -fexceptions"
CFLAGS << " -Wno-parentheses -Wno-deprecated-declarations -Werror" if NO_WARN_BUILD
OBJC_CFLAGS = CFLAGS + " -fobjc-gc-only"
@@ -235,4 +235,4 @@ def dependencies
end
end
-$builder = Builder.new(OBJS)
+$builder = Builder.new(OBJS)
View
56 roxor.cpp
@@ -3,7 +3,7 @@
#define ROXOR_COMPILER_DEBUG 0
#define ROXOR_VM_DEBUG 0
#define ROXOR_DUMP_IR_BEFORE_EXIT 0
-#define ROXOR_ULTRA_LAZY_JIT 0
+#define ROXOR_ULTRA_LAZY_JIT 1
#include <llvm/Module.h>
#include <llvm/DerivedTypes.h>
@@ -16,6 +16,7 @@
#include <llvm/Target/TargetData.h>
#include <llvm/ExecutionEngine/JIT.h>
#include <llvm/ExecutionEngine/JITMemoryManager.h>
+#include <llvm/ExecutionEngine/GenericValue.h>
#include <llvm/Target/TargetData.h>
#include <llvm/Target/TargetMachine.h>
#include <llvm/Target/TargetOptions.h>
@@ -399,6 +400,7 @@ class RoxorVM
ExistingModuleProvider *emp;
RoxorJITManager *jmm;
ExecutionEngine *ee;
+ ExecutionEngine *iee;
FunctionPassManager *fpm;
bool running;
@@ -441,6 +443,7 @@ class RoxorVM
RoxorVM(void);
IMP compile(Function *func);
+ VALUE interpret(Function *func);
bool symbolize_call_address(void *addr, void **startp,
unsigned long *ln, char *name, size_t name_len);
@@ -2223,6 +2226,7 @@ RoxorVM::RoxorVM(void)
emp = new ExistingModuleProvider(RoxorCompiler::module);
jmm = new RoxorJITManager;
ee = ExecutionEngine::createJIT(emp, 0, jmm, true);
+ assert(ee != NULL);
fpm = new FunctionPassManager(emp);
fpm->add(new TargetData(*ee->getTargetData()));
@@ -2239,6 +2243,9 @@ RoxorVM::RoxorVM(void)
fpm->add(createCFGSimplificationPass());
// Eliminate tail calls.
fpm->add(createTailCallEliminationPass());
+
+ iee = ExecutionEngine::create(emp, true);
+ assert(iee != NULL);
}
IMP
@@ -2277,6 +2284,15 @@ RoxorVM::compile(Function *func)
return imp;
}
+VALUE
+RoxorVM::interpret(Function *func)
+{
+ std::vector<GenericValue> args;
+ args.push_back(PTOGV((void *)GET_VM()->current_top_object));
+ args.push_back(PTOGV(NULL));
+ return (VALUE)iee->runFunction(func, args).IntVal.getZExtValue();
+}
+
bool
RoxorVM::symbolize_call_address(void *addr, void **startp, unsigned long *ln,
char *name, size_t name_len)
@@ -6811,41 +6827,41 @@ rb_dvar_defined(ID id)
}
extern "C"
-IMP
-rb_vm_compile(const char *fname, NODE *node)
-{
- assert(node != NULL);
-
- RoxorCompiler *compiler = new RoxorCompiler(fname);
-
- Function *function = compiler->compile_main_function(node);
-
- delete compiler;
-
- return GET_VM()->compile(function);
-}
-
-extern "C"
VALUE
-rb_vm_run(const char *fname, NODE *node, rb_vm_binding_t *binding)
+rb_vm_run(const char *fname, NODE *node, rb_vm_binding_t *binding,
+ bool try_interpreter)
{
if (binding != NULL) {
GET_VM()->bindings.push_back(binding);
}
- IMP imp = rb_vm_compile(fname, node);
+ RoxorCompiler *compiler = new RoxorCompiler(fname);
+ Function *function = compiler->compile_main_function(node);
+ delete compiler;
if (binding != NULL) {
GET_VM()->bindings.pop_back();
}
+#if 0
+ // TODO the LLVM interpreter is not ready yet
+ if (try_interpreter) {
+ return GET_VM()->interpret(function);
+ }
+ else {
+ IMP imp = GET_VM()->compile(function);
+ return ((VALUE(*)(VALUE, SEL))imp)(GET_VM()->current_top_object, 0);
+ }
+#else
+ IMP imp = GET_VM()->compile(function);
return ((VALUE(*)(VALUE, SEL))imp)(GET_VM()->current_top_object, 0);
+#endif
}
extern "C"
VALUE
rb_vm_run_under(VALUE klass, VALUE self, const char *fname, NODE *node,
- rb_vm_binding_t *binding)
+ rb_vm_binding_t *binding, bool try_interpreter)
{
VALUE old_top_object = GET_VM()->current_top_object;
if (binding != NULL) {
@@ -6859,7 +6875,7 @@ rb_vm_run_under(VALUE klass, VALUE self, const char *fname, NODE *node,
GET_VM()->current_class = (Class)klass;
}
- VALUE val = rb_vm_run(fname, node, binding);
+ VALUE val = rb_vm_run(fname, node, binding, try_interpreter);
GET_VM()->current_top_object = old_top_object;
GET_VM()->current_class = old_class;
View
6 roxor.h
@@ -48,10 +48,10 @@ typedef struct {
void *cache;
} rb_vm_method_t;
-VALUE rb_vm_run(const char *fname, NODE *node, rb_vm_binding_t *binding);
+VALUE rb_vm_run(const char *fname, NODE *node, rb_vm_binding_t *binding,
+ bool try_interpreter);
VALUE rb_vm_run_under(VALUE klass, VALUE self, const char *fname, NODE *node,
- rb_vm_binding_t *binding);
-IMP rb_vm_compile(const char *fname, NODE *node);
+ rb_vm_binding_t *binding, bool try_interpreter);
bool rb_vm_running(void);
void rb_vm_set_running(bool flag);
View
2  tool/compile_prelude.rb
@@ -80,7 +80,7 @@ def c_esc(str)
rb_vm_run(prelude_name<%=i%>, rb_compile_string(
prelude_name<%=i%>,
rb_str_new(prelude_code<%=i%>, sizeof(prelude_code<%=i%>) - 1),
- 1), NULL);
+ 1), NULL, false);
% }
}
View
2  vm_eval.c
@@ -348,7 +348,7 @@ eval_string(VALUE self, VALUE klass, VALUE src, VALUE scope, const char *file,
}
}
- return rb_vm_run_under(klass, self, file, node, b);
+ return rb_vm_run_under(klass, self, file, node, b, true);
}
static VALUE
Please sign in to comment.
Something went wrong with that request. Please try again.