Skip to content

Commit

Permalink
Speedup ao-render.rb 200sec to 140sec
Browse files Browse the repository at this point in the history
  • Loading branch information
miura1729 committed Feb 12, 2009
1 parent f57e25a commit 73f68d4
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 22 deletions.
24 changes: 21 additions & 3 deletions lib/intruby.rb
Expand Up @@ -17,12 +17,15 @@ module IntRuby
include LLVMUtil

def gen_ivar_ptr(builder)
ftype = Type.function(P_VALUE, [VALUE, VALUE])
ftype = Type.function(P_VALUE, [VALUE, VALUE, P_VALUE])
b = builder.define_function_raw('llvm_ivar_ptr', ftype)
args = builder.arguments
embed = builder.create_block
nonembed = builder.create_block
comm = builder.create_block
cachehit = builder.create_block
cachemiss = builder.create_block

rbp = Type.pointer(RBASIC)
slfop = b.int_to_ptr(args[0], Type.pointer(ROBJECT))
slf = b.int_to_ptr(args[0], rbp)
Expand Down Expand Up @@ -56,8 +59,8 @@ def gen_ivar_ptr(builder)
niv_index_tbl = b.load(ivitp)

b.br(comm)

b.set_insert_point(comm)

ptr = b.phi(P_VALUE)
ptr.add_incoming(eptr, embed)
ptr.add_incoming(nptr, nonembed)
Expand All @@ -66,6 +69,20 @@ def gen_ivar_ptr(builder)
iv_index_tbl.add_incoming(eiv_index_tbl, embed)
iv_index_tbl.add_incoming(niv_index_tbl, nonembed)

oldindex = b.load(args[2])
ishit = b.icmp_ne(oldindex, -1.llvm)

b.cond_br(ishit, cachehit, cachemiss)

# Inline Cache hit
b.set_insert_point(cachehit)
index = b.load(args[2])
resp = b.gep(ptr, index)
b.return(resp)

# Inline Cache Misss
b.set_insert_point(cachemiss)


indexp = b.alloca(VALUE, 1)

Expand All @@ -75,8 +92,9 @@ def gen_ivar_ptr(builder)

index = b.load(indexp)
resp = b.gep(ptr, index)

b.store(index, args[2])
b.return(resp)

end
end
end
3 changes: 1 addition & 2 deletions lib/llvmutil.rb
Expand Up @@ -107,8 +107,7 @@ def gen_call_var_args_common(para, fname, rtype, ftype)
end

def add_global_variable(name, type, init)
@global_malloc_area_tab[name] = [type, init]
@global_malloc_area_tab.size - 1
@builder.define_global_variable(type, init)
end

def gen_binary_operator(para, core)
Expand Down
4 changes: 1 addition & 3 deletions lib/methoddef_ex.rb
Expand Up @@ -15,13 +15,11 @@ module MethodDefinition
lambda {|para|
info = para[:info]
rettype = RubyType.fixnum(info[3], "Return type of gen_interval_cycle")
glno = add_global_variable("interval_cycle",
prevvalp = add_global_variable("interval_cycle",
Type::Int64Ty,
0.llvm(Type::Int64Ty))
@expstack.push [rettype,
lambda {|b, context|
prevvalp = context.builder.global_variable
prevvalp = b.struct_gep(prevvalp, glno)
prevval = b.load(prevvalp)
ftype = Type.function(Type::Int64Ty, [])
fname = 'llvm.readcyclecounter'
Expand Down
20 changes: 7 additions & 13 deletions lib/vmtraverse.rb
Expand Up @@ -179,7 +179,7 @@ def initialize(iseq, bind, preload)
}

# Information of global variables by malloc
@global_malloc_area_tab = {}
@global_malloc_area_tab = []

# Number of trace(for profile speed up)
@trace_no = 0
Expand Down Expand Up @@ -374,11 +374,15 @@ def visit_block_start(code, ins, local_vars, ln, info)
if cnt > 0 and
OPTION[:cache_instance_variable] and
info[1] != :initialize then
ftype = Type.function(P_VALUE, [VALUE, VALUE])

# define inline cache area
oldindex = add_global_variable("old_index", VALUE, -1.llvm)
ftype = Type.function(P_VALUE, [VALUE, VALUE, P_VALUE])
func = context.builder.get_or_insert_function_raw('llvm_ivar_ptr', ftype)
ivid = ((key.object_id << 1) / RVALUE_SIZE)
slf = b.load(context.local_vars[2][:area])
vptr = b.call(func, slf, ivid.llvm)

vptr = b.call(func, slf, ivid.llvm, oldindex)
context.instance_vars_local_area[key] = vptr
else
context.instance_vars_local_area[key] = nil
Expand Down Expand Up @@ -2364,17 +2368,7 @@ def gen_init_ruby(builder)
b = builder.define_function_raw('init_ruby', ftype)
initfunc = builder.current_function
member = []
@global_malloc_area_tab.each do |vname, val|
member.push val[0]
end
type = Type.struct(member)

initarg = []
@global_malloc_area_tab.each do |vname, val|
initarg.push val[1]
end
init = Value.get_struct_constant(type, *initarg)
gl = builder.define_global_variable(type, init)

@generated_define_func.each do |klass, defperklass|
if klass then
Expand Down
1 change: 1 addition & 0 deletions lib/yarv2llvm.rb
Expand Up @@ -92,6 +92,7 @@ def llvm
module LLVM::RubyInternals
RFLOAT = Type.struct([RBASIC, Type::DoubleTy])
P_RFLOAT = Type.pointer(RFLOAT)
P_P_VALUE = Type.pointer(P_VALUE)
end

=begin
Expand Down
2 changes: 1 addition & 1 deletion sample/ao-render.rb
@@ -1,4 +1,4 @@
# AO rebder benchmark
# AO render benchmark
# Original program (C) Syoyo Fujita in Javascript (and other languages)
# http://lucille.atso-net.jp/blog/?p=642
# http://lucille.atso-net.jp/blog/?p=711
Expand Down

0 comments on commit 73f68d4

Please sign in to comment.