32 #define DEBUG_TYPE "mccodeemitter" 34 STATISTIC(MCNumEmitted,
"Number of MC instructions emitted");
40 class LanaiMCCodeEmitter :
public MCCodeEmitter {
42 LanaiMCCodeEmitter(
const MCInstrInfo &MCII, MCContext &
C) {}
43 LanaiMCCodeEmitter(
const LanaiMCCodeEmitter &) =
delete;
44 void operator=(
const LanaiMCCodeEmitter &) =
delete;
45 ~LanaiMCCodeEmitter()
override =
default;
52 uint64_t getBinaryCodeForInstr(
const MCInst &Inst,
53 SmallVectorImpl<MCFixup> &
Fixups,
54 const MCSubtargetInfo &SubtargetInfo)
const;
58 unsigned getMachineOpValue(
const MCInst &Inst,
const MCOperand &MCOp,
59 SmallVectorImpl<MCFixup> &
Fixups,
60 const MCSubtargetInfo &SubtargetInfo)
const;
62 unsigned getRiMemoryOpValue(
const MCInst &Inst,
unsigned OpNo,
63 SmallVectorImpl<MCFixup> &
Fixups,
64 const MCSubtargetInfo &SubtargetInfo)
const;
66 unsigned getRrMemoryOpValue(
const MCInst &Inst,
unsigned OpNo,
67 SmallVectorImpl<MCFixup> &
Fixups,
68 const MCSubtargetInfo &SubtargetInfo)
const;
70 unsigned getSplsOpValue(
const MCInst &Inst,
unsigned OpNo,
71 SmallVectorImpl<MCFixup> &
Fixups,
72 const MCSubtargetInfo &SubtargetInfo)
const;
75 SmallVectorImpl<MCFixup> &
Fixups,
76 const MCSubtargetInfo &SubtargetInfo)
const;
78 void encodeInstruction(
const MCInst &Inst, raw_ostream &Ostream,
79 SmallVectorImpl<MCFixup> &
Fixups,
80 const MCSubtargetInfo &SubtargetInfo)
const override;
82 unsigned adjustPqBitsRmAndRrm(
const MCInst &Inst,
unsigned Value,
83 const MCSubtargetInfo &STI)
const;
85 unsigned adjustPqBitsSpls(
const MCInst &Inst,
unsigned Value,
86 const MCSubtargetInfo &STI)
const;
92 if (isa<MCSymbolRefExpr>(Expr))
94 if (
const LanaiMCExpr *McExpr = dyn_cast<LanaiMCExpr>(Expr)) {
110 unsigned LanaiMCCodeEmitter::getMachineOpValue(
116 return static_cast<unsigned>(MCOp.
getImm());
125 Expr = BinaryExpr->
getLHS();
137 unsigned PBitShift,
unsigned QBitShift) {
144 Value &= ~(1 << PBitShift);
148 Value |= (1 << PBitShift);
152 "Expected register operand.");
153 Value &= ~(1 << QBitShift);
156 Value |= (1 << QBitShift);
162 LanaiMCCodeEmitter::adjustPqBitsRmAndRrm(
const MCInst &Inst,
unsigned Value,
168 LanaiMCCodeEmitter::adjustPqBitsSpls(
const MCInst &Inst,
unsigned Value,
173 void LanaiMCCodeEmitter::encodeInstruction(
177 unsigned Value = getBinaryCodeForInstr(Inst, Fixups, SubtargetInfo);
181 for (
int i = (4 - 1) * 8; i >= 0; i -= 8)
182 Ostream << static_cast<char>((Value >> i) & 0xff);
186 unsigned LanaiMCCodeEmitter::getRiMemoryOpValue(
194 assert(Op1.
isReg() &&
"First operand is not register.");
196 "Second operand is neither an immediate nor an expression.");
198 "Register immediate only supports addition operator");
203 "Constant value truncated (limited to 16-bit)");
205 Encoding |= (Op2.
getImm() & 0xffff);
208 Encoding |= (0x3 << 16);
210 Encoding |= (0x1 << 16);
213 getMachineOpValue(Inst, Op2, Fixups, SubtargetInfo);
218 unsigned LanaiMCCodeEmitter::getRrMemoryOpValue(
226 assert(Op1.
isReg() &&
"First operand is not register.");
228 assert(Op2.
isReg() &&
"Second operand is not register.");
231 assert(AluMCOp.
isImm() &&
"Third operator is not immediate.");
233 unsigned AluOp = AluMCOp.
getImm();
237 Encoding |= (0x3 << 8);
239 Encoding |= (0x1 << 8);
257 LanaiMCCodeEmitter::getSplsOpValue(
const MCInst &Inst,
unsigned OpNo,
265 assert(Op1.
isReg() &&
"First operand is not register.");
267 "Second operand is neither an immediate nor an expression.");
269 "Register immediate only supports addition operator");
274 "Constant value truncated (limited to 10-bit)");
276 Encoding |= (Op2.
getImm() & 0x3ff);
279 Encoding |= (0x3 << 10);
281 Encoding |= (0x1 << 10);
284 getMachineOpValue(Inst, Op2, Fixups, SubtargetInfo);
294 return getMachineOpValue(Inst, MCOp, Fixups, SubtargetInfo);
302 #include "LanaiGenMCCodeEmitter.inc" 310 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.