Comment cleanup. Don't repeat the function name in the comment.
[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   /// This method must be called before any actual lowering is done.  This
52   /// specifies the current context for codegen, and gives the lowering
53   /// 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   /// Extract the dependent library name from a linker option string. Returns
61   /// StringRef() if the option does not specify a library.
62   virtual StringRef getDepLibFromLinkerOpt(StringRef LinkerOption) const {
63     return StringRef();
64   }
65
66   /// 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   /// This hook allows targets to selectively decide not to emit the
73   /// 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   /// Given a constant with the SectionKind, return a section that it should be
81   /// placed in.
82   virtual const MCSection *getSectionForConstant(SectionKind Kind) const;
83
84   /// Classify the specified global variable into a set of target independent
85   /// categories embodied in SectionKind.
86   static SectionKind getKindForGlobal(const GlobalValue *GV,
87                                       const TargetMachine &TM);
88
89   /// This method computes the appropriate section to emit the specified global
90   /// variable or function definition. This should not be passed external (or
91   /// available externally) globals.
92   const MCSection *SectionForGlobal(const GlobalValue *GV,
93                                     SectionKind Kind, Mangler *Mang,
94                                     const TargetMachine &TM) const;
95
96   /// This method computes the appropriate section to emit the specified global
97   /// variable or function definition. This should not be passed external (or
98   /// 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   /// Targets should implement this method to assign a section to globals with
106   /// an explicit section specfied. The implementation of this method can
107   /// 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   /// Allow the target to completely override section assignment of a global.
113   virtual const MCSection *
114   getSpecialCasedSectionGlobals(const GlobalValue *GV, Mangler *Mang,
115                                 SectionKind Kind) const {
116     return 0;
117   }
118
119   /// Return an MCExpr to use for a reference to the specified global variable
120   /// from exception handling information.
121   virtual const MCExpr *
122   getTTypeGlobalReference(const GlobalValue *GV, Mangler *Mang,
123                           MachineModuleInfo *MMI, unsigned Encoding,
124                           MCStreamer &Streamer) const;
125
126   /// Return the MCSymbol for the specified global value. This symbol is the
127   /// main label that is the address of the global
128   MCSymbol *getSymbol(Mangler &M, const GlobalValue *GV) const;
129
130   /// Return the MCSymbol for a private symbol with global value name as its
131   /// base, with the specified suffix.
132   MCSymbol *getSymbolWithGlobalValueBase(Mangler &M, const GlobalValue *GV,
133                                          StringRef Suffix) const;
134
135   // The symbol that gets passed to .cfi_personality.
136   virtual MCSymbol *
137   getCFIPersonalitySymbol(const GlobalValue *GV, Mangler *Mang,
138                           MachineModuleInfo *MMI) const;
139
140   const MCExpr *
141   getTTypeReference(const MCSymbolRefExpr *Sym, unsigned Encoding,
142                     MCStreamer &Streamer) const;
143
144   virtual const MCSection *
145   getStaticCtorSection(unsigned Priority = 65535) const {
146     (void)Priority;
147     return StaticCtorSection;
148   }
149   virtual const MCSection *
150   getStaticDtorSection(unsigned Priority = 65535) const {
151     (void)Priority;
152     return StaticDtorSection;
153   }
154
155   /// \brief Create a symbol reference to describe the given TLS variable when
156   /// emitting the address in debug info.
157   virtual const MCExpr *getDebugThreadLocalSymbol(const MCSymbol *Sym) const;
158
159   virtual const MCExpr *
160   getExecutableRelativeSymbol(const ConstantExpr *CE, Mangler *Mang) const {
161     return 0;
162   }
163
164 protected:
165   virtual const MCSection *
166   SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
167                          Mangler *Mang, const TargetMachine &TM) const;
168 };
169
170 } // end namespace llvm
171
172 #endif