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/MCExpr.h"
21#include "llvm/MC/MCSection.h"
22#include "llvm/MC/MCSubtargetInfo.h"
23
24namespace llvm {
25
26class LoongArchAsmBackend : public MCAsmBackend {
27 const MCSubtargetInfo &STI;
28 uint8_t OSABI;
29 bool Is64Bit;
30 const MCTargetOptions &TargetOptions;
31 DenseMap<MCSection *, const MCSymbolRefExpr *> SecToAlignSym;
32 // Temporary symbol used to check whether a PC-relative fixup is resolved.
33 MCSymbol *PCRelTemp = nullptr;
34
35 bool isPCRelFixupResolved(const MCSymbol *SymA, const MCFragment &F);
36
37public:
38 LoongArchAsmBackend(const MCSubtargetInfo &STI, uint8_t OSABI, bool Is64Bit,
39 const MCTargetOptions &Options);
40
41 bool addReloc(const MCFragment &, const MCFixup &, const MCValue &,
42 uint64_t &FixedValue, bool IsResolved);
43
44 void applyFixup(const MCFragment &, const MCFixup &, const MCValue &Target,
45 uint8_t *Data, uint64_t Value, bool IsResolved) override;
46
47 std::optional<MCFixupKind> getFixupKind(StringRef Name) const override;
48
49 MCFixupKindInfo getFixupKindInfo(MCFixupKind Kind) const override;
50
51 bool relaxAlign(MCFragment &F, unsigned &Size) override;
52 bool relaxDwarfLineAddr(MCFragment &) const override;
53 bool relaxDwarfCFA(MCFragment &) const override;
54 std::pair<bool, bool> relaxLEB128(MCFragment &F,
55 int64_t &Value) const override;
56
57 bool writeNopData(raw_ostream &OS, uint64_t Count,
58 const MCSubtargetInfo *STI) const override;
59
60 std::unique_ptr<MCObjectTargetWriter>
61 createObjectTargetWriter() const override;
62 const MCTargetOptions &getTargetOptions() const { return TargetOptions; }
63 DenseMap<MCSection *, const MCSymbolRefExpr *> &getSecToAlignSym() {
64 return SecToAlignSym;
65 }
66};
67} // end namespace llvm
68
69#endif // LLVM_LIB_TARGET_LOONGARCH_MCTARGETDESC_LOONGARCHASMBACKEND_H
70