1 | //===-- RISCVAsmBackend.h - RISC-V Assembler Backend ----------------------===// |
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 | #ifndef LLVM_LIB_TARGET_RISCV_MCTARGETDESC_RISCVASMBACKEND_H |
10 | #define LLVM_LIB_TARGET_RISCV_MCTARGETDESC_RISCVASMBACKEND_H |
11 | |
12 | #include "MCTargetDesc/RISCVBaseInfo.h" |
13 | #include "MCTargetDesc/RISCVFixupKinds.h" |
14 | #include "MCTargetDesc/RISCVMCTargetDesc.h" |
15 | #include "llvm/ADT/StringMap.h" |
16 | #include "llvm/MC/MCAsmBackend.h" |
17 | #include "llvm/MC/MCFixupKindInfo.h" |
18 | #include "llvm/MC/MCSubtargetInfo.h" |
19 | |
20 | namespace llvm { |
21 | class MCAssembler; |
22 | class MCObjectTargetWriter; |
23 | class raw_ostream; |
24 | |
25 | class RISCVAsmBackend : public MCAsmBackend { |
26 | const MCSubtargetInfo &STI; |
27 | uint8_t OSABI; |
28 | bool Is64Bit; |
29 | const MCTargetOptions &TargetOptions; |
30 | // Temporary symbol used to check whether a PC-relative fixup is resolved. |
31 | MCSymbol *PCRelTemp = nullptr; |
32 | |
33 | bool isPCRelFixupResolved(const MCSymbol *SymA, const MCFragment &F); |
34 | |
35 | StringMap<MCSymbol *> VendorSymbols; |
36 | |
37 | public: |
38 | RISCVAsmBackend(const MCSubtargetInfo &STI, uint8_t OSABI, bool Is64Bit, |
39 | const MCTargetOptions &Options); |
40 | ~RISCVAsmBackend() override = default; |
41 | |
42 | // Return Size with extra Nop Bytes for alignment directive in code section. |
43 | bool (const MCAlignFragment &AF, |
44 | unsigned &Size) override; |
45 | |
46 | // Insert target specific fixup type for alignment directive in code section. |
47 | bool shouldInsertFixupForCodeAlign(MCAssembler &Asm, |
48 | MCAlignFragment &AF) override; |
49 | |
50 | bool evaluateTargetFixup(const MCFixup &Fixup, const MCValue &Target, |
51 | uint64_t &Value) override; |
52 | |
53 | bool addReloc(const MCFragment &, const MCFixup &, const MCValue &, |
54 | uint64_t &FixedValue, bool IsResolved); |
55 | |
56 | void maybeAddVendorReloc(const MCFragment &, const MCFixup &); |
57 | |
58 | void applyFixup(const MCFragment &, const MCFixup &, const MCValue &Target, |
59 | MutableArrayRef<char> Data, uint64_t Value, |
60 | bool IsResolved) override; |
61 | |
62 | std::unique_ptr<MCObjectTargetWriter> |
63 | createObjectTargetWriter() const override; |
64 | |
65 | bool fixupNeedsRelaxationAdvanced(const MCFixup &, const MCValue &, uint64_t, |
66 | bool) const override; |
67 | |
68 | std::optional<MCFixupKind> getFixupKind(StringRef Name) const override; |
69 | |
70 | MCFixupKindInfo getFixupKindInfo(MCFixupKind Kind) const override; |
71 | |
72 | bool mayNeedRelaxation(const MCInst &Inst, |
73 | const MCSubtargetInfo &STI) const override; |
74 | |
75 | void relaxInstruction(MCInst &Inst, |
76 | const MCSubtargetInfo &STI) const override; |
77 | |
78 | bool relaxDwarfLineAddr(MCDwarfLineAddrFragment &DF, |
79 | bool &WasRelaxed) const override; |
80 | bool relaxDwarfCFA(MCDwarfCallFrameFragment &DF, |
81 | bool &WasRelaxed) const override; |
82 | std::pair<bool, bool> relaxLEB128(MCLEBFragment &LF, |
83 | int64_t &Value) const override; |
84 | |
85 | bool writeNopData(raw_ostream &OS, uint64_t Count, |
86 | const MCSubtargetInfo *STI) const override; |
87 | |
88 | const MCTargetOptions &getTargetOptions() const { return TargetOptions; } |
89 | }; |
90 | } |
91 | |
92 | #endif |
93 | |