31 #define DEBUG_TYPE "mccodeemitter" 33 STATISTIC(MCNumEmitted,
"Number of MC instructions emitted");
39 class LanaiMCCodeEmitter :
public MCCodeEmitter {
41 LanaiMCCodeEmitter(
const MCInstrInfo &MCII, MCContext &
C) {}
42 LanaiMCCodeEmitter(
const LanaiMCCodeEmitter &) =
delete;
43 void operator=(
const LanaiMCCodeEmitter &) =
delete;
44 ~LanaiMCCodeEmitter()
override =
default;
51 uint64_t getBinaryCodeForInstr(
const MCInst &Inst,
52 SmallVectorImpl<MCFixup> &
Fixups,
53 const MCSubtargetInfo &SubtargetInfo)
const;
57 unsigned getMachineOpValue(
const MCInst &Inst,
const MCOperand &MCOp,
58 SmallVectorImpl<MCFixup> &
Fixups,
59 const MCSubtargetInfo &SubtargetInfo)
const;
61 unsigned getRiMemoryOpValue(
const MCInst &Inst,
unsigned OpNo,
62 SmallVectorImpl<MCFixup> &
Fixups,
63 const MCSubtargetInfo &SubtargetInfo)
const;
65 unsigned getRrMemoryOpValue(
const MCInst &Inst,
unsigned OpNo,
66 SmallVectorImpl<MCFixup> &
Fixups,
67 const MCSubtargetInfo &SubtargetInfo)
const;
69 unsigned getSplsOpValue(
const MCInst &Inst,
unsigned OpNo,
70 SmallVectorImpl<MCFixup> &
Fixups,
71 const MCSubtargetInfo &SubtargetInfo)
const;
74 SmallVectorImpl<MCFixup> &
Fixups,
75 const MCSubtargetInfo &SubtargetInfo)
const;
77 void encodeInstruction(
const MCInst &Inst, raw_ostream &Ostream,
78 SmallVectorImpl<MCFixup> &
Fixups,
79 const MCSubtargetInfo &SubtargetInfo)
const override;
81 unsigned adjustPqBitsRmAndRrm(
const MCInst &Inst,
unsigned Value,
82 const MCSubtargetInfo &STI)
const;
84 unsigned adjustPqBitsSpls(
const MCInst &Inst,
unsigned Value,
85 const MCSubtargetInfo &STI)
const;
91 if (isa<MCSymbolRefExpr>(Expr))
93 if (
const LanaiMCExpr *McExpr = dyn_cast<LanaiMCExpr>(Expr)) {
109 unsigned LanaiMCCodeEmitter::getMachineOpValue(
115 return static_cast<unsigned>(MCOp.
getImm());
124 Expr = BinaryExpr->
getLHS();
136 unsigned PBitShift,
unsigned QBitShift) {
143 Value &= ~(1 << PBitShift);
147 Value |= (1 << PBitShift);
151 "Expected register operand.");
152 Value &= ~(1 << QBitShift);
155 Value |= (1 << QBitShift);
161 LanaiMCCodeEmitter::adjustPqBitsRmAndRrm(
const MCInst &Inst,
unsigned Value,
167 LanaiMCCodeEmitter::adjustPqBitsSpls(
const MCInst &Inst,
unsigned Value,
172 void LanaiMCCodeEmitter::encodeInstruction(
176 unsigned Value = getBinaryCodeForInstr(Inst, Fixups, SubtargetInfo);
180 for (
int i = (4 - 1) * 8; i >= 0; i -= 8)
181 Ostream << static_cast<char>((Value >> i) & 0xff);
185 unsigned LanaiMCCodeEmitter::getRiMemoryOpValue(
193 assert(Op1.
isReg() &&
"First operand is not register.");
195 "Second operand is neither an immediate nor an expression.");
197 "Register immediate only supports addition operator");
202 "Constant value truncated (limited to 16-bit)");
204 Encoding |= (Op2.
getImm() & 0xffff);
207 Encoding |= (0x3 << 16);
209 Encoding |= (0x1 << 16);
212 getMachineOpValue(Inst, Op2, Fixups, SubtargetInfo);
217 unsigned LanaiMCCodeEmitter::getRrMemoryOpValue(
225 assert(Op1.
isReg() &&
"First operand is not register.");
227 assert(Op2.
isReg() &&
"Second operand is not register.");
230 assert(AluMCOp.
isImm() &&
"Third operator is not immediate.");
232 unsigned AluOp = AluMCOp.
getImm();
236 Encoding |= (0x3 << 8);
238 Encoding |= (0x1 << 8);
256 LanaiMCCodeEmitter::getSplsOpValue(
const MCInst &Inst,
unsigned OpNo,
264 assert(Op1.
isReg() &&
"First operand is not register.");
266 "Second operand is neither an immediate nor an expression.");
268 "Register immediate only supports addition operator");
273 "Constant value truncated (limited to 10-bit)");
275 Encoding |= (Op2.
getImm() & 0x3ff);
278 Encoding |= (0x3 << 10);
280 Encoding |= (0x1 << 10);
283 getMachineOpValue(Inst, Op2, Fixups, SubtargetInfo);
293 return getMachineOpValue(Inst, MCOp, Fixups, SubtargetInfo);
301 #include "LanaiGenMCCodeEmitter.inc" 309 return new LanaiMCCodeEmitter(InstrInfo, context);
This class represents lattice values for constants.
static bool modifiesOp(unsigned AluOp)
void push_back(const T &Elt)
static unsigned getAluOp(unsigned AluOp)
const MCExpr * getLHS() const
Get the left-hand side expression of the binary operator.
MCCodeEmitter * createLanaiMCCodeEmitter(const MCInstrInfo &MCII, const MCRegisterInfo &MRI, MCContext &Ctx)
static unsigned getLanaiRegisterNumbering(unsigned Reg)
constexpr bool isInt< 16 >(int64_t x)
static Lanai::Fixups FixupKind(const MCExpr *Expr)
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Base class for the full range of assembler expressions which are needed for parsing.
unsigned getReg() const
Returns the register number.
Context object for machine code objects.
const MCExpr * getExpr() const
Instances of this class represent a single low-level machine instruction.
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
static bool isPreOp(unsigned AluOp)
MCCodeEmitter - Generic instruction encoding interface.
Interface to description of machine instruction set.
MCFixupKind
Extensible enumeration to represent the type of a fixup.
Binary assembler expressions.
static MCFixup create(uint32_t Offset, const MCExpr *Value, MCFixupKind Kind, SMLoc Loc=SMLoc())
STATISTIC(MCNumEmitted, "Number of MC instructions emitted")
const MCOperand & getOperand(unsigned i) const
static bool isPostOp(unsigned AluOp)
Generic base class for all target subtargets.
References to labels and assigned expressions.
static unsigned encodeLanaiAluCode(unsigned AluOp)
static uint32_t getBranchTargetOpValue(const MCInst &MI, unsigned OpIdx, unsigned FixupKind, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI)
getBranchTargetOpValue - Helper function to get the branch target operand, which is either an immedia...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVM Value Representation.
This class implements an extremely fast bulk output stream that can only output to a stream...
static unsigned adjustPqBits(const MCInst &Inst, unsigned Value, unsigned PBitShift, unsigned QBitShift)
Instances of this class represent operands of the MCInst class.