xref: /freebsd/contrib/llvm-project/llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.h (revision 5b56413d04e608379c9a306373554a8e4d321bc0)
1 //===-- ARMAsmBackend.h - ARM 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 #ifndef LLVM_LIB_TARGET_ARM_ARMASMBACKEND_H
10 #define LLVM_LIB_TARGET_ARM_ARMASMBACKEND_H
11 
12 #include "MCTargetDesc/ARMFixupKinds.h"
13 #include "MCTargetDesc/ARMMCTargetDesc.h"
14 #include "llvm/MC/MCAsmBackend.h"
15 #include "llvm/MC/MCSubtargetInfo.h"
16 #include "llvm/MC/TargetRegistry.h"
17 
18 namespace llvm {
19 
20 class ARMAsmBackend : public MCAsmBackend {
21   bool isThumbMode;    // Currently emitting Thumb code.
22 public:
23   ARMAsmBackend(const Target &T, bool isThumb, llvm::endianness Endian)
24       : MCAsmBackend(Endian), isThumbMode(isThumb) {}
25 
26   unsigned getNumFixupKinds() const override {
27     return ARM::NumTargetFixupKinds;
28   }
29 
30   bool hasNOP(const MCSubtargetInfo *STI) const {
31     return STI->hasFeature(ARM::HasV6T2Ops);
32   }
33 
34   std::optional<MCFixupKind> getFixupKind(StringRef Name) const override;
35 
36   const MCFixupKindInfo &getFixupKindInfo(MCFixupKind Kind) const override;
37 
38   bool shouldForceRelocation(const MCAssembler &Asm, const MCFixup &Fixup,
39                              const MCValue &Target,
40                              const MCSubtargetInfo *STI) override;
41 
42   unsigned adjustFixupValue(const MCAssembler &Asm, const MCFixup &Fixup,
43                             const MCValue &Target, uint64_t Value,
44                             bool IsResolved, MCContext &Ctx,
45                             const MCSubtargetInfo *STI) const;
46 
47   void applyFixup(const MCAssembler &Asm, const MCFixup &Fixup,
48                   const MCValue &Target, MutableArrayRef<char> Data,
49                   uint64_t Value, bool IsResolved,
50                   const MCSubtargetInfo *STI) const override;
51 
52   unsigned getRelaxedOpcode(unsigned Op, const MCSubtargetInfo &STI) const;
53 
54   bool mayNeedRelaxation(const MCInst &Inst,
55                          const MCSubtargetInfo &STI) const override;
56 
57   const char *reasonForFixupRelaxation(const MCFixup &Fixup,
58                                        uint64_t Value) const;
59 
60   bool fixupNeedsRelaxation(const MCFixup &Fixup, uint64_t Value,
61                             const MCRelaxableFragment *DF,
62                             const MCAsmLayout &Layout) const override;
63 
64   void relaxInstruction(MCInst &Inst,
65                         const MCSubtargetInfo &STI) const override;
66 
67   bool writeNopData(raw_ostream &OS, uint64_t Count,
68                     const MCSubtargetInfo *STI) const override;
69 
70   void handleAssemblerFlag(MCAssemblerFlag Flag) override;
71 
72   unsigned getPointerSize() const { return 4; }
73   bool isThumb() const { return isThumbMode; }
74   void setIsThumb(bool it) { isThumbMode = it; }
75 };
76 } // end namespace llvm
77 
78 #endif
79