[llvm] a95473c - [XCOFF] handle string constants generation for AIX
Chen Zheng via llvm-commits
llvm-commits at lists.llvm.org
Thu May 6 23:43:47 PDT 2021
Author: Chen Zheng
Date: 2021-05-07T06:43:36Z
New Revision: a95473c563bf5b6d657f5e5fa99bd551b2df339b
URL: https://github.com/llvm/llvm-project/commit/a95473c563bf5b6d657f5e5fa99bd551b2df339b
DIFF: https://github.com/llvm/llvm-project/commit/a95473c563bf5b6d657f5e5fa99bd551b2df339b.diff
LOG: [XCOFF] handle string constants generation for AIX
This follows https://www.ibm.com/docs/en/aix/7.2?topic=constants-string
Reviewed By: hubert.reinterpretcast
Differential Revision: https://reviews.llvm.org/D101280
Added:
llvm/test/CodeGen/PowerPC/aix-filename-special-character-double-quotation.ll
llvm/test/CodeGen/PowerPC/aix-filename-special-character-single-quotation.ll
Modified:
llvm/include/llvm/MC/MCAsmInfo.h
llvm/lib/MC/MCAsmInfoXCOFF.cpp
llvm/lib/MC/MCAsmStreamer.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/MC/MCAsmInfo.h b/llvm/include/llvm/MC/MCAsmInfo.h
index d24aaa257f63c..b7c075cb34512 100644
--- a/llvm/include/llvm/MC/MCAsmInfo.h
+++ b/llvm/include/llvm/MC/MCAsmInfo.h
@@ -357,9 +357,15 @@ class MCAsmInfo {
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.
+ /// target also needs the directory along with the basename. Defaults to true.
bool HasBasenameOnlyForFileDirective = true;
+ /// True if the target represents string constants as mostly raw characters in
+ /// paired double quotation with paired double quotation marks as the escape
+ /// mechanism to represent a double quotation mark within the string. Defaults
+ /// to false.
+ bool HasPairedDoubleQuoteStringConstants = false;
+
// True if the target allows .align directives on functions. This is true for
// most targets, so defaults to true.
bool HasFunctionAlignment = true;
@@ -697,6 +703,9 @@ class MCAsmInfo {
bool hasBasenameOnlyForFileDirective() const {
return HasBasenameOnlyForFileDirective;
}
+ bool hasPairedDoubleQuoteStringConstants() const {
+ return HasPairedDoubleQuoteStringConstants;
+ }
bool hasFunctionAlignment() const { return HasFunctionAlignment; }
bool hasDotTypeDotSizeDirective() const { return HasDotTypeDotSizeDirective; }
bool hasSingleParameterDotFile() const { return HasSingleParameterDotFile; }
diff --git a/llvm/lib/MC/MCAsmInfoXCOFF.cpp b/llvm/lib/MC/MCAsmInfoXCOFF.cpp
index f90fc5a8f4983..7ee0eef6aecee 100644
--- a/llvm/lib/MC/MCAsmInfoXCOFF.cpp
+++ b/llvm/lib/MC/MCAsmInfoXCOFF.cpp
@@ -20,6 +20,11 @@ MCAsmInfoXCOFF::MCAsmInfoXCOFF() {
IsLittleEndian = false;
HasVisibilityOnlyWithLinkage = true;
HasBasenameOnlyForFileDirective = false;
+
+ // For XCOFF, string constant consists of any number of characters enclosed in
+ // "" (double quotation marks).
+ HasPairedDoubleQuoteStringConstants = true;
+
PrivateGlobalPrefix = "L..";
PrivateLabelPrefix = "L..";
SupportsQuotedNames = false;
diff --git a/llvm/lib/MC/MCAsmStreamer.cpp b/llvm/lib/MC/MCAsmStreamer.cpp
index c988f36e0a9fd..ec4429d629001 100644
--- a/llvm/lib/MC/MCAsmStreamer.cpp
+++ b/llvm/lib/MC/MCAsmStreamer.cpp
@@ -60,6 +60,13 @@ class MCAsmStreamer final : public MCStreamer {
unsigned UseDwarfDirectory : 1;
void EmitRegisterName(int64_t Register);
+ void PrintQuotedString(StringRef Data, raw_ostream &OS) const;
+ void printDwarfFileDirective(unsigned FileNo, StringRef Directory,
+ StringRef Filename,
+ Optional<MD5::MD5Result> Checksum,
+ Optional<StringRef> Source,
+ bool UseDwarfDirectory,
+ raw_svector_ostream &OS) const;
void emitCFIStartProcImpl(MCDwarfFrameInfo &Frame) override;
void emitCFIEndProcImpl(MCDwarfFrameInfo &Frame) override;
@@ -1039,33 +1046,53 @@ static void PrintByteList(StringRef Data, raw_ostream &OS,
llvm_unreachable("Invalid AsmCharLiteralSyntax value!");
}
-static void PrintQuotedString(StringRef Data, raw_ostream &OS) {
+void MCAsmStreamer::PrintQuotedString(StringRef Data, raw_ostream &OS) const {
OS << '"';
- for (unsigned i = 0, e = Data.size(); i != e; ++i) {
- unsigned char C = Data[i];
- if (C == '"' || C == '\\') {
- OS << '\\' << (char)C;
- continue;
+ if (MAI->hasPairedDoubleQuoteStringConstants()) {
+ for (unsigned i = 0, e = Data.size(); i != e; ++i) {
+ unsigned char C = Data[i];
+ if (C == '"')
+ OS << "\"\"";
+ else
+ OS << (char)C;
}
+ } else {
+ for (unsigned i = 0, e = Data.size(); i != e; ++i) {
+ unsigned char C = Data[i];
+ if (C == '"' || C == '\\') {
+ OS << '\\' << (char)C;
+ continue;
+ }
- if (isPrint((unsigned char)C)) {
- OS << (char)C;
- continue;
- }
+ if (isPrint((unsigned char)C)) {
+ OS << (char)C;
+ continue;
+ }
- switch (C) {
- case '\b': OS << "\\b"; break;
- case '\f': OS << "\\f"; break;
- case '\n': OS << "\\n"; break;
- case '\r': OS << "\\r"; break;
- case '\t': OS << "\\t"; break;
+ switch (C) {
+ case '\b':
+ OS << "\\b";
+ break;
+ case '\f':
+ OS << "\\f";
+ break;
+ case '\n':
+ OS << "\\n";
+ break;
+ case '\r':
+ OS << "\\r";
+ break;
+ case '\t':
+ OS << "\\t";
+ break;
default:
OS << '\\';
OS << toOctal(C >> 6);
OS << toOctal(C >> 3);
OS << toOctal(C >> 0);
break;
+ }
}
}
@@ -1390,12 +1417,10 @@ void MCAsmStreamer::emitFileDirective(StringRef Filename) {
EmitEOL();
}
-static void printDwarfFileDirective(unsigned FileNo, StringRef Directory,
- StringRef Filename,
- Optional<MD5::MD5Result> Checksum,
- Optional<StringRef> Source,
- bool UseDwarfDirectory,
- raw_svector_ostream &OS) {
+void MCAsmStreamer::printDwarfFileDirective(
+ unsigned FileNo, StringRef Directory, StringRef Filename,
+ Optional<MD5::MD5Result> Checksum, Optional<StringRef> Source,
+ bool UseDwarfDirectory, raw_svector_ostream &OS) const {
SmallString<128> FullPathName;
if (!UseDwarfDirectory && !Directory.empty()) {
diff --git a/llvm/test/CodeGen/PowerPC/aix-filename-special-character-double-quotation.ll b/llvm/test/CodeGen/PowerPC/aix-filename-special-character-double-quotation.ll
new file mode 100644
index 0000000000000..05ef566bcf093
--- /dev/null
+++ b/llvm/test/CodeGen/PowerPC/aix-filename-special-character-double-quotation.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 "1""2.c"
+
+source_filename = "1\222.c"
diff --git a/llvm/test/CodeGen/PowerPC/aix-filename-special-character-single-quotation.ll b/llvm/test/CodeGen/PowerPC/aix-filename-special-character-single-quotation.ll
new file mode 100644
index 0000000000000..a600494e151b4
--- /dev/null
+++ b/llvm/test/CodeGen/PowerPC/aix-filename-special-character-single-quotation.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 "1'2.c"
+
+source_filename = "1'2.c"
More information about the llvm-commits
mailing list