[PATCH] D41221: [RISCV] writeNopData support generate c.nop
Alex Bradbury via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 17 06:19:21 PST 2018
This revision was automatically updated to reflect the committed changes.
Closed by commit rL322658: [RISCV] Allow RISCVAsmBackend::writeNopData to generate c.nop when supported (authored by asb, committed by ).
Changed prior to commit:
https://reviews.llvm.org/D41221?vs=129616&id=130165#toc
Repository:
rL LLVM
https://reviews.llvm.org/D41221
Files:
llvm/trunk/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp
llvm/trunk/test/MC/RISCV/cnop.s
Index: llvm/trunk/test/MC/RISCV/cnop.s
===================================================================
--- llvm/trunk/test/MC/RISCV/cnop.s
+++ llvm/trunk/test/MC/RISCV/cnop.s
@@ -0,0 +1,26 @@
+# RUN: llvm-mc -filetype=obj -triple riscv32 -mattr=+c < %s \
+# RUN: | llvm-objdump -mattr=+c -d - | FileCheck -check-prefix=CHECK-INST %s
+
+# alpha and main are 8 byte alignment
+# but the alpha function's size is 6
+# So assembler will insert a c.nop to make sure 8 byte alignment.
+
+ .text
+ .p2align 3
+ .type alpha, at function
+alpha:
+# BB#0:
+ addi sp, sp, -16
+ c.lw a0, 0(a0)
+# CHECK-INST: c.nop
+.Lfunc_end0:
+ .size alpha, .Lfunc_end0-alpha
+ # -- End function
+ .globl main
+ .p2align 3
+ .type main, at function
+main: # @main
+# BB#0:
+.Lfunc_end1:
+ .size main, .Lfunc_end1-main
+ # -- End function
Index: llvm/trunk/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp
===================================================================
--- llvm/trunk/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp
+++ llvm/trunk/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp
@@ -27,12 +27,13 @@
namespace {
class RISCVAsmBackend : public MCAsmBackend {
+ const MCSubtargetInfo &STI;
uint8_t OSABI;
bool Is64Bit;
public:
- RISCVAsmBackend(uint8_t OSABI, bool Is64Bit)
- : MCAsmBackend(), OSABI(OSABI), Is64Bit(Is64Bit) {}
+ RISCVAsmBackend(const MCSubtargetInfo &STI, uint8_t OSABI, bool Is64Bit)
+ : MCAsmBackend(), STI(STI), OSABI(OSABI), Is64Bit(Is64Bit) {}
~RISCVAsmBackend() override {}
void applyFixup(const MCAssembler &Asm, const MCFixup &Fixup,
@@ -88,15 +89,24 @@
};
bool RISCVAsmBackend::writeNopData(uint64_t Count, MCObjectWriter *OW) const {
- // Once support for the compressed instruction set is added, we will be able
- // to conditionally support 16-bit NOPs
- if ((Count % 4) != 0)
+ bool HasStdExtC = STI.getFeatureBits()[RISCV::FeatureStdExtC];
+ unsigned MinNopLen = HasStdExtC ? 2 : 4;
+
+ if ((Count % MinNopLen) != 0)
return false;
- // The canonical nop on RISC-V is addi x0, x0, 0
- for (uint64_t i = 0; i < Count; i += 4)
+ // The canonical nop on RISC-V is addi x0, x0, 0.
+ uint64_t Nop32Count = Count / 4;
+ for (uint64_t i = Nop32Count; i != 0; --i)
OW->write32(0x13);
+ // The canonical nop on RVC is c.nop.
+ if (HasStdExtC) {
+ uint64_t Nop16Count = (Count - Nop32Count * 4) / 2;
+ for (uint64_t i = Nop16Count; i != 0; --i)
+ OW->write16(0x01);
+ }
+
return true;
}
@@ -235,5 +245,5 @@
const MCTargetOptions &Options) {
const Triple &TT = STI.getTargetTriple();
uint8_t OSABI = MCELFObjectTargetWriter::getOSABI(TT.getOS());
- return new RISCVAsmBackend(OSABI, TT.isArch64Bit());
+ return new RISCVAsmBackend(STI, OSABI, TT.isArch64Bit());
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D41221.130165.patch
Type: text/x-patch
Size: 3019 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180117/5622dcaa/attachment-0001.bin>
More information about the llvm-commits
mailing list