LLVM  5.0.0
ARMAsmBackend.h
Go to the documentation of this file.
1 //===-- 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 
15 #include "llvm/MC/MCAsmBackend.h"
18 
19 namespace llvm {
20 
21 class ARMAsmBackend : public MCAsmBackend {
22  const MCSubtargetInfo *STI;
23  bool isThumbMode; // Currently emitting Thumb code.
24  bool IsLittleEndian; // Big or little endian.
25 public:
26  ARMAsmBackend(const Target &T, const Triple &TT, bool IsLittle)
27  : MCAsmBackend(), STI(ARM_MC::createARMMCSubtargetInfo(TT, "", "")),
28  isThumbMode(TT.getArchName().startswith("thumb")),
29  IsLittleEndian(IsLittle) {}
30 
31  ~ARMAsmBackend() override { delete STI; }
32 
33  unsigned getNumFixupKinds() const override {
35  }
36 
37  bool hasNOP() const { return STI->getFeatureBits()[ARM::HasV6T2Ops]; }
38 
39  const MCFixupKindInfo &getFixupKindInfo(MCFixupKind Kind) const override;
40 
41  bool shouldForceRelocation(const MCAssembler &Asm, const MCFixup &Fixup,
42  const MCValue &Target) override;
43 
44  unsigned adjustFixupValue(const MCAssembler &Asm, const MCFixup &Fixup,
45  const MCValue &Target, uint64_t Value,
46  bool IsResolved, MCContext &Ctx,
47  bool IsLittleEndian) const;
48 
49  void applyFixup(const MCAssembler &Asm, const MCFixup &Fixup,
51  uint64_t Value, bool IsResolved) const override;
52 
53  unsigned getRelaxedOpcode(unsigned Op) const;
54 
55  bool mayNeedRelaxation(const MCInst &Inst) 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(const MCInst &Inst, const MCSubtargetInfo &STI,
65  MCInst &Res) const override;
66 
67  bool writeNopData(uint64_t Count, MCObjectWriter *OW) const override;
68 
70 
71  unsigned getPointerSize() const { return 4; }
72  bool isThumb() const { return isThumbMode; }
73  void setIsThumb(bool it) { isThumbMode = it; }
74  bool isLittle() const { return IsLittleEndian; }
75 };
76 } // end namespace llvm
77 
78 #endif
unsigned getNumFixupKinds() const override
Get the number of target specific fixup kinds.
Definition: ARMAsmBackend.h:33
void setIsThumb(bool it)
Definition: ARMAsmBackend.h:73
This represents an "assembler immediate".
Definition: MCValue.h:40
bool hasNOP() const
Definition: ARMAsmBackend.h:37
const char * reasonForFixupRelaxation(const MCFixup &Fixup, uint64_t Value) const
unsigned getRelaxedOpcode(unsigned Op) const
Defines the object file and target independent interfaces used by the assembler backend to write nati...
Encode information on a single operation to perform on a byte sequence (e.g., an encoded instruction)...
Definition: MCFixup.h:66
StringRef getArchName(unsigned ArchKind)
~ARMAsmBackend() override
Definition: ARMAsmBackend.h:31
Encapsulates the layout of an assembly file at a particular point in time.
Definition: MCAsmLayout.h:29
bool mayNeedRelaxation(const MCInst &Inst) const override
Check whether the given instruction may need relaxation.
static bool startswith(StringRef Magic, const char(&S)[N])
Definition: Magic.cpp:29
Context object for machine code objects.
Definition: MCContext.h:59
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:159
Flag
These should be considered private to the implementation of the MCInstrDesc class.
Definition: MCInstrDesc.h:121
A relaxable fragment holds on to its MCInst, since it may need to be relaxed during the assembler lay...
Definition: MCFragment.h:255
unsigned getPointerSize() const
Definition: ARMAsmBackend.h:71
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
Definition: ArrayRef.h:291
bool fixupNeedsRelaxation(const MCFixup &Fixup, uint64_t Value, const MCRelaxableFragment *DF, const MCAsmLayout &Layout) const override
Simple predicate for targets where !Resolved implies requiring relaxation.
MCFixupKind
Extensible enumeration to represent the type of a fixup.
Definition: MCFixup.h:23
ARMAsmBackend(const Target &T, const Triple &TT, bool IsLittle)
Definition: ARMAsmBackend.h:26
const MCFixupKindInfo & getFixupKindInfo(MCFixupKind Kind) const override
Get information on a fixup kind.
MCSubtargetInfo * createARMMCSubtargetInfo(const Triple &TT, StringRef CPU, StringRef FS)
Create a ARM MCSubtargetInfo instance.
void applyFixup(const MCAssembler &Asm, const MCFixup &Fixup, const MCValue &Target, MutableArrayRef< char > Data, uint64_t Value, bool IsResolved) const override
Apply the Value for given Fixup into the provided data fragment, at the offset specified by the fixup...
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
bool writeNopData(uint64_t Count, MCObjectWriter *OW) const override
Write an (optimal) nop sequence of Count bytes to the given output.
void relaxInstruction(const MCInst &Inst, const MCSubtargetInfo &STI, MCInst &Res) const override
Relax the instruction in the given fragment to the next wider instruction.
const FeatureBitset & getFeatureBits() const
getFeatureBits - Return the feature bits.
Target - Wrapper for Target specific information.
bool isLittle() const
Definition: ARMAsmBackend.h:74
void handleAssemblerFlag(MCAssemblerFlag Flag) override
Handle any target-specific assembler flags. By default, do nothing.
MCAssemblerFlag
Definition: MCDirectives.h:48
MCSubtargetInfo - Generic base class for all target subtargets.
bool isThumb() const
Definition: ARMAsmBackend.h:72
Target independent information on a fixup kind.
unsigned adjustFixupValue(const MCAssembler &Asm, const MCFixup &Fixup, const MCValue &Target, uint64_t Value, bool IsResolved, MCContext &Ctx, bool IsLittleEndian) const
const unsigned Kind
LLVM Value Representation.
Definition: Value.h:73
Generic interface to target specific assembler backends.
Definition: MCAsmBackend.h:35
bool shouldForceRelocation(const MCAssembler &Asm, const MCFixup &Fixup, const MCValue &Target) override
Hook to check if a relocation is needed for some target specific reason.