Skip to content

Commit

Permalink
1st step of escape analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
miura1729 committed Jun 1, 2009
1 parent 1b66271 commit 83758bd
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/llvmutil.rb
Expand Up @@ -501,6 +501,7 @@ def gen_arg_eval(args, receiver, ins, local_vars, info, minfo, mname)
if minfo then
pe[0].add_same_type(minfo[:argtype][nargs - n - 1])
minfo[:argtype][nargs - n - 1].add_same_value(pe[0])
pe[0].add_extent_base minfo[:argtype][nargs - n - 1]
end
para[n] = pe
end
Expand Down
4 changes: 4 additions & 0 deletions lib/methoddef.rb
Expand Up @@ -60,6 +60,7 @@ module MethodDefinition
val[0].add_same_type(arr[0].type.element_type)
arr[0].type.element_type.add_same_type(val[0])
end
val[0].add_extent_base arr[0]

oldrescode = @rescode
v = nil
Expand Down Expand Up @@ -473,13 +474,16 @@ module MethodDefinition
end
minfo[:argtype][i].add_same_type ele[0]
ele[0].add_same_type minfo[:argtype][i]
ele[0].add_extent_base rettype
ele[0].add_extent_base minfo[:argtype][i]
end
# minfo[:argtype][-1].add_same_type rec[0]
rec[0].add_same_type minfo[:argtype][-1]
#=end

@expstack.push [rettype,
lambda {|b, context|
print "#{rettype.name} -> #{rettype.real_extent}\n"
cargs = []
context = rec[1].call(b, context)
recv = context.rc
Expand Down
41 changes: 41 additions & 0 deletions lib/type.rb
Expand Up @@ -52,6 +52,9 @@ def initialize(type, lno = nil, name = nil, klass = nil)
@same_value = []
@@type_table.push self
@conflicted_types = Hash.new

@extent = []
@extent_base = [self]
end
attr_accessor :type
attr_accessor :conflicted_types
Expand Down Expand Up @@ -99,6 +102,7 @@ def inspect2

attr_accessor :type
attr_accessor :resolveed
attr_accessor :extent
attr :name
attr :line_no

Expand Down Expand Up @@ -241,6 +245,43 @@ def resolve
end
end

EXTENT_ORDER = {
nil => 0,
:block => 1,
:method => 2,
:instance => 3,
:global => 4
}

def add_extent_base(fty)
@extent_base.push fty
end

def extent_base
@extent_base.map do |e|
if e == self then
@extent_base
else
e.extent_base
end
end.flatten
end

def real_extent
ext_all = @extent_base.map {|e| e.extent_base}.flatten

extmax = ext_all.max_by {|e| EXTENT_ORDER[e.extent[0]] }
if extmax.extent[0] then
if extmax.extent[0] == :instance then
return extmax.extent[1].real_extent
else
return extmax.extent[0]
end
end

return :local
end

def self.fixnum(lno = nil, name = nil, klass = Fixnum)
RubyType.new(Type::Int32Ty, lno, name, klass)
end
Expand Down
9 changes: 9 additions & 0 deletions lib/vmtraverse.rb
Expand Up @@ -855,6 +855,8 @@ def visit_getinstancevariable(code, ins, local_vars, ln, info)
type = RubyType.new(nil, info[3], "#{info[0]}##{ivname}")
@instance_var_tab[info[0]][ivname][:type] = type
end
type.extent = [:instance, local_vars[2][:type]]

@expstack.push [type,
lambda {|b, context|
if vptr = context.instance_vars_local_area[ivname] then
Expand Down Expand Up @@ -900,6 +902,7 @@ def visit_setinstancevariable(code, ins, local_vars, ln, info)

srctype.add_same_value(dsttype)
dsttype.add_same_value(srctype)
srctype.extent = [:instance, local_vars[2][:type]]

oldrescode = @rescode
@rescode = lambda {|b, context|
Expand Down Expand Up @@ -987,6 +990,7 @@ def visit_setconstant(code, ins, local_vars, ln, info)
else
const_klass = Object
end
val[0].extent = [:global]
if !UNDEF.equal?(val[0].type.constant) then
const_klass.const_set(ins[1], val[0].type.constant)
else
Expand Down Expand Up @@ -1023,6 +1027,7 @@ def visit_getglobal(code, ins, local_vars, ln, info)
@global_var_tab[glname][:type] = type
areap = add_global_variable("glarea_ptr", VALUE, 4.llvm)
@global_var_tab[glname][:area] = areap
type.extent = [:global]
end
areap = @global_var_tab[glname][:area]
@expstack.push [type,
Expand Down Expand Up @@ -1064,6 +1069,7 @@ def visit_setglobal(code, ins, local_vars, ln, info)

srctype.add_same_value(dsttype)
dsttype.add_same_value(srctype)
srctype.extent = [:global]

oldrescode = @rescode
@rescode = lambda {|b, context|
Expand Down Expand Up @@ -1735,6 +1741,7 @@ def visit_leave(code, ins, local_vars, ln, info)
retexp[0].add_same_type rett2
RubyType.resolve
end
retexp[0].extent = [:global]

oldrescode = @rescode
@rescode = lambda {|b, context|
Expand Down Expand Up @@ -2618,6 +2625,7 @@ def store_to_local(voff, src, local_vars, ln, info)

srctype.add_same_type(dsttype)
dsttype.add_same_value(srctype)
srctype.add_extent_base dsttype

oldrescode = @rescode
@rescode = lambda {|b, context|
Expand Down Expand Up @@ -2678,6 +2686,7 @@ def store_to_parent(voff, slev, src, acode, ln, info)

srctype.add_same_type(dsttype)
dsttype.add_same_value(srctype)
srctype.add_extent_base dsttype

oldrescode = @rescode
@rescode = lambda {|b, context|
Expand Down

0 comments on commit 83758bd

Please sign in to comment.