Supporting dumping, switching off and debug printing of optimization phases.

These changes were checked for stability and performance issues on Linux and Windows.