xref: /llvm-project/llvm/lib/CodeGen/TargetPassConfig.cpp (revision 65528f29913a541f3d250dbee2d93a3b1db68e4d)
1 //===- TargetPassConfig.cpp - Target independent code generation passes ---===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines interfaces to access the target independent code
11 // generation passes provided by the LLVM backend.
12 //
13 //===---------------------------------------------------------------------===//
14 
15 #include "llvm/CodeGen/TargetPassConfig.h"
16 #include "llvm/ADT/DenseMap.h"
17 #include "llvm/ADT/SmallVector.h"
18 #include "llvm/ADT/StringRef.h"
19 #include "llvm/Analysis/BasicAliasAnalysis.h"
20 #include "llvm/Analysis/CFLAndersAliasAnalysis.h"
21 #include "llvm/Analysis/CFLSteensAliasAnalysis.h"
22 #include "llvm/Analysis/CallGraphSCCPass.h"
23 #include "llvm/Analysis/ScopedNoAliasAA.h"
24 #include "llvm/Analysis/TargetTransformInfo.h"
25 #include "llvm/Analysis/TypeBasedAliasAnalysis.h"
26 #include "llvm/CodeGen/MachineFunctionPass.h"
27 #include "llvm/CodeGen/MachinePassRegistry.h"
28 #include "llvm/CodeGen/Passes.h"
29 #include "llvm/CodeGen/RegAllocRegistry.h"
30 #include "llvm/IR/IRPrintingPasses.h"
31 #include "llvm/IR/LegacyPassManager.h"
32 #include "llvm/IR/Verifier.h"
33 #include "llvm/MC/MCAsmInfo.h"
34 #include "llvm/MC/MCTargetOptions.h"
35 #include "llvm/Pass.h"
36 #include "llvm/Support/CodeGen.h"
37 #include "llvm/Support/CommandLine.h"
38 #include "llvm/Support/Compiler.h"
39 #include "llvm/Support/Debug.h"
40 #include "llvm/Support/ErrorHandling.h"
41 #include "llvm/Support/Threading.h"
42 #include "llvm/Target/TargetMachine.h"
43 #include "llvm/Transforms/Scalar.h"
44 #include "llvm/Transforms/Utils/SymbolRewriter.h"
45 #include <cassert>
46 #include <string>
47 
48 using namespace llvm;
49 
50 cl::opt<bool> EnableIPRA("enable-ipra", cl::init(false), cl::Hidden,
51                          cl::desc("Enable interprocedural register allocation "
52                                   "to reduce load/store at procedure calls."));
53 static cl::opt<bool> DisablePostRASched("disable-post-ra", cl::Hidden,
54     cl::desc("Disable Post Regalloc Scheduler"));
55 static cl::opt<bool> DisableBranchFold("disable-branch-fold", cl::Hidden,
56     cl::desc("Disable branch folding"));
57 static cl::opt<bool> DisableTailDuplicate("disable-tail-duplicate", cl::Hidden,
58     cl::desc("Disable tail duplication"));
59 static cl::opt<bool> DisableEarlyTailDup("disable-early-taildup", cl::Hidden,
60     cl::desc("Disable pre-register allocation tail duplication"));
61 static cl::opt<bool> DisableBlockPlacement("disable-block-placement",
62     cl::Hidden, cl::desc("Disable probability-driven block placement"));
63 static cl::opt<bool> EnableBlockPlacementStats("enable-block-placement-stats",
64     cl::Hidden, cl::desc("Collect probability-driven block placement stats"));
65 static cl::opt<bool> DisableSSC("disable-ssc", cl::Hidden,
66     cl::desc("Disable Stack Slot Coloring"));
67 static cl::opt<bool> DisableMachineDCE("disable-machine-dce", cl::Hidden,
68     cl::desc("Disable Machine Dead Code Elimination"));
69 static cl::opt<bool> DisableEarlyIfConversion("disable-early-ifcvt", cl::Hidden,
70     cl::desc("Disable Early If-conversion"));
71 static cl::opt<bool> DisableMachineLICM("disable-machine-licm", cl::Hidden,
72     cl::desc("Disable Machine LICM"));
73 static cl::opt<bool> DisableMachineCSE("disable-machine-cse", cl::Hidden,
74     cl::desc("Disable Machine Common Subexpression Elimination"));
75 static cl::opt<cl::boolOrDefault> OptimizeRegAlloc(
76     "optimize-regalloc", cl::Hidden,
77     cl::desc("Enable optimized register allocation compilation path."));
78 static cl::opt<bool> DisablePostRAMachineLICM("disable-postra-machine-licm",
79     cl::Hidden,
80     cl::desc("Disable Machine LICM"));
81 static cl::opt<bool> DisableMachineSink("disable-machine-sink", cl::Hidden,
82     cl::desc("Disable Machine Sinking"));
83 static cl::opt<bool> DisableLSR("disable-lsr", cl::Hidden,
84     cl::desc("Disable Loop Strength Reduction Pass"));
85 static cl::opt<bool> DisableConstantHoisting("disable-constant-hoisting",
86     cl::Hidden, cl::desc("Disable ConstantHoisting"));
87 static cl::opt<bool> DisableCGP("disable-cgp", cl::Hidden,
88     cl::desc("Disable Codegen Prepare"));
89 static cl::opt<bool> DisableCopyProp("disable-copyprop", cl::Hidden,
90     cl::desc("Disable Copy Propagation pass"));
91 static cl::opt<bool> DisableCopyPropPreRegRewrite("disable-copyprop-prerewrite", cl::Hidden,
92     cl::desc("Disable Copy Propagation Pre-Register Re-write pass"));
93 static cl::opt<bool> DisablePartialLibcallInlining("disable-partial-libcall-inlining",
94     cl::Hidden, cl::desc("Disable Partial Libcall Inlining"));
95 static cl::opt<bool> EnableImplicitNullChecks(
96     "enable-implicit-null-checks",
97     cl::desc("Fold null checks into faulting memory operations"),
98     cl::init(false));
99 static cl::opt<bool> EnableMergeICmps(
100     "enable-mergeicmps",
101     cl::desc("Merge ICmp chains into a single memcmp"),
102     cl::init(false));
103 static cl::opt<bool> PrintLSR("print-lsr-output", cl::Hidden,
104     cl::desc("Print LLVM IR produced by the loop-reduce pass"));
105 static cl::opt<bool> PrintISelInput("print-isel-input", cl::Hidden,
106     cl::desc("Print LLVM IR input to isel pass"));
107 static cl::opt<bool> PrintGCInfo("print-gc", cl::Hidden,
108     cl::desc("Dump garbage collector data"));
109 static cl::opt<bool> VerifyMachineCode("verify-machineinstrs", cl::Hidden,
110     cl::desc("Verify generated machine code"),
111     cl::init(false),
112     cl::ZeroOrMore);
113 static cl::opt<bool> EnableMachineOutliner("enable-machine-outliner",
114     cl::Hidden,
115     cl::desc("Enable machine outliner"));
116 // Enable or disable FastISel. Both options are needed, because
117 // FastISel is enabled by default with -fast, and we wish to be
118 // able to enable or disable fast-isel independently from -O0.
119 static cl::opt<cl::boolOrDefault>
120 EnableFastISelOption("fast-isel", cl::Hidden,
121   cl::desc("Enable the \"fast\" instruction selector"));
122 
123 static cl::opt<cl::boolOrDefault>
124     EnableGlobalISel("global-isel", cl::Hidden,
125                      cl::desc("Enable the \"global\" instruction selector"));
126 
127 static cl::opt<std::string>
128 PrintMachineInstrs("print-machineinstrs", cl::ValueOptional,
129                    cl::desc("Print machine instrs"),
130                    cl::value_desc("pass-name"), cl::init("option-unspecified"));
131 
132 static cl::opt<int> EnableGlobalISelAbort(
133     "global-isel-abort", cl::Hidden,
134     cl::desc("Enable abort calls when \"global\" instruction selection "
135              "fails to lower/select an instruction: 0 disable the abort, "
136              "1 enable the abort, and "
137              "2 disable the abort but emit a diagnostic on failure"),
138     cl::init(1));
139 
140 // Temporary option to allow experimenting with MachineScheduler as a post-RA
141 // scheduler. Targets can "properly" enable this with
142 // substitutePass(&PostRASchedulerID, &PostMachineSchedulerID).
143 // Targets can return true in targetSchedulesPostRAScheduling() and
144 // insert a PostRA scheduling pass wherever it wants.
145 cl::opt<bool> MISchedPostRA("misched-postra", cl::Hidden,
146   cl::desc("Run MachineScheduler post regalloc (independent of preRA sched)"));
147 
148 // Experimental option to run live interval analysis early.
149 static cl::opt<bool> EarlyLiveIntervals("early-live-intervals", cl::Hidden,
150     cl::desc("Run live interval analysis earlier in the pipeline"));
151 
152 // Experimental option to use CFL-AA in codegen
153 enum class CFLAAType { None, Steensgaard, Andersen, Both };
154 static cl::opt<CFLAAType> UseCFLAA(
155     "use-cfl-aa-in-codegen", cl::init(CFLAAType::None), cl::Hidden,
156     cl::desc("Enable the new, experimental CFL alias analysis in CodeGen"),
157     cl::values(clEnumValN(CFLAAType::None, "none", "Disable CFL-AA"),
158                clEnumValN(CFLAAType::Steensgaard, "steens",
159                           "Enable unification-based CFL-AA"),
160                clEnumValN(CFLAAType::Andersen, "anders",
161                           "Enable inclusion-based CFL-AA"),
162                clEnumValN(CFLAAType::Both, "both",
163                           "Enable both variants of CFL-AA")));
164 
165 /// Option names for limiting the codegen pipeline.
166 /// Those are used in error reporting and we didn't want
167 /// to duplicate their names all over the place.
168 const char *StartAfterOptName = "start-after";
169 const char *StartBeforeOptName = "start-before";
170 const char *StopAfterOptName = "stop-after";
171 const char *StopBeforeOptName = "stop-before";
172 
173 static cl::opt<std::string>
174     StartAfterOpt(StringRef(StartAfterOptName),
175                   cl::desc("Resume compilation after a specific pass"),
176                   cl::value_desc("pass-name"), cl::init(""));
177 
178 static cl::opt<std::string>
179     StartBeforeOpt(StringRef(StartBeforeOptName),
180                    cl::desc("Resume compilation before a specific pass"),
181                    cl::value_desc("pass-name"), cl::init(""));
182 
183 static cl::opt<std::string>
184     StopAfterOpt(StringRef(StopAfterOptName),
185                  cl::desc("Stop compilation after a specific pass"),
186                  cl::value_desc("pass-name"), cl::init(""));
187 
188 static cl::opt<std::string>
189     StopBeforeOpt(StringRef(StopBeforeOptName),
190                   cl::desc("Stop compilation before a specific pass"),
191                   cl::value_desc("pass-name"), cl::init(""));
192 
193 /// Allow standard passes to be disabled by command line options. This supports
194 /// simple binary flags that either suppress the pass or do nothing.
195 /// i.e. -disable-mypass=false has no effect.
196 /// These should be converted to boolOrDefault in order to use applyOverride.
197 static IdentifyingPassPtr applyDisable(IdentifyingPassPtr PassID,
198                                        bool Override) {
199   if (Override)
200     return IdentifyingPassPtr();
201   return PassID;
202 }
203 
204 /// Allow standard passes to be disabled by the command line, regardless of who
205 /// is adding the pass.
206 ///
207 /// StandardID is the pass identified in the standard pass pipeline and provided
208 /// to addPass(). It may be a target-specific ID in the case that the target
209 /// directly adds its own pass, but in that case we harmlessly fall through.
210 ///
211 /// TargetID is the pass that the target has configured to override StandardID.
212 ///
213 /// StandardID may be a pseudo ID. In that case TargetID is the name of the real
214 /// pass to run. This allows multiple options to control a single pass depending
215 /// on where in the pipeline that pass is added.
216 static IdentifyingPassPtr overridePass(AnalysisID StandardID,
217                                        IdentifyingPassPtr TargetID) {
218   if (StandardID == &PostRASchedulerID)
219     return applyDisable(TargetID, DisablePostRASched);
220 
221   if (StandardID == &BranchFolderPassID)
222     return applyDisable(TargetID, DisableBranchFold);
223 
224   if (StandardID == &TailDuplicateID)
225     return applyDisable(TargetID, DisableTailDuplicate);
226 
227   if (StandardID == &TargetPassConfig::EarlyTailDuplicateID)
228     return applyDisable(TargetID, DisableEarlyTailDup);
229 
230   if (StandardID == &MachineBlockPlacementID)
231     return applyDisable(TargetID, DisableBlockPlacement);
232 
233   if (StandardID == &StackSlotColoringID)
234     return applyDisable(TargetID, DisableSSC);
235 
236   if (StandardID == &DeadMachineInstructionElimID)
237     return applyDisable(TargetID, DisableMachineDCE);
238 
239   if (StandardID == &EarlyIfConverterID)
240     return applyDisable(TargetID, DisableEarlyIfConversion);
241 
242   if (StandardID == &MachineLICMID)
243     return applyDisable(TargetID, DisableMachineLICM);
244 
245   if (StandardID == &MachineCSEID)
246     return applyDisable(TargetID, DisableMachineCSE);
247 
248   if (StandardID == &TargetPassConfig::PostRAMachineLICMID)
249     return applyDisable(TargetID, DisablePostRAMachineLICM);
250 
251   if (StandardID == &MachineSinkingID)
252     return applyDisable(TargetID, DisableMachineSink);
253 
254   if (StandardID == &MachineCopyPropagationID)
255     return applyDisable(TargetID, DisableCopyProp);
256 
257   if (StandardID == &MachineCopyPropagationPreRegRewriteID)
258     return applyDisable(TargetID, DisableCopyPropPreRegRewrite);
259 
260   return TargetID;
261 }
262 
263 //===---------------------------------------------------------------------===//
264 /// TargetPassConfig
265 //===---------------------------------------------------------------------===//
266 
267 INITIALIZE_PASS(TargetPassConfig, "targetpassconfig",
268                 "Target Pass Configuration", false, false)
269 char TargetPassConfig::ID = 0;
270 
271 // Pseudo Pass IDs.
272 char TargetPassConfig::EarlyTailDuplicateID = 0;
273 char TargetPassConfig::PostRAMachineLICMID = 0;
274 
275 namespace {
276 
277 struct InsertedPass {
278   AnalysisID TargetPassID;
279   IdentifyingPassPtr InsertedPassID;
280   bool VerifyAfter;
281   bool PrintAfter;
282 
283   InsertedPass(AnalysisID TargetPassID, IdentifyingPassPtr InsertedPassID,
284                bool VerifyAfter, bool PrintAfter)
285       : TargetPassID(TargetPassID), InsertedPassID(InsertedPassID),
286         VerifyAfter(VerifyAfter), PrintAfter(PrintAfter) {}
287 
288   Pass *getInsertedPass() const {
289     assert(InsertedPassID.isValid() && "Illegal Pass ID!");
290     if (InsertedPassID.isInstance())
291       return InsertedPassID.getInstance();
292     Pass *NP = Pass::createPass(InsertedPassID.getID());
293     assert(NP && "Pass ID not registered");
294     return NP;
295   }
296 };
297 
298 } // end anonymous namespace
299 
300 namespace llvm {
301 
302 class PassConfigImpl {
303 public:
304   // List of passes explicitly substituted by this target. Normally this is
305   // empty, but it is a convenient way to suppress or replace specific passes
306   // that are part of a standard pass pipeline without overridding the entire
307   // pipeline. This mechanism allows target options to inherit a standard pass's
308   // user interface. For example, a target may disable a standard pass by
309   // default by substituting a pass ID of zero, and the user may still enable
310   // that standard pass with an explicit command line option.
311   DenseMap<AnalysisID,IdentifyingPassPtr> TargetPasses;
312 
313   /// Store the pairs of <AnalysisID, AnalysisID> of which the second pass
314   /// is inserted after each instance of the first one.
315   SmallVector<InsertedPass, 4> InsertedPasses;
316 };
317 
318 } // end namespace llvm
319 
320 // Out of line virtual method.
321 TargetPassConfig::~TargetPassConfig() {
322   delete Impl;
323 }
324 
325 static const PassInfo *getPassInfo(StringRef PassName) {
326   if (PassName.empty())
327     return nullptr;
328 
329   const PassRegistry &PR = *PassRegistry::getPassRegistry();
330   const PassInfo *PI = PR.getPassInfo(PassName);
331   if (!PI)
332     report_fatal_error(Twine('\"') + Twine(PassName) +
333                        Twine("\" pass is not registered."));
334   return PI;
335 }
336 
337 static AnalysisID getPassIDFromName(StringRef PassName) {
338   const PassInfo *PI = getPassInfo(PassName);
339   return PI ? PI->getTypeInfo() : nullptr;
340 }
341 
342 void TargetPassConfig::setStartStopPasses() {
343   StartBefore = getPassIDFromName(StartBeforeOpt);
344   StartAfter = getPassIDFromName(StartAfterOpt);
345   StopBefore = getPassIDFromName(StopBeforeOpt);
346   StopAfter = getPassIDFromName(StopAfterOpt);
347   if (StartBefore && StartAfter)
348     report_fatal_error(Twine(StartBeforeOptName) + Twine(" and ") +
349                        Twine(StartAfterOptName) + Twine(" specified!"));
350   if (StopBefore && StopAfter)
351     report_fatal_error(Twine(StopBeforeOptName) + Twine(" and ") +
352                        Twine(StopAfterOptName) + Twine(" specified!"));
353   Started = (StartAfter == nullptr) && (StartBefore == nullptr);
354 }
355 
356 // Out of line constructor provides default values for pass options and
357 // registers all common codegen passes.
358 TargetPassConfig::TargetPassConfig(LLVMTargetMachine &TM, PassManagerBase &pm)
359     : ImmutablePass(ID), PM(&pm), TM(&TM) {
360   Impl = new PassConfigImpl();
361 
362   // Register all target independent codegen passes to activate their PassIDs,
363   // including this pass itself.
364   initializeCodeGen(*PassRegistry::getPassRegistry());
365 
366   // Also register alias analysis passes required by codegen passes.
367   initializeBasicAAWrapperPassPass(*PassRegistry::getPassRegistry());
368   initializeAAResultsWrapperPassPass(*PassRegistry::getPassRegistry());
369 
370   // Substitute Pseudo Pass IDs for real ones.
371   substitutePass(&EarlyTailDuplicateID, &TailDuplicateID);
372   substitutePass(&PostRAMachineLICMID, &MachineLICMID);
373 
374   if (StringRef(PrintMachineInstrs.getValue()).equals(""))
375     TM.Options.PrintMachineCode = true;
376 
377   if (EnableIPRA.getNumOccurrences())
378     TM.Options.EnableIPRA = EnableIPRA;
379   else {
380     // If not explicitly specified, use target default.
381     TM.Options.EnableIPRA = TM.useIPRA();
382   }
383 
384   if (TM.Options.EnableIPRA)
385     setRequiresCodeGenSCCOrder();
386 
387   setStartStopPasses();
388 }
389 
390 CodeGenOpt::Level TargetPassConfig::getOptLevel() const {
391   return TM->getOptLevel();
392 }
393 
394 /// Insert InsertedPassID pass after TargetPassID.
395 void TargetPassConfig::insertPass(AnalysisID TargetPassID,
396                                   IdentifyingPassPtr InsertedPassID,
397                                   bool VerifyAfter, bool PrintAfter) {
398   assert(((!InsertedPassID.isInstance() &&
399            TargetPassID != InsertedPassID.getID()) ||
400           (InsertedPassID.isInstance() &&
401            TargetPassID != InsertedPassID.getInstance()->getPassID())) &&
402          "Insert a pass after itself!");
403   Impl->InsertedPasses.emplace_back(TargetPassID, InsertedPassID, VerifyAfter,
404                                     PrintAfter);
405 }
406 
407 /// createPassConfig - Create a pass configuration object to be used by
408 /// addPassToEmitX methods for generating a pipeline of CodeGen passes.
409 ///
410 /// Targets may override this to extend TargetPassConfig.
411 TargetPassConfig *LLVMTargetMachine::createPassConfig(PassManagerBase &PM) {
412   return new TargetPassConfig(*this, PM);
413 }
414 
415 TargetPassConfig::TargetPassConfig()
416   : ImmutablePass(ID) {
417   report_fatal_error("Trying to construct TargetPassConfig without a target "
418                      "machine. Scheduling a CodeGen pass without a target "
419                      "triple set?");
420 }
421 
422 bool TargetPassConfig::hasLimitedCodeGenPipeline() const {
423   return StartBefore || StartAfter || StopBefore || StopAfter;
424 }
425 
426 std::string
427 TargetPassConfig::getLimitedCodeGenPipelineReason(const char *Separator) const {
428   if (!hasLimitedCodeGenPipeline())
429     return std::string();
430   std::string Res;
431   static cl::opt<std::string> *PassNames[] = {&StartAfterOpt, &StartBeforeOpt,
432                                               &StopAfterOpt, &StopBeforeOpt};
433   static const char *OptNames[] = {StartAfterOptName, StartBeforeOptName,
434                                    StopAfterOptName, StopBeforeOptName};
435   bool IsFirst = true;
436   for (int Idx = 0; Idx < 4; ++Idx)
437     if (!PassNames[Idx]->empty()) {
438       if (!IsFirst)
439         Res += Separator;
440       IsFirst = false;
441       Res += OptNames[Idx];
442     }
443   return Res;
444 }
445 
446 // Helper to verify the analysis is really immutable.
447 void TargetPassConfig::setOpt(bool &Opt, bool Val) {
448   assert(!Initialized && "PassConfig is immutable");
449   Opt = Val;
450 }
451 
452 void TargetPassConfig::substitutePass(AnalysisID StandardID,
453                                       IdentifyingPassPtr TargetID) {
454   Impl->TargetPasses[StandardID] = TargetID;
455 }
456 
457 IdentifyingPassPtr TargetPassConfig::getPassSubstitution(AnalysisID ID) const {
458   DenseMap<AnalysisID, IdentifyingPassPtr>::const_iterator
459     I = Impl->TargetPasses.find(ID);
460   if (I == Impl->TargetPasses.end())
461     return ID;
462   return I->second;
463 }
464 
465 bool TargetPassConfig::isPassSubstitutedOrOverridden(AnalysisID ID) const {
466   IdentifyingPassPtr TargetID = getPassSubstitution(ID);
467   IdentifyingPassPtr FinalPtr = overridePass(ID, TargetID);
468   return !FinalPtr.isValid() || FinalPtr.isInstance() ||
469       FinalPtr.getID() != ID;
470 }
471 
472 /// Add a pass to the PassManager if that pass is supposed to be run.  If the
473 /// Started/Stopped flags indicate either that the compilation should start at
474 /// a later pass or that it should stop after an earlier pass, then do not add
475 /// the pass.  Finally, compare the current pass against the StartAfter
476 /// and StopAfter options and change the Started/Stopped flags accordingly.
477 void TargetPassConfig::addPass(Pass *P, bool verifyAfter, bool printAfter) {
478   assert(!Initialized && "PassConfig is immutable");
479 
480   // Cache the Pass ID here in case the pass manager finds this pass is
481   // redundant with ones already scheduled / available, and deletes it.
482   // Fundamentally, once we add the pass to the manager, we no longer own it
483   // and shouldn't reference it.
484   AnalysisID PassID = P->getPassID();
485 
486   if (StartBefore == PassID)
487     Started = true;
488   if (StopBefore == PassID)
489     Stopped = true;
490   if (Started && !Stopped) {
491     std::string Banner;
492     // Construct banner message before PM->add() as that may delete the pass.
493     if (AddingMachinePasses && (printAfter || verifyAfter))
494       Banner = std::string("After ") + std::string(P->getPassName());
495     PM->add(P);
496     if (AddingMachinePasses) {
497       if (printAfter)
498         addPrintPass(Banner);
499       if (verifyAfter)
500         addVerifyPass(Banner);
501     }
502 
503     // Add the passes after the pass P if there is any.
504     for (auto IP : Impl->InsertedPasses) {
505       if (IP.TargetPassID == PassID)
506         addPass(IP.getInsertedPass(), IP.VerifyAfter, IP.PrintAfter);
507     }
508   } else {
509     delete P;
510   }
511   if (StopAfter == PassID)
512     Stopped = true;
513   if (StartAfter == PassID)
514     Started = true;
515   if (Stopped && !Started)
516     report_fatal_error("Cannot stop compilation after pass that is not run");
517 }
518 
519 /// Add a CodeGen pass at this point in the pipeline after checking for target
520 /// and command line overrides.
521 ///
522 /// addPass cannot return a pointer to the pass instance because is internal the
523 /// PassManager and the instance we create here may already be freed.
524 AnalysisID TargetPassConfig::addPass(AnalysisID PassID, bool verifyAfter,
525                                      bool printAfter) {
526   IdentifyingPassPtr TargetID = getPassSubstitution(PassID);
527   IdentifyingPassPtr FinalPtr = overridePass(PassID, TargetID);
528   if (!FinalPtr.isValid())
529     return nullptr;
530 
531   Pass *P;
532   if (FinalPtr.isInstance())
533     P = FinalPtr.getInstance();
534   else {
535     P = Pass::createPass(FinalPtr.getID());
536     if (!P)
537       llvm_unreachable("Pass ID not registered");
538   }
539   AnalysisID FinalID = P->getPassID();
540   addPass(P, verifyAfter, printAfter); // Ends the lifetime of P.
541 
542   return FinalID;
543 }
544 
545 void TargetPassConfig::printAndVerify(const std::string &Banner) {
546   addPrintPass(Banner);
547   addVerifyPass(Banner);
548 }
549 
550 void TargetPassConfig::addPrintPass(const std::string &Banner) {
551   if (TM->shouldPrintMachineCode())
552     PM->add(createMachineFunctionPrinterPass(dbgs(), Banner));
553 }
554 
555 void TargetPassConfig::addVerifyPass(const std::string &Banner) {
556   bool Verify = VerifyMachineCode;
557 #ifdef EXPENSIVE_CHECKS
558   if (VerifyMachineCode == cl::BOU_UNSET)
559     Verify = TM->isMachineVerifierClean();
560 #endif
561   if (Verify)
562     PM->add(createMachineVerifierPass(Banner));
563 }
564 
565 /// Add common target configurable passes that perform LLVM IR to IR transforms
566 /// following machine independent optimization.
567 void TargetPassConfig::addIRPasses() {
568   switch (UseCFLAA) {
569   case CFLAAType::Steensgaard:
570     addPass(createCFLSteensAAWrapperPass());
571     break;
572   case CFLAAType::Andersen:
573     addPass(createCFLAndersAAWrapperPass());
574     break;
575   case CFLAAType::Both:
576     addPass(createCFLAndersAAWrapperPass());
577     addPass(createCFLSteensAAWrapperPass());
578     break;
579   default:
580     break;
581   }
582 
583   // Basic AliasAnalysis support.
584   // Add TypeBasedAliasAnalysis before BasicAliasAnalysis so that
585   // BasicAliasAnalysis wins if they disagree. This is intended to help
586   // support "obvious" type-punning idioms.
587   addPass(createTypeBasedAAWrapperPass());
588   addPass(createScopedNoAliasAAWrapperPass());
589   addPass(createBasicAAWrapperPass());
590 
591   // Before running any passes, run the verifier to determine if the input
592   // coming from the front-end and/or optimizer is valid.
593   if (!DisableVerify)
594     addPass(createVerifierPass());
595 
596   // Run loop strength reduction before anything else.
597   if (getOptLevel() != CodeGenOpt::None && !DisableLSR) {
598     addPass(createLoopStrengthReducePass());
599     if (PrintLSR)
600       addPass(createPrintFunctionPass(dbgs(), "\n\n*** Code after LSR ***\n"));
601   }
602 
603   if (getOptLevel() != CodeGenOpt::None && EnableMergeICmps) {
604     addPass(createMergeICmpsPass());
605   }
606 
607   // Run GC lowering passes for builtin collectors
608   // TODO: add a pass insertion point here
609   addPass(createGCLoweringPass());
610   addPass(createShadowStackGCLoweringPass());
611 
612   // Make sure that no unreachable blocks are instruction selected.
613   addPass(createUnreachableBlockEliminationPass());
614 
615   // Prepare expensive constants for SelectionDAG.
616   if (getOptLevel() != CodeGenOpt::None && !DisableConstantHoisting)
617     addPass(createConstantHoistingPass());
618 
619   if (getOptLevel() != CodeGenOpt::None && !DisablePartialLibcallInlining)
620     addPass(createPartiallyInlineLibCallsPass());
621 
622   // Insert calls to mcount-like functions.
623   addPass(createCountingFunctionInserterPass());
624 
625   // Add scalarization of target's unsupported masked memory intrinsics pass.
626   // the unsupported intrinsic will be replaced with a chain of basic blocks,
627   // that stores/loads element one-by-one if the appropriate mask bit is set.
628   addPass(createScalarizeMaskedMemIntrinPass());
629 
630   // Expand reduction intrinsics into shuffle sequences if the target wants to.
631   addPass(createExpandReductionsPass());
632 }
633 
634 /// Turn exception handling constructs into something the code generators can
635 /// handle.
636 void TargetPassConfig::addPassesToHandleExceptions() {
637   const MCAsmInfo *MCAI = TM->getMCAsmInfo();
638   assert(MCAI && "No MCAsmInfo");
639   switch (MCAI->getExceptionHandlingType()) {
640   case ExceptionHandling::SjLj:
641     // SjLj piggy-backs on dwarf for this bit. The cleanups done apply to both
642     // Dwarf EH prepare needs to be run after SjLj prepare. Otherwise,
643     // catch info can get misplaced when a selector ends up more than one block
644     // removed from the parent invoke(s). This could happen when a landing
645     // pad is shared by multiple invokes and is also a target of a normal
646     // edge from elsewhere.
647     addPass(createSjLjEHPreparePass());
648     LLVM_FALLTHROUGH;
649   case ExceptionHandling::DwarfCFI:
650   case ExceptionHandling::ARM:
651     addPass(createDwarfEHPass());
652     break;
653   case ExceptionHandling::WinEH:
654     // We support using both GCC-style and MSVC-style exceptions on Windows, so
655     // add both preparation passes. Each pass will only actually run if it
656     // recognizes the personality function.
657     addPass(createWinEHPass());
658     addPass(createDwarfEHPass());
659     break;
660   case ExceptionHandling::None:
661     addPass(createLowerInvokePass());
662 
663     // The lower invoke pass may create unreachable code. Remove it.
664     addPass(createUnreachableBlockEliminationPass());
665     break;
666   }
667 }
668 
669 /// Add pass to prepare the LLVM IR for code generation. This should be done
670 /// before exception handling preparation passes.
671 void TargetPassConfig::addCodeGenPrepare() {
672   if (getOptLevel() != CodeGenOpt::None && !DisableCGP)
673     addPass(createCodeGenPreparePass());
674   addPass(createRewriteSymbolsPass());
675 }
676 
677 /// Add common passes that perform LLVM IR to IR transforms in preparation for
678 /// instruction selection.
679 void TargetPassConfig::addISelPrepare() {
680   addPreISel();
681 
682   // Force codegen to run according to the callgraph.
683   if (requiresCodeGenSCCOrder())
684     addPass(new DummyCGSCCPass);
685 
686   // Add both the safe stack and the stack protection passes: each of them will
687   // only protect functions that have corresponding attributes.
688   addPass(createSafeStackPass());
689   addPass(createStackProtectorPass());
690 
691   if (PrintISelInput)
692     addPass(createPrintFunctionPass(
693         dbgs(), "\n\n*** Final LLVM Code input to ISel ***\n"));
694 
695   // All passes which modify the LLVM IR are now complete; run the verifier
696   // to ensure that the IR is valid.
697   if (!DisableVerify)
698     addPass(createVerifierPass());
699 }
700 
701 bool TargetPassConfig::addCoreISelPasses() {
702   // Enable FastISel with -fast, but allow that to be overridden.
703   TM->setO0WantsFastISel(EnableFastISelOption != cl::BOU_FALSE);
704   if (EnableFastISelOption == cl::BOU_TRUE ||
705       (TM->getOptLevel() == CodeGenOpt::None && TM->getO0WantsFastISel()))
706     TM->setFastISel(true);
707 
708   // Ask the target for an isel.
709   // Enable GlobalISel if the target wants to, but allow that to be overriden.
710   if (EnableGlobalISel == cl::BOU_TRUE ||
711       (EnableGlobalISel == cl::BOU_UNSET && isGlobalISelEnabled())) {
712     if (addIRTranslator())
713       return true;
714 
715     addPreLegalizeMachineIR();
716 
717     if (addLegalizeMachineIR())
718       return true;
719 
720     // Before running the register bank selector, ask the target if it
721     // wants to run some passes.
722     addPreRegBankSelect();
723 
724     if (addRegBankSelect())
725       return true;
726 
727     addPreGlobalInstructionSelect();
728 
729     if (addGlobalInstructionSelect())
730       return true;
731 
732     // Pass to reset the MachineFunction if the ISel failed.
733     addPass(createResetMachineFunctionPass(
734         reportDiagnosticWhenGlobalISelFallback(), isGlobalISelAbortEnabled()));
735 
736     // Provide a fallback path when we do not want to abort on
737     // not-yet-supported input.
738     if (!isGlobalISelAbortEnabled() && addInstSelector())
739       return true;
740 
741   } else if (addInstSelector())
742     return true;
743 
744   return false;
745 }
746 
747 bool TargetPassConfig::addISelPasses() {
748   if (TM->Options.EmulatedTLS)
749     addPass(createLowerEmuTLSPass());
750 
751   addPass(createPreISelIntrinsicLoweringPass());
752   addPass(createTargetTransformInfoWrapperPass(TM->getTargetIRAnalysis()));
753   addIRPasses();
754   addCodeGenPrepare();
755   addPassesToHandleExceptions();
756   addISelPrepare();
757 
758   return addCoreISelPasses();
759 }
760 
761 /// -regalloc=... command line option.
762 static FunctionPass *useDefaultRegisterAllocator() { return nullptr; }
763 static cl::opt<RegisterRegAlloc::FunctionPassCtor, false,
764                RegisterPassParser<RegisterRegAlloc> >
765 RegAlloc("regalloc",
766          cl::init(&useDefaultRegisterAllocator),
767          cl::desc("Register allocator to use"));
768 
769 /// Add the complete set of target-independent postISel code generator passes.
770 ///
771 /// This can be read as the standard order of major LLVM CodeGen stages. Stages
772 /// with nontrivial configuration or multiple passes are broken out below in
773 /// add%Stage routines.
774 ///
775 /// Any TargetPassConfig::addXX routine may be overriden by the Target. The
776 /// addPre/Post methods with empty header implementations allow injecting
777 /// target-specific fixups just before or after major stages. Additionally,
778 /// targets have the flexibility to change pass order within a stage by
779 /// overriding default implementation of add%Stage routines below. Each
780 /// technique has maintainability tradeoffs because alternate pass orders are
781 /// not well supported. addPre/Post works better if the target pass is easily
782 /// tied to a common pass. But if it has subtle dependencies on multiple passes,
783 /// the target should override the stage instead.
784 ///
785 /// TODO: We could use a single addPre/Post(ID) hook to allow pass injection
786 /// before/after any target-independent pass. But it's currently overkill.
787 void TargetPassConfig::addMachinePasses() {
788   AddingMachinePasses = true;
789 
790   // Insert a machine instr printer pass after the specified pass.
791   if (!StringRef(PrintMachineInstrs.getValue()).equals("") &&
792       !StringRef(PrintMachineInstrs.getValue()).equals("option-unspecified")) {
793     const PassRegistry *PR = PassRegistry::getPassRegistry();
794     const PassInfo *TPI = PR->getPassInfo(PrintMachineInstrs.getValue());
795     const PassInfo *IPI = PR->getPassInfo(StringRef("machineinstr-printer"));
796     assert (TPI && IPI && "Pass ID not registered!");
797     const char *TID = (const char *)(TPI->getTypeInfo());
798     const char *IID = (const char *)(IPI->getTypeInfo());
799     insertPass(TID, IID);
800   }
801 
802   // Print the instruction selected machine code...
803   printAndVerify("After Instruction Selection");
804 
805   // Expand pseudo-instructions emitted by ISel.
806   addPass(&ExpandISelPseudosID);
807 
808   // Add passes that optimize machine instructions in SSA form.
809   if (getOptLevel() != CodeGenOpt::None) {
810     addMachineSSAOptimization();
811   } else {
812     // If the target requests it, assign local variables to stack slots relative
813     // to one another and simplify frame index references where possible.
814     addPass(&LocalStackSlotAllocationID, false);
815   }
816 
817   if (TM->Options.EnableIPRA)
818     addPass(createRegUsageInfoPropPass());
819 
820   // Run pre-ra passes.
821   addPreRegAlloc();
822 
823   // Run register allocation and passes that are tightly coupled with it,
824   // including phi elimination and scheduling.
825   if (getOptimizeRegAlloc())
826     addOptimizedRegAlloc(createRegAllocPass(true));
827   else {
828     if (RegAlloc != &useDefaultRegisterAllocator &&
829         RegAlloc != &createFastRegisterAllocator)
830       report_fatal_error("Must use fast (default) register allocator for unoptimized regalloc.");
831     addFastRegAlloc(createRegAllocPass(false));
832   }
833 
834   // Run post-ra passes.
835   addPostRegAlloc();
836 
837   // Insert prolog/epilog code.  Eliminate abstract frame index references...
838   if (getOptLevel() != CodeGenOpt::None)
839     addPass(&ShrinkWrapID);
840 
841   // Prolog/Epilog inserter needs a TargetMachine to instantiate. But only
842   // do so if it hasn't been disabled, substituted, or overridden.
843   if (!isPassSubstitutedOrOverridden(&PrologEpilogCodeInserterID))
844       addPass(createPrologEpilogInserterPass());
845 
846   /// Add passes that optimize machine instructions after register allocation.
847   if (getOptLevel() != CodeGenOpt::None)
848     addMachineLateOptimization();
849 
850   // Expand pseudo instructions before second scheduling pass.
851   addPass(&ExpandPostRAPseudosID);
852 
853   // Run pre-sched2 passes.
854   addPreSched2();
855 
856   if (EnableImplicitNullChecks)
857     addPass(&ImplicitNullChecksID);
858 
859   // Second pass scheduler.
860   // Let Target optionally insert this pass by itself at some other
861   // point.
862   if (getOptLevel() != CodeGenOpt::None &&
863       !TM->targetSchedulesPostRAScheduling()) {
864     if (MISchedPostRA)
865       addPass(&PostMachineSchedulerID);
866     else
867       addPass(&PostRASchedulerID);
868   }
869 
870   // GC
871   if (addGCPasses()) {
872     if (PrintGCInfo)
873       addPass(createGCInfoPrinter(dbgs()), false, false);
874   }
875 
876   // Basic block placement.
877   if (getOptLevel() != CodeGenOpt::None)
878     addBlockPlacement();
879 
880   addPreEmitPass();
881 
882   if (TM->Options.EnableIPRA)
883     // Collect register usage information and produce a register mask of
884     // clobbered registers, to be used to optimize call sites.
885     addPass(createRegUsageInfoCollector());
886 
887   addPass(&FuncletLayoutID, false);
888 
889   addPass(&StackMapLivenessID, false);
890   addPass(&LiveDebugValuesID, false);
891 
892   // Insert before XRay Instrumentation.
893   addPass(&FEntryInserterID, false);
894 
895   addPass(&XRayInstrumentationID, false);
896   addPass(&PatchableFunctionID, false);
897 
898   if (EnableMachineOutliner)
899     PM->add(createMachineOutlinerPass());
900 
901   AddingMachinePasses = false;
902 }
903 
904 /// Add passes that optimize machine instructions in SSA form.
905 void TargetPassConfig::addMachineSSAOptimization() {
906   // Pre-ra tail duplication.
907   addPass(&EarlyTailDuplicateID);
908 
909   // Optimize PHIs before DCE: removing dead PHI cycles may make more
910   // instructions dead.
911   addPass(&OptimizePHIsID, false);
912 
913   // This pass merges large allocas. StackSlotColoring is a different pass
914   // which merges spill slots.
915   addPass(&StackColoringID, false);
916 
917   // If the target requests it, assign local variables to stack slots relative
918   // to one another and simplify frame index references where possible.
919   addPass(&LocalStackSlotAllocationID, false);
920 
921   // With optimization, dead code should already be eliminated. However
922   // there is one known exception: lowered code for arguments that are only
923   // used by tail calls, where the tail calls reuse the incoming stack
924   // arguments directly (see t11 in test/CodeGen/X86/sibcall.ll).
925   addPass(&DeadMachineInstructionElimID);
926 
927   // Allow targets to insert passes that improve instruction level parallelism,
928   // like if-conversion. Such passes will typically need dominator trees and
929   // loop info, just like LICM and CSE below.
930   addILPOpts();
931 
932   addPass(&MachineLICMID, false);
933   addPass(&MachineCSEID, false);
934 
935   // Coalesce basic blocks with the same branch condition
936   addPass(&BranchCoalescingID);
937 
938   addPass(&MachineSinkingID);
939 
940   addPass(&PeepholeOptimizerID);
941   // Clean-up the dead code that may have been generated by peephole
942   // rewriting.
943   addPass(&DeadMachineInstructionElimID);
944 }
945 
946 //===---------------------------------------------------------------------===//
947 /// Register Allocation Pass Configuration
948 //===---------------------------------------------------------------------===//
949 
950 bool TargetPassConfig::getOptimizeRegAlloc() const {
951   switch (OptimizeRegAlloc) {
952   case cl::BOU_UNSET: return getOptLevel() != CodeGenOpt::None;
953   case cl::BOU_TRUE:  return true;
954   case cl::BOU_FALSE: return false;
955   }
956   llvm_unreachable("Invalid optimize-regalloc state");
957 }
958 
959 /// RegisterRegAlloc's global Registry tracks allocator registration.
960 MachinePassRegistry RegisterRegAlloc::Registry;
961 
962 /// A dummy default pass factory indicates whether the register allocator is
963 /// overridden on the command line.
964 static llvm::once_flag InitializeDefaultRegisterAllocatorFlag;
965 
966 static RegisterRegAlloc
967 defaultRegAlloc("default",
968                 "pick register allocator based on -O option",
969                 useDefaultRegisterAllocator);
970 
971 static void initializeDefaultRegisterAllocatorOnce() {
972   RegisterRegAlloc::FunctionPassCtor Ctor = RegisterRegAlloc::getDefault();
973 
974   if (!Ctor) {
975     Ctor = RegAlloc;
976     RegisterRegAlloc::setDefault(RegAlloc);
977   }
978 }
979 
980 /// Instantiate the default register allocator pass for this target for either
981 /// the optimized or unoptimized allocation path. This will be added to the pass
982 /// manager by addFastRegAlloc in the unoptimized case or addOptimizedRegAlloc
983 /// in the optimized case.
984 ///
985 /// A target that uses the standard regalloc pass order for fast or optimized
986 /// allocation may still override this for per-target regalloc
987 /// selection. But -regalloc=... always takes precedence.
988 FunctionPass *TargetPassConfig::createTargetRegisterAllocator(bool Optimized) {
989   if (Optimized)
990     return createGreedyRegisterAllocator();
991   else
992     return createFastRegisterAllocator();
993 }
994 
995 /// Find and instantiate the register allocation pass requested by this target
996 /// at the current optimization level.  Different register allocators are
997 /// defined as separate passes because they may require different analysis.
998 ///
999 /// This helper ensures that the regalloc= option is always available,
1000 /// even for targets that override the default allocator.
1001 ///
1002 /// FIXME: When MachinePassRegistry register pass IDs instead of function ptrs,
1003 /// this can be folded into addPass.
1004 FunctionPass *TargetPassConfig::createRegAllocPass(bool Optimized) {
1005   // Initialize the global default.
1006   llvm::call_once(InitializeDefaultRegisterAllocatorFlag,
1007                   initializeDefaultRegisterAllocatorOnce);
1008 
1009   RegisterRegAlloc::FunctionPassCtor Ctor = RegisterRegAlloc::getDefault();
1010   if (Ctor != useDefaultRegisterAllocator)
1011     return Ctor();
1012 
1013   // With no -regalloc= override, ask the target for a regalloc pass.
1014   return createTargetRegisterAllocator(Optimized);
1015 }
1016 
1017 /// Return true if the default global register allocator is in use and
1018 /// has not be overriden on the command line with '-regalloc=...'
1019 bool TargetPassConfig::usingDefaultRegAlloc() const {
1020   return RegAlloc.getNumOccurrences() == 0;
1021 }
1022 
1023 /// Add the minimum set of target-independent passes that are required for
1024 /// register allocation. No coalescing or scheduling.
1025 void TargetPassConfig::addFastRegAlloc(FunctionPass *RegAllocPass) {
1026   addPass(&PHIEliminationID, false);
1027   addPass(&TwoAddressInstructionPassID, false);
1028 
1029   if (RegAllocPass)
1030     addPass(RegAllocPass);
1031 }
1032 
1033 /// Add standard target-independent passes that are tightly coupled with
1034 /// optimized register allocation, including coalescing, machine instruction
1035 /// scheduling, and register allocation itself.
1036 void TargetPassConfig::addOptimizedRegAlloc(FunctionPass *RegAllocPass) {
1037   addPass(&DetectDeadLanesID, false);
1038 
1039   addPass(&ProcessImplicitDefsID, false);
1040 
1041   // LiveVariables currently requires pure SSA form.
1042   //
1043   // FIXME: Once TwoAddressInstruction pass no longer uses kill flags,
1044   // LiveVariables can be removed completely, and LiveIntervals can be directly
1045   // computed. (We still either need to regenerate kill flags after regalloc, or
1046   // preferably fix the scavenger to not depend on them).
1047   addPass(&LiveVariablesID, false);
1048 
1049   // Edge splitting is smarter with machine loop info.
1050   addPass(&MachineLoopInfoID, false);
1051   addPass(&PHIEliminationID, false);
1052 
1053   // Eventually, we want to run LiveIntervals before PHI elimination.
1054   if (EarlyLiveIntervals)
1055     addPass(&LiveIntervalsID, false);
1056 
1057   addPass(&TwoAddressInstructionPassID, false);
1058   addPass(&RegisterCoalescerID);
1059 
1060   // The machine scheduler may accidentally create disconnected components
1061   // when moving subregister definitions around, avoid this by splitting them to
1062   // separate vregs before. Splitting can also improve reg. allocation quality.
1063   addPass(&RenameIndependentSubregsID);
1064 
1065   // PreRA instruction scheduling.
1066   addPass(&MachineSchedulerID);
1067 
1068   if (RegAllocPass) {
1069     // Add the selected register allocation pass.
1070     addPass(RegAllocPass);
1071 
1072     // Allow targets to change the register assignments before rewriting.
1073     addPreRewrite();
1074 
1075     // Copy propagate to forward register uses and try to eliminate COPYs that
1076     // were not coalesced.
1077     addPass(&MachineCopyPropagationPreRegRewriteID);
1078 
1079     // Finally rewrite virtual registers.
1080     addPass(&VirtRegRewriterID);
1081 
1082     // Perform stack slot coloring and post-ra machine LICM.
1083     //
1084     // FIXME: Re-enable coloring with register when it's capable of adding
1085     // kill markers.
1086     addPass(&StackSlotColoringID);
1087 
1088     // Run post-ra machine LICM to hoist reloads / remats.
1089     //
1090     // FIXME: can this move into MachineLateOptimization?
1091     addPass(&PostRAMachineLICMID);
1092   }
1093 }
1094 
1095 //===---------------------------------------------------------------------===//
1096 /// Post RegAlloc Pass Configuration
1097 //===---------------------------------------------------------------------===//
1098 
1099 /// Add passes that optimize machine instructions after register allocation.
1100 void TargetPassConfig::addMachineLateOptimization() {
1101   // Branch folding must be run after regalloc and prolog/epilog insertion.
1102   addPass(&BranchFolderPassID);
1103 
1104   // Tail duplication.
1105   // Note that duplicating tail just increases code size and degrades
1106   // performance for targets that require Structured Control Flow.
1107   // In addition it can also make CFG irreducible. Thus we disable it.
1108   if (!TM->requiresStructuredCFG())
1109     addPass(&TailDuplicateID);
1110 
1111   // Copy propagation.
1112   addPass(&MachineCopyPropagationID);
1113 }
1114 
1115 /// Add standard GC passes.
1116 bool TargetPassConfig::addGCPasses() {
1117   addPass(&GCMachineCodeAnalysisID, false);
1118   return true;
1119 }
1120 
1121 /// Add standard basic block placement passes.
1122 void TargetPassConfig::addBlockPlacement() {
1123   if (addPass(&MachineBlockPlacementID)) {
1124     // Run a separate pass to collect block placement statistics.
1125     if (EnableBlockPlacementStats)
1126       addPass(&MachineBlockPlacementStatsID);
1127   }
1128 }
1129 
1130 //===---------------------------------------------------------------------===//
1131 /// GlobalISel Configuration
1132 //===---------------------------------------------------------------------===//
1133 
1134 bool TargetPassConfig::isGlobalISelEnabled() const {
1135   return false;
1136 }
1137 
1138 bool TargetPassConfig::isGlobalISelAbortEnabled() const {
1139   return EnableGlobalISelAbort == 1;
1140 }
1141 
1142 bool TargetPassConfig::reportDiagnosticWhenGlobalISelFallback() const {
1143   return EnableGlobalISelAbort == 2;
1144 }
1145