Remove training whitespace.
[oota-llvm.git] / include / llvm / Target / TargetLoweringObjectFile.h
1 //===-- llvm/Target/TargetLoweringObjectFile.h - Object Info ----*- 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 // This file implements classes used to handle lowerings specific to common
11 // object file formats.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #ifndef LLVM_TARGET_TARGETLOWERINGOBJECTFILE_H
16 #define LLVM_TARGET_TARGETLOWERINGOBJECTFILE_H
17
18 #include "llvm/ADT/ArrayRef.h"
19 #include "llvm/IR/Module.h"
20 #include "llvm/MC/MCObjectFileInfo.h"
21 #include "llvm/MC/SectionKind.h"
22
23 namespace llvm {
24   class MachineModuleInfo;
25   class Mangler;
26   class MCContext;
27   class MCExpr;
28   class MCSection;
29   class MCSymbol;
30   class MCSymbolRefExpr;
31   class MCStreamer;
32   class ConstantExpr;
33   class GlobalValue;
34   class TargetMachine;
35
36 class TargetLoweringObjectFile : public MCObjectFileInfo {
37   MCContext *Ctx;
38   const DataLayout *DL;
39
40   TargetLoweringObjectFile(
41     const TargetLoweringObjectFile&) LLVM_DELETED_FUNCTION;
42   void operator=(const TargetLoweringObjectFile&) LLVM_DELETED_FUNCTION;
43
44 public:
45   MCContext &getContext() const { return *Ctx; }
46
47   TargetLoweringObjectFile() : MCObjectFileInfo(), Ctx(0), DL(0) {}
48
49   virtual ~TargetLoweringObjectFile();
50
51   /// Initialize - this method must be called before any actual lowering is
52   /// done.  This specifies the current context for codegen, and gives the
53   /// lowering implementations a chance to set up their default sections.
54   virtual void Initialize(MCContext &ctx, const TargetMachine &TM);
55
56   virtual void emitPersonalityValue(MCStreamer &Streamer,
57                                     const TargetMachine &TM,
58                                     const MCSymbol *Sym) const;
59
60   /// getDepLibFromLinkerOpt - Extract the dependent library name from a linker
61   /// option string. Returns StringRef() if the option does not specify a library.
62   virtual StringRef getDepLibFromLinkerOpt(StringRef LinkerOption) const {
63     return StringRef();
64   }
65
66   /// emitModuleFlags - Emit the module flags that the platform cares about.
67   virtual void emitModuleFlags(MCStreamer &,
68                                ArrayRef<Module::ModuleFlagEntry>,
69                                Mangler *, const TargetMachine &) const {
70   }
71
72   /// shouldEmitUsedDirectiveFor - This hook allows targets to selectively
73   /// decide not to emit the UsedDirective for some symbols in llvm.used.
74   /// FIXME: REMOVE this (rdar://7071300)
75   virtual bool shouldEmitUsedDirectiveFor(const GlobalValue *GV,
76                                           Mangler *) const {
77     return GV != 0;
78   }
79
80   /// getSectionForConstant - Given a constant with the SectionKind, return a
81   /// section that it should be placed in.
82   virtual const MCSection *getSectionForConstant(SectionKind Kind) const;
83
84   /// getKindForGlobal - Classify the specified global variable into a set of
85   /// target independent categories embodied in SectionKind.
86   static SectionKind getKindForGlobal(const GlobalValue *GV,
87                                       const TargetMachine &TM);
88
89   /// SectionForGlobal - This method computes the appropriate section to emit
90   /// the specified global variable or function definition.  This should not
91   /// be passed external (or available externally) globals.
92   const MCSection *SectionForGlobal(const GlobalValue *GV,
93                                     SectionKind Kind, Mangler *Mang,
94                                     const TargetMachine &TM) const;
95
96   /// SectionForGlobal - This method computes the appropriate section to emit
97   /// the specified global variable or function definition.  This should not
98   /// be passed external (or available externally) globals.
99   const MCSection *SectionForGlobal(const GlobalValue *GV,
100                                     Mangler *Mang,
101                                     const TargetMachine &TM) const {
102     return SectionForGlobal(GV, getKindForGlobal(GV, TM), Mang, TM);
103   }
104
105   /// getExplicitSectionGlobal - Targets should implement this method to assign
106   /// a section to globals with an explicit section specfied.  The
107   /// implementation of this method can assume that GV->hasSection() is true.
108   virtual const MCSection *
109   getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
110                            Mangler *Mang, const TargetMachine &TM) const = 0;
111
112   /// getSpecialCasedSectionGlobals - Allow the target to completely override
113   /// section assignment of a global.
114   virtual const MCSection *
115   getSpecialCasedSectionGlobals(const GlobalValue *GV, Mangler *Mang,
116                                 SectionKind Kind) const {
117     return 0;
118   }
119
120   /// getTTypeGlobalReference - Return an MCExpr to use for a reference
121   /// to the specified global variable from exception handling information.
122   ///
123   virtual const MCExpr *
124   getTTypeGlobalReference(const GlobalValue *GV, Mangler *Mang,
125                           MachineModuleInfo *MMI, unsigned Encoding,
126                           MCStreamer &Streamer) const;
127
128   /// Return the MCSymbol for the specified global value.  This symbol is the
129   /// main label that is the address of the global
130   MCSymbol *getSymbol(Mangler &M, const GlobalValue *GV) const;
131
132   /// Return the MCSymbol for a private symbol with global value name as its
133   /// base, with the specified suffix.
134   MCSymbol *getSymbolWithGlobalValueBase(Mangler &M, const GlobalValue *GV,
135                                          StringRef Suffix) const;
136
137   // getCFIPersonalitySymbol - The symbol that gets passed to .cfi_personality.
138   virtual MCSymbol *
139   getCFIPersonalitySymbol(const GlobalValue *GV, Mangler *Mang,
140                           MachineModuleInfo *MMI) const;
141
142   ///
143   const MCExpr *
144   getTTypeReference(const MCSymbolRefExpr *Sym, unsigned Encoding,
145                     MCStreamer &Streamer) const;
146
147   virtual const MCSection *
148   getStaticCtorSection(unsigned Priority = 65535) const {
149     (void)Priority;
150     return StaticCtorSection;
151   }
152   virtual const MCSection *
153   getStaticDtorSection(unsigned Priority = 65535) const {
154     (void)Priority;
155     return StaticDtorSection;
156   }
157
158   /// \brief Create a symbol reference to describe the given TLS variable when
159   /// emitting the address in debug info.
160   virtual const MCExpr *getDebugThreadLocalSymbol(const MCSymbol *Sym) const;
161
162   virtual const MCExpr *
163   getExecutableRelativeSymbol(const ConstantExpr *CE, Mangler *Mang) const {
164     return 0;
165   }
166
167 protected:
168   virtual const MCSection *
169   SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
170                          Mangler *Mang, const TargetMachine &TM) const;
171 };
172
173 } // end namespace llvm
174
175 #endif