[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 25 20:11:45 PDT 2022


Yunzezhu updated this revision to Diff 455780.
Yunzezhu added a comment.

Deleted unnecessary check prefix.
Added space in attributes flag.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D132204/new/

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 %s
+
+; CHECK: 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,11 @@
 }
 
 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 @@
   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.455780.patch
Type: text/x-patch
Size: 1782 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220826/19a3d46a/attachment.bin>


More information about the llvm-commits mailing list