Pass the Mangler by reference.
[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 &Streamer,
68                                ArrayRef<Module::ModuleFlagEntry> Flags,
69                                Mangler &Mang, const TargetMachine &TM) const {}
70
71   /// This hook allows targets to selectively decide not to emit the
72   /// UsedDirective for some symbols in llvm.used.
73   /// FIXME: REMOVE this (rdar://7071300)
74   virtual bool shouldEmitUsedDirectiveFor(const GlobalValue *GV,
75                                           Mangler &Mang) const {
76     return GV != 0;
77   }
78
79   /// Given a constant with the SectionKind, return a section that it should be
80   /// placed in.
81   virtual const MCSection *getSectionForConstant(SectionKind Kind) const;
82
83   /// Classify the specified global variable into a set of target independent
84   /// categories embodied in SectionKind.
85   static SectionKind getKindForGlobal(const GlobalValue *GV,
86                                       const TargetMachine &TM);
87
88   /// This method computes the appropriate section to emit the specified global
89   /// variable or function definition. This should not be passed external (or
90   /// available externally) globals.
91   const MCSection *SectionForGlobal(const GlobalValue *GV,
92                                     SectionKind Kind, Mangler &Mang,
93                                     const TargetMachine &TM) const;
94
95   /// This method computes the appropriate section to emit the specified global
96   /// variable or function definition. This should not be passed external (or
97   /// available externally) globals.
98   const MCSection *SectionForGlobal(const GlobalValue *GV,
99                                     Mangler &Mang,
100                                     const TargetMachine &TM) const {
101     return SectionForGlobal(GV, getKindForGlobal(GV, TM), Mang, TM);
102   }
103
104   /// Targets should implement this method to assign a section to globals with
105   /// an explicit section specfied. The implementation of this method can
106   /// assume that GV->hasSection() is true.
107   virtual const MCSection *
108   getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
109                            Mangler &Mang, const TargetMachine &TM) const = 0;
110
111   /// Allow the target to completely override section assignment of a global.
112   virtual const MCSection *
113   getSpecialCasedSectionGlobals(const GlobalValue *GV, Mangler &Mang,
114                                 SectionKind Kind) const {
115     return 0;
116   }
117
118   /// Return an MCExpr to use for a reference to the specified global variable
119   /// from exception handling information.
120   virtual const MCExpr *
121   getTTypeGlobalReference(const GlobalValue *GV, Mangler &Mang,
122                           MachineModuleInfo *MMI, unsigned Encoding,
123                           MCStreamer &Streamer) const;
124
125   /// Return the MCSymbol for the specified global value. This symbol is the
126   /// main label that is the address of the global
127   MCSymbol *getSymbol(Mangler &M, const GlobalValue *GV) const;
128
129   /// Return the MCSymbol for a private symbol with global value name as its
130   /// base, with the specified suffix.
131   MCSymbol *getSymbolWithGlobalValueBase(Mangler &M, const GlobalValue *GV,
132                                          StringRef Suffix) const;
133
134   // The symbol that gets passed to .cfi_personality.
135   virtual MCSymbol *
136   getCFIPersonalitySymbol(const GlobalValue *GV, Mangler &Mang,
137                           MachineModuleInfo *MMI) const;
138
139   const MCExpr *
140   getTTypeReference(const MCSymbolRefExpr *Sym, unsigned Encoding,
141                     MCStreamer &Streamer) const;
142
143   virtual const MCSection *
144   getStaticCtorSection(unsigned Priority = 65535) const {
145     (void)Priority;
146     return StaticCtorSection;
147   }
148   virtual const MCSection *
149   getStaticDtorSection(unsigned Priority = 65535) const {
150     (void)Priority;
151     return StaticDtorSection;
152   }
153
154   /// \brief Create a symbol reference to describe the given TLS variable when
155   /// emitting the address in debug info.
156   virtual const MCExpr *getDebugThreadLocalSymbol(const MCSymbol *Sym) const;
157
158   virtual const MCExpr *
159   getExecutableRelativeSymbol(const ConstantExpr *CE, Mangler &Mang) const {
160     return 0;
161   }
162
163 protected:
164   virtual const MCSection *
165   SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
166                          Mangler &Mang, const TargetMachine &TM) const;
167 };
168
169 } // end namespace llvm
170
171 #endif