[PATCH] D99785: [XCOFF] make .file directive have directory info

ChenZheng via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 1 20:53:29 PDT 2021


shchenz created this revision.
shchenz added reviewers: hubert.reinterpretcast, jasonliu, jsji, Esme, PowerPC.
Herald added subscribers: hiraditya, nemanjai.
shchenz requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

The `.file` directive is changed to only have basename in D36018 <https://reviews.llvm.org/D36018> for ELF.

But on AIX, we require the .file directive to also contain the directory info. This aligns with previous AIX compiler like XLC and is required by some AIX tool like DBX.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D99785

Files:
  llvm/include/llvm/MC/MCAsmInfo.h
  llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
  llvm/lib/MC/MCAsmInfoXCOFF.cpp
  llvm/test/CodeGen/PowerPC/aix-filename.ll


Index: llvm/test/CodeGen/PowerPC/aix-filename.ll
===================================================================
--- /dev/null
+++ llvm/test/CodeGen/PowerPC/aix-filename.ll
@@ -0,0 +1,8 @@
+; RUN: llc -verify-machineinstrs -mtriple powerpc-ibm-aix-xcoff < %s \
+; RUN:   | FileCheck %s
+; RUN: llc -verify-machineinstrs -mtriple powerpc64-ibm-aix-xcoff < %s \
+; RUN:   | FileCheck %s
+
+; CHECK: .file "/path/to/file"
+
+source_filename = "/path/to/file"
Index: llvm/lib/MC/MCAsmInfoXCOFF.cpp
===================================================================
--- llvm/lib/MC/MCAsmInfoXCOFF.cpp
+++ llvm/lib/MC/MCAsmInfoXCOFF.cpp
@@ -19,6 +19,7 @@
 MCAsmInfoXCOFF::MCAsmInfoXCOFF() {
   IsLittleEndian = false;
   HasVisibilityOnlyWithLinkage = true;
+  HasBasenameOnlyForFileDirective = false;
   PrivateGlobalPrefix = "L..";
   PrivateLabelPrefix = "L..";
   SupportsQuotedNames = false;
Index: llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
===================================================================
--- llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -296,8 +296,11 @@
   // don't, this at least helps the user find where a global came from.
   if (MAI->hasSingleParameterDotFile()) {
     // .file "foo.c"
-    OutStreamer->emitFileDirective(
-        llvm::sys::path::filename(M.getSourceFileName()));
+    if (MAI->hasBasenameOnlyForFileDirective())
+      OutStreamer->emitFileDirective(
+          llvm::sys::path::filename(M.getSourceFileName()));
+    else
+      OutStreamer->emitFileDirective(M.getSourceFileName());
   }
 
   GCModuleInfo *MI = getAnalysisIfAvailable<GCModuleInfo>();
Index: llvm/include/llvm/MC/MCAsmInfo.h
===================================================================
--- llvm/include/llvm/MC/MCAsmInfo.h
+++ llvm/include/llvm/MC/MCAsmInfo.h
@@ -316,6 +316,10 @@
   /// argument and how it is interpreted.  Defaults to NoAlignment.
   LCOMM::LCOMMType LCOMMDirectiveAlignmentType = LCOMM::NoAlignment;
 
+  /// True if the target only has basename for .file directive. False if the
+  /// target also needs the directory along with the basename. Default to true.
+  bool HasBasenameOnlyForFileDirective = true;
+
   // True if the target allows .align directives on functions. This is true for
   // most targets, so defaults to true.
   bool HasFunctionAlignment = true;
@@ -629,6 +633,9 @@
     return LCOMMDirectiveAlignmentType;
   }
 
+  bool hasBasenameOnlyForFileDirective() const {
+     return HasBasenameOnlyForFileDirective;
+  }
   bool hasFunctionAlignment() const { return HasFunctionAlignment; }
   bool hasDotTypeDotSizeDirective() const { return HasDotTypeDotSizeDirective; }
   bool hasSingleParameterDotFile() const { return HasSingleParameterDotFile; }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D99785.334889.patch
Type: text/x-patch
Size: 2768 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210402/46464dbf/attachment.bin>


More information about the llvm-commits mailing list