AssumeBundleBuilder.h 3.3 KB

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