Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/lib/Passes/PassBuilder.cpp
Line
Count
Source (jump to first uncovered line)
1
//===- Parsing, selection, and construction of pass pipelines -------------===//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
/// \file
9
///
10
/// This file provides the implementation of the PassBuilder based on our
11
/// static pass registry as well as related functionality. It also provides
12
/// helpers to aid in analyzing, debugging, and testing passes and pass
13
/// pipelines.
14
///
15
//===----------------------------------------------------------------------===//
16
17
#include "llvm/Passes/PassBuilder.h"
18
#include "llvm/ADT/StringSwitch.h"
19
#include "llvm/Analysis/AliasAnalysis.h"
20
#include "llvm/Analysis/AliasAnalysisEvaluator.h"
21
#include "llvm/Analysis/AssumptionCache.h"
22
#include "llvm/Analysis/BasicAliasAnalysis.h"
23
#include "llvm/Analysis/BlockFrequencyInfo.h"
24
#include "llvm/Analysis/BranchProbabilityInfo.h"
25
#include "llvm/Analysis/CFGPrinter.h"
26
#include "llvm/Analysis/CFLAndersAliasAnalysis.h"
27
#include "llvm/Analysis/CFLSteensAliasAnalysis.h"
28
#include "llvm/Analysis/CGSCCPassManager.h"
29
#include "llvm/Analysis/CallGraph.h"
30
#include "llvm/Analysis/DemandedBits.h"
31
#include "llvm/Analysis/DependenceAnalysis.h"
32
#include "llvm/Analysis/DominanceFrontier.h"
33
#include "llvm/Analysis/GlobalsModRef.h"
34
#include "llvm/Analysis/IVUsers.h"
35
#include "llvm/Analysis/LazyCallGraph.h"
36
#include "llvm/Analysis/LazyValueInfo.h"
37
#include "llvm/Analysis/LoopAccessAnalysis.h"
38
#include "llvm/Analysis/LoopInfo.h"
39
#include "llvm/Analysis/MemoryDependenceAnalysis.h"
40
#include "llvm/Analysis/MemorySSA.h"
41
#include "llvm/Analysis/ModuleSummaryAnalysis.h"
42
#include "llvm/Analysis/OptimizationRemarkEmitter.h"
43
#include "llvm/Analysis/PhiValues.h"
44
#include "llvm/Analysis/PostDominators.h"
45
#include "llvm/Analysis/ProfileSummaryInfo.h"
46
#include "llvm/Analysis/RegionInfo.h"
47
#include "llvm/Analysis/ScalarEvolution.h"
48
#include "llvm/Analysis/ScalarEvolutionAliasAnalysis.h"
49
#include "llvm/Analysis/ScopedNoAliasAA.h"
50
#include "llvm/Analysis/StackSafetyAnalysis.h"
51
#include "llvm/Analysis/TargetLibraryInfo.h"
52
#include "llvm/Analysis/TargetTransformInfo.h"
53
#include "llvm/Analysis/TypeBasedAliasAnalysis.h"
54
#include "llvm/CodeGen/PreISelIntrinsicLowering.h"
55
#include "llvm/CodeGen/UnreachableBlockElim.h"
56
#include "llvm/IR/Dominators.h"
57
#include "llvm/IR/IRPrintingPasses.h"
58
#include "llvm/IR/PassManager.h"
59
#include "llvm/IR/SafepointIRVerifier.h"
60
#include "llvm/IR/Verifier.h"
61
#include "llvm/Support/Debug.h"
62
#include "llvm/Support/FormatVariadic.h"
63
#include "llvm/Support/Regex.h"
64
#include "llvm/Target/TargetMachine.h"
65
#include "llvm/Transforms/AggressiveInstCombine/AggressiveInstCombine.h"
66
#include "llvm/Transforms/IPO/AlwaysInliner.h"
67
#include "llvm/Transforms/IPO/ArgumentPromotion.h"
68
#include "llvm/Transforms/IPO/Attributor.h"
69
#include "llvm/Transforms/IPO/CalledValuePropagation.h"
70
#include "llvm/Transforms/IPO/ConstantMerge.h"
71
#include "llvm/Transforms/IPO/CrossDSOCFI.h"
72
#include "llvm/Transforms/IPO/DeadArgumentElimination.h"
73
#include "llvm/Transforms/IPO/ElimAvailExtern.h"
74
#include "llvm/Transforms/IPO/ForceFunctionAttrs.h"
75
#include "llvm/Transforms/IPO/FunctionAttrs.h"
76
#include "llvm/Transforms/IPO/FunctionImport.h"
77
#include "llvm/Transforms/IPO/GlobalDCE.h"
78
#include "llvm/Transforms/IPO/GlobalOpt.h"
79
#include "llvm/Transforms/IPO/GlobalSplit.h"
80
#include "llvm/Transforms/IPO/HotColdSplitting.h"
81
#include "llvm/Transforms/IPO/InferFunctionAttrs.h"
82
#include "llvm/Transforms/IPO/Inliner.h"
83
#include "llvm/Transforms/IPO/Internalize.h"
84
#include "llvm/Transforms/IPO/LowerTypeTests.h"
85
#include "llvm/Transforms/IPO/PartialInlining.h"
86
#include "llvm/Transforms/IPO/SCCP.h"
87
#include "llvm/Transforms/IPO/SampleProfile.h"
88
#include "llvm/Transforms/IPO/StripDeadPrototypes.h"
89
#include "llvm/Transforms/IPO/SyntheticCountsPropagation.h"
90
#include "llvm/Transforms/IPO/WholeProgramDevirt.h"
91
#include "llvm/Transforms/InstCombine/InstCombine.h"
92
#include "llvm/Transforms/Instrumentation.h"
93
#include "llvm/Transforms/Instrumentation/AddressSanitizer.h"
94
#include "llvm/Transforms/Instrumentation/BoundsChecking.h"
95
#include "llvm/Transforms/Instrumentation/CGProfile.h"
96
#include "llvm/Transforms/Instrumentation/ControlHeightReduction.h"
97
#include "llvm/Transforms/Instrumentation/GCOVProfiler.h"
98
#include "llvm/Transforms/Instrumentation/HWAddressSanitizer.h"
99
#include "llvm/Transforms/Instrumentation/InstrOrderFile.h"
100
#include "llvm/Transforms/Instrumentation/InstrProfiling.h"
101
#include "llvm/Transforms/Instrumentation/MemorySanitizer.h"
102
#include "llvm/Transforms/Instrumentation/PGOInstrumentation.h"
103
#include "llvm/Transforms/Instrumentation/PoisonChecking.h"
104
#include "llvm/Transforms/Instrumentation/ThreadSanitizer.h"
105
#include "llvm/Transforms/Scalar/ADCE.h"
106
#include "llvm/Transforms/Scalar/AlignmentFromAssumptions.h"
107
#include "llvm/Transforms/Scalar/BDCE.h"
108
#include "llvm/Transforms/Scalar/CallSiteSplitting.h"
109
#include "llvm/Transforms/Scalar/ConstantHoisting.h"
110
#include "llvm/Transforms/Scalar/CorrelatedValuePropagation.h"
111
#include "llvm/Transforms/Scalar/DCE.h"
112
#include "llvm/Transforms/Scalar/DeadStoreElimination.h"
113
#include "llvm/Transforms/Scalar/DivRemPairs.h"
114
#include "llvm/Transforms/Scalar/EarlyCSE.h"
115
#include "llvm/Transforms/Scalar/Float2Int.h"
116
#include "llvm/Transforms/Scalar/GVN.h"
117
#include "llvm/Transforms/Scalar/GuardWidening.h"
118
#include "llvm/Transforms/Scalar/IVUsersPrinter.h"
119
#include "llvm/Transforms/Scalar/IndVarSimplify.h"
120
#include "llvm/Transforms/Scalar/InductiveRangeCheckElimination.h"
121
#include "llvm/Transforms/Scalar/InstSimplifyPass.h"
122
#include "llvm/Transforms/Scalar/JumpThreading.h"
123
#include "llvm/Transforms/Scalar/LICM.h"
124
#include "llvm/Transforms/Scalar/LoopAccessAnalysisPrinter.h"
125
#include "llvm/Transforms/Scalar/LoopDataPrefetch.h"
126
#include "llvm/Transforms/Scalar/LoopDeletion.h"
127
#include "llvm/Transforms/Scalar/LoopDistribute.h"
128
#include "llvm/Transforms/Scalar/LoopFuse.h"
129
#include "llvm/Transforms/Scalar/LoopIdiomRecognize.h"
130
#include "llvm/Transforms/Scalar/LoopInstSimplify.h"
131
#include "llvm/Transforms/Scalar/LoopLoadElimination.h"
132
#include "llvm/Transforms/Scalar/LoopPassManager.h"
133
#include "llvm/Transforms/Scalar/LoopPredication.h"
134
#include "llvm/Transforms/Scalar/LoopRotation.h"
135
#include "llvm/Transforms/Scalar/LoopSimplifyCFG.h"
136
#include "llvm/Transforms/Scalar/LoopSink.h"
137
#include "llvm/Transforms/Scalar/LoopStrengthReduce.h"
138
#include "llvm/Transforms/Scalar/LoopUnrollAndJamPass.h"
139
#include "llvm/Transforms/Scalar/LoopUnrollPass.h"
140
#include "llvm/Transforms/Scalar/LowerAtomic.h"
141
#include "llvm/Transforms/Scalar/LowerExpectIntrinsic.h"
142
#include "llvm/Transforms/Scalar/LowerGuardIntrinsic.h"
143
#include "llvm/Transforms/Scalar/LowerWidenableCondition.h"
144
#include "llvm/Transforms/Scalar/MakeGuardsExplicit.h"
145
#include "llvm/Transforms/Scalar/MemCpyOptimizer.h"
146
#include "llvm/Transforms/Scalar/MergedLoadStoreMotion.h"
147
#include "llvm/Transforms/Scalar/MergeICmps.h"
148
#include "llvm/Transforms/Scalar/NaryReassociate.h"
149
#include "llvm/Transforms/Scalar/NewGVN.h"
150
#include "llvm/Transforms/Scalar/PartiallyInlineLibCalls.h"
151
#include "llvm/Transforms/Scalar/Reassociate.h"
152
#include "llvm/Transforms/Scalar/RewriteStatepointsForGC.h"
153
#include "llvm/Transforms/Scalar/SCCP.h"
154
#include "llvm/Transforms/Scalar/SROA.h"
155
#include "llvm/Transforms/Scalar/Scalarizer.h"
156
#include "llvm/Transforms/Scalar/SimpleLoopUnswitch.h"
157
#include "llvm/Transforms/Scalar/SimplifyCFG.h"
158
#include "llvm/Transforms/Scalar/Sink.h"
159
#include "llvm/Transforms/Scalar/SpeculateAroundPHIs.h"
160
#include "llvm/Transforms/Scalar/SpeculativeExecution.h"
161
#include "llvm/Transforms/Scalar/TailRecursionElimination.h"
162
#include "llvm/Transforms/Scalar/WarnMissedTransforms.h"
163
#include "llvm/Transforms/Utils/AddDiscriminators.h"
164
#include "llvm/Transforms/Utils/BreakCriticalEdges.h"
165
#include "llvm/Transforms/Utils/CanonicalizeAliases.h"
166
#include "llvm/Transforms/Utils/EntryExitInstrumenter.h"
167
#include "llvm/Transforms/Utils/LCSSA.h"
168
#include "llvm/Transforms/Utils/LibCallsShrinkWrap.h"
169
#include "llvm/Transforms/Utils/LoopSimplify.h"
170
#include "llvm/Transforms/Utils/LowerInvoke.h"
171
#include "llvm/Transforms/Utils/Mem2Reg.h"
172
#include "llvm/Transforms/Utils/NameAnonGlobals.h"
173
#include "llvm/Transforms/Utils/SymbolRewriter.h"
174
#include "llvm/Transforms/Vectorize/LoadStoreVectorizer.h"
175
#include "llvm/Transforms/Vectorize/LoopVectorize.h"
176
#include "llvm/Transforms/Vectorize/SLPVectorizer.h"
177
178
using namespace llvm;
179
180
static cl::opt<unsigned> MaxDevirtIterations("pm-max-devirt-iterations",
181
                                             cl::ReallyHidden, cl::init(4));
182
static cl::opt<bool>
183
    RunPartialInlining("enable-npm-partial-inlining", cl::init(false),
184
                       cl::Hidden, cl::ZeroOrMore,
185
                       cl::desc("Run Partial inlinining pass"));
186
187
static cl::opt<bool>
188
    RunNewGVN("enable-npm-newgvn", cl::init(false),
189
              cl::Hidden, cl::ZeroOrMore,
190
              cl::desc("Run NewGVN instead of GVN"));
191
192
static cl::opt<bool> EnableGVNHoist(
193
    "enable-npm-gvn-hoist", cl::init(false), cl::Hidden,
194
    cl::desc("Enable the GVN hoisting pass for the new PM (default = off)"));
195
196
static cl::opt<bool> EnableGVNSink(
197
    "enable-npm-gvn-sink", cl::init(false), cl::Hidden,
198
    cl::desc("Enable the GVN hoisting pass for the new PM (default = off)"));
199
200
static cl::opt<bool> EnableUnrollAndJam(
201
    "enable-npm-unroll-and-jam", cl::init(false), cl::Hidden,
202
    cl::desc("Enable the Unroll and Jam pass for the new PM (default = off)"));
203
204
static cl::opt<bool> EnableSyntheticCounts(
205
    "enable-npm-synthetic-counts", cl::init(false), cl::Hidden, cl::ZeroOrMore,
206
    cl::desc("Run synthetic function entry count generation "
207
             "pass"));
208
209
static Regex DefaultAliasRegex(
210
    "^(default|thinlto-pre-link|thinlto|lto-pre-link|lto)<(O[0123sz])>$");
211
212
// This option is used in simplifying testing SampleFDO optimizations for
213
// profile loading.
214
static cl::opt<bool>
215
    EnableCHR("enable-chr-npm", cl::init(true), cl::Hidden,
216
              cl::desc("Enable control height reduction optimization (CHR)"));
217
218
1.44k
PipelineTuningOptions::PipelineTuningOptions() {
219
1.44k
  LoopInterleaving = EnableLoopInterleaving;
220
1.44k
  LoopVectorization = EnableLoopVectorization;
221
1.44k
  SLPVectorization = RunSLPVectorization;
222
1.44k
  LoopUnrolling = true;
223
1.44k
  ForgetAllSCEVInLoopUnroll = ForgetSCEVInLoopUnroll;
224
1.44k
  LicmMssaOptCap = SetLicmMssaOptCap;
225
1.44k
  LicmMssaNoAccForPromotionCap = SetLicmMssaNoAccForPromotionCap;
226
1.44k
}
227
228
extern cl::opt<bool> EnableHotColdSplit;
229
extern cl::opt<bool> EnableOrderFileInstrumentation;
230
231
extern cl::opt<bool> FlattenedProfileUsed;
232
233
214
static bool isOptimizingForSize(PassBuilder::OptimizationLevel Level) {
234
214
  switch (Level) {
235
214
  case PassBuilder::O0:
236
203
  case PassBuilder::O1:
237
203
  case PassBuilder::O2:
238
203
  case PassBuilder::O3:
239
203
    return false;
240
203
241
203
  case PassBuilder::Os:
242
11
  case PassBuilder::Oz:
243
11
    return true;
244
0
  }
245
0
  llvm_unreachable("Invalid optimization level!");
246
0
}
247
248
namespace {
249
250
/// No-op module pass which does nothing.
251
struct NoOpModulePass {
252
21
  PreservedAnalyses run(Module &M, ModuleAnalysisManager &) {
253
21
    return PreservedAnalyses::all();
254
21
  }
255
17
  static StringRef name() { return "NoOpModulePass"; }
256
};
257
258
/// No-op module analysis.
259
class NoOpModuleAnalysis : public AnalysisInfoMixin<NoOpModuleAnalysis> {
260
  friend AnalysisInfoMixin<NoOpModuleAnalysis>;
261
  static AnalysisKey Key;
262
263
public:
264
  struct Result {};
265
9
  Result run(Module &, ModuleAnalysisManager &) { return Result(); }
266
12
  static StringRef name() { return "NoOpModuleAnalysis"; }
267
};
268
269
/// No-op CGSCC pass which does nothing.
270
struct NoOpCGSCCPass {
271
  PreservedAnalyses run(LazyCallGraph::SCC &C, CGSCCAnalysisManager &,
272
10
                        LazyCallGraph &, CGSCCUpdateResult &UR) {
273
10
    return PreservedAnalyses::all();
274
10
  }
275
10
  static StringRef name() { return "NoOpCGSCCPass"; }
276
};
277
278
/// No-op CGSCC analysis.
279
class NoOpCGSCCAnalysis : public AnalysisInfoMixin<NoOpCGSCCAnalysis> {
280
  friend AnalysisInfoMixin<NoOpCGSCCAnalysis>;
281
  static AnalysisKey Key;
282
283
public:
284
  struct Result {};
285
7
  Result run(LazyCallGraph::SCC &, CGSCCAnalysisManager &, LazyCallGraph &G) {
286
7
    return Result();
287
7
  }
288
10
  static StringRef name() { return "NoOpCGSCCAnalysis"; }
289
};
290
291
/// No-op function pass which does nothing.
292
struct NoOpFunctionPass {
293
26
  PreservedAnalyses run(Function &F, FunctionAnalysisManager &) {
294
26
    return PreservedAnalyses::all();
295
26
  }
296
25
  static StringRef name() { return "NoOpFunctionPass"; }
297
};
298
299
/// No-op function analysis.
300
class NoOpFunctionAnalysis : public AnalysisInfoMixin<NoOpFunctionAnalysis> {
301
  friend AnalysisInfoMixin<NoOpFunctionAnalysis>;
302
  static AnalysisKey Key;
303
304
public:
305
  struct Result {};
306
9
  Result run(Function &, FunctionAnalysisManager &) { return Result(); }
307
13
  static StringRef name() { return "NoOpFunctionAnalysis"; }
308
};
309
310
/// No-op loop pass which does nothing.
311
struct NoOpLoopPass {
312
  PreservedAnalyses run(Loop &L, LoopAnalysisManager &,
313
43
                        LoopStandardAnalysisResults &, LPMUpdater &) {
314
43
    return PreservedAnalyses::all();
315
43
  }
316
39
  static StringRef name() { return "NoOpLoopPass"; }
317
};
318
319
/// No-op loop analysis.
320
class NoOpLoopAnalysis : public AnalysisInfoMixin<NoOpLoopAnalysis> {
321
  friend AnalysisInfoMixin<NoOpLoopAnalysis>;
322
  static AnalysisKey Key;
323
324
public:
325
  struct Result {};
326
0
  Result run(Loop &, LoopAnalysisManager &, LoopStandardAnalysisResults &) {
327
0
    return Result();
328
0
  }
329
0
  static StringRef name() { return "NoOpLoopAnalysis"; }
330
};
331
332
AnalysisKey NoOpModuleAnalysis::Key;
333
AnalysisKey NoOpCGSCCAnalysis::Key;
334
AnalysisKey NoOpFunctionAnalysis::Key;
335
AnalysisKey NoOpLoopAnalysis::Key;
336
337
} // End anonymous namespace.
338
339
void PassBuilder::invokePeepholeEPCallbacks(
340
723
    FunctionPassManager &FPM, PassBuilder::OptimizationLevel Level) {
341
723
  for (auto &C : PeepholeEPCallbacks)
342
7
    C(FPM, Level);
343
723
}
344
345
1.43k
void PassBuilder::registerModuleAnalyses(ModuleAnalysisManager &MAM) {
346
1.43k
#define MODULE_ANALYSIS(NAME, CREATE_PASS)                                     \
347
15.7k
  MAM.registerPass([&] 
{ return CREATE_PASS; }15.6k
);
PassBuilder.cpp:llvm::PassBuilder::registerModuleAnalyses(llvm::AnalysisManager<llvm::Module>&)::$_0::operator()() const
Line
Count
Source
347
1.43k
  MAM.registerPass([&] { return CREATE_PASS; });
PassBuilder.cpp:llvm::PassBuilder::registerModuleAnalyses(llvm::AnalysisManager<llvm::Module>&)::$_1::operator()() const
Line
Count
Source
347
1.43k
  MAM.registerPass([&] { return CREATE_PASS; });
PassBuilder.cpp:llvm::PassBuilder::registerModuleAnalyses(llvm::AnalysisManager<llvm::Module>&)::$_2::operator()() const
Line
Count
Source
347
1.43k
  MAM.registerPass([&] { return CREATE_PASS; });
PassBuilder.cpp:llvm::PassBuilder::registerModuleAnalyses(llvm::AnalysisManager<llvm::Module>&)::$_3::operator()() const
Line
Count
Source
347
1.43k
  MAM.registerPass([&] { return CREATE_PASS; });
PassBuilder.cpp:llvm::PassBuilder::registerModuleAnalyses(llvm::AnalysisManager<llvm::Module>&)::$_4::operator()() const
Line
Count
Source
347
1.43k
  MAM.registerPass([&] { return CREATE_PASS; });
PassBuilder.cpp:llvm::PassBuilder::registerModuleAnalyses(llvm::AnalysisManager<llvm::Module>&)::$_5::operator()() const
Line
Count
Source
347
1.43k
  MAM.registerPass([&] { return CREATE_PASS; });
PassBuilder.cpp:llvm::PassBuilder::registerModuleAnalyses(llvm::AnalysisManager<llvm::Module>&)::$_6::operator()() const
Line
Count
Source
347
1.31k
  MAM.registerPass([&] { return CREATE_PASS; });
PassBuilder.cpp:llvm::PassBuilder::registerModuleAnalyses(llvm::AnalysisManager<llvm::Module>&)::$_7::operator()() const
Line
Count
Source
347
1.43k
  MAM.registerPass([&] { return CREATE_PASS; });
PassBuilder.cpp:llvm::PassBuilder::registerModuleAnalyses(llvm::AnalysisManager<llvm::Module>&)::$_8::operator()() const
Line
Count
Source
347
1.43k
  MAM.registerPass([&] { return CREATE_PASS; });
PassBuilder.cpp:llvm::PassBuilder::registerModuleAnalyses(llvm::AnalysisManager<llvm::Module>&)::$_9::operator()() const
Line
Count
Source
347
1.43k
  MAM.registerPass([&] { return CREATE_PASS; });
PassBuilder.cpp:llvm::PassBuilder::registerModuleAnalyses(llvm::AnalysisManager<llvm::Module>&)::$_10::operator()() const
Line
Count
Source
347
1.43k
  MAM.registerPass([&] { return CREATE_PASS; });
348
1.43k
#include "PassRegistry.def"
349
1.43k
350
1.43k
  for (auto &C : ModuleAnalysisRegistrationCallbacks)
351
5
    C(MAM);
352
1.43k
}
353
354
1.43k
void PassBuilder::registerCGSCCAnalyses(CGSCCAnalysisManager &CGAM) {
355
1.43k
#define CGSCC_ANALYSIS(NAME, CREATE_PASS)                                      \
356
4.30k
  CGAM.registerPass([&] { return CREATE_PASS; });
PassBuilder.cpp:llvm::PassBuilder::registerCGSCCAnalyses(llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>&)::$_11::operator()() const
Line
Count
Source
356
1.43k
  CGAM.registerPass([&] { return CREATE_PASS; });
PassBuilder.cpp:llvm::PassBuilder::registerCGSCCAnalyses(llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>&)::$_12::operator()() const
Line
Count
Source
356
1.43k
  CGAM.registerPass([&] { return CREATE_PASS; });
PassBuilder.cpp:llvm::PassBuilder::registerCGSCCAnalyses(llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>&)::$_13::operator()() const
Line
Count
Source
356
1.43k
  CGAM.registerPass([&] { return CREATE_PASS; });
357
1.43k
#include "PassRegistry.def"
358
1.43k
359
1.43k
  for (auto &C : CGSCCAnalysisRegistrationCallbacks)
360
5
    C(CGAM);
361
1.43k
}
362
363
1.43k
void PassBuilder::registerFunctionAnalyses(FunctionAnalysisManager &FAM) {
364
1.43k
#define FUNCTION_ANALYSIS(NAME, CREATE_PASS)                                   \
365
41.6k
  FAM.registerPass([&] 
{ return 40.1k
CREATE_PASS1.43k
; });
PassBuilder.cpp:llvm::PassBuilder::registerFunctionAnalyses(llvm::AnalysisManager<llvm::Function>&)::$_14::operator()() const
Line
Count
Source
365
24
  FAM.registerPass([&] { return CREATE_PASS; });
PassBuilder.cpp:llvm::PassBuilder::registerFunctionAnalyses(llvm::AnalysisManager<llvm::Function>&)::$_15::operator()() const
Line
Count
Source
365
1.43k
  FAM.registerPass([&] { return CREATE_PASS; });
PassBuilder.cpp:llvm::PassBuilder::registerFunctionAnalyses(llvm::AnalysisManager<llvm::Function>&)::$_16::operator()() const
Line
Count
Source
365
1.43k
  FAM.registerPass([&] { return CREATE_PASS; });
PassBuilder.cpp:llvm::PassBuilder::registerFunctionAnalyses(llvm::AnalysisManager<llvm::Function>&)::$_17::operator()() const
Line
Count
Source
365
1.43k
  FAM.registerPass([&] { return CREATE_PASS; });
PassBuilder.cpp:llvm::PassBuilder::registerFunctionAnalyses(llvm::AnalysisManager<llvm::Function>&)::$_18::operator()() const
Line
Count
Source
365
1.43k
  FAM.registerPass([&] { return CREATE_PASS; });
PassBuilder.cpp:llvm::PassBuilder::registerFunctionAnalyses(llvm::AnalysisManager<llvm::Function>&)::$_19::operator()() const
Line
Count
Source
365
1.43k
  FAM.registerPass([&] { return CREATE_PASS; });
PassBuilder.cpp:llvm::PassBuilder::registerFunctionAnalyses(llvm::AnalysisManager<llvm::Function>&)::$_20::operator()() const
Line
Count
Source
365
1.43k
  FAM.registerPass([&] { return CREATE_PASS; });
PassBuilder.cpp:llvm::PassBuilder::registerFunctionAnalyses(llvm::AnalysisManager<llvm::Function>&)::$_21::operator()() const
Line
Count
Source
365
1.43k
  FAM.registerPass([&] { return CREATE_PASS; });
PassBuilder.cpp:llvm::PassBuilder::registerFunctionAnalyses(llvm::AnalysisManager<llvm::Function>&)::$_22::operator()() const
Line
Count
Source
365
1.43k
  FAM.registerPass([&] { return CREATE_PASS; });
PassBuilder.cpp:llvm::PassBuilder::registerFunctionAnalyses(llvm::AnalysisManager<llvm::Function>&)::$_23::operator()() const
Line
Count
Source
365
1.43k
  FAM.registerPass([&] { return CREATE_PASS; });
PassBuilder.cpp:llvm::PassBuilder::registerFunctionAnalyses(llvm::AnalysisManager<llvm::Function>&)::$_24::operator()() const
Line
Count
Source
365
1.43k
  FAM.registerPass([&] { return CREATE_PASS; });
PassBuilder.cpp:llvm::PassBuilder::registerFunctionAnalyses(llvm::AnalysisManager<llvm::Function>&)::$_25::operator()() const
Line
Count
Source
365
1.43k
  FAM.registerPass([&] { return CREATE_PASS; });
PassBuilder.cpp:llvm::PassBuilder::registerFunctionAnalyses(llvm::AnalysisManager<llvm::Function>&)::$_26::operator()() const
Line
Count
Source
365
1.43k
  FAM.registerPass([&] { return CREATE_PASS; });
PassBuilder.cpp:llvm::PassBuilder::registerFunctionAnalyses(llvm::AnalysisManager<llvm::Function>&)::$_27::operator()() const
Line
Count
Source
365
1.43k
  FAM.registerPass([&] { return CREATE_PASS; });
PassBuilder.cpp:llvm::PassBuilder::registerFunctionAnalyses(llvm::AnalysisManager<llvm::Function>&)::$_28::operator()() const
Line
Count
Source
365
1.43k
  FAM.registerPass([&] { return CREATE_PASS; });
PassBuilder.cpp:llvm::PassBuilder::registerFunctionAnalyses(llvm::AnalysisManager<llvm::Function>&)::$_29::operator()() const
Line
Count
Source
365
1.43k
  FAM.registerPass([&] { return CREATE_PASS; });
PassBuilder.cpp:llvm::PassBuilder::registerFunctionAnalyses(llvm::AnalysisManager<llvm::Function>&)::$_30::operator()() const
Line
Count
Source
365
1.43k
  FAM.registerPass([&] { return CREATE_PASS; });
PassBuilder.cpp:llvm::PassBuilder::registerFunctionAnalyses(llvm::AnalysisManager<llvm::Function>&)::$_31::operator()() const
Line
Count
Source
365
1.43k
  FAM.registerPass([&] { return CREATE_PASS; });
PassBuilder.cpp:llvm::PassBuilder::registerFunctionAnalyses(llvm::AnalysisManager<llvm::Function>&)::$_32::operator()() const
Line
Count
Source
365
1.43k
  FAM.registerPass([&] { return CREATE_PASS; });
PassBuilder.cpp:llvm::PassBuilder::registerFunctionAnalyses(llvm::AnalysisManager<llvm::Function>&)::$_33::operator()() const
Line
Count
Source
365
1.31k
  FAM.registerPass([&] { return CREATE_PASS; });
PassBuilder.cpp:llvm::PassBuilder::registerFunctionAnalyses(llvm::AnalysisManager<llvm::Function>&)::$_34::operator()() const
Line
Count
Source
365
1.43k
  FAM.registerPass([&] { return CREATE_PASS; });
PassBuilder.cpp:llvm::PassBuilder::registerFunctionAnalyses(llvm::AnalysisManager<llvm::Function>&)::$_35::operator()() const
Line
Count
Source
365
1.43k
  FAM.registerPass([&] { return CREATE_PASS; });
PassBuilder.cpp:llvm::PassBuilder::registerFunctionAnalyses(llvm::AnalysisManager<llvm::Function>&)::$_36::operator()() const
Line
Count
Source
365
1.43k
  FAM.registerPass([&] { return CREATE_PASS; });
PassBuilder.cpp:llvm::PassBuilder::registerFunctionAnalyses(llvm::AnalysisManager<llvm::Function>&)::$_37::operator()() const
Line
Count
Source
365
1.43k
  FAM.registerPass([&] { return CREATE_PASS; });
PassBuilder.cpp:llvm::PassBuilder::registerFunctionAnalyses(llvm::AnalysisManager<llvm::Function>&)::$_38::operator()() const
Line
Count
Source
365
1.43k
  FAM.registerPass([&] { return CREATE_PASS; });
PassBuilder.cpp:llvm::PassBuilder::registerFunctionAnalyses(llvm::AnalysisManager<llvm::Function>&)::$_39::operator()() const
Line
Count
Source
365
1.43k
  FAM.registerPass([&] { return CREATE_PASS; });
PassBuilder.cpp:llvm::PassBuilder::registerFunctionAnalyses(llvm::AnalysisManager<llvm::Function>&)::$_40::operator()() const
Line
Count
Source
365
1.43k
  FAM.registerPass([&] { return CREATE_PASS; });
PassBuilder.cpp:llvm::PassBuilder::registerFunctionAnalyses(llvm::AnalysisManager<llvm::Function>&)::$_41::operator()() const
Line
Count
Source
365
1.43k
  FAM.registerPass([&] { return CREATE_PASS; });
PassBuilder.cpp:llvm::PassBuilder::registerFunctionAnalyses(llvm::AnalysisManager<llvm::Function>&)::$_42::operator()() const
Line
Count
Source
365
1.43k
  FAM.registerPass([&] { return CREATE_PASS; });
366
1.43k
#include "PassRegistry.def"
367
1.43k
368
1.43k
  for (auto &C : FunctionAnalysisRegistrationCallbacks)
369
1.25k
    C(FAM);
370
1.43k
}
371
372
1.43k
void PassBuilder::registerLoopAnalyses(LoopAnalysisManager &LAM) {
373
1.43k
#define LOOP_ANALYSIS(NAME, CREATE_PASS)                                       \
374
5.73k
  LAM.registerPass([&] { return CREATE_PASS; });
PassBuilder.cpp:llvm::PassBuilder::registerLoopAnalyses(llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>&)::$_43::operator()() const
Line
Count
Source
374
1.43k
  LAM.registerPass([&] { return CREATE_PASS; });
PassBuilder.cpp:llvm::PassBuilder::registerLoopAnalyses(llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>&)::$_44::operator()() const
Line
Count
Source
374
1.43k
  LAM.registerPass([&] { return CREATE_PASS; });
PassBuilder.cpp:llvm::PassBuilder::registerLoopAnalyses(llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>&)::$_45::operator()() const
Line
Count
Source
374
1.43k
  LAM.registerPass([&] { return CREATE_PASS; });
PassBuilder.cpp:llvm::PassBuilder::registerLoopAnalyses(llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>&)::$_46::operator()() const
Line
Count
Source
374
1.43k
  LAM.registerPass([&] { return CREATE_PASS; });
375
1.43k
#include "PassRegistry.def"
376
1.43k
377
1.43k
  for (auto &C : LoopAnalysisRegistrationCallbacks)
378
5
    C(LAM);
379
1.43k
}
380
381
FunctionPassManager
382
PassBuilder::buildFunctionSimplificationPipeline(OptimizationLevel Level,
383
                                                 ThinLTOPhase Phase,
384
160
                                                 bool DebugLogging) {
385
160
  assert(Level != O0 && "Must request optimizations!");
386
160
  FunctionPassManager FPM(DebugLogging);
387
160
388
160
  // Form SSA out of local memory accesses after breaking apart aggregates into
389
160
  // scalars.
390
160
  FPM.addPass(SROA());
391
160
392
160
  // Catch trivial redundancies
393
160
  FPM.addPass(EarlyCSEPass(true /* Enable mem-ssa. */));
394
160
395
160
  // Hoisting of scalars and load expressions.
396
160
  if (EnableGVNHoist)
397
0
    FPM.addPass(GVNHoistPass());
398
160
399
160
  // Global value numbering based sinking.
400
160
  if (EnableGVNSink) {
401
0
    FPM.addPass(GVNSinkPass());
402
0
    FPM.addPass(SimplifyCFGPass());
403
0
  }
404
160
405
160
  // Speculative execution if the target has divergent branches; otherwise nop.
406
160
  FPM.addPass(SpeculativeExecutionPass());
407
160
408
160
  // Optimize based on known information about branches, and cleanup afterward.
409
160
  FPM.addPass(JumpThreadingPass());
410
160
  FPM.addPass(CorrelatedValuePropagationPass());
411
160
  FPM.addPass(SimplifyCFGPass());
412
160
  if (Level == O3)
413
23
    FPM.addPass(AggressiveInstCombinePass());
414
160
  FPM.addPass(InstCombinePass());
415
160
416
160
  if (!isOptimizingForSize(Level))
417
149
    FPM.addPass(LibCallsShrinkWrapPass());
418
160
419
160
  invokePeepholeEPCallbacks(FPM, Level);
420
160
421
160
  // For PGO use pipeline, try to optimize memory intrinsics such as memcpy
422
160
  // using the size value profile. Don't perform this when optimizing for size.
423
160
  if (PGOOpt && 
PGOOpt->Action == PGOOptions::IRUse43
&&
424
160
      
!isOptimizingForSize(Level)22
)
425
22
    FPM.addPass(PGOMemOPSizeOpt());
426
160
427
160
  FPM.addPass(TailCallElimPass());
428
160
  FPM.addPass(SimplifyCFGPass());
429
160
430
160
  // Form canonically associated expression trees, and simplify the trees using
431
160
  // basic mathematical properties. For example, this will form (nearly)
432
160
  // minimal multiplication trees.
433
160
  FPM.addPass(ReassociatePass());
434
160
435
160
  // Add the primary loop simplification pipeline.
436
160
  // FIXME: Currently this is split into two loop pass pipelines because we run
437
160
  // some function passes in between them. These can and should be removed
438
160
  // and/or replaced by scheduling the loop pass equivalents in the correct
439
160
  // positions. But those equivalent passes aren't powerful enough yet.
440
160
  // Specifically, `SimplifyCFGPass` and `InstCombinePass` are currently still
441
160
  // used. We have `LoopSimplifyCFGPass` which isn't yet powerful enough yet to
442
160
  // fully replace `SimplifyCFGPass`, and the closest to the other we have is
443
160
  // `LoopInstSimplify`.
444
160
  LoopPassManager LPM1(DebugLogging), LPM2(DebugLogging);
445
160
446
160
  // Simplify the loop body. We do this initially to clean up after other loop
447
160
  // passes run, either when iterating on a loop or on inner loops with
448
160
  // implications on the outer loop.
449
160
  LPM1.addPass(LoopInstSimplifyPass());
450
160
  LPM1.addPass(LoopSimplifyCFGPass());
451
160
452
160
  // Rotate Loop - disable header duplication at -Oz
453
160
  LPM1.addPass(LoopRotatePass(Level != Oz));
454
160
  LPM1.addPass(LICMPass(PTO.LicmMssaOptCap, PTO.LicmMssaNoAccForPromotionCap));
455
160
  LPM1.addPass(SimpleLoopUnswitchPass());
456
160
  LPM2.addPass(IndVarSimplifyPass());
457
160
  LPM2.addPass(LoopIdiomRecognizePass());
458
160
459
160
  for (auto &C : LateLoopOptimizationsEPCallbacks)
460
1
    C(LPM2, Level);
461
160
462
160
  LPM2.addPass(LoopDeletionPass());
463
160
  // Do not enable unrolling in PreLinkThinLTO phase during sample PGO
464
160
  // because it changes IR to makes profile annotation in back compile
465
160
  // inaccurate.
466
160
  if ((Phase != ThinLTOPhase::PreLink || 
!PGOOpt23
||
467
160
       
PGOOpt->Action != PGOOptions::SampleUse10
) &&
468
160
      
PTO.LoopUnrolling155
)
469
120
    LPM2.addPass(
470
120
        LoopFullUnrollPass(Level, false, PTO.ForgetAllSCEVInLoopUnroll));
471
160
472
160
  for (auto &C : LoopOptimizerEndEPCallbacks)
473
1
    C(LPM2, Level);
474
160
475
160
  // We provide the opt remark emitter pass for LICM to use. We only need to do
476
160
  // this once as it is immutable.
477
160
  FPM.addPass(RequireAnalysisPass<OptimizationRemarkEmitterAnalysis, Function>());
478
160
  FPM.addPass(createFunctionToLoopPassAdaptor(std::move(LPM1), DebugLogging));
479
160
  FPM.addPass(SimplifyCFGPass());
480
160
  FPM.addPass(InstCombinePass());
481
160
  FPM.addPass(createFunctionToLoopPassAdaptor(std::move(LPM2), DebugLogging));
482
160
483
160
  // Eliminate redundancies.
484
160
  if (Level != O1) {
485
120
    // These passes add substantial compile time so skip them at O1.
486
120
    FPM.addPass(MergedLoadStoreMotionPass());
487
120
    if (RunNewGVN)
488
0
      FPM.addPass(NewGVNPass());
489
120
    else
490
120
      FPM.addPass(GVN());
491
120
  }
492
160
493
160
  // Specially optimize memory movement as it doesn't look like dataflow in SSA.
494
160
  FPM.addPass(MemCpyOptPass());
495
160
496
160
  // Sparse conditional constant propagation.
497
160
  // FIXME: It isn't clear why we do this *after* loop passes rather than
498
160
  // before...
499
160
  FPM.addPass(SCCPPass());
500
160
501
160
  // Delete dead bit computations (instcombine runs after to fold away the dead
502
160
  // computations, and then ADCE will run later to exploit any new DCE
503
160
  // opportunities that creates).
504
160
  FPM.addPass(BDCEPass());
505
160
506
160
  // Run instcombine after redundancy and dead bit elimination to exploit
507
160
  // opportunities opened up by them.
508
160
  FPM.addPass(InstCombinePass());
509
160
  invokePeepholeEPCallbacks(FPM, Level);
510
160
511
160
  // Re-consider control flow based optimizations after redundancy elimination,
512
160
  // redo DCE, etc.
513
160
  FPM.addPass(JumpThreadingPass());
514
160
  FPM.addPass(CorrelatedValuePropagationPass());
515
160
  FPM.addPass(DSEPass());
516
160
  FPM.addPass(createFunctionToLoopPassAdaptor(
517
160
      LICMPass(PTO.LicmMssaOptCap, PTO.LicmMssaNoAccForPromotionCap),
518
160
      DebugLogging));
519
160
520
160
  for (auto &C : ScalarOptimizerLateEPCallbacks)
521
1
    C(FPM, Level);
522
160
523
160
  // Finally, do an expensive DCE pass to catch all the dead code exposed by
524
160
  // the simplifications and basic cleanup after all the simplifications.
525
160
  FPM.addPass(ADCEPass());
526
160
  FPM.addPass(SimplifyCFGPass());
527
160
  FPM.addPass(InstCombinePass());
528
160
  invokePeepholeEPCallbacks(FPM, Level);
529
160
530
160
  if (EnableCHR && Level == O3 && 
PGOOpt23
&&
531
160
      
(0
PGOOpt->Action == PGOOptions::IRUse0
||
532
0
       PGOOpt->Action == PGOOptions::SampleUse))
533
0
    FPM.addPass(ControlHeightReductionPass());
534
160
535
160
  return FPM;
536
160
}
537
538
void PassBuilder::addPGOInstrPasses(ModulePassManager &MPM, bool DebugLogging,
539
                                    PassBuilder::OptimizationLevel Level,
540
                                    bool RunProfileGen, bool IsCS,
541
                                    std::string ProfileFile,
542
32
                                    std::string ProfileRemappingFile) {
543
32
  // Generally running simplification passes and the inliner with an high
544
32
  // threshold results in smaller executables, but there may be cases where
545
32
  // the size grows, so let's be conservative here and skip this simplification
546
32
  // at -Os/Oz. We will not do this  inline for context sensistive PGO (when
547
32
  // IsCS is true).
548
32
  if (!isOptimizingForSize(Level) && !IsCS) {
549
20
    InlineParams IP;
550
20
551
20
    // In the old pass manager, this is a cl::opt. Should still this be one?
552
20
    IP.DefaultThreshold = 75;
553
20
554
20
    // FIXME: The hint threshold has the same value used by the regular inliner.
555
20
    // This should probably be lowered after performance testing.
556
20
    // FIXME: this comment is cargo culted from the old pass manager, revisit).
557
20
    IP.HintThreshold = 325;
558
20
559
20
    CGSCCPassManager CGPipeline(DebugLogging);
560
20
561
20
    CGPipeline.addPass(InlinerPass(IP));
562
20
563
20
    FunctionPassManager FPM;
564
20
    FPM.addPass(SROA());
565
20
    FPM.addPass(EarlyCSEPass());    // Catch trivial redundancies.
566
20
    FPM.addPass(SimplifyCFGPass()); // Merge & remove basic blocks.
567
20
    FPM.addPass(InstCombinePass()); // Combine silly sequences.
568
20
    invokePeepholeEPCallbacks(FPM, Level);
569
20
570
20
    CGPipeline.addPass(createCGSCCToFunctionPassAdaptor(std::move(FPM)));
571
20
572
20
    MPM.addPass(createModuleToPostOrderCGSCCPassAdaptor(std::move(CGPipeline)));
573
20
  }
574
32
575
32
  // Delete anything that is now dead to make sure that we don't instrument
576
32
  // dead code. Instrumentation can end up keeping dead code around and
577
32
  // dramatically increase code size.
578
32
  MPM.addPass(GlobalDCEPass());
579
32
580
32
  if (RunProfileGen) {
581
9
    MPM.addPass(PGOInstrumentationGen(IsCS));
582
9
583
9
    FunctionPassManager FPM;
584
9
    FPM.addPass(
585
9
        createFunctionToLoopPassAdaptor(LoopRotatePass(), DebugLogging));
586
9
    MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
587
9
588
9
    // Add the profile lowering pass.
589
9
    InstrProfOptions Options;
590
9
    if (!ProfileFile.empty())
591
9
      Options.InstrProfileOutput = ProfileFile;
592
9
    Options.DoCounterPromotion = true;
593
9
    Options.UseBFIInPromotion = IsCS;
594
9
    MPM.addPass(InstrProfiling(Options, IsCS));
595
23
  } else if (!ProfileFile.empty()) {
596
23
    MPM.addPass(PGOInstrumentationUse(ProfileFile, ProfileRemappingFile, IsCS));
597
23
    // Cache ProfileSummaryAnalysis once to avoid the potential need to insert
598
23
    // RequireAnalysisPass for PSI before subsequent non-module passes.
599
23
    MPM.addPass(RequireAnalysisPass<ProfileSummaryAnalysis, Module>());
600
23
  }
601
32
}
602
603
static InlineParams
604
181
getInlineParamsFromOptLevel(PassBuilder::OptimizationLevel Level) {
605
181
  auto O3 = PassBuilder::O3;
606
181
  unsigned OptLevel = Level > O3 ? 
213
:
Level168
;
607
181
  unsigned SizeLevel = Level > O3 ? 
Level - O313
:
0168
;
608
181
  return getInlineParams(OptLevel, SizeLevel);
609
181
}
610
611
ModulePassManager
612
PassBuilder::buildModuleSimplificationPipeline(OptimizationLevel Level,
613
                                               ThinLTOPhase Phase,
614
160
                                               bool DebugLogging) {
615
160
  ModulePassManager MPM(DebugLogging);
616
160
617
160
  bool HasSampleProfile = PGOOpt && 
(PGOOpt->Action == PGOOptions::SampleUse)43
;
618
160
619
160
  // In ThinLTO mode, when flattened profile is used, all the available
620
160
  // profile information will be annotated in PreLink phase so there is
621
160
  // no need to load the profile again in PostLink.
622
160
  bool LoadSampleProfile =
623
160
      HasSampleProfile &&
624
160
      
!(14
FlattenedProfileUsed14
&&
Phase == ThinLTOPhase::PostLink3
);
625
160
626
160
  // During the ThinLTO backend phase we perform early indirect call promotion
627
160
  // here, before globalopt. Otherwise imported available_externally functions
628
160
  // look unreferenced and are removed. If we are going to load the sample
629
160
  // profile then defer until later.
630
160
  // TODO: See if we can move later and consolidate with the location where
631
160
  // we perform ICP when we are loading a sample profile.
632
160
  // TODO: We pass HasSampleProfile (whether there was a sample profile file
633
160
  // passed to the compile) to the SamplePGO flag of ICP. This is used to
634
160
  // determine whether the new direct calls are annotated with prof metadata.
635
160
  // Ideally this should be determined from whether the IR is annotated with
636
160
  // sample profile, and not whether the a sample profile was provided on the
637
160
  // command line. E.g. for flattened profiles where we will not be reloading
638
160
  // the sample profile in the ThinLTO backend, we ideally shouldn't have to
639
160
  // provide the sample profile file.
640
160
  if (Phase == ThinLTOPhase::PostLink && 
!LoadSampleProfile24
)
641
22
    MPM.addPass(PGOIndirectCallPromotion(true /* InLTO */, HasSampleProfile));
642
160
643
160
  // Do basic inference of function attributes from known properties of system
644
160
  // libraries and other oracles.
645
160
  MPM.addPass(InferFunctionAttrsPass());
646
160
647
160
  // Create an early function pass manager to cleanup the output of the
648
160
  // frontend.
649
160
  FunctionPassManager EarlyFPM(DebugLogging);
650
160
  EarlyFPM.addPass(SimplifyCFGPass());
651
160
  EarlyFPM.addPass(SROA());
652
160
  EarlyFPM.addPass(EarlyCSEPass());
653
160
  EarlyFPM.addPass(LowerExpectIntrinsicPass());
654
160
  if (Level == O3)
655
23
    EarlyFPM.addPass(CallSiteSplittingPass());
656
160
657
160
  // In SamplePGO ThinLTO backend, we need instcombine before profile annotation
658
160
  // to convert bitcast to direct calls so that they can be inlined during the
659
160
  // profile annotation prepration step.
660
160
  // More details about SamplePGO design can be found in:
661
160
  // https://research.google.com/pubs/pub45290.html
662
160
  // FIXME: revisit how SampleProfileLoad/Inliner/ICP is structured.
663
160
  if (LoadSampleProfile)
664
13
    EarlyFPM.addPass(InstCombinePass());
665
160
  MPM.addPass(createModuleToFunctionPassAdaptor(std::move(EarlyFPM)));
666
160
667
160
  if (LoadSampleProfile) {
668
13
    // Annotate sample profile right after early FPM to ensure freshness of
669
13
    // the debug info.
670
13
    MPM.addPass(SampleProfileLoaderPass(PGOOpt->ProfileFile,
671
13
                                        PGOOpt->ProfileRemappingFile,
672
13
                                        Phase == ThinLTOPhase::PreLink));
673
13
    // Cache ProfileSummaryAnalysis once to avoid the potential need to insert
674
13
    // RequireAnalysisPass for PSI before subsequent non-module passes.
675
13
    MPM.addPass(RequireAnalysisPass<ProfileSummaryAnalysis, Module>());
676
13
    // Do not invoke ICP in the ThinLTOPrelink phase as it makes it hard
677
13
    // for the profile annotation to be accurate in the ThinLTO backend.
678
13
    if (Phase != ThinLTOPhase::PreLink)
679
8
      // We perform early indirect call promotion here, before globalopt.
680
8
      // This is important for the ThinLTO backend phase because otherwise
681
8
      // imported available_externally functions look unreferenced and are
682
8
      // removed.
683
8
      MPM.addPass(PGOIndirectCallPromotion(Phase == ThinLTOPhase::PostLink,
684
8
                                           true /* SamplePGO */));
685
13
  }
686
160
687
160
  // Interprocedural constant propagation now that basic cleanup has occurred
688
160
  // and prior to optimizing globals.
689
160
  // FIXME: This position in the pipeline hasn't been carefully considered in
690
160
  // years, it should be re-analyzed.
691
160
  MPM.addPass(IPSCCPPass());
692
160
693
160
  // Attach metadata to indirect call sites indicating the set of functions
694
160
  // they may target at run-time. This should follow IPSCCP.
695
160
  MPM.addPass(CalledValuePropagationPass());
696
160
697
160
  // Optimize globals to try and fold them into constants.
698
160
  MPM.addPass(GlobalOptPass());
699
160
700
160
  // Promote any localized globals to SSA registers.
701
160
  // FIXME: Should this instead by a run of SROA?
702
160
  // FIXME: We should probably run instcombine and simplify-cfg afterward to
703
160
  // delete control flows that are dead once globals have been folded to
704
160
  // constants.
705
160
  MPM.addPass(createModuleToFunctionPassAdaptor(PromotePass()));
706
160
707
160
  // Remove any dead arguments exposed by cleanups and constand folding
708
160
  // globals.
709
160
  MPM.addPass(DeadArgumentEliminationPass());
710
160
711
160
  // Create a small function pass pipeline to cleanup after all the global
712
160
  // optimizations.
713
160
  FunctionPassManager GlobalCleanupPM(DebugLogging);
714
160
  GlobalCleanupPM.addPass(InstCombinePass());
715
160
  invokePeepholeEPCallbacks(GlobalCleanupPM, Level);
716
160
717
160
  GlobalCleanupPM.addPass(SimplifyCFGPass());
718
160
  MPM.addPass(createModuleToFunctionPassAdaptor(std::move(GlobalCleanupPM)));
719
160
720
160
  // Add all the requested passes for instrumentation PGO, if requested.
721
160
  if (PGOOpt && 
Phase != ThinLTOPhase::PostLink43
&&
722
160
      
(35
PGOOpt->Action == PGOOptions::IRInstr35
||
723
35
       
PGOOpt->Action == PGOOptions::IRUse33
)) {
724
20
    addPGOInstrPasses(MPM, DebugLogging, Level,
725
20
                      /* RunProfileGen */ PGOOpt->Action == PGOOptions::IRInstr,
726
20
                      /* IsCS */ false, PGOOpt->ProfileFile,
727
20
                      PGOOpt->ProfileRemappingFile);
728
20
    MPM.addPass(PGOIndirectCallPromotion(false, false));
729
20
  }
730
160
  if (PGOOpt && 
Phase != ThinLTOPhase::PostLink43
&&
731
160
      
PGOOpt->CSAction == PGOOptions::CSIRInstr35
)
732
8
    MPM.addPass(PGOInstrumentationGenCreateVar(PGOOpt->CSProfileGenFile));
733
160
734
160
  // Synthesize function entry counts for non-PGO compilation.
735
160
  if (EnableSyntheticCounts && 
!PGOOpt0
)
736
0
    MPM.addPass(SyntheticCountsPropagation());
737
160
738
160
  // Require the GlobalsAA analysis for the module so we can query it within
739
160
  // the CGSCC pipeline.
740
160
  MPM.addPass(RequireAnalysisPass<GlobalsAA, Module>());
741
160
742
160
  // Require the ProfileSummaryAnalysis for the module so we can query it within
743
160
  // the inliner pass.
744
160
  MPM.addPass(RequireAnalysisPass<ProfileSummaryAnalysis, Module>());
745
160
746
160
  // Now begin the main postorder CGSCC pipeline.
747
160
  // FIXME: The current CGSCC pipeline has its origins in the legacy pass
748
160
  // manager and trying to emulate its precise behavior. Much of this doesn't
749
160
  // make a lot of sense and we should revisit the core CGSCC structure.
750
160
  CGSCCPassManager MainCGPipeline(DebugLogging);
751
160
752
160
  // Note: historically, the PruneEH pass was run first to deduce nounwind and
753
160
  // generally clean up exception handling overhead. It isn't clear this is
754
160
  // valuable as the inliner doesn't currently care whether it is inlining an
755
160
  // invoke or a call.
756
160
757
160
  // Run the inliner first. The theory is that we are walking bottom-up and so
758
160
  // the callees have already been fully optimized, and we want to inline them
759
160
  // into the callers so that our optimizations can reflect that.
760
160
  // For PreLinkThinLTO pass, we disable hot-caller heuristic for sample PGO
761
160
  // because it makes profile annotation in the backend inaccurate.
762
160
  InlineParams IP = getInlineParamsFromOptLevel(Level);
763
160
  if (Phase == ThinLTOPhase::PreLink && 
PGOOpt23
&&
764
160
      
PGOOpt->Action == PGOOptions::SampleUse10
)
765
5
    IP.HotCallSiteThreshold = 0;
766
160
  MainCGPipeline.addPass(InlinerPass(IP));
767
160
768
160
  // Now deduce any function attributes based in the current code.
769
160
  MainCGPipeline.addPass(PostOrderFunctionAttrsPass());
770
160
771
160
  // When at O3 add argument promotion to the pass pipeline.
772
160
  // FIXME: It isn't at all clear why this should be limited to O3.
773
160
  if (Level == O3)
774
23
    MainCGPipeline.addPass(ArgumentPromotionPass());
775
160
776
160
  // Lastly, add the core function simplification pipeline nested inside the
777
160
  // CGSCC walk.
778
160
  MainCGPipeline.addPass(createCGSCCToFunctionPassAdaptor(
779
160
      buildFunctionSimplificationPipeline(Level, Phase, DebugLogging)));
780
160
781
160
  for (auto &C : CGSCCOptimizerLateEPCallbacks)
782
1
    C(MainCGPipeline, Level);
783
160
784
160
  // We wrap the CGSCC pipeline in a devirtualization repeater. This will try
785
160
  // to detect when we devirtualize indirect calls and iterate the SCC passes
786
160
  // in that case to try and catch knock-on inlining or function attrs
787
160
  // opportunities. Then we add it to the module pipeline by walking the SCCs
788
160
  // in postorder (or bottom-up).
789
160
  MPM.addPass(
790
160
      createModuleToPostOrderCGSCCPassAdaptor(createDevirtSCCRepeatedPass(
791
160
          std::move(MainCGPipeline), MaxDevirtIterations)));
792
160
793
160
  return MPM;
794
160
}
795
796
ModulePassManager PassBuilder::buildModuleOptimizationPipeline(
797
137
    OptimizationLevel Level, bool DebugLogging, bool LTOPreLink) {
798
137
  ModulePassManager MPM(DebugLogging);
799
137
800
137
  // Optimize globals now that the module is fully simplified.
801
137
  MPM.addPass(GlobalOptPass());
802
137
  MPM.addPass(GlobalDCEPass());
803
137
804
137
  // Run partial inlining pass to partially inline functions that have
805
137
  // large bodies.
806
137
  if (RunPartialInlining)
807
0
    MPM.addPass(PartialInlinerPass());
808
137
809
137
  // Remove avail extern fns and globals definitions since we aren't compiling
810
137
  // an object file for later LTO. For LTO we want to preserve these so they
811
137
  // are eligible for inlining at link-time. Note if they are unreferenced they
812
137
  // will be removed by GlobalDCE later, so this only impacts referenced
813
137
  // available externally globals. Eventually they will be suppressed during
814
137
  // codegen, but eliminating here enables more opportunity for GlobalDCE as it
815
137
  // may make globals referenced by available external functions dead and saves
816
137
  // running remaining passes on the eliminated functions. These should be
817
137
  // preserved during prelinking for link-time inlining decisions.
818
137
  if (!LTOPreLink)
819
120
    MPM.addPass(EliminateAvailableExternallyPass());
820
137
821
137
  if (EnableOrderFileInstrumentation)
822
0
    MPM.addPass(InstrOrderFilePass());
823
137
824
137
  // Do RPO function attribute inference across the module to forward-propagate
825
137
  // attributes where applicable.
826
137
  // FIXME: Is this really an optimization rather than a canonicalization?
827
137
  MPM.addPass(ReversePostOrderFunctionAttrsPass());
828
137
829
137
  // Do a post inline PGO instrumentation and use pass. This is a context
830
137
  // sensitive PGO pass. We don't want to do this in LTOPreLink phrase as
831
137
  // cross-module inline has not been done yet. The context sensitive
832
137
  // instrumentation is after all the inlines are done.
833
137
  if (!LTOPreLink && 
PGOOpt120
) {
834
28
    if (PGOOpt->CSAction == PGOOptions::CSIRInstr)
835
6
      addPGOInstrPasses(MPM, DebugLogging, Level, /* RunProfileGen */ true,
836
6
                        /* IsCS */ true, PGOOpt->CSProfileGenFile,
837
6
                        PGOOpt->ProfileRemappingFile);
838
22
    else if (PGOOpt->CSAction == PGOOptions::CSIRUse)
839
4
      addPGOInstrPasses(MPM, DebugLogging, Level, /* RunProfileGen */ false,
840
4
                        /* IsCS */ true, PGOOpt->ProfileFile,
841
4
                        PGOOpt->ProfileRemappingFile);
842
28
  }
843
137
844
137
  // Re-require GloblasAA here prior to function passes. This is particularly
845
137
  // useful as the above will have inlined, DCE'ed, and function-attr
846
137
  // propagated everything. We should at this point have a reasonably minimal
847
137
  // and richly annotated call graph. By computing aliasing and mod/ref
848
137
  // information for all local globals here, the late loop passes and notably
849
137
  // the vectorizer will be able to use them to help recognize vectorizable
850
137
  // memory operations.
851
137
  MPM.addPass(RequireAnalysisPass<GlobalsAA, Module>());
852
137
853
137
  FunctionPassManager OptimizePM(DebugLogging);
854
137
  OptimizePM.addPass(Float2IntPass());
855
137
  // FIXME: We need to run some loop optimizations to re-rotate loops after
856
137
  // simplify-cfg and others undo their rotation.
857
137
858
137
  // Optimize the loop execution. These passes operate on entire loop nests
859
137
  // rather than on each loop in an inside-out manner, and so they are actually
860
137
  // function passes.
861
137
862
137
  for (auto &C : VectorizerStartEPCallbacks)
863
47
    C(OptimizePM, Level);
864
137
865
137
  // First rotate loops that may have been un-rotated by prior passes.
866
137
  OptimizePM.addPass(
867
137
      createFunctionToLoopPassAdaptor(LoopRotatePass(), DebugLogging));
868
137
869
137
  // Distribute loops to allow partial vectorization.  I.e. isolate dependences
870
137
  // into separate loop that would otherwise inhibit vectorization.  This is
871
137
  // currently only performed for loops marked with the metadata
872
137
  // llvm.loop.distribute=true or when -enable-loop-distribute is specified.
873
137
  OptimizePM.addPass(LoopDistributePass());
874
137
875
137
  // Now run the core loop vectorizer.
876
137
  OptimizePM.addPass(LoopVectorizePass(
877
137
      LoopVectorizeOptions(!PTO.LoopInterleaving, !PTO.LoopVectorization)));
878
137
879
137
  // Eliminate loads by forwarding stores from the previous iteration to loads
880
137
  // of the current iteration.
881
137
  OptimizePM.addPass(LoopLoadEliminationPass());
882
137
883
137
  // Cleanup after the loop optimization passes.
884
137
  OptimizePM.addPass(InstCombinePass());
885
137
886
137
  // Now that we've formed fast to execute loop structures, we do further
887
137
  // optimizations. These are run afterward as they might block doing complex
888
137
  // analyses and transforms such as what are needed for loop vectorization.
889
137
890
137
  // Cleanup after loop vectorization, etc. Simplification passes like CVP and
891
137
  // GVN, loop transforms, and others have already run, so it's now better to
892
137
  // convert to more optimized IR using more aggressive simplify CFG options.
893
137
  // The extra sinking transform can create larger basic blocks, so do this
894
137
  // before SLP vectorization.
895
137
  OptimizePM.addPass(SimplifyCFGPass(SimplifyCFGOptions().
896
137
                                     forwardSwitchCondToPhi(true).
897
137
                                     convertSwitchToLookupTable(true).
898
137
                                     needCanonicalLoops(false).
899
137
                                     sinkCommonInsts(true)));
900
137
901
137
  // Optimize parallel scalar instruction chains into SIMD instructions.
902
137
  if (PTO.SLPVectorization)
903
4
    OptimizePM.addPass(SLPVectorizerPass());
904
137
905
137
  OptimizePM.addPass(InstCombinePass());
906
137
907
137
  // Unroll small loops to hide loop backedge latency and saturate any parallel
908
137
  // execution resources of an out-of-order processor. We also then need to
909
137
  // clean up redundancies and loop invariant code.
910
137
  // FIXME: It would be really good to use a loop-integrated instruction
911
137
  // combiner for cleanup here so that the unrolling and LICM can be pipelined
912
137
  // across the loop nests.
913
137
  // We do UnrollAndJam in a separate LPM to ensure it happens before unroll
914
137
  if (EnableUnrollAndJam) {
915
0
    OptimizePM.addPass(
916
0
        createFunctionToLoopPassAdaptor(LoopUnrollAndJamPass(Level)));
917
0
  }
918
137
  if (PTO.LoopUnrolling)
919
106
    OptimizePM.addPass(LoopUnrollPass(
920
106
        LoopUnrollOptions(Level, false, PTO.ForgetAllSCEVInLoopUnroll)));
921
137
  OptimizePM.addPass(WarnMissedTransformationsPass());
922
137
  OptimizePM.addPass(InstCombinePass());
923
137
  OptimizePM.addPass(RequireAnalysisPass<OptimizationRemarkEmitterAnalysis, Function>());
924
137
  OptimizePM.addPass(createFunctionToLoopPassAdaptor(
925
137
      LICMPass(PTO.LicmMssaOptCap, PTO.LicmMssaNoAccForPromotionCap),
926
137
      DebugLogging));
927
137
928
137
  // Now that we've vectorized and unrolled loops, we may have more refined
929
137
  // alignment information, try to re-derive it here.
930
137
  OptimizePM.addPass(AlignmentFromAssumptionsPass());
931
137
932
137
  // Split out cold code. Splitting is done late to avoid hiding context from
933
137
  // other optimizations and inadvertently regressing performance. The tradeoff
934
137
  // is that this has a higher code size cost than splitting early.
935
137
  if (EnableHotColdSplit && 
!LTOPreLink1
)
936
1
    MPM.addPass(HotColdSplittingPass());
937
137
938
137
  // LoopSink pass sinks instructions hoisted by LICM, which serves as a
939
137
  // canonicalization pass that enables other optimizations. As a result,
940
137
  // LoopSink pass needs to be a very late IR pass to avoid undoing LICM
941
137
  // result too early.
942
137
  OptimizePM.addPass(LoopSinkPass());
943
137
944
137
  // And finally clean up LCSSA form before generating code.
945
137
  OptimizePM.addPass(InstSimplifyPass());
946
137
947
137
  // This hoists/decomposes div/rem ops. It should run after other sink/hoist
948
137
  // passes to avoid re-sinking, but before SimplifyCFG because it can allow
949
137
  // flattening of blocks.
950
137
  OptimizePM.addPass(DivRemPairsPass());
951
137
952
137
  // LoopSink (and other loop passes since the last simplifyCFG) might have
953
137
  // resulted in single-entry-single-exit or empty blocks. Clean up the CFG.
954
137
  OptimizePM.addPass(SimplifyCFGPass());
955
137
956
137
  // Optimize PHIs by speculating around them when profitable. Note that this
957
137
  // pass needs to be run after any PRE or similar pass as it is essentially
958
137
  // inserting redundancies into the program. This even includes SimplifyCFG.
959
137
  OptimizePM.addPass(SpeculateAroundPHIsPass());
960
137
961
137
  for (auto &C : OptimizerLastEPCallbacks)
962
9
    C(OptimizePM, Level);
963
137
964
137
  // Add the core optimizing pipeline.
965
137
  MPM.addPass(createModuleToFunctionPassAdaptor(std::move(OptimizePM)));
966
137
967
137
  MPM.addPass(CGProfilePass());
968
137
969
137
  // Now we need to do some global optimization transforms.
970
137
  // FIXME: It would seem like these should come first in the optimization
971
137
  // pipeline and maybe be the bottom of the canonicalization pipeline? Weird
972
137
  // ordering here.
973
137
  MPM.addPass(GlobalDCEPass());
974
137
  MPM.addPass(ConstantMergePass());
975
137
976
137
  return MPM;
977
137
}
978
979
ModulePassManager
980
PassBuilder::buildPerModuleDefaultPipeline(OptimizationLevel Level,
981
113
                                           bool DebugLogging, bool LTOPreLink) {
982
113
  assert(Level != O0 && "Must request optimizations for the default pipeline!");
983
113
984
113
  ModulePassManager MPM(DebugLogging);
985
113
986
113
  // Force any function attributes we want the rest of the pipeline to observe.
987
113
  MPM.addPass(ForceFunctionAttrsPass());
988
113
989
113
  // Apply module pipeline start EP callback.
990
113
  for (auto &C : PipelineStartEPCallbacks)
991
86
    C(MPM);
992
113
993
113
  if (PGOOpt && 
PGOOpt->SamplePGOSupport25
)
994
7
    MPM.addPass(createModuleToFunctionPassAdaptor(AddDiscriminatorsPass()));
995
113
996
113
  // Add the core simplification pipeline.
997
113
  MPM.addPass(buildModuleSimplificationPipeline(Level, ThinLTOPhase::None,
998
113
                                                DebugLogging));
999
113
1000
113
  // Now add the optimization pipeline.
1001
113
  MPM.addPass(buildModuleOptimizationPipeline(Level, DebugLogging, LTOPreLink));
1002
113
1003
113
  return MPM;
1004
113
}
1005
1006
ModulePassManager
1007
PassBuilder::buildThinLTOPreLinkDefaultPipeline(OptimizationLevel Level,
1008
23
                                                bool DebugLogging) {
1009
23
  assert(Level != O0 && "Must request optimizations for the default pipeline!");
1010
23
1011
23
  ModulePassManager MPM(DebugLogging);
1012
23
1013
23
  // Force any function attributes we want the rest of the pipeline to observe.
1014
23
  MPM.addPass(ForceFunctionAttrsPass());
1015
23
1016
23
  if (PGOOpt && 
PGOOpt->SamplePGOSupport10
)
1017
6
    MPM.addPass(createModuleToFunctionPassAdaptor(AddDiscriminatorsPass()));
1018
23
1019
23
  // Apply module pipeline start EP callback.
1020
23
  for (auto &C : PipelineStartEPCallbacks)
1021
14
    C(MPM);
1022
23
1023
23
  // If we are planning to perform ThinLTO later, we don't bloat the code with
1024
23
  // unrolling/vectorization/... now. Just simplify the module as much as we
1025
23
  // can.
1026
23
  MPM.addPass(buildModuleSimplificationPipeline(Level, ThinLTOPhase::PreLink,
1027
23
                                                DebugLogging));
1028
23
1029
23
  // Run partial inlining pass to partially inline functions that have
1030
23
  // large bodies.
1031
23
  // FIXME: It isn't clear whether this is really the right place to run this
1032
23
  // in ThinLTO. Because there is another canonicalization and simplification
1033
23
  // phase that will run after the thin link, running this here ends up with
1034
23
  // less information than will be available later and it may grow functions in
1035
23
  // ways that aren't beneficial.
1036
23
  if (RunPartialInlining)
1037
0
    MPM.addPass(PartialInlinerPass());
1038
23
1039
23
  // Reduce the size of the IR as much as possible.
1040
23
  MPM.addPass(GlobalOptPass());
1041
23
1042
23
  return MPM;
1043
23
}
1044
1045
ModulePassManager PassBuilder::buildThinLTODefaultPipeline(
1046
    OptimizationLevel Level, bool DebugLogging,
1047
25
    const ModuleSummaryIndex *ImportSummary) {
1048
25
  ModulePassManager MPM(DebugLogging);
1049
25
1050
25
  if (ImportSummary) {
1051
15
    // These passes import type identifier resolutions for whole-program
1052
15
    // devirtualization and CFI. They must run early because other passes may
1053
15
    // disturb the specific instruction patterns that these passes look for,
1054
15
    // creating dependencies on resolutions that may not appear in the summary.
1055
15
    //
1056
15
    // For example, GVN may transform the pattern assume(type.test) appearing in
1057
15
    // two basic blocks into assume(phi(type.test, type.test)), which would
1058
15
    // transform a dependency on a WPD resolution into a dependency on a type
1059
15
    // identifier resolution for CFI.
1060
15
    //
1061
15
    // Also, WPD has access to more precise information than ICP and can
1062
15
    // devirtualize more effectively, so it should operate on the IR first.
1063
15
    //
1064
15
    // The WPD and LowerTypeTest passes need to run at -O0 to lower type
1065
15
    // metadata and intrinsics.
1066
15
    MPM.addPass(WholeProgramDevirtPass(nullptr, ImportSummary));
1067
15
    MPM.addPass(LowerTypeTestsPass(nullptr, ImportSummary));
1068
15
  }
1069
25
1070
25
  if (Level == O0)
1071
1
    return MPM;
1072
24
1073
24
  // Force any function attributes we want the rest of the pipeline to observe.
1074
24
  MPM.addPass(ForceFunctionAttrsPass());
1075
24
1076
24
  // Add the core simplification pipeline.
1077
24
  MPM.addPass(buildModuleSimplificationPipeline(Level, ThinLTOPhase::PostLink,
1078
24
                                                DebugLogging));
1079
24
1080
24
  // Now add the optimization pipeline.
1081
24
  MPM.addPass(buildModuleOptimizationPipeline(Level, DebugLogging));
1082
24
1083
24
  return MPM;
1084
24
}
1085
1086
ModulePassManager
1087
PassBuilder::buildLTOPreLinkDefaultPipeline(OptimizationLevel Level,
1088
17
                                            bool DebugLogging) {
1089
17
  assert(Level != O0 && "Must request optimizations for the default pipeline!");
1090
17
  // FIXME: We should use a customized pre-link pipeline!
1091
17
  return buildPerModuleDefaultPipeline(Level, DebugLogging,
1092
17
                                       /* LTOPreLink */true);
1093
17
}
1094
1095
ModulePassManager
1096
PassBuilder::buildLTODefaultPipeline(OptimizationLevel Level, bool DebugLogging,
1097
22
                                     ModuleSummaryIndex *ExportSummary) {
1098
22
  ModulePassManager MPM(DebugLogging);
1099
22
1100
22
  if (Level == O0) {
1101
0
    // The WPD and LowerTypeTest passes need to run at -O0 to lower type
1102
0
    // metadata and intrinsics.
1103
0
    MPM.addPass(WholeProgramDevirtPass(ExportSummary, nullptr));
1104
0
    MPM.addPass(LowerTypeTestsPass(ExportSummary, nullptr));
1105
0
    return MPM;
1106
0
  }
1107
22
1108
22
  if (PGOOpt && 
PGOOpt->Action == PGOOptions::SampleUse4
) {
1109
2
    // Load sample profile before running the LTO optimization pipeline.
1110
2
    MPM.addPass(SampleProfileLoaderPass(PGOOpt->ProfileFile,
1111
2
                                        PGOOpt->ProfileRemappingFile,
1112
2
                                        false /* ThinLTOPhase::PreLink */));
1113
2
    // Cache ProfileSummaryAnalysis once to avoid the potential need to insert
1114
2
    // RequireAnalysisPass for PSI before subsequent non-module passes.
1115
2
    MPM.addPass(RequireAnalysisPass<ProfileSummaryAnalysis, Module>());
1116
2
  }
1117
22
1118
22
  // Remove unused virtual tables to improve the quality of code generated by
1119
22
  // whole-program devirtualization and bitset lowering.
1120
22
  MPM.addPass(GlobalDCEPass());
1121
22
1122
22
  // Force any function attributes we want the rest of the pipeline to observe.
1123
22
  MPM.addPass(ForceFunctionAttrsPass());
1124
22
1125
22
  // Do basic inference of function attributes from known properties of system
1126
22
  // libraries and other oracles.
1127
22
  MPM.addPass(InferFunctionAttrsPass());
1128
22
1129
22
  if (Level > 1) {
1130
21
    FunctionPassManager EarlyFPM(DebugLogging);
1131
21
    EarlyFPM.addPass(CallSiteSplittingPass());
1132
21
    MPM.addPass(createModuleToFunctionPassAdaptor(std::move(EarlyFPM)));
1133
21
1134
21
    // Indirect call promotion. This should promote all the targets that are
1135
21
    // left by the earlier promotion pass that promotes intra-module targets.
1136
21
    // This two-step promotion is to save the compile time. For LTO, it should
1137
21
    // produce the same result as if we only do promotion here.
1138
21
    MPM.addPass(PGOIndirectCallPromotion(
1139
21
        true /* InLTO */, PGOOpt && 
PGOOpt->Action == PGOOptions::SampleUse4
));
1140
21
    // Propagate constants at call sites into the functions they call.  This
1141
21
    // opens opportunities for globalopt (and inlining) by substituting function
1142
21
    // pointers passed as arguments to direct uses of functions.
1143
21
   MPM.addPass(IPSCCPPass());
1144
21
1145
21
   // Attach metadata to indirect call sites indicating the set of functions
1146
21
   // they may target at run-time. This should follow IPSCCP.
1147
21
   MPM.addPass(CalledValuePropagationPass());
1148
21
  }
1149
22
1150
22
  // Now deduce any function attributes based in the current code.
1151
22
  MPM.addPass(createModuleToPostOrderCGSCCPassAdaptor(
1152
22
              PostOrderFunctionAttrsPass()));
1153
22
1154
22
  // Do RPO function attribute inference across the module to forward-propagate
1155
22
  // attributes where applicable.
1156
22
  // FIXME: Is this really an optimization rather than a canonicalization?
1157
22
  MPM.addPass(ReversePostOrderFunctionAttrsPass());
1158
22
1159
22
  // Use in-range annotations on GEP indices to split globals where beneficial.
1160
22
  MPM.addPass(GlobalSplitPass());
1161
22
1162
22
  // Run whole program optimization of virtual call when the list of callees
1163
22
  // is fixed.
1164
22
  MPM.addPass(WholeProgramDevirtPass(ExportSummary, nullptr));
1165
22
1166
22
  // Stop here at -O1.
1167
22
  if (Level == 1) {
1168
1
    // The LowerTypeTestsPass needs to run to lower type metadata and the
1169
1
    // type.test intrinsics. The pass does nothing if CFI is disabled.
1170
1
    MPM.addPass(LowerTypeTestsPass(ExportSummary, nullptr));
1171
1
    return MPM;
1172
1
  }
1173
21
1174
21
  // Optimize globals to try and fold them into constants.
1175
21
  MPM.addPass(GlobalOptPass());
1176
21
1177
21
  // Promote any localized globals to SSA registers.
1178
21
  MPM.addPass(createModuleToFunctionPassAdaptor(PromotePass()));
1179
21
1180
21
  // Linking modules together can lead to duplicate global constant, only
1181
21
  // keep one copy of each constant.
1182
21
  MPM.addPass(ConstantMergePass());
1183
21
1184
21
  // Remove unused arguments from functions.
1185
21
  MPM.addPass(DeadArgumentEliminationPass());
1186
21
1187
21
  // Reduce the code after globalopt and ipsccp.  Both can open up significant
1188
21
  // simplification opportunities, and both can propagate functions through
1189
21
  // function pointers.  When this happens, we often have to resolve varargs
1190
21
  // calls, etc, so let instcombine do this.
1191
21
  FunctionPassManager PeepholeFPM(DebugLogging);
1192
21
  if (Level == O3)
1193
2
    PeepholeFPM.addPass(AggressiveInstCombinePass());
1194
21
  PeepholeFPM.addPass(InstCombinePass());
1195
21
  invokePeepholeEPCallbacks(PeepholeFPM, Level);
1196
21
1197
21
  MPM.addPass(createModuleToFunctionPassAdaptor(std::move(PeepholeFPM)));
1198
21
1199
21
  // Note: historically, the PruneEH pass was run first to deduce nounwind and
1200
21
  // generally clean up exception handling overhead. It isn't clear this is
1201
21
  // valuable as the inliner doesn't currently care whether it is inlining an
1202
21
  // invoke or a call.
1203
21
  // Run the inliner now.
1204
21
  MPM.addPass(createModuleToPostOrderCGSCCPassAdaptor(
1205
21
      InlinerPass(getInlineParamsFromOptLevel(Level))));
1206
21
1207
21
  // Optimize globals again after we ran the inliner.
1208
21
  MPM.addPass(GlobalOptPass());
1209
21
1210
21
  // Garbage collect dead functions.
1211
21
  // FIXME: Add ArgumentPromotion pass after once it's ported.
1212
21
  MPM.addPass(GlobalDCEPass());
1213
21
1214
21
  FunctionPassManager FPM(DebugLogging);
1215
21
  // The IPO Passes may leave cruft around. Clean up after them.
1216
21
  FPM.addPass(InstCombinePass());
1217
21
  invokePeepholeEPCallbacks(FPM, Level);
1218
21
1219
21
  FPM.addPass(JumpThreadingPass());
1220
21
1221
21
  // Do a post inline PGO instrumentation and use pass. This is a context
1222
21
  // sensitive PGO pass.
1223
21
  if (PGOOpt) {
1224
4
    if (PGOOpt->CSAction == PGOOptions::CSIRInstr)
1225
1
      addPGOInstrPasses(MPM, DebugLogging, Level, /* RunProfileGen */ true,
1226
1
                        /* IsCS */ true, PGOOpt->CSProfileGenFile,
1227
1
                        PGOOpt->ProfileRemappingFile);
1228
3
    else if (PGOOpt->CSAction == PGOOptions::CSIRUse)
1229
1
      addPGOInstrPasses(MPM, DebugLogging, Level, /* RunProfileGen */ false,
1230
1
                        /* IsCS */ true, PGOOpt->ProfileFile,
1231
1
                        PGOOpt->ProfileRemappingFile);
1232
4
  }
1233
21
1234
21
  // Break up allocas
1235
21
  FPM.addPass(SROA());
1236
21
1237
21
  // LTO provides additional opportunities for tailcall elimination due to
1238
21
  // link-time inlining, and visibility of nocapture attribute.
1239
21
  FPM.addPass(TailCallElimPass());
1240
21
1241
21
  // Run a few AA driver optimizations here and now to cleanup the code.
1242
21
  MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
1243
21
1244
21
  MPM.addPass(createModuleToPostOrderCGSCCPassAdaptor(
1245
21
              PostOrderFunctionAttrsPass()));
1246
21
  // FIXME: here we run IP alias analysis in the legacy PM.
1247
21
1248
21
  FunctionPassManager MainFPM;
1249
21
1250
21
  // FIXME: once we fix LoopPass Manager, add LICM here.
1251
21
  // FIXME: once we provide support for enabling MLSM, add it here.
1252
21
  if (RunNewGVN)
1253
0
    MainFPM.addPass(NewGVNPass());
1254
21
  else
1255
21
    MainFPM.addPass(GVN());
1256
21
1257
21
  // Remove dead memcpy()'s.
1258
21
  MainFPM.addPass(MemCpyOptPass());
1259
21
1260
21
  // Nuke dead stores.
1261
21
  MainFPM.addPass(DSEPass());
1262
21
1263
21
  // FIXME: at this point, we run a bunch of loop passes:
1264
21
  // indVarSimplify, loopDeletion, loopInterchange, loopUnroll,
1265
21
  // loopVectorize. Enable them once the remaining issue with LPM
1266
21
  // are sorted out.
1267
21
1268
21
  MainFPM.addPass(InstCombinePass());
1269
21
  MainFPM.addPass(SimplifyCFGPass());
1270
21
  MainFPM.addPass(SCCPPass());
1271
21
  MainFPM.addPass(InstCombinePass());
1272
21
  MainFPM.addPass(BDCEPass());
1273
21
1274
21
  // FIXME: We may want to run SLPVectorizer here.
1275
21
  // After vectorization, assume intrinsics may tell us more
1276
21
  // about pointer alignments.
1277
#if 0
1278
  MainFPM.add(AlignmentFromAssumptionsPass());
1279
#endif
1280
1281
21
  // FIXME: Conditionally run LoadCombine here, after it's ported
1282
21
  // (in case we still have this pass, given its questionable usefulness).
1283
21
1284
21
  MainFPM.addPass(InstCombinePass());
1285
21
  invokePeepholeEPCallbacks(MainFPM, Level);
1286
21
  MainFPM.addPass(JumpThreadingPass());
1287
21
  MPM.addPass(createModuleToFunctionPassAdaptor(std::move(MainFPM)));
1288
21
1289
21
  // Create a function that performs CFI checks for cross-DSO calls with
1290
21
  // targets in the current module.
1291
21
  MPM.addPass(CrossDSOCFIPass());
1292
21
1293
21
  // Lower type metadata and the type.test intrinsic. This pass supports
1294
21
  // clang's control flow integrity mechanisms (-fsanitize=cfi*) and needs
1295
21
  // to be run at link time if CFI is enabled. This pass does nothing if
1296
21
  // CFI is disabled.
1297
21
  MPM.addPass(LowerTypeTestsPass(ExportSummary, nullptr));
1298
21
1299
21
  // Enable splitting late in the FullLTO post-link pipeline. This is done in
1300
21
  // the same stage in the old pass manager (\ref addLateLTOOptimizationPasses).
1301
21
  if (EnableHotColdSplit)
1302
0
    MPM.addPass(HotColdSplittingPass());
1303
21
1304
21
  // Add late LTO optimization passes.
1305
21
  // Delete basic blocks, which optimization passes may have killed.
1306
21
  MPM.addPass(createModuleToFunctionPassAdaptor(SimplifyCFGPass()));
1307
21
1308
21
  // Drop bodies of available eternally objects to improve GlobalDCE.
1309
21
  MPM.addPass(EliminateAvailableExternallyPass());
1310
21
1311
21
  // Now that we have optimized the program, discard unreachable functions.
1312
21
  MPM.addPass(GlobalDCEPass());
1313
21
1314
21
  // FIXME: Maybe enable MergeFuncs conditionally after it's ported.
1315
21
  return MPM;
1316
21
}
1317
1318
161
AAManager PassBuilder::buildDefaultAAPipeline() {
1319
161
  AAManager AA;
1320
161
1321
161
  // The order in which these are registered determines their priority when
1322
161
  // being queried.
1323
161
1324
161
  // First we register the basic alias analysis that provides the majority of
1325
161
  // per-function local AA logic. This is a stateless, on-demand local set of
1326
161
  // AA techniques.
1327
161
  AA.registerFunctionAnalysis<BasicAA>();
1328
161
1329
161
  // Next we query fast, specialized alias analyses that wrap IR-embedded
1330
161
  // information about aliasing.
1331
161
  AA.registerFunctionAnalysis<ScopedNoAliasAA>();
1332
161
  AA.registerFunctionAnalysis<TypeBasedAA>();
1333
161
1334
161
  // Add support for querying global aliasing information when available.
1335
161
  // Because the `AAManager` is a function analysis and `GlobalsAA` is a module
1336
161
  // analysis, all that the `AAManager` can do is query for any *cached*
1337
161
  // results from `GlobalsAA` through a readonly proxy.
1338
161
  AA.registerModuleAnalysis<GlobalsAA>();
1339
161
1340
161
  return AA;
1341
161
}
1342
1343
2.45k
static Optional<int> parseRepeatPassName(StringRef Name) {
1344
2.45k
  if (!Name.consume_front("repeat<") || 
!Name.consume_back(">")5
)
1345
2.44k
    return None;
1346
5
  int Count;
1347
5
  if (Name.getAsInteger(0, Count) || Count <= 0)
1348
0
    return None;
1349
5
  return Count;
1350
5
}
1351
1352
739
static Optional<int> parseDevirtPassName(StringRef Name) {
1353
739
  if (!Name.consume_front("devirt<") || 
!Name.consume_back(">")3
)
1354
736
    return None;
1355
3
  int Count;
1356
3
  if (Name.getAsInteger(0, Count) || Count <= 0)
1357
0
    return None;
1358
3
  return Count;
1359
3
}
1360
1361
599
static bool checkParametrizedPassName(StringRef Name, StringRef PassName) {
1362
599
  if (!Name.consume_front(PassName))
1363
436
    return false;
1364
163
  // normal pass name w/o parameters == default parameters
1365
163
  if (Name.empty())
1366
77
    return true;
1367
86
  return Name.startswith("<") && Name.endswith(">");
1368
86
}
1369
1370
namespace {
1371
1372
/// This performs customized parsing of pass name with parameters.
1373
///
1374
/// We do not need parametrization of passes in textual pipeline very often,
1375
/// yet on a rare occasion ability to specify parameters right there can be
1376
/// useful.
1377
///
1378
/// \p Name - parameterized specification of a pass from a textual pipeline
1379
/// is a string in a form of :
1380
///      PassName '<' parameter-list '>'
1381
///
1382
/// Parameter list is being parsed by the parser callable argument, \p Parser,
1383
/// It takes a string-ref of parameters and returns either StringError or a
1384
/// parameter list in a form of a custom parameters type, all wrapped into
1385
/// Expected<> template class.
1386
///
1387
template <typename ParametersParseCallableT>
1388
auto parsePassParameters(ParametersParseCallableT &&Parser, StringRef Name,
1389
122
                         StringRef PassName) -> decltype(Parser(StringRef{})) {
1390
122
  using ParametersT = typename decltype(Parser(StringRef{}))::value_type;
1391
122
1392
122
  StringRef Params = Name;
1393
122
  if (!Params.consume_front(PassName)) {
1394
0
    assert(false &&
1395
0
           "unable to strip pass name from parametrized pass specification");
1396
0
  }
1397
122
  if (Params.empty())
1398
62
    return ParametersT{};
1399
60
  if (!Params.consume_front("<") || !Params.consume_back(">")) {
1400
0
    assert(false && "invalid format for parametrized pass name");
1401
0
  }
1402
60
1403
60
  Expected<ParametersT> Result = Parser(Params);
1404
60
  assert((Result || Result.template errorIsA<StringError>()) &&
1405
60
         "Pass parameter parser can only return StringErrors.");
1406
60
  return std::move(Result);
1407
60
}
PassBuilder.cpp:decltype(fp(llvm::StringRef{})) (anonymous namespace)::parsePassParameters<llvm::Expected<llvm::LoopUnrollOptions> (&)(llvm::StringRef)>(llvm::Expected<llvm::LoopUnrollOptions> (&&&)(llvm::StringRef), llvm::StringRef, llvm::StringRef)
Line
Count
Source
1389
24
                         StringRef PassName) -> decltype(Parser(StringRef{})) {
1390
24
  using ParametersT = typename decltype(Parser(StringRef{}))::value_type;
1391
24
1392
24
  StringRef Params = Name;
1393
24
  if (!Params.consume_front(PassName)) {
1394
0
    assert(false &&
1395
0
           "unable to strip pass name from parametrized pass specification");
1396
0
  }
1397
24
  if (Params.empty())
1398
21
    return ParametersT{};
1399
3
  if (!Params.consume_front("<") || !Params.consume_back(">")) {
1400
0
    assert(false && "invalid format for parametrized pass name");
1401
0
  }
1402
3
1403
3
  Expected<ParametersT> Result = Parser(Params);
1404
3
  assert((Result || Result.template errorIsA<StringError>()) &&
1405
3
         "Pass parameter parser can only return StringErrors.");
1406
3
  return std::move(Result);
1407
3
}
PassBuilder.cpp:decltype(fp(llvm::StringRef{})) (anonymous namespace)::parsePassParameters<llvm::Expected<llvm::MemorySanitizerOptions> (&)(llvm::StringRef)>(llvm::Expected<llvm::MemorySanitizerOptions> (&&&)(llvm::StringRef), llvm::StringRef, llvm::StringRef)
Line
Count
Source
1389
2
                         StringRef PassName) -> decltype(Parser(StringRef{})) {
1390
2
  using ParametersT = typename decltype(Parser(StringRef{}))::value_type;
1391
2
1392
2
  StringRef Params = Name;
1393
2
  if (!Params.consume_front(PassName)) {
1394
0
    assert(false &&
1395
0
           "unable to strip pass name from parametrized pass specification");
1396
0
  }
1397
2
  if (Params.empty())
1398
0
    return ParametersT{};
1399
2
  if (!Params.consume_front("<") || !Params.consume_back(">")) {
1400
0
    assert(false && "invalid format for parametrized pass name");
1401
0
  }
1402
2
1403
2
  Expected<ParametersT> Result = Parser(Params);
1404
2
  assert((Result || Result.template errorIsA<StringError>()) &&
1405
2
         "Pass parameter parser can only return StringErrors.");
1406
2
  return std::move(Result);
1407
2
}
PassBuilder.cpp:decltype(fp(llvm::StringRef{})) (anonymous namespace)::parsePassParameters<llvm::Expected<llvm::SimplifyCFGOptions> (&)(llvm::StringRef)>(llvm::Expected<llvm::SimplifyCFGOptions> (&&&)(llvm::StringRef), llvm::StringRef, llvm::StringRef)
Line
Count
Source
1389
38
                         StringRef PassName) -> decltype(Parser(StringRef{})) {
1390
38
  using ParametersT = typename decltype(Parser(StringRef{}))::value_type;
1391
38
1392
38
  StringRef Params = Name;
1393
38
  if (!Params.consume_front(PassName)) {
1394
0
    assert(false &&
1395
0
           "unable to strip pass name from parametrized pass specification");
1396
0
  }
1397
38
  if (Params.empty())
1398
17
    return ParametersT{};
1399
21
  if (!Params.consume_front("<") || !Params.consume_back(">")) {
1400
0
    assert(false && "invalid format for parametrized pass name");
1401
0
  }
1402
21
1403
21
  Expected<ParametersT> Result = Parser(Params);
1404
21
  assert((Result || Result.template errorIsA<StringError>()) &&
1405
21
         "Pass parameter parser can only return StringErrors.");
1406
21
  return std::move(Result);
1407
21
}
PassBuilder.cpp:decltype(fp(llvm::StringRef{})) (anonymous namespace)::parsePassParameters<llvm::Expected<llvm::LoopVectorizeOptions> (&)(llvm::StringRef)>(llvm::Expected<llvm::LoopVectorizeOptions> (&&&)(llvm::StringRef), llvm::StringRef, llvm::StringRef)
Line
Count
Source
1389
14
                         StringRef PassName) -> decltype(Parser(StringRef{})) {
1390
14
  using ParametersT = typename decltype(Parser(StringRef{}))::value_type;
1391
14
1392
14
  StringRef Params = Name;
1393
14
  if (!Params.consume_front(PassName)) {
1394
0
    assert(false &&
1395
0
           "unable to strip pass name from parametrized pass specification");
1396
0
  }
1397
14
  if (Params.empty())
1398
12
    return ParametersT{};
1399
2
  if (!Params.consume_front("<") || !Params.consume_back(">")) {
1400
0
    assert(false && "invalid format for parametrized pass name");
1401
0
  }
1402
2
1403
2
  Expected<ParametersT> Result = Parser(Params);
1404
2
  assert((Result || Result.template errorIsA<StringError>()) &&
1405
2
         "Pass parameter parser can only return StringErrors.");
1406
2
  return std::move(Result);
1407
2
}
PassBuilder.cpp:decltype(fp(llvm::StringRef{})) (anonymous namespace)::parsePassParameters<llvm::Expected<bool> (&)(llvm::StringRef)>(llvm::Expected<bool> (&&&)(llvm::StringRef), llvm::StringRef, llvm::StringRef)
Line
Count
Source
1389
44
                         StringRef PassName) -> decltype(Parser(StringRef{})) {
1390
44
  using ParametersT = typename decltype(Parser(StringRef{}))::value_type;
1391
44
1392
44
  StringRef Params = Name;
1393
44
  if (!Params.consume_front(PassName)) {
1394
0
    assert(false &&
1395
0
           "unable to strip pass name from parametrized pass specification");
1396
0
  }
1397
44
  if (Params.empty())
1398
12
    return ParametersT{};
1399
32
  if (!Params.consume_front("<") || !Params.consume_back(">")) {
1400
0
    assert(false && "invalid format for parametrized pass name");
1401
0
  }
1402
32
1403
32
  Expected<ParametersT> Result = Parser(Params);
1404
32
  assert((Result || Result.template errorIsA<StringError>()) &&
1405
32
         "Pass parameter parser can only return StringErrors.");
1406
32
  return std::move(Result);
1407
32
}
1408
1409
/// Parser of parameters for LoopUnroll pass.
1410
3
Expected<LoopUnrollOptions> parseLoopUnrollOptions(StringRef Params) {
1411
3
  LoopUnrollOptions UnrollOpts;
1412
9
  while (!Params.empty()) {
1413
6
    StringRef ParamName;
1414
6
    std::tie(ParamName, Params) = Params.split(';');
1415
6
    int OptLevel = StringSwitch<int>(ParamName)
1416
6
                       .Case("O0", 0)
1417
6
                       .Case("O1", 1)
1418
6
                       .Case("O2", 2)
1419
6
                       .Case("O3", 3)
1420
6
                       .Default(-1);
1421
6
    if (OptLevel >= 0) {
1422
0
      UnrollOpts.setOptLevel(OptLevel);
1423
0
      continue;
1424
0
    }
1425
6
1426
6
    bool Enable = !ParamName.consume_front("no-");
1427
6
    if (ParamName == "partial") {
1428
0
      UnrollOpts.setPartial(Enable);
1429
6
    } else if (ParamName == "peeling") {
1430
3
      UnrollOpts.setPeeling(Enable);
1431
3
    } else if (ParamName == "runtime") {
1432
3
      UnrollOpts.setRuntime(Enable);
1433
3
    } else 
if (0
ParamName == "upperbound"0
) {
1434
0
      UnrollOpts.setUpperBound(Enable);
1435
0
    } else {
1436
0
      return make_error<StringError>(
1437
0
          formatv("invalid LoopUnrollPass parameter '{0}' ", ParamName).str(),
1438
0
          inconvertibleErrorCode());
1439
0
    }
1440
6
  }
1441
3
  return UnrollOpts;
1442
3
}
1443
1444
2
Expected<MemorySanitizerOptions> parseMSanPassOptions(StringRef Params) {
1445
2
  MemorySanitizerOptions Result;
1446
4
  while (!Params.empty()) {
1447
2
    StringRef ParamName;
1448
2
    std::tie(ParamName, Params) = Params.split(';');
1449
2
1450
2
    if (ParamName == "recover") {
1451
0
      Result.Recover = true;
1452
2
    } else if (ParamName == "kernel") {
1453
1
      Result.Kernel = true;
1454
1
    } else if (ParamName.consume_front("track-origins=")) {
1455
1
      if (ParamName.getAsInteger(0, Result.TrackOrigins))
1456
0
        return make_error<StringError>(
1457
0
            formatv("invalid argument to MemorySanitizer pass track-origins "
1458
0
                    "parameter: '{0}' ",
1459
0
                    ParamName)
1460
0
                .str(),
1461
0
            inconvertibleErrorCode());
1462
0
    } else {
1463
0
      return make_error<StringError>(
1464
0
          formatv("invalid MemorySanitizer pass parameter '{0}' ", ParamName)
1465
0
              .str(),
1466
0
          inconvertibleErrorCode());
1467
0
    }
1468
2
  }
1469
2
  return Result;
1470
2
}
1471
1472
/// Parser of parameters for SimplifyCFG pass.
1473
21
Expected<SimplifyCFGOptions> parseSimplifyCFGOptions(StringRef Params) {
1474
21
  SimplifyCFGOptions Result;
1475
44
  while (!Params.empty()) {
1476
23
    StringRef ParamName;
1477
23
    std::tie(ParamName, Params) = Params.split(';');
1478
23
1479
23
    bool Enable = !ParamName.consume_front("no-");
1480
23
    if (ParamName == "forward-switch-cond") {
1481
2
      Result.forwardSwitchCondToPhi(Enable);
1482
21
    } else if (ParamName == "switch-to-lookup") {
1483
13
      Result.convertSwitchToLookupTable(Enable);
1484
13
    } else 
if (8
ParamName == "keep-loops"8
) {
1485
4
      Result.needCanonicalLoops(Enable);
1486
4
    } else if (ParamName == "sink-common-insts") {
1487
2
      Result.sinkCommonInsts(Enable);
1488
2
    } else if (Enable && ParamName.consume_front("bonus-inst-threshold=")) {
1489
2
      APInt BonusInstThreshold;
1490
2
      if (ParamName.getAsInteger(0, BonusInstThreshold))
1491
0
        return make_error<StringError>(
1492
0
            formatv("invalid argument to SimplifyCFG pass bonus-threshold "
1493
0
                    "parameter: '{0}' ",
1494
0
                    ParamName).str(),
1495
0
            inconvertibleErrorCode());
1496
2
      Result.bonusInstThreshold(BonusInstThreshold.getSExtValue());
1497
2
    } else {
1498
0
      return make_error<StringError>(
1499
0
          formatv("invalid SimplifyCFG pass parameter '{0}' ", ParamName).str(),
1500
0
          inconvertibleErrorCode());
1501
0
    }
1502
23
  }
1503
21
  return Result;
1504
21
}
1505
1506
/// Parser of parameters for LoopVectorize pass.
1507
2
Expected<LoopVectorizeOptions> parseLoopVectorizeOptions(StringRef Params) {
1508
2
  LoopVectorizeOptions Opts;
1509
6
  while (!Params.empty()) {
1510
4
    StringRef ParamName;
1511
4
    std::tie(ParamName, Params) = Params.split(';');
1512
4
1513
4
    bool Enable = !ParamName.consume_front("no-");
1514
4
    if (ParamName == "interleave-forced-only") {
1515
2
      Opts.setInterleaveOnlyWhenForced(Enable);
1516
2
    } else if (ParamName == "vectorize-forced-only") {
1517
2
      Opts.setVectorizeOnlyWhenForced(Enable);
1518
2
    } else {
1519
0
      return make_error<StringError>(
1520
0
          formatv("invalid LoopVectorize parameter '{0}' ", ParamName).str(),
1521
0
          inconvertibleErrorCode());
1522
0
    }
1523
4
  }
1524
2
  return Opts;
1525
2
}
1526
1527
32
Expected<bool> parseLoopUnswitchOptions(StringRef Params) {
1528
32
  bool Result = false;
1529
64
  while (!Params.empty()) {
1530
32
    StringRef ParamName;
1531
32
    std::tie(ParamName, Params) = Params.split(';');
1532
32
1533
32
    bool Enable = !ParamName.consume_front("no-");
1534
32
    if (ParamName == "nontrivial") {
1535
32
      Result = Enable;
1536
32
    } else {
1537
0
      return make_error<StringError>(
1538
0
          formatv("invalid LoopUnswitch pass parameter '{0}' ", ParamName)
1539
0
              .str(),
1540
0
          inconvertibleErrorCode());
1541
0
    }
1542
32
  }
1543
32
  return Result;
1544
32
}
1545
} // namespace
1546
1547
/// Tests whether a pass name starts with a valid prefix for a default pipeline
1548
/// alias.
1549
1.72k
static bool startsWithDefaultPipelineAliasPrefix(StringRef Name) {
1550
1.72k
  return Name.startswith("default") || 
Name.startswith("thinlto")1.66k
||
1551
1.72k
         
Name.startswith("lto")1.61k
;
1552
1.72k
}
1553
1554
/// Tests whether registered callbacks will accept a given pass name.
1555
///
1556
/// When parsing a pipeline text, the type of the outermost pipeline may be
1557
/// omitted, in which case the type is automatically determined from the first
1558
/// pass name in the text. This may be a name that is handled through one of the
1559
/// callbacks. We check this through the oridinary parsing callbacks by setting
1560
/// up a dummy PassManager in order to not force the client to also handle this
1561
/// type of query.
1562
template <typename PassManagerT, typename CallbacksT>
1563
1.45k
static bool callbacksAcceptPassName(StringRef Name, CallbacksT &Callbacks) {
1564
1.45k
  if (!Callbacks.empty()) {
1565
744
    PassManagerT DummyPM;
1566
744
    for (auto &CB : Callbacks)
1567
763
      if (CB(Name, DummyPM, {}))
1568
23
        return true;
1569
744
  }
1570
1.45k
  
return false1.43k
;
1571
1.45k
}
PassBuilder.cpp:bool callbacksAcceptPassName<llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module> >, llvm::SmallVector<std::__1::function<bool (llvm::StringRef, llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module> >&, llvm::ArrayRef<llvm::PassBuilder::PipelineElement>)>, 2u> >(llvm::StringRef, llvm::SmallVector<std::__1::function<bool (llvm::StringRef, llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module> >&, llvm::ArrayRef<llvm::PassBuilder::PipelineElement>)>, 2u>&)
Line
Count
Source
1563
740
static bool callbacksAcceptPassName(StringRef Name, CallbacksT &Callbacks) {
1564
740
  if (!Callbacks.empty()) {
1565
710
    PassManagerT DummyPM;
1566
710
    for (auto &CB : Callbacks)
1567
710
      if (CB(Name, DummyPM, {}))
1568
8
        return true;
1569
710
  }
1570
740
  
return false732
;
1571
740
}
PassBuilder.cpp:bool callbacksAcceptPassName<llvm::PassManager<llvm::LazyCallGraph::SCC, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&>, llvm::SmallVector<std::__1::function<bool (llvm::StringRef, llvm::PassManager<llvm::LazyCallGraph::SCC, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&>&, llvm::ArrayRef<llvm::PassBuilder::PipelineElement>)>, 2u> >(llvm::StringRef, llvm::SmallVector<std::__1::function<bool (llvm::StringRef, llvm::PassManager<llvm::LazyCallGraph::SCC, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&>&, llvm::ArrayRef<llvm::PassBuilder::PipelineElement>)>, 2u>&)
Line
Count
Source
1563
663
static bool callbacksAcceptPassName(StringRef Name, CallbacksT &Callbacks) {
1564
663
  if (!Callbacks.empty()) {
1565
5
    PassManagerT DummyPM;
1566
5
    for (auto &CB : Callbacks)
1567
5
      if (CB(Name, DummyPM, {}))
1568
5
        return true;
1569
5
  }
1570
663
  
return false658
;
1571
663
}
PassBuilder.cpp:bool callbacksAcceptPassName<llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function> >, llvm::SmallVector<std::__1::function<bool (llvm::StringRef, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function> >&, llvm::ArrayRef<llvm::PassBuilder::PipelineElement>)>, 2u> >(llvm::StringRef, llvm::SmallVector<std::__1::function<bool (llvm::StringRef, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function> >&, llvm::ArrayRef<llvm::PassBuilder::PipelineElement>)>, 2u>&)
Line
Count
Source
1563
39
static bool callbacksAcceptPassName(StringRef Name, CallbacksT &Callbacks) {
1564
39
  if (!Callbacks.empty()) {
1565
24
    PassManagerT DummyPM;
1566
24
    for (auto &CB : Callbacks)
1567
43
      if (CB(Name, DummyPM, {}))
1568
5
        return true;
1569
24
  }
1570
39
  
return false34
;
1571
39
}
PassBuilder.cpp:bool callbacksAcceptPassName<llvm::PassManager<llvm::Loop, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&>, llvm::SmallVector<std::__1::function<bool (llvm::StringRef, llvm::PassManager<llvm::Loop, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&>&, llvm::ArrayRef<llvm::PassBuilder::PipelineElement>)>, 2u> >(llvm::StringRef, llvm::SmallVector<std::__1::function<bool (llvm::StringRef, llvm::PassManager<llvm::Loop, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&>&, llvm::ArrayRef<llvm::PassBuilder::PipelineElement>)>, 2u>&)
Line
Count
Source
1563
12
static bool callbacksAcceptPassName(StringRef Name, CallbacksT &Callbacks) {
1564
12
  if (!Callbacks.empty()) {
1565
5
    PassManagerT DummyPM;
1566
5
    for (auto &CB : Callbacks)
1567
5
      if (CB(Name, DummyPM, {}))
1568
5
        return true;
1569
5
  }
1570
12
  
return false7
;
1571
12
}
1572
1573
template <typename CallbacksT>
1574
1.28k
static bool isModulePassName(StringRef Name, CallbacksT &Callbacks) {
1575
1.28k
  // Manually handle aliases for pre-configured pipeline fragments.
1576
1.28k
  if (startsWithDefaultPipelineAliasPrefix(Name))
1577
67
    return DefaultAliasRegex.match(Name);
1578
1.21k
1579
1.21k
  // Explicitly handle pass manager names.
1580
1.21k
  if (Name == "module")
1581
9
    return true;
1582
1.20k
  if (Name == "cgscc")
1583
93
    return true;
1584
1.11k
  if (Name == "function")
1585
66
    return true;
1586
1.04k
1587
1.04k
  // Explicitly handle custom-parsed pass names.
1588
1.04k
  if (parseRepeatPassName(Name))
1589
1
    return true;
1590
1.04k
1591
1.04k
#define MODULE_PASS(NAME, CREATE_PASS)                                         \
1592
44.7k
  if (Name == NAME)                                                            \
1593
44.7k
    
return true281
;
1594
1.04k
#define MODULE_ANALYSIS(NAME, CREATE_PASS)                                     \
1595
12.4k
  if (
Name == "require<" NAME ">"11.3k
||
Name == "invalidate<" NAME ">"11.3k
) \
1596
12.4k
    
return true26
;
1597
56.1k
#include 
"PassRegistry.def"1.04k
1598
56.1k
1599
56.1k
  
return callbacksAcceptPassName<ModulePassManager>(Name, Callbacks)740
;
1600
56.1k
}
1601
1602
template <typename CallbacksT>
1603
735
static bool isCGSCCPassName(StringRef Name, CallbacksT &Callbacks) {
1604
735
  // Explicitly handle pass manager names.
1605
735
  if (Name == "cgscc")
1606
0
    return true;
1607
735
  if (Name == "function")
1608
0
    return true;
1609
735
1610
735
  // Explicitly handle custom-parsed pass names.
1611
735
  if (parseRepeatPassName(Name))
1612
0
    return true;
1613
735
  if (parseDevirtPassName(Name))
1614
0
    return true;
1615
735
1616
735
#define CGSCC_PASS(NAME, CREATE_PASS)                                          \
1617
3.52k
  if (Name == NAME)                                                            \
1618
3.52k
    
return true72
;
1619
735
#define CGSCC_ANALYSIS(NAME, CREATE_PASS)                                      \
1620
2.94k
  if (
Name == "require<" NAME ">"2.20k
||
Name == "invalidate<" NAME ">"2.20k
) \
1621
2.94k
    
return true0
;
1622
5.73k
#include 
"PassRegistry.def"735
1623
5.73k
1624
5.73k
  
return callbacksAcceptPassName<CGSCCPassManager>(Name, Callbacks)663
;
1625
5.73k
}
1626
1627
template <typename CallbacksT>
1628
675
static bool isFunctionPassName(StringRef Name, CallbacksT &Callbacks) {
1629
675
  // Explicitly handle pass manager names.
1630
675
  if (Name == "function")
1631
0
    return true;
1632
675
  if (Name == "loop")
1633
50
    return true;
1634
625
1635
625
  // Explicitly handle custom-parsed pass names.
1636
625
  if (parseRepeatPassName(Name))
1637
0
    return true;
1638
625
1639
625
#define FUNCTION_PASS(NAME, CREATE_PASS)                                       \
1640
25.1k
  if (Name == NAME)                                                            \
1641
25.1k
    
return true364
;
1642
625
#define FUNCTION_PASS_WITH_PARAMS(NAME, CREATE_PASS, PARSER)                   \
1643
625
  
if (287
checkParametrizedPassName(Name, NAME)287
) \
1644
287
    
return true40
;
1645
625
#define FUNCTION_ANALYSIS(NAME, CREATE_PASS)                                   \
1646
15.4k
  if (
Name == "require<" NAME ">"14.8k
||
Name == "invalidate<" NAME ">"14.6k
) \
1647
15.4k
    
return true182
;
1648
40.3k
#include 
"PassRegistry.def"625
1649
40.3k
1650
40.3k
  
return callbacksAcceptPassName<FunctionPassManager>(Name, Callbacks)39
;
1651
40.3k
}
1652
1653
template <typename CallbacksT>
1654
31
static bool isLoopPassName(StringRef Name, CallbacksT &Callbacks) {
1655
31
  // Explicitly handle pass manager names.
1656
31
  if (Name == "loop")
1657
0
    return true;
1658
31
1659
31
  // Explicitly handle custom-parsed pass names.
1660
31
  if (parseRepeatPassName(Name))
1661
0
    return true;
1662
31
1663
31
#define LOOP_PASS(NAME, CREATE_PASS)                                           \
1664
338
  if (Name == NAME)                                                            \
1665
338
    
return true14
;
1666
31
#define LOOP_PASS_WITH_PARAMS(NAME, CREATE_PASS, PARSER)                       \
1667
31
  
if (13
checkParametrizedPassName(Name, NAME)13
) \
1668
13
    
return true1
;
1669
31
#define LOOP_ANALYSIS(NAME, CREATE_PASS)                                       \
1670
151
  if (
Name == "require<" NAME ">"120
||
Name == "invalidate<" NAME ">"116
) \
1671
151
    
return true4
;
1672
471
#include 
"PassRegistry.def"31
1673
471
1674
471
  
return callbacksAcceptPassName<LoopPassManager>(Name, Callbacks)12
;
1675
471
}
1676
1677
Optional<std::vector<PassBuilder::PipelineElement>>
1678
1.32k
PassBuilder::parsePipelineText(StringRef Text) {
1679
1.32k
  std::vector<PipelineElement> ResultPipeline;
1680
1.32k
1681
1.32k
  SmallVector<std::vector<PipelineElement> *, 4> PipelineStack = {
1682
1.32k
      &ResultPipeline};
1683
2.46k
  for (;;) {
1684
2.46k
    std::vector<PipelineElement> &Pipeline = *PipelineStack.back();
1685
2.46k
    size_t Pos = Text.find_first_of(",()");
1686
2.46k
    Pipeline.push_back({Text.substr(0, Pos), {}});
1687
2.46k
1688
2.46k
    // If we have a single terminating name, we're done.
1689
2.46k
    if (Pos == Text.npos)
1690
966
      break;
1691
1.49k
1692
1.49k
    char Sep = Text[Pos];
1693
1.49k
    Text = Text.substr(Pos + 1);
1694
1.49k
    if (Sep == ',')
1695
561
      // Just a name ending in a comma, continue.
1696
561
      continue;
1697
935
1698
935
    if (Sep == '(') {
1699
483
      // Push the inner pipeline onto the stack to continue processing.
1700
483
      PipelineStack.push_back(&Pipeline.back().InnerPipeline);
1701
483
      continue;
1702
483
    }
1703
452
1704
452
    assert(Sep == ')' && "Bogus separator!");
1705
452
    // When handling the close parenthesis, we greedily consume them to avoid
1706
452
    // empty strings in the pipeline.
1707
487
    do {
1708
487
      // If we try to pop the outer pipeline we have unbalanced parentheses.
1709
487
      if (PipelineStack.size() == 1)
1710
7
        return None;
1711
480
1712
480
      PipelineStack.pop_back();
1713
480
    } while (Text.consume_front(")"));
1714
452
1715
452
    // Check if we've finished parsing.
1716
452
    
if (445
Text.empty()445
)
1717
347
      break;
1718
98
1719
98
    // Otherwise, the end of an inner pipeline always has to be followed by
1720
98
    // a comma, and then we can continue.
1721
98
    if (!Text.consume_front(","))
1722
1
      return None;
1723
98
  }
1724
1.32k
1725
1.32k
  
if (1.31k
PipelineStack.size() > 11.31k
)
1726
3
    // Unbalanced paretheses.
1727
3
    return None;
1728
1.31k
1729
1.31k
  assert(PipelineStack.back() == &ResultPipeline &&
1730
1.31k
         "Wrong pipeline at the bottom of the stack!");
1731
1.31k
  return {std::move(ResultPipeline)};
1732
1.31k
}
1733
1734
Error PassBuilder::parseModulePass(ModulePassManager &MPM,
1735
                                   const PipelineElement &E,
1736
1.39k
                                   bool VerifyEachPass, bool DebugLogging) {
1737
1.39k
  auto &Name = E.Name;
1738
1.39k
  auto &InnerPipeline = E.InnerPipeline;
1739
1.39k
1740
1.39k
  // First handle complex passes like the pass managers which carry pipelines.
1741
1.39k
  if (!InnerPipeline.empty()) {
1742
957
    if (Name == "module") {
1743
14
      ModulePassManager NestedMPM(DebugLogging);
1744
14
      if (auto Err = parseModulePassPipeline(NestedMPM, InnerPipeline,
1745
2
                                             VerifyEachPass, DebugLogging))
1746
2
        return Err;
1747
12
      MPM.addPass(std::move(NestedMPM));
1748
12
      return Error::success();
1749
12
    }
1750
943
    if (Name == "cgscc") {
1751
192
      CGSCCPassManager CGPM(DebugLogging);
1752
192
      if (auto Err = parseCGSCCPassPipeline(CGPM, InnerPipeline, VerifyEachPass,
1753
3
                                            DebugLogging))
1754
3
        return Err;
1755
189
      MPM.addPass(createModuleToPostOrderCGSCCPassAdaptor(std::move(CGPM)));
1756
189
      return Error::success();
1757
189
    }
1758
751
    if (Name == "function") {
1759
749
      FunctionPassManager FPM(DebugLogging);
1760
749
      if (auto Err = parseFunctionPassPipeline(FPM, InnerPipeline,
1761
9
                                               VerifyEachPass, DebugLogging))
1762
9
        return Err;
1763
740
      MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
1764
740
      return Error::success();
1765
740
    }
1766
2
    if (auto Count = parseRepeatPassName(Name)) {
1767
1
      ModulePassManager NestedMPM(DebugLogging);
1768
1
      if (auto Err = parseModulePassPipeline(NestedMPM, InnerPipeline,
1769
0
                                             VerifyEachPass, DebugLogging))
1770
0
        return Err;
1771
1
      MPM.addPass(createRepeatedPass(*Count, std::move(NestedMPM)));
1772
1
      return Error::success();
1773
1
    }
1774
1
1775
1
    for (auto &C : ModulePipelineParsingCallbacks)
1776
1
      if (C(Name, MPM, InnerPipeline))
1777
0
        return Error::success();
1778
1
1779
1
    // Normal passes can't have pipelines.
1780
1
    return make_error<StringError>(
1781
1
        formatv("invalid use of '{0}' pass as module pipeline", Name).str(),
1782
1
        inconvertibleErrorCode());
1783
1
    ;
1784
0
  }
1785
1.39k
1786
1.39k
  // Manually handle aliases for pre-configured pipeline fragments.
1787
1.39k
  
if (441
startsWithDefaultPipelineAliasPrefix(Name)441
) {
1788
67
    SmallVector<StringRef, 3> Matches;
1789
67
    if (!DefaultAliasRegex.match(Name, &Matches))
1790
0
      return make_error<StringError>(
1791
0
          formatv("unknown default pipeline alias '{0}'", Name).str(),
1792
0
          inconvertibleErrorCode());
1793
67
1794
67
    assert(Matches.size() == 3 && "Must capture two matched strings!");
1795
67
1796
67
    OptimizationLevel L = StringSwitch<OptimizationLevel>(Matches[2])
1797
67
                              .Case("O0", O0)
1798
67
                              .Case("O1", O1)
1799
67
                              .Case("O2", O2)
1800
67
                              .Case("O3", O3)
1801
67
                              .Case("Os", Os)
1802
67
                              .Case("Oz", Oz);
1803
67
    if (L == O0)
1804
1
      // At O0 we do nothing at all!
1805
1
      return Error::success();
1806
66
1807
66
    if (Matches[1] == "default") {
1808
31
      MPM.addPass(buildPerModuleDefaultPipeline(L, DebugLogging));
1809
35
    } else if (Matches[1] == "thinlto-pre-link") {
1810
12
      MPM.addPass(buildThinLTOPreLinkDefaultPipeline(L, DebugLogging));
1811
23
    } else if (Matches[1] == "thinlto") {
1812
10
      MPM.addPass(buildThinLTODefaultPipeline(L, DebugLogging, nullptr));
1813
13
    } else if (Matches[1] == "lto-pre-link") {
1814
5
      MPM.addPass(buildLTOPreLinkDefaultPipeline(L, DebugLogging));
1815
8
    } else {
1816
8
      assert(Matches[1] == "lto" && "Not one of the matched options!");
1817
8
      MPM.addPass(buildLTODefaultPipeline(L, DebugLogging, nullptr));
1818
8
    }
1819
66
    return Error::success();
1820
66
  }
1821
374
1822
374
  // Finally expand the basic registered passes from the .inc file.
1823
374
#define MODULE_PASS(NAME, CREATE_PASS)                                         \
1824
10.2k
  if (Name == NAME) {                                                          \
1825
320
    MPM.addPass(CREATE_PASS);                                                  \
1826
320
    return Error::success();                                                   \
1827
320
  }
1828
374
#define MODULE_ANALYSIS(NAME, CREATE_PASS)                                     \
1829
4.27k
  if (
Name == "require<" NAME ">"3.89k
) { \
1830
39
    MPM.addPass(                                                               \
1831
39
        RequireAnalysisPass<                                                   \
1832
39
            std::remove_reference<decltype(CREATE_PASS)>::type, Module>());    \
1833
39
    return Error::success();                                                   \
1834
39
  }                                                                            \
1835
4.27k
  
if (3.85k
Name == "invalidate<" NAME ">"3.85k
) { \
1836
2
    MPM.addPass(InvalidateAnalysisPass<                                        \
1837
2
                std::remove_reference<decltype(CREATE_PASS)>::type>());        \
1838
2
    return Error::success();                                                   \
1839
2
  }
1840
17.9k
#include 
"PassRegistry.def"441
1841
17.9k
1842
17.9k
  
for (auto &C : ModulePipelineParsingCallbacks)13
1843
13
    if (C(Name, MPM, InnerPipeline))
1844
12
      return Error::success();
1845
13
  return make_error<StringError>(
1846
1
      formatv("unknown module pass '{0}'", Name).str(),
1847
1
      inconvertibleErrorCode());
1848
13
}
1849
1850
Error PassBuilder::parseCGSCCPass(CGSCCPassManager &CGPM,
1851
                                  const PipelineElement &E, bool VerifyEachPass,
1852
240
                                  bool DebugLogging) {
1853
240
  auto &Name = E.Name;
1854
240
  auto &InnerPipeline = E.InnerPipeline;
1855
240
1856
240
  // First handle complex passes like the pass managers which carry pipelines.
1857
240
  if (!InnerPipeline.empty()) {
1858
36
    if (Name == "cgscc") {
1859
0
      CGSCCPassManager NestedCGPM(DebugLogging);
1860
0
      if (auto Err = parseCGSCCPassPipeline(NestedCGPM, InnerPipeline,
1861
0
                                            VerifyEachPass, DebugLogging))
1862
0
        return Err;
1863
0
      // Add the nested pass manager with the appropriate adaptor.
1864
0
      CGPM.addPass(std::move(NestedCGPM));
1865
0
      return Error::success();
1866
0
    }
1867
36
    if (Name == "function") {
1868
31
      FunctionPassManager FPM(DebugLogging);
1869
31
      if (auto Err = parseFunctionPassPipeline(FPM, InnerPipeline,
1870
1
                                               VerifyEachPass, DebugLogging))
1871
1
        return Err;
1872
30
      // Add the nested pass manager with the appropriate adaptor.
1873
30
      CGPM.addPass(createCGSCCToFunctionPassAdaptor(std::move(FPM)));
1874
30
      return Error::success();
1875
30
    }
1876
5
    if (auto Count = parseRepeatPassName(Name)) {
1877
1
      CGSCCPassManager NestedCGPM(DebugLogging);
1878
1
      if (auto Err = parseCGSCCPassPipeline(NestedCGPM, InnerPipeline,
1879
0
                                            VerifyEachPass, DebugLogging))
1880
0
        return Err;
1881
1
      CGPM.addPass(createRepeatedPass(*Count, std::move(NestedCGPM)));
1882
1
      return Error::success();
1883
1
    }
1884
4
    if (auto MaxRepetitions = parseDevirtPassName(Name)) {
1885
3
      CGSCCPassManager NestedCGPM(DebugLogging);
1886
3
      if (auto Err = parseCGSCCPassPipeline(NestedCGPM, InnerPipeline,
1887
0
                                            VerifyEachPass, DebugLogging))
1888
0
        return Err;
1889
3
      CGPM.addPass(
1890
3
          createDevirtSCCRepeatedPass(std::move(NestedCGPM), *MaxRepetitions));
1891
3
      return Error::success();
1892
3
    }
1893
1
1894
1
    for (auto &C : CGSCCPipelineParsingCallbacks)
1895
0
      if (C(Name, CGPM, InnerPipeline))
1896
0
        return Error::success();
1897
1
1898
1
    // Normal passes can't have pipelines.
1899
1
    return make_error<StringError>(
1900
1
        formatv("invalid use of '{0}' pass as cgscc pipeline", Name).str(),
1901
1
        inconvertibleErrorCode());
1902
204
  }
1903
204
1904
204
// Now expand the basic registered passes from the .inc file.
1905
204
#define CGSCC_PASS(NAME, CREATE_PASS)                                          \
1906
693
  if (Name == NAME) {                                                          \
1907
187
    CGPM.addPass(CREATE_PASS);                                                 \
1908
187
    return Error::success();                                                   \
1909
187
  }
1910
204
#define CGSCC_ANALYSIS(NAME, CREATE_PASS)                                      \
1911
796
  if (
Name == "require<" NAME ">"592
) { \
1912
9
    CGPM.addPass(RequireAnalysisPass<                                          \
1913
9
                 std::remove_reference<decltype(CREATE_PASS)>::type,           \
1914
9
                 LazyCallGraph::SCC, CGSCCAnalysisManager, LazyCallGraph &,    \
1915
9
                 CGSCCUpdateResult &>());                                      \
1916
9
    return Error::success();                                                   \
1917
9
  }                                                                            \
1918
796
  
if (583
Name == "invalidate<" NAME ">"583
) { \
1919
1
    CGPM.addPass(InvalidateAnalysisPass<                                       \
1920
1
                 std::remove_reference<decltype(CREATE_PASS)>::type>());       \
1921
1
    return Error::success();                                                   \
1922
1
  }
1923
1.86k
#include 
"PassRegistry.def"240
1924
1.86k
1925
1.86k
  
for (auto &C : CGSCCPipelineParsingCallbacks)7
1926
6
    if (C(Name, CGPM, InnerPipeline))
1927
6
      return Error::success();
1928
7
  return make_error<StringError>(
1929
1
      formatv("unknown cgscc pass '{0}'", Name).str(),
1930
1
      inconvertibleErrorCode());
1931
7
}
1932
1933
Error PassBuilder::parseFunctionPass(FunctionPassManager &FPM,
1934
                                     const PipelineElement &E,
1935
1.27k
                                     bool VerifyEachPass, bool DebugLogging) {
1936
1.27k
  auto &Name = E.Name;
1937
1.27k
  auto &InnerPipeline = E.InnerPipeline;
1938
1.27k
1939
1.27k
  // First handle complex passes like the pass managers which carry pipelines.
1940
1.27k
  if (!InnerPipeline.empty()) {
1941
226
    if (Name == "function") {
1942
1
      FunctionPassManager NestedFPM(DebugLogging);
1943
1
      if (auto Err = parseFunctionPassPipeline(NestedFPM, InnerPipeline,
1944
0
                                               VerifyEachPass, DebugLogging))
1945
0
        return Err;
1946
1
      // Add the nested pass manager with the appropriate adaptor.
1947
1
      FPM.addPass(std::move(NestedFPM));
1948
1
      return Error::success();
1949
1
    }
1950
225
    if (Name == "loop") {
1951
221
      LoopPassManager LPM(DebugLogging);
1952
221
      if (auto Err = parseLoopPassPipeline(LPM, InnerPipeline, VerifyEachPass,
1953
2
                                           DebugLogging))
1954
2
        return Err;
1955
219
      // Add the nested pass manager with the appropriate adaptor.
1956
219
      FPM.addPass(
1957
219
          createFunctionToLoopPassAdaptor(std::move(LPM), DebugLogging));
1958
219
      return Error::success();
1959
219
    }
1960
4
    if (auto Count = parseRepeatPassName(Name)) {
1961
1
      FunctionPassManager NestedFPM(DebugLogging);
1962
1
      if (auto Err = parseFunctionPassPipeline(NestedFPM, InnerPipeline,
1963
0
                                               VerifyEachPass, DebugLogging))
1964
0
        return Err;
1965
1
      FPM.addPass(createRepeatedPass(*Count, std::move(NestedFPM)));
1966
1
      return Error::success();
1967
1
    }
1968
3
1969
3
    for (auto &C : FunctionPipelineParsingCallbacks)
1970
6
      if (C(Name, FPM, InnerPipeline))
1971
1
        return Error::success();
1972
3
1973
3
    // Normal passes can't have pipelines.
1974
3
    return make_error<StringError>(
1975
2
        formatv("invalid use of '{0}' pass as function pipeline", Name).str(),
1976
2
        inconvertibleErrorCode());
1977
1.04k
  }
1978
1.04k
1979
1.04k
// Now expand the basic registered passes from the .inc file.
1980
1.04k
#define FUNCTION_PASS(NAME, CREATE_PASS)                                       \
1981
36.9k
  if (Name == NAME) {                                                          \
1982
587
    FPM.addPass(CREATE_PASS);                                                  \
1983
587
    return Error::success();                                                   \
1984
587
  }
1985
1.04k
#define FUNCTION_PASS_WITH_PARAMS(NAME, CREATE_PASS, PARSER)                   \
1986
1.04k
  
if (246
checkParametrizedPassName(Name, NAME)246
) { \
1987
78
    auto Params = parsePassParameters(PARSER, Name, NAME);                     \
1988
78
    if (!Params)                                                               \
1989
78
      
return Params.takeError()0
; \
1990
78
    FPM.addPass(CREATE_PASS(Params.get()));                                    \
PassBuilder.cpp:llvm::PassBuilder::parseFunctionPass(llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function> >&, llvm::PassBuilder::PipelineElement const&, bool, bool)::$_47::operator()(llvm::LoopUnrollOptions) const
Line
Count
Source
1990
24
    FPM.addPass(CREATE_PASS(Params.get()));                                    \
PassBuilder.cpp:llvm::PassBuilder::parseFunctionPass(llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function> >&, llvm::PassBuilder::PipelineElement const&, bool, bool)::$_48::operator()(llvm::MemorySanitizerOptions) const
Line
Count
Source
1990
2
    FPM.addPass(CREATE_PASS(Params.get()));                                    \
PassBuilder.cpp:llvm::PassBuilder::parseFunctionPass(llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function> >&, llvm::PassBuilder::PipelineElement const&, bool, bool)::$_49::operator()(llvm::SimplifyCFGOptions) const
Line
Count
Source
1990
38
    FPM.addPass(CREATE_PASS(Params.get()));                                    \
PassBuilder.cpp:llvm::PassBuilder::parseFunctionPass(llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function> >&, llvm::PassBuilder::PipelineElement const&, bool, bool)::$_50::operator()(llvm::LoopVectorizeOptions) const
Line
Count
Source
1990
14
    FPM.addPass(CREATE_PASS(Params.get()));                                    \
1991
78
    return Error::success();                                                   \
1992
78
  }
1993
1.04k
#define FUNCTION_ANALYSIS(NAME, CREATE_PASS)                                   \
1994
25.1k
  if (
Name == "require<" NAME ">"24.1k
) { \
1995
350
    FPM.addPass(                                                               \
1996
350
        RequireAnalysisPass<                                                   \
1997
350
            std::remove_reference<decltype(CREATE_PASS)>::type, Function>());  \
1998
350
    return Error::success();                                                   \
1999
350
  }                                                                            \
2000
25.1k
  
if (23.7k
Name == "invalidate<" NAME ">"23.7k
) { \
2001
19
    FPM.addPass(InvalidateAnalysisPass<                                        \
2002
19
                std::remove_reference<decltype(CREATE_PASS)>::type>());        \
2003
19
    return Error::success();                                                   \
2004
19
  }
2005
85.0k
#include 
"PassRegistry.def"1.27k
2006
85.0k
2007
85.0k
  
for (auto &C : FunctionPipelineParsingCallbacks)12
2008
18
    if (C(Name, FPM, InnerPipeline))
2009
6
      return Error::success();
2010
12
  return make_error<StringError>(
2011
6
      formatv("unknown function pass '{0}'", Name).str(),
2012
6
      inconvertibleErrorCode());
2013
12
}
2014
2015
Error PassBuilder::parseLoopPass(LoopPassManager &LPM, const PipelineElement &E,
2016
247
                                 bool VerifyEachPass, bool DebugLogging) {
2017
247
  StringRef Name = E.Name;
2018
247
  auto &InnerPipeline = E.InnerPipeline;
2019
247
2020
247
  // First handle complex passes like the pass managers which carry pipelines.
2021
247
  if (!InnerPipeline.empty()) {
2022
2
    if (Name == "loop") {
2023
0
      LoopPassManager NestedLPM(DebugLogging);
2024
0
      if (auto Err = parseLoopPassPipeline(NestedLPM, InnerPipeline,
2025
0
                                           VerifyEachPass, DebugLogging))
2026
0
        return Err;
2027
0
      // Add the nested pass manager with the appropriate adaptor.
2028
0
      LPM.addPass(std::move(NestedLPM));
2029
0
      return Error::success();
2030
0
    }
2031
2
    if (auto Count = parseRepeatPassName(Name)) {
2032
1
      LoopPassManager NestedLPM(DebugLogging);
2033
1
      if (auto Err = parseLoopPassPipeline(NestedLPM, InnerPipeline,
2034
0
                                           VerifyEachPass, DebugLogging))
2035
0
        return Err;
2036
1
      LPM.addPass(createRepeatedPass(*Count, std::move(NestedLPM)));
2037
1
      return Error::success();
2038
1
    }
2039
1
2040
1
    for (auto &C : LoopPipelineParsingCallbacks)
2041
0
      if (C(Name, LPM, InnerPipeline))
2042
0
        return Error::success();
2043
1
2044
1
    // Normal passes can't have pipelines.
2045
1
    return make_error<StringError>(
2046
1
        formatv("invalid use of '{0}' pass as loop pipeline", Name).str(),
2047
1
        inconvertibleErrorCode());
2048
245
  }
2049
245
2050
245
// Now expand the basic registered passes from the .inc file.
2051
245
#define LOOP_PASS(NAME, CREATE_PASS)                                           \
2052
2.54k
  if (Name == NAME) {                                                          \
2053
185
    LPM.addPass(CREATE_PASS);                                                  \
2054
185
    return Error::success();                                                   \
2055
185
  }
2056
245
#define LOOP_PASS_WITH_PARAMS(NAME, CREATE_PASS, PARSER)                       \
2057
245
  
if (53
checkParametrizedPassName(Name, NAME)53
) { \
2058
44
    auto Params = parsePassParameters(PARSER, Name, NAME);                     \
2059
44
    if (!Params)                                                               \
2060
44
      
return Params.takeError()0
; \
2061
44
    LPM.addPass(CREATE_PASS(Params.get()));                                    \
2062
44
    return Error::success();                                                   \
2063
44
  }
2064
245
#define LOOP_ANALYSIS(NAME, CREATE_PASS)                                       \
2065
1.21k
  if (
Name == "require<" NAME ">"972
) { \
2066
7
    LPM.addPass(RequireAnalysisPass<                                           \
2067
7
                std::remove_reference<decltype(CREATE_PASS)>::type, Loop,      \
2068
7
                LoopAnalysisManager, LoopStandardAnalysisResults &,            \
2069
7
                LPMUpdater &>());                                              \
2070
7
    return Error::success();                                                   \
2071
7
  }                                                                            \
2072
1.21k
  
if (965
Name == "invalidate<" NAME ">"965
) { \
2073
0
    LPM.addPass(InvalidateAnalysisPass<                                        \
2074
0
                std::remove_reference<decltype(CREATE_PASS)>::type>());        \
2075
0
    return Error::success();                                                   \
2076
0
  }
2077
4.53k
#include 
"PassRegistry.def"247
2078
4.53k
2079
4.53k
  
for (auto &C : LoopPipelineParsingCallbacks)9
2080
6
    if (C(Name, LPM, InnerPipeline))
2081
6
      return Error::success();
2082
9
  return make_error<StringError>(formatv("unknown loop pass '{0}'", Name).str(),
2083
3
                                 inconvertibleErrorCode());
2084
9
}
2085
2086
206
bool PassBuilder::parseAAPassName(AAManager &AA, StringRef Name) {
2087
206
#define MODULE_ALIAS_ANALYSIS(NAME, CREATE_PASS)                               \
2088
206
  if (Name == NAME) {                                                          \
2089
5
    AA.registerModuleAnalysis<                                                 \
2090
5
        std::remove_reference<decltype(CREATE_PASS)>::type>();                 \
2091
5
    return true;                                                               \
2092
5
  }
2093
206
#define FUNCTION_ALIAS_ANALYSIS(NAME, CREATE_PASS)                             \
2094
306
  if (Name == NAME) {                                                          \
2095
198
    AA.registerFunctionAnalysis<                                               \
2096
198
        std::remove_reference<decltype(CREATE_PASS)>::type>();                 \
2097
198
    return true;                                                               \
2098
198
  }
2099
306
#include 
"PassRegistry.def"206
2100
306
2101
306
  
for (auto &C : AAParsingCallbacks)3
2102
0
    if (C(Name, AA))
2103
0
      return true;
2104
3
  return false;
2105
3
}
2106
2107
Error PassBuilder::parseLoopPassPipeline(LoopPassManager &LPM,
2108
                                         ArrayRef<PipelineElement> Pipeline,
2109
                                         bool VerifyEachPass,
2110
228
                                         bool DebugLogging) {
2111
247
  for (const auto &Element : Pipeline) {
2112
247
    if (auto Err = parseLoopPass(LPM, Element, VerifyEachPass, DebugLogging))
2113
4
      return Err;
2114
247
    // FIXME: No verifier support for Loop passes!
2115
247
  }
2116
228
  
return Error::success()224
;
2117
228
}
2118
2119
Error PassBuilder::parseFunctionPassPipeline(FunctionPassManager &FPM,
2120
                                             ArrayRef<PipelineElement> Pipeline,
2121
                                             bool VerifyEachPass,
2122
797
                                             bool DebugLogging) {
2123
1.27k
  for (const auto &Element : Pipeline) {
2124
1.27k
    if (auto Err =
2125
10
            parseFunctionPass(FPM, Element, VerifyEachPass, DebugLogging))
2126
10
      return Err;
2127
1.26k
    if (VerifyEachPass)
2128
20
      FPM.addPass(VerifierPass());
2129
1.26k
  }
2130
797
  
return Error::success()787
;
2131
797
}
2132
2133
Error PassBuilder::parseCGSCCPassPipeline(CGSCCPassManager &CGPM,
2134
                                          ArrayRef<PipelineElement> Pipeline,
2135
                                          bool VerifyEachPass,
2136
198
                                          bool DebugLogging) {
2137
240
  for (const auto &Element : Pipeline) {
2138
240
    if (auto Err = parseCGSCCPass(CGPM, Element, VerifyEachPass, DebugLogging))
2139
3
      return Err;
2140
240
    // FIXME: No verifier support for CGSCC passes!
2141
240
  }
2142
198
  
return Error::success()195
;
2143
198
}
2144
2145
void PassBuilder::crossRegisterProxies(LoopAnalysisManager &LAM,
2146
                                       FunctionAnalysisManager &FAM,
2147
                                       CGSCCAnalysisManager &CGAM,
2148
1.43k
                                       ModuleAnalysisManager &MAM) {
2149
1.43k
  MAM.registerPass([&] { return FunctionAnalysisManagerModuleProxy(FAM); });
2150
1.43k
  MAM.registerPass([&] { return CGSCCAnalysisManagerModuleProxy(CGAM); });
2151
1.43k
  CGAM.registerPass([&] { return ModuleAnalysisManagerCGSCCProxy(MAM); });
2152
1.43k
  FAM.registerPass([&] { return CGSCCAnalysisManagerFunctionProxy(CGAM); });
2153
1.43k
  FAM.registerPass([&] { return ModuleAnalysisManagerFunctionProxy(MAM); });
2154
1.43k
  FAM.registerPass([&] { return LoopAnalysisManagerFunctionProxy(LAM); });
2155
1.43k
  LAM.registerPass([&] { return FunctionAnalysisManagerLoopProxy(FAM); });
2156
1.43k
}
2157
2158
Error PassBuilder::parseModulePassPipeline(ModulePassManager &MPM,
2159
                                           ArrayRef<PipelineElement> Pipeline,
2160
                                           bool VerifyEachPass,
2161
1.29k
                                           bool DebugLogging) {
2162
1.39k
  for (const auto &Element : Pipeline) {
2163
1.39k
    if (auto Err = parseModulePass(MPM, Element, VerifyEachPass, DebugLogging))
2164
16
      return Err;
2165
1.38k
    if (VerifyEachPass)
2166
31
      MPM.addPass(VerifierPass());
2167
1.38k
  }
2168
1.29k
  
return Error::success()1.27k
;
2169
1.29k
}
2170
2171
// Primary pass pipeline description parsing routine for a \c ModulePassManager
2172
// FIXME: Should this routine accept a TargetMachine or require the caller to
2173
// pre-populate the analysis managers with target-specific stuff?
2174
Error PassBuilder::parsePassPipeline(ModulePassManager &MPM,
2175
                                     StringRef PipelineText,
2176
1.29k
                                     bool VerifyEachPass, bool DebugLogging) {
2177
1.29k
  auto Pipeline = parsePipelineText(PipelineText);
2178
1.29k
  if (!Pipeline || 
Pipeline->empty()1.28k
)
2179
11
    return make_error<StringError>(
2180
11
        formatv("invalid pipeline '{0}'", PipelineText).str(),
2181
11
        inconvertibleErrorCode());
2182
1.28k
2183
1.28k
  // If the first name isn't at the module layer, wrap the pipeline up
2184
1.28k
  // automatically.
2185
1.28k
  StringRef FirstName = Pipeline->front().Name;
2186
1.28k
2187
1.28k
  if (!isModulePassName(FirstName, ModulePipelineParsingCallbacks)) {
2188
732
    if (isCGSCCPassName(FirstName, CGSCCPipelineParsingCallbacks)) {
2189
75
      Pipeline = {{"cgscc", std::move(*Pipeline)}};
2190
657
    } else if (isFunctionPassName(FirstName,
2191
657
                                  FunctionPipelineParsingCallbacks)) {
2192
626
      Pipeline = {{"function", std::move(*Pipeline)}};
2193
626
    } else 
if (31
isLoopPassName(FirstName, LoopPipelineParsingCallbacks)31
) {
2194
24
      Pipeline = {{"function", {{"loop", std::move(*Pipeline)}}}};
2195
24
    } else {
2196
7
      for (auto &C : TopLevelPipelineParsingCallbacks)
2197
2
        if (C(MPM, *Pipeline, VerifyEachPass, DebugLogging))
2198
1
          return Error::success();
2199
7
2200
7
      // Unknown pass or pipeline name!
2201
7
      auto &InnerPipeline = Pipeline->front().InnerPipeline;
2202
6
      return make_error<StringError>(
2203
6
          formatv("unknown {0} name '{1}'",
2204
6
                  (InnerPipeline.empty() ? 
"pass"5
:
"pipeline"1
), FirstName)
2205
6
              .str(),
2206
6
          inconvertibleErrorCode());
2207
1.27k
    }
2208
732
  }
2209
1.27k
2210
1.27k
  if (auto Err =
2211
14
          parseModulePassPipeline(MPM, *Pipeline, VerifyEachPass, DebugLogging))
2212
14
    return Err;
2213
1.26k
  return Error::success();
2214
1.26k
}
2215
2216
// Primary pass pipeline description parsing routine for a \c CGSCCPassManager
2217
Error PassBuilder::parsePassPipeline(CGSCCPassManager &CGPM,
2218
                                     StringRef PipelineText,
2219
3
                                     bool VerifyEachPass, bool DebugLogging) {
2220
3
  auto Pipeline = parsePipelineText(PipelineText);
2221
3
  if (!Pipeline || Pipeline->empty())
2222
0
    return make_error<StringError>(
2223
0
        formatv("invalid pipeline '{0}'", PipelineText).str(),
2224
0
        inconvertibleErrorCode());
2225
3
2226
3
  StringRef FirstName = Pipeline->front().Name;
2227
3
  if (!isCGSCCPassName(FirstName, CGSCCPipelineParsingCallbacks))
2228
1
    return make_error<StringError>(
2229
1
        formatv("unknown cgscc pass '{0}' in pipeline '{1}'", FirstName,
2230
1
                PipelineText)
2231
1
            .str(),
2232
1
        inconvertibleErrorCode());
2233
2
2234
2
  if (auto Err =
2235
0
          parseCGSCCPassPipeline(CGPM, *Pipeline, VerifyEachPass, DebugLogging))
2236
0
    return Err;
2237
2
  return Error::success();
2238
2
}
2239
2240
// Primary pass pipeline description parsing routine for a \c
2241
// FunctionPassManager
2242
Error PassBuilder::parsePassPipeline(FunctionPassManager &FPM,
2243
                                     StringRef PipelineText,
2244
18
                                     bool VerifyEachPass, bool DebugLogging) {
2245
18
  auto Pipeline = parsePipelineText(PipelineText);
2246
18
  if (!Pipeline || Pipeline->empty())
2247
0
    return make_error<StringError>(
2248
0
        formatv("invalid pipeline '{0}'", PipelineText).str(),
2249
0
        inconvertibleErrorCode());
2250
18
2251
18
  StringRef FirstName = Pipeline->front().Name;
2252
18
  if (!isFunctionPassName(FirstName, FunctionPipelineParsingCallbacks))
2253
3
    return make_error<StringError>(
2254
3
        formatv("unknown function pass '{0}' in pipeline '{1}'", FirstName,
2255
3
                PipelineText)
2256
3
            .str(),
2257
3
        inconvertibleErrorCode());
2258
15
2259
15
  if (auto Err = parseFunctionPassPipeline(FPM, *Pipeline, VerifyEachPass,
2260
0
                                           DebugLogging))
2261
0
    return Err;
2262
15
  return Error::success();
2263
15
}
2264
2265
// Primary pass pipeline description parsing routine for a \c LoopPassManager
2266
Error PassBuilder::parsePassPipeline(LoopPassManager &CGPM,
2267
                                     StringRef PipelineText,
2268
6
                                     bool VerifyEachPass, bool DebugLogging) {
2269
6
  auto Pipeline = parsePipelineText(PipelineText);
2270
6
  if (!Pipeline || Pipeline->empty())
2271
0
    return make_error<StringError>(
2272
0
        formatv("invalid pipeline '{0}'", PipelineText).str(),
2273
0
        inconvertibleErrorCode());
2274
6
2275
6
  if (auto Err =
2276
2
          parseLoopPassPipeline(CGPM, *Pipeline, VerifyEachPass, DebugLogging))
2277
2
    return Err;
2278
4
2279
4
  return Error::success();
2280
4
}
2281
2282
1.28k
Error PassBuilder::parseAAPipeline(AAManager &AA, StringRef PipelineText) {
2283
1.28k
  // If the pipeline just consists of the word 'default' just replace the AA
2284
1.28k
  // manager with our default one.
2285
1.28k
  if (PipelineText == "default") {
2286
31
    AA = buildDefaultAAPipeline();
2287
31
    return Error::success();
2288
31
  }
2289
1.25k
2290
1.45k
  
while (1.25k
!PipelineText.empty()) {
2291
206
    StringRef Name;
2292
206
    std::tie(Name, PipelineText) = PipelineText.split(',');
2293
206
    if (!parseAAPassName(AA, Name))
2294
3
      return make_error<StringError>(
2295
3
          formatv("unknown alias analysis name '{0}'", Name).str(),
2296
3
          inconvertibleErrorCode());
2297
206
  }
2298
1.25k
2299
1.25k
  
return Error::success()1.24k
;
2300
1.25k
}