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