[PATCH] D117193: [PowerPC] Emit gnu_attribute according to float-abi metadata
Qiu Chaofan via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 13 00:11:22 PST 2022
qiucf created this revision.
qiucf added reviewers: nemanjai, shchenz, jsji, PowerPC.
Herald added subscribers: steven.zhang, kbarton, hiraditya.
qiucf requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
According to GNU as documentation, PowerPC supports two kinds of .gnu_attribute tag to represent the vector and float ABI type in the object file. (https://sourceware.org/binutils/docs-2.35/as/GNU-Object-Attributes.html) Some linkers like GNU ld respects the attribute and will prevent objects with conflicting ABIs being linked.
This patch emits gnu_attribute value in assembly printer according to the `float-abi` metadata defined in D116016 <https://reviews.llvm.org/D116016>.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D117193
Files:
llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
llvm/test/CodeGen/PowerPC/gnu-attribute.ll
Index: llvm/test/CodeGen/PowerPC/gnu-attribute.ll
===================================================================
--- /dev/null
+++ llvm/test/CodeGen/PowerPC/gnu-attribute.ll
@@ -0,0 +1,15 @@
+; RUN: sed -e 's/FLTABI/ieeequad/' %s | llc -mtriple=powerpc64le | FileCheck %s --check-prefix=IEEE
+; RUN: sed -e 's/FLTABI/doubledouble/' %s | llc -mtriple=powerpc64le | FileCheck %s --check-prefix=IBM
+; RUN: sed -e 's/FLTABI/ieeedouble/' %s | llc -mtriple=powerpc64le | FileCheck %s --check-prefix=DBL
+; RUN: sed -e 's/FLTABI//' %s | llc -mtriple=powerpc64le | FileCheck %s --check-prefix=NONE
+
+; IEEE: .gnu_attribute 4, 13
+; IBM: .gnu_attribute 4, 5
+; DBL: .gnu_attribute 4, 9
+; NONE-NOT: .gnu_attribute 4,
+
+!llvm.module.flags = !{!0, !1, !2}
+
+!0 = !{i32 1, !"wchar_size", i32 4}
+!1 = !{i32 7, !"uwtable", i32 1}
+!2 = !{i32 1, !"float-abi", !"FLTABI"}
Index: llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
===================================================================
--- llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
+++ llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
@@ -178,6 +178,8 @@
return "Linux PPC Assembly Printer";
}
+ void emitAttributes(Module &M);
+
void emitStartOfAsmFile(Module &M) override;
void emitEndOfAsmFile(Module &) override;
@@ -1388,6 +1390,20 @@
EmitToStreamer(*OutStreamer, TmpInst);
}
+void PPCLinuxAsmPrinter::emitAttributes(Module &M) {
+ Metadata *MD = M.getModuleFlag("float-abi");
+ MDString *FloatABI = dyn_cast_or_null<MDString>(MD);
+ if (!FloatABI)
+ return;
+ StringRef flt = FloatABI->getString();
+ if (flt == "doubledouble")
+ OutStreamer->emitGNUAttribute(4, 5);
+ else if (flt == "ieeequad")
+ OutStreamer->emitGNUAttribute(4, 13);
+ else if (flt == "ieeedouble")
+ OutStreamer->emitGNUAttribute(4, 9);
+}
+
void PPCLinuxAsmPrinter::emitInstruction(const MachineInstr *MI) {
if (!Subtarget->isPPC64())
return PPCAsmPrinter::emitInstruction(MI);
@@ -1642,6 +1658,8 @@
PPCTargetStreamer *TS =
static_cast<PPCTargetStreamer *>(OutStreamer->getTargetStreamer());
+ emitAttributes(M);
+
if (!TOC.empty()) {
const char *Name = isPPC64 ? ".toc" : ".got2";
MCSectionELF *Section = OutContext.getELFSection(
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D117193.399566.patch
Type: text/x-patch
Size: 2229 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220113/f8425e84/attachment.bin>
More information about the llvm-commits
mailing list