@@ -1114,33 +1114,6 @@ void DwarfDebug::constructAndAddImportedEntityDIE(DwarfCompileUnit &TheCU,
1114
1114
D->addChild (TheCU.constructImportedEntityDIE (N));
1115
1115
}
1116
1116
1117
- // / Sort and unique GVEs by comparing their fragment offset.
1118
- static SmallVectorImpl<DwarfCompileUnit::GlobalExpr> &
1119
- sortGlobalExprs (SmallVectorImpl<DwarfCompileUnit::GlobalExpr> &GVEs) {
1120
- llvm::sort (
1121
- GVEs, [](DwarfCompileUnit::GlobalExpr A, DwarfCompileUnit::GlobalExpr B) {
1122
- // Sort order: first null exprs, then exprs without fragment
1123
- // info, then sort by fragment offset in bits.
1124
- // FIXME: Come up with a more comprehensive comparator so
1125
- // the sorting isn't non-deterministic, and so the following
1126
- // std::unique call works correctly.
1127
- if (!A.Expr || !B.Expr )
1128
- return !!B.Expr ;
1129
- auto FragmentA = A.Expr ->getFragmentInfo ();
1130
- auto FragmentB = B.Expr ->getFragmentInfo ();
1131
- if (!FragmentA || !FragmentB)
1132
- return !!FragmentB;
1133
- return FragmentA->OffsetInBits < FragmentB->OffsetInBits ;
1134
- });
1135
- GVEs.erase (std::unique (GVEs.begin (), GVEs.end (),
1136
- [](DwarfCompileUnit::GlobalExpr A,
1137
- DwarfCompileUnit::GlobalExpr B) {
1138
- return A.Expr == B.Expr ;
1139
- }),
1140
- GVEs.end ());
1141
- return GVEs;
1142
- }
1143
-
1144
1117
// Emit all Dwarf sections that should come prior to the content. Create
1145
1118
// global DIEs and emit initial debug info sections. This is invoked by
1146
1119
// the target AsmPrinter.
@@ -1156,14 +1129,6 @@ void DwarfDebug::beginModule(Module *M) {
1156
1129
assert (MMI->hasDebugInfo () &&
1157
1130
" DebugInfoAvailabilty unexpectedly not initialized" );
1158
1131
SingleCU = NumDebugCUs == 1 ;
1159
- DenseMap<DIGlobalVariable *, SmallVector<DwarfCompileUnit::GlobalExpr, 1 >>
1160
- GVMap;
1161
- for (const GlobalVariable &Global : M->globals ()) {
1162
- SmallVector<DIGlobalVariableExpression *, 1 > GVs;
1163
- Global.getDebugInfo (GVs);
1164
- for (auto *GVE : GVs)
1165
- GVMap[GVE->getVariable ()].push_back ({&Global, GVE->getExpression ()});
1166
- }
1167
1132
1168
1133
// Create the symbol that designates the start of the unit's contribution
1169
1134
// to the string offsets table. In a split DWARF scenario, only the skeleton
@@ -1189,58 +1154,6 @@ void DwarfDebug::beginModule(Module *M) {
1189
1154
// address table (.debug_addr) header.
1190
1155
AddrPool.setLabel (Asm->createTempSymbol (" addr_table_base" ));
1191
1156
DebugLocs.setSym (Asm->createTempSymbol (" loclists_table_base" ));
1192
-
1193
- for (DICompileUnit *CUNode : M->debug_compile_units ()) {
1194
- // FIXME: Move local imported entities into a list attached to the
1195
- // subprogram, then this search won't be needed and a
1196
- // getImportedEntities().empty() test should go below with the rest.
1197
- bool HasNonLocalImportedEntities = llvm::any_of (
1198
- CUNode->getImportedEntities (), [](const DIImportedEntity *IE) {
1199
- return !isa<DILocalScope>(IE->getScope ());
1200
- });
1201
-
1202
- if (!HasNonLocalImportedEntities && CUNode->getEnumTypes ().empty () &&
1203
- CUNode->getRetainedTypes ().empty () &&
1204
- CUNode->getGlobalVariables ().empty () && CUNode->getMacros ().empty ())
1205
- continue ;
1206
-
1207
- DwarfCompileUnit &CU = getOrCreateDwarfCompileUnit (CUNode);
1208
-
1209
- // Global Variables.
1210
- for (auto *GVE : CUNode->getGlobalVariables ()) {
1211
- // Don't bother adding DIGlobalVariableExpressions listed in the CU if we
1212
- // already know about the variable and it isn't adding a constant
1213
- // expression.
1214
- auto &GVMapEntry = GVMap[GVE->getVariable ()];
1215
- auto *Expr = GVE->getExpression ();
1216
- if (!GVMapEntry.size () || (Expr && Expr->isConstant ()))
1217
- GVMapEntry.push_back ({nullptr , Expr});
1218
- }
1219
-
1220
- DenseSet<DIGlobalVariable *> Processed;
1221
- for (auto *GVE : CUNode->getGlobalVariables ()) {
1222
- DIGlobalVariable *GV = GVE->getVariable ();
1223
- if (Processed.insert (GV).second )
1224
- CU.getOrCreateGlobalVariableDIE (GV, sortGlobalExprs (GVMap[GV]));
1225
- }
1226
-
1227
- for (auto *Ty : CUNode->getEnumTypes ()) {
1228
- // The enum types array by design contains pointers to
1229
- // MDNodes rather than DIRefs. Unique them here.
1230
- CU.getOrCreateTypeDIE (cast<DIType>(Ty));
1231
- }
1232
- for (auto *Ty : CUNode->getRetainedTypes ()) {
1233
- // The retained types array by design contains pointers to
1234
- // MDNodes rather than DIRefs. Unique them here.
1235
- if (DIType *RT = dyn_cast<DIType>(Ty))
1236
- // There is no point in force-emitting a forward declaration.
1237
- CU.getOrCreateTypeDIE (RT);
1238
- }
1239
- // Emit imported_modules last so that the relevant context is already
1240
- // available.
1241
- for (auto *IE : CUNode->getImportedEntities ())
1242
- constructAndAddImportedEntityDIE (CU, IE);
1243
- }
1244
1157
}
1245
1158
1246
1159
void DwarfDebug::finishEntityDefinitions () {
@@ -1405,6 +1318,33 @@ void DwarfDebug::finalizeModuleInfo() {
1405
1318
SkeletonHolder.computeSizeAndOffsets ();
1406
1319
}
1407
1320
1321
+ // / Sort and unique GVEs by comparing their fragment offset.
1322
+ static SmallVectorImpl<DwarfCompileUnit::GlobalExpr> &
1323
+ sortGlobalExprs (SmallVectorImpl<DwarfCompileUnit::GlobalExpr> &GVEs) {
1324
+ llvm::sort (
1325
+ GVEs, [](DwarfCompileUnit::GlobalExpr A, DwarfCompileUnit::GlobalExpr B) {
1326
+ // Sort order: first null exprs, then exprs without fragment
1327
+ // info, then sort by fragment offset in bits.
1328
+ // FIXME: Come up with a more comprehensive comparator so
1329
+ // the sorting isn't non-deterministic, and so the following
1330
+ // std::unique call works correctly.
1331
+ if (!A.Expr || !B.Expr )
1332
+ return !!B.Expr ;
1333
+ auto FragmentA = A.Expr ->getFragmentInfo ();
1334
+ auto FragmentB = B.Expr ->getFragmentInfo ();
1335
+ if (!FragmentA || !FragmentB)
1336
+ return !!FragmentB;
1337
+ return FragmentA->OffsetInBits < FragmentB->OffsetInBits ;
1338
+ });
1339
+ GVEs.erase (std::unique (GVEs.begin (), GVEs.end (),
1340
+ [](DwarfCompileUnit::GlobalExpr A,
1341
+ DwarfCompileUnit::GlobalExpr B) {
1342
+ return A.Expr == B.Expr ;
1343
+ }),
1344
+ GVEs.end ());
1345
+ return GVEs;
1346
+ }
1347
+
1408
1348
// Emit all Dwarf sections that should come after the content.
1409
1349
void DwarfDebug::endModule () {
1410
1350
// Terminate the pending line table.
@@ -1414,9 +1354,68 @@ void DwarfDebug::endModule() {
1414
1354
assert (CurFn == nullptr );
1415
1355
assert (CurMI == nullptr );
1416
1356
1417
- for (const auto &P : CUMap) {
1418
- auto &CU = *P.second ;
1419
- CU.createBaseTypeDIEs ();
1357
+ DenseMap<DIGlobalVariable *, SmallVector<DwarfCompileUnit::GlobalExpr, 1 >>
1358
+ GVMap;
1359
+ for (const GlobalVariable &Global : MMI->getModule ()->globals ()) {
1360
+ SmallVector<DIGlobalVariableExpression *, 1 > GVs;
1361
+ Global.getDebugInfo (GVs);
1362
+ for (auto *GVE : GVs)
1363
+ GVMap[GVE->getVariable ()].push_back ({&Global, GVE->getExpression ()});
1364
+ }
1365
+
1366
+ for (DICompileUnit *CUNode : MMI->getModule ()->debug_compile_units ()) {
1367
+ auto *CU = CUMap.lookup (CUNode);
1368
+
1369
+ // If this CU hasn't been emitted yet, create it here unless it is empty.
1370
+ if (!CU) {
1371
+ // FIXME: Move local imported entities into a list attached to the
1372
+ // subprogram, then this search won't be needed and a
1373
+ // getImportedEntities().empty() test should go below with the rest.
1374
+ bool HasNonLocalImportedEntities = llvm::any_of (
1375
+ CUNode->getImportedEntities (), [](const DIImportedEntity *IE) {
1376
+ return !isa<DILocalScope>(IE->getScope ());
1377
+ });
1378
+
1379
+ if (!HasNonLocalImportedEntities && CUNode->getEnumTypes ().empty () &&
1380
+ CUNode->getRetainedTypes ().empty () &&
1381
+ CUNode->getGlobalVariables ().empty () && CUNode->getMacros ().empty ())
1382
+ continue ;
1383
+
1384
+ CU = &getOrCreateDwarfCompileUnit (CUNode);
1385
+ }
1386
+
1387
+ // Global Variables.
1388
+ for (auto *GVE : CUNode->getGlobalVariables ()) {
1389
+ // Don't bother adding DIGlobalVariableExpressions listed in the CU if we
1390
+ // already know about the variable and it isn't adding a constant
1391
+ // expression.
1392
+ auto &GVMapEntry = GVMap[GVE->getVariable ()];
1393
+ auto *Expr = GVE->getExpression ();
1394
+ if (!GVMapEntry.size () || (Expr && Expr->isConstant ()))
1395
+ GVMapEntry.push_back ({nullptr , Expr});
1396
+ }
1397
+
1398
+ DenseSet<DIGlobalVariable *> Processed;
1399
+ for (auto *GVE : CUNode->getGlobalVariables ()) {
1400
+ DIGlobalVariable *GV = GVE->getVariable ();
1401
+ if (Processed.insert (GV).second )
1402
+ CU->getOrCreateGlobalVariableDIE (GV, sortGlobalExprs (GVMap[GV]));
1403
+ }
1404
+
1405
+ for (auto *Ty : CUNode->getEnumTypes ())
1406
+ CU->getOrCreateTypeDIE (cast<DIType>(Ty));
1407
+
1408
+ for (auto *Ty : CUNode->getRetainedTypes ())
1409
+ if (DIType *RT = dyn_cast<DIType>(Ty))
1410
+ // There is no point in force-emitting a forward declaration.
1411
+ CU->getOrCreateTypeDIE (RT);
1412
+
1413
+ // Emit imported entities last so that the relevant context
1414
+ // is already available.
1415
+ for (auto *IE : CUNode->getImportedEntities ())
1416
+ constructAndAddImportedEntityDIE (*CU, IE);
1417
+
1418
+ CU->createBaseTypeDIEs ();
1420
1419
}
1421
1420
1422
1421
// If we aren't actually generating debug info (check beginModule -
0 commit comments