[llvm] [DwarfDump] Add new set of line-table-related statistics to llvm-dwarfdump (PR #93289)

Djordje Todorovic via llvm-commits llvm-commits at lists.llvm.org
Fri May 24 05:46:40 PDT 2024


================
@@ -882,8 +900,58 @@ bool dwarfdump::collectStatsForObjectFile(ObjectFile &Obj, DWARFContext &DICtx,
         CrossCUReferencesToBeResolved.push_back(
             DIELocation(CUDie.getDwarfUnit(), CrossCUReferencingDIEOffset));
     }
+    if (const auto *LineTable = DICtx.getLineTableForUnit(CU.get())) {
+      auto LastFileIdxOpt = LineTable->getLastValidFileIndex();
+      // Each CU has its own file index; in order to track unique line entries
+      // across CUs, we therefore need to map each CU file index to a global
+      // file index, which we store here.
+      DenseMap<uint64_t, uint16_t> CUFileMapping;
+      if (LastFileIdxOpt) {
+        std::string File;
+        for (uint64_t FileIdx = 0; FileIdx <= *LastFileIdxOpt; ++FileIdx) {
+          if (LineTable->getFileNameByIndex(
+                  FileIdx, CU->getCompilationDir(),
+                  DILineInfoSpecifier::FileLineInfoKind::AbsoluteFilePath,
+                  File)) {
+            auto ExistingFile = llvm::find(Files, File);
+            if (ExistingFile != Files.end()) {
+              CUFileMapping[FileIdx] =
+                  std::distance(Files.begin(), ExistingFile);
+            } else {
+              CUFileMapping[FileIdx] = Files.size();
+              Files.push_back(File);
+            }
+          }
+        }
+      }
+      for (auto Seq : LineTable->Sequences) {
----------------
djolertrk wrote:

`const auto&` instead?

https://github.com/llvm/llvm-project/pull/93289


More information about the llvm-commits mailing list