summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorQiu Chaofan <qiucofan@cn.ibm.com>2022-01-22 23:29:34 +0800
committerQiu Chaofan <qiucofan@cn.ibm.com>2022-01-22 23:29:34 +0800
commit00d68c3824bfcb103783b94c4cd8df353e4ee85d (patch)
treed82bac29d24a92dd22a8d45fd277231412a45783
parent8dedf9b58bff3589bff8cb422e449c4ee7f11499 (diff)
[PowerPC] Support parsing GNU attributes in MC
This patch is the first step to enable support of GNU attribute in LLVM PowerPC, enabling it for PowerPC targets, otherwise llvm-mc raises error when seeing the attribute section. Reviewed By: jsji Differential Revision: https://reviews.llvm.org/D115854
-rw-r--r--llvm/lib/Target/PowerPC/AsmParser/PPCAsmParser.cpp12
-rw-r--r--llvm/test/MC/PowerPC/gnu-attribute.s11
2 files changed, 23 insertions, 0 deletions
diff --git a/llvm/lib/Target/PowerPC/AsmParser/PPCAsmParser.cpp b/llvm/lib/Target/PowerPC/AsmParser/PPCAsmParser.cpp
index a640e63b5df8..715cff72dcab 100644
--- a/llvm/lib/Target/PowerPC/AsmParser/PPCAsmParser.cpp
+++ b/llvm/lib/Target/PowerPC/AsmParser/PPCAsmParser.cpp
@@ -121,6 +121,7 @@ class PPCAsmParser : public MCTargetAsmParser {
bool ParseDirectiveMachine(SMLoc L);
bool ParseDirectiveAbiVersion(SMLoc L);
bool ParseDirectiveLocalEntry(SMLoc L);
+ bool ParseGNUAttribute(SMLoc L);
bool MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
OperandVector &Operands, MCStreamer &Out,
@@ -1605,6 +1606,8 @@ bool PPCAsmParser::ParseDirective(AsmToken DirectiveID) {
ParseDirectiveAbiVersion(DirectiveID.getLoc());
else if (IDVal == ".localentry")
ParseDirectiveLocalEntry(DirectiveID.getLoc());
+ else if (IDVal.startswith(".gnu_attribute"))
+ ParseGNUAttribute(DirectiveID.getLoc());
else
return true;
return false;
@@ -1720,7 +1723,16 @@ bool PPCAsmParser::ParseDirectiveLocalEntry(SMLoc L) {
return false;
}
+bool PPCAsmParser::ParseGNUAttribute(SMLoc L) {
+ int64_t Tag;
+ int64_t IntegerValue;
+ if (!getParser().parseGNUAttribute(L, Tag, IntegerValue))
+ return false;
+
+ getParser().getStreamer().emitGNUAttribute(Tag, IntegerValue);
+ return true;
+}
/// Force static initialization.
extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializePowerPCAsmParser() {
diff --git a/llvm/test/MC/PowerPC/gnu-attribute.s b/llvm/test/MC/PowerPC/gnu-attribute.s
new file mode 100644
index 000000000000..98a558d52c6f
--- /dev/null
+++ b/llvm/test/MC/PowerPC/gnu-attribute.s
@@ -0,0 +1,11 @@
+# RUN: llvm-mc -triple powerpc64-unknown-linux-gnu < %s | FileCheck %s
+# RUN: llvm-mc -triple powerpc64le-unknown-linux-gnu < %s | FileCheck %s
+
+ .text
+add:
+ add 3, 4, 3
+ blr
+ .gnu_attribute 4, 13
+
+# CHECK-LABEL: add:
+# CHECK: .gnu_attribute 4, 13