Module: Laser::Analysis::ControlFlow::ConstantPropagation
- Included in:
- ControlFlowGraph
- Defined in:
- lib/laser/analysis/control_flow/constant_propagation.rb
Overview
Sparse Conditional Constant Propagation: Wegman and Zadeck Love those IBMers Using Morgan's implementation though.
Instance Attribute Summary (collapse)
-
- (Object) constants
readonly
Returns the value of attribute constants.
Instance Method Summary (collapse)
-
- (Object) perform_constant_propagation(opts = {})
Only public method: mutably turns the CFG into a constant-propagated one.
Instance Attribute Details
- (Object) constants (readonly)
Returns the value of attribute constants
10 11 12 |
# File 'lib/laser/analysis/control_flow/constant_propagation.rb', line 10 def constants @constants end |
Instance Method Details
- (Object) perform_constant_propagation(opts = {})
Only public method: mutably turns the CFG into a constant-propagated one. Each binding will have a value assigned to it afterward: either the constant, as a Ruby object (or a proxy to one), UNDEFINED, or VARYING.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/laser/analysis/control_flow/constant_propagation.rb', line 15 def perform_constant_propagation(opts={}) opts = {fixed_methods: {}, initial_block: self.enter}.merge(opts) initialize_constant_propagation(opts) visited = Set.new worklist = Set.new blocklist = Set[opts[:initial_block]] while worklist.any? || blocklist.any? while worklist.any? constant_propagation_for_instruction( worklist.pop, blocklist, worklist, opts) end while blocklist.any? constant_propagation_for_block( blocklist.pop, visited, blocklist, worklist, opts) end end teardown_constant_propagation @constants = find_remaining_constants end |