diff options
author | Fangrui Song <i@maskray.me> | 2023-08-09 09:49:12 -0700 |
---|---|---|
committer | Fangrui Song <i@maskray.me> | 2023-08-09 09:49:12 -0700 |
commit | 2f5a183ff30667ce5d596e5ddd069f99a620cbeb (patch) | |
tree | 1ee28b58e730048894fcad0f324723a84bd4f251 | |
parent | d4128a2a06aa7fa9a4b13eb09e3811b9bb4c4fe7 (diff) | |
download | llvm-2f5a183ff30667ce5d596e5ddd069f99a620cbeb.zip llvm-2f5a183ff30667ce5d596e5ddd069f99a620cbeb.tar.gz llvm-2f5a183ff30667ce5d596e5ddd069f99a620cbeb.tar.bz2 |
[CSKY] Migrate to new encodeInstruction that uses SmallVectorImpl<char>. NFC
-rw-r--r-- | llvm/lib/Target/CSKY/MCTargetDesc/CSKYMCCodeEmitter.cpp | 49 | ||||
-rw-r--r-- | llvm/lib/Target/CSKY/MCTargetDesc/CSKYMCCodeEmitter.h | 8 |
2 files changed, 23 insertions, 34 deletions
diff --git a/llvm/lib/Target/CSKY/MCTargetDesc/CSKYMCCodeEmitter.cpp b/llvm/lib/Target/CSKY/MCTargetDesc/CSKYMCCodeEmitter.cpp index ea41d53e..4437c5c 100644 --- a/llvm/lib/Target/CSKY/MCTargetDesc/CSKYMCCodeEmitter.cpp +++ b/llvm/lib/Target/CSKY/MCTargetDesc/CSKYMCCodeEmitter.cpp @@ -57,17 +57,14 @@ CSKYMCCodeEmitter::getImmOpValueMSBSize(const MCInst &MI, unsigned Idx, return MSB.getImm() - LSB.getImm(); } -static void writeData(uint32_t Bin, unsigned Size, raw_ostream &OS) { - uint16_t LO16 = static_cast<uint16_t>(Bin); - uint16_t HI16 = static_cast<uint16_t>(Bin >> 16); - +static void writeData(uint32_t Bin, unsigned Size, SmallVectorImpl<char> &CB) { if (Size == 4) - support::endian::write<uint16_t>(OS, HI16, support::little); - - support::endian::write<uint16_t>(OS, LO16, support::little); + support::endian::write(CB, static_cast<uint16_t>(Bin >> 16), + support::little); + support::endian::write(CB, static_cast<uint16_t>(Bin), support::little); } -void CSKYMCCodeEmitter::expandJBTF(const MCInst &MI, raw_ostream &OS, +void CSKYMCCodeEmitter::expandJBTF(const MCInst &MI, SmallVectorImpl<char> &CB, SmallVectorImpl<MCFixup> &Fixups, const MCSubtargetInfo &STI) const { @@ -80,7 +77,7 @@ void CSKYMCCodeEmitter::expandJBTF(const MCInst &MI, raw_ostream &OS, .addOperand(MI.getOperand(0)) .addImm(6); Binary = getBinaryCodeForInstr(TmpInst, Fixups, STI); - writeData(Binary, 2, OS); + writeData(Binary, 2, CB); if (!STI.hasFeature(CSKY::Has2E3)) TmpInst = MCInstBuilder(CSKY::BR32) @@ -90,10 +87,10 @@ void CSKYMCCodeEmitter::expandJBTF(const MCInst &MI, raw_ostream &OS, TmpInst = MCInstBuilder(CSKY::JMPI32).addOperand(MI.getOperand(2)); Binary = getBinaryCodeForInstr(TmpInst, Fixups, STI); Fixups[Fixups.size() - 1].setOffset(2); - writeData(Binary, 4, OS); + writeData(Binary, 4, CB); } -void CSKYMCCodeEmitter::expandNEG(const MCInst &MI, raw_ostream &OS, +void CSKYMCCodeEmitter::expandNEG(const MCInst &MI, SmallVectorImpl<char> &CB, SmallVectorImpl<MCFixup> &Fixups, const MCSubtargetInfo &STI) const { @@ -105,17 +102,17 @@ void CSKYMCCodeEmitter::expandNEG(const MCInst &MI, raw_ostream &OS, .addOperand(MI.getOperand(0)) .addOperand(MI.getOperand(1)); Binary = getBinaryCodeForInstr(TmpInst, Fixups, STI); - writeData(Binary, Size, OS); + writeData(Binary, Size, CB); TmpInst = MCInstBuilder(Size == 4 ? CSKY::ADDI32 : CSKY::ADDI16) .addOperand(MI.getOperand(0)) .addOperand(MI.getOperand(0)) .addImm(1); Binary = getBinaryCodeForInstr(TmpInst, Fixups, STI); - writeData(Binary, Size, OS); + writeData(Binary, Size, CB); } -void CSKYMCCodeEmitter::expandRSUBI(const MCInst &MI, raw_ostream &OS, +void CSKYMCCodeEmitter::expandRSUBI(const MCInst &MI, SmallVectorImpl<char> &CB, SmallVectorImpl<MCFixup> &Fixups, const MCSubtargetInfo &STI) const { @@ -127,17 +124,18 @@ void CSKYMCCodeEmitter::expandRSUBI(const MCInst &MI, raw_ostream &OS, .addOperand(MI.getOperand(0)) .addOperand(MI.getOperand(1)); Binary = getBinaryCodeForInstr(TmpInst, Fixups, STI); - writeData(Binary, Size, OS); + writeData(Binary, Size, CB); TmpInst = MCInstBuilder(Size == 4 ? CSKY::ADDI32 : CSKY::ADDI16) .addOperand(MI.getOperand(0)) .addOperand(MI.getOperand(0)) .addImm(MI.getOperand(2).getImm() + 1); Binary = getBinaryCodeForInstr(TmpInst, Fixups, STI); - writeData(Binary, Size, OS); + writeData(Binary, Size, CB); } -void CSKYMCCodeEmitter::encodeInstruction(const MCInst &MI, raw_ostream &OS, +void CSKYMCCodeEmitter::encodeInstruction(const MCInst &MI, + SmallVectorImpl<char> &CB, SmallVectorImpl<MCFixup> &Fixups, const MCSubtargetInfo &STI) const { const MCInstrDesc &Desc = MII.get(MI.getOpcode()); @@ -151,17 +149,17 @@ void CSKYMCCodeEmitter::encodeInstruction(const MCInst &MI, raw_ostream &OS, break; case CSKY::JBT_E: case CSKY::JBF_E: - expandJBTF(MI, OS, Fixups, STI); + expandJBTF(MI, CB, Fixups, STI); MCNumEmitted += 2; return; case CSKY::NEG32: case CSKY::NEG16: - expandNEG(MI, OS, Fixups, STI); + expandNEG(MI, CB, Fixups, STI); MCNumEmitted += 2; return; case CSKY::RSUBI32: case CSKY::RSUBI16: - expandRSUBI(MI, OS, Fixups, STI); + expandRSUBI(MI, CB, Fixups, STI); MCNumEmitted += 2; return; case CSKY::JBSR32: @@ -229,16 +227,7 @@ void CSKYMCCodeEmitter::encodeInstruction(const MCInst &MI, raw_ostream &OS, } ++MCNumEmitted; - - uint32_t Bin = getBinaryCodeForInstr(TmpInst, Fixups, STI); - - uint16_t LO16 = static_cast<uint16_t>(Bin); - uint16_t HI16 = static_cast<uint16_t>(Bin >> 16); - - if (Size == 4) - support::endian::write<uint16_t>(OS, HI16, support::little); - - support::endian::write<uint16_t>(OS, LO16, support::little); + writeData(getBinaryCodeForInstr(TmpInst, Fixups, STI), Size, CB); } unsigned diff --git a/llvm/lib/Target/CSKY/MCTargetDesc/CSKYMCCodeEmitter.h b/llvm/lib/Target/CSKY/MCTargetDesc/CSKYMCCodeEmitter.h index 1284301..0e47d25 100644 --- a/llvm/lib/Target/CSKY/MCTargetDesc/CSKYMCCodeEmitter.h +++ b/llvm/lib/Target/CSKY/MCTargetDesc/CSKYMCCodeEmitter.h @@ -32,7 +32,7 @@ public: ~CSKYMCCodeEmitter() {} - void encodeInstruction(const MCInst &Inst, raw_ostream &OS, + void encodeInstruction(const MCInst &Inst, SmallVectorImpl<char> &CB, SmallVectorImpl<MCFixup> &Fixups, const MCSubtargetInfo &STI) const override; @@ -172,13 +172,13 @@ public: return 0; } - void expandJBTF(const MCInst &MI, raw_ostream &OS, + void expandJBTF(const MCInst &MI, SmallVectorImpl<char> &CB, SmallVectorImpl<MCFixup> &Fixups, const MCSubtargetInfo &STI) const; - void expandNEG(const MCInst &MI, raw_ostream &OS, + void expandNEG(const MCInst &MI, SmallVectorImpl<char> &CB, SmallVectorImpl<MCFixup> &Fixups, const MCSubtargetInfo &STI) const; - void expandRSUBI(const MCInst &MI, raw_ostream &OS, + void expandRSUBI(const MCInst &MI, SmallVectorImpl<char> &CB, SmallVectorImpl<MCFixup> &Fixups, const MCSubtargetInfo &STI) const; }; |