blob: 67722a5e5b649ba8d65dd5023636b0a960f58f3e [file] [log] [blame]
Joe Abbey8e72eb72014-09-16 09:18:23 +00001//===-- ARMAsmBackend.h - ARM Assembler Backend -----------------*- C++ -*-===//
2//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// 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
Joe Abbey8e72eb72014-09-16 09:18:23 +00006//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_LIB_TARGET_ARM_ARMASMBACKEND_H
10#define LLVM_LIB_TARGET_ARM_ARMASMBACKEND_H
11
12#include "MCTargetDesc/ARMFixupKinds.h"
Benjamin Kramerb32a5042016-01-27 19:29:42 +000013#include "MCTargetDesc/ARMMCTargetDesc.h"
Joe Abbey8e72eb72014-09-16 09:18:23 +000014#include "llvm/MC/MCAsmBackend.h"
15#include "llvm/MC/MCSubtargetInfo.h"
Benjamin Kramerb32a5042016-01-27 19:29:42 +000016#include "llvm/Support/TargetRegistry.h"
Joe Abbey8e72eb72014-09-16 09:18:23 +000017
Benjamin Kramerb32a5042016-01-27 19:29:42 +000018namespace llvm {
Joe Abbey8e72eb72014-09-16 09:18:23 +000019
20class ARMAsmBackend : public MCAsmBackend {
Peter Smith57f661b2018-06-06 09:40:06 +000021 // The STI from the target triple the MCAsmBackend was instantiated with
22 // note that MCFragments may have a different local STI that should be
23 // used in preference.
Alex Bradbury46db78b2018-01-03 13:46:21 +000024 const MCSubtargetInfo &STI;
Joe Abbey8e72eb72014-09-16 09:18:23 +000025 bool isThumbMode; // Currently emitting Thumb code.
Joe Abbey8e72eb72014-09-16 09:18:23 +000026public:
Peter Collingbourne571a3302018-05-21 17:57:19 +000027 ARMAsmBackend(const Target &T, const MCSubtargetInfo &STI,
28 support::endianness Endian)
29 : MCAsmBackend(Endian), STI(STI),
30 isThumbMode(STI.getTargetTriple().isThumb()) {}
Joe Abbey8e72eb72014-09-16 09:18:23 +000031
Joe Abbey8e72eb72014-09-16 09:18:23 +000032 unsigned getNumFixupKinds() const override {
33 return ARM::NumTargetFixupKinds;
34 }
35
Peter Smith57f661b2018-06-06 09:40:06 +000036 // FIXME: this should be calculated per fragment as the STI may be
37 // different.
Alex Bradbury46db78b2018-01-03 13:46:21 +000038 bool hasNOP() const { return STI.getFeatureBits()[ARM::HasV6T2Ops]; }
Joe Abbey8e72eb72014-09-16 09:18:23 +000039
Fangrui Song43ca0e92019-05-17 02:51:54 +000040 Optional<MCFixupKind> getFixupKind(StringRef Name) const override;
41
Joe Abbey8e72eb72014-09-16 09:18:23 +000042 const MCFixupKindInfo &getFixupKindInfo(MCFixupKind Kind) const override;
43
Rafael Espindola76287ab2017-06-30 22:47:27 +000044 bool shouldForceRelocation(const MCAssembler &Asm, const MCFixup &Fixup,
45 const MCValue &Target) override;
Joe Abbey8e72eb72014-09-16 09:18:23 +000046
Rafael Espindola801b42d2017-06-23 22:52:36 +000047 unsigned adjustFixupValue(const MCAssembler &Asm, const MCFixup &Fixup,
Rafael Espindola1beb7022017-07-11 23:18:25 +000048 const MCValue &Target, uint64_t Value,
Peter Smith57f661b2018-06-06 09:40:06 +000049 bool IsResolved, MCContext &Ctx,
50 const MCSubtargetInfo *STI) const;
Tim Northover8d67b8e2015-10-02 18:07:18 +000051
Rafael Espindola801b42d2017-06-23 22:52:36 +000052 void applyFixup(const MCAssembler &Asm, const MCFixup &Fixup,
53 const MCValue &Target, MutableArrayRef<char> Data,
Peter Smith57f661b2018-06-06 09:40:06 +000054 uint64_t Value, bool IsResolved,
55 const MCSubtargetInfo *STI) const override;
Joe Abbey8e72eb72014-09-16 09:18:23 +000056
Peter Smith57f661b2018-06-06 09:40:06 +000057 unsigned getRelaxedOpcode(unsigned Op, const MCSubtargetInfo &STI) const;
Tim Northover42335572015-04-06 18:44:42 +000058
Peter Smith57f661b2018-06-06 09:40:06 +000059 bool mayNeedRelaxation(const MCInst &Inst,
60 const MCSubtargetInfo &STI) const override;
Joe Abbey8e72eb72014-09-16 09:18:23 +000061
Tim Northover8d67b8e2015-10-02 18:07:18 +000062 const char *reasonForFixupRelaxation(const MCFixup &Fixup,
63 uint64_t Value) const;
64
Joe Abbey8e72eb72014-09-16 09:18:23 +000065 bool fixupNeedsRelaxation(const MCFixup &Fixup, uint64_t Value,
66 const MCRelaxableFragment *DF,
67 const MCAsmLayout &Layout) const override;
68
Nirav Dave86030622016-07-11 14:23:53 +000069 void relaxInstruction(const MCInst &Inst, const MCSubtargetInfo &STI,
70 MCInst &Res) const override;
Joe Abbey8e72eb72014-09-16 09:18:23 +000071
Peter Collingbourne571a3302018-05-21 17:57:19 +000072 bool writeNopData(raw_ostream &OS, uint64_t Count) const override;
Joe Abbey8e72eb72014-09-16 09:18:23 +000073
74 void handleAssemblerFlag(MCAssemblerFlag Flag) override;
75
76 unsigned getPointerSize() const { return 4; }
77 bool isThumb() const { return isThumbMode; }
78 void setIsThumb(bool it) { isThumbMode = it; }
Joe Abbey8e72eb72014-09-16 09:18:23 +000079};
Benjamin Kramerb32a5042016-01-27 19:29:42 +000080} // end namespace llvm
Joe Abbey8e72eb72014-09-16 09:18:23 +000081
82#endif