Path: blob/main/contrib/llvm-project/llvm/lib/Target/Mips/MCTargetDesc/MipsMCCodeEmitter.h
35294 views
//===- MipsMCCodeEmitter.h - Convert Mips Code to Machine Code --*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// This file defines the MipsMCCodeEmitter class.9//10//===----------------------------------------------------------------------===//1112#ifndef LLVM_LIB_TARGET_MIPS_MCTARGETDESC_MIPSMCCODEEMITTER_H13#define LLVM_LIB_TARGET_MIPS_MCTARGETDESC_MIPSMCCODEEMITTER_H1415#include "llvm/MC/MCCodeEmitter.h"16#include <cstdint>1718namespace llvm {1920class MCContext;21class MCExpr;22class MCFixup;23class MCInst;24class MCInstrInfo;25class MCOperand;26class MCSubtargetInfo;27class raw_ostream;2829class MipsMCCodeEmitter : public MCCodeEmitter {30const MCInstrInfo &MCII;31MCContext &Ctx;32bool IsLittleEndian;3334bool isMicroMips(const MCSubtargetInfo &STI) const;35bool isMips32r6(const MCSubtargetInfo &STI) const;3637public:38MipsMCCodeEmitter(const MCInstrInfo &mcii, MCContext &Ctx_, bool IsLittle)39: MCII(mcii), Ctx(Ctx_), IsLittleEndian(IsLittle) {}40MipsMCCodeEmitter(const MipsMCCodeEmitter &) = delete;41MipsMCCodeEmitter &operator=(const MipsMCCodeEmitter &) = delete;42~MipsMCCodeEmitter() override = default;4344void EmitByte(unsigned char C, raw_ostream &OS) const;4546void encodeInstruction(const MCInst &MI, SmallVectorImpl<char> &CB,47SmallVectorImpl<MCFixup> &Fixups,48const MCSubtargetInfo &STI) const override;4950// getBinaryCodeForInstr - TableGen'erated function for getting the51// binary encoding for an instruction.52uint64_t getBinaryCodeForInstr(const MCInst &MI,53SmallVectorImpl<MCFixup> &Fixups,54const MCSubtargetInfo &STI) const;5556// getJumpTargetOpValue - Return binary encoding of the jump57// target operand. If the machine operand requires relocation,58// record the relocation and return zero.59unsigned getJumpTargetOpValue(const MCInst &MI, unsigned OpNo,60SmallVectorImpl<MCFixup> &Fixups,61const MCSubtargetInfo &STI) const;6263// getBranchJumpOpValueMM - Return binary encoding of the microMIPS jump64// target operand. If the machine operand requires relocation,65// record the relocation and return zero.66unsigned getJumpTargetOpValueMM(const MCInst &MI, unsigned OpNo,67SmallVectorImpl<MCFixup> &Fixups,68const MCSubtargetInfo &STI) const;6970// getUImm5Lsl2Encoding - Return binary encoding of the microMIPS jump71// target operand.72unsigned getUImm5Lsl2Encoding(const MCInst &MI, unsigned OpNo,73SmallVectorImpl<MCFixup> &Fixups,74const MCSubtargetInfo &STI) const;7576unsigned getSImm3Lsa2Value(const MCInst &MI, unsigned OpNo,77SmallVectorImpl<MCFixup> &Fixups,78const MCSubtargetInfo &STI) const;7980unsigned getUImm6Lsl2Encoding(const MCInst &MI, unsigned OpNo,81SmallVectorImpl<MCFixup> &Fixups,82const MCSubtargetInfo &STI) const;8384// getSImm9AddiuspValue - Return binary encoding of the microMIPS addiusp85// instruction immediate operand.86unsigned getSImm9AddiuspValue(const MCInst &MI, unsigned OpNo,87SmallVectorImpl<MCFixup> &Fixups,88const MCSubtargetInfo &STI) const;8990// getBranchTargetOpValue - Return binary encoding of the branch91// target operand. If the machine operand requires relocation,92// record the relocation and return zero.93unsigned getBranchTargetOpValue(const MCInst &MI, unsigned OpNo,94SmallVectorImpl<MCFixup> &Fixups,95const MCSubtargetInfo &STI) const;9697// getBranchTargetOpValue1SImm16 - Return binary encoding of the branch98// target operand. If the machine operand requires relocation,99// record the relocation and return zero.100unsigned getBranchTargetOpValue1SImm16(const MCInst &MI, unsigned OpNo,101SmallVectorImpl<MCFixup> &Fixups,102const MCSubtargetInfo &STI) const;103104// getBranchTargetOpValueMMR6 - Return binary encoding of the branch105// target operand. If the machine operand requires relocation,106// record the relocation and return zero.107unsigned getBranchTargetOpValueMMR6(const MCInst &MI, unsigned OpNo,108SmallVectorImpl<MCFixup> &Fixups,109const MCSubtargetInfo &STI) const;110111// getBranchTargetOpValueLsl2MMR6 - Return binary encoding of the branch112// target operand. If the machine operand requires relocation,113// record the relocation and return zero.114unsigned getBranchTargetOpValueLsl2MMR6(const MCInst &MI, unsigned OpNo,115SmallVectorImpl<MCFixup> &Fixups,116const MCSubtargetInfo &STI) const;117118// getBranchTarget7OpValue - Return binary encoding of the microMIPS branch119// target operand. If the machine operand requires relocation,120// record the relocation and return zero.121unsigned getBranchTarget7OpValueMM(const MCInst &MI, unsigned OpNo,122SmallVectorImpl<MCFixup> &Fixups,123const MCSubtargetInfo &STI) const;124125// getBranchTargetOpValueMMPC10 - Return binary encoding of the microMIPS126// 10-bit branch target operand. If the machine operand requires relocation,127// record the relocation and return zero.128unsigned getBranchTargetOpValueMMPC10(const MCInst &MI, unsigned OpNo,129SmallVectorImpl<MCFixup> &Fixups,130const MCSubtargetInfo &STI) const;131132// getBranchTargetOpValue - Return binary encoding of the microMIPS branch133// target operand. If the machine operand requires relocation,134// record the relocation and return zero.135unsigned getBranchTargetOpValueMM(const MCInst &MI, unsigned OpNo,136SmallVectorImpl<MCFixup> &Fixups,137const MCSubtargetInfo &STI) const;138139// getBranchTarget21OpValue - Return binary encoding of the branch140// offset operand. If the machine operand requires relocation,141// record the relocation and return zero.142unsigned getBranchTarget21OpValue(const MCInst &MI, unsigned OpNo,143SmallVectorImpl<MCFixup> &Fixups,144const MCSubtargetInfo &STI) const;145146// getBranchTarget21OpValueMM - Return binary encoding of the branch147// offset operand for microMIPS. If the machine operand requires148// relocation,record the relocation and return zero.149unsigned getBranchTarget21OpValueMM(const MCInst &MI, unsigned OpNo,150SmallVectorImpl<MCFixup> &Fixups,151const MCSubtargetInfo &STI) const;152153// getBranchTarget26OpValue - Return binary encoding of the branch154// offset operand. If the machine operand requires relocation,155// record the relocation and return zero.156unsigned getBranchTarget26OpValue(const MCInst &MI, unsigned OpNo,157SmallVectorImpl<MCFixup> &Fixups,158const MCSubtargetInfo &STI) const;159160// getBranchTarget26OpValueMM - Return binary encoding of the branch161// offset operand. If the machine operand requires relocation,162// record the relocation and return zero.163unsigned getBranchTarget26OpValueMM(const MCInst &MI, unsigned OpNo,164SmallVectorImpl<MCFixup> &Fixups,165const MCSubtargetInfo &STI) const;166167// getJumpOffset16OpValue - Return binary encoding of the jump168// offset operand. If the machine operand requires relocation,169// record the relocation and return zero.170unsigned getJumpOffset16OpValue(const MCInst &MI, unsigned OpNo,171SmallVectorImpl<MCFixup> &Fixups,172const MCSubtargetInfo &STI) const;173174// getMachineOpValue - Return binary encoding of operand. If the machin175// operand requires relocation, record the relocation and return zero.176unsigned getMachineOpValue(const MCInst &MI, const MCOperand &MO,177SmallVectorImpl<MCFixup> &Fixups,178const MCSubtargetInfo &STI) const;179180unsigned getMSAMemEncoding(const MCInst &MI, unsigned OpNo,181SmallVectorImpl<MCFixup> &Fixups,182const MCSubtargetInfo &STI) const;183184template <unsigned ShiftAmount = 0>185unsigned getMemEncoding(const MCInst &MI, unsigned OpNo,186SmallVectorImpl<MCFixup> &Fixups,187const MCSubtargetInfo &STI) const;188unsigned getMemEncodingMMImm4(const MCInst &MI, unsigned OpNo,189SmallVectorImpl<MCFixup> &Fixups,190const MCSubtargetInfo &STI) const;191unsigned getMemEncodingMMImm4Lsl1(const MCInst &MI, unsigned OpNo,192SmallVectorImpl<MCFixup> &Fixups,193const MCSubtargetInfo &STI) const;194unsigned getMemEncodingMMImm4Lsl2(const MCInst &MI, unsigned OpNo,195SmallVectorImpl<MCFixup> &Fixups,196const MCSubtargetInfo &STI) const;197unsigned getMemEncodingMMSPImm5Lsl2(const MCInst &MI, unsigned OpNo,198SmallVectorImpl<MCFixup> &Fixups,199const MCSubtargetInfo &STI) const;200unsigned getMemEncodingMMGPImm7Lsl2(const MCInst &MI, unsigned OpNo,201SmallVectorImpl<MCFixup> &Fixups,202const MCSubtargetInfo &STI) const;203unsigned getMemEncodingMMImm9(const MCInst &MI, unsigned OpNo,204SmallVectorImpl<MCFixup> &Fixups,205const MCSubtargetInfo &STI) const;206unsigned getMemEncodingMMImm11(const MCInst &MI, unsigned OpNo,207SmallVectorImpl<MCFixup> &Fixups,208const MCSubtargetInfo &STI) const;209unsigned getMemEncodingMMImm12(const MCInst &MI, unsigned OpNo,210SmallVectorImpl<MCFixup> &Fixups,211const MCSubtargetInfo &STI) const;212unsigned getMemEncodingMMImm16(const MCInst &MI, unsigned OpNo,213SmallVectorImpl<MCFixup> &Fixups,214const MCSubtargetInfo &STI) const;215unsigned getMemEncodingMMImm4sp(const MCInst &MI, unsigned OpNo,216SmallVectorImpl<MCFixup> &Fixups,217const MCSubtargetInfo &STI) const;218unsigned getSizeInsEncoding(const MCInst &MI, unsigned OpNo,219SmallVectorImpl<MCFixup> &Fixups,220const MCSubtargetInfo &STI) const;221222/// Subtract Offset then encode as a N-bit unsigned integer.223template <unsigned Bits, int Offset>224unsigned getUImmWithOffsetEncoding(const MCInst &MI, unsigned OpNo,225SmallVectorImpl<MCFixup> &Fixups,226const MCSubtargetInfo &STI) const;227228unsigned getSimm19Lsl2Encoding(const MCInst &MI, unsigned OpNo,229SmallVectorImpl<MCFixup> &Fixups,230const MCSubtargetInfo &STI) const;231232unsigned getSimm18Lsl3Encoding(const MCInst &MI, unsigned OpNo,233SmallVectorImpl<MCFixup> &Fixups,234const MCSubtargetInfo &STI) const;235236unsigned getUImm3Mod8Encoding(const MCInst &MI, unsigned OpNo,237SmallVectorImpl<MCFixup> &Fixups,238const MCSubtargetInfo &STI) const;239unsigned getUImm4AndValue(const MCInst &MI, unsigned OpNo,240SmallVectorImpl<MCFixup> &Fixups,241const MCSubtargetInfo &STI) const;242243unsigned getMovePRegPairOpValue(const MCInst &MI, unsigned OpNo,244SmallVectorImpl<MCFixup> &Fixups,245const MCSubtargetInfo &STI) const;246unsigned getMovePRegSingleOpValue(const MCInst &MI, unsigned OpNo,247SmallVectorImpl<MCFixup> &Fixups,248const MCSubtargetInfo &STI) const;249250unsigned getSimm23Lsl2Encoding(const MCInst &MI, unsigned OpNo,251SmallVectorImpl<MCFixup> &Fixups,252const MCSubtargetInfo &STI) const;253254unsigned getExprOpValue(const MCExpr *Expr, SmallVectorImpl<MCFixup> &Fixups,255const MCSubtargetInfo &STI) const;256257unsigned getRegisterListOpValue(const MCInst &MI, unsigned OpNo,258SmallVectorImpl<MCFixup> &Fixups,259const MCSubtargetInfo &STI) const;260261unsigned getRegisterListOpValue16(const MCInst &MI, unsigned OpNo,262SmallVectorImpl<MCFixup> &Fixups,263const MCSubtargetInfo &STI) const;264265private:266void LowerCompactBranch(MCInst& Inst) const;267};268269} // end namespace llvm270271#endif // LLVM_LIB_TARGET_MIPS_MCTARGETDESC_MIPSMCCODEEMITTER_H272273274