[PATCH] D123702: [NVPTX] Disable parens for identifiers starting with '$'

Andrew Savonichev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 15 06:39:48 PDT 2022


asavonic updated this revision to Diff 423082.
asavonic edited the summary of this revision.
asavonic added a comment.
Herald added a subscriber: mattd.

- Fixed issues found in Mips LIT tests: MCAsmStreamer had one call to 'operator<<' function which doesn't pass MAI to MCExpr::print.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D123702/new/

https://reviews.llvm.org/D123702

Files:
  llvm/include/llvm/MC/MCAsmInfo.h
  llvm/lib/MC/MCAsmStreamer.cpp
  llvm/lib/MC/MCExpr.cpp
  llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXMCAsmInfo.cpp
  llvm/test/CodeGen/NVPTX/no-extra-parens.ll


Index: llvm/test/CodeGen/NVPTX/no-extra-parens.ll
===================================================================
--- /dev/null
+++ llvm/test/CodeGen/NVPTX/no-extra-parens.ll
@@ -0,0 +1,14 @@
+; RUN: llc < %s -march=nvptx64 -mcpu=sm_20 | FileCheck %s
+
+; ptxas has no special meaning for '$' character, so it should be used
+; without parens.
+
+@"$str" = private addrspace(1) constant [4 x i8] c"str\00"
+
+declare void @str2(i8* %str)
+define void @str1() {
+entry:
+;; CHECK: mov.u64 %rd{{[0-9]+}}, $str;
+  tail call void @str2(i8* getelementptr ([4 x i8], [4 x i8]* addrspacecast ([4 x i8] addrspace(1)* @"$str" to [4 x i8]*), i64 0, i64 0))
+  ret void
+}
Index: llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXMCAsmInfo.cpp
===================================================================
--- llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXMCAsmInfo.cpp
+++ llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXMCAsmInfo.cpp
@@ -54,4 +54,8 @@
   GlobalDirective = "\t// .globl\t";
 
   UseIntegratedAssembler = false;
+
+  // Avoid using parens for identifiers starting with $ - ptxas does
+  // not expect them.
+  UseParensForDollarSignNames = false;
 }
Index: llvm/lib/MC/MCExpr.cpp
===================================================================
--- llvm/lib/MC/MCExpr.cpp
+++ llvm/lib/MC/MCExpr.cpp
@@ -75,8 +75,9 @@
     const MCSymbol &Sym = SRE.getSymbol();
     // Parenthesize names that start with $ so that they don't look like
     // absolute names.
-    bool UseParens =
-        !InParens && !Sym.getName().empty() && Sym.getName()[0] == '$';
+    bool UseParens = MAI && MAI->useParensForDollarSignNames() && !InParens &&
+                     !Sym.getName().empty() && Sym.getName()[0] == '$';
+
     if (UseParens) {
       OS << '(';
       Sym.print(OS, MAI);
Index: llvm/lib/MC/MCAsmStreamer.cpp
===================================================================
--- llvm/lib/MC/MCAsmStreamer.cpp
+++ llvm/lib/MC/MCAsmStreamer.cpp
@@ -2251,8 +2251,10 @@
     MCFixup &F = Fixups[i];
     const MCFixupKindInfo &Info =
         getAssembler().getBackend().getFixupKindInfo(F.getKind());
-    OS << "  fixup " << char('A' + i) << " - " << "offset: " << F.getOffset()
-       << ", value: " << *F.getValue() << ", kind: " << Info.Name << "\n";
+    OS << "  fixup " << char('A' + i) << " - "
+       << "offset: " << F.getOffset() << ", value: ";
+    F.getValue()->print(OS, MAI);
+    OS << ", kind: " << Info.Name << "\n";
   }
 }
 
Index: llvm/include/llvm/MC/MCAsmInfo.h
===================================================================
--- llvm/include/llvm/MC/MCAsmInfo.h
+++ llvm/include/llvm/MC/MCAsmInfo.h
@@ -478,6 +478,10 @@
   /// For example, foo(plt) instead of foo at plt.  Defaults to false.
   bool UseParensForSymbolVariant = false;
 
+  /// True if the target uses parens for symbol names starting with
+  /// '$' character to distinguish them from absolute names.
+  bool UseParensForDollarSignNames = true;
+
   /// True if the target supports flags in ".loc" directive, false if only
   /// location is allowed.
   bool SupportsExtendedDwarfLocDirective = true;
@@ -789,6 +793,9 @@
   bool doDwarfFDESymbolsUseAbsDiff() const { return DwarfFDESymbolsUseAbsDiff; }
   bool useDwarfRegNumForCFI() const { return DwarfRegNumForCFI; }
   bool useParensForSymbolVariant() const { return UseParensForSymbolVariant; }
+  bool useParensForDollarSignNames() const {
+    return UseParensForDollarSignNames;
+  }
   bool supportsExtendedDwarfLocDirective() const {
     return SupportsExtendedDwarfLocDirective;
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D123702.423082.patch
Type: text/x-patch
Size: 3540 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220415/fd34da4e/attachment.bin>


More information about the llvm-commits mailing list