[PATCH] D123702: [NVPTX] Disable parens for identifiers starting with '$'
Andrew Savonichev via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 13 12:27:17 PDT 2022
asavonic updated this revision to Diff 422597.
asavonic added a comment.
- Rebased and added patch context.
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/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
@@ -73,10 +73,15 @@
case MCExpr::SymbolRef: {
const MCSymbolRefExpr &SRE = cast<MCSymbolRefExpr>(*this);
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 = false;
+ if (MAI && MAI->useParensForDollarSignNames()) {
+ UseParens =
+ !InParens && !Sym.getName().empty() && Sym.getName()[0] == '$';
+ }
+
if (UseParens) {
OS << '(';
Sym.print(OS, MAI);
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;
@@ -788,6 +792,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.422597.patch
Type: text/x-patch
Size: 2993 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220413/bc9ec187/attachment.bin>
More information about the llvm-commits
mailing list