SimplifyCFGOptions.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- SimplifyCFGOptions.h - Control structure for SimplifyCFG -*- 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. // A set of parameters used to control the transforms in the SimplifyCFG pass.
  15. // Options may change depending on the position in the optimization pipeline.
  16. // For example, canonical form that includes switches and branches may later be
  17. // replaced by lookup tables and selects.
  18. //
  19. //===----------------------------------------------------------------------===//
  20. #ifndef LLVM_TRANSFORMS_UTILS_SIMPLIFYCFGOPTIONS_H
  21. #define LLVM_TRANSFORMS_UTILS_SIMPLIFYCFGOPTIONS_H
  22. namespace llvm {
  23. class AssumptionCache;
  24. struct SimplifyCFGOptions {
  25. int BonusInstThreshold = 1;
  26. bool ForwardSwitchCondToPhi = false;
  27. bool ConvertSwitchRangeToICmp = false;
  28. bool ConvertSwitchToLookupTable = false;
  29. bool NeedCanonicalLoop = true;
  30. bool HoistCommonInsts = false;
  31. bool SinkCommonInsts = false;
  32. bool SimplifyCondBranch = true;
  33. bool FoldTwoEntryPHINode = true;
  34. AssumptionCache *AC = nullptr;
  35. // Support 'builder' pattern to set members by name at construction time.
  36. SimplifyCFGOptions &bonusInstThreshold(int I) {
  37. BonusInstThreshold = I;
  38. return *this;
  39. }
  40. SimplifyCFGOptions &forwardSwitchCondToPhi(bool B) {
  41. ForwardSwitchCondToPhi = B;
  42. return *this;
  43. }
  44. SimplifyCFGOptions &convertSwitchRangeToICmp(bool B) {
  45. ConvertSwitchRangeToICmp = B;
  46. return *this;
  47. }
  48. SimplifyCFGOptions &convertSwitchToLookupTable(bool B) {
  49. ConvertSwitchToLookupTable = B;
  50. return *this;
  51. }
  52. SimplifyCFGOptions &needCanonicalLoops(bool B) {
  53. NeedCanonicalLoop = B;
  54. return *this;
  55. }
  56. SimplifyCFGOptions &hoistCommonInsts(bool B) {
  57. HoistCommonInsts = B;
  58. return *this;
  59. }
  60. SimplifyCFGOptions &sinkCommonInsts(bool B) {
  61. SinkCommonInsts = B;
  62. return *this;
  63. }
  64. SimplifyCFGOptions &setAssumptionCache(AssumptionCache *Cache) {
  65. AC = Cache;
  66. return *this;
  67. }
  68. SimplifyCFGOptions &setSimplifyCondBranch(bool B) {
  69. SimplifyCondBranch = B;
  70. return *this;
  71. }
  72. SimplifyCFGOptions &setFoldTwoEntryPHINode(bool B) {
  73. FoldTwoEntryPHINode = B;
  74. return *this;
  75. }
  76. };
  77. } // namespace llvm
  78. #endif // LLVM_TRANSFORMS_UTILS_SIMPLIFYCFGOPTIONS_H
  79. #ifdef __GNUC__
  80. #pragma GCC diagnostic pop
  81. #endif