[PATCH] D102535: [RISCV] -mno-relax: emit .option norelax

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri May 14 14:28:29 PDT 2021


MaskRay created this revision.
MaskRay added reviewers: kito-cheng, raj.khem, jrtc27.
Herald added subscribers: 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, asb, hiraditya.
MaskRay requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

GNU as defaults to -mrelax. Emit `.option norelax` so that the emitted
assembly file can be assembled back correctly in -mno-relax mode.
This matches GCC.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D102535

Files:
  llvm/lib/Target/RISCV/RISCVAsmPrinter.cpp
  llvm/test/CodeGen/RISCV/option-norelax2.ll


Index: llvm/test/CodeGen/RISCV/option-norelax2.ll
===================================================================
--- /dev/null
+++ llvm/test/CodeGen/RISCV/option-norelax2.ll
@@ -0,0 +1,8 @@
+; RUN: llc -mtriple=riscv32 -mattr=-relax < %s | FileCheck %s
+; RUN: llc -mtriple=riscv64 -mattr=-relax < %s | FileCheck %s
+
+; CHECK: .option norelax
+
+define void @foo() {
+  ret void
+}
Index: llvm/lib/Target/RISCV/RISCVAsmPrinter.cpp
===================================================================
--- llvm/lib/Target/RISCV/RISCVAsmPrinter.cpp
+++ llvm/lib/Target/RISCV/RISCVAsmPrinter.cpp
@@ -178,6 +178,11 @@
 }
 
 void RISCVAsmPrinter::emitStartOfAsmFile(Module &M) {
+  if (!STI->getFeatureBits()[RISCV::FeatureRelax]) {
+    static_cast<RISCVTargetStreamer &>(*OutStreamer->getTargetStreamer())
+        .emitDirectiveOptionNoRelax();
+  }
+
   if (TM.getTargetTriple().isOSBinFormatELF())
     emitAttributes();
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D102535.345564.patch
Type: text/x-patch
Size: 928 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210514/488d9ec4/attachment.bin>


More information about the llvm-commits mailing list