28 #define DEBUG_TYPE "mccodeemitter"
31 using namespace Hexagon;
33 STATISTIC(MCNumEmitted,
"Number of MC instructions emitted");
37 : MCT(aMCT), MCII(aMII), Addend(new
unsigned(0)),
39 CurrentIndex(new size_t(0)) {}
45 if (*CurrentIndex == 0) {
48 assert(*CurrentIndex != Last);
52 if (*CurrentIndex == 1) {
55 assert(*CurrentIndex != Last);
60 assert(*CurrentIndex == Last);
63 if(*CurrentIndex == Last)
83 verifyInstructionPredicates(HMI,
97 if (Consumer == Producer)
99 if (Consumer == Producer2)
102 if (Producer >= Hexagon::W0 && Producer <= Hexagon::W15)
103 if (Consumer >= Hexagon::V0 && Consumer <= Hexagon::V31)
104 return ((Consumer - Hexagon::V0) >> 1) == (Producer - Hexagon::W0);
118 "pseudo-instruction found");
137 if (MI.
getOpcode() >= Hexagon::DuplexIClass0 &&
138 MI.
getOpcode() <= Hexagon::DuplexIClassF) {
140 "Emitting duplex without duplex parse bits");
141 unsigned dupIClass = MI.
getOpcode() - Hexagon::DuplexIClass0;
145 Binary = ((dupIClass & 0xE) << (29 - 1)) | ((dupIClass & 0x1) << 13);
155 Binary |= subInstSlot0Bits | (subInstSlot1Bits << 16);
162 void raise_relocation_error(
unsigned bits,
unsigned kind) {
166 Stream <<
"Unrecognized relocation combination bits: " << bits
167 <<
" kind: " << kind;
209 for (
auto I = Insts.begin(),
N = Insts.end();
I !=
N; ++
I) {
210 if (
I->getInst() == &
MI) {
211 const MCInst &NextI = *(
I+1)->getInst();
219 raise_relocation_error(0, kind);
222 raise_relocation_error(0, kind);
229 case Hexagon::A2_tfrih:
250 raise_relocation_error(0, kind);
254 case Hexagon::A2_tfril:
275 raise_relocation_error(0, kind);
283 if (*ImpUses != Hexagon::GP)
295 raise_relocation_error(0, kind);
299 raise_relocation_error(0, kind);
309 bool isPCRel (
unsigned Kind) {
336 unsigned HexagonMCCodeEmitter::getExprOpValue(
const MCInst &MI,
343 if (isa<HexagonMCExpr>(ME))
346 if (ME->evaluateAsAbsolute(Value))
364 DEBUG(
dbgs() <<
"----------------------------------------\n");
368 DEBUG(
dbgs() <<
"Relocation bits: " << bits <<
"\n");
369 DEBUG(
dbgs() <<
"Addend: " << *Addend <<
"\n");
370 DEBUG(
dbgs() <<
"----------------------------------------\n");
374 raise_relocation_error(bits, kind);
417 raise_relocation_error(bits, kind);
439 raise_relocation_error(bits, kind);
474 raise_relocation_error(bits, kind);
485 if (*ImpUses != Hexagon::GP)
501 raise_relocation_error(bits, kind);
505 raise_relocation_error(bits, kind);
539 raise_relocation_error(bits, kind);
550 raise_relocation_error(bits, kind);
560 raise_relocation_error(bits, kind);
578 raise_relocation_error(bits, kind);
581 raise_relocation_error(bits, kind);
618 raise_relocation_error(bits, kind);
626 raise_relocation_error(bits, kind);
638 raise_relocation_error(bits, kind);
641 raise_relocation_error(bits, kind);
652 raise_relocation_error(bits, kind);
659 raise_relocation_error(bits, kind);
670 raise_relocation_error(bits, kind);
697 raise_relocation_error(bits, kind);
700 raise_relocation_error(bits, kind);
704 FixupKind = getFixupNoBits(MCII, MI, MO, kind);
708 MCExpr const *FixupExpression =
709 (*Addend > 0 && isPCRel(FixupKind))
726 size_t OperandNumber = ~0U;
732 assert((OperandNumber != ~0U) &&
"Operand not found");
740 unsigned SOffset = 0;
741 unsigned VOffset = 0;
746 auto i = Instructions.begin() + *CurrentIndex - 1;
748 assert(i != Instructions.begin() - 1 &&
"Couldn't find producer");
749 MCInst const &Inst = *i->getInst();
759 :
static_cast<unsigned>(Hexagon::NoRegister);
763 :
static_cast<unsigned>(Hexagon::NoRegister);
771 "Unpredicated consumer depending on predicated producer");
803 #define ENABLE_INSTR_PREDICATE_VERIFIER
804 #include "HexagonGenMCCodeEmitter.inc"
bool isDuplex(MCInstrInfo const &MCII, MCInst const &MCI)
void push_back(const T &Elt)
unsigned short getNewValueOp(MCInstrInfo const &MCII, MCInst const &MCI)
STATISTIC(NumFunctions,"Total number of functions")
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
bool mayStore() const
Return true if this instruction could possibly modify memory.
Describe properties that are true of each instruction in the target description file.
bool isBundle(MCInst const &MCI)
uint64_t getBinaryCodeForInstr(MCInst const &MI, SmallVectorImpl< MCFixup > &Fixups, MCSubtargetInfo const &STI) const
uint32_t parseBits(size_t Last, MCInst const &MCB, MCInst const &MCI) const
bool isSubInstruction(MCInst const &MCI)
bool isOuterLoop(MCInst const &MCI)
static Lanai::Fixups FixupKind(const MCExpr *Expr)
bool isNewValue(MCInstrInfo const &MCII, MCInst const &MCI)
Return whether the insn expects newly produced value.
Encode information on a single operation to perform on a byte sequence (e.g., an encoded instruction)...
MCCodeEmitter * createHexagonMCCodeEmitter(const MCInstrInfo &MCII, const MCRegisterInfo &MRI, MCContext &MCT)
bool isImmext(MCInst const &MCI)
void EncodeSingleInstruction(const MCInst &MI, raw_ostream &OS, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI, uint32_t Parse) const
EncodeSingleInstruction - Emit a single.
MCOperand const & getNewValueOperand2(MCInstrInfo const &MCII, MCInst const &MCI)
bool isBranch() const
Returns true if this is a conditional, unconditional, or indirect branch.
bool isCall() const
Return true if the instruction is a call.
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.
const MCInstrDesc HexagonInsts[]
Reg
All possible values of the reg field in the ModR/M byte.
Represent a reference to a symbol from inside an expression.
iterator_range< Hexagon::PacketIterator > bundleInstructions(MCInstrInfo const &MCII, MCInst const &MCI)
bool s27_2_reloc(MCExpr const &Expr)
StringRef getName(MCInstrInfo const &MCII, MCInst const &MCI)
Context object for machine code objects.
unsigned getReg() const
Returns the register number.
bool hasNewValue2(MCInstrInfo const &MCII, MCInst const &MCI)
Return whether the insn produces a second value.
static const MCBinaryExpr * createAdd(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Instances of this class represent a single low-level machine instruction.
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
void encodeInstruction(MCInst const &MI, raw_ostream &OS, SmallVectorImpl< MCFixup > &Fixups, MCSubtargetInfo const &STI) const override
EncodeInstruction - Emit the bundle.
const MCExpr * getExpr() const
Function Alias Analysis false
const MCExpr * getLHS() const
Get the left-hand side expression of the binary operator.
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.
MCExpr const & getExpr(MCExpr const &Expr)
Definition for classes that emit Hexagon machine code from MCInsts.
Binary assembler expressions.
static MCFixup create(uint32_t Offset, const MCExpr *Value, MCFixupKind Kind, SMLoc Loc=SMLoc())
unsigned SubregisterBit(unsigned Consumer, unsigned Producer, unsigned Producer2)
unsigned getOpcode() const
Return the opcode number for this descriptor.
void fixup(unsigned Size, const MCFixup &Fixup, uint64_t &Value, MCContext *Ctx=nullptr)
Adjusts a value to fix up the immediate of an LDI Rd, K instruction.
bool isVector(MCInstrInfo const &MCII, MCInst const &MCI)
Promote Memory to Register
bool mayLoad() const
Return true if this instruction could possibly read memory.
HexagonII::MemAccessSize getAccessSize(MCInstrInfo const &MCII, MCInst const &MCI)
const FeatureBitset & getFeatureBits() const
getFeatureBits - Return the feature bits.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
unsigned getOpcode() const
bool isPredicated(MCInstrInfo const &MCII, MCInst const &MCI)
HexagonMCCodeEmitter(MCInstrInfo const &aMII, MCContext &aMCT)
llvm_unreachable("Unknown RegBank!")
const MCRegisterInfo * getRegisterInfo() const
const MCExpr * getRHS() const
Get the right-hand side expression of the binary operator.
unsigned getNumOperands() const
MCSubtargetInfo - Generic base class for all target subtargets.
const MCInst * getInst() const
References to labels and assigned expressions.
MCInstrDesc const & getDesc(MCInstrInfo const &MCII, MCInst const &MCI)
const MCPhysReg * getImplicitUses() const
Return a list of registers that are potentially read by any instance of this machine instruction...
size_t bundleSize(MCInst const &MCI)
VariantKind getKind() const
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
bool isInnerLoop(MCInst const &MCI)
A raw_ostream that writes to an std::string.
#define HEXAGON_INSTR_SIZE
uint16_t getEncodingValue(unsigned RegNo) const
Returns the encoding for RegNo.
LLVM Value Representation.
static bool RegisterMatches(unsigned Consumer, unsigned Producer, unsigned Producer2)
This class implements an extremely fast bulk output stream that can only output to a stream...
unsigned getDuplexRegisterNumbering(unsigned Reg)
bool hasNewValue(MCInstrInfo const &MCII, MCInst const &MCI)
Return whether the insn produces a value.
unsigned getType(MCInstrInfo const &MCII, MCInst const &MCI)
Return the Hexagon ISA class for the insn.
unsigned getExtentAlignment(MCInstrInfo const &MCII, MCInst const &MCI)
Instances of this class represent operands of the MCInst class.
bool isPredicatedTrue(MCInstrInfo const &MCII, MCInst const &MCI)
static const MCConstantExpr * create(int64_t Value, MCContext &Ctx)
unsigned getMachineOpValue(MCInst const &MI, MCOperand const &MO, SmallVectorImpl< MCFixup > &Fixups, MCSubtargetInfo const &STI) const
Return binary encoding of operand.
const MCOperand & getOperand(unsigned i) const
MCOperand const & getNewValueOperand(MCInstrInfo const &MCII, MCInst const &MCI)
unsigned getExtentBits(MCInstrInfo const &MCII, MCInst const &MCI)