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/System/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.
32 TargetAsmBackend(const Target &);
34 /// TheTarget - The Target that this machine was created for.
35 const Target &TheTarget;
37 unsigned HasReliableSymbolDifference : 1;
38 unsigned HasScatteredSymbols : 1;
41 virtual ~TargetAsmBackend();
43 const Target &getTarget() const { return TheTarget; }
45 virtual const MCObjectFormat &getObjectFormat() const = 0;
47 /// createObjectWriter - Create a new MCObjectWriter instance for use by the
48 /// assembler backend to emit the final object file.
49 virtual MCObjectWriter *createObjectWriter(raw_ostream &OS) const = 0;
51 /// hasReliableSymbolDifference - Check whether this target implements
52 /// accurate relocations for differences between symbols. If not, differences
53 /// between symbols will always be relocatable expressions and any references
54 /// to temporary symbols will be assumed to be in the same atom, unless they
55 /// reside in a different section.
57 /// This should always be true (since it results in fewer relocations with no
58 /// loss of functionality), but is currently supported as a way to maintain
59 /// exact object compatibility with Darwin 'as' (on non-x86_64). It should
60 /// eventually should be eliminated.
61 bool hasReliableSymbolDifference() const {
62 return HasReliableSymbolDifference;
65 /// hasScatteredSymbols - Check whether this target supports scattered
66 /// symbols. If so, the assembler should assume that atoms can be scattered by
67 /// the linker. In particular, this means that the offsets between symbols
68 /// which are in distinct atoms is not known at link time, and the assembler
69 /// must generate fixups and relocations appropriately.
71 /// Note that the assembler currently does not reason about atoms, instead it
72 /// assumes all temporary symbols reside in the "current atom".
73 bool hasScatteredSymbols() const { return HasScatteredSymbols; }
75 /// doesSectionRequireSymbols - Check whether the given section requires that
76 /// all symbols (even temporaries) have symbol table entries.
77 virtual bool doesSectionRequireSymbols(const MCSection &Section) const {
81 /// isSectionAtomizable - Check whether the given section can be split into
84 /// \see MCAssembler::isSymbolLinkerVisible().
85 virtual bool isSectionAtomizable(const MCSection &Section) const {
89 /// getPointerSize - Get the pointer size in bytes.
90 virtual unsigned getPointerSize() const = 0;
92 /// ApplyFixup - Apply the \arg Value for given \arg Fixup into the provided
93 /// data fragment, at the offset specified by the fixup and following the
94 /// fixup kind as appropriate.
95 virtual void ApplyFixup(const MCFixup &Fixup, MCDataFragment &Fragment,
96 uint64_t Value) const = 0;
98 /// MayNeedRelaxation - Check whether the given instruction may need
101 /// \param Inst - The instruction to test.
102 virtual bool MayNeedRelaxation(const MCInst &Inst) const = 0;
104 /// RelaxInstruction - Relax the instruction in the given fragment to the next
105 /// wider instruction.
107 /// \param Inst - The instruction to relax, which may be the same as the
109 /// \parm Res [output] - On return, the relaxed instruction.
110 virtual void RelaxInstruction(const MCInst &Inst, MCInst &Res) const = 0;
112 /// WriteNopData - Write an (optimal) nop sequence of Count bytes to the given
113 /// output. If the target cannot generate such a sequence, it should return an
116 /// \return - True on success.
117 virtual bool WriteNopData(uint64_t Count, MCObjectWriter *OW) const = 0;
120 } // End llvm namespace