Class: CastOff::Compiler::SimpleIR::SubIR
- Defined in:
- lib/cast_off/compile/ir/sub_ir.rb
Instance Attribute Summary collapse
-
#dst ⇒ Object
readonly
Returns the value of attribute dst.
-
#result_variable ⇒ Object
readonly
Returns the value of attribute result_variable.
-
#src ⇒ Object
readonly
Returns the value of attribute src.
-
#values ⇒ Object
readonly
Returns the value of attribute values.
-
#variables ⇒ Object
readonly
Returns the value of attribute variables.
-
#variables_without_result ⇒ Object
readonly
Returns the value of attribute variables_without_result.
Attributes inherited from IR
Instance Method Summary collapse
-
#initialize(src, dst, insn, cfg) ⇒ SubIR
constructor
A new instance of SubIR.
- #mark(defs) ⇒ Object
- #propergate_boxed_value(defs) ⇒ Object
-
#propergate_exact_class(defs) ⇒ Object
unboxing end ###.
- #to_c ⇒ Object
- #to_debug_string ⇒ Object
- #type_propergation(defs) ⇒ Object
-
#unboxing_prelude ⇒ Object
unboxing begin ###.
Methods inherited from IR
#add_sampling_variable, #alive, #alive?, #dispatch_method?, #generate_guard, #get_definition, #get_definition_str, #get_usage, #get_variable, #inlining_target?, #propergate_guard_usage, #reset, #sampling_variable, #set_info, #standard_guard_target, #vanish, #vanish?
Methods included from Util
Constructor Details
#initialize(src, dst, insn, cfg) ⇒ SubIR
Returns a new instance of SubIR.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/cast_off/compile/ir/sub_ir.rb', line 7 def initialize(src, dst, insn, cfg) super(insn, cfg) @src = src @dst = dst @values = [@src, @dst] @variables = [] @variables_without_result = [] if @src.is_a?(Variable) @variables << @src @variables_without_result << @src end bug() unless @dst.is_a?(Variable) @variables << @dst @result_variable = @dst end |
Instance Attribute Details
#dst ⇒ Object (readonly)
Returns the value of attribute dst.
6 7 8 |
# File 'lib/cast_off/compile/ir/sub_ir.rb', line 6 def dst @dst end |
#result_variable ⇒ Object (readonly)
Returns the value of attribute result_variable.
6 7 8 |
# File 'lib/cast_off/compile/ir/sub_ir.rb', line 6 def result_variable @result_variable end |
#src ⇒ Object (readonly)
Returns the value of attribute src.
6 7 8 |
# File 'lib/cast_off/compile/ir/sub_ir.rb', line 6 def src @src end |
#values ⇒ Object (readonly)
Returns the value of attribute values.
6 7 8 |
# File 'lib/cast_off/compile/ir/sub_ir.rb', line 6 def values @values end |
#variables ⇒ Object (readonly)
Returns the value of attribute variables.
6 7 8 |
# File 'lib/cast_off/compile/ir/sub_ir.rb', line 6 def variables @variables end |
#variables_without_result ⇒ Object (readonly)
Returns the value of attribute variables_without_result.
6 7 8 |
# File 'lib/cast_off/compile/ir/sub_ir.rb', line 6 def variables_without_result @variables_without_result end |
Instance Method Details
#mark(defs) ⇒ Object
137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/cast_off/compile/ir/sub_ir.rb', line 137 def mark(defs) if @dst.is_a?(Pointer) # read に関しては、使われてないなら行う必要はない if !alive? alive() defs.mark(@src) true else defs.mark(@src) end else alive? && defs.mark(@src) end end |
#propergate_boxed_value(defs) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/cast_off/compile/ir/sub_ir.rb', line 35 def propergate_boxed_value(defs) change = false # forward change |= defs.propergate_boxed_value_forward(@src) change |= @dst.box() if @src.boxed? # backward change |= @src.box() if @dst.boxed? change |= defs.propergate_boxed_value_backward(@src) if @src.boxed? bug() unless @src.boxed? == @dst.boxed? bug() unless @src.unboxed? == @dst.unboxed? change end |
#propergate_exact_class(defs) ⇒ Object
unboxing end ###
53 54 55 56 57 58 59 60 |
# File 'lib/cast_off/compile/ir/sub_ir.rb', line 53 def propergate_exact_class(defs) change = defs.exact_class_resolve(@src) if @src.class_exact? && !@dst.class_exact? @dst.is_class_exact() change = true end change end |
#to_c ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/cast_off/compile/ir/sub_ir.rb', line 62 def to_c() return '' if vanish? ret = [] case @src when Argument if !@translator.inline_block? && @insn.iseq.root? ret << " #{@dst} = #{@src.lvar};" else # nothing to do end when ConstWrapper @insn.iseq.reference_constant if @src.prefetch? @translator.prefetch_constant(@src.to_name, @src.path, false) ret << " #{@dst} = #{@src};" else if @src.cache? ret << <<-EOS if (UNLIKELY(#{@src} == Qundef)) { #{@src.get_constant_chain()} } #{@dst} = #{@src}; EOS else ret << <<-EOS #{@src.get_constant_chain()} #{@dst} = #{@src}; EOS end end when GlobalVariable bug() unless @dst.is_a?(TmpVariable) ret << " #{@dst} = rb_gvar_get(rb_global_entry(#{@translator.allocate_id(@src.id)}));" ret << " #{@src} = #{@dst};" when ClassVariable bug() unless @dst.is_a?(TmpVariable) ret << " #{@dst} = rb_cvar_get(cast_off_get_cvar_base(), #{@translator.allocate_id(@src.id)});" ret << " #{@src} = #{@dst};" when InstanceVariable bug() unless @dst.is_a?(TmpVariable) # FIXME 間にメソッド呼び出しをはさんでいない場合は、読んだ結果をローカル変数(instance_id)にキャッシュする if @translator.use_fast_ivar? ret << " #{@dst} = iv_table_ptr[#{@translator.get_ivar_index(@translator.allocate_id(@src.id), @src.to_name)}];" else ret << " #{@dst} = vm_getivar(self, #{@translator.allocate_id(@src.id)}, &#{@translator.get_ic(@src.to_name)});" end ret << " #{@src} = #{@dst};" else case @dst when Argument, ConstWrapper bug() when InstanceVariable # FIXME 間にメソッド呼び出しをはさんでいない場合は、書いた結果をローカル変数(instance_id)にキャッシュする if @translator.use_fast_ivar? ret << " iv_table_ptr[#{@translator.get_ivar_index(@translator.allocate_id(@dst.id), @dst.to_name)}] = #{@src};" else ret << " vm_setivar(self, #{@translator.allocate_id(@dst.id)}, #{@src}, &#{@translator.get_ic(@dst.to_name)});" end when ClassVariable ret << " rb_cvar_set(cast_off_get_cvar_base(), #{@translator.allocate_id(@dst.id)}, #{@src});" when GlobalVariable ret << " rb_gvar_set(rb_global_entry(#{@translator.allocate_id(@dst.id)}), #{@src});" else ret << " #{@dst} = #{@src};" end end s = sampling_variable() ret << s if s ret.join("\n") end |
#to_debug_string ⇒ Object
23 24 25 |
# File 'lib/cast_off/compile/ir/sub_ir.rb', line 23 def to_debug_string() "#{@dst.to_debug_string()} = #{@src.to_debug_string()}" end |
#type_propergation(defs) ⇒ Object
133 134 135 |
# File 'lib/cast_off/compile/ir/sub_ir.rb', line 133 def type_propergation(defs) defs.type_resolve(@src) | @dst.union(@src) end |
#unboxing_prelude ⇒ Object
unboxing begin ###
28 29 30 31 32 33 |
# File 'lib/cast_off/compile/ir/sub_ir.rb', line 28 def unboxing_prelude() unless @src.can_unbox? && @dst.can_unbox? @src.box() @dst.box() end end |