Add support for pattern-replace and code optimizations.