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 HasAbsolutizedSet : 1;
38 unsigned HasReliableSymbolDifference : 1;
39 unsigned HasScatteredSymbols : 1;
42 virtual ~TargetAsmBackend();
44 const Target &getTarget() const { return TheTarget; }
46 /// createObjectWriter - Create a new MCObjectWriter instance for use by the
47 /// assembler backend to emit the final object file.
48 virtual MCObjectWriter *createObjectWriter(raw_ostream &OS) const = 0;
50 /// hasAbsolutizedSet - Check whether this target "absolutizes"
51 /// assignments. That is, given code like:
57 /// will the value of 'tmp' be a relocatable expression, or the assembly time
58 /// value of L0 - L1. This distinction is only relevant for platforms that
59 /// support scattered symbols, since in the absence of scattered symbols (a -
60 /// b) cannot change after assembly.
61 bool hasAbsolutizedSet() const { return HasAbsolutizedSet; }
63 /// hasReliableSymbolDifference - Check whether this target implements
64 /// accurate relocations for differences between symbols. If not, differences
65 /// between symbols will always be relocatable expressions and any references
66 /// to temporary symbols will be assumed to be in the same atom, unless they
67 /// reside in a different section.
69 /// This should always be true (since it results in fewer relocations with no
70 /// loss of functionality), but is currently supported as a way to maintain
71 /// exact object compatibility with Darwin 'as' (on non-x86_64). It should
72 /// eventually should be eliminated. See also \see hasAbsolutizedSet.
73 bool hasReliableSymbolDifference() const {
74 return HasReliableSymbolDifference;
77 /// hasScatteredSymbols - Check whether this target supports scattered
78 /// symbols. If so, the assembler should assume that atoms can be scattered by
79 /// the linker. In particular, this means that the offsets between symbols
80 /// which are in distinct atoms is not known at link time, and the assembler
81 /// must generate fixups and relocations appropriately.
83 /// Note that the assembler currently does not reason about atoms, instead it
84 /// assumes all temporary symbols reside in the "current atom".
85 bool hasScatteredSymbols() const { return HasScatteredSymbols; }
87 /// doesSectionRequireSymbols - Check whether the given section requires that
88 /// all symbols (even temporaries) have symbol table entries.
89 virtual bool doesSectionRequireSymbols(const MCSection &Section) const {
93 /// isSectionAtomizable - Check whether the given section can be split into
96 /// \see MCAssembler::isSymbolLinkerVisible().
97 virtual bool isSectionAtomizable(const MCSection &Section) const {
101 /// isVirtualSection - Check whether the given section is "virtual", that is
102 /// has no actual object file contents.
103 virtual bool isVirtualSection(const MCSection &Section) const = 0;
105 /// ApplyFixup - Apply the \arg Value for given \arg Fixup into the provided
106 /// data fragment, at the offset specified by the fixup and following the
107 /// fixup kind as appropriate.
108 virtual void ApplyFixup(const MCAsmFixup &Fixup, MCDataFragment &Fragment,
109 uint64_t Value) const = 0;
111 /// MayNeedRelaxation - Check whether the given instruction may need
114 /// \arg Inst - The instruction to test.
115 /// \arg Fixups - The actual fixups this instruction encoded to, for potential
116 /// use by the target backend.
117 virtual bool MayNeedRelaxation(const MCInst &Inst,
118 const SmallVectorImpl<MCAsmFixup> &Fixups) const = 0;
120 /// RelaxInstruction - Relax the instruction in the given fragment to the next
121 /// wider instruction.
122 virtual void RelaxInstruction(const MCInstFragment *IF,
123 MCInst &Res) const = 0;
125 /// WriteNopData - Write an (optimal) nop sequence of Count bytes to the given
126 /// output. If the target cannot generate such a sequence, it should return an
129 /// \return - True on success.
130 virtual bool WriteNopData(uint64_t Count, MCObjectWriter *OW) const = 0;
133 } // End llvm namespace