1 //===- llvm/IR/OptBisect.h - LLVM Bisect support ----------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
10 /// This file declares the interface for bisecting optimizations.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_IR_OPTBISECT_H
15 #define LLVM_IR_OPTBISECT_H
17 #include "llvm/ADT/StringRef.h"
29 /// Extensions to this class implement mechanisms to disable passes and
30 /// individual optimizations at compile time.
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
{
49 /// Default constructor, initializes the OptBisect state based on the
50 /// -opt-bisect-limit command line argument.
52 /// By default, bisection is disabled.
54 /// Clients should not instantiate this class directly. All access should go
55 /// through LLVMContext.
58 virtual ~OptBisect() = default;
60 /// Checks the bisect limit to determine if the specified pass should run.
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.
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
;
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