This patch proposes to move the emission of global variables, types, imported entities, etc from DwarfDebug::beginModule() to DwarfDebug::endModule().
Effectively, this changes nothing but the order of debug entities.
Note that the order of emitted compile units may also be changed as now we emit units that contain subprograms first and then all other non-empty units.
This is a part extracted from D113741.
The motivation behind this change is the following:
(1) DwarfDebug::beginModule() is run at the very beginning of backend's pipeline, from this time IR can be significantly changed by target-specific passes, and debug info never accounts for these changes (for example, address space lowering done by generic-to-nvvm for NVPTX backend).
(2) imported subprogram names should refer to an abstract subprogram if it exists, but it isn't known in DwarfDebug::beginModule() (it's possible to make some guesses based on location info, but it's not quite reliable);
(3) aforementioned entities if they are scoped within a bracketed block (subject of D113741) couldn't be emitted in DwarfDebug::beginModule() (they need parent emitted first). Another problem is if we try to gather some information about local entities and defer their emission (till subprogram's processing or DwarfDebug::endModule()) all the gathered details might be irrelevant by the time the entities are being emitted (because of (1)).
This patch isn't intended to fix something but the issue (1), but I believe it should also simplify reviewing and testing of D113741.
It also removes some comments that I believe are no longer relevant.