[PATCH] D127568: [RISCV][MC] Delete unnecessary code section align

luxufan via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Jun 11 06:59:53 PDT 2022


StephenFan created this revision.
StephenFan added reviewers: MaskRay, luismarques, asb, jrtc27, kito-cheng.
Herald added subscribers: sunshaoce, VincentWu, luke957, vkmr, frasercrmck, evandro, 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.
StephenFan requested review of this revision.
Herald added subscribers: llvm-commits, pcwang-thead, eopXD.
Herald added a project: LLVM.

Since RISCVELFTargetObjectFile does not inherit RISCVMCObjectFileInfo,
the alignment of code section is always 4 even if c extension was enabled.
If c extension was enabled, the nop instruction is 2 bytes, which will
make the assember to emit a code align fixup.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D127568

Files:
  llvm/include/llvm/Target/TargetLoweringObjectFile.h
  llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCObjectFileInfo.h
  llvm/lib/Target/RISCV/RISCVTargetObjectFile.h
  llvm/test/MC/RISCV/unnecessary-code-align.ll


Index: llvm/test/MC/RISCV/unnecessary-code-align.ll
===================================================================
--- llvm/test/MC/RISCV/unnecessary-code-align.ll
+++ llvm/test/MC/RISCV/unnecessary-code-align.ll
@@ -2,9 +2,9 @@
 ; RUN:     | llvm-readobj -r - | FileCheck %s
 
 ; CHECK: Relocations [
-; CHECK:   Section (3) .rela.text {
-; CHECK:     0x0 R_RISCV_ALIGN - 0x2
-; CHECK:   }
+; CHECK-NOT:   Section (3) .rela.text {
+; CHECK-NOT:     0x0 R_RISCV_ALIGN - 0x2
+; CHECK-NOT:   }
 ; CHECK: ]
 define i32 @test() #0 {
 entry:
Index: llvm/lib/Target/RISCV/RISCVTargetObjectFile.h
===================================================================
--- llvm/lib/Target/RISCV/RISCVTargetObjectFile.h
+++ llvm/lib/Target/RISCV/RISCVTargetObjectFile.h
@@ -9,12 +9,14 @@
 #ifndef LLVM_LIB_TARGET_RISCV_RISCVTARGETOBJECTFILE_H
 #define LLVM_LIB_TARGET_RISCV_RISCVTARGETOBJECTFILE_H
 
+#include "MCTargetDesc/RISCVMCObjectFileInfo.h"
 #include "llvm/CodeGen/TargetLoweringObjectFileImpl.h"
 
 namespace llvm {
 
 /// This implementation is used for RISCV ELF targets.
-class RISCVELFTargetObjectFile : public TargetLoweringObjectFileELF {
+class RISCVELFTargetObjectFile : public RISCVMCObjectFileInfo,
+                                 public TargetLoweringObjectFileELF {
   MCSection *SmallDataSection;
   MCSection *SmallBSSSection;
   unsigned SSThreshold = 8;
Index: llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCObjectFileInfo.h
===================================================================
--- llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCObjectFileInfo.h
+++ llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCObjectFileInfo.h
@@ -17,7 +17,7 @@
 
 namespace llvm {
 
-class RISCVMCObjectFileInfo : public MCObjectFileInfo {
+class RISCVMCObjectFileInfo : public virtual MCObjectFileInfo {
 public:
   unsigned getTextSectionAlignment() const override;
 };
Index: llvm/include/llvm/Target/TargetLoweringObjectFile.h
===================================================================
--- llvm/include/llvm/Target/TargetLoweringObjectFile.h
+++ llvm/include/llvm/Target/TargetLoweringObjectFile.h
@@ -42,7 +42,7 @@
 class TargetMachine;
 class DSOLocalEquivalent;
 
-class TargetLoweringObjectFile : public MCObjectFileInfo {
+class TargetLoweringObjectFile : public virtual MCObjectFileInfo {
   /// Name-mangler for global names.
   Mangler *Mang = nullptr;
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D127568.436139.patch
Type: text/x-patch
Size: 2367 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220611/5ec0fe16/attachment.bin>


More information about the llvm-commits mailing list