[macruby-changes] [4246] MacRuby/trunk
source_changes at macosforge.org
source_changes at macosforge.org
Fri Jun 18 15:41:50 PDT 2010
Revision: 4246
http://trac.macosforge.org/projects/ruby/changeset/4246
Author: lsansonetti at apple.com
Date: 2010-06-18 15:41:50 -0700 (Fri, 18 Jun 2010)
Log Message:
-----------
don't instantiate the JIT when running in AOT mode, honor the target triple from the deserialized kernel module, expose the VM_KERNEL_PATH variable to specify a kernel bitcode file
Modified Paths:
--------------
MacRuby/trunk/HACKING.rdoc
MacRuby/trunk/ruby.c
MacRuby/trunk/vm.cpp
MacRuby/trunk/vm.h
Modified: MacRuby/trunk/HACKING.rdoc
===================================================================
--- MacRuby/trunk/HACKING.rdoc 2010-06-18 22:39:40 UTC (rev 4245)
+++ MacRuby/trunk/HACKING.rdoc 2010-06-18 22:41:50 UTC (rev 4246)
@@ -130,6 +130,10 @@
* VM_OPT_LEVEL: set it either to 0, 1, 2 or 3 to change the optimization level
of the LLVM code generator.
+* VM_KERNEL_PATH: specify a path to a kernel bitcode file to be used instead of
+ the hardcoded one, when deserializing the main module. This is useful when
+ cross-compiling Ruby code to a different architecture.
+
* DYLD_LIBRARY_PATH: in case you are debugging a Cocoa application, set this
variable to "." before starting gdb, and you won't have to re-install MacRuby
every time you re-compile it.
Modified: MacRuby/trunk/ruby.c
===================================================================
--- MacRuby/trunk/ruby.c 2010-06-18 22:39:40 UTC (rev 4245)
+++ MacRuby/trunk/ruby.c 2010-06-18 22:41:50 UTC (rev 4246)
@@ -837,6 +837,8 @@
static rb_encoding *src_encoding;
+void rb_vm_init_jit(void);
+
static VALUE
process_options(VALUE arg)
{
@@ -900,6 +902,10 @@
opt->ext.enc.name = ext_enc_name;
}
+ if (!ruby_aot_compile) {
+ rb_vm_init_jit();
+ }
+
if (opt->version) {
ruby_show_version();
return Qtrue;
Modified: MacRuby/trunk/vm.cpp
===================================================================
--- MacRuby/trunk/vm.cpp 2010-06-18 22:39:40 UTC (rev 4245)
+++ MacRuby/trunk/vm.cpp 2010-06-18 22:41:50 UTC (rev 4246)
@@ -321,18 +321,34 @@
#if !MACRUBY_STATIC
bs_parser = NULL;
-
llvm_start_multithreaded();
+ interpreter_enabled = getenv("VM_DISABLE_INTERPRETER") == NULL;
+ // The JIT is created later, if necessary.
+ InitializeNativeTarget();
# if !defined(LLVM_TOT)
+ emp = NULL;
+# endif
+ jmm = NULL;
+ ee = NULL;
+ fpm = NULL;
+
+# if ROXOR_VM_DEBUG
+ functions_compiled = 0;
+# endif
+#endif // !MACRUBY_STATIC
+}
+
+void
+RoxorCore::prepare_jit(void)
+{
+#if !defined(MACRUBY_STATIC)
+ assert(ee == NULL);
+# if !defined(LLVM_TOT)
emp = new ExistingModuleProvider(RoxorCompiler::module);
# endif
jmm = new RoxorJITManager;
- InitializeNativeTarget();
-
- interpreter_enabled = getenv("VM_DISABLE_INTERPRETER") == NULL;
-
CodeGenOpt::Level opt = CodeGenOpt::Default;
inlining_enabled = false;
optims_enabled = true;
@@ -392,11 +408,7 @@
fpm->add(createCFGSimplificationPass());
// Eliminate tail calls.
fpm->add(createTailCallEliminationPass());
-
-# if ROXOR_VM_DEBUG
- functions_compiled = 0;
-# endif
-#endif // !MACRUBY_STATIC
+#endif
}
RoxorCore::~RoxorCore(void)
@@ -557,7 +569,7 @@
if (inlining_enabled) {
RoxorCompiler::shared->inline_function_calls(func);
}
- if (optims_enabled) {
+ if (optims_enabled && fpm != NULL) {
fpm->run(*func);
}
}
@@ -3671,6 +3683,13 @@
extern "C"
void
+rb_vm_init_jit(void)
+{
+ GET_CORE()->prepare_jit();
+}
+
+extern "C"
+void
rb_vm_init_compiler(void)
{
#if !defined(MACRUBY_STATIC)
@@ -4634,15 +4653,10 @@
}
#endif
-// We can't trust LLVM to pick the right target at runtime.
-#if __LP64__
-# define TARGET_TRIPLE "x86_64-apple-darwin"
-#else
-# define TARGET_TRIPLE "i386-apple-darwin"
+#if !defined(MACRUBY_STATIC)
+# include "./.objs/kernel_data.c"
#endif
-#include "kernel_data.c"
-
extern "C"
void
Init_PreVM(void)
@@ -4661,25 +4675,38 @@
// To not corrupt stack pointer (essential for backtracing).
llvm::NoFramePointerElim = true;
- // Retrieve the kernel bitcode for the right architecture. We substract
- // 1 to the length because it's NULL terminated.
- const char *kernel_beg;
- const char *kernel_end;
+ MemoryBuffer *mbuf;
+ const char *kernel_file = getenv("VM_KERNEL_PATH");
+ if (kernel_file != NULL) {
+ std::string err;
+ mbuf = MemoryBuffer::getFile(kernel_file, &err);
+ if (mbuf == NULL) {
+ printf("can't open given kernel file `%s': %s\n", kernel_file,
+ err.c_str());
+ abort();
+ }
+ }
+ else {
+ // Retrieve the kernel bitcode for the right architecture. We substract
+ // 1 to the length because it's NULL terminated.
+ const char *kernel_beg;
+ const char *kernel_end;
#if __LP64__
- kernel_beg = (const char *)kernel_x86_64_bc;
- kernel_end = kernel_beg + kernel_x86_64_bc_len - 1;
+ kernel_beg = (const char *)_objs_kernel_x86_64_bc;
+ kernel_end = kernel_beg + _objs_kernel_x86_64_bc_len - 1;
#else
- kernel_beg = (const char *)kernel_i386_bc;
- kernel_end = kernel_beg + kernel_i386_bc_len - 1;
+ kernel_beg = (const char *)_objs_kernel_i386_bc;
+ kernel_end = kernel_beg + _objs_kernel_i386_bc_len - 1;
#endif
#if LLVM_TOT
- MemoryBuffer *mbuf = MemoryBuffer::getMemBuffer(StringRef(kernel_beg,
- kernel_end - kernel_beg));
+ mbuf = MemoryBuffer::getMemBuffer(StringRef(kernel_beg,
+ kernel_end - kernel_beg));
#else
- MemoryBuffer *mbuf = MemoryBuffer::getMemBuffer(kernel_beg, kernel_end);
+ mbuf = MemoryBuffer::getMemBuffer(kernel_beg, kernel_end);
+ assert(mbuf != NULL);
#endif
- assert(mbuf != NULL);
+ }
std::string err;
RoxorCompiler::module = ParseBitcodeFile(mbuf, getGlobalContext(), &err);
delete mbuf;
@@ -4688,9 +4715,8 @@
}
assert(RoxorCompiler::module != NULL);
- RoxorCompiler::module->setTargetTriple(TARGET_TRIPLE);
RoxorInterpreter::shared = new RoxorInterpreter();
-#endif
+#endif // !MACRUBY_STATIC
RoxorCore::shared = new RoxorCore();
RoxorVM::main = new RoxorVM();
@@ -4715,7 +4741,7 @@
assert(m != NULL);
old_resolveInstanceMethod_imp = method_getImplementation(m);
method_setImplementation(m, (IMP)resolveInstanceMethod_imp);
-#endif
+#endif // !MACRUBY_STATIC
// Early define some classes.
rb_cNSString = (VALUE)objc_getClass("NSString");
Modified: MacRuby/trunk/vm.h
===================================================================
--- MacRuby/trunk/vm.h 2010-06-18 22:39:40 UTC (rev 4245)
+++ MacRuby/trunk/vm.h 2010-06-18 22:41:50 UTC (rev 4246)
@@ -759,6 +759,8 @@
RoxorCore(void);
~RoxorCore(void);
+ void prepare_jit(void);
+
ACCESSOR(running, bool);
ACCESSOR(abort_on_exception, bool);
ACCESSOR(default_random, VALUE);
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20100618/346a583c/attachment-0001.html>
More information about the macruby-changes
mailing list