[PATCH] D132204: [RISCV] Generate correct ELF abi flag when empty .ll file has target-abi attribute
Yunze Zhu(Thead) via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 18 23:27:47 PDT 2022
Yunzezhu created this revision.
Yunzezhu added reviewers: jrtc27, asb, craig.topper, khchen, kito-cheng.
Herald added subscribers: sunshaoce, VincentWu, luke957, StephenFan, vkmr, frasercrmck, evandro, luismarques, apazos, sameer.abuasal, s.egerton, Jim, benna, psnobl, jocewei, PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, shiva0217, niosHD, sabuasal, simoncook, johnrusso, rbar, hiraditya, arichardson.
Herald added a project: All.
Yunzezhu requested review of this revision.
Herald added subscribers: llvm-commits, pcwang-thead, eopXD, MaskRay.
Herald added a project: LLVM.
In patch https://reviews.llvm.org/D121183 target abi value is get from .ll file's target-abi attribute and set in RISCVAsmPrinter::emitFunctionEntryLabel function .
In this problem https://github.com/llvm/llvm-project/issues/57242, an api mismatch error may be caused by failing to call function RISCVAsmPrinter::emitFunctionEntryLabel to set target-abi to correct one when the .ll is empty or a module has no function.
This patch move setting target-abi part to function RISCVAsmPrinter::emitStartOfAsmFile, make sure all .ll file and module in LTO read target-abi from module flag and set, with or without function.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D132204
Files:
llvm/lib/Target/RISCV/RISCVAsmPrinter.cpp
llvm/test/CodeGen/RISCV/module-target-abi3.ll
Index: llvm/test/CodeGen/RISCV/module-target-abi3.ll
===================================================================
--- /dev/null
+++ llvm/test/CodeGen/RISCV/module-target-abi3.ll
@@ -0,0 +1,7 @@
+; RUN: llc -mtriple=riscv32 -filetype=obj < %s | llvm-readelf -h - | FileCheck -check-prefixes=FLAGS %s
+
+; FLAGS: Flags: 0x2, single-float ABI
+
+attributes #0 = { "target-features"="+f"}
+!llvm.module.flags = !{!0}
+!0 = !{i32 1, !"target-abi", !"ilp32f"}
Index: llvm/lib/Target/RISCV/RISCVAsmPrinter.cpp
===================================================================
--- llvm/lib/Target/RISCV/RISCVAsmPrinter.cpp
+++ llvm/lib/Target/RISCV/RISCVAsmPrinter.cpp
@@ -69,8 +69,6 @@
void emitStartOfAsmFile(Module &M) override;
void emitEndOfAsmFile(Module &M) override;
- void emitFunctionEntryLabel() override;
-
private:
void emitAttributes();
};
@@ -185,6 +183,12 @@
}
void RISCVAsmPrinter::emitStartOfAsmFile(Module &M) {
+ RISCVTargetStreamer &RTS =
+ static_cast<RISCVTargetStreamer &>(*OutStreamer->getTargetStreamer());
+ if (const MDString *ModuleTargetABI =
+ dyn_cast_or_null<MDString>(M.getModuleFlag("target-abi"))) {
+ RTS.setTargetABI(RISCVABI::getTargetABI(ModuleTargetABI->getString()));
+ }
if (TM.getTargetTriple().isOSBinFormatELF())
emitAttributes();
}
@@ -203,13 +207,6 @@
RTS.emitTargetAttributes(*MCSTI);
}
-void RISCVAsmPrinter::emitFunctionEntryLabel() {
- AsmPrinter::emitFunctionEntryLabel();
- RISCVTargetStreamer &RTS =
- static_cast<RISCVTargetStreamer &>(*OutStreamer->getTargetStreamer());
- RTS.setTargetABI(STI->getTargetABI());
-}
-
// Force static initialization.
extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeRISCVAsmPrinter() {
RegisterAsmPrinter<RISCVAsmPrinter> X(getTheRISCV32Target());
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D132204.453892.patch
Type: text/x-patch
Size: 1810 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220819/09bb469c/attachment.bin>
More information about the llvm-commits
mailing list