[PATCH] D68466: [DebugInfo] Allow <Symbol, Offset> pairs in AddressPool [NFC]

David Stenberg via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 4 07:49:42 PDT 2019


dstenb created this revision.
dstenb added reviewers: dblaikie, aprantl, vsk, probinson.
dstenb added a project: debug-info.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.
dstenb added a child revision: D68465: [DebugInfo] Trim call-clobbered location list entries when tuning for GDB.

This is a preparatory commit for D68465 <https://reviews.llvm.org/D68465>. That commit introduces location
list range trimming for values that are call-clobbered, in order to
improve compatibility with GDB. If a variable is described by a mix of
values that are call-clobbered and those that are not, then we need to
be able to start a location list entry inside the call instruction for
all values that are not call-clobbered. This commit adds support for
inserting such expressions in the address pool.

My initial thought was to allow MCExprs in the address pool, but I gave
up on that idea when I did not find a good way to unique them, and went
with simple <Symbol, Offset> pairs instead, as I did not foresee the
need for more advanced expressions.

D68465 <https://reviews.llvm.org/D68465> only adds tests for cases where the offset is negative. I'm not
sure how to test cases where the offset is positive. Should that be
covered by an assert instead?


Repository:
  rL LLVM

https://reviews.llvm.org/D68466

Files:
  llvm/lib/CodeGen/AsmPrinter/AddressPool.cpp
  llvm/lib/CodeGen/AsmPrinter/AddressPool.h


Index: llvm/lib/CodeGen/AsmPrinter/AddressPool.h
===================================================================
--- llvm/lib/CodeGen/AsmPrinter/AddressPool.h
+++ llvm/lib/CodeGen/AsmPrinter/AddressPool.h
@@ -17,6 +17,9 @@
 class MCSection;
 class MCSymbol;
 
+/// Pair of a symbol and an offset in number of bytes.
+typedef std::pair<const MCSymbol *, int> SymbolWithOffset;
+
 // Collection of addresses for this unit and assorted labels.
 // A Symbol->unsigned mapping of addresses used by indirect
 // references.
@@ -27,7 +30,7 @@
 
     AddressPoolEntry(unsigned Number, bool TLS) : Number(Number), TLS(TLS) {}
   };
-  DenseMap<const MCSymbol *, AddressPoolEntry> Pool;
+  DenseMap<SymbolWithOffset, AddressPoolEntry> Pool;
 
   /// Record whether the AddressPool has been queried for an address index since
   /// the last "resetUsedFlag" call. Used to implement type unit fallback - a
@@ -42,6 +45,10 @@
   /// label/symbol.
   unsigned getIndex(const MCSymbol *Sym, bool TLS = false);
 
+  /// Returns the index into the address pool with the given
+  /// label/symbol and offset.
+  unsigned getIndex(SymbolWithOffset SymWithOffs, bool TLS = false);
+
   void emit(AsmPrinter &Asm, MCSection *AddrSection);
 
   bool isEmpty() { return Pool.empty(); }
Index: llvm/lib/CodeGen/AsmPrinter/AddressPool.cpp
===================================================================
--- llvm/lib/CodeGen/AsmPrinter/AddressPool.cpp
+++ llvm/lib/CodeGen/AsmPrinter/AddressPool.cpp
@@ -18,8 +18,15 @@
 
 unsigned AddressPool::getIndex(const MCSymbol *Sym, bool TLS) {
   HasBeenUsed = true;
-  auto IterBool =
-      Pool.insert(std::make_pair(Sym, AddressPoolEntry(Pool.size(), TLS)));
+  auto IterBool = Pool.insert(std::make_pair(
+      std::make_pair(Sym, 0), AddressPoolEntry(Pool.size(), TLS)));
+  return IterBool.first->second.Number;
+}
+
+unsigned AddressPool::getIndex(SymbolWithOffset SymWithOffs, bool TLS) {
+  HasBeenUsed = true;
+  auto IterBool = Pool.insert(
+      std::make_pair(SymWithOffs, AddressPoolEntry(Pool.size(), TLS)));
   return IterBool.first->second.Number;
 }
 
@@ -63,11 +70,22 @@
   // Order the address pool entries by ID
   SmallVector<const MCExpr *, 64> Entries(Pool.size());
 
-  for (const auto &I : Pool)
+  for (const auto &I : Pool) {
     Entries[I.second.Number] =
         I.second.TLS
-            ? Asm.getObjFileLowering().getDebugThreadLocalSymbol(I.first)
-            : MCSymbolRefExpr::create(I.first, Asm.OutContext);
+            ? Asm.getObjFileLowering().getDebugThreadLocalSymbol(I.first.first)
+            : MCSymbolRefExpr::create(I.first.first, Asm.OutContext);
+    auto Offset = I.first.second;
+    if (!Offset)
+      continue;
+    // Create an expression for the addition or subtraction of the offset.
+    auto Op = Offset < 0 ? MCBinaryExpr::Sub : MCBinaryExpr::Add;
+    const auto OffsetExpr =
+        MCConstantExpr::create(std::abs(Offset), Asm.OutContext);
+    const auto SymbolExpr = Entries[I.second.Number];
+    Entries[I.second.Number] =
+        MCBinaryExpr::create(Op, SymbolExpr, OffsetExpr, Asm.OutContext);
+  }
 
   for (const MCExpr *Entry : Entries)
     Asm.OutStreamer->EmitValue(Entry, Asm.getDataLayout().getPointerSize());


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D68466.223222.patch
Type: text/x-patch
Size: 3222 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191004/b42073d7/attachment.bin>


More information about the llvm-commits mailing list