Path: blob/main/contrib/llvm-project/llvm/lib/Target/CSKY/MCTargetDesc/CSKYMCCodeEmitter.h
35294 views
//===-- CSKYMCCodeEmitter.cpp - CSKY Code Emitter interface ---------------===//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 implements the CSKYMCCodeEmitter class.9//10//===----------------------------------------------------------------------===//1112#ifndef LLVM_LIB_TARGET_CSKY_MCTARGETDESC_CSKYMCCODEEMITTER_H13#define LLVM_LIB_TARGET_CSKY_MCTARGETDESC_CSKYMCCODEEMITTER_H1415#include "MCTargetDesc/CSKYFixupKinds.h"16#include "MCTargetDesc/CSKYMCExpr.h"17#include "llvm/MC/MCCodeEmitter.h"18#include "llvm/MC/MCContext.h"1920namespace llvm {2122class MCInstrInfo;2324class CSKYMCCodeEmitter : public MCCodeEmitter {25MCContext &Ctx;26const MCInstrInfo &MII;2728public:29CSKYMCCodeEmitter(MCContext &Ctx, const MCInstrInfo &MII)30: Ctx(Ctx), MII(MII) {}3132~CSKYMCCodeEmitter() {}3334void encodeInstruction(const MCInst &Inst, SmallVectorImpl<char> &CB,35SmallVectorImpl<MCFixup> &Fixups,36const MCSubtargetInfo &STI) const override;3738// Generated by tablegen.39uint64_t getBinaryCodeForInstr(const MCInst &MI,40SmallVectorImpl<MCFixup> &Fixups,41const MCSubtargetInfo &STI) const;4243// Default encoding method used by tablegen.44unsigned getMachineOpValue(const MCInst &MI, const MCOperand &MO,45SmallVectorImpl<MCFixup> &Fixups,46const MCSubtargetInfo &STI) const;4748template <int shift = 0>49unsigned getImmOpValue(const MCInst &MI, unsigned Idx,50SmallVectorImpl<MCFixup> &Fixups,51const MCSubtargetInfo &STI) const {52const MCOperand &MO = MI.getOperand(Idx);53if (MO.isImm())54return (MO.getImm() >> shift);5556assert(MO.isExpr() && "Unexpected MO type.");5758MCFixupKind Kind = getTargetFixup(MO.getExpr());59Fixups.push_back(MCFixup::create(0, MO.getExpr(), Kind, MI.getLoc()));60return 0;61}6263unsigned getRegSeqImmOpValue(const MCInst &MI, unsigned Idx,64SmallVectorImpl<MCFixup> &Fixups,65const MCSubtargetInfo &STI) const;6667unsigned getRegisterSeqOpValue(const MCInst &MI, unsigned Op,68SmallVectorImpl<MCFixup> &Fixups,69const MCSubtargetInfo &STI) const;7071unsigned getOImmOpValue(const MCInst &MI, unsigned Idx,72SmallVectorImpl<MCFixup> &Fixups,73const MCSubtargetInfo &STI) const;7475unsigned getImmOpValueIDLY(const MCInst &MI, unsigned Idx,76SmallVectorImpl<MCFixup> &Fixups,77const MCSubtargetInfo &STI) const;7879unsigned getImmJMPIX(const MCInst &MI, unsigned Idx,80SmallVectorImpl<MCFixup> &Fixups,81const MCSubtargetInfo &STI) const;8283unsigned getImmOpValueMSBSize(const MCInst &MI, unsigned Idx,84SmallVectorImpl<MCFixup> &Fixups,85const MCSubtargetInfo &STI) const;8687unsigned getImmShiftOpValue(const MCInst &MI, unsigned Idx,88SmallVectorImpl<MCFixup> &Fixups,89const MCSubtargetInfo &STI) const {90const MCOperand &MO = MI.getOperand(Idx);91assert(MO.isImm() && "Unexpected MO type.");92return 1 << MO.getImm();93}9495MCFixupKind getTargetFixup(const MCExpr *Expr) const;9697template <llvm::CSKY::Fixups FIXUP>98unsigned getBranchSymbolOpValue(const MCInst &MI, unsigned Idx,99SmallVectorImpl<MCFixup> &Fixups,100const MCSubtargetInfo &STI) const {101const MCOperand &MO = MI.getOperand(Idx);102103if (MO.isImm())104return MO.getImm() >> 1;105106assert(MO.isExpr() && "Unexpected MO type.");107108MCFixupKind Kind = MCFixupKind(FIXUP);109if (MO.getExpr()->getKind() == MCExpr::Target)110Kind = getTargetFixup(MO.getExpr());111112Fixups.push_back(MCFixup::create(0, MO.getExpr(), Kind, MI.getLoc()));113return 0;114}115116template <llvm::CSKY::Fixups FIXUP>117unsigned getConstpoolSymbolOpValue(const MCInst &MI, unsigned Idx,118SmallVectorImpl<MCFixup> &Fixups,119const MCSubtargetInfo &STI) const {120const MCOperand &MO = MI.getOperand(Idx);121assert(MO.isExpr() && "Unexpected MO type.");122123MCFixupKind Kind = MCFixupKind(FIXUP);124if (MO.getExpr()->getKind() == MCExpr::Target)125Kind = getTargetFixup(MO.getExpr());126127Fixups.push_back(MCFixup::create(0, MO.getExpr(), Kind, MI.getLoc()));128return 0;129}130131template <llvm::CSKY::Fixups FIXUP>132unsigned getDataSymbolOpValue(const MCInst &MI, unsigned Idx,133SmallVectorImpl<MCFixup> &Fixups,134const MCSubtargetInfo &STI) const {135const MCOperand &MO = MI.getOperand(Idx);136assert(MO.isExpr() && "Unexpected MO type.");137138MCFixupKind Kind = MCFixupKind(FIXUP);139if (MO.getExpr()->getKind() == MCExpr::Target)140Kind = getTargetFixup(MO.getExpr());141142Fixups.push_back(MCFixup::create(0, MO.getExpr(), Kind, MI.getLoc()));143return 0;144}145146unsigned getCallSymbolOpValue(const MCInst &MI, unsigned Idx,147SmallVectorImpl<MCFixup> &Fixups,148const MCSubtargetInfo &STI) const {149const MCOperand &MO = MI.getOperand(Idx);150assert(MO.isExpr() && "Unexpected MO type.");151152MCFixupKind Kind = MCFixupKind(CSKY::fixup_csky_pcrel_imm26_scale2);153if (MO.getExpr()->getKind() == MCExpr::Target)154Kind = getTargetFixup(MO.getExpr());155156Fixups.push_back(MCFixup::create(0, MO.getExpr(), Kind, MI.getLoc()));157return 0;158}159160unsigned getBareSymbolOpValue(const MCInst &MI, unsigned Idx,161SmallVectorImpl<MCFixup> &Fixups,162const MCSubtargetInfo &STI) const {163const MCOperand &MO = MI.getOperand(Idx);164assert(MO.isExpr() && "Unexpected MO type.");165166MCFixupKind Kind = MCFixupKind(CSKY::fixup_csky_pcrel_imm18_scale2);167if (MO.getExpr()->getKind() == MCExpr::Target)168Kind = getTargetFixup(MO.getExpr());169170Fixups.push_back(MCFixup::create(0, MO.getExpr(), Kind, MI.getLoc()));171return 0;172}173174void expandJBTF(const MCInst &MI, SmallVectorImpl<char> &CB,175SmallVectorImpl<MCFixup> &Fixups,176const MCSubtargetInfo &STI) const;177void expandNEG(const MCInst &MI, SmallVectorImpl<char> &CB,178SmallVectorImpl<MCFixup> &Fixups,179const MCSubtargetInfo &STI) const;180void expandRSUBI(const MCInst &MI, SmallVectorImpl<char> &CB,181SmallVectorImpl<MCFixup> &Fixups,182const MCSubtargetInfo &STI) const;183};184185} // namespace llvm186187#endif // LLVM_LIB_TARGET_CSKY_MCTARGETDESC_CSKYMCCODEEMITTER_H188189190