summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorAlex Bradbury <asb@lowrisc.org>2018-01-17 14:17:12 +0000
committerAlex Bradbury <asb@lowrisc.org>2018-01-17 14:17:12 +0000
commitd93f889d8944fa0175f6f4b3eced2224086a7b00 (patch)
tree79cce6ab3c110eef00c42b066387fa7ec74d25ff /llvm/lib
parentc62a16234b587bdfd934da85ddd2b49ce0584c3a (diff)
downloadbcm5719-llvm-d93f889d8944fa0175f6f4b3eced2224086a7b00.tar.gz
bcm5719-llvm-d93f889d8944fa0175f6f4b3eced2224086a7b00.zip
[RISCV] Allow RISCVAsmBackend::writeNopData to generate c.nop when supported
When the compressed instruction set is enabled, the 16-bit c.nop can be generated if necessary. Differential Revision: https://reviews.llvm.org/D41221 Patch by Shiva Chen. llvm-svn: 322658
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp26
1 files changed, 18 insertions, 8 deletions
diff --git a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp
index 6e06a4975e2..3dcd36f1b71 100644
--- a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp
+++ b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp
@@ -27,12 +27,13 @@ using namespace llvm;
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 @@ public:
};
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 @@ MCAsmBackend *llvm::createRISCVAsmBackend(const Target &T,
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());
}
OpenPOWER on IntegriCloud