37 #define DEBUG_TYPE "mccodeemitter" 39 STATISTIC(MCNumEmitted,
"Number of MC instructions emitted.");
40 STATISTIC(MCNumFixups,
"Number of MC fixups created.");
50 : Ctx(ctx), MCII(mcii) {}
51 AArch64MCCodeEmitter(
const AArch64MCCodeEmitter &) =
delete;
52 void operator=(
const AArch64MCCodeEmitter &) =
delete;
53 ~AArch64MCCodeEmitter()
override =
default;
57 uint64_t getBinaryCodeForInstr(
const MCInst &
MI,
70 template <u
int32_t FixupKind>
173 unsigned fixMOVZ(
const MCInst &
MI,
unsigned EncodedValue,
180 unsigned fixMulHigh(
const MCInst &
MI,
unsigned EncodedValue,
183 template<
int hasRs,
int hasRt2>
unsigned 184 fixLoadStoreExclusive(
const MCInst &
MI,
unsigned EncodedValue,
187 unsigned fixOneOperandFPComparison(
const MCInst &
MI,
unsigned EncodedValue,
191 uint64_t computeAvailableFeatures(
const FeatureBitset &FB)
const;
192 void verifyInstructionPredicates(
const MCInst &
MI,
193 uint64_t AvailableFeatures)
const;
205 return Ctx.getRegisterInfo()->getEncodingValue(MO.
getReg());
207 assert(MO.
isImm() &&
"did not expect relocated expression");
208 return static_cast<unsigned>(MO.
getImm());
211 template<
unsigned FixupKind>
uint32_t 212 AArch64MCCodeEmitter::getLdStUImm12OpValue(
const MCInst &MI,
unsigned OpIdx,
219 ImmVal = static_cast<uint32_t>(MO.
getImm());
221 assert(MO.
isExpr() &&
"unable to encode load/store imm operand");
233 AArch64MCCodeEmitter::getAdrLabelOpValue(
const MCInst &MI,
unsigned OpIdx,
259 AArch64MCCodeEmitter::getAddSubImmOpValue(
const MCInst &MI,
unsigned OpIdx,
266 "unexpected shift type for add/sub immediate");
268 assert((ShiftVal == 0 || ShiftVal == 12) &&
269 "unexpected shift value for add/sub immediate");
271 return MO.
getImm() | (ShiftVal == 0 ? 0 : (1 << ShiftVal));
283 if (
const AArch64MCExpr *A64E = dyn_cast<AArch64MCExpr>(Expr)) {
290 return ShiftVal == 0 ? 0 : (1 << ShiftVal);
295 uint32_t AArch64MCCodeEmitter::getCondBranchTargetOpValue(
317 AArch64MCCodeEmitter::getLoadLiteralOpValue(
const MCInst &MI,
unsigned OpIdx,
337 AArch64MCCodeEmitter::getMemExtendOpValue(
const MCInst &MI,
unsigned OpIdx,
342 return (SignExtend << 1) | DoShift;
346 AArch64MCCodeEmitter::getMoveWideImmOpValue(
const MCInst &MI,
unsigned OpIdx,
353 assert(MO.
isExpr() &&
"Unexpected movz/movk immediate");
365 uint32_t AArch64MCCodeEmitter::getTestBranchTargetOpValue(
415 AArch64MCCodeEmitter::getVecShifterOpValue(
const MCInst &MI,
unsigned OpIdx,
419 assert(MO.
isImm() &&
"Expected an immediate value for the shift amount!");
439 uint32_t AArch64MCCodeEmitter::getFixedPointScaleOpValue(
443 assert(MO.
isImm() &&
"Expected an immediate value for the scale amount!");
448 AArch64MCCodeEmitter::getVecShiftR64OpValue(
const MCInst &MI,
unsigned OpIdx,
452 assert(MO.
isImm() &&
"Expected an immediate value for the scale amount!");
457 AArch64MCCodeEmitter::getVecShiftR32OpValue(
const MCInst &MI,
unsigned OpIdx,
461 assert(MO.
isImm() &&
"Expected an immediate value for the scale amount!");
466 AArch64MCCodeEmitter::getVecShiftR16OpValue(
const MCInst &MI,
unsigned OpIdx,
470 assert(MO.
isImm() &&
"Expected an immediate value for the scale amount!");
475 AArch64MCCodeEmitter::getVecShiftR8OpValue(
const MCInst &MI,
unsigned OpIdx,
479 assert(MO.
isImm() &&
"Expected an immediate value for the scale amount!");
484 AArch64MCCodeEmitter::getVecShiftL64OpValue(
const MCInst &MI,
unsigned OpIdx,
488 assert(MO.
isImm() &&
"Expected an immediate value for the scale amount!");
493 AArch64MCCodeEmitter::getVecShiftL32OpValue(
const MCInst &MI,
unsigned OpIdx,
497 assert(MO.
isImm() &&
"Expected an immediate value for the scale amount!");
502 AArch64MCCodeEmitter::getVecShiftL16OpValue(
const MCInst &MI,
unsigned OpIdx,
506 assert(MO.
isImm() &&
"Expected an immediate value for the scale amount!");
511 AArch64MCCodeEmitter::getVecShiftL8OpValue(
const MCInst &MI,
unsigned OpIdx,
515 assert(MO.
isImm() &&
"Expected an immediate value for the scale amount!");
520 AArch64MCCodeEmitter::getImm8OptLsl(
const MCInst &MI,
unsigned OpIdx,
526 "Unexpected shift type for imm8_opt_lsl immediate.");
529 assert((ShiftVal == 0 || ShiftVal == 8) &&
530 "Unexpected shift value for imm8_opt_lsl immediate.");
534 return (Immediate & 0xff) | (ShiftVal == 0 ? 0 : (1 << ShiftVal));
538 AArch64MCCodeEmitter::getSVEIncDecImm(
const MCInst &MI,
unsigned OpIdx,
542 assert(MO.
isImm() &&
"Expected an immediate value!");
549 uint32_t AArch64MCCodeEmitter::getMoveVecShifterOpValue(
554 "Expected an immediate value for the move shift amount!");
556 assert((ShiftVal == 8 || ShiftVal == 16) &&
"Invalid shift amount!");
557 return ShiftVal == 8 ? 0 : 1;
560 unsigned AArch64MCCodeEmitter::fixMOVZ(
const MCInst &MI,
unsigned EncodedValue,
569 if (UImm16MO.
isImm())
581 return EncodedValue & ~(1u << 30);
588 return EncodedValue & ~(1u << 30);
594 verifyInstructionPredicates(MI,
597 if (MI.
getOpcode() == AArch64::TLSDESCCALL) {
604 }
else if (MI.
getOpcode() == AArch64::CompilerBarrier) {
609 uint64_t Binary = getBinaryCodeForInstr(MI, Fixups, STI);
615 AArch64MCCodeEmitter::fixMulHigh(
const MCInst &MI,
616 unsigned EncodedValue,
620 EncodedValue |= 0x1f << 10;
624 template<
int hasRs,
int hasRt2>
unsigned 625 AArch64MCCodeEmitter::fixLoadStoreExclusive(
const MCInst &MI,
626 unsigned EncodedValue,
628 if (!hasRs) EncodedValue |= 0x001F0000;
629 if (!hasRt2) EncodedValue |= 0x00007C00;
634 unsigned AArch64MCCodeEmitter::fixOneOperandFPComparison(
638 EncodedValue &= ~(0x1f << 16);
642 #define ENABLE_INSTR_PREDICATE_VERIFIER 643 #include "AArch64GenMCCodeEmitter.inc" 648 return new AArch64MCCodeEmitter(MCII, Ctx);
VariantKind getKind() const
Get the kind of this expression.
This class represents lattice values for constants.
void push_back(const T &Elt)
STATISTIC(NumFunctions, "Total number of functions")
static Lanai::Fixups FixupKind(const MCExpr *Expr)
const FeatureBitset & getFeatureBits() const
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 unsigned getShiftValue(unsigned Imm)
getShiftValue - Extract the shift value.
unsigned const MachineRegisterInfo * MRI
Container class for subtarget features.
MCCodeEmitter - Generic instruction encoding interface.
Interface to description of machine instruction set.
MCFixupKind
Extensible enumeration to represent the type of a fixup.
static MCFixup create(uint32_t Offset, const MCExpr *Value, MCFixupKind Kind, SMLoc Loc=SMLoc())
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
PowerPC TLS Dynamic Call Fixup
MCCodeEmitter * createAArch64MCCodeEmitter(const MCInstrInfo &MCII, const MCRegisterInfo &MRI, MCContext &Ctx)
const MCOperand & getOperand(unsigned i) const
static AArch64_AM::ShiftExtendType getShiftType(unsigned Imm)
getShiftType - Extract the shift type.
Generic base class for all target subtargets.
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())
This class implements an extremely fast bulk output stream that can only output to a stream...
unsigned getOpcode() const
Instances of this class represent operands of the MCInst class.