31 #define DEBUG_TYPE "mccodeemitter" 33 #define GET_INSTRMAP_INFO 34 #include "AVRGenInstrInfo.inc" 35 #undef GET_INSTRMAP_INFO 68 AVRMCCodeEmitter::loadStorePostEncoder(
const MCInst &
MI,
unsigned EncodedValue,
69 const MCSubtargetInfo &STI)
const {
71 assert(MI.getOperand(0).isReg() && MI.getOperand(1).isReg() &&
72 "the load/store operands must be registers");
74 unsigned Opcode = MI.getOpcode();
77 bool IsRegX = MI.getOperand(0).getReg() == AVR::R27R26 ||
78 MI.getOperand(1).getReg() == AVR::R27R26;
80 bool IsPredec = Opcode == AVR::LDRdPtrPd || Opcode == AVR::STPtrPdRr;
81 bool IsPostinc = Opcode == AVR::LDRdPtrPi || Opcode == AVR::STPtrPiRr;
84 if (IsRegX || IsPredec || IsPostinc) {
85 EncodedValue |= (1 << 12);
91 template <AVR::Fixups Fixup>
93 AVRMCCodeEmitter::encodeRelCondBrTarget(
const MCInst &MI,
unsigned OpNo,
94 SmallVectorImpl<MCFixup> &
Fixups,
95 const MCSubtargetInfo &STI)
const {
96 const MCOperand &MO = MI.getOperand(OpNo);
108 auto target = MO.getImm();
113 unsigned AVRMCCodeEmitter::encodeLDSTPtrReg(
const MCInst &MI,
unsigned OpNo,
114 SmallVectorImpl<MCFixup> &Fixups,
115 const MCSubtargetInfo &STI)
const {
116 auto MO = MI.getOperand(OpNo);
121 switch (MO.getReg()) {
122 case AVR::R27R26:
return 0x03;
123 case AVR::R29R28:
return 0x02;
124 case AVR::R31R30:
return 0x00;
134 unsigned AVRMCCodeEmitter::encodeMemri(
const MCInst &MI,
unsigned OpNo,
135 SmallVectorImpl<MCFixup> &Fixups,
136 const MCSubtargetInfo &STI)
const {
137 auto RegOp = MI.getOperand(OpNo);
138 auto OffsetOp = MI.getOperand(OpNo + 1);
140 assert(RegOp.isReg() &&
"Expected register operand");
144 switch (RegOp.getReg()) {
157 if (OffsetOp.isImm()) {
158 OffsetBits = OffsetOp.getImm();
159 }
else if (OffsetOp.isExpr()) {
167 return (RegBit << 6) | OffsetBits;
170 unsigned AVRMCCodeEmitter::encodeComplement(
const MCInst &MI,
unsigned OpNo,
171 SmallVectorImpl<MCFixup> &Fixups,
172 const MCSubtargetInfo &STI)
const {
174 assert(MI.getOperand(OpNo).isImm());
176 auto Imm = MI.getOperand(OpNo).getImm();
180 template <AVR::Fixups Fixup,
unsigned Offset>
181 unsigned AVRMCCodeEmitter::encodeImm(
const MCInst &MI,
unsigned OpNo,
182 SmallVectorImpl<MCFixup> &Fixups,
183 const MCSubtargetInfo &STI)
const {
184 auto MO = MI.getOperand(OpNo);
187 if (isa<AVRMCExpr>(MO.getExpr())) {
192 return getExprOpValue(MO.getExpr(),
Fixups, STI);
205 unsigned AVRMCCodeEmitter::encodeCallTarget(
const MCInst &MI,
unsigned OpNo,
206 SmallVectorImpl<MCFixup> &Fixups,
207 const MCSubtargetInfo &STI)
const {
208 auto MO = MI.getOperand(OpNo);
218 auto Target = MO.getImm();
223 unsigned AVRMCCodeEmitter::getExprOpValue(
const MCExpr *Expr,
224 SmallVectorImpl<MCFixup> &Fixups,
225 const MCSubtargetInfo &STI)
const {
230 Expr =
static_cast<const MCBinaryExpr *
>(Expr)->getLHS();
231 Kind = Expr->getKind();
235 AVRMCExpr
const *AVRExpr = cast<AVRMCExpr>(Expr);
237 if (AVRExpr->evaluateAsConstant(Result)) {
250 unsigned AVRMCCodeEmitter::getMachineOpValue(
const MCInst &MI,
252 SmallVectorImpl<MCFixup> &Fixups,
253 const MCSubtargetInfo &STI)
const {
255 if (MO.isImm())
return static_cast<unsigned>(MO.getImm());
258 return static_cast<unsigned>(
APFloat(MO.getFPImm())
266 return getExprOpValue(MO.getExpr(),
Fixups, STI);
269 void AVRMCCodeEmitter::emitInstruction(uint64_t Val,
unsigned Size,
270 const MCSubtargetInfo &STI,
271 raw_ostream &OS)
const {
272 const uint16_t *Words =
reinterpret_cast<uint16_t
const *
>(&Val);
273 size_t WordCount = Size / 2;
275 for (int64_t i = WordCount - 1; i >= 0; --i) {
276 uint16_t
Word = Words[i];
278 OS << (uint8_t) ((Word & 0x00ff) >> 0);
279 OS << (uint8_t) ((Word & 0xff00) >> 8);
283 void AVRMCCodeEmitter::encodeInstruction(
const MCInst &MI, raw_ostream &OS,
284 SmallVectorImpl<MCFixup> &Fixups,
285 const MCSubtargetInfo &STI)
const {
286 const MCInstrDesc &Desc = MCII.
get(MI.getOpcode());
289 unsigned Size = Desc.getSize();
291 assert(Size > 0 &&
"Instruction size cannot be zero");
293 uint64_t BinaryOpCode = getBinaryCodeForInstr(MI, Fixups, STI);
294 emitInstruction(BinaryOpCode, Size, STI, OS);
298 const MCRegisterInfo &
MRI,
303 #include "AVRGenMCCodeEmitter.inc"
This class represents lattice values for constants.
MCCodeEmitter * createAVRMCCodeEmitter(const MCInstrInfo &MCII, const MCRegisterInfo &MRI, MCContext &Ctx)
Creates a machine code emitter for AVR.
static Lanai::Fixups FixupKind(const MCExpr *Expr)
support::ulittle32_t Word
unsigned const MachineRegisterInfo * MRI
MCFixupKind
Extensible enumeration to represent the type of a fixup.
This file declares a class to represent arbitrary precision floating point values and provide a varie...
static MCFixup create(uint32_t Offset, const MCExpr *Value, MCFixupKind Kind, SMLoc Loc=SMLoc())
AVRMCCodeEmitter(const MCInstrInfo &MCII, MCContext &Ctx)
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
PowerPC TLS Dynamic Call Fixup
void adjustBranchTarget(T &val)
Adjusts the value of a branch target.
uint16_t getEncodingValue(unsigned RegNo) const
Returns the encoding for RegNo.
const MCInstrDesc & get(unsigned Opcode) const
Return the machine instruction descriptor that corresponds to the specified instruction opcode...
References to labels and assigned expressions.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
const MCRegisterInfo * getRegisterInfo() const
A 22-bit fixup for the target of a CALL k or JMP k instruction.
Target specific expression.