[llvm] 3846e39 - [RISCV] Generate correct ELF abi flag when empty .ll file has target-abi attribute

via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 25 23:42:08 PDT 2022


Author: Yunze Zhu
Date: 2022-08-26T14:39:39+08:00
New Revision: 3846e3970feb506f52cf2cc696bb4a530633acc6

URL: https://github.com/llvm/llvm-project/commit/3846e3970feb506f52cf2cc696bb4a530633acc6
DIFF: https://github.com/llvm/llvm-project/commit/3846e3970feb506f52cf2cc696bb4a530633acc6.diff

LOG: [RISCV] Generate correct ELF abi flag when empty .ll file has target-abi attribute

In patch D121183, target abi is get from .ll file's target-abi
attribute and set in RISCVAsmPrinter::emitFunctionEntryLabel
function. In 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.

Signed-off-by: xiaojing.zhang <xiaojing.zhang at xcalibyte.com>
Signed-off-by: jianxin.lai <jianxin.lai at xcalibyte.com>

Reviewed By: luismarques

Differential Revision: https://reviews.llvm.org/D132204

Added: 
    llvm/test/CodeGen/RISCV/module-target-abi3.ll

Modified: 
    llvm/lib/Target/RISCV/RISCVAsmPrinter.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/RISCV/RISCVAsmPrinter.cpp b/llvm/lib/Target/RISCV/RISCVAsmPrinter.cpp
index edd39f6547ed..3f0584821fe3 100644
--- a/llvm/lib/Target/RISCV/RISCVAsmPrinter.cpp
+++ b/llvm/lib/Target/RISCV/RISCVAsmPrinter.cpp
@@ -69,8 +69,6 @@ class RISCVAsmPrinter : public AsmPrinter {
   void emitStartOfAsmFile(Module &M) override;
   void emitEndOfAsmFile(Module &M) override;
 
-  void emitFunctionEntryLabel() override;
-
 private:
   void emitAttributes();
 };
@@ -185,6 +183,11 @@ bool RISCVAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
 }
 
 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 +206,6 @@ void RISCVAsmPrinter::emitAttributes() {
   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());

diff  --git a/llvm/test/CodeGen/RISCV/module-target-abi3.ll b/llvm/test/CodeGen/RISCV/module-target-abi3.ll
new file mode 100644
index 000000000000..5df750c0d4b6
--- /dev/null
+++ b/llvm/test/CodeGen/RISCV/module-target-abi3.ll
@@ -0,0 +1,7 @@
+; RUN: llc -mtriple=riscv32 -filetype=obj < %s | llvm-readelf -h - | FileCheck %s
+
+; CHECK: Flags: 0x2, single-float ABI
+
+attributes #0 = { "target-features"="+f" }
+!llvm.module.flags = !{!0}
+!0 = !{i32 1, !"target-abi", !"ilp32f"}


        


More information about the llvm-commits mailing list