code: def const_elimination_block(block):
      # shallow copy hides changes on f.operations during the loop
      for op in list(block.operations):
          if op.op_type == "const":
              continue
  
          for b in op.blocks:
              const_elimination_block(b)
  
          all_outputs_are_const = True
          for i, o in enumerate(op.outputs):
              if o.val is not None:
                  with block:
                      res = mb.const(
                          val=o.val,
                          mode=get_const_mode(o.val),
                          before_op=op,
                          # same var name, but different python
                          # instance does not violate SSA property.
                          name=o.name,
                      )
                  op.enclosing_block.replace_uses_of_var_after_op(
                      anchor_op=op, old_var=o, new_var=res
                  )
                  # rename the const output
                  o.set_name(o.name + "_ignored")
              else:
                  all_outputs_are_const = False
  
          if all_outputs_are_const:
              op.remove_from_block()
  
file_path: turicreate/src/external/coremltools_wrap/coremltools/coremltools/converters/mil/mil/passes/const_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 2 for calling a global function with example usage: const_elimination_block(block) without return types