Skip to content

Commit

Permalink
Conditionalize using LLVM
Browse files Browse the repository at this point in the history
  • Loading branch information
Evan Phoenix committed May 15, 2009
1 parent f7cb6ca commit 0356ed3
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 529 deletions.
5 changes: 2 additions & 3 deletions rakelib/vm.rake
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ else
LLVM_STYLE = "Release" LLVM_STYLE = "Release"
end end


LLVM_ENABLE = true LLVM_ENABLE = false



ENV.delete 'CDPATH' # confuses llvm_config ENV.delete 'CDPATH' # confuses llvm_config
LLVM_CONFIG = "vm/external_libs/llvm/#{LLVM_STYLE}/bin/llvm-config" LLVM_CONFIG = "vm/external_libs/llvm/#{LLVM_STYLE}/bin/llvm-config"
Expand Down Expand Up @@ -185,7 +184,7 @@ if RUBY_PLATFORM =~ /darwin/i && `sw_vers` =~ /10\.4/
end end


if LLVM_ENABLE if LLVM_ENABLE
# FLAGS << "-DENABLE_LLVM" FLAGS << "-DENABLE_LLVM"
llvm_flags = `#{LLVM_CONFIG} --cflags`.split(/\s+/) llvm_flags = `#{LLVM_CONFIG} --cflags`.split(/\s+/)
llvm_flags.delete_if { |e| e.index("-O") == 0 } llvm_flags.delete_if { |e| e.index("-O") == 0 }
FLAGS.concat llvm_flags FLAGS.concat llvm_flags
Expand Down
16 changes: 0 additions & 16 deletions vm/builtin/compiledmethod.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include "ffi.hpp" #include "ffi.hpp"
#include "marshal.hpp" #include "marshal.hpp"
#include "primitives.hpp" #include "primitives.hpp"
#include "llvm.hpp"
#include "objectmemory.hpp" #include "objectmemory.hpp"
#include "arguments.hpp" #include "arguments.hpp"
#include "dispatch.hpp" #include "dispatch.hpp"
Expand Down Expand Up @@ -70,22 +69,7 @@ namespace rubinius {
VMMethod* CompiledMethod::formalize(STATE, bool ondemand) { VMMethod* CompiledMethod::formalize(STATE, bool ondemand) {
if(!backend_method_) { if(!backend_method_) {
VMMethod* vmm = NULL; VMMethod* vmm = NULL;
#ifdef ENABLE_LLVM
/* Controls whether we use LLVM out of the gate or not. */
if(state->config.compile_up_front) {
if(ondemand) {
set_executor(VMLLVMMethod::uncompiled_execute);
} else {
VMLLVMMethod* llvm = new VMLLVMMethod(state, this);
llvm->compile(state);
vmm = llvm;
}
} else {
vmm = new VMMethod(state, this);
}
#else
vmm = new VMMethod(state, this); vmm = new VMMethod(state, this);
#endif
backend_method_ = vmm; backend_method_ = vmm;


resolve_primitive(state); resolve_primitive(state);
Expand Down
10 changes: 10 additions & 0 deletions vm/builtin/machine_method.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@


#include "detection.hpp" #include "detection.hpp"


#ifdef ENABLE_LLVM
#include "llvm/jit.hpp" #include "llvm/jit.hpp"
#include <llvm/Support/CommandLine.h> #include <llvm/Support/CommandLine.h>
#endif


// #define MM_DEBUG // #define MM_DEBUG


Expand All @@ -20,8 +22,10 @@ namespace rubinius {
GO(machine_method).set(state->new_class_under("MachineMethod", G(rubinius))); GO(machine_method).set(state->new_class_under("MachineMethod", G(rubinius)));
GO(machine_method)->name(state, state->symbol("Rubinius::MachineMethod")); GO(machine_method)->name(state, state->symbol("Rubinius::MachineMethod"));


#ifdef ENABLE_LLVM
//setenv("RBX_JIT", "--debug-only=jit", 1); //setenv("RBX_JIT", "--debug-only=jit", 1);
llvm::cl::ParseEnvironmentOptions("rbx", "RBX_JIT", "blah", false); llvm::cl::ParseEnvironmentOptions("rbx", "RBX_JIT", "blah", false);
#endif
} }




Expand Down Expand Up @@ -80,6 +84,7 @@ namespace rubinius {
} }


MachineMethod* MachineMethod::create(STATE, VMMethod* vmm) { MachineMethod* MachineMethod::create(STATE, VMMethod* vmm) {
#ifdef ENABLE_LLVM
LLVMCompiler* jit = new LLVMCompiler(); LLVMCompiler* jit = new LLVMCompiler();
jit->compile(state, vmm); jit->compile(state, vmm);


Expand All @@ -94,6 +99,9 @@ namespace rubinius {


mm->jit_data_ = reinterpret_cast<void*>(jit); mm->jit_data_ = reinterpret_cast<void*>(jit);
return mm; return mm;
#else
return (MachineMethod*)Qnil;
#endif
} }


void* MachineMethod::resolve_virtual_ip(int ip) { void* MachineMethod::resolve_virtual_ip(int ip) {
Expand All @@ -103,6 +111,7 @@ namespace rubinius {
} }


Object* MachineMethod::show(STATE) { Object* MachineMethod::show(STATE) {
#ifdef ENABLE_LLVM
if(code_size_ == 0) { if(code_size_ == 0) {
std::cout << "== llvm assembly ==\n"; std::cout << "== llvm assembly ==\n";
reinterpret_cast<LLVMCompiler*>(jit_data_)->show_assembly(state); reinterpret_cast<LLVMCompiler*>(jit_data_)->show_assembly(state);
Expand All @@ -117,6 +126,7 @@ namespace rubinius {
std::cout << "\n== x86 assembly ==\n"; std::cout << "\n== x86 assembly ==\n";
assembler_x86::AssemblerX86::show_buffer(function(), code_size_, false, comments_); assembler_x86::AssemblerX86::show_buffer(function(), code_size_, false, comments_);
} }
#endif


return Qnil; return Qnil;
} }
Expand Down
8 changes: 7 additions & 1 deletion vm/codegen/instruction_macros.rb
Original file line number Original file line Diff line number Diff line change
@@ -1,6 +1,12 @@
require "#{File.dirname(__FILE__)}/../../kernel/compiler/iseq" require "#{File.dirname(__FILE__)}/../../kernel/compiler/iseq"


File.open "#{File.dirname(__FILE__)}/../gen/inst_list.hpp", "w" do |f| dir = "#{File.dirname(__FILE__)}/../gen/"

unless File.directory? dir
Dir.mkdir dir
end

File.open "#{dir}/inst_list.hpp", "w" do |f|
Rubinius::InstructionSet::OpCodes.each do |ins| Rubinius::InstructionSet::OpCodes.each do |ins|
case ins.arg_count case ins.arg_count
when 2 when 2
Expand Down
Loading

0 comments on commit 0356ed3

Please sign in to comment.