peephole.mli 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. (** Peephole optimisation on generated assembly. *)
  2. (** This is a final optimisation round that makes use of optimised VM
  3. instructions and common optimisable constructions in generated assembly
  4. code.
  5. There are two optimisations on branch instructions: if the branch is never
  6. taken, remove it. If the branch is always taken, replace it with a jump
  7. instruction:
  8. {v bloadc_t
  9. branch_t label
  10. OR
  11. bloadc_f
  12. branch_f label v}
  13. becomes [jump label].
  14. {v bloadc_f
  15. branch_t label
  16. OR
  17. bloadc_t
  18. branch_f label v}
  19. is removed.
  20. The last performed optimisation is somewhat more complex, namely the
  21. conversion of addition or subtraction of an integer variable by a constant
  22. value, to specialised [iinc|idec] instructions:
  23. {v iload L | iload L
  24. iloadc C | iloadc_1
  25. i{add,sub} | i{add,sub}
  26. istore L | istore L
  27. | |
  28. v v
  29. i{inc,dec} L C | i{inc,dec}_1 L v}
  30. Note that the [iload] and [iloadc] may also be in reverse order, which in
  31. CiviC code is the difference between [i = i + 1;] and [i = 1 + i;]. Both
  32. orders of succession are supported by the implementation.
  33. *)
  34. (** Main phase function, called by {!Main}. *)
  35. val phase : Main.phase_func