30#define DEBUG_TYPE "mccodeemitter"
40 : MCII(MCII), Ctx(Ctx) {}
42 ~SystemZMCCodeEmitter()
override =
default;
65 template <SystemZ::FixupKind Kind>
72 template <SystemZ::FixupKind Kind>
84 unsigned Kind, int64_t
Offset,
90 return getPCRelEncoding(
MI, OpNum, Fixups,
96 return getPCRelEncoding(
MI, OpNum, Fixups,
102 return getPCRelEncoding(
MI, OpNum, Fixups,
108 return getPCRelEncoding(
MI, OpNum, Fixups,
114 return getPCRelEncoding(
MI, OpNum, Fixups,
120 return getPCRelEncoding(
MI, OpNum, Fixups,
126 return getPCRelEncoding(
MI, OpNum, Fixups,
138void SystemZMCCodeEmitter::encodeInstruction(
const MCInst &
MI,
142 uint64_t
Bits = getBinaryCodeForInstr(
MI, Fixups, STI);
145 unsigned ShiftValue = (
Size * 8) - 8;
146 for (
unsigned I = 0;
I !=
Size; ++
I) {
147 CB.
push_back(uint8_t(Bits >> ShiftValue));
152uint64_t SystemZMCCodeEmitter::
153getMachineOpValue(
const MCInst &
MI,
const MCOperand &MO,
154 SmallVectorImpl<MCFixup> &Fixups,
155 const MCSubtargetInfo &STI)
const {
161 return static_cast<uint64_t
>(MO.
getImm());
165template <SystemZ::FixupKind Kind>
166uint64_t SystemZMCCodeEmitter::getImmOpValue(
const MCInst &
MI,
unsigned OpNum,
167 SmallVectorImpl<MCFixup> &Fixups,
168 const MCSubtargetInfo &STI)
const {
169 const MCOperand &MO =
MI.getOperand(OpNum);
171 return static_cast<uint64_t
>(MO.
getImm());
173 unsigned MIBitSize = MCII.
get(
MI.getOpcode()).
getSize() * 8;
174 uint32_t RawBitOffset = getOperandBitOffset(
MI, OpNum, STI);
177 uint32_t BitOffset = MIBitSize - RawBitOffset - OpBitSize;
184template <SystemZ::FixupKind Kind>
186SystemZMCCodeEmitter::getLenEncoding(
const MCInst &
MI,
unsigned OpNum,
187 SmallVectorImpl<MCFixup> &Fixups,
188 const MCSubtargetInfo &STI)
const {
189 return getImmOpValue<Kind>(
MI, OpNum, Fixups, STI) - 1;
193SystemZMCCodeEmitter::getPCRelEncoding(
const MCInst &
MI,
unsigned OpNum,
194 SmallVectorImpl<MCFixup> &Fixups,
195 unsigned Kind, int64_t
Offset,
196 bool AllowTLS)
const {
197 SMLoc Loc =
MI.getLoc();
198 const MCOperand &MO =
MI.getOperand(OpNum);
216 if (AllowTLS && OpNum + 1 <
MI.getNumOperands()) {
217 const MCOperand &MOTLS =
MI.getOperand(OpNum + 1);
223#define GET_OPERAND_BIT_OFFSET
224#include "SystemZGenMCCodeEmitter.inc"
228 return new SystemZMCCodeEmitter(MCII, Ctx);
static void addFixup(SmallVectorImpl< MCFixup > &Fixups, uint32_t Offset, const MCExpr *Value, uint16_t Kind, bool PCRel=false)
This file defines the SmallVector class.
static const MCBinaryExpr * createAdd(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx, SMLoc Loc=SMLoc())
MCCodeEmitter - Generic instruction encoding interface.
static LLVM_ABI const MCConstantExpr * create(int64_t Value, MCContext &Ctx, bool PrintInHex=false, unsigned SizeInBytes=0)
Context object for machine code objects.
const MCRegisterInfo * getRegisterInfo() const
Base class for the full range of assembler expressions which are needed for parsing.
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.
unsigned getSize() const
Return the number of bytes in the encoding of this instruction, or zero if the encoding size cannot b...
Interface to description of machine instruction set.
const MCInstrDesc & get(unsigned Opcode) const
Return the machine instruction descriptor that corresponds to the specified instruction opcode.
Instances of this class represent operands of the MCInst class.
MCRegister getReg() const
Returns the register number.
const MCExpr * getExpr() const
uint16_t getEncodingValue(MCRegister Reg) const
Returns the encoding for Reg.
Generic base class for all target subtargets.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void push_back(const T &Elt)
LLVM Value Representation.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
static const MCFixupKindInfo MCFixupKindInfos[SystemZ::NumTargetFixupKinds]
This is an optimization pass for GlobalISel generic memory operations.
static void addFixup(SmallVectorImpl< MCFixup > &Fixups, uint32_t Offset, const MCExpr *Value, uint16_t Kind)
MCCodeEmitter * createSystemZMCCodeEmitter(const MCInstrInfo &MCII, MCContext &Ctx)
uint8_t TargetSize
The number of bits written by this fixup.