blob: 8d51b6856dda2178064d05f1d01955e2420cb315 [file] [log] [blame]
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001//===- llvm/IR/OptBisect.h - LLVM Bisect support ----------------*- C++ -*-===//
2//
Andrew Walbran16937d02019-10-22 13:54:20 +01003// 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
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01006//
7//===----------------------------------------------------------------------===//
8///
9/// \file
10/// This file declares the interface for bisecting optimizations.
11///
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_IR_OPTBISECT_H
15#define LLVM_IR_OPTBISECT_H
16
17#include "llvm/ADT/StringRef.h"
18
19namespace llvm {
20
21class Pass;
22class Module;
23class Function;
24class BasicBlock;
25class Region;
26class Loop;
27class CallGraphSCC;
28
29/// Extensions to this class implement mechanisms to disable passes and
30/// individual optimizations at compile time.
31class OptPassGate {
32public:
33 virtual ~OptPassGate() = default;
34
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; }
41};
42
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.
47class OptBisect : public OptPassGate {
48public:
Andrew Scullcdfcccc2018-10-05 20:58:37 +010049 /// Default constructor, initializes the OptBisect state based on the
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010050 /// -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();
57
58 virtual ~OptBisect() = default;
59
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;
78
79private:
80 bool checkPass(const StringRef PassName, const StringRef TargetDesc);
81
82 bool BisectEnabled = false;
83 unsigned LastBisectNum = 0;
84};
85
86} // end namespace llvm
87
88#endif // LLVM_IR_OPTBISECT_H