Class: CastOff::Compiler::SimpleIR::IR
- Inherits:
-
Object
- Object
- CastOff::Compiler::SimpleIR::IR
show all
- Includes:
- Util
- Defined in:
- lib/cast_off/compile/ir/simple_ir.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Util
#bug, #dlog, #todo, #vlog
Constructor Details
#initialize(insn, cfg) ⇒ IR
Returns a new instance of IR.
592
593
594
595
596
597
598
599
600
601
602
603
|
# File 'lib/cast_off/compile/ir/simple_ir.rb', line 592
def initialize(insn, cfg)
@insn = insn
@cfg = cfg
@translator = cfg.translator
@configuration = @translator.configuration
@dependency = @translator.dependency
@information = nil
@alias = nil
@alive = false
@valish_p = false
@sampling_variable = []
end
|
Instance Attribute Details
#alias ⇒ Object
Returns the value of attribute alias.
590
591
592
|
# File 'lib/cast_off/compile/ir/simple_ir.rb', line 590
def alias
@alias
end
|
#insn ⇒ Object
Returns the value of attribute insn.
590
591
592
|
# File 'lib/cast_off/compile/ir/simple_ir.rb', line 590
def insn
@insn
end
|
Instance Method Details
#add_sampling_variable(var) ⇒ Object
634
635
636
|
# File 'lib/cast_off/compile/ir/simple_ir.rb', line 634
def add_sampling_variable(var)
@sampling_variable |= [var]
end
|
#alive ⇒ Object
638
639
640
|
# File 'lib/cast_off/compile/ir/simple_ir.rb', line 638
def alive()
@alive ? false : (@alive = true)
end
|
#alive? ⇒ Boolean
642
643
644
|
# File 'lib/cast_off/compile/ir/simple_ir.rb', line 642
def alive?
@alive
end
|
#dispatch_method? ⇒ Boolean
812
813
814
815
816
|
# File 'lib/cast_off/compile/ir/simple_ir.rb', line 812
def dispatch_method?
return true if !@translator.inline_block? && self.is_a?(LoopIR)
self.is_a?(InvokeIR) || self.is_a?(YieldIR)
end
|
#generate_guard(vars) ⇒ Object
659
660
661
662
663
664
665
666
667
|
# File 'lib/cast_off/compile/ir/simple_ir.rb', line 659
def generate_guard(vars)
target = standard_guard_target()
if target.is_a?(Variable) && !target.dynamic? && @insn.need_guard?
StandardGuard.new(target, vars, @insn, @cfg)
else
nil
end
end
|
#get_definition(target) ⇒ Object
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
|
# File 'lib/cast_off/compile/ir/simple_ir.rb', line 748
def get_definition(target)
case target
when Literal
return [target]
when Variable
ds = @information.definition_of(target)
if ds.empty?
case target
when TmpBuffer, Pointer, Argument, Self
return []
else
bug() unless @information.undefined_variables.include?(target)
return [] end
end
ary = []
ds.each do |d|
case d
when SubIR
src = d.src
if src.is_a?(TmpVariable)
ary += d.get_definition(src)
else
ary << d
end
when CallIR
ary << d
else
bug()
end
end
return ary
else
raise(UnsupportedError.new("Currently, CastOff cannot compile this method or block"))
end
bug()
end
|
#get_definition_str(target) ⇒ Object
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
|
# File 'lib/cast_off/compile/ir/simple_ir.rb', line 786
def get_definition_str(target)
ary = get_definition(target)
ary.map {|d|
case d
when Literal
d.source
when SubIR
d.src.source
when LoopIR, VMInsnIR
"vm internal value"
when InvokeIR
"result of #{d.to_verbose_string}"
when YieldIR
"result of yield"
else
bug()
end
}.join("\n")
end
|
#get_usage ⇒ Object
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
|
# File 'lib/cast_off/compile/ir/simple_ir.rb', line 669
def get_usage()
blocks = []
usage = {}
irs = [self]
change = true
while change
change = false
@cfg.blocks.each do |b|
foo = b.irs & irs
bar = b.information.definition & irs
if foo.size > 0 || bar.size > 0
vars = []
bar.each do |ir|
result_variable = ir.result_variable
next unless result_variable
vars << result_variable
end
b.irs.each do |ir|
case ir
when SubIR
src = ir.src
dst = ir.dst
if src != dst
if vars.include?(dst)
vars.reject! {|v| v == dst}
end
if vars.include?(src)
if dst.is_a?(Pointer)
usage[:escape] = ir
return usage
end
vars |= [dst]
if !irs.include?(ir)
irs << ir
change = true
end
end
end
when JumpIR
when ParamIR
if vars.include?(ir.param_value) && !irs.include?(ir)
irs << ir
change = true
end
when CallIR
argc = ir.argc
return_value = ir.return_value
param = ir.param_variables()
param.each do |p|
if vars.include?(p)
usage[[param[0], ir]] = vars.index(param[0])
break
end
end
if vars.include?(return_value)
vars.reject! {|v| v == return_value}
end
when ReturnIR
if vars.include?(ir.return_value)
usage[:escape] = ir
return usage
end
end
result_variable = ir.result_variable
vars |= [result_variable] if foo.include?(ir) && result_variable
end
end
end
end
usage
end
|
#get_variable(v) ⇒ Object
806
807
808
809
810
|
# File 'lib/cast_off/compile/ir/simple_ir.rb', line 806
def get_variable(v)
bug() unless v.is_a?(Variable)
bug() unless @information
@information.get_variable(v)
end
|
#inlining_target? ⇒ Boolean
818
819
820
|
# File 'lib/cast_off/compile/ir/simple_ir.rb', line 818
def inlining_target?
false
end
|
#propergate_boxed_value(defs) ⇒ Object
618
619
620
|
# File 'lib/cast_off/compile/ir/simple_ir.rb', line 618
def propergate_boxed_value(defs)
bug()
end
|
#propergate_guard_usage ⇒ Object
655
656
657
|
# File 'lib/cast_off/compile/ir/simple_ir.rb', line 655
def propergate_guard_usage()
end
|
#reset ⇒ Object
646
647
648
649
|
# File 'lib/cast_off/compile/ir/simple_ir.rb', line 646
def reset()
@alive = false
@variables.each{|v| v.reset()}
end
|
#sampling_variable ⇒ Object
623
624
625
626
627
628
629
630
631
632
|
# File 'lib/cast_off/compile/ir/simple_ir.rb', line 623
def sampling_variable()
s = []
if @configuration.development?
@sampling_variable.each do |var|
next if var.is_a?(Literal)
s << " sampling_variable(#{var.boxed_form}, ID2SYM(rb_intern(#{var.source.inspect})));"
end
end
s.empty? ? nil : s.join("\n")
end
|
#set_info(d) ⇒ Object
744
745
746
|
# File 'lib/cast_off/compile/ir/simple_ir.rb', line 744
def set_info(d)
@information = d
end
|
#standard_guard_target ⇒ Object
651
652
653
|
# File 'lib/cast_off/compile/ir/simple_ir.rb', line 651
def standard_guard_target()
nil
end
|
#unboxing_prelude ⇒ Object
614
615
616
|
# File 'lib/cast_off/compile/ir/simple_ir.rb', line 614
def unboxing_prelude()
bug()
end
|
#vanish ⇒ Object
605
606
607
|
# File 'lib/cast_off/compile/ir/simple_ir.rb', line 605
def vanish()
@vanish_p = true
end
|
#vanish? ⇒ Boolean
609
610
611
|
# File 'lib/cast_off/compile/ir/simple_ir.rb', line 609
def vanish?
@vanish_p
end
|