blob: 88c476bf65f4ec23db6fa89349dbf7ad60a452ba [file] [log] [blame]
Joe Abbey8e72eb72014-09-16 09:18:23 +00001//===-- ARMAsmBackend.h - ARM Assembler Backend -----------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef LLVM_LIB_TARGET_ARM_ARMASMBACKEND_H
11#define LLVM_LIB_TARGET_ARM_ARMASMBACKEND_H
12
13#include "MCTargetDesc/ARMFixupKinds.h"
Benjamin Kramerb32a5042016-01-27 19:29:42 +000014#include "MCTargetDesc/ARMMCTargetDesc.h"
Joe Abbey8e72eb72014-09-16 09:18:23 +000015#include "llvm/MC/MCAsmBackend.h"
16#include "llvm/MC/MCSubtargetInfo.h"
Benjamin Kramerb32a5042016-01-27 19:29:42 +000017#include "llvm/Support/TargetRegistry.h"
Joe Abbey8e72eb72014-09-16 09:18:23 +000018
Benjamin Kramerb32a5042016-01-27 19:29:42 +000019namespace llvm {
Joe Abbey8e72eb72014-09-16 09:18:23 +000020
21class ARMAsmBackend : public MCAsmBackend {
Peter Smith57f661b2018-06-06 09:40:06 +000022 // The STI from the target triple the MCAsmBackend was instantiated with
23 // note that MCFragments may have a different local STI that should be
24 // used in preference.
Alex Bradbury46db78b2018-01-03 13:46:21 +000025 const MCSubtargetInfo &STI;
Joe Abbey8e72eb72014-09-16 09:18:23 +000026 bool isThumbMode; // Currently emitting Thumb code.
Joe Abbey8e72eb72014-09-16 09:18:23 +000027public:
Peter Collingbourne571a3302018-05-21 17:57:19 +000028 ARMAsmBackend(const Target &T, const MCSubtargetInfo &STI,
29 support::endianness Endian)
30 : MCAsmBackend(Endian), STI(STI),
31 isThumbMode(STI.getTargetTriple().isThumb()) {}
Joe Abbey8e72eb72014-09-16 09:18:23 +000032
Joe Abbey8e72eb72014-09-16 09:18:23 +000033 unsigned getNumFixupKinds() const override {
34 return ARM::NumTargetFixupKinds;
35 }
36
Peter Smith57f661b2018-06-06 09:40:06 +000037 // FIXME: this should be calculated per fragment as the STI may be
38 // different.
Alex Bradbury46db78b2018-01-03 13:46:21 +000039 bool hasNOP() const { return STI.getFeatureBits()[ARM::HasV6T2Ops]; }
Joe Abbey8e72eb72014-09-16 09:18:23 +000040
41 const MCFixupKindInfo &getFixupKindInfo(MCFixupKind Kind) const override;
42
Rafael Espindola76287ab2017-06-30 22:47:27 +000043 bool shouldForceRelocation(const MCAssembler &Asm, const MCFixup &Fixup,
44 const MCValue &Target) override;
Joe Abbey8e72eb72014-09-16 09:18:23 +000045
Rafael Espindola801b42d2017-06-23 22:52:36 +000046 unsigned adjustFixupValue(const MCAssembler &Asm, const MCFixup &Fixup,
Rafael Espindola1beb7022017-07-11 23:18:25 +000047 const MCValue &Target, uint64_t Value,
Peter Smith57f661b2018-06-06 09:40:06 +000048 bool IsResolved, MCContext &Ctx,
49 const MCSubtargetInfo *STI) const;
Tim Northover8d67b8e2015-10-02 18:07:18 +000050
Rafael Espindola801b42d2017-06-23 22:52:36 +000051 void applyFixup(const MCAssembler &Asm, const MCFixup &Fixup,
52 const MCValue &Target, MutableArrayRef<char> Data,
Peter Smith57f661b2018-06-06 09:40:06 +000053 uint64_t Value, bool IsResolved,
54 const MCSubtargetInfo *STI) const override;
Joe Abbey8e72eb72014-09-16 09:18:23 +000055
Peter Smith57f661b2018-06-06 09:40:06 +000056 unsigned getRelaxedOpcode(unsigned Op, const MCSubtargetInfo &STI) const;
Tim Northover42335572015-04-06 18:44:42 +000057
Peter Smith57f661b2018-06-06 09:40:06 +000058 bool mayNeedRelaxation(const MCInst &Inst,
59 const MCSubtargetInfo &STI) const override;
Joe Abbey8e72eb72014-09-16 09:18:23 +000060
Tim Northover8d67b8e2015-10-02 18:07:18 +000061 const char *reasonForFixupRelaxation(const MCFixup &Fixup,
62 uint64_t Value) const;
63
Joe Abbey8e72eb72014-09-16 09:18:23 +000064 bool fixupNeedsRelaxation(const MCFixup &Fixup, uint64_t Value,
65 const MCRelaxableFragment *DF,
66 const MCAsmLayout &Layout) const override;
67
Nirav Dave86030622016-07-11 14:23:53 +000068 void relaxInstruction(const MCInst &Inst, const MCSubtargetInfo &STI,
69 MCInst &Res) const override;
Joe Abbey8e72eb72014-09-16 09:18:23 +000070
Peter Collingbourne571a3302018-05-21 17:57:19 +000071 bool writeNopData(raw_ostream &OS, uint64_t Count) const override;
Joe Abbey8e72eb72014-09-16 09:18:23 +000072
73 void handleAssemblerFlag(MCAssemblerFlag Flag) override;
74
75 unsigned getPointerSize() const { return 4; }
76 bool isThumb() const { return isThumbMode; }
77 void setIsThumb(bool it) { isThumbMode = it; }
Joe Abbey8e72eb72014-09-16 09:18:23 +000078};
Benjamin Kramerb32a5042016-01-27 19:29:42 +000079} // end namespace llvm
Joe Abbey8e72eb72014-09-16 09:18:23 +000080
81#endif