Class: CastOff::Compiler::Translator::CFG::Information

Inherits:
Object
  • Object
show all
Includes:
SimpleIR, Util
Defined in:
lib/cast_off/compile/information.rb

Constant Summary

Constants included from SimpleIR

SimpleIR::SPLATCALL_LIMIT, SimpleIR::SupportLoopInstruction

Constants included from Instruction

Instruction::BlockSeparator, Instruction::BranchInstruction, Instruction::IgnoreInstruction, Instruction::JumpOrReturnInstruction, Instruction::SupportInstruction, Instruction::TypeInfoUser, Instruction::VM_CALL_ARGS_BLOCKARG_BIT, Instruction::VM_CALL_ARGS_SPLAT_BIT, Instruction::VM_CALL_FCALL_BIT, Instruction::VM_CALL_OPT_SEND_BIT, Instruction::VM_CALL_SUPER_BIT, Instruction::VM_CALL_TAILCALL_BIT, Instruction::VM_CALL_TAILRECURSION_BIT, Instruction::VM_CALL_VCALL_BIT

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from SimpleIR

#block_argument_is_unsupported, #generate_ir

Methods included from Util

#bug, #dlog, #todo, #vlog

Constructor Details

#initialize(block, vars, a, c, defs, undefs, ptr_defs, ptrs) ⇒ Information

Returns a new instance of Information.



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/cast_off/compile/information.rb', line 11

def initialize(block, vars, a, c, defs, undefs, ptr_defs, ptrs)
  @block = block
  @alias = a.instance_of?(Alias) ? a : Alias.new(@block, a, vars, ptrs)
  @condition = c
  @definition = defs
  @ptr_defs = ptr_defs
  @undefs = undefs
  @ptrs = ptrs
  @vars = vars
  check_initialize()
end

Instance Attribute Details

#aliasObject (readonly)

Returns the value of attribute alias.



9
10
11
# File 'lib/cast_off/compile/information.rb', line 9

def alias
  @alias
end

#blockObject (readonly)

Returns the value of attribute block.



9
10
11
# File 'lib/cast_off/compile/information.rb', line 9

def block
  @block
end

#definitionObject (readonly)

Returns the value of attribute definition.



9
10
11
# File 'lib/cast_off/compile/information.rb', line 9

def definition
  @definition
end

#undefsObject (readonly)

Returns the value of attribute undefs.



9
10
11
# File 'lib/cast_off/compile/information.rb', line 9

def undefs
  @undefs
end

Instance Method Details

#==(other) ⇒ Object



119
120
121
122
# File 'lib/cast_off/compile/information.rb', line 119

def ==(other)
  check_initialize()
  eql?(other)
end

#conditionObject



27
28
29
# File 'lib/cast_off/compile/information.rb', line 27

def condition()
  @condition
end

#condition=(cond) ⇒ Object



31
32
33
34
35
# File 'lib/cast_off/compile/information.rb', line 31

def condition=(cond)
  bug() unless @condition
  bug() unless cond.instance_of?(Condition)
  @condition = cond
end

#definition_of(var) ⇒ Object



158
159
160
161
# File 'lib/cast_off/compile/information.rb', line 158

def definition_of(var)
  check_initialize()
  @definition.select{|d| d.result_variable == var}
end

#dupObject



149
150
151
152
# File 'lib/cast_off/compile/information.rb', line 149

def dup()
  check_initialize()
  Information.new(@block, @vars, @alias.dup(), @condition ? @condition.dup() : nil, @definition.dup(), @undefs.dup(), @ptr_defs, @ptrs)
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


109
110
111
112
113
114
115
116
117
# File 'lib/cast_off/compile/information.rb', line 109

def eql?(other)
  check_initialize()
  bug() unless other.instance_of?(Information)
  bug() unless @block == other.block
  return false unless (@definition - other.definition).empty? && (other.definition - @definition).empty?
  return false unless (@undefs - other.undefs).empty? && (other.undefs - @undefs).empty?
  return false unless @condition == other.condition
  @alias == other.alias
end

#exact_class_resolve(var) ⇒ Object



214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
# File 'lib/cast_off/compile/information.rb', line 214

def exact_class_resolve(var)
  check_initialize()
  return false if !var.is_a?(Variable) || var.class_exact?

  ds = @definition.select{|d| var == d.result_variable }
  if @undefs.include?(var) || ds.empty?
    case var
    when TmpBuffer, Pointer, Argument, Self
      return false
    else
      bug(var)
    end
  else
    ds.each do |d|
      r = d.result_variable
      return false unless r.class_exact?
    end
    var.is_class_exact()
    return true
  end
  bug()
end

#final_stateObject



50
51
52
53
54
55
56
57
58
# File 'lib/cast_off/compile/information.rb', line 50

def final_state()
  # variable_condition までは final_state にならないので注意
  check_initialize()
  final_alias = @alias.final_state()
  final_cond = @condition ? @condition.final_state() : nil
  final_defs = (@definition - @block.ekill) | @block.egen
  final_undefs = @undefs + @block.ekill.map{|ir| ir.result_variable} - @block.egen.map{|ir| ir.result_variable}
  Information.new(@block, @vars, final_alias, final_cond, final_defs, final_undefs, @ptr_defs, @ptrs)
end

#find_same_variables(var) ⇒ Object



60
61
62
63
# File 'lib/cast_off/compile/information.rb', line 60

def find_same_variables(var)
  check_initialize()
  @alias.find_set(var)
end

#flatten!Object



140
141
142
143
# File 'lib/cast_off/compile/information.rb', line 140

def flatten!
  check_initialize()
  @definition.flatten!
end

#freezeObject



37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/cast_off/compile/information.rb', line 37

def freeze()
  super()
  check_initialize()
  @alias.freeze()
  @definition.freeze()
  @ptr_defs.freeze()
  @undefs.freeze()
  @ptrs.freeze()
  @vars.freeze()
  @condition.freeze()
  self
end

#get_variable(var) ⇒ Object



175
176
177
178
179
180
# File 'lib/cast_off/compile/information.rb', line 175

def get_variable(var)
  vars = get_variables(var)
  boxed_p = vars.first.boxed?
  bug() if boxed_p ? vars.find{|v| v.unboxed?} : vars.find{|v| v.boxed?}
  vars.first
end

#get_variables(var) ⇒ Object



168
169
170
171
172
173
# File 'lib/cast_off/compile/information.rb', line 168

def get_variables(var)
  check_initialize()
  ds = @definition.select{|d| var == d.result_variable }
  bug() if ds.empty?
  ds.map{|d| d.result_variable}
end

#hashObject



145
146
147
# File 'lib/cast_off/compile/information.rb', line 145

def hash()
  bug()
end

#initialize_conditionObject



23
24
25
# File 'lib/cast_off/compile/information.rb', line 23

def initialize_condition()
  @condition = Condition.new(@block, @ptrs, @alias)
end

#kill_definition(other) ⇒ Object



102
103
104
105
106
107
# File 'lib/cast_off/compile/information.rb', line 102

def kill_definition(other)
  @definition.delete_if do |d0|
    next unless d0.result_variable
    not other.definition.find{|d1| d0.result_variable == d1.result_variable}
  end
end

#mark(var) ⇒ Object



182
183
184
185
186
# File 'lib/cast_off/compile/information.rb', line 182

def mark(var)
  check_initialize()
  ds = @definition.select {|d| var == d.result_variable }
  ds.inject(false){|change, d| d.alive() || change}
end

#propergate_boxed_value_backward(var) ⇒ Object



255
256
257
258
259
260
261
262
263
264
265
266
267
268
# File 'lib/cast_off/compile/information.rb', line 255

def propergate_boxed_value_backward(var)
  check_initialize()
  bug() unless var.boxed?
  ds = @definition.select {|d| var == d.result_variable }
  if ds.empty?
    case var
    when TmpBuffer, Pointer, Argument, Self, ConstWrapper, Literal
      return false
    else
      bug(var)
    end
  end
  ds.inject(false){|change, d| d.result_variable.box() || change}
end

#propergate_boxed_value_forward(var) ⇒ Object

unboxing begin ###



238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
# File 'lib/cast_off/compile/information.rb', line 238

def propergate_boxed_value_forward(var)
  check_initialize()
  return false if var.boxed?
  ds = @definition.select {|d| var == d.result_variable }
  if ds.empty?
    bug(var) unless var.is_a?(Literal) # should be boxed => TmpBuffer, Pointer, Argument, Self, ConstWrapper
    return false
  end
  ds.each do |d|
    if d.result_variable.boxed?
      var.box()
      return true
    end
  end
  return false
end

#reject!(&b) ⇒ Object



135
136
137
138
# File 'lib/cast_off/compile/information.rb', line 135

def reject!(&b)
  check_initialize()
  @definition.reject!{|ir| yield ir}
end

#replace_entry(ir) ⇒ Object



129
130
131
132
133
# File 'lib/cast_off/compile/information.rb', line 129

def replace_entry(ir)
  check_initialize()
  i = @definition.index(ir)
  @definition[i] = ir if i
end

#sizeObject



124
125
126
127
# File 'lib/cast_off/compile/information.rb', line 124

def size()
  check_initialize()
  @definition.size()
end

#step(ir) ⇒ Object



86
87
88
89
90
91
92
93
# File 'lib/cast_off/compile/information.rb', line 86

def step(ir)
  check_initialize()
  @alias.step(ir)
  bug() unless @condition.instance_of?(Condition)
  @condition.step(ir)
  delete(ir)
  add(ir)
end

#to_sObject



154
155
156
# File 'lib/cast_off/compile/information.rb', line 154

def to_s()
  @definition.join("\n")
end

#type_resolve(var) ⇒ Object



188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
# File 'lib/cast_off/compile/information.rb', line 188

def type_resolve(var)
  check_initialize()
  #return false if var.dynamic? || var.static?
  return false unless var.is_a?(Variable)
  ret = false

  bug() unless @condition
  ret |= @condition.use(var)
  ds = @definition.select {|d| var == d.result_variable }
  if @undefs.include?(var) || ds.empty?
    case var
    when TmpBuffer
      ret |= var.is_dynamic()
    when Pointer, Argument
      ret |= var.is_dynamic()
    when Self
      bug() if var.undefined?
    else
      bug(var)
    end
  else
    ds.each { |d| ret = true if var.union(d.result_variable) }
  end
  ret
end

#undefined_variablesObject



163
164
165
166
# File 'lib/cast_off/compile/information.rb', line 163

def undefined_variables()
  check_initialize()
  @undefs
end

#validateObject



65
66
67
68
69
70
71
72
# File 'lib/cast_off/compile/information.rb', line 65

def validate()
  check_initialize()
  @alias.validate()
  bug() unless @alias.final_state() == @block.information.alias.final_state()
  defs = @definition.map{|d| d.result_variable}.compact()
  bug() unless (defs & @undefs).empty?
  bug() unless (@vars - (defs | @undefs)).empty?
end

#validate_finalObject



74
75
76
77
78
79
80
81
82
83
84
# File 'lib/cast_off/compile/information.rb', line 74

def validate_final()
  check_initialize()
  @alias.validate()
  bug() unless @alias == @block.information.alias.final_state()
  defs = @definition.map{|d| d.result_variable}.compact()
  bug() unless (defs & @undefs).empty?
  bug() unless (@vars - (defs | @undefs)).empty?
  bug() unless @condition.instance_of?(Condition)
  bug() unless @block.information.condition.instance_of?(Condition)
  bug() unless @condition == @block.information.condition.final_state()
end

#|(other) ⇒ Object



95
96
97
98
99
100
# File 'lib/cast_off/compile/information.rb', line 95

def |(other)
  check_initialize()
  bug() unless other.instance_of?(Information)
  bug() if @condition
  Information.new(@block, @vars, @alias.union(other.alias), nil, @definition | other.definition, @undefs | other.undefs, @ptr_defs, @ptrs)
end