code: def loop_invariant_elimination(prog):
      """
      prog: Program
  
      # When a block does not modify a block input var, eliminate that block
      # input var and use the corresponding var in the outer scope. Example:
      #
      # Given:
      #    main(%a: (1, 2, fp32),
      #         %b: (1, 2, fp32)) {
      #      block0() {
      #        %loop:0: (1, 2, fp32), %loop:1: (1, 2, fp32) = \
      #        while_loop(loop_vars=(%a, %b))
      #          loop_cond(%a.x, %b.x) {
      #            %cond_var: (bool) = some_op(x=%a.x, y=%b.x)
      #          } -> (%cond_var)
      #          loop_body(%a.x, %b.x) {
      #            %add_0: (1, 2, fp32) = add(x=%a.x, y=%b.x)
      #          } -> (%add_0, %b.x)
      #      } -> (%loop:0, %loop:1)
      #    }
      #
      # (Notice that %b.x is constant through while loop iterates)
      #
      # Result:
      #    main(%a: (1, 2, fp32),
      #         %b: (1, 2, fp32)) {
      #      block0() {
      #        %loop:1: (1, 2, fp32) = identity(x=%b)
      #        %loop:0: (1, 2, fp32) = \
      #        while_loop(loop_vars=(%a))
      #          loop_cond(%a.x) {
      #            %cond_var: (bool) = some_op(x=%a.x, y=%b)
      #          } -> (%cond_var)
      #          loop_body(%a.x) {
      #            %add_0: (1, 2, fp32) = add(x=%a.x, y=%b)
      #          } -> (%add_0)
      #      } -> (%loop:0, %loop:1)
      #    }
      #
      # where we eliminate loop invariant %b.x from while_loop, which returns 1
      # instead of 2 outputs. We also preserve the return var names with
      # identity.
      """
      for f_name, f in prog.functions.items():
          loop_invariant_elimination_block(f)
  
file_path: turicreate/src/external/coremltools_wrap/coremltools/coremltools/converters/mil/mil/passes/loop_invariant_elimination.py
imports: from __future__ import print_function
  from __future__ import division
  from __future__ import absolute_import
  import numpy
  import six
  from coremltools.converters.mil.mil import Builder
  from coremltools.converters.mil.mil.passes.pass_registry import register_pass
label_desc: Use image node_id 3 for calling a global function with example usage: loop_invariant_elimination(prog) without return types