LLVM API Documentation

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MCAsmBackend.h
Go to the documentation of this file.
1 //===-- llvm/MC/MCAsmBack.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 /// MCAsmBackend - Generic interface to target specific assembler backends.
34 class MCAsmBackend {
36  void operator=(const MCAsmBackend &) LLVM_DELETED_FUNCTION;
37 
38 protected: // Can only create subclasses.
39  MCAsmBackend();
40 
42  unsigned HasDataInCodeSupport : 1;
43 
44 public:
45  virtual ~MCAsmBackend();
46 
47  /// lifetime management
48  virtual void reset() {}
49 
50  /// createObjectWriter - Create a new MCObjectWriter instance for use by the
51  /// assembler backend to emit the final object file.
52  virtual MCObjectWriter *createObjectWriter(raw_ostream &OS) const = 0;
53 
54  /// createELFObjectTargetWriter - Create a new ELFObjectTargetWriter to enable
55  /// non-standard ELFObjectWriters.
57  llvm_unreachable("createELFObjectTargetWriter is not supported by asm "
58  "backend");
59  }
60 
61  /// hasReliableSymbolDifference - Check whether this target implements
62  /// accurate relocations for differences between symbols. If not, differences
63  /// between symbols will always be relocatable expressions and any references
64  /// to temporary symbols will be assumed to be in the same atom, unless they
65  /// reside in a different section.
66  ///
67  /// This should always be true (since it results in fewer relocations with no
68  /// loss of functionality), but is currently supported as a way to maintain
69  /// exact object compatibility with Darwin 'as' (on non-x86_64). It should
70  /// eventually should be eliminated.
73  }
74 
75  /// hasDataInCodeSupport - Check whether this target implements data-in-code
76  /// markers. If not, data region directives will be ignored.
77  bool hasDataInCodeSupport() const { return HasDataInCodeSupport; }
78 
79  /// doesSectionRequireSymbols - Check whether the given section requires that
80  /// all symbols (even temporaries) have symbol table entries.
81  virtual bool doesSectionRequireSymbols(const MCSection &Section) const {
82  return false;
83  }
84 
85  /// isSectionAtomizable - Check whether the given section can be split into
86  /// atoms.
87  ///
88  /// \see MCAssembler::isSymbolLinkerVisible().
89  virtual bool isSectionAtomizable(const MCSection &Section) const {
90  return true;
91  }
92 
93  /// @name Target Fixup Interfaces
94  /// @{
95 
96  /// getNumFixupKinds - Get the number of target specific fixup kinds.
97  virtual unsigned getNumFixupKinds() const = 0;
98 
99  /// getFixupKindInfo - Get information on a fixup kind.
100  virtual const MCFixupKindInfo &getFixupKindInfo(MCFixupKind Kind) const;
101 
102  /// processFixupValue - Target hook to adjust the literal value of a fixup
103  /// if necessary. IsResolved signals whether the caller believes a relocation
104  /// is needed; the target can modify the value. The default does nothing.
105  virtual void processFixupValue(const MCAssembler &Asm,
106  const MCAsmLayout &Layout,
107  const MCFixup &Fixup, const MCFragment *DF,
108  MCValue &Target, uint64_t &Value,
109  bool &IsResolved) {}
110 
111  /// @}
112 
113  /// applyFixup - Apply the \p Value for given \p Fixup into the provided
114  /// data fragment, at the offset specified by the fixup and following the
115  /// fixup kind as appropriate.
116  virtual void applyFixup(const MCFixup &Fixup, char *Data, unsigned DataSize,
117  uint64_t Value) const = 0;
118 
119  /// @}
120 
121  /// @name Target Relaxation Interfaces
122  /// @{
123 
124  /// mayNeedRelaxation - Check whether the given instruction may need
125  /// relaxation.
126  ///
127  /// \param Inst - The instruction to test.
128  virtual bool mayNeedRelaxation(const MCInst &Inst) const = 0;
129 
130  /// fixupNeedsRelaxation - Target specific predicate for whether a given
131  /// fixup requires the associated instruction to be relaxed.
132  virtual bool fixupNeedsRelaxation(const MCFixup &Fixup, uint64_t Value,
133  const MCRelaxableFragment *DF,
134  const MCAsmLayout &Layout) const = 0;
135 
136  /// RelaxInstruction - Relax the instruction in the given fragment to the next
137  /// wider instruction.
138  ///
139  /// \param Inst The instruction to relax, which may be the same as the
140  /// output.
141  /// \param [out] Res On return, the relaxed instruction.
142  virtual void relaxInstruction(const MCInst &Inst, MCInst &Res) const = 0;
143 
144  /// @}
145 
146  /// getMinimumNopSize - Returns the minimum size of a nop in bytes on this
147  /// target. The assembler will use this to emit excess padding in situations
148  /// where the padding required for simple alignment would be less than the
149  /// minimum nop size.
150  ///
151  virtual unsigned getMinimumNopSize() const { return 1; }
152 
153  /// writeNopData - Write an (optimal) nop sequence of Count bytes to the given
154  /// output. If the target cannot generate such a sequence, it should return an
155  /// error.
156  ///
157  /// \return - True on success.
158  virtual bool writeNopData(uint64_t Count, MCObjectWriter *OW) const = 0;
159 
160  /// handleAssemblerFlag - Handle any target-specific assembler flags.
161  /// By default, do nothing.
162  virtual void handleAssemblerFlag(MCAssemblerFlag Flag) {}
163 
164  /// \brief Generate the compact unwind encoding for the CFI instructions.
165  virtual uint32_t
167  return 0;
168  }
169 };
170 
171 } // End llvm namespace
172 
173 #endif
unsigned HasReliableSymbolDifference
Definition: MCAsmBackend.h:41
virtual ~MCAsmBackend()
virtual bool fixupNeedsRelaxation(const MCFixup &Fixup, uint64_t Value, const MCRelaxableFragment *DF, const MCAsmLayout &Layout) const =0
virtual bool doesSectionRequireSymbols(const MCSection &Section) const
Definition: MCAsmBackend.h:81
virtual unsigned getMinimumNopSize() const
Definition: MCAsmBackend.h:151
#define llvm_unreachable(msg)
unsigned HasDataInCodeSupport
Definition: MCAsmBackend.h:42
virtual bool isSectionAtomizable(const MCSection &Section) const
Definition: MCAsmBackend.h:89
virtual void processFixupValue(const MCAssembler &Asm, const MCAsmLayout &Layout, const MCFixup &Fixup, const MCFragment *DF, MCValue &Target, uint64_t &Value, bool &IsResolved)
Definition: MCAsmBackend.h:105
virtual bool writeNopData(uint64_t Count, MCObjectWriter *OW) const =0
virtual void relaxInstruction(const MCInst &Inst, MCInst &Res) const =0
MCFixupKind
MCFixupKind - Extensible enumeration to represent the type of a fixup.
Definition: MCFixup.h:22
virtual bool mayNeedRelaxation(const MCInst &Inst) const =0
virtual unsigned getNumFixupKinds() const =0
getNumFixupKinds - Get the number of target specific fixup kinds.
virtual MCObjectWriter * createObjectWriter(raw_ostream &OS) const =0
virtual void applyFixup(const MCFixup &Fixup, char *Data, unsigned DataSize, uint64_t Value) const =0
#define LLVM_DELETED_FUNCTION
Definition: Compiler.h:137
bool hasDataInCodeSupport() const
Definition: MCAsmBackend.h:77
virtual void handleAssemblerFlag(MCAssemblerFlag Flag)
Definition: MCAsmBackend.h:162
MCAssemblerFlag
Definition: MCDirectives.h:47
virtual uint32_t generateCompactUnwindEncoding(ArrayRef< MCCFIInstruction >) const
Generate the compact unwind encoding for the CFI instructions.
Definition: MCAsmBackend.h:166
bool hasReliableSymbolDifference() const
Definition: MCAsmBackend.h:71
MCFixupKindInfo - Target independent information on a fixup kind.
LLVM Value Representation.
Definition: Value.h:66
MCAsmBackend - Generic interface to target specific assembler backends.
Definition: MCAsmBackend.h:34
virtual MCELFObjectTargetWriter * createELFObjectTargetWriter() const
Definition: MCAsmBackend.h:56
virtual const MCFixupKindInfo & getFixupKindInfo(MCFixupKind Kind) const
getFixupKindInfo - Get information on a fixup kind.
virtual void reset()
lifetime management
Definition: MCAsmBackend.h:48