30#define DEBUG_TYPE "mccodeemitter"
32#define GET_INSTRMAP_INFO
33#include "AVRGenInstrInfo.inc"
34#undef GET_INSTRMAP_INFO
78AVRMCCodeEmitter::loadStorePostEncoder(
const MCInst &
MI,
unsigned EncodedValue,
79 const MCSubtargetInfo &STI)
const {
81 assert(
MI.getOperand(0).isReg() &&
MI.getOperand(1).isReg() &&
82 "the load/store operands must be registers");
84 unsigned Opcode =
MI.getOpcode();
88 if (Opcode == AVR::LDRdPtrPd || Opcode == AVR::LDRdPtrPi ||
89 Opcode == AVR::LDRdPtr)
93 bool IsPredec = Opcode == AVR::LDRdPtrPd || Opcode == AVR::STPtrPdRr;
94 bool IsPostinc = Opcode == AVR::LDRdPtrPi || Opcode == AVR::STPtrPiRr;
95 if (
MI.getOperand(Idx).getReg() == AVR::R27R26 || IsPredec || IsPostinc)
96 EncodedValue |= (1 << 12);
99 switch (
MI.getOperand(Idx).getReg()) {
116template <AVR::Fixups Fixup>
118AVRMCCodeEmitter::encodeRelCondBrTarget(
const MCInst &
MI,
unsigned OpNo,
121 const MCOperand &MO =
MI.getOperand(OpNo);
132 auto target = MO.getImm();
141unsigned AVRMCCodeEmitter::encodeMemri(
const MCInst &
MI,
unsigned OpNo,
144 auto RegOp =
MI.getOperand(OpNo);
147 assert(RegOp.isReg() &&
"Expected register operand");
151 switch (RegOp.getReg().id()) {
153 Ctx.reportError(
MI.getLoc(),
"Expected either Y or Z register");
174 return (RegBit << 6) | OffsetBits;
177unsigned AVRMCCodeEmitter::encodeComplement(
const MCInst &
MI,
unsigned OpNo,
181 assert(
MI.getOperand(OpNo).isImm());
183 auto Imm =
MI.getOperand(OpNo).getImm();
187template <AVR::Fixups Fixup,
unsigned Offset>
188unsigned AVRMCCodeEmitter::encodeImm(
const MCInst &
MI,
unsigned OpNo,
191 auto MO =
MI.getOperand(OpNo);
199 return getExprOpValue(MO.getExpr(), Fixups, STI);
212unsigned AVRMCCodeEmitter::encodeCallTarget(
const MCInst &
MI,
unsigned OpNo,
215 auto MO =
MI.getOperand(OpNo);
225 auto Target = MO.getImm();
230unsigned AVRMCCodeEmitter::getExprOpValue(
const MCExpr *Expr,
237 Expr =
static_cast<const MCBinaryExpr *
>(Expr)->getLHS();
238 Kind = Expr->getKind();
244 if (AVRExpr->evaluateAsConstant(Result)) {
257unsigned AVRMCCodeEmitter::getMachineOpValue(
const MCInst &
MI,
262 return Ctx.getRegisterInfo()->getEncodingValue(MO.getReg());
264 return static_cast<unsigned>(MO.getImm());
272 return getExprOpValue(MO.getExpr(), Fixups, STI);
275void AVRMCCodeEmitter::encodeInstruction(
const MCInst &
MI,
279 const MCInstrDesc &
Desc = MCII.get(
MI.getOpcode());
284 assert(
Size > 0 &&
"Instruction size cannot be zero");
286 uint64_t BinaryOpCode = getBinaryCodeForInstr(
MI, Fixups, STI);
288 for (int64_t i =
Size / 2 - 1; i >= 0; --i) {
289 uint16_t
Word = (BinaryOpCode >> (i * 16)) & 0xFFFF;
298#include "AVRGenMCCodeEmitter.inc"
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file declares a class to represent arbitrary precision floating point values and provide a varie...
std::pair< Instruction::BinaryOps, Value * > OffsetOp
Find all possible pairs (BinOp, RHS) that BinOp V, RHS can be simplified.
PowerPC TLS Dynamic Call Fixup
This file defines the SmallVector class.
Writes AVR machine code to a stream.
MCCodeEmitter - Generic instruction encoding interface.
Context object for machine code objects.
Base class for the full range of assembler expressions which are needed for parsing.
@ SymbolRef
References to labels and assigned expressions.
@ Specifier
Expression with a relocation specifier.
@ Binary
Binary expressions.
static MCFixup create(uint32_t Offset, const MCExpr *Value, MCFixupKind Kind, bool PCRel=false)
Consider bit fields if we need more flags.
Instances of this class represent a single low-level machine instruction.
Interface to description of machine instruction set.
Instances of this class represent operands of the MCInst class.
Generic base class for all target subtargets.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
LLVM Value Representation.
#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.
@ fixup_7_pcrel
A 7-bit PC-relative fixup for the family of conditional branches which take 7-bit targets (BRNE,...
@ fixup_13_pcrel
A 12-bit PC-relative fixup for the family of branches which take 12-bit targets (RJMP,...
support::ulittle32_t Word
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.
uint16_t MCFixupKind
Extensible enumeration to represent the type of a fixup.
static Lanai::Fixups FixupKind(const MCExpr *Expr)
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
static void addFixup(SmallVectorImpl< MCFixup > &Fixups, uint32_t Offset, const MCExpr *Value, uint16_t Kind)
To bit_cast(const From &from) noexcept
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.