Currently, the dead functions information getting from optimizations remarks does not contain debug location, but knowing where these dead functions locate could be useful for debugging or for detecting dead code.
Cause in LTO::addRegularLTO() we use BitcodeModule::getLazyModule() to read the bitcode module, when we pass Function F to ore::NV(), F is not materialized, so F->getSubprogram() returns nullptr, and there is no debug location information of dead functions in optimizations remarks.
This patch call F->materialize() before we pass Function F to ore::NV(), then debug location information will be emitted for dead functions in optimization remarks.
Were we eventually materializing these dead functions without this change? If not, this seems like a compile time degradation. Would it work to move the materialize call later, capture the OptimizationRemark in a variable, and guard the materialization by isEnabled() on the remark?