1 //===-- llvm/Target/TargetAsmBackend.h - Target 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_TARGET_TARGETASMBACKEND_H
11 #define LLVM_TARGET_TARGETASMBACKEND_H
13 #include "llvm/Support/DataTypes.h"
23 class SmallVectorImpl;
27 /// TargetAsmBackend - Generic interface to target specific assembler backends.
28 class TargetAsmBackend {
29 TargetAsmBackend(const TargetAsmBackend &); // DO NOT IMPLEMENT
30 void operator=(const TargetAsmBackend &); // DO NOT IMPLEMENT
31 protected: // Can only create subclasses.
34 unsigned HasReliableSymbolDifference : 1;
35 unsigned HasScatteredSymbols : 1;
38 virtual ~TargetAsmBackend();
40 virtual const MCObjectFormat &getObjectFormat() const = 0;
42 /// createObjectWriter - Create a new MCObjectWriter instance for use by the
43 /// assembler backend to emit the final object file.
44 virtual MCObjectWriter *createObjectWriter(raw_ostream &OS) const = 0;
46 /// hasReliableSymbolDifference - Check whether this target implements
47 /// accurate relocations for differences between symbols. If not, differences
48 /// between symbols will always be relocatable expressions and any references
49 /// to temporary symbols will be assumed to be in the same atom, unless they
50 /// reside in a different section.
52 /// This should always be true (since it results in fewer relocations with no
53 /// loss of functionality), but is currently supported as a way to maintain
54 /// exact object compatibility with Darwin 'as' (on non-x86_64). It should
55 /// eventually should be eliminated.
56 bool hasReliableSymbolDifference() const {
57 return HasReliableSymbolDifference;
60 /// hasScatteredSymbols - Check whether this target supports scattered
61 /// symbols. If so, the assembler should assume that atoms can be scattered by
62 /// the linker. In particular, this means that the offsets between symbols
63 /// which are in distinct atoms is not known at link time, and the assembler
64 /// must generate fixups and relocations appropriately.
66 /// Note that the assembler currently does not reason about atoms, instead it
67 /// assumes all temporary symbols reside in the "current atom".
68 bool hasScatteredSymbols() const { return HasScatteredSymbols; }
70 /// doesSectionRequireSymbols - Check whether the given section requires that
71 /// all symbols (even temporaries) have symbol table entries.
72 virtual bool doesSectionRequireSymbols(const MCSection &Section) const {
76 /// isSectionAtomizable - Check whether the given section can be split into
79 /// \see MCAssembler::isSymbolLinkerVisible().
80 virtual bool isSectionAtomizable(const MCSection &Section) const {
84 /// getPointerSize - Get the pointer size in bytes.
85 virtual unsigned getPointerSize() const = 0;
87 /// ApplyFixup - Apply the \arg Value for given \arg Fixup into the provided
88 /// data fragment, at the offset specified by the fixup and following the
89 /// fixup kind as appropriate.
90 virtual void ApplyFixup(const MCFixup &Fixup, MCDataFragment &Fragment,
91 uint64_t Value) const = 0;
93 /// MayNeedRelaxation - Check whether the given instruction may need
96 /// \param Inst - The instruction to test.
97 virtual bool MayNeedRelaxation(const MCInst &Inst) const = 0;
99 /// RelaxInstruction - Relax the instruction in the given fragment to the next
100 /// wider instruction.
102 /// \param Inst - The instruction to relax, which may be the same as the
104 /// \parm Res [output] - On return, the relaxed instruction.
105 virtual void RelaxInstruction(const MCInst &Inst, MCInst &Res) const = 0;
107 /// WriteNopData - Write an (optimal) nop sequence of Count bytes to the given
108 /// output. If the target cannot generate such a sequence, it should return an
111 /// \return - True on success.
112 virtual bool WriteNopData(uint64_t Count, MCObjectWriter *OW) const = 0;
115 } // End llvm namespace