34 #define DEBUG_TYPE "mccodeemitter" 36 STATISTIC(MCNumEmitted,
"Number of MC instructions emitted");
37 STATISTIC(MCNumFixups,
"Number of MC fixups created");
41 RISCVMCCodeEmitter(
const RISCVMCCodeEmitter &) =
delete;
42 void operator=(
const RISCVMCCodeEmitter &) =
delete;
48 : Ctx(ctx), MCII(MCII) {}
50 ~RISCVMCCodeEmitter()
override {}
66 uint64_t getBinaryCodeForInstr(
const MCInst &
MI,
76 unsigned getImmOpValueAsr1(
const MCInst &
MI,
unsigned OpNo,
80 unsigned getImmOpValue(
const MCInst &
MI,
unsigned OpNo,
89 return new RISCVMCCodeEmitter(Ctx, MCII);
105 if (MI.
getOpcode() == RISCV::PseudoTAIL) {
108 }
else if (MI.
getOpcode() == RISCV::PseudoCALLReg) {
125 Binary = getBinaryCodeForInstr(TmpInst, Fixups, STI);
134 Binary = getBinaryCodeForInstr(TmpInst, Fixups, STI);
146 "Expected thread pointer as second input to TP-relative add");
149 assert(SrcSymbol.isExpr() &&
150 "Expected expression as third input to TP-relative add");
154 "Expected tprel_add relocation on TP-relative symbol");
172 uint32_t Binary = getBinaryCodeForInstr(TmpInst, Fixups, STI);
183 if (MI.
getOpcode() == RISCV::PseudoCALLReg ||
186 expandFunctionCall(MI, OS, Fixups, STI);
191 if (MI.
getOpcode() == RISCV::PseudoAddTPRel) {
192 expandAddTPRel(MI, OS, Fixups, STI);
216 RISCVMCCodeEmitter::getMachineOpValue(
const MCInst &MI,
const MCOperand &MO,
221 return Ctx.getRegisterInfo()->getEncodingValue(MO.
getReg());
224 return static_cast<unsigned>(MO.
getImm());
231 RISCVMCCodeEmitter::getImmOpValueAsr1(
const MCInst &MI,
unsigned OpNo,
237 unsigned Res = MO.
getImm();
238 assert((Res & 1) == 0 &&
"LSB is non-zero");
242 return getImmOpValue(MI, OpNo, Fixups, STI);
245 unsigned RISCVMCCodeEmitter::getImmOpValue(
const MCInst &MI,
unsigned OpNo,
259 "getImmOpValue expects only expressions or immediates");
263 bool RelaxCandidate =
false;
265 const RISCVMCExpr *RVExpr = cast<RISCVMCExpr>(Expr);
278 "VK_RISCV_TPREL_ADD should not represent an instruction operand");
286 RelaxCandidate =
true;
290 RelaxCandidate =
true;
299 "VK_RISCV_PCREL_LO used with unexpected instruction format");
300 RelaxCandidate =
true;
304 RelaxCandidate =
true;
316 "VK_RISCV_TPREL_LO used with unexpected instruction format");
317 RelaxCandidate =
true;
321 RelaxCandidate =
true;
331 RelaxCandidate =
true;
335 RelaxCandidate =
true;
360 if (EnableRelax && RelaxCandidate) {
371 #include "RISCVGenMCCodeEmitter.inc"
This class represents lattice values for constants.
static MCOperand createExpr(const MCExpr *Val)
void push_back(const T &Elt)
Describe properties that are true of each instruction in the target description file.
VariantKind getKind() const
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.
MCCodeEmitter * createRISCVMCCodeEmitter(const MCInstrInfo &MCII, const MCRegisterInfo &MRI, MCContext &Ctx)
unsigned getReg() const
Returns the register number.
Context object for machine code objects.
Simple integer binary arithmetic operators.
const MCExpr * getExpr() const
MCInstBuilder & addOperand(const MCOperand &Op)
Add an operand.
Instances of this class represent a single low-level machine instruction.
static const MCConstantExpr * create(int64_t Value, MCContext &Ctx, bool PrintInHex=false)
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
void write(void *memory, value_type value, endianness endian)
Write a value to memory with a particular endianness.
MCInstBuilder & addReg(unsigned Reg)
Add a new register operand.
unsigned const MachineRegisterInfo * MRI
MCCodeEmitter - Generic instruction encoding interface.
Interface to description of machine instruction set.
MCFixupKind
Extensible enumeration to represent the type of a fixup.
MCInstBuilder & addImm(int64_t Val)
Add a new integer immediate operand.
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.
const MCOperand & getOperand(unsigned i) const
Generic base class for all target subtargets.
References to labels and assigned expressions.
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
unsigned getOpcode() const
Return the opcode number for this descriptor.
This class implements an extremely fast bulk output stream that can only output to a stream...
Target specific expression.
unsigned getOpcode() const
Instances of this class represent operands of the MCInst class.
Wrapper class representing virtual and physical registers.
unsigned getSize() const
Return the number of bytes in the encoding of this instruction, or zero if the encoding size cannot b...