[XCOFF] make .file directive have directory info
authorChen Zheng <czhengsz@cn.ibm.com>
Mon, 26 Apr 2021 05:31:23 +0000 (01:31 -0400)
committerChen Zheng <czhengsz@cn.ibm.com>
Tue, 27 Apr 2021 04:15:23 +0000 (00:15 -0400)
The .file directive is changed to only have basename in D36018 for
ELF.

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

Reviewed By: hubert.reinterpretcast

Differential Revision: https://reviews.llvm.org/D99785

llvm/include/llvm/MC/MCAsmInfo.h
llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
llvm/lib/MC/MCAsmInfoXCOFF.cpp
llvm/test/CodeGen/PowerPC/aix-filename-absolute-path.ll [new file with mode: 0644]
llvm/test/CodeGen/PowerPC/aix-filename-relative-path.ll [new file with mode: 0644]

index 250d219..b674af0 100644 (file)
@@ -341,6 +341,10 @@ protected:
   /// 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;
@@ -666,6 +670,9 @@ public:
     return LCOMMDirectiveAlignmentType;
   }
 
+  bool hasBasenameOnlyForFileDirective() const {
+    return HasBasenameOnlyForFileDirective;
+  }
   bool hasFunctionAlignment() const { return HasFunctionAlignment; }
   bool hasDotTypeDotSizeDirective() const { return HasDotTypeDotSizeDirective; }
   bool hasSingleParameterDotFile() const { return HasSingleParameterDotFile; }
index f12fd14..0f7616f 100644 (file)
@@ -297,8 +297,11 @@ bool AsmPrinter::doInitialization(Module &M) {
   // 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 a23a71b..f90fc5a 100644 (file)
@@ -19,6 +19,7 @@ void MCAsmInfoXCOFF::anchor() {}
 MCAsmInfoXCOFF::MCAsmInfoXCOFF() {
   IsLittleEndian = false;
   HasVisibilityOnlyWithLinkage = true;
+  HasBasenameOnlyForFileDirective = false;
   PrivateGlobalPrefix = "L..";
   PrivateLabelPrefix = "L..";
   SupportsQuotedNames = false;
diff --git a/llvm/test/CodeGen/PowerPC/aix-filename-absolute-path.ll b/llvm/test/CodeGen/PowerPC/aix-filename-absolute-path.ll
new file mode 100644 (file)
index 0000000..d5b6886
--- /dev/null
@@ -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 "/absolute/path/to/file"
+
+source_filename = "/absolute/path/to/file"
diff --git a/llvm/test/CodeGen/PowerPC/aix-filename-relative-path.ll b/llvm/test/CodeGen/PowerPC/aix-filename-relative-path.ll
new file mode 100644 (file)
index 0000000..6df85c8
--- /dev/null
@@ -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 "../relative/path/to/file"
+
+source_filename = "../relative/path/to/file"