1 //===- llvm/IR/OptBisect.h - LLVM Bisect support ----------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
11 /// This file declares the interface for bisecting optimizations.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_IR_OPTBISECT_H
16 #define LLVM_IR_OPTBISECT_H
18 #include "llvm/ADT/StringRef.h"
30 /// Extensions to this class implement mechanisms to disable passes and
31 /// individual optimizations at compile time.
34 virtual ~OptPassGate() = default;
36 virtual bool shouldRunPass(const Pass *P, const Module &U) { return true; }
37 virtual bool shouldRunPass(const Pass *P, const Function &U) {return true; }
38 virtual bool shouldRunPass(const Pass *P, const BasicBlock &U) { return true; }
39 virtual bool shouldRunPass(const Pass *P, const Region &U) { return true; }
40 virtual bool shouldRunPass(const Pass *P, const Loop &U) { return true; }
41 virtual bool shouldRunPass(const Pass *P, const CallGraphSCC &U) { return true; }
44 /// This class implements a mechanism to disable passes and individual
45 /// optimizations at compile time based on a command line option
46 /// (-opt-bisect-limit) in order to perform a bisecting search for
47 /// optimization-related problems.
48 class OptBisect : public OptPassGate {
50 /// Default constructor, initializes the OptBisect state based on the
51 /// -opt-bisect-limit command line argument.
53 /// By default, bisection is disabled.
55 /// Clients should not instantiate this class directly. All access should go
56 /// through LLVMContext.
59 virtual ~OptBisect() = default;
61 /// Checks the bisect limit to determine if the specified pass should run.
63 /// These functions immediately return true if bisection is disabled. If the
64 /// bisect limit is set to -1, the functions print a message describing
65 /// the pass and the bisect number assigned to it and return true. Otherwise,
66 /// the functions print a message with the bisect number assigned to the
67 /// pass and indicating whether or not the pass will be run and return true if
68 /// the bisect limit has not yet been exceeded or false if it has.
70 /// Most passes should not call these routines directly. Instead, they are
71 /// called through helper routines provided by the pass base classes. For
72 /// instance, function passes should call FunctionPass::skipFunction().
73 bool shouldRunPass(const Pass *P, const Module &U) override;
74 bool shouldRunPass(const Pass *P, const Function &U) override;
75 bool shouldRunPass(const Pass *P, const BasicBlock &U) override;
76 bool shouldRunPass(const Pass *P, const Region &U) override;
77 bool shouldRunPass(const Pass *P, const Loop &U) override;
78 bool shouldRunPass(const Pass *P, const CallGraphSCC &U) override;
81 bool checkPass(const StringRef PassName, const StringRef TargetDesc);
83 bool BisectEnabled = false;
84 unsigned LastBisectNum = 0;
87 } // end namespace llvm
89 #endif // LLVM_IR_OPTBISECT_H