Coverage Report

Created: 2018-12-11 17:59

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/include/llvm/CodeGen/MachineModuleInfo.h
Line
Count
Source (jump to first uncovered line)
1
//===-- llvm/CodeGen/MachineModuleInfo.h ------------------------*- 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
// Collect meta information for a module.  This information should be in a
11
// neutral form that can be used by different debugging and exception handling
12
// schemes.
13
//
14
// The organization of information is primarily clustered around the source
15
// compile units.  The main exception is source line correspondence where
16
// inlining may interleave code from various compile units.
17
//
18
// The following information can be retrieved from the MachineModuleInfo.
19
//
20
//  -- Source directories - Directories are uniqued based on their canonical
21
//     string and assigned a sequential numeric ID (base 1.)
22
//  -- Source files - Files are also uniqued based on their name and directory
23
//     ID.  A file ID is sequential number (base 1.)
24
//  -- Source line correspondence - A vector of file ID, line#, column# triples.
25
//     A DEBUG_LOCATION instruction is generated  by the DAG Legalizer
26
//     corresponding to each entry in the source line list.  This allows a debug
27
//     emitter to generate labels referenced by debug information tables.
28
//
29
//===----------------------------------------------------------------------===//
30
31
#ifndef LLVM_CODEGEN_MACHINEMODULEINFO_H
32
#define LLVM_CODEGEN_MACHINEMODULEINFO_H
33
34
#include "llvm/ADT/ArrayRef.h"
35
#include "llvm/ADT/DenseMap.h"
36
#include "llvm/ADT/PointerIntPair.h"
37
#include "llvm/MC/MCContext.h"
38
#include "llvm/MC/MCSymbol.h"
39
#include "llvm/Pass.h"
40
#include <memory>
41
#include <utility>
42
#include <vector>
43
44
namespace llvm {
45
46
class BasicBlock;
47
class CallInst;
48
class Function;
49
class LLVMTargetMachine;
50
class MMIAddrLabelMap;
51
class MachineFunction;
52
class Module;
53
54
//===----------------------------------------------------------------------===//
55
/// This class can be derived from and used by targets to hold private
56
/// target-specific information for each Module.  Objects of type are
57
/// accessed/created with MMI::getInfo and destroyed when the MachineModuleInfo
58
/// is destroyed.
59
///
60
class MachineModuleInfoImpl {
61
public:
62
  using StubValueTy = PointerIntPair<MCSymbol *, 1, bool>;
63
  using SymbolListTy = std::vector<std::pair<MCSymbol *, StubValueTy>>;
64
65
  virtual ~MachineModuleInfoImpl();
66
67
protected:
68
  /// Return the entries from a DenseMap in a deterministic sorted orer.
69
  /// Clears the map.
70
  static SymbolListTy getSortedStubs(DenseMap<MCSymbol*, StubValueTy>&);
71
};
72
73
//===----------------------------------------------------------------------===//
74
/// This class contains meta information specific to a module.  Queries can be
75
/// made by different debugging and exception handling schemes and reformated
76
/// for specific use.
77
///
78
class MachineModuleInfo : public ImmutablePass {
79
  const LLVMTargetMachine &TM;
80
81
  /// This is the MCContext used for the entire code generator.
82
  MCContext Context;
83
84
  /// This is the LLVM Module being worked on.
85
  const Module *TheModule;
86
87
  /// This is the object-file-format-specific implementation of
88
  /// MachineModuleInfoImpl, which lets targets accumulate whatever info they
89
  /// want.
90
  MachineModuleInfoImpl *ObjFileMMI;
91
92
  /// \name Exception Handling
93
  /// \{
94
95
  /// Vector of all personality functions ever seen. Used to emit common EH
96
  /// frames.
97
  std::vector<const Function *> Personalities;
98
99
  /// The current call site index being processed, if any. 0 if none.
100
  unsigned CurCallSite;
101
102
  /// \}
103
104
  /// This map keeps track of which symbol is being used for the specified
105
  /// basic block's address of label.
106
  MMIAddrLabelMap *AddrLabelSymbols;
107
108
  // TODO: Ideally, what we'd like is to have a switch that allows emitting
109
  // synchronous (precise at call-sites only) CFA into .eh_frame. However,
110
  // even under this switch, we'd like .debug_frame to be precise when using
111
  // -g. At this moment, there's no way to specify that some CFI directives
112
  // go into .eh_frame only, while others go into .debug_frame only.
113
114
  /// True if debugging information is available in this module.
115
  bool DbgInfoAvailable;
116
117
  /// True if this module calls VarArg function with floating-point arguments.
118
  /// This is used to emit an undefined reference to _fltused on Windows
119
  /// targets.
120
  bool UsesVAFloatArgument;
121
122
  /// True if the module calls the __morestack function indirectly, as is
123
  /// required under the large code model on x86. This is used to emit
124
  /// a definition of a symbol, __morestack_addr, containing the address. See
125
  /// comments in lib/Target/X86/X86FrameLowering.cpp for more details.
126
  bool UsesMorestackAddr;
127
128
  /// True if the module contains split-stack functions. This is used to
129
  /// emit .note.GNU-split-stack section as required by the linker for
130
  /// special handling split-stack function calling no-split-stack function.
131
  bool HasSplitStack;
132
133
  /// True if the module contains no-split-stack functions. This is used to
134
  /// emit .note.GNU-no-split-stack section when it also contains split-stack
135
  /// functions.
136
  bool HasNosplitStack;
137
138
  /// Maps IR Functions to their corresponding MachineFunctions.
139
  DenseMap<const Function*, std::unique_ptr<MachineFunction>> MachineFunctions;
140
  /// Next unique number available for a MachineFunction.
141
  unsigned NextFnNum = 0;
142
  const Function *LastRequest = nullptr; ///< Used for shortcut/cache.
143
  MachineFunction *LastResult = nullptr; ///< Used for shortcut/cache.
144
145
public:
146
  static char ID; // Pass identification, replacement for typeid
147
148
  explicit MachineModuleInfo(const LLVMTargetMachine *TM = nullptr);
149
  ~MachineModuleInfo() override;
150
151
  // Initialization and Finalization
152
  bool doInitialization(Module &) override;
153
  bool doFinalization(Module &) override;
154
155
0
  const MCContext &getContext() const { return Context; }
156
2.06M
  MCContext &getContext() { return Context; }
157
158
3.48M
  const Module *getModule() const { return TheModule; }
159
160
  /// Returns the MachineFunction constructed for the IR function \p F.
161
  /// Creates a new MachineFunction if none exists yet.
162
  MachineFunction &getOrCreateMachineFunction(const Function &F);
163
164
  /// \bried Returns the MachineFunction associated to IR function \p F if there
165
  /// is one, otherwise nullptr.
166
  MachineFunction *getMachineFunction(const Function &F) const;
167
168
  /// Delete the MachineFunction \p MF and reset the link in the IR Function to
169
  /// Machine Function map.
170
  void deleteMachineFunctionFor(Function &F);
171
172
  /// Keep track of various per-function pieces of information for backends
173
  /// that would like to do so.
174
  template<typename Ty>
175
84.0k
  Ty &getObjFileInfo() {
176
84.0k
    if (ObjFileMMI == nullptr)
177
30.0k
      ObjFileMMI = new Ty(*this);
178
84.0k
    return *static_cast<Ty*>(ObjFileMMI);
179
84.0k
  }
llvm::MachineModuleInfoCOFF& llvm::MachineModuleInfo::getObjFileInfo<llvm::MachineModuleInfoCOFF>()
Line
Count
Source
175
868
  Ty &getObjFileInfo() {
176
868
    if (ObjFileMMI == nullptr)
177
789
      ObjFileMMI = new Ty(*this);
178
868
    return *static_cast<Ty*>(ObjFileMMI);
179
868
  }
llvm::AMDGPUMachineModuleInfo& llvm::MachineModuleInfo::getObjFileInfo<llvm::AMDGPUMachineModuleInfo>()
Line
Count
Source
175
20.6k
  Ty &getObjFileInfo() {
176
20.6k
    if (ObjFileMMI == nullptr)
177
2.00k
      ObjFileMMI = new Ty(*this);
178
20.6k
    return *static_cast<Ty*>(ObjFileMMI);
179
20.6k
  }
llvm::MachineModuleInfoMachO& llvm::MachineModuleInfo::getObjFileInfo<llvm::MachineModuleInfoMachO>()
Line
Count
Source
175
45.1k
  Ty &getObjFileInfo() {
176
45.1k
    if (ObjFileMMI == nullptr)
177
11.9k
      ObjFileMMI = new Ty(*this);
178
45.1k
    return *static_cast<Ty*>(ObjFileMMI);
179
45.1k
  }
llvm::MachineModuleInfoELF& llvm::MachineModuleInfo::getObjFileInfo<llvm::MachineModuleInfoELF>()
Line
Count
Source
175
17.3k
  Ty &getObjFileInfo() {
176
17.3k
    if (ObjFileMMI == nullptr)
177
15.3k
      ObjFileMMI = new Ty(*this);
178
17.3k
    return *static_cast<Ty*>(ObjFileMMI);
179
17.3k
  }
180
181
  template<typename Ty>
182
  const Ty &getObjFileInfo() const {
183
    return const_cast<MachineModuleInfo*>(this)->getObjFileInfo<Ty>();
184
  }
185
186
  /// Returns true if valid debug info is present.
187
14.3M
  bool hasDebugInfo() const { return DbgInfoAvailable; }
188
137
  void setDebugInfoAvailability(bool avail) { DbgInfoAvailable = avail; }
189
190
41.0k
  bool usesVAFloatArgument() const {
191
41.0k
    return UsesVAFloatArgument;
192
41.0k
  }
193
194
343
  void setUsesVAFloatArgument(bool b) {
195
343
    UsesVAFloatArgument = b;
196
343
  }
197
198
38.5k
  bool usesMorestackAddr() const {
199
38.5k
    return UsesMorestackAddr;
200
38.5k
  }
201
202
7
  void setUsesMorestackAddr(bool b) {
203
7
    UsesMorestackAddr = b;
204
7
  }
205
206
17.3k
  bool hasSplitStack() const {
207
17.3k
    return HasSplitStack;
208
17.3k
  }
209
210
241
  void setHasSplitStack(bool b) {
211
241
    HasSplitStack = b;
212
241
  }
213
214
41
  bool hasNosplitStack() const {
215
41
    return HasNosplitStack;
216
41
  }
217
218
515k
  void setHasNosplitStack(bool b) {
219
515k
    HasNosplitStack = b;
220
515k
  }
221
222
  /// Return the symbol to be used for the specified basic block when its
223
  /// address is taken.  This cannot be its normal LBB label because the block
224
  /// may be accessed outside its containing function.
225
953
  MCSymbol *getAddrLabelSymbol(const BasicBlock *BB) {
226
953
    return getAddrLabelSymbolToEmit(BB).front();
227
953
  }
228
229
  /// Return the symbol to be used for the specified basic block when its
230
  /// address is taken.  If other blocks were RAUW'd to this one, we may have
231
  /// to emit them as well, return the whole set.
232
  ArrayRef<MCSymbol *> getAddrLabelSymbolToEmit(const BasicBlock *BB);
233
234
  /// If the specified function has had any references to address-taken blocks
235
  /// generated, but the block got deleted, return the symbol now so we can
236
  /// emit it.  This prevents emitting a reference to a symbol that has no
237
  /// definition.
238
  void takeDeletedSymbolsForFunction(const Function *F,
239
                                     std::vector<MCSymbol*> &Result);
240
241
  /// \name Exception Handling
242
  /// \{
243
244
  /// Set the call site currently being processed.
245
350
  void setCurrentCallSite(unsigned Site) { CurCallSite = Site; }
246
247
  /// Get the call site currently being processed, if any.  return zero if
248
  /// none.
249
24.2k
  unsigned getCurrentCallSite() { return CurCallSite; }
250
251
  /// Provide the personality function for the exception information.
252
  void addPersonality(const Function *Personality);
253
254
  /// Return array of personality functions ever seen.
255
21.2k
  const std::vector<const Function *>& getPersonalities() const {
256
21.2k
    return Personalities;
257
21.2k
  }
258
  /// \}
259
}; // End class MachineModuleInfo
260
261
//===- MMI building helpers -----------------------------------------------===//
262
263
/// Determine if any floating-point values are being passed to this variadic
264
/// function, and set the MachineModuleInfo's usesVAFloatArgument flag if so.
265
/// This flag is used to emit an undefined reference to _fltused on Windows,
266
/// which will link in MSVCRT's floating-point support.
267
void computeUsesVAFloatArgument(const CallInst &I, MachineModuleInfo &MMI);
268
269
} // end namespace llvm
270
271
#endif // LLVM_CODEGEN_MACHINEMODULEINFO_H