SimplifyCFGOptions.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 ConvertSwitchToLookupTable = false;
  28. bool NeedCanonicalLoop = true;
  29. bool HoistCommonInsts = false;
  30. bool SinkCommonInsts = false;
  31. bool SimplifyCondBranch = true;
  32. bool FoldTwoEntryPHINode = true;
  33. AssumptionCache *AC = nullptr;
  34. // Support 'builder' pattern to set members by name at construction time.
  35. SimplifyCFGOptions &bonusInstThreshold(int I) {
  36. BonusInstThreshold = I;
  37. return *this;
  38. }
  39. SimplifyCFGOptions &forwardSwitchCondToPhi(bool B) {
  40. ForwardSwitchCondToPhi = B;
  41. return *this;
  42. }
  43. SimplifyCFGOptions &convertSwitchToLookupTable(bool B) {
  44. ConvertSwitchToLookupTable = B;
  45. return *this;
  46. }
  47. SimplifyCFGOptions &needCanonicalLoops(bool B) {
  48. NeedCanonicalLoop = B;
  49. return *this;
  50. }
  51. SimplifyCFGOptions &hoistCommonInsts(bool B) {
  52. HoistCommonInsts = B;
  53. return *this;
  54. }
  55. SimplifyCFGOptions &sinkCommonInsts(bool B) {
  56. SinkCommonInsts = B;
  57. return *this;
  58. }
  59. SimplifyCFGOptions &setAssumptionCache(AssumptionCache *Cache) {
  60. AC = Cache;
  61. return *this;
  62. }
  63. SimplifyCFGOptions &setSimplifyCondBranch(bool B) {
  64. SimplifyCondBranch = B;
  65. return *this;
  66. }
  67. SimplifyCFGOptions &setFoldTwoEntryPHINode(bool B) {
  68. FoldTwoEntryPHINode = B;
  69. return *this;
  70. }
  71. };
  72. } // namespace llvm
  73. #endif // LLVM_TRANSFORMS_UTILS_SIMPLIFYCFGOPTIONS_H
  74. #ifdef __GNUC__
  75. #pragma GCC diagnostic pop
  76. #endif