15a956b0a62928d7ece576c7c5e12bf236882b76
[oota-llvm.git] / include / llvm / MC / MCAsmBackend.h
1 //===-- llvm/MC/MCAsmBackend.h - MC 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_MC_MCASMBACKEND_H
11 #define LLVM_MC_MCASMBACKEND_H
12
13 #include "llvm/ADT/ArrayRef.h"
14 #include "llvm/MC/MCDirectives.h"
15 #include "llvm/MC/MCDwarf.h"
16 #include "llvm/MC/MCFixup.h"
17 #include "llvm/Support/DataTypes.h"
18 #include "llvm/Support/ErrorHandling.h"
19
20 namespace llvm {
21 class MCAsmLayout;
22 class MCAssembler;
23 class MCELFObjectTargetWriter;
24 struct MCFixupKindInfo;
25 class MCFragment;
26 class MCInst;
27 class MCRelaxableFragment;
28 class MCObjectWriter;
29 class MCSection;
30 class MCValue;
31 class raw_ostream;
32
33 /// MCAsmBackend - Generic interface to target specific assembler backends.
34 class MCAsmBackend {
35   MCAsmBackend(const MCAsmBackend &) LLVM_DELETED_FUNCTION;
36   void operator=(const MCAsmBackend &) LLVM_DELETED_FUNCTION;
37
38 protected: // Can only create subclasses.
39   MCAsmBackend();
40
41   unsigned HasDataInCodeSupport : 1;
42
43 public:
44   virtual ~MCAsmBackend();
45
46   /// lifetime management
47   virtual void reset() {}
48
49   /// createObjectWriter - Create a new MCObjectWriter instance for use by the
50   /// assembler backend to emit the final object file.
51   virtual MCObjectWriter *createObjectWriter(raw_ostream &OS) const = 0;
52
53   /// createELFObjectTargetWriter - Create a new ELFObjectTargetWriter to enable
54   /// non-standard ELFObjectWriters.
55   virtual MCELFObjectTargetWriter *createELFObjectTargetWriter() const {
56     llvm_unreachable("createELFObjectTargetWriter is not supported by asm "
57                      "backend");
58   }
59
60   /// hasDataInCodeSupport - Check whether this target implements data-in-code
61   /// markers. If not, data region directives will be ignored.
62   bool hasDataInCodeSupport() const { return HasDataInCodeSupport; }
63
64   /// doesSectionRequireSymbols - Check whether the given section requires that
65   /// all symbols (even temporaries) have symbol table entries.
66   virtual bool doesSectionRequireSymbols(const MCSection &Section) const {
67     return false;
68   }
69
70   /// isSectionAtomizable - Check whether the given section can be split into
71   /// atoms.
72   ///
73   /// \see MCAssembler::isSymbolLinkerVisible().
74   virtual bool isSectionAtomizable(const MCSection &Section) const {
75     return true;
76   }
77
78   /// @name Target Fixup Interfaces
79   /// @{
80
81   /// getNumFixupKinds - Get the number of target specific fixup kinds.
82   virtual unsigned getNumFixupKinds() const = 0;
83
84   /// getFixupKindInfo - Get information on a fixup kind.
85   virtual const MCFixupKindInfo &getFixupKindInfo(MCFixupKind Kind) const;
86
87   /// processFixupValue - Target hook to adjust the literal value of a fixup
88   /// if necessary. IsResolved signals whether the caller believes a relocation
89   /// is needed; the target can modify the value. The default does nothing.
90   virtual void processFixupValue(const MCAssembler &Asm,
91                                  const MCAsmLayout &Layout,
92                                  const MCFixup &Fixup, const MCFragment *DF,
93                                  const MCValue &Target, uint64_t &Value,
94                                  bool &IsResolved) {}
95
96   /// applyFixup - Apply the \p Value for given \p Fixup into the provided
97   /// data fragment, at the offset specified by the fixup and following the
98   /// fixup kind as appropriate.
99   virtual void applyFixup(const MCFixup &Fixup, char *Data, unsigned DataSize,
100                           uint64_t Value, bool IsPCRel) const = 0;
101
102   /// @}
103
104   /// @name Target Relaxation Interfaces
105   /// @{
106
107   /// mayNeedRelaxation - Check whether the given instruction may need
108   /// relaxation.
109   ///
110   /// \param Inst - The instruction to test.
111   virtual bool mayNeedRelaxation(const MCInst &Inst) const = 0;
112
113   /// fixupNeedsRelaxation - Target specific predicate for whether a given
114   /// fixup requires the associated instruction to be relaxed.
115   virtual bool fixupNeedsRelaxation(const MCFixup &Fixup, uint64_t Value,
116                                     const MCRelaxableFragment *DF,
117                                     const MCAsmLayout &Layout) const = 0;
118
119   /// RelaxInstruction - Relax the instruction in the given fragment to the next
120   /// wider instruction.
121   ///
122   /// \param Inst The instruction to relax, which may be the same as the
123   /// output.
124   /// \param [out] Res On return, the relaxed instruction.
125   virtual void relaxInstruction(const MCInst &Inst, MCInst &Res) const = 0;
126
127   /// @}
128
129   /// getMinimumNopSize - Returns the minimum size of a nop in bytes on this
130   /// target. The assembler will use this to emit excess padding in situations
131   /// where the padding required for simple alignment would be less than the
132   /// minimum nop size.
133   ///
134   virtual unsigned getMinimumNopSize() const { return 1; }
135
136   /// writeNopData - Write an (optimal) nop sequence of Count bytes to the given
137   /// output. If the target cannot generate such a sequence, it should return an
138   /// error.
139   ///
140   /// \return - True on success.
141   virtual bool writeNopData(uint64_t Count, MCObjectWriter *OW) const = 0;
142
143   /// handleAssemblerFlag - Handle any target-specific assembler flags.
144   /// By default, do nothing.
145   virtual void handleAssemblerFlag(MCAssemblerFlag Flag) {}
146
147   /// \brief Generate the compact unwind encoding for the CFI instructions.
148   virtual uint32_t
149       generateCompactUnwindEncoding(ArrayRef<MCCFIInstruction>) const {
150     return 0;
151   }
152 };
153
154 } // End llvm namespace
155
156 #endif