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/Module.h"
19#include "llvm/MC/MCObjectFileInfo.h"
20#include "llvm/MC/SectionKind.h"
21#include "llvm/ADT/ArrayRef.h"
22
23namespace llvm {
24  class MachineModuleInfo;
25  class Mangler;
26  class MCContext;
27  class MCExpr;
28  class MCSection;
29  class MCSymbol;
30  class MCStreamer;
31  class GlobalValue;
32  class TargetMachine;
33
34class TargetLoweringObjectFile : public MCObjectFileInfo {
35  MCContext *Ctx;
36
37  TargetLoweringObjectFile(
38    const TargetLoweringObjectFile&) LLVM_DELETED_FUNCTION;
39  void operator=(const TargetLoweringObjectFile&) LLVM_DELETED_FUNCTION;
40
41public:
42  MCContext &getContext() const { return *Ctx; }
43
44  TargetLoweringObjectFile() : MCObjectFileInfo(), Ctx(0) {}
45
46  virtual ~TargetLoweringObjectFile();
47
48  /// Initialize - this method must be called before any actual lowering is
49  /// done.  This specifies the current context for codegen, and gives the
50  /// lowering implementations a chance to set up their default sections.
51  virtual void Initialize(MCContext &ctx, const TargetMachine &TM);
52
53  virtual void emitPersonalityValue(MCStreamer &Streamer,
54                                    const TargetMachine &TM,
55                                    const MCSymbol *Sym) const;
56
57  /// emitModuleFlags - Emit the module flags that the platform cares about.
58  virtual void emitModuleFlags(MCStreamer &,
59                               ArrayRef<Module::ModuleFlagEntry>,
60                               Mangler *, const TargetMachine &) const {
61  }
62
63  /// shouldEmitUsedDirectiveFor - This hook allows targets to selectively
64  /// decide not to emit the UsedDirective for some symbols in llvm.used.
65  /// FIXME: REMOVE this (rdar://7071300)
66  virtual bool shouldEmitUsedDirectiveFor(const GlobalValue *GV,
67                                          Mangler *) const {
68    return GV != 0;
69  }
70
71  /// getSectionForConstant - Given a constant with the SectionKind, return a
72  /// section that it should be placed in.
73  virtual const MCSection *getSectionForConstant(SectionKind Kind) const;
74
75  /// getKindForGlobal - Classify the specified global variable into a set of
76  /// target independent categories embodied in SectionKind.
77  static SectionKind getKindForGlobal(const GlobalValue *GV,
78                                      const TargetMachine &TM);
79
80  /// SectionForGlobal - This method computes the appropriate section to emit
81  /// the specified global variable or function definition.  This should not
82  /// be passed external (or available externally) globals.
83  const MCSection *SectionForGlobal(const GlobalValue *GV,
84                                    SectionKind Kind, Mangler *Mang,
85                                    const TargetMachine &TM) const;
86
87  /// SectionForGlobal - This method computes the appropriate section to emit
88  /// the specified global variable or function definition.  This should not
89  /// be passed external (or available externally) globals.
90  const MCSection *SectionForGlobal(const GlobalValue *GV,
91                                    Mangler *Mang,
92                                    const TargetMachine &TM) const {
93    return SectionForGlobal(GV, getKindForGlobal(GV, TM), Mang, TM);
94  }
95
96  /// getExplicitSectionGlobal - Targets should implement this method to assign
97  /// a section to globals with an explicit section specfied.  The
98  /// implementation of this method can assume that GV->hasSection() is true.
99  virtual const MCSection *
100  getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
101                           Mangler *Mang, const TargetMachine &TM) const = 0;
102
103  /// getSpecialCasedSectionGlobals - Allow the target to completely override
104  /// section assignment of a global.
105  virtual const MCSection *
106  getSpecialCasedSectionGlobals(const GlobalValue *GV, Mangler *Mang,
107                                SectionKind Kind) const {
108    return 0;
109  }
110
111  /// getExprForDwarfGlobalReference - Return an MCExpr to use for a reference
112  /// to the specified global variable from exception handling information.
113  ///
114  virtual const MCExpr *
115  getExprForDwarfGlobalReference(const GlobalValue *GV, Mangler *Mang,
116                                 MachineModuleInfo *MMI, unsigned Encoding,
117                                 MCStreamer &Streamer) const;
118
119  // getCFIPersonalitySymbol - The symbol that gets passed to .cfi_personality.
120  virtual MCSymbol *
121  getCFIPersonalitySymbol(const GlobalValue *GV, Mangler *Mang,
122                          MachineModuleInfo *MMI) const;
123
124  ///
125  const MCExpr *
126  getExprForDwarfReference(const MCSymbol *Sym, unsigned Encoding,
127                           MCStreamer &Streamer) const;
128
129  virtual const MCSection *
130  getStaticCtorSection(unsigned Priority = 65535) const {
131    (void)Priority;
132    return StaticCtorSection;
133  }
134  virtual const MCSection *
135  getStaticDtorSection(unsigned Priority = 65535) const {
136    (void)Priority;
137    return StaticDtorSection;
138  }
139
140protected:
141  virtual const MCSection *
142  SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
143                         Mangler *Mang, const TargetMachine &TM) const;
144};
145
146} // end namespace llvm
147
148#endif
149