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"
22
class SmallVectorImpl;
26
/// TargetAsmBackend - Generic interface to target specific assembler backends.
27
class TargetAsmBackend {
28
TargetAsmBackend(const TargetAsmBackend &); // DO NOT IMPLEMENT
29
void operator=(const TargetAsmBackend &); // DO NOT IMPLEMENT
30
protected: // Can only create subclasses.
31
TargetAsmBackend(const Target &);
33
/// TheTarget - The Target that this machine was created for.
34
const Target &TheTarget;
36
unsigned HasAbsolutizedSet : 1;
37
unsigned HasReliableSymbolDifference : 1;
38
unsigned HasScatteredSymbols : 1;
41
virtual ~TargetAsmBackend();
43
const Target &getTarget() const { return TheTarget; }
45
/// createObjectWriter - Create a new MCObjectWriter instance for use by the
46
/// assembler backend to emit the final object file.
47
virtual MCObjectWriter *createObjectWriter(raw_ostream &OS) const = 0;
49
/// hasAbsolutizedSet - Check whether this target "absolutizes"
50
/// assignments. That is, given code like:
56
/// will the value of 'tmp' be a relocatable expression, or the assembly time
57
/// value of L0 - L1. This distinction is only relevant for platforms that
58
/// support scattered symbols, since in the absence of scattered symbols (a -
59
/// b) cannot change after assembly.
60
bool hasAbsolutizedSet() const { return HasAbsolutizedSet; }
62
/// hasReliableSymbolDifference - Check whether this target implements
63
/// accurate relocations for differences between symbols. If not, differences
64
/// between symbols will always be relocatable expressions and any references
65
/// to temporary symbols will be assumed to be in the same atom, unless they
66
/// reside in a different section.
68
/// This should always be true (since it results in fewer relocations with no
69
/// loss of functionality), but is currently supported as a way to maintain
70
/// exact object compatibility with Darwin 'as' (on non-x86_64). It should
71
/// eventually should be eliminated. See also \see hasAbsolutizedSet.
72
bool hasReliableSymbolDifference() const {
73
return HasReliableSymbolDifference;
76
/// hasScatteredSymbols - Check whether this target supports scattered
77
/// symbols. If so, the assembler should assume that atoms can be scattered by
78
/// the linker. In particular, this means that the offsets between symbols
79
/// which are in distinct atoms is not known at link time, and the assembler
80
/// must generate fixups and relocations appropriately.
82
/// Note that the assembler currently does not reason about atoms, instead it
83
/// assumes all temporary symbols reside in the "current atom".
84
bool hasScatteredSymbols() const { return HasScatteredSymbols; }
86
/// doesSectionRequireSymbols - Check whether the given section requires that
87
/// all symbols (even temporaries) have symbol table entries.
88
virtual bool doesSectionRequireSymbols(const MCSection &Section) const {
92
/// isSectionAtomizable - Check whether the given section can be split into
95
/// \see MCAssembler::isSymbolLinkerVisible().
96
virtual bool isSectionAtomizable(const MCSection &Section) const {
100
/// isVirtualSection - Check whether the given section is "virtual", that is
101
/// has no actual object file contents.
102
virtual bool isVirtualSection(const MCSection &Section) const = 0;
104
/// ApplyFixup - Apply the \arg Value for given \arg Fixup into the provided
105
/// data fragment, at the offset specified by the fixup and following the
106
/// fixup kind as appropriate.
107
virtual void ApplyFixup(const MCFixup &Fixup, MCDataFragment &Fragment,
108
uint64_t Value) const = 0;
110
/// MayNeedRelaxation - Check whether the given instruction may need
113
/// \param Inst - The instruction to test.
114
virtual bool MayNeedRelaxation(const MCInst &Inst) const = 0;
116
/// RelaxInstruction - Relax the instruction in the given fragment to the next
117
/// wider instruction.
119
/// \param Inst - The instruction to relax, which may be the same as the
121
/// \parm Res [output] - On return, the relaxed instruction.
122
virtual void RelaxInstruction(const MCInst &Inst, MCInst &Res) const = 0;
124
/// WriteNopData - Write an (optimal) nop sequence of Count bytes to the given
125
/// output. If the target cannot generate such a sequence, it should return an
128
/// \return - True on success.
129
virtual bool WriteNopData(uint64_t Count, MCObjectWriter *OW) const = 0;
132
} // End llvm namespace