1 //===-- llvm/MC/MCAsmBack.h - MC Asm Backend --------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef LLVM_MC_MCASMBACKEND_H
11 #define LLVM_MC_MCASMBACKEND_H
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"
18 #include "llvm/Support/ErrorHandling.h"
23 class MCELFObjectTargetWriter;
24 struct MCFixupKindInfo;
27 class MCRelaxableFragment;
33 /// MCAsmBackend - Generic interface to target specific assembler backends.
35 MCAsmBackend(const MCAsmBackend &) LLVM_DELETED_FUNCTION;
36 void operator=(const MCAsmBackend &) LLVM_DELETED_FUNCTION;
38 protected: // Can only create subclasses.
41 unsigned HasReliableSymbolDifference : 1;
42 unsigned HasDataInCodeSupport : 1;
45 virtual ~MCAsmBackend();
47 /// lifetime management
48 virtual void reset() {}
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;
54 /// createELFObjectTargetWriter - Create a new ELFObjectTargetWriter to enable
55 /// non-standard ELFObjectWriters.
56 virtual MCELFObjectTargetWriter *createELFObjectTargetWriter() const {
57 llvm_unreachable("createELFObjectTargetWriter is not supported by asm "
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.
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.
71 bool hasReliableSymbolDifference() const {
72 return HasReliableSymbolDifference;
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; }
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 {
85 /// isSectionAtomizable - Check whether the given section can be split into
88 /// \see MCAssembler::isSymbolLinkerVisible().
89 virtual bool isSectionAtomizable(const MCSection &Section) const {
93 /// @name Target Fixup Interfaces
96 /// getNumFixupKinds - Get the number of target specific fixup kinds.
97 virtual unsigned getNumFixupKinds() const = 0;
99 /// getFixupKindInfo - Get information on a fixup kind.
100 virtual const MCFixupKindInfo &getFixupKindInfo(MCFixupKind Kind) const;
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,
111 /// applyFixup - Apply the \p Value for given \p Fixup into the provided
112 /// data fragment, at the offset specified by the fixup and following the
113 /// fixup kind as appropriate.
114 virtual void applyFixup(const MCFixup &Fixup, char *Data, unsigned DataSize,
115 uint64_t Value) const = 0;
119 /// @name Target Relaxation Interfaces
122 /// mayNeedRelaxation - Check whether the given instruction may need
125 /// \param Inst - The instruction to test.
126 virtual bool mayNeedRelaxation(const MCInst &Inst) const = 0;
128 /// fixupNeedsRelaxation - Target specific predicate for whether a given
129 /// fixup requires the associated instruction to be relaxed.
130 virtual bool fixupNeedsRelaxation(const MCFixup &Fixup, uint64_t Value,
131 const MCRelaxableFragment *DF,
132 const MCAsmLayout &Layout) const = 0;
134 /// RelaxInstruction - Relax the instruction in the given fragment to the next
135 /// wider instruction.
137 /// \param Inst The instruction to relax, which may be the same as the
139 /// \param [out] Res On return, the relaxed instruction.
140 virtual void relaxInstruction(const MCInst &Inst, MCInst &Res) const = 0;
144 /// getMinimumNopSize - Returns the minimum size of a nop in bytes on this
145 /// target. The assembler will use this to emit excess padding in situations
146 /// where the padding required for simple alignment would be less than the
147 /// minimum nop size.
149 virtual unsigned getMinimumNopSize() const { return 1; }
151 /// writeNopData - Write an (optimal) nop sequence of Count bytes to the given
152 /// output. If the target cannot generate such a sequence, it should return an
155 /// \return - True on success.
156 virtual bool writeNopData(uint64_t Count, MCObjectWriter *OW) const = 0;
158 /// handleAssemblerFlag - Handle any target-specific assembler flags.
159 /// By default, do nothing.
160 virtual void handleAssemblerFlag(MCAssemblerFlag Flag) {}
162 /// \brief Generate the compact unwind encoding for the CFI instructions.
164 generateCompactUnwindEncoding(ArrayRef<MCCFIInstruction>) const {
169 } // End llvm namespace