OptBisect.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- llvm/IR/OptBisect.h - LLVM Bisect support ----------------*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. ///
  14. /// \file
  15. /// This file declares the interface for bisecting optimizations.
  16. ///
  17. //===----------------------------------------------------------------------===//
  18. #ifndef LLVM_IR_OPTBISECT_H
  19. #define LLVM_IR_OPTBISECT_H
  20. #include "llvm/ADT/StringRef.h"
  21. #include "llvm/Support/ManagedStatic.h"
  22. namespace llvm {
  23. class Pass;
  24. /// Extensions to this class implement mechanisms to disable passes and
  25. /// individual optimizations at compile time.
  26. class OptPassGate {
  27. public:
  28. virtual ~OptPassGate() = default;
  29. /// IRDescription is a textual description of the IR unit the pass is running
  30. /// over.
  31. virtual bool shouldRunPass(const Pass *P, StringRef IRDescription) {
  32. return true;
  33. }
  34. /// isEnabled() should return true before calling shouldRunPass().
  35. virtual bool isEnabled() const { return false; }
  36. };
  37. /// This class implements a mechanism to disable passes and individual
  38. /// optimizations at compile time based on a command line option
  39. /// (-opt-bisect-limit) in order to perform a bisecting search for
  40. /// optimization-related problems.
  41. class OptBisect : public OptPassGate {
  42. public:
  43. /// Default constructor, initializes the OptBisect state based on the
  44. /// -opt-bisect-limit command line argument.
  45. ///
  46. /// By default, bisection is disabled.
  47. ///
  48. /// Clients should not instantiate this class directly. All access should go
  49. /// through LLVMContext.
  50. OptBisect();
  51. virtual ~OptBisect() = default;
  52. /// Checks the bisect limit to determine if the specified pass should run.
  53. ///
  54. /// This forwards to checkPass().
  55. bool shouldRunPass(const Pass *P, StringRef IRDescription) override;
  56. /// isEnabled() should return true before calling shouldRunPass().
  57. bool isEnabled() const override { return BisectEnabled; }
  58. /// Checks the bisect limit to determine if the specified pass should run.
  59. ///
  60. /// If the bisect limit is set to -1, the function prints a message describing
  61. /// the pass and the bisect number assigned to it and return true. Otherwise,
  62. /// the function prints a message with the bisect number assigned to the
  63. /// pass and indicating whether or not the pass will be run and return true if
  64. /// the bisect limit has not yet been exceeded or false if it has.
  65. ///
  66. /// Most passes should not call this routine directly. Instead, they are
  67. /// called through helper routines provided by the pass base classes. For
  68. /// instance, function passes should call FunctionPass::skipFunction().
  69. bool checkPass(const StringRef PassName, const StringRef TargetDesc);
  70. private:
  71. bool BisectEnabled = false;
  72. unsigned LastBisectNum = 0;
  73. };
  74. /// Singleton instance of the OptBisect class, so multiple pass managers don't
  75. /// need to coordinate their uses of OptBisect.
  76. extern ManagedStatic<OptBisect> OptBisector;
  77. } // end namespace llvm
  78. #endif // LLVM_IR_OPTBISECT_H
  79. #ifdef __GNUC__
  80. #pragma GCC diagnostic pop
  81. #endif