!Note! Extracted from the following patch for review purpose only, should
be squashed with the next patch (D144004) before committing.
Currently the back-end emits imported entities in DwarfDebug::beginModule().
However in case an imported declaration is a function, it must point to an
abstract subprogram if it exists (see PR51501). But in DwarfDebug::beginModule()
the DWARF generator doesn't have information to identify if an abstract
subprogram needs to be created.
Only by entering DwarfDebug::endModule() all subprograms are processed,
so it's clear which subprogram DIE should be referred to. Hence, the patch moves
the emission there.
The patch is need to fix PR51501, but it only does the preliminary
work. Since it changes the order of debug entities in emitted DWARF and
therefore affect many tests it's separated from the fix for the sake of
simplifying review.
Note that there are other issues with handling an imported declaration in
DwarfDebug::beginModule(). They are described in more details in D114705.
Could we iterate the CUMap directly - to avoid needing to do lookups? like teh old code - *p.first would be the DICompileUnit* CUNode?