1 //===- HexagonMCCodeEmitter.h - Hexagon Target Descriptions -----*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
11 /// Definition for classes that emit Hexagon machine code from MCInsts
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_LIB_TARGET_HEXAGON_MCTARGETDESC_HEXAGONMCCODEEMITTER_H
16 #define LLVM_LIB_TARGET_HEXAGON_MCTARGETDESC_HEXAGONMCCODEEMITTER_H
18 #include "MCTargetDesc/HexagonFixupKinds.h"
19 #include "llvm/MC/MCCodeEmitter.h"
20 #include "llvm/MC/MCExpr.h"
21 #include "llvm/MC/SubtargetFeature.h"
32 class MCSubtargetInfo;
35 class HexagonMCCodeEmitter : public MCCodeEmitter {
37 MCInstrInfo const &MCII;
39 // A mutable state of the emitter when encoding bundles and duplexes.
42 bool Extended = false;
43 bool SubInst1 = false;
44 const MCInst *Bundle = nullptr;
47 mutable EmitterState State;
50 HexagonMCCodeEmitter(MCInstrInfo const &MII, MCContext &MCT)
51 : MCT(MCT), MCII(MII) {}
53 void encodeInstruction(MCInst const &MI, raw_ostream &OS,
54 SmallVectorImpl<MCFixup> &Fixups,
55 MCSubtargetInfo const &STI) const override;
57 void EncodeSingleInstruction(const MCInst &MI, raw_ostream &OS,
58 SmallVectorImpl<MCFixup> &Fixups,
59 const MCSubtargetInfo &STI,
60 uint32_t Parse) const;
62 // TableGen'erated function for getting the
63 // binary encoding for an instruction.
64 uint64_t getBinaryCodeForInstr(MCInst const &MI,
65 SmallVectorImpl<MCFixup> &Fixups,
66 MCSubtargetInfo const &STI) const;
68 /// Return binary encoding of operand.
69 unsigned getMachineOpValue(MCInst const &MI, MCOperand const &MO,
70 SmallVectorImpl<MCFixup> &Fixups,
71 MCSubtargetInfo const &STI) const;
74 // helper routine for getMachineOpValue()
75 unsigned getExprOpValue(const MCInst &MI, const MCOperand &MO,
76 const MCExpr *ME, SmallVectorImpl<MCFixup> &Fixups,
77 const MCSubtargetInfo &STI) const;
79 Hexagon::Fixups getFixupNoBits(MCInstrInfo const &MCII, const MCInst &MI,
81 const MCSymbolRefExpr::VariantKind Kind) const;
83 // Return parse bits for instruction `MCI' inside bundle `MCB'
84 uint32_t parseBits(size_t Last, MCInst const &MCB, MCInst const &MCI) const;
86 uint64_t computeAvailableFeatures(const FeatureBitset &FB) const;
87 void verifyInstructionPredicates(const MCInst &MI,
88 uint64_t AvailableFeatures) const;
91 } // end namespace llvm
93 #endif // LLVM_LIB_TARGET_HEXAGON_MCTARGETDESC_HEXAGONMCCODEEMITTER_H