blob: 54cb162ee11233898cca2f08a79c45ad8f92c10e [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 {
22 const MCSubtargetInfo *STI;
23 bool isThumbMode; // Currently emitting Thumb code.
24 bool IsLittleEndian; // Big or little endian.
25public:
Daniel Sanders50f17232015-09-15 16:17:27 +000026 ARMAsmBackend(const Target &T, const Triple &TT, bool IsLittle)
Daniel Sandersa73f1fd2015-06-10 12:11:26 +000027 : MCAsmBackend(), STI(ARM_MC::createARMMCSubtargetInfo(TT, "", "")),
Daniel Sanders418caf52015-06-10 10:35:34 +000028 isThumbMode(TT.getArchName().startswith("thumb")),
29 IsLittleEndian(IsLittle) {}
Joe Abbey8e72eb72014-09-16 09:18:23 +000030
31 ~ARMAsmBackend() override { delete STI; }
32
33 unsigned getNumFixupKinds() const override {
34 return ARM::NumTargetFixupKinds;
35 }
36
Michael Kupersteindb0712f2015-05-26 10:47:10 +000037 bool hasNOP() const { return STI->getFeatureBits()[ARM::HasV6T2Ops]; }
Joe Abbey8e72eb72014-09-16 09:18:23 +000038
39 const MCFixupKindInfo &getFixupKindInfo(MCFixupKind Kind) const override;
40
41 /// processFixupValue - Target hook to process the literal value of a fixup
42 /// if necessary.
43 void processFixupValue(const MCAssembler &Asm, const MCAsmLayout &Layout,
44 const MCFixup &Fixup, const MCFragment *DF,
45 const MCValue &Target, uint64_t &Value,
46 bool &IsResolved) override;
47
Rafael Espindola801b42d2017-06-23 22:52:36 +000048 unsigned adjustFixupValue(const MCAssembler &Asm, const MCFixup &Fixup,
49 const MCValue &Target, uint64_t Value, bool IsPCRel,
Alex Bradbury866113c2017-04-05 10:16:14 +000050 MCContext &Ctx, bool IsLittleEndian,
Tim Northover8d67b8e2015-10-02 18:07:18 +000051 bool IsResolved) const;
52
Rafael Espindola801b42d2017-06-23 22:52:36 +000053 void applyFixup(const MCAssembler &Asm, const MCFixup &Fixup,
54 const MCValue &Target, MutableArrayRef<char> Data,
Alex Bradbury866113c2017-04-05 10:16:14 +000055 uint64_t Value, bool IsPCRel, MCContext &Ctx) const override;
Joe Abbey8e72eb72014-09-16 09:18:23 +000056
Tim Northover42335572015-04-06 18:44:42 +000057 unsigned getRelaxedOpcode(unsigned Op) const;
58
Joe Abbey8e72eb72014-09-16 09:18:23 +000059 bool mayNeedRelaxation(const MCInst &Inst) const override;
60
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
71 bool writeNopData(uint64_t Count, MCObjectWriter *OW) const override;
72
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; }
78 bool isLittle() const { return IsLittleEndian; }
79};
Benjamin Kramerb32a5042016-01-27 19:29:42 +000080} // end namespace llvm
Joe Abbey8e72eb72014-09-16 09:18:23 +000081
82#endif