Path: blob/main/contrib/llvm-project/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.h
35294 views
//===-- RISCVAsmBackend.h - RISC-V Assembler Backend ----------------------===//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//===----------------------------------------------------------------------===//78#ifndef LLVM_LIB_TARGET_RISCV_MCTARGETDESC_RISCVASMBACKEND_H9#define LLVM_LIB_TARGET_RISCV_MCTARGETDESC_RISCVASMBACKEND_H1011#include "MCTargetDesc/RISCVBaseInfo.h"12#include "MCTargetDesc/RISCVFixupKinds.h"13#include "MCTargetDesc/RISCVMCTargetDesc.h"14#include "llvm/MC/MCAsmBackend.h"15#include "llvm/MC/MCFixupKindInfo.h"16#include "llvm/MC/MCSubtargetInfo.h"1718namespace llvm {19class MCAssembler;20class MCObjectTargetWriter;21class raw_ostream;2223class RISCVAsmBackend : public MCAsmBackend {24const MCSubtargetInfo &STI;25uint8_t OSABI;26bool Is64Bit;27bool ForceRelocs = false;28const MCTargetOptions &TargetOptions;2930public:31RISCVAsmBackend(const MCSubtargetInfo &STI, uint8_t OSABI, bool Is64Bit,32const MCTargetOptions &Options)33: MCAsmBackend(llvm::endianness::little, RISCV::fixup_riscv_relax),34STI(STI), OSABI(OSABI), Is64Bit(Is64Bit), TargetOptions(Options) {35RISCVFeatures::validate(STI.getTargetTriple(), STI.getFeatureBits());36}37~RISCVAsmBackend() override = default;3839void setForceRelocs() { ForceRelocs = true; }4041// Return Size with extra Nop Bytes for alignment directive in code section.42bool shouldInsertExtraNopBytesForCodeAlign(const MCAlignFragment &AF,43unsigned &Size) override;4445// Insert target specific fixup type for alignment directive in code section.46bool shouldInsertFixupForCodeAlign(MCAssembler &Asm,47MCAlignFragment &AF) override;4849bool evaluateTargetFixup(const MCAssembler &Asm, const MCFixup &Fixup,50const MCFragment *DF, const MCValue &Target,51const MCSubtargetInfo *STI, uint64_t &Value,52bool &WasForced) override;5354bool handleAddSubRelocations(const MCAssembler &Asm, const MCFragment &F,55const MCFixup &Fixup, const MCValue &Target,56uint64_t &FixedValue) const override;5758void applyFixup(const MCAssembler &Asm, const MCFixup &Fixup,59const MCValue &Target, MutableArrayRef<char> Data,60uint64_t Value, bool IsResolved,61const MCSubtargetInfo *STI) const override;6263std::unique_ptr<MCObjectTargetWriter>64createObjectTargetWriter() const override;6566bool shouldForceRelocation(const MCAssembler &Asm, const MCFixup &Fixup,67const MCValue &Target,68const MCSubtargetInfo *STI) override;6970bool fixupNeedsRelaxationAdvanced(const MCAssembler &Asm,71const MCFixup &Fixup, bool Resolved,72uint64_t Value,73const MCRelaxableFragment *DF,74const bool WasForced) const override;7576unsigned getNumFixupKinds() const override {77return RISCV::NumTargetFixupKinds;78}7980std::optional<MCFixupKind> getFixupKind(StringRef Name) const override;8182const MCFixupKindInfo &getFixupKindInfo(MCFixupKind Kind) const override;8384bool mayNeedRelaxation(const MCInst &Inst,85const MCSubtargetInfo &STI) const override;86unsigned getRelaxedOpcode(unsigned Op) const;8788void relaxInstruction(MCInst &Inst,89const MCSubtargetInfo &STI) const override;9091bool relaxDwarfLineAddr(const MCAssembler &Asm, MCDwarfLineAddrFragment &DF,92bool &WasRelaxed) const override;93bool relaxDwarfCFA(const MCAssembler &Asm, MCDwarfCallFrameFragment &DF,94bool &WasRelaxed) const override;95std::pair<bool, bool> relaxLEB128(const MCAssembler &Asm, MCLEBFragment &LF,96int64_t &Value) const override;9798bool writeNopData(raw_ostream &OS, uint64_t Count,99const MCSubtargetInfo *STI) const override;100101const MCTargetOptions &getTargetOptions() const { return TargetOptions; }102};103}104105#endif106107108