30#define DEBUG_TYPE "mccodeemitter"
32#define GET_INSTRMAP_INFO
33#include "AVRGenInstrInfo.inc"
34#undef GET_INSTRMAP_INFO
67AVRMCCodeEmitter::loadStorePostEncoder(
const MCInst &
MI,
unsigned EncodedValue,
68 const MCSubtargetInfo &STI)
const {
70 assert(
MI.getOperand(0).isReg() &&
MI.getOperand(1).isReg() &&
71 "the load/store operands must be registers");
73 unsigned Opcode =
MI.getOpcode();
77 if (Opcode == AVR::LDRdPtrPd || Opcode == AVR::LDRdPtrPi ||
78 Opcode == AVR::LDRdPtr)
82 bool IsPredec = Opcode == AVR::LDRdPtrPd || Opcode == AVR::STPtrPdRr;
83 bool IsPostinc = Opcode == AVR::LDRdPtrPi || Opcode == AVR::STPtrPiRr;
84 if (
MI.getOperand(
Idx).getReg() == AVR::R27R26 || IsPredec || IsPostinc)
85 EncodedValue |= (1 << 12);
88 switch (
MI.getOperand(
Idx).getReg()) {
105template <AVR::Fixups Fixup>
107AVRMCCodeEmitter::encodeRelCondBrTarget(
const MCInst &
MI,
unsigned OpNo,
108 SmallVectorImpl<MCFixup> &Fixups,
109 const MCSubtargetInfo &STI)
const {
110 const MCOperand &MO =
MI.getOperand(OpNo);
122 auto target = MO.getImm();
131unsigned AVRMCCodeEmitter::encodeMemri(
const MCInst &
MI,
unsigned OpNo,
132 SmallVectorImpl<MCFixup> &Fixups,
133 const MCSubtargetInfo &STI)
const {
134 auto RegOp =
MI.getOperand(OpNo);
135 auto OffsetOp =
MI.getOperand(OpNo + 1);
137 assert(RegOp.isReg() &&
"Expected register operand");
141 switch (RegOp.getReg().id()) {
143 Ctx.
reportError(
MI.getLoc(),
"Expected either Y or Z register");
155 if (OffsetOp.isImm()) {
156 OffsetBits = OffsetOp.getImm();
157 }
else if (OffsetOp.isExpr()) {
165 return (RegBit << 6) | OffsetBits;
168unsigned AVRMCCodeEmitter::encodeComplement(
const MCInst &
MI,
unsigned OpNo,
169 SmallVectorImpl<MCFixup> &Fixups,
170 const MCSubtargetInfo &STI)
const {
172 assert(
MI.getOperand(OpNo).isImm());
174 auto Imm =
MI.getOperand(OpNo).getImm();
178template <AVR::Fixups Fixup,
unsigned Offset>
179unsigned AVRMCCodeEmitter::encodeImm(
const MCInst &
MI,
unsigned OpNo,
180 SmallVectorImpl<MCFixup> &Fixups,
181 const MCSubtargetInfo &STI)
const {
182 auto MO =
MI.getOperand(OpNo);
185 if (isa<AVRMCExpr>(MO.getExpr())) {
190 return getExprOpValue(MO.getExpr(), Fixups, STI);
204unsigned AVRMCCodeEmitter::encodeCallTarget(
const MCInst &
MI,
unsigned OpNo,
205 SmallVectorImpl<MCFixup> &Fixups,
206 const MCSubtargetInfo &STI)
const {
207 auto MO =
MI.getOperand(OpNo);
217 auto Target = MO.getImm();
222unsigned AVRMCCodeEmitter::getExprOpValue(
const MCExpr *Expr,
223 SmallVectorImpl<MCFixup> &Fixups,
224 const MCSubtargetInfo &STI)
const {
229 Expr =
static_cast<const MCBinaryExpr *
>(Expr)->getLHS();
230 Kind = Expr->getKind();
234 AVRMCExpr
const *AVRExpr = cast<AVRMCExpr>(Expr);
236 if (AVRExpr->evaluateAsConstant(Result)) {
249unsigned AVRMCCodeEmitter::getMachineOpValue(
const MCInst &
MI,
251 SmallVectorImpl<MCFixup> &Fixups,
252 const MCSubtargetInfo &STI)
const {
256 return static_cast<unsigned>(MO.getImm());
259 return static_cast<unsigned>(bit_cast<double>(MO.getDFPImm()));
264 return getExprOpValue(MO.getExpr(), Fixups, STI);
267void AVRMCCodeEmitter::encodeInstruction(
const MCInst &
MI,
268 SmallVectorImpl<char> &CB,
269 SmallVectorImpl<MCFixup> &Fixups,
270 const MCSubtargetInfo &STI)
const {
271 const MCInstrDesc &
Desc = MCII.
get(
MI.getOpcode());
276 assert(
Size > 0 &&
"Instruction size cannot be zero");
278 uint64_t BinaryOpCode = getBinaryCodeForInstr(
MI, Fixups, STI);
280 for (int64_t i =
Size / 2 - 1; i >= 0; --i) {
281 uint16_t Word = (BinaryOpCode >> (i * 16)) & 0xFFFF;
287 return new AVRMCCodeEmitter(MCII, Ctx);
290#include "AVRGenMCCodeEmitter.inc"
This file declares a class to represent arbitrary precision floating point values and provide a varie...
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
PowerPC TLS Dynamic Call Fixup
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file defines the SmallVector class.
const MCRegisterInfo * getRegisterInfo() const
void reportError(SMLoc L, const Twine &Msg)
@ SymbolRef
References to labels and assigned expressions.
@ Target
Target specific expression.
@ Binary
Binary expressions.
static MCFixup create(uint32_t Offset, const MCExpr *Value, MCFixupKind Kind, SMLoc Loc=SMLoc())
const MCInstrDesc & get(unsigned Opcode) const
Return the machine instruction descriptor that corresponds to the specified instruction opcode.
uint16_t getEncodingValue(MCRegister Reg) const
Returns the encoding for Reg.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
void adjustBranchTarget(T &val)
Adjusts the value of a branch target.
@ fixup_call
A 22-bit fixup for the target of a CALL k or JMP k instruction.
void write(void *memory, value_type value, endianness endian)
Write a value to memory with a particular endianness.
This is an optimization pass for GlobalISel generic memory operations.
MCCodeEmitter * createAVRMCCodeEmitter(const MCInstrInfo &MCII, MCContext &Ctx)
Creates a machine code emitter for AVR.
MCFixupKind
Extensible enumeration to represent the type of a fixup.