LLVM  3.7.0
MCAsmBackend.h
Go to the documentation of this file.
1 //===-- llvm/MC/MCAsmBackend.h - MC Asm 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_MC_MCASMBACKEND_H
11 #define LLVM_MC_MCASMBACKEND_H
12 
13 #include "llvm/ADT/ArrayRef.h"
14 #include "llvm/MC/MCDirectives.h"
15 #include "llvm/MC/MCDwarf.h"
16 #include "llvm/MC/MCFixup.h"
17 #include "llvm/Support/DataTypes.h"
19 
20 namespace llvm {
21 class MCAsmLayout;
22 class MCAssembler;
23 class MCELFObjectTargetWriter;
24 struct MCFixupKindInfo;
25 class MCFragment;
26 class MCInst;
27 class MCRelaxableFragment;
28 class MCObjectWriter;
29 class MCSection;
30 class MCValue;
31 class raw_ostream;
32 
33 /// Generic interface to target specific assembler backends.
34 class MCAsmBackend {
35  MCAsmBackend(const MCAsmBackend &) = delete;
36  void operator=(const MCAsmBackend &) = delete;
37 
38 protected: // Can only create subclasses.
39  MCAsmBackend();
40 
41  unsigned HasDataInCodeSupport : 1;
42 
43 public:
44  virtual ~MCAsmBackend();
45 
46  /// lifetime management
47  virtual void reset() {}
48 
49  /// Create a new MCObjectWriter instance for use by the assembler backend to
50  /// emit the final object file.
51  virtual MCObjectWriter *createObjectWriter(raw_pwrite_stream &OS) const = 0;
52 
53  /// Create a new ELFObjectTargetWriter to enable non-standard
54  /// ELFObjectWriters.
56  llvm_unreachable("createELFObjectTargetWriter is not supported by asm "
57  "backend");
58  }
59 
60  /// Check whether this target implements data-in-code markers. If not, data
61  /// region directives will be ignored.
62  bool hasDataInCodeSupport() const { return HasDataInCodeSupport; }
63 
64  /// \name Target Fixup Interfaces
65  /// @{
66 
67  /// Get the number of target specific fixup kinds.
68  virtual unsigned getNumFixupKinds() const = 0;
69 
70  /// Get information on a fixup kind.
71  virtual const MCFixupKindInfo &getFixupKindInfo(MCFixupKind Kind) const;
72 
73  /// Target hook to adjust the literal value of a fixup if necessary.
74  /// IsResolved signals whether the caller believes a relocation is needed; the
75  /// target can modify the value. The default does nothing.
76  virtual void processFixupValue(const MCAssembler &Asm,
77  const MCAsmLayout &Layout,
78  const MCFixup &Fixup, const MCFragment *DF,
79  const MCValue &Target, uint64_t &Value,
80  bool &IsResolved) {}
81 
82  /// Apply the \p Value for given \p Fixup into the provided data fragment, at
83  /// the offset specified by the fixup and following the fixup kind as
84  /// appropriate.
85  virtual void applyFixup(const MCFixup &Fixup, char *Data, unsigned DataSize,
86  uint64_t Value, bool IsPCRel) const = 0;
87 
88  /// @}
89 
90  /// \name Target Relaxation Interfaces
91  /// @{
92 
93  /// Check whether the given instruction may need relaxation.
94  ///
95  /// \param Inst - The instruction to test.
96  virtual bool mayNeedRelaxation(const MCInst &Inst) const = 0;
97 
98  /// Target specific predicate for whether a given fixup requires the
99  /// associated instruction to be relaxed.
100  virtual bool fixupNeedsRelaxationAdvanced(const MCFixup &Fixup, bool Resolved,
101  uint64_t Value,
102  const MCRelaxableFragment *DF,
103  const MCAsmLayout &Layout) const;
104 
105  /// Simple predicate for targets where !Resolved implies requiring relaxation
106  virtual bool fixupNeedsRelaxation(const MCFixup &Fixup, uint64_t Value,
107  const MCRelaxableFragment *DF,
108  const MCAsmLayout &Layout) const = 0;
109 
110  /// Relax the instruction in the given fragment to the next wider instruction.
111  ///
112  /// \param Inst The instruction to relax, which may be the same as the
113  /// output.
114  /// \param [out] Res On return, the relaxed instruction.
115  virtual void relaxInstruction(const MCInst &Inst, MCInst &Res) const = 0;
116 
117  /// @}
118 
119  /// Returns the minimum size of a nop in bytes on this target. The assembler
120  /// will use this to emit excess padding in situations where the padding
121  /// required for simple alignment would be less than the minimum nop size.
122  ///
123  virtual unsigned getMinimumNopSize() const { return 1; }
124 
125  /// Write an (optimal) nop sequence of Count bytes to the given output. If the
126  /// target cannot generate such a sequence, it should return an error.
127  ///
128  /// \return - True on success.
129  virtual bool writeNopData(uint64_t Count, MCObjectWriter *OW) const = 0;
130 
131  /// Handle any target-specific assembler flags. By default, do nothing.
133 
134  /// \brief Generate the compact unwind encoding for the CFI instructions.
135  virtual uint32_t
137  return 0;
138  }
139 };
140 
141 } // End llvm namespace
142 
143 #endif
virtual MCObjectWriter * createObjectWriter(raw_pwrite_stream &OS) const =0
Create a new MCObjectWriter instance for use by the assembler backend to emit the final object file...
This represents an "assembler immediate".
Definition: MCValue.h:44
virtual bool fixupNeedsRelaxationAdvanced(const MCFixup &Fixup, bool Resolved, uint64_t Value, const MCRelaxableFragment *DF, const MCAsmLayout &Layout) const
Target specific predicate for whether a given fixup requires the associated instruction to be relaxed...
virtual ~MCAsmBackend()
virtual bool fixupNeedsRelaxation(const MCFixup &Fixup, uint64_t Value, const MCRelaxableFragment *DF, const MCAsmLayout &Layout) const =0
Simple predicate for targets where !Resolved implies requiring relaxation.
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:62
virtual unsigned getMinimumNopSize() const
Returns the minimum size of a nop in bytes on this target.
Definition: MCAsmBackend.h:123
Encapsulates the layout of an assembly file at a particular point in time.
Definition: MCAsmLayout.h:29
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:98
unsigned HasDataInCodeSupport
Definition: MCAsmBackend.h:41
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: ArrayRef.h:31
virtual void applyFixup(const MCFixup &Fixup, char *Data, unsigned DataSize, uint64_t Value, bool IsPCRel) const =0
Apply the Value for given Fixup into the provided data fragment, at the offset specified by the fixup...
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:150
virtual bool writeNopData(uint64_t Count, MCObjectWriter *OW) const =0
Write an (optimal) nop sequence of Count bytes to the given output.
Flag
These should be considered private to the implementation of the MCInstrDesc class.
Definition: MCInstrDesc.h:97
A relaxable fragment holds on to its MCInst, since it may need to be relaxed during the assembler lay...
Definition: MCAssembler.h:259
virtual void relaxInstruction(const MCInst &Inst, MCInst &Res) const =0
Relax the instruction in the given fragment to the next wider instruction.
MCFixupKind
Extensible enumeration to represent the type of a fixup.
Definition: MCFixup.h:23
virtual void processFixupValue(const MCAssembler &Asm, const MCAsmLayout &Layout, const MCFixup &Fixup, const MCFragment *DF, const MCValue &Target, uint64_t &Value, bool &IsResolved)
Target hook to adjust the literal value of a fixup if necessary.
Definition: MCAsmBackend.h:76
virtual bool mayNeedRelaxation(const MCInst &Inst) const =0
Check whether the given instruction may need relaxation.
virtual unsigned getNumFixupKinds() const =0
Get the number of target specific fixup kinds.
PowerPC TLS Dynamic Call Fixup
Target - Wrapper for Target specific information.
bool hasDataInCodeSupport() const
Check whether this target implements data-in-code markers.
Definition: MCAsmBackend.h:62
virtual void handleAssemblerFlag(MCAssemblerFlag Flag)
Handle any target-specific assembler flags. By default, do nothing.
Definition: MCAsmBackend.h:132
MCAssemblerFlag
Definition: MCDirectives.h:47
virtual uint32_t generateCompactUnwindEncoding(ArrayRef< MCCFIInstruction >) const
Generate the compact unwind encoding for the CFI instructions.
Definition: MCAsmBackend.h:136
Target independent information on a fixup kind.
An abstract base class for streams implementations that also support a pwrite operation.
Definition: raw_ostream.h:321
const ARM::ArchExtKind Kind
LLVM Value Representation.
Definition: Value.h:69
Generic interface to target specific assembler backends.
Definition: MCAsmBackend.h:34
virtual MCELFObjectTargetWriter * createELFObjectTargetWriter() const
Create a new ELFObjectTargetWriter to enable non-standard ELFObjectWriters.
Definition: MCAsmBackend.h:55
virtual const MCFixupKindInfo & getFixupKindInfo(MCFixupKind Kind) const
Get information on a fixup kind.
virtual void reset()
lifetime management
Definition: MCAsmBackend.h:47