CodeGenModule::EmitTargetMetadata() is redundant on all targets but xcore
| Bugzilla Link | 23927 |
| Resolution | FIXED |
| Resolved on | Sep 03, 2021 02:17 |
| Version | trunk |
| OS | Windows NT |
| Reporter | LLVM Bugzilla Contributor |
| CC | @nigelp-xmos,@zygoloid |
Extended Description
The loop in EmitTargetMetadata introduced in r212263 iterates over all MangledDeclNames (the module may have 1000s of them), for every one performing a lookup in the module symbol table and then calling emitTargetMD() which is a no-op on all targets but xcore.
Hopefully all of this optimizes out in release builds. In Debug builds the code is still there, slowing down every run as EmitTargetMetadata is always called by CodeGenModule::Release().
This xcore-specific functionality should probably move into xcore target rather than living in CodeGenModule. At the very least it should bail out early if target != xcore and skip the loop.
I don't know if this is wrong: EmitDeclMetadata() is called if (getCodeGenOpts().EmitDeclMetadata) but EmitTargetMetadata() is always called regardless the flag.
In addition, MangledDeclNames was modified from a DenseMap into a MapVector, a heavier and slower data structure. If the code is decoupled into xmos target maybe MangledDeclNames could be DenseMap again.
Finally, this code does not appear to be covered by regression tests at all. If the whole function is #if 0 and MangledDeclNames is DenseMap, regression tests pass, at least on Windows and Linux.
https://reviews.llvm.org/D77068 moved the loop into the XCore target.