Introduce needsCodegen.

This is a backport of the code from 2.065.