MCAsmBackend.h revision c3cee57f7d20f69a84fd88464ed8cf050e63c7ad
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" 18#include "llvm/Support/ErrorHandling.h" 19 20namespace llvm { 21class MCAsmLayout; 22class MCAssembler; 23class MCELFObjectTargetWriter; 24struct MCFixupKindInfo; 25class MCFragment; 26class MCInst; 27class MCRelaxableFragment; 28class MCObjectWriter; 29class MCSection; 30class MCValue; 31class raw_ostream; 32 33/// MCAsmBackend - Generic interface to target specific assembler backends. 34class MCAsmBackend { 35 MCAsmBackend(const MCAsmBackend &) LLVM_DELETED_FUNCTION; 36 void operator=(const MCAsmBackend &) LLVM_DELETED_FUNCTION; 37 38protected: // Can only create subclasses. 39 MCAsmBackend(); 40 41 unsigned HasReliableSymbolDifference : 1; 42 unsigned HasDataInCodeSupport : 1; 43 44public: 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. 56 virtual MCELFObjectTargetWriter *createELFObjectTargetWriter() const { 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. 71 bool hasReliableSymbolDifference() const { 72 return HasReliableSymbolDifference; 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 unsigned 166 generateCompactUnwindEncoding(ArrayRef<MCCFIInstruction>) const { 167 return 0; 168 } 169}; 170 171} // End llvm namespace 172 173#endif 174