Skip to content

Commit

Permalink
Add hand mantained types.ll and offset gen code
Browse files Browse the repository at this point in the history
Previously, we'd use LLVM to read the code base and output an .ll file
for each of the structs we'd want. Then we'd turn that .ll file into a
.cpp file that would recreate the types for LLVM to use. Using llvm-g++
for this has proved difficult because of structal typing collapses. So
instead we're going to hand maintain a types.ll with the types and field
names of the things want to access in the JIT.

Additionally, the comments with the field names are read auto
offset_specific.hpp is output, making it easier to access a field in a
struct by it's name (this will replace the hand maintained offset.hpp)
  • Loading branch information
Evan Phoenix committed Feb 1, 2011
1 parent ef7bcf7 commit ddc4961
Show file tree
Hide file tree
Showing 13 changed files with 520 additions and 131 deletions.
50 changes: 48 additions & 2 deletions rakelib/jit.rake
@@ -1,6 +1,6 @@
namespace :jit do
task :generate_header do
puts "GEN vm/llvm/types.cpp.gen"
task :regenerate_header do
puts "GEN vm/llvm/types.ll, vm/llvm/types.cpp.gen"

classes = %w!
rubinius::ObjectFlags
Expand Down Expand Up @@ -86,4 +86,50 @@ namespace :jit do
`llvm-as < vm/gen/types.ll > vm/gen/types.bc`
`vm/external_libs/llvm/Release/bin/llc -march=cpp -cppgen=contents -o vm/llvm/types.cpp.gen vm/gen/types.bc`
end

task :generate_header do
puts "GEN vm/llvm/types.cpp.gen"
`llvm-as < vm/llvm/types.ll > vm/gen/types.bc`
`vm/external_libs/llvm/Release/bin/llc -march=cpp -cppgen=contents -o vm/llvm/types.cpp.gen vm/gen/types.bc`
end

task :generate_offsets do
classes = {}
File.open "vm/llvm/types.ll" do |f|
while line = f.gets
if m1 = /%"?(struct|union)\.rubinius::([^"]*)"?\s*=\s*type\s*\{\n/.match(line)
line = f.gets

fields = []
while line.strip != "}"
if m2 = /;\s*(.*)/.match(line)
fields << m2[1].strip
else
fields << nil
end

line = f.gets
end

classes[m1[2]] = fields
end
end
end

File.open "vm/llvm/offset_specific.hpp", "w" do |f|
f.puts "namespace offset {"

classes.each do |name, fields|
f.puts "namespace #{name.gsub('::', '_')} {"
fields.each_with_index do |name, idx|
if name
f.puts " const static int #{name} = #{idx};"
end
end
f.puts "}"
end

f.puts "}"
end
end
end
1 change: 0 additions & 1 deletion vm/builtin/taskprobe.cpp
Expand Up @@ -8,7 +8,6 @@
#include "vm/object_utils.hpp"
#include "objectmemory.hpp"
#include "vm.hpp"
#include "jit_state.h"
#include "arguments.hpp"
#include "dispatch.hpp"

Expand Down
1 change: 0 additions & 1 deletion vm/call_frame.hpp
Expand Up @@ -3,7 +3,6 @@

#include "vmmethod.hpp"
#include "unwind_info.hpp"
#include "jit_state.h"
#include "stack_variables.hpp"
#include "builtin/variable_scope.hpp"
#include "dispatch.hpp"
Expand Down
16 changes: 0 additions & 16 deletions vm/jit_state.h

This file was deleted.

20 changes: 10 additions & 10 deletions vm/llvm/jit_block.cpp
Expand Up @@ -187,26 +187,26 @@ namespace jit {
}

void BlockBuilder::initialize_frame(int stack_size) {
Value* cm_gep = get_field(call_frame, offset::cf_cm);
Value* cm_gep = get_field(call_frame, offset::CallFrame::cm);

method = b().CreateLoad(get_field(block_env, offset::blockenv_method),
"env.method");

// previous
b().CreateStore(prev, get_field(call_frame, offset::cf_previous));
b().CreateStore(prev, get_field(call_frame, offset::CallFrame::previous));

// static_scope
Value* ss = b().CreateLoad(get_field(block_inv, offset::blockinv_static_scope),
"invocation.static_scope");

b().CreateStore(ss, get_field(call_frame, offset::cf_static_scope));
b().CreateStore(ss, get_field(call_frame, offset::CallFrame::static_scope));

// arguments
b().CreateStore(args, get_field(call_frame, offset::cf_arguments));
b().CreateStore(args, get_field(call_frame, offset::CallFrame::arguments));

// msg
b().CreateStore(Constant::getNullValue(ls_->Int8PtrTy),
get_field(call_frame, offset::cf_msg));
get_field(call_frame, offset::CallFrame::dispatch_data));

// cm
b().CreateStore(method, cm_gep);
Expand All @@ -225,26 +225,26 @@ namespace jit {
Value* flags = b().CreateOr(inv_flags,
ConstantInt::get(ls_->Int32Ty, block_flags), "flags");

b().CreateStore(flags, get_field(call_frame, offset::cf_flags));
b().CreateStore(flags, get_field(call_frame, offset::CallFrame::flags));

// ip
b().CreateStore(ConstantInt::get(ls_->Int32Ty, 0),
get_field(call_frame, offset::cf_ip));
get_field(call_frame, offset::CallFrame::ip));

// scope
b().CreateStore(vars, get_field(call_frame, offset::cf_scope));
b().CreateStore(vars, get_field(call_frame, offset::CallFrame::scope));

// top_scope
top_scope = b().CreateLoad(
get_field(block_env, offset::blockenv_top_scope),
"env.top_scope");

b().CreateStore(top_scope, get_field(call_frame, offset::cf_top_scope));
b().CreateStore(top_scope, get_field(call_frame, offset::CallFrame::top_scope));

// jit_data
b().CreateStore(
constant(info_.context().runtime_data_holder(), ls_->Int8PtrTy),
get_field(call_frame, offset::cf_jit_data));
get_field(call_frame, offset::CallFrame::jit_data));

}
}
Expand Down
12 changes: 6 additions & 6 deletions vm/llvm/jit_inline_block.cpp
Expand Up @@ -56,34 +56,34 @@ namespace jit {
// Setup the CallFrame
//
// previous
b().CreateStore(prev, get_field(call_frame, offset::cf_previous));
b().CreateStore(prev, get_field(call_frame, offset::CallFrame::previous));

// msg
b().CreateStore(
b().CreatePointerCast(rd, ls_->Int8PtrTy),
get_field(call_frame, offset::cf_msg));
get_field(call_frame, offset::CallFrame::dispatch_data));

// cm
method = b().CreateLoad(
b().CreateConstGEP2_32(rd, 0, offset::runtime_data_method, "method_pos"),
"cm");

Value* cm_gep = get_field(call_frame, offset::cf_cm);
Value* cm_gep = get_field(call_frame, offset::CallFrame::cm);
b().CreateStore(method, cm_gep);

// flags
int flags = CallFrame::cInlineFrame;
if(!use_full_scope_) flags |= CallFrame::cClosedScope;

b().CreateStore(ConstantInt::get(ls_->Int32Ty, flags),
get_field(call_frame, offset::cf_flags));
get_field(call_frame, offset::CallFrame::flags));

// ip
b().CreateStore(ConstantInt::get(ls_->Int32Ty, 0),
get_field(call_frame, offset::cf_ip));
get_field(call_frame, offset::CallFrame::ip));

// scope
b().CreateStore(vars, get_field(call_frame, offset::cf_scope));
b().CreateStore(vars, get_field(call_frame, offset::CallFrame::scope));

nil_stack(vmm_->stack_size, constant(Qnil, obj_type));

Expand Down
12 changes: 6 additions & 6 deletions vm/llvm/jit_inline_method.cpp
Expand Up @@ -57,34 +57,34 @@ namespace jit {
// Setup the CallFrame
//
// previous
b().CreateStore(prev, get_field(call_frame, offset::cf_previous));
b().CreateStore(prev, get_field(call_frame, offset::CallFrame::previous));

// msg
b().CreateStore(
b().CreatePointerCast(rd, ls_->Int8PtrTy),
get_field(call_frame, offset::cf_msg));
get_field(call_frame, offset::CallFrame::dispatch_data));

// cm
method = b().CreateLoad(
b().CreateConstGEP2_32(rd, 0, offset::runtime_data_method, "method_pos"),
"cm");

Value* cm_gep = get_field(call_frame, offset::cf_cm);
Value* cm_gep = get_field(call_frame, offset::CallFrame::cm);
b().CreateStore(method, cm_gep);

// flags
int flags = CallFrame::cInlineFrame;
if(!use_full_scope_) flags |= CallFrame::cClosedScope;

b().CreateStore(ConstantInt::get(ls_->Int32Ty, flags),
get_field(call_frame, offset::cf_flags));
get_field(call_frame, offset::CallFrame::flags));

// ip
b().CreateStore(ConstantInt::get(ls_->Int32Ty, 0),
get_field(call_frame, offset::cf_ip));
get_field(call_frame, offset::CallFrame::ip));

// scope
b().CreateStore(vars, get_field(call_frame, offset::cf_scope));
b().CreateStore(vars, get_field(call_frame, offset::CallFrame::scope));

nil_stack(vmm_->stack_size, constant(Qnil, obj_type));

Expand Down
16 changes: 8 additions & 8 deletions vm/llvm/jit_method.cpp
Expand Up @@ -373,20 +373,20 @@ namespace jit {

void MethodBuilder::initialize_frame(int stack_size) {
Value* exec = this->exec;
Value* cm_gep = get_field(call_frame, offset::cf_cm);
Value* cm_gep = get_field(call_frame, offset::CallFrame::cm);
method = b().CreateBitCast(
exec, cast<llvm::PointerType>(cm_gep->getType())->getElementType(), "cm");

// previous
b().CreateStore(prev, get_field(call_frame, offset::cf_previous));
b().CreateStore(prev, get_field(call_frame, offset::CallFrame::previous));

// arguments
b().CreateStore(args, get_field(call_frame, offset::cf_arguments));
b().CreateStore(args, get_field(call_frame, offset::CallFrame::arguments));

// msg
b().CreateStore(
ConstantInt::getNullValue(ls_->Int8PtrTy),
get_field(call_frame, offset::cf_msg));
get_field(call_frame, offset::CallFrame::dispatch_data));

// cm
b().CreateStore(method, cm_gep);
Expand All @@ -397,20 +397,20 @@ namespace jit {

b().CreateStore(
ConstantInt::get(ls_->Int32Ty, flags),
get_field(call_frame, offset::cf_flags));
get_field(call_frame, offset::CallFrame::flags));

// ip
b().CreateStore(
ConstantInt::get(ls_->Int32Ty, 0),
get_field(call_frame, offset::cf_ip));
get_field(call_frame, offset::CallFrame::ip));

// scope
b().CreateStore(vars, get_field(call_frame, offset::cf_scope));
b().CreateStore(vars, get_field(call_frame, offset::CallFrame::scope));

// jit_data
b().CreateStore(
constant(info_.context().runtime_data_holder(), ls_->Int8PtrTy),
get_field(call_frame, offset::cf_jit_data));
get_field(call_frame, offset::CallFrame::jit_data));

if(ls_->include_profiling()) {
Value* test = b().CreateLoad(ls_->profiling(), "profiling");
Expand Down
10 changes: 5 additions & 5 deletions vm/llvm/jit_visit.hpp
Expand Up @@ -201,7 +201,7 @@ namespace rubinius {

set_block(start);

ip_pos_ = b().CreateConstGEP2_32(call_frame_, 0, offset::cf_ip, "ip_pos");
ip_pos_ = b().CreateConstGEP2_32(call_frame_, 0, offset::CallFrame::ip, "ip_pos");

global_serial_pos = b().CreateIntToPtr(
ConstantInt::get(ls_->IntPtrTy, (intptr_t)ls_->shared().global_serial_address()),
Expand Down Expand Up @@ -234,13 +234,13 @@ namespace rubinius {

Value* scope() {
return b().CreateLoad(
b().CreateConstGEP2_32(call_frame_, 0, offset::cf_scope, "scope_pos"),
b().CreateConstGEP2_32(call_frame_, 0, offset::CallFrame::scope, "scope_pos"),
"scope");
}

Value* top_scope() {
return b().CreateLoad(
b().CreateConstGEP2_32(call_frame_, 0, offset::cf_top_scope, "top_scope_pos"),
b().CreateConstGEP2_32(call_frame_, 0, offset::CallFrame::top_scope, "top_scope_pos"),
"top_scope");
}

Expand Down Expand Up @@ -1099,7 +1099,7 @@ namespace rubinius {
}

Value* get_literal(opcode which) {
Value* gep = b().CreateConstGEP2_32(call_frame_, 0, offset::cf_cm, "cm_pos");
Value* gep = b().CreateConstGEP2_32(call_frame_, 0, offset::CallFrame::cm, "cm_pos");
Value* cm = b().CreateLoad(gep, "cm");

gep = b().CreateConstGEP2_32(cm, 0, offset::cm_literals, "literals_pos");
Expand Down Expand Up @@ -2208,7 +2208,7 @@ namespace rubinius {

void visit_push_scope() {
Value* cm = b().CreateLoad(
b().CreateConstGEP2_32(call_frame_, 0, offset::cf_cm, "cm_pos"),
b().CreateConstGEP2_32(call_frame_, 0, offset::CallFrame::cm, "cm_pos"),
"cm");

Value* gep = b().CreateConstGEP2_32(cm, 0, offset::cm_static_scope, "scope_pos");
Expand Down
14 changes: 2 additions & 12 deletions vm/llvm/offset.hpp
@@ -1,19 +1,9 @@
#ifndef RBX_LLVM_OFFSET_HPP
#define RBX_LLVM_OFFSET_HPP

namespace offset {
const static int cf_previous = 0;
const static int cf_static_scope = 1;
const static int cf_msg = 2;
const static int cf_cm = 3;
const static int cf_flags = 4;
const static int cf_ip = 5;
const static int cf_jit_data = 6;
const static int cf_top_scope = 7;
const static int cf_scope = 8;
const static int cf_arguments = 9;
const static int cf_stk = 10;
#include "llvm/offset_specific.hpp"

namespace offset {
const static int args_name = 0;
const static int args_recv = 1;
const static int args_block = 2;
Expand Down

0 comments on commit ddc4961

Please sign in to comment.