xref: /freebsd/contrib/llvm-project/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.h (revision 59c8e88e72633afbc47a4ace0d2170d00d51f7dc)
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(support::little), STI(STI), OSABI(OSABI), Is64Bit(Is64Bit),
35         TargetOptions(Options) {}
36   ~LoongArchAsmBackend() override {}
37 
38   void applyFixup(const MCAssembler &Asm, const MCFixup &Fixup,
39                   const MCValue &Target, MutableArrayRef<char> Data,
40                   uint64_t Value, bool IsResolved,
41                   const MCSubtargetInfo *STI) const override;
42 
43   bool shouldForceRelocation(const MCAssembler &Asm, const MCFixup &Fixup,
44                              const MCValue &Target) override;
45 
46   bool fixupNeedsRelaxation(const MCFixup &Fixup, uint64_t Value,
47                             const MCRelaxableFragment *DF,
48                             const MCAsmLayout &Layout) const override {
49     return false;
50   }
51 
52   unsigned getNumFixupKinds() const override {
53     return LoongArch::NumTargetFixupKinds;
54   }
55 
56   std::optional<MCFixupKind> getFixupKind(StringRef Name) const override;
57 
58   const MCFixupKindInfo &getFixupKindInfo(MCFixupKind Kind) const override;
59 
60   void relaxInstruction(MCInst &Inst,
61                         const MCSubtargetInfo &STI) const override {}
62 
63   bool writeNopData(raw_ostream &OS, uint64_t Count,
64                     const MCSubtargetInfo *STI) const override;
65 
66   std::unique_ptr<MCObjectTargetWriter>
67   createObjectTargetWriter() const override;
68   const MCTargetOptions &getTargetOptions() const { return TargetOptions; }
69 };
70 } // end namespace llvm
71 
72 #endif // LLVM_LIB_TARGET_LOONGARCH_MCTARGETDESC_LOONGARCHASMBACKEND_H
73