Skip to content

Commit bf66003

Browse files
committed
[MC,NVPTX] Add MCAsmPrinter support for unsigned-only data directives.
PTX does not support negative values in .bNN data directives and we must typecast such values to unsigned before printing them. MCAsmInfo can now specify whether such casting is necessary for particular target. Differential Revision: https://reviews.llvm.org/D83423
1 parent a560910 commit bf66003

File tree

4 files changed

+9
-1
lines changed

4 files changed

+9
-1
lines changed

llvm/include/llvm/MC/MCAsmInfo.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,9 @@ class MCAsmInfo {
209209
const char *Data32bitsDirective;
210210
const char *Data64bitsDirective;
211211

212+
/// True if data directives support signed values
213+
bool SupportsSignedData = true;
214+
212215
/// If non-null, a directive that is used to emit a word which should be
213216
/// relocated as a 64-bit GP-relative offset, e.g. .gpdword on Mips. Defaults
214217
/// to nullptr.
@@ -436,6 +439,7 @@ class MCAsmInfo {
436439
const char *getData16bitsDirective() const { return Data16bitsDirective; }
437440
const char *getData32bitsDirective() const { return Data32bitsDirective; }
438441
const char *getData64bitsDirective() const { return Data64bitsDirective; }
442+
bool supportsSignedData() const { return SupportsSignedData; }
439443
const char *getGPRel64Directive() const { return GPRel64Directive; }
440444
const char *getGPRel32Directive() const { return GPRel32Directive; }
441445
const char *getDTPRel64Directive() const { return DTPRel64Directive; }

llvm/lib/MC/MCExpr.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ void MCExpr::print(raw_ostream &OS, const MCAsmInfo *MAI, bool InParens) const {
4747
auto Value = cast<MCConstantExpr>(*this).getValue();
4848
auto PrintInHex = cast<MCConstantExpr>(*this).useHexFormat();
4949
auto SizeInBytes = cast<MCConstantExpr>(*this).getSizeInBytes();
50+
if (Value < 0 && MAI && !MAI->supportsSignedData())
51+
PrintInHex = true;
5052
if (PrintInHex)
5153
switch (SizeInBytes) {
5254
default:

llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXMCAsmInfo.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ NVPTXMCAsmInfo::NVPTXMCAsmInfo(const Triple &TheTriple,
4747
AscizDirective = nullptr; // not supported
4848
SupportsQuotedNames = false;
4949
SupportsExtendedDwarfLocDirective = false;
50+
SupportsSignedData = false;
5051

5152
// @TODO: Can we just disable this?
5253
WeakDirective = "\t// .weak\t";

llvm/test/DebugInfo/NVPTX/packed_bitfields.ll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
; CHECK: .b8 3 // DW_AT_decl_line
1515
; CHECK-NEXT: .b8 1 // DW_AT_byte_size
1616
; CHECK-NEXT: .b8 6 // DW_AT_bit_size
17-
; CHECK-NEXT: .b64 -1 // DW_AT_bit_offset
17+
; Negative offset must be encoded as an unsigned integer.
18+
; CHECK-NEXT: .b64 0xffffffffffffffff // DW_AT_bit_offset
1819
; CHECK-NEXT: .b8 2 // DW_AT_data_member_location
1920

2021
%struct.anon = type { i16 }

0 commit comments

Comments
 (0)