MC/Mach-O/x86_64: Add a new hook for checking whether a particular section can
[oota-llvm.git] / include / llvm / Target / TargetAsmBackend.h
1 //===-- llvm/Target/TargetAsmBackend.h - Target 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_TARGET_TARGETASMBACKEND_H
11 #define LLVM_TARGET_TARGETASMBACKEND_H
12
13 #include "llvm/System/DataTypes.h"
14
15 namespace llvm {
16 class MCAsmFixup;
17 class MCDataFragment;
18 class MCInst;
19 class MCInstFragment;
20 class MCObjectWriter;
21 class MCSection;
22 template<typename T>
23 class SmallVectorImpl;
24 class Target;
25 class raw_ostream;
26
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 &);
33
34   /// TheTarget - The Target that this machine was created for.
35   const Target &TheTarget;
36
37   unsigned HasAbsolutizedSet : 1;
38   unsigned HasReliableSymbolDifference : 1;
39   unsigned HasScatteredSymbols : 1;
40
41 public:
42   virtual ~TargetAsmBackend();
43
44   const Target &getTarget() const { return TheTarget; }
45
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;
49
50   /// hasAbsolutizedSet - Check whether this target "absolutizes"
51   /// assignments. That is, given code like:
52   ///   a:
53   ///   ...
54   ///   b:
55   ///   tmp = a - b
56   ///       .long tmp
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; }
62
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.
68   ///
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;
75   }
76
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.
82   ///
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; }
86
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 {
90     return false;
91   }
92
93   /// isSectionAtomizable - Check whether the given section can be split into
94   /// atoms.
95   ///
96   /// \see MCAssembler::isSymbolLinkerVisible().
97   virtual bool isSectionAtomizable(const MCSection &Section) const {
98     return true;
99   }
100
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;
104
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;
110
111   /// MayNeedRelaxation - Check whether the given instruction may need
112   /// relaxation.
113   ///
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;
119
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;
124
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
127   /// error.
128   ///
129   /// \return - True on success.
130   virtual bool WriteNopData(uint64_t Count, MCObjectWriter *OW) const = 0;
131 };
132
133 } // End llvm namespace
134
135 #endif