Recommit [NFC] Better encapsulation of llvm::Optional Storage
[llvm-complete.git] / include / llvm / IR / OptBisect.h
blob8d51b6856dda2178064d05f1d01955e2420cb315
1 //===- llvm/IR/OptBisect.h - LLVM Bisect support ----------------*- C++ -*-===//
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 ///
9 /// \file
10 /// This file declares the interface for bisecting optimizations.
11 ///
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_IR_OPTBISECT_H
15 #define LLVM_IR_OPTBISECT_H
17 #include "llvm/ADT/StringRef.h"
19 namespace llvm {
21 class Pass;
22 class Module;
23 class Function;
24 class BasicBlock;
25 class Region;
26 class Loop;
27 class CallGraphSCC;
29 /// Extensions to this class implement mechanisms to disable passes and
30 /// individual optimizations at compile time.
31 class OptPassGate {
32 public:
33 virtual ~OptPassGate() = default;
35 virtual bool shouldRunPass(const Pass *P, const Module &U) { return true; }
36 virtual bool shouldRunPass(const Pass *P, const Function &U) {return true; }
37 virtual bool shouldRunPass(const Pass *P, const BasicBlock &U) { return true; }
38 virtual bool shouldRunPass(const Pass *P, const Region &U) { return true; }
39 virtual bool shouldRunPass(const Pass *P, const Loop &U) { return true; }
40 virtual bool shouldRunPass(const Pass *P, const CallGraphSCC &U) { return true; }
43 /// This class implements a mechanism to disable passes and individual
44 /// optimizations at compile time based on a command line option
45 /// (-opt-bisect-limit) in order to perform a bisecting search for
46 /// optimization-related problems.
47 class OptBisect : public OptPassGate {
48 public:
49 /// Default constructor, initializes the OptBisect state based on the
50 /// -opt-bisect-limit command line argument.
51 ///
52 /// By default, bisection is disabled.
53 ///
54 /// Clients should not instantiate this class directly. All access should go
55 /// through LLVMContext.
56 OptBisect();
58 virtual ~OptBisect() = default;
60 /// Checks the bisect limit to determine if the specified pass should run.
61 ///
62 /// These functions immediately return true if bisection is disabled. If the
63 /// bisect limit is set to -1, the functions print a message describing
64 /// the pass and the bisect number assigned to it and return true. Otherwise,
65 /// the functions print a message with the bisect number assigned to the
66 /// pass and indicating whether or not the pass will be run and return true if
67 /// the bisect limit has not yet been exceeded or false if it has.
68 ///
69 /// Most passes should not call these routines directly. Instead, they are
70 /// called through helper routines provided by the pass base classes. For
71 /// instance, function passes should call FunctionPass::skipFunction().
72 bool shouldRunPass(const Pass *P, const Module &U) override;
73 bool shouldRunPass(const Pass *P, const Function &U) override;
74 bool shouldRunPass(const Pass *P, const BasicBlock &U) override;
75 bool shouldRunPass(const Pass *P, const Region &U) override;
76 bool shouldRunPass(const Pass *P, const Loop &U) override;
77 bool shouldRunPass(const Pass *P, const CallGraphSCC &U) override;
79 private:
80 bool checkPass(const StringRef PassName, const StringRef TargetDesc);
82 bool BisectEnabled = false;
83 unsigned LastBisectNum = 0;
86 } // end namespace llvm
88 #endif // LLVM_IR_OPTBISECT_H