AssumeBundleBuilder.h 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- AssumeBundleBuilder.h - utils to build assume bundles ----*- 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. // This file contain tools to preserve informations. They should be used before
  15. // performing a transformation that may move and delete instructions as those
  16. // transformation may destroy or worsen information that can be derived from the
  17. // IR.
  18. //
  19. //===----------------------------------------------------------------------===//
  20. #ifndef LLVM_TRANSFORMS_UTILS_ASSUMEBUNDLEBUILDER_H
  21. #define LLVM_TRANSFORMS_UTILS_ASSUMEBUNDLEBUILDER_H
  22. #include "llvm/Analysis/AssumeBundleQueries.h"
  23. #include "llvm/IR/PassManager.h"
  24. namespace llvm {
  25. class AssumeInst;
  26. class Function;
  27. class FunctionPass;
  28. class Instruction;
  29. class AssumptionCache;
  30. class DominatorTree;
  31. /// Build a call to llvm.assume to preserve informations that can be derived
  32. /// from the given instruction.
  33. /// If no information derived from \p I, this call returns null.
  34. /// The returned instruction is not inserted anywhere.
  35. AssumeInst *buildAssumeFromInst(Instruction *I);
  36. /// Calls BuildAssumeFromInst and if the resulting llvm.assume is valid insert
  37. /// if before I. This is usually what need to be done to salvage the knowledge
  38. /// contained in the instruction I.
  39. /// The AssumptionCache must be provided if it is available or the cache may
  40. /// become silently be invalid.
  41. /// The DominatorTree can optionally be provided to enable cross-block
  42. /// reasoning.
  43. void salvageKnowledge(Instruction *I, AssumptionCache *AC = nullptr,
  44. DominatorTree *DT = nullptr);
  45. /// Build and return a new assume created from the provided knowledge
  46. /// if the knowledge in the assume is fully redundant this will return nullptr
  47. AssumeInst *buildAssumeFromKnowledge(ArrayRef<RetainedKnowledge> Knowledge,
  48. Instruction *CtxI,
  49. AssumptionCache *AC = nullptr,
  50. DominatorTree *DT = nullptr);
  51. /// This pass attempts to minimize the number of assume without loosing any
  52. /// information.
  53. struct AssumeSimplifyPass : public PassInfoMixin<AssumeSimplifyPass> {
  54. PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
  55. };
  56. FunctionPass *createAssumeSimplifyPass();
  57. /// This pass will try to build an llvm.assume for every instruction in the
  58. /// function. Its main purpose is testing.
  59. struct AssumeBuilderPass : public PassInfoMixin<AssumeBuilderPass> {
  60. PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
  61. };
  62. /// canonicalize the RetainedKnowledge RK. it is assumed that RK is part of
  63. /// Assume. This will return an empty RetainedKnowledge if the knowledge is
  64. /// useless.
  65. RetainedKnowledge simplifyRetainedKnowledge(AssumeInst *Assume,
  66. RetainedKnowledge RK,
  67. AssumptionCache *AC,
  68. DominatorTree *DT);
  69. } // namespace llvm
  70. #endif
  71. #ifdef __GNUC__
  72. #pragma GCC diagnostic pop
  73. #endif