1 //===-- LoongArchAsmBackend.h - LoongArch Assembler Backend ---*- C++ -*---===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 // 9 // This file defines the LoongArchAsmBackend class. 10 // 11 //===----------------------------------------------------------------------===// 12 13 #ifndef LLVM_LIB_TARGET_LOONGARCH_MCTARGETDESC_LOONGARCHASMBACKEND_H 14 #define LLVM_LIB_TARGET_LOONGARCH_MCTARGETDESC_LOONGARCHASMBACKEND_H 15 16 #include "MCTargetDesc/LoongArchBaseInfo.h" 17 #include "MCTargetDesc/LoongArchFixupKinds.h" 18 #include "MCTargetDesc/LoongArchMCTargetDesc.h" 19 #include "llvm/MC/MCAsmBackend.h" 20 #include "llvm/MC/MCFixupKindInfo.h" 21 #include "llvm/MC/MCSubtargetInfo.h" 22 23 namespace llvm { 24 25 class LoongArchAsmBackend : public MCAsmBackend { 26 const MCSubtargetInfo &STI; 27 uint8_t OSABI; 28 bool Is64Bit; 29 const MCTargetOptions &TargetOptions; 30 31 public: 32 LoongArchAsmBackend(const MCSubtargetInfo &STI, uint8_t OSABI, bool Is64Bit, 33 const MCTargetOptions &Options) 34 : MCAsmBackend(llvm::endianness::little, 35 LoongArch::fixup_loongarch_relax), 36 STI(STI), OSABI(OSABI), Is64Bit(Is64Bit), TargetOptions(Options) {} 37 ~LoongArchAsmBackend() override {} 38 39 bool handleAddSubRelocations(const MCAsmLayout &Layout, const MCFragment &F, 40 const MCFixup &Fixup, const MCValue &Target, 41 uint64_t &FixedValue) const override; 42 43 void applyFixup(const MCAssembler &Asm, const MCFixup &Fixup, 44 const MCValue &Target, MutableArrayRef<char> Data, 45 uint64_t Value, bool IsResolved, 46 const MCSubtargetInfo *STI) const override; 47 48 bool shouldForceRelocation(const MCAssembler &Asm, const MCFixup &Fixup, 49 const MCValue &Target, 50 const MCSubtargetInfo *STI) override; 51 52 bool fixupNeedsRelaxation(const MCFixup &Fixup, uint64_t Value, 53 const MCRelaxableFragment *DF, 54 const MCAsmLayout &Layout) const override { 55 return false; 56 } 57 58 unsigned getNumFixupKinds() const override { 59 return LoongArch::NumTargetFixupKinds; 60 } 61 62 std::optional<MCFixupKind> getFixupKind(StringRef Name) const override; 63 64 const MCFixupKindInfo &getFixupKindInfo(MCFixupKind Kind) const override; 65 66 void relaxInstruction(MCInst &Inst, 67 const MCSubtargetInfo &STI) const override {} 68 69 std::pair<bool, bool> relaxLEB128(MCLEBFragment &LF, MCAsmLayout &Layout, 70 int64_t &Value) const override; 71 72 bool writeNopData(raw_ostream &OS, uint64_t Count, 73 const MCSubtargetInfo *STI) const override; 74 75 std::unique_ptr<MCObjectTargetWriter> 76 createObjectTargetWriter() const override; 77 const MCTargetOptions &getTargetOptions() const { return TargetOptions; } 78 }; 79 } // end namespace llvm 80 81 #endif // LLVM_LIB_TARGET_LOONGARCH_MCTARGETDESC_LOONGARCHASMBACKEND_H 82