[PATCH] D11969: Avoid using of DataLayout::getPointerSize() without address space argument in DWARF info generation

Stanislav Mekhanoshin via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 11 17:20:23 PDT 2015


rampitec created this revision.
rampitec added reviewers: arsenm, joker-eph, echristo.
rampitec added a subscriber: llvm-commits.
rampitec set the repository for this revision to rL LLVM.

DataLayout::getPointerSize() supposed to be used with the address space argument, though it has default value 0 for the transition period. There are the cases when some kind of a general pointer size is desirable, such as with debug info. In some places DataLayout is used though. This creates problem if target is 64 bit, but some address spaces are 32 bit, and notably if address space 0 has 32 bit pointers in 64 bit mode. An example of such target is HSAIL.

In this change calls to DataLayout::getPointerSize() are replaced with recently added AsmPrinter::getPointerSize() in DWARF debug code. The AsmPrinter::getPointerSize() itself is modified to call MAI->getPointerSize(). Originally it was calling TargetMachine::getPointerSize() which ends up in the DataLayout::getPointerSize() with the default argument. Since this call is not virtual in both AsmPrinter and TargetMachine that makes a little sense to override it in the target implementation for DWARF info purposes. The MCAsmInfo implementation has the benefit to query member variable PointerSize which can be previously initialized by the target, thus target will have control over the returned value.

In LLVM 3.6 many (but not all) of the getPointerSize() references in DWARF info were pointing to the MAI implementation, but recently that was changed to the new AsmPrinter and TargetMachine functions.

Repository:
  rL LLVM

http://reviews.llvm.org/D11969

Files:
  lib/CodeGen/AsmPrinter/AsmPrinter.cpp
  lib/CodeGen/AsmPrinter/AsmPrinterDwarf.cpp
  lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
  lib/CodeGen/AsmPrinter/DwarfDebug.cpp
  lib/CodeGen/AsmPrinter/DwarfUnit.cpp

Index: lib/CodeGen/AsmPrinter/DwarfUnit.cpp
===================================================================
--- lib/CodeGen/AsmPrinter/DwarfUnit.cpp
+++ lib/CodeGen/AsmPrinter/DwarfUnit.cpp
@@ -1517,7 +1517,7 @@
                                 UseOffsets);

   Asm->OutStreamer->AddComment("Address Size (in bytes)");
-  Asm->EmitInt8(Asm->getDataLayout().getPointerSize());
+  Asm->EmitInt8(Asm->getPointerSize());
 }

 void DwarfUnit::initSection(MCSection *Section) {
Index: lib/CodeGen/AsmPrinter/DwarfDebug.cpp
===================================================================
--- lib/CodeGen/AsmPrinter/DwarfDebug.cpp
+++ lib/CodeGen/AsmPrinter/DwarfDebug.cpp
@@ -1589,7 +1589,7 @@
   // Start the dwarf loc section.
   Asm->OutStreamer->SwitchSection(
       Asm->getObjFileLowering().getDwarfLocSection());
-  unsigned char Size = Asm->getDataLayout().getPointerSize();
+  unsigned char Size = Asm->getPointerSize();
   for (const auto &List : DebugLocs.getLists()) {
     Asm->OutStreamer->EmitLabel(List.Label);
     const DwarfCompileUnit *CU = List.CU;
@@ -1727,7 +1727,7 @@
   Asm->OutStreamer->SwitchSection(
       Asm->getObjFileLowering().getDwarfARangesSection());

-  unsigned PtrSize = Asm->getDataLayout().getPointerSize();
+  unsigned PtrSize = Asm->getPointerSize();

   // Build a list of CUs used.
   std::vector<DwarfCompileUnit *> CUs;
@@ -1809,7 +1809,7 @@
       Asm->getObjFileLowering().getDwarfRangesSection());

   // Size for our labels.
-  unsigned char Size = Asm->getDataLayout().getPointerSize();
+  unsigned char Size = Asm->getPointerSize();

   // Grab the specific ranges for the compile units in the module.
   for (const auto &I : CUMap) {
Index: lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
===================================================================
--- lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
+++ lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
@@ -155,7 +155,7 @@
         // TODO: add debug info for emulated thread local mode.
       } else {
         // FIXME: Make this work with -gsplit-dwarf.
-        unsigned PointerSize = Asm->getDataLayout().getPointerSize();
+        unsigned PointerSize = Asm->getPointerSize();
         assert((PointerSize == 4 || PointerSize == 8) &&
                "Add support for other sizes if necessary");
         // Based on GCC's support for TLS:
Index: lib/CodeGen/AsmPrinter/AsmPrinterDwarf.cpp
===================================================================
--- lib/CodeGen/AsmPrinter/AsmPrinterDwarf.cpp
+++ lib/CodeGen/AsmPrinter/AsmPrinterDwarf.cpp
@@ -134,7 +134,7 @@
   default:
     llvm_unreachable("Invalid encoded value.");
   case dwarf::DW_EH_PE_absptr:
-    return MF->getDataLayout().getPointerSize();
+    return MAI->getPointerSize();
   case dwarf::DW_EH_PE_udata2:
     return 2;
   case dwarf::DW_EH_PE_udata4:
Index: lib/CodeGen/AsmPrinter/AsmPrinter.cpp
===================================================================
--- lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -141,7 +141,7 @@

 // Do not use the cached DataLayout because some client use it without a Module
 // (llmv-dsymutil, llvm-dwarfdump).
-unsigned AsmPrinter::getPointerSize() const { return TM.getPointerSize(); }
+unsigned AsmPrinter::getPointerSize() const { return MAI->getPointerSize(); }

 const MCSubtargetInfo &AsmPrinter::getSubtargetInfo() const {
   assert(MF && "getSubtargetInfo requires a valid MachineFunction!");


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D11969.31886.patch
Type: text/x-patch
Size: 3466 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150812/c62c7962/attachment.bin>


More information about the llvm-commits mailing list