LLVM: lib/DebugInfo/LogicalView/Core/LVScope.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
21
22using namespace llvm;
24
25#define DEBUG_TYPE "Scope"
26
27namespace {
28const char *const KindArray = "Array";
29const char *const KindBlock = "Block";
30const char *const KindCallSite = "CallSite";
31const char *const KindClass = "Class";
32const char *const KindCompileUnit = "CompileUnit";
33const char *const KindEnumeration = "Enumeration";
34const char *const KindFile = "File";
35const char *const KindFunction = "Function";
36const char *const KindInlinedFunction = "InlinedFunction";
37const char *const KindModule = "Module";
38const char *const KindNamespace = "Namespace";
39const char *const KindStruct = "Struct";
40const char *const KindTemplateAlias = "TemplateAlias";
41const char *const KindTemplatePack = "TemplatePack";
42const char *const KindUndefined = "Undefined";
43const char *const KindUnion = "Union";
44}
45
46
47
48
49
51 const char *Kind = KindUndefined;
52 if (getIsArray())
53 Kind = KindArray;
54 else if (getIsModule())
55 Kind = KindModule;
56 else if (getIsBlock())
57 Kind = KindBlock;
58 else if (getIsCallSite())
59 Kind = KindCallSite;
60 else if (getIsCompileUnit())
61 Kind = KindCompileUnit;
62 else if (getIsEnumeration())
63 Kind = KindEnumeration;
64 else if (getIsInlinedFunction())
65 Kind = KindInlinedFunction;
66 else if (getIsNamespace())
67 Kind = KindNamespace;
68 else if (getIsTemplatePack())
69 Kind = KindTemplatePack;
70 else if (getIsRoot())
71 Kind = KindFile;
72 else if (getIsTemplateAlias())
73 Kind = KindTemplateAlias;
74 else if (getIsClass())
75 Kind = KindClass;
76 else if (getIsFunction())
77 Kind = KindFunction;
78 else if (getIsStructure())
79 Kind = KindStruct;
80 else if (getIsUnion())
81 Kind = KindUnion;
83}
84
109
110const LVTypes LVScope::EmptyTypes{};
111const LVSymbols LVScope::EmptySymbols{};
112const LVScopes LVScope::EmptyScopes{};
113
115 const auto UnsortedChildren = getChildren();
116 LVElements Elements{UnsortedChildren.begin(), UnsortedChildren.end()};
117 if (SortFunction)
120}
121
124 if (Element->getIsType())
126 else if (Element->getIsScope())
128 else if (Element->getIsSymbol())
130 else if (Element->getIsLine())
132 else
134}
135
136
139 assert(->getParent() && "Line already inserted");
141 Lines = std::make_unique();
142
143
145 Line->setParent(this);
146
147
149
150
151
152
153
154
155
156
157 traverseParents(&LVScope::getHasLines, &LVScope::setHasLines);
158}
159
160
163 assert(->getParent() && "Location already inserted");
165 Ranges = std::make_unique();
166
167
170
172 setHasRanges();
173}
174
175
178 assert(->getParent() && "Scope already inserted");
180 Scopes = std::make_unique();
181
182
184 Scope->setParent(this);
185
186
188
189
190
191
192 if (Scope->getIsGlobalReference())
193 traverseParents(&LVScope::getHasGlobals, &LVScope::setHasGlobals);
194 else
195 traverseParents(&LVScope::getHasLocals, &LVScope::setHasLocals);
196
197
198 traverseParents(&LVScope::getHasScopes, &LVScope::setHasScopes);
199}
200
201
204 assert(->getParent() && "Symbol already inserted");
206 Symbols = std::make_unique();
207
208
210 Symbol->setParent(this);
211
212
214
215
216
217
218 if (Symbol->getIsGlobalReference())
219 traverseParents(&LVScope::getHasGlobals, &LVScope::setHasGlobals);
220 else
221 traverseParents(&LVScope::getHasLocals, &LVScope::setHasLocals);
222
223
224 traverseParents(&LVScope::getHasSymbols, &LVScope::setHasSymbols);
225}
226
227
230 assert(->getParent() && "Type already inserted");
232 Types = std::make_unique();
233
234
236 Type->setParent(this);
237
238
240
241
242
243
244 if (Type->getIsGlobalReference())
245 traverseParents(&LVScope::getHasGlobals, &LVScope::setHasGlobals);
246 else
247 traverseParents(&LVScope::getHasLocals, &LVScope::setHasLocals);
248
249
250 traverseParents(&LVScope::getHasTypes, &LVScope::setHasTypes);
251}
252
253
255
257 Location->setLowerAddress(LowerAddress);
258 Location->setUpperAddress(UpperAddress);
259 Location->setIsAddressRange();
260
262}
263
267 };
268 auto RemoveElement = [Element, Predicate](auto &Container) -> bool {
270 if (Iter != Container->end()) {
271 Container->erase(Iter, Container->end());
273 return true;
274 }
275 return false;
276 };
277
278
279
280 if (Element->getIsLine())
281 return RemoveElement(Lines);
282
283 if (Element->getIsSymbol())
284 return RemoveElement(Symbols);
285 if (Element->getIsType())
286 return RemoveElement(Types);
287 if (Element->getIsScope())
288 return RemoveElement(Scopes);
289
290 return false;
291}
292
294 setAddedMissing();
296 return;
297
298
300 if (!ReferenceSymbols)
301 return;
302
304 References.append(ReferenceSymbols->begin(), ReferenceSymbols->end());
305
306
307
310 if (Symbol->getHasReferenceAbstract())
312
313
314
315 if (References.size()) {
317 dbgs() << "Insert Missing Inlined Elements\n"
320 << "\n";
321 });
325 << "\n";
326 });
327
328
329
330
334 Symbol->setIsOptimized();
336
337
338
340 Symbol->setIsConstant();
341 else if (Reference->getIsParameter())
342 Symbol->setIsParameter();
343 else if (Reference->getIsVariable())
344 Symbol->setIsVariable();
345 else if (Reference->getIsUnspecified())
346 Symbol->setIsUnspecified();
347 else
349 }
350 }
351}
352
354
355
356 setLevel(Parent->getLevel() + 1);
357
358
360 Element->updateLevel(this, Moved);
361
362
365 Line->updateLevel(this, Moved);
366}
367
369 if (getIsResolved())
370 return;
371
372
374
375
377 if (getIsGlobalReference())
378
379 Element->setIsGlobalReference();
381 }
382}
383
385 if (getIsResolvedName())
386 return;
387 setIsResolvedName();
388
389
390
391 if (getIsTemplate())
393 else {
397 }
398 }
399
400
401
402
404 if (getIsArtificial())
406 else
408 }
409
411
412
414}
415
417
418
419
420
421
422
423
424
425
426
430
432 }
433
434
436
437
440}
441
443
445 return;
446
451
453 }
454}
455
457
458
459 if (getHasReference() && ())
461
463}
464
465
467
468
469
472 if (Type->getIsTemplateParam()) {
473 Type->resolve();
475 }
476
477 return !Params.empty();
478}
479
480
482 if (getIsTemplateResolved())
483 return;
484 setIsTemplateResolved();
485
486
487 if (options().getAttributeEncoded()) {
490 std::string EncodedArgs;
491
492
495 }
496 }
497}
498
499
501 if (getIsRoot() || getIsCompileUnit())
502 return;
503
509}
510
511
513
514
515
516
517
518
519
520
521
522
523
524
525 std::string BaseName;
527 if (getIsTemplateResolved())
528 Name.append(BaseName);
529}
530
533
534 Name.append("<");
535
536
538 bool AddComma = false;
540 if (AddComma)
541 Name.append(", ");
542 Type->encodeTemplateArgument(Name);
543 AddComma = true;
544 }
545 }
546
547 Name.append(">");
548}
549
550bool LVScope::resolvePrinting() const {
551
552
553
554 if (options().getPrintWarnings() && (getIsRoot() || getIsCompileUnit()))
555 return true;
556
557
558
559
560 if (options().getSelectExecute()) {
561 return getIsRoot() || getIsCompileUnit() || getHasPattern();
562 }
563
564 bool Globals = options().getAttributeGlobal();
565 bool Locals = options().getAttributeLocal();
566 if ((Globals && Locals) || (!Globals && !Locals)) {
567
568 } else {
569
570 if ((Globals && !(getHasGlobals() || getIsGlobalReference())) ||
571 (Locals && !(getHasLocals() || !getIsGlobalReference())))
572 return false;
573 }
574
575
576 if (getIsFunction() && getIsArtificial() &&
577 ().getAttributeGenerated())
578 return false;
579
580 return true;
581}
582
584 bool Full) const {
585
586
588
589
590 if (getIsSystem() && ().getAttributeSystem())
592
593
594
595 if (getIsCompileUnit()) {
598 std::string ScopeName(getName());
599 if (std::error_code EC =
602 ScopeName.c_str());
604 }
605 }
606
607
608 bool DoPrint = (options().getAttributeDiscarded()) ? true : !getIsDiscarded();
609
610
611
612
613
614 if (DoPrint) {
615 DoPrint =
616 getIsInCompare() ? options().getReportExecute() : resolvePrinting();
617 }
618
619
620
621
622 DoPrint = DoPrint && (Print || options().getOutputSplit());
623
624 if (DoPrint) {
625
627
628
629
630 if ((getIsRoot() || options().getPrintAnyElement()) &&
631 options().getPrintFormatting() &&
633
635 if (Match && ->getHasPattern())
636 continue;
639 return Err;
640 }
641
642
645 if (Match && ->getHasPattern())
646 continue;
648 Line->doPrint(Split, Match, Print, *StreamSplit, Full))
649 return Err;
650 }
651
652
653 if (options().getPrintWarnings())
655 }
656 }
657
658
659
660 if (getIsCompileUnit()) {
661 if (options().getPrintSummary())
663 if (options().getPrintSizes())
668 }
669 }
670
671 if (getIsRoot() && options().getPrintWarnings()) {
673 }
674
676}
677
679
681 if (SortFunction) {
684 auto Traverse = [&](auto &Set, LVSortFunction SortFunction) {
685 if (Set)
687 };
688 Traverse(Parent->Types, SortFunction);
689 Traverse(Parent->Symbols, SortFunction);
690 Traverse(Parent->Scopes, SortFunction);
692
693 if (Parent->Scopes)
695 Sort(Scope, SortFunction);
696 };
697
698
699 Sort(this, SortFunction);
700 }
701}
702
705
707 while (Parent) {
708
709 if ((Parent->*GetFunction)())
710 break;
711 (Parent->*SetFunction)();
713 }
714}
715
718 if (options().getReportParents()) {
719
721 while (Parent) {
722
723 if ((Parent->*GetFunction)())
724 break;
725 (Parent->*SetFunction)();
726 Parent = Parent->getParentScope();
727 }
728 }
729
731 auto Traverse = [&](const auto *Set) {
732 if (Set)
733 for (const auto &Entry : *Set)
734 (Entry->*SetFunction)();
735 };
736
737 (Scope->*SetFunction)();
738
739 Traverse(Scope->getTypes());
740 Traverse(Scope->getSymbols());
741 Traverse(Scope->getLines());
742
745 TraverseChildren(Scope);
746 };
747
748 if (options().getReportChildren())
749 TraverseChildren(this);
750}
751
752
753
754
755
758
761 Symbol->getLocations(LocationList, ValidLocation, RecordInvalid);
764 Scope->getLocations(LocationList, ValidLocation, RecordInvalid);
765}
766
767
768
769
770
773
774 if (getIsDiscarded())
775 return;
776
777
780
781 if (!(Location->*ValidLocation)() && RecordInvalid)
783 }
784
785
786 calculateCoverage();
787 }
788
789
792 Scope->getRanges(LocationList, ValidLocation, RecordInvalid);
793}
794
795
797
798 if (getIsDiscarded())
799 return;
800
805 Scope->getRanges(RangeList);
806}
807
810 while (Parent) {
811 const LVLocations *ParentRanges = Parent->getRanges();
812 if (ParentRanges)
815 return Parent;
816 Parent = Parent->getParentScope();
817 }
818 return Parent;
819}
820
822 if (!Targets)
823 return nullptr;
824
825
826
827
832
834 if (!Candidates.empty()) {
835 dbgs() << "\n[LVScope::findIn]\n"
836 << "Reference: "
838 << "Level = " << getLevel() << ", "
841 for (const LVScope *Candidate : Candidates)
842 dbgs() << "Candidate: "
843 << "Offset = " << hexSquareString(Candidate->getOffset()) << ", "
844 << "Level = " << Candidate->getLevel() << ", "
845 << "Kind = " << formattedKind(Candidate->kind()) << ", "
846 << "Name = " << formattedName(Candidate->getName()) << "\n";
847 }
848 });
849
850 if (!Candidates.empty())
851 return (Candidates.size() == 1)
852 ? (equals(Candidates[0]) ? Candidates[0] : nullptr)
854
855 return nullptr;
856}
857
859
860
861 return !(
863 (options().getCompareSymbols() &&
867}
868
870 auto SetCompareState = [&](auto &Container) {
871 if (Container)
872 for (auto *Entry : *Container)
873 Entry->setIsInCompare();
874 };
875 SetCompareState(Types);
876 SetCompareState(Symbols);
877 SetCompareState(Lines);
878 SetCompareState(Scopes);
879
880
881
890 TraverseChildren);
891}
892
895 bool TraverseChildren) {
896 if (!(References && Targets))
897 return;
898
900 dbgs() << "\n[LVScope::markMissingParents]\n";
902 dbgs() << "References: "
904 << "Level = " << Reference->getLevel() << ", "
908 dbgs() << "Targets : "
910 << "Level = " << Target->getLevel() << ", "
913 });
914
916
918 continue;
919
921 dbgs() << "\nSearch Reference: "
924 });
928 dbgs() << "\nFound Target: "
931 });
932 if (TraverseChildren)
934 } else {
936 dbgs() << "Missing Reference: "
939 });
940 Reference->markBranchAsMissing();
941 }
942 }
943}
944
947 return false;
948
949 if (getIsLexicalBlock() && Scope->getIsLexicalBlock())
951 return true;
952}
953
955 assert(Scopes && "Scopes must not be nullptr");
959 return nullptr;
960}
961
963 if (!References && !Targets)
964 return true;
965 if (References && Targets && References->size() == Targets->size()) {
968 return false;
969 return true;
970 }
971 return false;
972}
973
985
987 if (options().getPrintFormatting() && options().getAttributeRange() &&
991 }
992}
993
999
1001 if (getIncludeInPrint() && getReader().doPrintScope(this)) {
1002
1003
1004 if (!(getIsRoot() || (getIsCompileUnit() && options().getSelectExecute())))
1008 }
1009}
1010
1013
1014 if (!getIsBlock()) {
1016 if (!getIsAggregate()) {
1019 }
1020 if (options().getAttributeSize())
1022 OS << " [Size = " << Size << "]";
1023 }
1024 OS << "\n";
1025
1026
1027 if (Full && getIsBlock())
1029}
1030
1031
1032
1033
1036 return false;
1037
1039 return false;
1040
1041
1043 return false;
1044
1046
1048 return false;
1049
1050 return true;
1051}
1052
1054 assert(Scopes && "Scopes must not be nullptr");
1058 return nullptr;
1059}
1060
1064 if (getIsTemplateResolved())
1067 if (Reference)
1069 }
1070}
1071
1072
1073
1074
1080
1086
1087
1088
1089
1091
1092
1093
1094 if (getIsArrayResolved())
1095 return;
1096 setIsArrayResolved();
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1119 if (Type->getIsSubrange()) {
1120 Type->resolve();
1122 }
1123
1124
1125
1129 }
1130
1131
1132 std::stringstream ArrayInfo;
1135
1136 for (const LVType *Type : Subranges) {
1137 if (Type->getIsSubrangeCount())
1138
1139 ArrayInfo << "[" << Type->getCount() << "]";
1140 else {
1141
1142 unsigned LowerBound;
1143 unsigned UpperBound;
1144 std::tie(LowerBound, UpperBound) = Type->getBounds();
1145
1146
1147
1148
1149
1150 if (LowerBound)
1151 ArrayInfo << "[" << LowerBound << ".." << UpperBound << "]";
1152 else
1153 ArrayInfo << "[" << UpperBound + 1 << "]";
1154 }
1155 }
1156
1157
1158 setName(ArrayInfo.str());
1159}
1160
1163 return false;
1164
1166 return false;
1167
1168
1169
1171 return false;
1172
1173 return true;
1174}
1175
1180
1181
1182
1183
1188 "CU [0x%08" PRIx64 "], Scope [0x%08" PRIx64 "], Range [0x%08" PRIx64
1189 ":0x%08" PRIx64 "], Size = %" PRId64 "\n",
1191 });
1192
1193
1194
1197 if (this == Scope)
1198
1199 CUContributionSize = Size;
1200}
1201
1202
1204
1205
1206
1207
1208 if (().getSelectExecute())
1209 return;
1210
1211 if (MatchedScopes.size()) {
1213 Scope->traverseParentsAndChildren(&LVScope::getHasPattern,
1214 &LVScope::setHasPattern);
1215 } else {
1216
1217
1218 setHasPattern();
1219 }
1220}
1221
1224 if (options().getAttributeRange()) {
1225
1227 bool RecordInvalid = options().getWarningRanges();
1229
1230
1231 if (RecordInvalid)
1234 }
1235
1236 if (options().getAttributeLocation()) {
1237
1239 bool RecordInvalid = options().getWarningLocations();
1241
1242
1243 if (RecordInvalid)
1246 }
1247}
1248
1251 SectionMappings.add(SectionIndex, Address, Line);
1252}
1253
1257 LVAddressToLine *Map = SectionMappings.findMap(SectionIndex);
1258 if (!Map || Map->empty())
1259 return nullptr;
1260 LVAddressToLine::const_iterator Iter = Map->lower_bound(Address);
1261 return (Iter != Map->end()) ? Iter->second : nullptr;
1262}
1263
1267 LVAddressToLine *Map = SectionMappings.findMap(SectionIndex);
1268 if (!Map || Map->empty())
1269 return nullptr;
1270 LVAddressToLine::const_iterator Iter = Map->upper_bound(Address);
1271 if (Iter != Map->begin())
1272 Iter = std::prev(Iter);
1273 return Iter->second;
1274}
1275
1277
1280 : Element->getParentScope();
1281 LVLine *LowLine = lineLowerBound(Location->getLowerAddress(), Parent);
1282 LVLine *HighLine = lineUpperBound(Location->getUpperAddress(), Parent);
1284}
1285
1287 if (Index <= 0 || Index > Filenames.size())
1290}
1291
1294 return false;
1295
1297}
1298
1300 options().getSelectExecute() ? ++Found.Lines : ++Printed.Lines;
1301}
1303 options().getSelectExecute() ? ++Found.Scopes : ++Printed.Scopes;
1304}
1306 options().getSelectExecute() ? ++Found.Symbols : ++Printed.Symbols;
1307}
1309 options().getSelectExecute() ? ++Found.Types : ++Printed.Types;
1310}
1311
1312
1314 if (Line->getIncludeInPrint())
1315 ++Allocated.Lines;
1316}
1318 if (Scope->getIncludeInPrint())
1319 ++Allocated.Scopes;
1320}
1322 if (Symbol->getIncludeInPrint())
1323 ++Allocated.Symbols;
1324}
1326 if (Type->getIncludeInPrint())
1327 ++Allocated.Types;
1328}
1329
1330
1331
1332
1349
1350
1354
1355
1357 if (WarningOffsets.find(Offset) == WarningOffsets.end())
1359}
1360
1361
1364 if (InvalidCoverages.find(Offset) == InvalidCoverages.end())
1366}
1367
1368
1370 addInvalidLocationOrRange(Location, Location->getParentSymbol(),
1371 &InvalidLocations);
1372}
1373
1374
1376 addInvalidLocationOrRange(Location, Location->getParentScope(),
1377 &InvalidRanges);
1378}
1379
1380
1387
1389 if (().getPrintFormatting())
1390 return;
1391
1392
1396
1397 enum class Option { Directory, File };
1398 auto PrintNames = [&](Option Action) {
1399 StringRef Kind = Action == Option::Directory ? "Directory" : "File";
1400 std::setstd::string UniqueNames;
1401 for (size_t Index : Filenames) {
1402
1403
1405 size_t Pos = Name.rfind('/');
1406 if (Pos != std:🧵:npos)
1407 Name = (Action == Option::File) ? Name.substr(Pos + 1)
1408 : Name.substr(0, Pos);
1409
1410 UniqueNames.insert(std::string(Name));
1411 }
1412 for (const std::string &Name : UniqueNames)
1413 OS << std::string(Indentation, ' ') << formattedKind(Kind) << " "
1415 };
1416
1417 if (options().getAttributeDirectories())
1418 PrintNames(Option::Directory);
1419 if (options().getAttributeFiles())
1420 PrintNames(Option::File);
1421 if (options().getAttributePublics()) {
1423
1424
1425 using OffsetSorted = std::map<LVAddress, LVPublicNames::const_iterator>;
1426 OffsetSorted SortedNames;
1427 for (LVPublicNames::const_iterator Iter = PublicNames.begin();
1428 Iter != PublicNames.end(); ++Iter)
1429 SortedNames.emplace(Iter->first->getOffset(), Iter);
1430
1431 LVPublicNames::const_iterator Iter;
1432 for (OffsetSorted::reference Entry : SortedNames) {
1433 Iter = Entry.second;
1434 OS << std::string(Indentation, ' ') << formattedKind(Kind) << " "
1436 if (options().getAttributeOffset()) {
1438 size_t Size = (*Iter).second.second;
1440 << "]";
1441 }
1442 OS << "\n";
1443 }
1444 }
1445}
1446
1448 auto PrintHeader = [&](const char *Header) { OS << "\n" << Header << ":\n"; };
1449 auto PrintFooter = [&](auto &Set) {
1450 if (Set.empty())
1451 OS << "None\n";
1452 };
1454 if (Count == 5) {
1456 OS << "\n";
1457 }
1460 };
1462 LVOffsetElementMap::const_iterator Iter = Map.find(Offset);
1463 LVElement *Element = Iter != Map.end() ? Iter->second : nullptr;
1468 OS << "\n";
1469 };
1471 const char *Header) {
1472 PrintHeader(Header);
1473 for (LVOffsetLocationsMap::const_reference Entry : Map) {
1474 PrintElement(WarningOffsets, Entry.first);
1477 << Location->getIntervalInfo() << "\n";
1478 }
1479 PrintFooter(Map);
1480 };
1481
1482 if (options().getInternalTag() && getReader().isBinaryTypeELF()) {
1483 PrintHeader("Unsupported DWARF Tags");
1484 for (LVTagOffsetsMap::const_reference Entry : DebugTags) {
1485 OS << format("\n0x%02x", (unsigned)Entry.first) << ", "
1487 unsigned Count = 0;
1490 OS << "\n";
1491 }
1492 PrintFooter(DebugTags);
1493 }
1494
1495 if (options().getWarningCoverages()) {
1496 PrintHeader("Symbols Invalid Coverages");
1497 for (LVOffsetSymbolMap::const_reference Entry : InvalidCoverages) {
1498
1501 << format("%.2f%%", Symbol->getCoveragePercentage()) << " "
1504 }
1505 PrintFooter(InvalidCoverages);
1506 }
1507
1508 if (options().getWarningLines()) {
1509 PrintHeader("Lines Zero References");
1510 for (LVOffsetLinesMap::const_reference Entry : LinesZero) {
1511 PrintElement(WarningOffsets, Entry.first);
1512 unsigned Count = 0;
1513 for (const LVLine *Line : Entry.second)
1514 PrintOffset(Count, Line->getOffset());
1515 OS << "\n";
1516 }
1517 PrintFooter(LinesZero);
1518 }
1519
1520 if (options().getWarningLocations())
1521 PrintInvalidLocations(InvalidLocations, "Invalid Location Ranges");
1522
1523 if (options().getWarningRanges())
1524 PrintInvalidLocations(InvalidRanges, "Invalid Code Ranges");
1525}
1526
1527void LVScopeCompileUnit::printTotals(raw_ostream &OS) const {
1528 OS << "\nTotals by lexical level:\n";
1529 for (size_t Index = 1; Index <= MaxSeenLevel; ++Index)
1530 OS << format("[%03d]: %10d (%6.2f%%)\n", Index, Totals[Index].first,
1531 Totals[Index].second);
1532}
1533
1534void LVScopeCompileUnit::printScopeSize(const LVScope *Scope, raw_ostream &OS) {
1535 LVSizesMap::const_iterator Iter = Sizes.find(Scope);
1536 if (Iter != Sizes.end()) {
1538 assert(CUContributionSize && "Invalid CU contribution size.");
1539
1540
1541 float Percentage =
1542 rint((float(Size) / CUContributionSize) * 100.0 * 100.0) / 100.0;
1543 OS << format("%10" PRId64 " (%6.2f%%) : ", Size, Percentage);
1544 Scope->print(OS);
1545
1546
1547 LVLevel Level = Scope->getLevel();
1548 if (Level > MaxSeenLevel)
1549 MaxSeenLevel = Level;
1550 if (Level >= Totals.size())
1551 Totals.resize(2 * Level);
1552 Totals[Level].first += Size;
1553 Totals[Level].second += Percentage;
1554 }
1555}
1556
1558
1559 std::function<void(const LVScope *Scope)> PrintScope =
1561
1562 if (options().getSelectExecute() && options().getReportAnyView()) {
1564 if (Scope->getLevel() < options().getOutputLevel())
1565 printScopeSize(Scope, OS);
1566 return;
1567 }
1568 if (Scope->getLevel() < options().getOutputLevel()) {
1571 printScopeSize(Scope, OS);
1572 PrintScope(Scope);
1573 }
1574 }
1575 };
1576
1577 bool PrintScopes = options().getPrintScopes();
1578 if (!PrintScopes)
1579 options().setPrintScopes();
1581
1582 OS << "\nScope Sizes:\n";
1583 options().resetPrintFormatting();
1584 options().setPrintOffset();
1585
1586
1587
1588 printScopeSize(this, OS);
1589 PrintScope(this);
1590
1591
1592 printTotals(OS);
1593
1594 options().resetPrintOffset();
1595 options().setPrintFormatting();
1596
1597 if (!PrintScopes)
1598 options().resetPrintScopes();
1599}
1600
1604
1605
1607 const char *Header) const {
1608 std::string Separator = std::string(29, '-');
1609 auto PrintSeparator = [&]() { OS << Separator << "\n"; };
1610 auto PrintHeadingRow = [&](const char *T, const char *U, const char *V) {
1611 OS << format("%-9s%9s %9s\n", T, U, V);
1612 };
1613 auto PrintDataRow = [&](const char *T, unsigned U, unsigned V) {
1614 OS << format("%-9s%9d %9d\n", T, U, V);
1615 };
1616
1617 OS << "\n";
1618 PrintSeparator();
1619 PrintHeadingRow("Element", "Total", Header);
1620 PrintSeparator();
1621 PrintDataRow("Scopes", Allocated.Scopes, Counter.Scopes);
1622 PrintDataRow("Symbols", Allocated.Symbols, Counter.Symbols);
1623 PrintDataRow("Types", Allocated.Types, Counter.Types);
1624 PrintDataRow("Lines", Allocated.Lines, Counter.Lines);
1625 PrintSeparator();
1626 PrintDataRow(
1627 "Total",
1628 Allocated.Scopes + Allocated.Symbols + Allocated.Lines + Allocated.Types,
1630}
1631
1633 bool UseMatchedElements) {
1635 if (SortFunction)
1637
1638
1639
1640
1641 if (options().getPrintAnyElement()) {
1642 if (UseMatchedElements)
1643 OS << "\n";
1645
1646 if (UseMatchedElements) {
1647
1650 } else {
1651
1652 for (const LVScope *Scope : MatchedScopes) {
1653 Scope->print(OS);
1656 }
1657 }
1658
1659
1660 if (options().getPrintSummary()) {
1661
1662
1663
1664 if (().getReportList()) {
1666 if (->getIncludeInPrint())
1667 continue;
1668 if (Element->getIsType())
1669 ++Found.Types;
1670 else if (Element->getIsSymbol())
1671 ++Found.Symbols;
1672 else if (Element->getIsScope())
1673 ++Found.Scopes;
1674 else if (Element->getIsLine())
1675 ++Found.Lines;
1676 else
1678 }
1679 }
1681 }
1682 }
1683
1684
1685
1686 if (options().getPrintSizes()) {
1687 OS << "\n";
1689
1690 OS << "\nScope Sizes:\n";
1691 printScopeSize(this, OS);
1693 if (Element->getIsScope())
1694
1695 printScopeSize(static_cast<LVScope *>(Element), OS);
1696
1697 printTotals(OS);
1698 }
1699}
1700
1702
1705
1706 if (getReader().doPrintScope(this) && options().getPrintFormatting())
1707 OS << "\n";
1708
1710}
1711
1714 if (options().getPrintFormatting()) {
1715 if (options().getAttributeProducer())
1718 true,
1719 false);
1720 if (options().getAttributeLanguage())
1724 true,
1725 false);
1726 }
1727
1728
1730
1731
1735 }
1736}
1737
1738
1739
1740
1746
1748
1749 OS << formattedKind(kind()) << " " << (getIsEnumClass() ? "class " : "")
1751 if (getHasType())
1754 OS << "\n";
1755}
1756
1757
1758
1759
1765
1769
1770
1771
1772
1774
1775
1776
1777 if (options().getAttributeInserted() && getHasReferenceAbstract() &&
1778 !getAddedMissing()) {
1779
1783 if (Scope->getHasReferenceAbstract() && ->getAddedMissing())
1784 Scope->addMissingElements(Scope->getReference());
1785 }
1786
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799 if (getHasReferenceSpecification()) {
1801 if (Reference && Reference->getIsExternal()) {
1802 Reference->resetIsExternal();
1803 setIsExternal();
1804 }
1805 }
1806
1807
1810 setType(Reference->getType());
1811}
1812
1818
1820
1821 if (getIsTemplate())
1823}
1824
1827 return false;
1828
1829
1831 return false;
1832
1833
1835 return false;
1836
1837
1839 return false;
1840
1841
1843 return false;
1844
1845
1846 if (options().getCompareLines() &&
1848 return false;
1849
1850
1852 return false;
1853
1855 return false;
1856
1857 return true;
1858}
1859
1861 assert(Scopes && "Scopes must not be nullptr");
1862
1864
1867 return nullptr;
1868}
1869
1872
1873
1875 Reference ? Reference->getInlineCode() : getInlineCode();
1876
1877
1879 if (getIsMember())
1882
1883 std::string Attributes =
1884 getIsCallSite()
1885 ? ""
1888
1892
1893
1895 if (getIsTemplateResolved())
1901 if (Reference)
1902 Reference->printReference(OS, Full, const_cast<LVScopeFunction *>(this));
1903 }
1904}
1905
1906
1907
1908
1910
1911 if (getIsTemplate())
1913}
1914
1917 return false;
1918
1919
1920 if (getHasDiscriminator() && Scope->getHasDiscriminator())
1922 return false;
1923
1924
1927 return false;
1928
1929 return true;
1930}
1931
1935
1939
1940
1941
1942
1943
1945 if (getIsMemberPointerResolved())
1946 return;
1947 setIsMemberPointerResolved();
1948
1949
1951 Name.append(" (*)");
1952 Name.append("(");
1953
1954
1956 bool AddComma = false;
1958 if (Symbol->getIsParameter()) {
1961 Type->resolveName();
1962 if (AddComma)
1963 Name.append(", ");
1964 Name.append(std::string(Symbol->getTypeName()));
1965 AddComma = true;
1966 }
1967 }
1968
1969 Name.append(")");
1970
1971
1973}
1974
1975
1976
1977
1982
1986
1987
1988
1989
1992 return false;
1993
1995 return false;
1996
1997
1999 return false;
2000
2002 return false;
2003
2004 return true;
2005}
2006
2008 assert(Scopes && "Scopes must not be nullptr");
2009
2013 return nullptr;
2014}
2015
2018
2019
2022
2025 }
2026}
2027
2028
2029
2030
2032 if (().getAttributeAnyLocation())
2033 return;
2034
2040 CompileUnit->processRangeLocationCoverage();
2041 }
2042}
2043
2045
2046 std::function<void(LVScope * Parent)> TraverseScope = [&](LVScope *Parent) {
2047 auto Traverse = [&](const auto *Set) {
2048 if (Set)
2049 for (const auto &Entry : *Set)
2050 Entry->setInnerComponent();
2051 };
2054 Scope->setInnerComponent();
2055 TraverseScope(Scope);
2056 }
2057 Traverse(Parent->getSymbols());
2058 Traverse(Parent->getTypes());
2059 Traverse(Parent->getLines());
2060 };
2061
2062
2063 TraverseScope(this);
2064}
2065
2069
2071 OS << "\nLogical View:\n";
2073}
2074
2077 if (options().getAttributeFormat())
2079 OS << "\n";
2080}
2081
2083 bool UseMatchedElements) const {
2084
2085
2087
2089 if (UseMatchedElements)
2090 options().resetPrintFormatting();
2092
2095
2096
2097
2099 std::string ScopeName(Scope->getName());
2100 if (std::error_code EC =
2103 ScopeName.c_str());
2105 }
2106
2107 Scope->printMatchedElements(*StreamSplit, UseMatchedElements);
2108
2109
2113 }
2114 }
2115 if (UseMatchedElements)
2116 options().setPrintFormatting();
2117 }
2118
2120}
2121
2122
2123
2124
2130
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
Pass interface - Implemented by all 'passes'.
void append(ItTy in_start, ItTy in_end)
Add the specified range to the end of the SmallVector.
void push_back(const T &Elt)
StringRef - Represent a constant reference to a string, i.e.
std::string str() const
str - Get the contents as an std::string.
Target - Wrapper for Target specific information.
const char * getName() const
getName - Get the target name.
The instances of the Type class are immutable: once they are created, they are never changed.
Stores all information relating to a compile unit, be it in its original instance in the object file ...
LLVM_ABI void printItem(LVElement *Element, LVComparePass Pass)
void push(LVScope *Scope)
size_t getNameIndex() const
std::string discriminatorAsString() const
StringRef getQualifiedName() const
void resolveFullname(LVElement *BaseType, StringRef Name=emptyString())
LVElement(LVSubclassID ID)
virtual void resolveName()
StringRef virtualityString(uint32_t Virtuality=dwarf::DW_VIRTUALITY_none) const
uint32_t getInlineCode() const
StringRef typeAsString() const
StringRef externalString() const
virtual StringRef getLinkageName() const
void setName(StringRef ElementName) override
StringRef getName() const override
LVElement * getType() const
bool referenceMatch(const LVElement *Element) const
void setFile(LVElement *Reference=nullptr)
void setType(LVElement *Element=nullptr)
StringRef getTypeName() const
void printLinkageName(raw_ostream &OS, bool Full, LVElement *Parent, LVScope *Scope) const
StringRef getTypeQualifiedName() const
StringRef accessibilityString(uint32_t Access=dwarf::DW_ACCESS_private) const
bool equals(const LVElement *Element) const
StringRef inlineCodeString(uint32_t Code) const
size_t getFilenameIndex() const
std::string typeOffsetAsString() const
uint32_t getStorageSizeInBytes() const
bool isNamed() const override
static void markMissingParents(const LVLines *References, const LVLines *Targets)
virtual bool equals(const LVLine *Line) const
LVScope * getParentScope() const
std::string indentAsString() const
virtual void print(raw_ostream &OS, bool Full=true) const
void setLevel(LVLevel Level)
void printAttributes(raw_ostream &OS, bool Full=true) const
virtual std::string lineNumberAsString(bool ShowZero=false) const
LVOffset getOffset() const
size_t indentationSize() const
void resetFilenameIndex()
void resolvePatternMatch(LVLine *Line)
void addEntry(LVScope *Scope, LVAddress LowerAddress, LVAddress UpperAddress)
void notifyAddedElement(LVLine *Line)
raw_ostream & outputStream()
virtual bool isSystemEntry(LVElement *Element, StringRef Name={}) const
virtual LVSectionIndex getSectionIndex(LVScope *Scope)
void setCompileUnit(LVScope *Scope)
virtual void printRecords(raw_ostream &OS) const
void printExtra(raw_ostream &OS, bool Full=true) const override
Definition LVScope.cpp:1061
LVScope * getReference() const override
bool equals(const LVScope *Scope) const override
Definition LVScope.cpp:1034
LVScope * findEqualScope(const LVScopes *Scopes) const override
Definition LVScope.cpp:1053
bool equals(const LVScope *Scope) const override
Definition LVScope.cpp:1075
void printExtra(raw_ostream &OS, bool Full=true) const override
Definition LVScope.cpp:1081
void resolveExtra() override
Definition LVScope.cpp:1090
bool equals(const LVScope *Scope) const override
Definition LVScope.cpp:1161
void printExtra(raw_ostream &OS, bool Full=true) const override
Definition LVScope.cpp:1176
void propagatePatternMatch()
Definition LVScope.cpp:1203
void addDebugTag(dwarf::Tag Target, LVOffset Offset)
Definition LVScope.cpp:1351
void printSummary(raw_ostream &OS) const override
Definition LVScope.cpp:1601
void addedElement(LVLine *Line)
Definition LVScope.cpp:1333
void printExtra(raw_ostream &OS, bool Full=true) const override
Definition LVScope.cpp:1712
void printMatchedElements(raw_ostream &OS, bool UseMatchedElements) override
Definition LVScope.cpp:1632
LVLineRange lineRange(LVLocation *Location) const
Definition LVScope.cpp:1276
void addMapping(LVLine *Line, LVSectionIndex SectionIndex)
Definition LVScope.cpp:1249
LVSourceLanguage getSourceLanguage() const override
void addInvalidLocation(LVLocation *Location)
Definition LVScope.cpp:1369
void incrementPrintedScopes()
Definition LVScope.cpp:1302
void increment(LVLine *Line)
Definition LVScope.cpp:1313
void addLineZero(LVLine *Line)
Definition LVScope.cpp:1381
void addInvalidOffset(LVOffset Offset, LVElement *Element)
Definition LVScope.cpp:1356
void addInvalidCoverage(LVSymbol *Symbol)
Definition LVScope.cpp:1362
void addSize(LVScope *Scope, LVOffset Lower, LVOffset Upper)
Definition LVScope.cpp:1184
void processRangeLocationCoverage(LVValidLocation ValidLocation=&LVLocation::validateRanges)
Definition LVScope.cpp:1222
void incrementPrintedLines()
Definition LVScope.cpp:1299
StringRef getFilename(size_t Index) const
Definition LVScope.cpp:1286
void print(raw_ostream &OS, bool Full=true) const override
Definition LVScope.cpp:1701
bool equals(const LVScope *Scope) const override
Definition LVScope.cpp:1292
void printSizes(raw_ostream &OS) const override
Definition LVScope.cpp:1557
void addInvalidRange(LVLocation *Location)
Definition LVScope.cpp:1375
void printLocalNames(raw_ostream &OS, bool Full=true) const
Definition LVScope.cpp:1388
StringRef getProducer() const override
void incrementPrintedSymbols()
Definition LVScope.cpp:1305
void incrementPrintedTypes()
Definition LVScope.cpp:1308
void printWarnings(raw_ostream &OS, bool Full=true) const override
Definition LVScope.cpp:1447
void printExtra(raw_ostream &OS, bool Full=true) const override
Definition LVScope.cpp:1747
bool equals(const LVScope *Scope) const override
Definition LVScope.cpp:1741
void printExtra(raw_ostream &OS, bool Full=true) const override
Definition LVScope.cpp:1766
bool equals(const LVScope *Scope) const override
Definition LVScope.cpp:1760
LVScope * findEqualScope(const LVScopes *Scopes) const override
Definition LVScope.cpp:1932
uint32_t getCallLineNumber() const override
void resolveExtra() override
Definition LVScope.cpp:1909
bool equals(const LVScope *Scope) const override
Definition LVScope.cpp:1915
uint32_t getDiscriminator() const override
size_t getCallFilenameIndex() const override
void printExtra(raw_ostream &OS, bool Full=true) const override
Definition LVScope.cpp:1936
void resolveExtra() override
Definition LVScope.cpp:1944
void setName(StringRef ObjectName) override
Definition LVScope.cpp:1813
LVScope * getReference() const override
LVScope * findEqualScope(const LVScopes *Scopes) const override
Definition LVScope.cpp:1860
size_t getLinkageNameIndex() const override
void printExtra(raw_ostream &OS, bool Full=true) const override
Definition LVScope.cpp:1870
bool equals(const LVScope *Scope) const override
Definition LVScope.cpp:1825
void resolveReferences() override
Definition LVScope.cpp:1773
void resolveExtra() override
Definition LVScope.cpp:1819
void printExtra(raw_ostream &OS, bool Full=true) const override
Definition LVScope.cpp:1983
bool equals(const LVScope *Scope) const override
Definition LVScope.cpp:1978
void printExtra(raw_ostream &OS, bool Full=true) const override
Definition LVScope.cpp:2016
bool equals(const LVScope *Scope) const override
Definition LVScope.cpp:1990
LVScope * findEqualScope(const LVScopes *Scopes) const override
Definition LVScope.cpp:2007
LVScope * getReference() const override
void processRangeInformation()
Definition LVScope.cpp:2031
void transformScopedName()
Definition LVScope.cpp:2044
void printExtra(raw_ostream &OS, bool Full=true) const override
Definition LVScope.cpp:2075
StringRef getFileFormatName() const
Error doPrintMatches(bool Split, raw_ostream &OS, bool UseMatchedElements) const
Definition LVScope.cpp:2082
void print(raw_ostream &OS, bool Full=true) const override
Definition LVScope.cpp:2070
bool equals(const LVScope *Scope) const override
Definition LVScope.cpp:2066
void printExtra(raw_ostream &OS, bool Full=true) const override
Definition LVScope.cpp:2131
bool equals(const LVScope *Scope) const override
Definition LVScope.cpp:2125
virtual LVScope * getReference() const
void addElement(LVElement *Element)
Definition LVScope.cpp:122
void traverseParentsAndChildren(LVObjectGetFunction GetFunction, LVObjectSetFunction SetFunction)
Definition LVScope.cpp:716
const LVLines * getLines() const
virtual void printSummary(raw_ostream &OS) const
StringRef resolveReferencesChain()
Definition LVScope.cpp:456
void printExtra(raw_ostream &OS, bool Full=true) const override
Definition LVScope.cpp:1011
void report(LVComparePass Pass) override
Definition LVScope.cpp:974
const char * kind() const override
Definition LVScope.cpp:50
virtual LVScope * findEqualScope(const LVScopes *Scopes) const
Definition LVScope.cpp:954
const LVScopes * getScopes() const
void print(raw_ostream &OS, bool Full=true) const override
Definition LVScope.cpp:1000
void resolveName() override
Definition LVScope.cpp:384
LVElementsView getChildren() const
void printActiveRanges(raw_ostream &OS, bool Full=true) const
Definition LVScope.cpp:986
size_t scopeCount() const
const LVSymbols * getSymbols() const
virtual void setEncodedArgs(StringRef EncodedArgs)
void printEncodedArgs(raw_ostream &OS, bool Full) const
Definition LVScope.cpp:994
void updateLevel(LVScope *Parent, bool Moved) override
Definition LVScope.cpp:353
LVScope * outermostParent(LVAddress Address)
Definition LVScope.cpp:808
void sort()
Definition LVScope.cpp:678
std::unique_ptr< LVLocations > Ranges
static void markMissingParents(const LVScopes *References, const LVScopes *Targets, bool TraverseChildren)
Definition LVScope.cpp:893
std::unique_ptr< LVSymbols > Symbols
const LVTypes * getTypes() const
void encodeTemplateArguments(std::string &Name) const
Definition LVScope.cpp:512
void addObject(LVLocation *Location)
Definition LVScope.cpp:161
void resolveElements()
Definition LVScope.cpp:442
virtual void printSizes(raw_ostream &OS) const
std::unique_ptr< LVTypes > Types
virtual bool equals(const LVScope *Scope) const
Definition LVScope.cpp:945
bool getTemplateParameterTypes(LVTypes &Params)
Definition LVScope.cpp:466
virtual StringRef getEncodedArgs() const
std::unique_ptr< LVLines > Lines
LVElements getSortedChildren(LVSortFunction SortFunction=llvm::logicalview::getSortFunction()) const
Definition LVScope.cpp:114
void getLocations(LVLocations &LocationList, LVValidLocation ValidLocation, bool RecordInvalid=false)
Definition LVScope.cpp:756
Error doPrint(bool Split, bool Match, bool Print, raw_ostream &OS, bool Full=true) const override
Definition LVScope.cpp:583
virtual bool equalNumberOfChildren(const LVScope *Scope) const
Definition LVScope.cpp:858
void resolveTemplate()
Definition LVScope.cpp:481
void addMissingElements(LVScope *Reference)
Definition LVScope.cpp:293
virtual void printWarnings(raw_ostream &OS, bool Full=true) const
void resolveReferences() override
Definition LVScope.cpp:416
std::unique_ptr< LVScopes > Scopes
const LVLocations * getRanges() const
size_t symbolCount() const
bool removeElement(LVElement *Element) override
Definition LVScope.cpp:264
void resolve() override
Definition LVScope.cpp:368
StringRef getString(size_t Index) const
static void markMissingParents(const LVSymbols *References, const LVSymbols *Targets)
static bool parametersMatch(const LVSymbols *References, const LVSymbols *Targets)
virtual bool equals(const LVType *Type) const
static bool parametersMatch(const LVTypes *References, const LVTypes *Targets)
static void markMissingParents(const LVTypes *References, const LVTypes *Targets)
This class implements an extremely fast bulk output stream that can only output to a stream.
LLVM_ABI StringRef TagString(unsigned Tag)
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
std::string hexString(uint64_t Value, size_t Width=HEX_WIDTH)
std::map< LVOffset, LVElement * > LVOffsetElementMap
std::string formattedNames(StringRef Name1, StringRef Name2)
LLVM_ABI LVStringPool & getStringPool()
SmallVector< LVElement *, 8 > LVElements
bool(LVScope::*)() const LVScopeGetFunction
std::string formattedKind(StringRef Kind)
std::map< LVOffset, LVLocations > LVOffsetLocationsMap
void addItem(MapType *Map, KeyType Key, ValueType Value)
LVScopeCompileUnit * getReaderCompileUnit()
SmallVector< LVScope *, 8 > LVScopes
std::map< LVScopeKind, LVScopeGetFunction > LVScopeDispatch
bool(LVLocation::*)() LVValidLocation
LVSortValue(*)(const LVObject *LHS, const LVObject *RHS) LVSortFunction
void(LVScope::*)() LVScopeSetFunction
LLVM_ABI LVSortValue compareRange(const LVObject *LHS, const LVObject *RHS)
std::string hexSquareString(uint64_t Value)
SmallVector< LVSymbol *, 8 > LVSymbols
LVSplitContext & getReaderSplitContext()
LLVM_ABI LVSortFunction getSortFunction()
std::string formattedName(StringRef Name)
std::pair< LVLine *, LVLine * > LVLineRange
bool(LVObject::*)() const LVObjectGetFunction
std::string formatAttributes(const StringRef First, Args... Others)
LVCompare & getComparator()
SmallVector< LVType *, 8 > LVTypes
void(LVObject::*)() LVObjectSetFunction
SmallVector< LVLocation *, 8 > LVLocations
This is an optimization pass for GlobalISel generic memory operations.
void stable_sort(R &&Range)
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
void erase(Container &C, ValueType V)
Wrapper function to remove a value from a container:
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
FunctionAddr VTableAddr Count
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
auto remove_if(R &&Range, UnaryPredicate P)
Provide wrappers to std::remove_if which take ranges instead of having to pass begin/end explicitly.