R600MCCodeEmitter &operator=(const R600MCCodeEmitter &) = delete;
/// Encode the instruction and write it to the OS.
- void encodeInstruction(const MCInst &MI, raw_ostream &OS,
+ void encodeInstruction(const MCInst &MI, SmallVectorImpl<char> &CB,
SmallVectorImpl<MCFixup> &Fixups,
const MCSubtargetInfo &STI) const override;
const MCSubtargetInfo &STI) const;
private:
-
- void Emit(uint32_t value, raw_ostream &OS) const;
- void Emit(uint64_t value, raw_ostream &OS) const;
+ void emit(uint32_t value, SmallVectorImpl<char> &CB) const;
+ void emit(uint64_t value, SmallVectorImpl<char> &CB) const;
unsigned getHWReg(unsigned regNo) const;
return new R600MCCodeEmitter(MCII, *Ctx.getRegisterInfo());
}
-void R600MCCodeEmitter::encodeInstruction(const MCInst &MI, raw_ostream &OS,
+void R600MCCodeEmitter::encodeInstruction(const MCInst &MI,
+ SmallVectorImpl<char> &CB,
SmallVectorImpl<MCFixup> &Fixups,
const MCSubtargetInfo &STI) const {
const MCInstrDesc &Desc = MCII.get(MI.getOpcode());
InstWord2 |= 1 << 19; // Mega-Fetch bit
}
- Emit(InstWord01, OS);
- Emit(InstWord2, OS);
- Emit((uint32_t) 0, OS);
+ emit(InstWord01, CB);
+ emit(InstWord2, CB);
+ emit((uint32_t)0, CB);
} else if (IS_TEX(Desc)) {
int64_t Sampler = MI.getOperand(14).getImm();
SrcSelect[ELEMENT_W] << 29 | Offsets[0] << 0 | Offsets[1] << 5 |
Offsets[2] << 10;
- Emit(Word01, OS);
- Emit(Word2, OS);
- Emit((uint32_t) 0, OS);
+ emit(Word01, CB);
+ emit(Word2, CB);
+ emit((uint32_t)0, CB);
} else {
uint64_t Inst = getBinaryCodeForInstr(MI, Fixups, STI);
if ((STI.hasFeature(R600::FeatureR600ALUInst)) &&
Inst &= ~(0x3FFULL << 39);
Inst |= ISAOpCode << 1;
}
- Emit(Inst, OS);
+ emit(Inst, CB);
}
}
-void R600MCCodeEmitter::Emit(uint32_t Value, raw_ostream &OS) const {
- support::endian::write(OS, Value, support::little);
+void R600MCCodeEmitter::emit(uint32_t Value, SmallVectorImpl<char> &CB) const {
+ support::endian::write(CB, Value, support::little);
}
-void R600MCCodeEmitter::Emit(uint64_t Value, raw_ostream &OS) const {
- support::endian::write(OS, Value, support::little);
+void R600MCCodeEmitter::emit(uint64_t Value, SmallVectorImpl<char> &CB) const {
+ support::endian::write(CB, Value, support::little);
}
unsigned R600MCCodeEmitter::getHWReg(unsigned RegNo) const {
#include "llvm/MC/MCSubtargetInfo.h"
#include "llvm/MC/SubtargetFeature.h"
#include "llvm/Support/Casting.h"
+#include "llvm/Support/EndianStream.h"
#include <optional>
using namespace llvm;
SIMCCodeEmitter &operator=(const SIMCCodeEmitter &) = delete;
/// Encode the instruction and write it to the OS.
- void encodeInstruction(const MCInst &MI, raw_ostream &OS,
+ void encodeInstruction(const MCInst &MI, SmallVectorImpl<char> &CB,
SmallVectorImpl<MCFixup> &Fixups,
const MCSubtargetInfo &STI) const override;
Desc.hasImplicitDefOfPhysReg(AMDGPU::EXEC);
}
-void SIMCCodeEmitter::encodeInstruction(const MCInst &MI, raw_ostream &OS,
+void SIMCCodeEmitter::encodeInstruction(const MCInst &MI,
+ SmallVectorImpl<char> &CB,
SmallVectorImpl<MCFixup> &Fixups,
const MCSubtargetInfo &STI) const {
int Opcode = MI.getOpcode();
}
for (unsigned i = 0; i < bytes; i++) {
- OS.write((uint8_t)Encoding.extractBitsAsZExtValue(8, 8 * i));
+ CB.push_back((uint8_t)Encoding.extractBitsAsZExtValue(8, 8 * i));
}
// NSA encoding.
for (unsigned i = 0; i < NumExtraAddrs; ++i) {
getMachineOpValue(MI, MI.getOperand(vaddr0 + 1 + i), Encoding, Fixups,
STI);
- OS.write((uint8_t)Encoding.getLimitedValue());
+ CB.push_back((uint8_t)Encoding.getLimitedValue());
}
- for (unsigned i = 0; i < NumPadding; ++i)
- OS.write(0);
+ CB.append(NumPadding, 0);
}
if ((bytes > 8 && STI.hasFeature(AMDGPU::FeatureVOP3Literal)) ||
} else if (!Op.isExpr()) // Exprs will be replaced with a fixup value.
llvm_unreachable("Must be immediate or expr");
- for (unsigned j = 0; j < 4; j++) {
- OS.write((uint8_t) ((Imm >> (8 * j)) & 0xff));
- }
+ support::endian::write<uint32_t>(CB, Imm, support::endianness::little);
// Only one literal value allowed
break;
SmallVectorImpl<MCFixup> &Fixups,
const MCSubtargetInfo &STI) const;
- void encodeInstruction(const MCInst &MI, raw_ostream &OS,
+ void encodeInstruction(const MCInst &MI, SmallVectorImpl<char> &CB,
SmallVectorImpl<MCFixup> &Fixups,
const MCSubtargetInfo &STI) const override;
};
return (Val & 0x0F) << 4 | (Val & 0xF0) >> 4;
}
-void BPFMCCodeEmitter::encodeInstruction(const MCInst &MI, raw_ostream &OS,
+void BPFMCCodeEmitter::encodeInstruction(const MCInst &MI,
+ SmallVectorImpl<char> &CB,
SmallVectorImpl<MCFixup> &Fixups,
const MCSubtargetInfo &STI) const {
unsigned Opcode = MI.getOpcode();
+ raw_svector_ostream OS(CB);
support::endian::Writer OSE(OS,
IsLittleEndian ? support::little : support::big);
if (Opcode == BPF::LD_imm64 || Opcode == BPF::LD_pseudo) {
uint64_t Value = getBinaryCodeForInstr(MI, Fixups, STI);
- OS << char(Value >> 56);
+ CB.push_back(Value >> 56);
if (IsLittleEndian)
- OS << char((Value >> 48) & 0xff);
+ CB.push_back((Value >> 48) & 0xff);
else
- OS << char(SwapBits((Value >> 48) & 0xff));
+ CB.push_back(SwapBits((Value >> 48) & 0xff));
OSE.write<uint16_t>(0);
OSE.write<uint32_t>(Value & 0xffffFFFF);
} else {
// Get instruction encoding and emit it
uint64_t Value = getBinaryCodeForInstr(MI, Fixups, STI);
- OS << char(Value >> 56);
+ CB.push_back(Value >> 56);
if (IsLittleEndian)
- OS << char((Value >> 48) & 0xff);
+ CB.push_back(char((Value >> 48) & 0xff));
else
- OS << char(SwapBits((Value >> 48) & 0xff));
+ CB.push_back(SwapBits((Value >> 48) & 0xff));
OSE.write<uint16_t>((Value >> 32) & 0xffff);
OSE.write<uint32_t>(Value & 0xffffFFFF);
}
~SystemZMCCodeEmitter() override = default;
// OVerride MCCodeEmitter.
- void encodeInstruction(const MCInst &MI, raw_ostream &OS,
+ void encodeInstruction(const MCInst &MI, SmallVectorImpl<char> &CB,
SmallVectorImpl<MCFixup> &Fixups,
const MCSubtargetInfo &STI) const override;
} // end anonymous namespace
-void SystemZMCCodeEmitter::encodeInstruction(const MCInst &MI, raw_ostream &OS,
+void SystemZMCCodeEmitter::encodeInstruction(const MCInst &MI,
+ SmallVectorImpl<char> &CB,
SmallVectorImpl<MCFixup> &Fixups,
const MCSubtargetInfo &STI) const {
MemOpsEmitted = 0;
// Big-endian insertion of Size bytes.
unsigned ShiftValue = (Size * 8) - 8;
for (unsigned I = 0; I != Size; ++I) {
- OS << uint8_t(Bits >> ShiftValue);
+ CB.push_back(uint8_t(Bits >> ShiftValue));
ShiftValue -= 8;
}
}
SmallVectorImpl<MCFixup> &Fixups,
const MCSubtargetInfo &STI) const;
- void encodeInstruction(const MCInst &MI, raw_ostream &OS,
+ void encodeInstruction(const MCInst &MI, SmallVectorImpl<char> &CB,
SmallVectorImpl<MCFixup> &Fixups,
const MCSubtargetInfo &STI) const override;
}
void WebAssemblyMCCodeEmitter::encodeInstruction(
- const MCInst &MI, raw_ostream &OS, SmallVectorImpl<MCFixup> &Fixups,
- const MCSubtargetInfo &STI) const {
+ const MCInst &MI, SmallVectorImpl<char> &CB,
+ SmallVectorImpl<MCFixup> &Fixups, const MCSubtargetInfo &STI) const {
+ raw_svector_ostream OS(CB);
uint64_t Start = OS.tell();
uint64_t Binary = getBinaryCodeForInstr(MI, Fixups, STI);