Coverage Report

Created: 2018-11-16 02:38

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/include/llvm/CodeGen/TargetPassConfig.h
Line
Count
Source (jump to first uncovered line)
1
//===- TargetPassConfig.h - Code Generation pass options --------*- 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
/// Target-Independent Code Generator Pass Configuration Options pass.
11
//
12
//===----------------------------------------------------------------------===//
13
14
#ifndef LLVM_CODEGEN_TARGETPASSCONFIG_H
15
#define LLVM_CODEGEN_TARGETPASSCONFIG_H
16
17
#include "llvm/Pass.h"
18
#include "llvm/Support/CodeGen.h"
19
#include <cassert>
20
#include <string>
21
22
namespace llvm {
23
24
class LLVMTargetMachine;
25
struct MachineSchedContext;
26
class PassConfigImpl;
27
class ScheduleDAGInstrs;
28
29
// The old pass manager infrastructure is hidden in a legacy namespace now.
30
namespace legacy {
31
32
class PassManagerBase;
33
34
} // end namespace legacy
35
36
using legacy::PassManagerBase;
37
38
/// Discriminated union of Pass ID types.
39
///
40
/// The PassConfig API prefers dealing with IDs because they are safer and more
41
/// efficient. IDs decouple configuration from instantiation. This way, when a
42
/// pass is overriden, it isn't unnecessarily instantiated. It is also unsafe to
43
/// refer to a Pass pointer after adding it to a pass manager, which deletes
44
/// redundant pass instances.
45
///
46
/// However, it is convient to directly instantiate target passes with
47
/// non-default ctors. These often don't have a registered PassInfo. Rather than
48
/// force all target passes to implement the pass registry boilerplate, allow
49
/// the PassConfig API to handle either type.
50
///
51
/// AnalysisID is sadly char*, so PointerIntPair won't work.
52
class IdentifyingPassPtr {
53
  union {
54
    AnalysisID ID;
55
    Pass *P;
56
  };
57
  bool IsInstance = false;
58
59
public:
60
40.6k
  IdentifyingPassPtr() : P(nullptr) {}
61
1.40M
  IdentifyingPassPtr(AnalysisID IDPtr) : ID(IDPtr) {}
62
  IdentifyingPassPtr(Pass *InstancePtr) : P(InstancePtr), IsInstance(true) {}
63
64
1.40M
  bool isValid() const { return P; }
65
1.40M
  bool isInstance() const { return IsInstance; }
66
67
1.40M
  AnalysisID getID() const {
68
1.40M
    assert(!IsInstance && "Not a Pass ID");
69
1.40M
    return ID;
70
1.40M
  }
71
72
0
  Pass *getInstance() const {
73
0
    assert(IsInstance && "Not a Pass Instance");
74
0
    return P;
75
0
  }
76
};
77
78
template <> struct isPodLike<IdentifyingPassPtr> {
79
  static const bool value = true;
80
};
81
82
/// Target-Independent Code Generator Pass Configuration Options.
83
///
84
/// This is an ImmutablePass solely for the purpose of exposing CodeGen options
85
/// to the internals of other CodeGen passes.
86
class TargetPassConfig : public ImmutablePass {
87
private:
88
  PassManagerBase *PM = nullptr;
89
  AnalysisID StartBefore = nullptr;
90
  AnalysisID StartAfter = nullptr;
91
  AnalysisID StopBefore = nullptr;
92
  AnalysisID StopAfter = nullptr;
93
  bool Started = true;
94
  bool Stopped = false;
95
  bool AddingMachinePasses = false;
96
97
  /// Set the StartAfter, StartBefore and StopAfter passes to allow running only
98
  /// a portion of the normal code-gen pass sequence.
99
  ///
100
  /// If the StartAfter and StartBefore pass ID is zero, then compilation will
101
  /// begin at the normal point; otherwise, clear the Started flag to indicate
102
  /// that passes should not be added until the starting pass is seen.  If the
103
  /// Stop pass ID is zero, then compilation will continue to the end.
104
  ///
105
  /// This function expects that at least one of the StartAfter or the
106
  /// StartBefore pass IDs is null.
107
  void setStartStopPasses();
108
109
protected:
110
  LLVMTargetMachine *TM;
111
  PassConfigImpl *Impl = nullptr; // Internal data structures
112
  bool Initialized = false; // Flagged after all passes are configured.
113
114
  // Target Pass Options
115
  // Targets provide a default setting, user flags override.
116
  bool DisableVerify = false;
117
118
  /// Default setting for -enable-tail-merge on this target.
119
  bool EnableTailMerge = true;
120
121
  /// Require processing of functions such that callees are generated before
122
  /// callers.
123
  bool RequireCodeGenSCCOrder = false;
124
125
  /// Add the actual instruction selection passes. This does not include
126
  /// preparation passes on IR.
127
  bool addCoreISelPasses();
128
129
public:
130
  TargetPassConfig(LLVMTargetMachine &TM, PassManagerBase &pm);
131
  // Dummy constructor.
132
  TargetPassConfig();
133
134
  ~TargetPassConfig() override;
135
136
  static char ID;
137
138
  /// Get the right type of TargetMachine for this target.
139
3.31M
  template<typename TMC> TMC &getTM() const {
140
3.31M
    return *static_cast<TMC*>(TM);
141
3.31M
  }
llvm::AArch64TargetMachine& llvm::TargetPassConfig::getTM<llvm::AArch64TargetMachine>() const
Line
Count
Source
139
263k
  template<typename TMC> TMC &getTM() const {
140
263k
    return *static_cast<TMC*>(TM);
141
263k
  }
llvm::TargetMachine& llvm::TargetPassConfig::getTM<llvm::TargetMachine>() const
Line
Count
Source
139
2.95M
  template<typename TMC> TMC &getTM() const {
140
2.95M
    return *static_cast<TMC*>(TM);
141
2.95M
  }
llvm::AMDGPUTargetMachine& llvm::TargetPassConfig::getTM<llvm::AMDGPUTargetMachine>() const
Line
Count
Source
139
24.6k
  template<typename TMC> TMC &getTM() const {
140
24.6k
    return *static_cast<TMC*>(TM);
141
24.6k
  }
Unexecuted instantiation: llvm::GCNTargetMachine& llvm::TargetPassConfig::getTM<llvm::GCNTargetMachine>() const
llvm::ARMBaseTargetMachine& llvm::TargetPassConfig::getTM<llvm::ARMBaseTargetMachine>() const
Line
Count
Source
139
4.92k
  template<typename TMC> TMC &getTM() const {
140
4.92k
    return *static_cast<TMC*>(TM);
141
4.92k
  }
llvm::BPFTargetMachine& llvm::TargetPassConfig::getTM<llvm::BPFTargetMachine>() const
Line
Count
Source
139
195
  template<typename TMC> TMC &getTM() const {
140
195
    return *static_cast<TMC*>(TM);
141
195
  }
llvm::HexagonTargetMachine& llvm::TargetPassConfig::getTM<llvm::HexagonTargetMachine>() const
Line
Count
Source
139
909
  template<typename TMC> TMC &getTM() const {
140
909
    return *static_cast<TMC*>(TM);
141
909
  }
llvm::LanaiTargetMachine& llvm::TargetPassConfig::getTM<llvm::LanaiTargetMachine>() const
Line
Count
Source
139
42
  template<typename TMC> TMC &getTM() const {
140
42
    return *static_cast<TMC*>(TM);
141
42
  }
llvm::MipsTargetMachine& llvm::TargetPassConfig::getTM<llvm::MipsTargetMachine>() const
Line
Count
Source
139
22.4k
  template<typename TMC> TMC &getTM() const {
140
22.4k
    return *static_cast<TMC*>(TM);
141
22.4k
  }
llvm::MSP430TargetMachine& llvm::TargetPassConfig::getTM<llvm::MSP430TargetMachine>() const
Line
Count
Source
139
63
  template<typename TMC> TMC &getTM() const {
140
63
    return *static_cast<TMC*>(TM);
141
63
  }
llvm::NVPTXTargetMachine& llvm::TargetPassConfig::getTM<llvm::NVPTXTargetMachine>() const
Line
Count
Source
139
988
  template<typename TMC> TMC &getTM() const {
140
988
    return *static_cast<TMC*>(TM);
141
988
  }
llvm::PPCTargetMachine& llvm::TargetPassConfig::getTM<llvm::PPCTargetMachine>() const
Line
Count
Source
139
22.2k
  template<typename TMC> TMC &getTM() const {
140
22.2k
    return *static_cast<TMC*>(TM);
141
22.2k
  }
llvm::SparcTargetMachine& llvm::TargetPassConfig::getTM<llvm::SparcTargetMachine>() const
Line
Count
Source
139
780
  template<typename TMC> TMC &getTM() const {
140
780
    return *static_cast<TMC*>(TM);
141
780
  }
llvm::SystemZTargetMachine& llvm::TargetPassConfig::getTM<llvm::SystemZTargetMachine>() const
Line
Count
Source
139
5.35k
  template<typename TMC> TMC &getTM() const {
140
5.35k
    return *static_cast<TMC*>(TM);
141
5.35k
  }
llvm::WebAssemblyTargetMachine& llvm::TargetPassConfig::getTM<llvm::WebAssemblyTargetMachine>() const
Line
Count
Source
139
321
  template<typename TMC> TMC &getTM() const {
140
321
    return *static_cast<TMC*>(TM);
141
321
  }
llvm::X86TargetMachine& llvm::TargetPassConfig::getTM<llvm::X86TargetMachine>() const
Line
Count
Source
139
11.6k
  template<typename TMC> TMC &getTM() const {
140
11.6k
    return *static_cast<TMC*>(TM);
141
11.6k
  }
llvm::XCoreTargetMachine& llvm::TargetPassConfig::getTM<llvm::XCoreTargetMachine>() const
Line
Count
Source
139
69
  template<typename TMC> TMC &getTM() const {
140
69
    return *static_cast<TMC*>(TM);
141
69
  }
142
143
  //
144
34.9k
  void setInitialized() { Initialized = true; }
145
146
  CodeGenOpt::Level getOptLevel() const;
147
148
  /// Returns true if one of the `-start-after`, `-start-before`, `-stop-after`
149
  /// or `-stop-before` options is set.
150
  static bool hasLimitedCodeGenPipeline();
151
152
  /// Returns true if none of the `-stop-before` and `-stop-after` options is
153
  /// set.
154
  static bool willCompleteCodeGenPipeline();
155
156
  /// If hasLimitedCodeGenPipeline is true, this method
157
  /// returns a string with the name of the options, separated
158
  /// by \p Separator that caused this pipeline to be limited.
159
  std::string
160
  getLimitedCodeGenPipelineReason(const char *Separator = "/") const;
161
162
34.9k
  void setDisableVerify(bool Disable) { setOpt(DisableVerify, Disable); }
163
164
613k
  bool getEnableTailMerge() const { return EnableTailMerge; }
165
0
  void setEnableTailMerge(bool Enable) { setOpt(EnableTailMerge, Enable); }
166
167
33.8k
  bool requiresCodeGenSCCOrder() const { return RequireCodeGenSCCOrder; }
168
4.86k
  void setRequiresCodeGenSCCOrder(bool Enable = true) {
169
4.86k
    setOpt(RequireCodeGenSCCOrder, Enable);
170
4.86k
  }
171
172
  /// Allow the target to override a specific pass without overriding the pass
173
  /// pipeline. When passes are added to the standard pipeline at the
174
  /// point where StandardID is expected, add TargetID in its place.
175
  void substitutePass(AnalysisID StandardID, IdentifyingPassPtr TargetID);
176
177
  /// Insert InsertedPassID pass after TargetPassID pass.
178
  void insertPass(AnalysisID TargetPassID, IdentifyingPassPtr InsertedPassID,
179
                  bool VerifyAfter = true, bool PrintAfter = true);
180
181
  /// Allow the target to enable a specific standard pass by default.
182
0
  void enablePass(AnalysisID PassID) { substitutePass(PassID, PassID); }
183
184
  /// Allow the target to disable a specific standard pass by default.
185
17.3k
  void disablePass(AnalysisID PassID) {
186
17.3k
    substitutePass(PassID, IdentifyingPassPtr());
187
17.3k
  }
188
189
  /// Return the pass substituted for StandardID by the target.
190
  /// If no substitution exists, return StandardID.
191
  IdentifyingPassPtr getPassSubstitution(AnalysisID StandardID) const;
192
193
  /// Return true if the pass has been substituted by the target or
194
  /// overridden on the command line.
195
  bool isPassSubstitutedOrOverridden(AnalysisID ID) const;
196
197
  /// Return true if the optimized regalloc pipeline is enabled.
198
  bool getOptimizeRegAlloc() const;
199
200
  /// Return true if the default global register allocator is in use and
201
  /// has not be overriden on the command line with '-regalloc=...'
202
  bool usingDefaultRegAlloc() const;
203
204
  /// High level function that adds all passes necessary to go from llvm IR
205
  /// representation to the MI representation.
206
  /// Adds IR based lowering and target specific optimization passes and finally
207
  /// the core instruction selection passes.
208
  /// \returns true if an error occurred, false otherwise.
209
  bool addISelPasses();
210
211
  /// Add common target configurable passes that perform LLVM IR to IR
212
  /// transforms following machine independent optimization.
213
  virtual void addIRPasses();
214
215
  /// Add passes to lower exception handling for the code generator.
216
  void addPassesToHandleExceptions();
217
218
  /// Add pass to prepare the LLVM IR for code generation. This should be done
219
  /// before exception handling preparation passes.
220
  virtual void addCodeGenPrepare();
221
222
  /// Add common passes that perform LLVM IR to IR transforms in preparation for
223
  /// instruction selection.
224
  virtual void addISelPrepare();
225
226
  /// addInstSelector - This method should install an instruction selector pass,
227
  /// which converts from LLVM code to machine instructions.
228
321
  virtual bool addInstSelector() {
229
321
    return true;
230
321
  }
231
232
  /// This method should install an IR translator pass, which converts from
233
  /// LLVM code to machine instructions with possibly generic opcodes.
234
0
  virtual bool addIRTranslator() { return true; }
235
236
  /// This method may be implemented by targets that want to run passes
237
  /// immediately before legalization.
238
130
  virtual void addPreLegalizeMachineIR() {}
239
240
  /// This method should install a legalize pass, which converts the instruction
241
  /// sequence into one that can be selected by the target.
242
0
  virtual bool addLegalizeMachineIR() { return true; }
243
244
  /// This method may be implemented by targets that want to run passes
245
  /// immediately before the register bank selection.
246
6.83k
  virtual void addPreRegBankSelect() {}
247
248
  /// This method should install a register bank selector pass, which
249
  /// assigns register banks to virtual registers without a register
250
  /// class or register banks.
251
0
  virtual bool addRegBankSelect() { return true; }
252
253
  /// This method may be implemented by targets that want to run passes
254
  /// immediately before the (global) instruction selection.
255
130
  virtual void addPreGlobalInstructionSelect() {}
256
257
  /// This method should install a (global) instruction selector pass, which
258
  /// converts possibly generic instructions to fully target-specific
259
  /// instructions, thereby constraining all generic virtual registers to
260
  /// register classes.
261
0
  virtual bool addGlobalInstructionSelect() { return true; }
262
263
  /// Add the complete, standard set of LLVM CodeGen passes.
264
  /// Fully developed targets will not generally override this.
265
  virtual void addMachinePasses();
266
267
  /// Create an instance of ScheduleDAGInstrs to be run within the standard
268
  /// MachineScheduler pass for this function and target at the current
269
  /// optimization level.
270
  ///
271
  /// This can also be used to plug a new MachineSchedStrategy into an instance
272
  /// of the standard ScheduleDAGMI:
273
  ///   return new ScheduleDAGMI(C, make_unique<MyStrategy>(C), /*RemoveKillFlags=*/false)
274
  ///
275
  /// Return NULL to select the default (generic) machine scheduler.
276
  virtual ScheduleDAGInstrs *
277
16.7k
  createMachineScheduler(MachineSchedContext *C) const {
278
16.7k
    return nullptr;
279
16.7k
  }
280
281
  /// Similar to createMachineScheduler but used when postRA machine scheduling
282
  /// is enabled.
283
  virtual ScheduleDAGInstrs *
284
8.88k
  createPostMachineScheduler(MachineSchedContext *C) const {
285
8.88k
    return nullptr;
286
8.88k
  }
287
288
  /// printAndVerify - Add a pass to dump then verify the machine function, if
289
  /// those steps are enabled.
290
  void printAndVerify(const std::string &Banner);
291
292
  /// Add a pass to print the machine function if printing is enabled.
293
  void addPrintPass(const std::string &Banner);
294
295
  /// Add a pass to perform basic verification of the machine function if
296
  /// verification is enabled.
297
  void addVerifyPass(const std::string &Banner);
298
299
  /// Check whether or not GlobalISel should abort on error.
300
  /// When this is disabled, GlobalISel will fall back on SDISel instead of
301
  /// erroring out.
302
  bool isGlobalISelAbortEnabled() const;
303
304
  /// Check whether or not a diagnostic should be emitted when GlobalISel
305
  /// uses the fallback path. In other words, it will emit a diagnostic
306
  /// when GlobalISel failed and isGlobalISelAbortEnabled is false.
307
  virtual bool reportDiagnosticWhenGlobalISelFallback() const;
308
309
protected:
310
  // Helper to verify the analysis is really immutable.
311
  void setOpt(bool &Opt, bool Val);
312
313
  /// Methods with trivial inline returns are convenient points in the common
314
  /// codegen pass pipeline where targets may insert passes. Methods with
315
  /// out-of-line standard implementations are major CodeGen stages called by
316
  /// addMachinePasses. Some targets may override major stages when inserting
317
  /// passes is insufficient, but maintaining overriden stages is more work.
318
  ///
319
320
  /// addPreISelPasses - This method should add any "last minute" LLVM->LLVM
321
  /// passes (which are run just before instruction selector).
322
4.68k
  virtual bool addPreISel() {
323
4.68k
    return true;
324
4.68k
  }
325
326
  /// addMachineSSAOptimization - Add standard passes that optimize machine
327
  /// instructions in SSA form.
328
  virtual void addMachineSSAOptimization();
329
330
  /// Add passes that optimize instruction level parallelism for out-of-order
331
  /// targets. These passes are run while the machine code is still in SSA
332
  /// form, so they can use MachineTraceMetrics to control their heuristics.
333
  ///
334
  /// All passes added here should preserve the MachineDominatorTree,
335
  /// MachineLoopInfo, and MachineTraceMetrics analyses.
336
10.4k
  virtual bool addILPOpts() {
337
10.4k
    return false;
338
10.4k
  }
339
340
  /// This method may be implemented by targets that want to run passes
341
  /// immediately before register allocation.
342
1.87k
  virtual void addPreRegAlloc() { }
343
344
  /// createTargetRegisterAllocator - Create the register allocator pass for
345
  /// this target at the current optimization level.
346
  virtual FunctionPass *createTargetRegisterAllocator(bool Optimized);
347
348
  /// addFastRegAlloc - Add the minimum set of target-independent passes that
349
  /// are required for fast register allocation.
350
  virtual void addFastRegAlloc(FunctionPass *RegAllocPass);
351
352
  /// addOptimizedRegAlloc - Add passes related to register allocation.
353
  /// LLVMTargetMachine provides standard regalloc passes for most targets.
354
  virtual void addOptimizedRegAlloc(FunctionPass *RegAllocPass);
355
356
  /// addPreRewrite - Add passes to the optimized register allocation pipeline
357
  /// after register allocation is complete, but before virtual registers are
358
  /// rewritten to physical registers.
359
  ///
360
  /// These passes must preserve VirtRegMap and LiveIntervals, and when running
361
  /// after RABasic or RAGreedy, they should take advantage of LiveRegMatrix.
362
  /// When these passes run, VirtRegMap contains legal physreg assignments for
363
  /// all virtual registers.
364
31.6k
  virtual bool addPreRewrite() {
365
31.6k
    return false;
366
31.6k
  }
367
368
  /// This method may be implemented by targets that want to run passes after
369
  /// register allocation pass pipeline but before prolog-epilog insertion.
370
12.4k
  virtual void addPostRegAlloc() { }
371
372
  /// Add passes that optimize machine instructions after register allocation.
373
  virtual void addMachineLateOptimization();
374
375
  /// This method may be implemented by targets that want to run passes after
376
  /// prolog-epilog insertion and before the second instruction scheduling pass.
377
2.92k
  virtual void addPreSched2() { }
378
379
  /// addGCPasses - Add late codegen passes that analyze code for garbage
380
  /// collection. This should return true if GC info should be printed after
381
  /// these passes.
382
  virtual bool addGCPasses();
383
384
  /// Add standard basic block placement passes.
385
  virtual void addBlockPlacement();
386
387
  /// This pass may be implemented by targets that want to run passes
388
  /// immediately before machine code is emitted.
389
568
  virtual void addPreEmitPass() { }
390
391
  /// Targets may add passes immediately before machine code is emitted in this
392
  /// callback. This is called even later than `addPreEmitPass`.
393
  // FIXME: Rename `addPreEmitPass` to something more sensible given its actual
394
  // position and remove the `2` suffix here as this callback is what
395
  // `addPreEmitPass` *should* be but in reality isn't.
396
22.1k
  virtual void addPreEmitPass2() {}
397
398
  /// Utilities for targets to add passes to the pass manager.
399
  ///
400
401
  /// Add a CodeGen pass at this point in the pipeline after checking overrides.
402
  /// Return the pass that was added, or zero if no pass was added.
403
  /// @p printAfter    if true and adding a machine function pass add an extra
404
  ///                  machine printer pass afterwards
405
  /// @p verifyAfter   if true and adding a machine function pass add an extra
406
  ///                  machine verification pass afterwards.
407
  AnalysisID addPass(AnalysisID PassID, bool verifyAfter = true,
408
                     bool printAfter = true);
409
410
  /// Add a pass to the PassManager if that pass is supposed to be run, as
411
  /// determined by the StartAfter and StopAfter options. Takes ownership of the
412
  /// pass.
413
  /// @p printAfter    if true and adding a machine function pass add an extra
414
  ///                  machine printer pass afterwards
415
  /// @p verifyAfter   if true and adding a machine function pass add an extra
416
  ///                  machine verification pass afterwards.
417
  void addPass(Pass *P, bool verifyAfter = true, bool printAfter = true);
418
419
  /// addMachinePasses helper to create the target-selected or overriden
420
  /// regalloc pass.
421
  FunctionPass *createRegAllocPass(bool Optimized);
422
};
423
424
} // end namespace llvm
425
426
#endif // LLVM_CODEGEN_TARGETPASSCONFIG_H