Assumptions.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===--- Assumptions.h - Assumption handling and organization ---*- 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. // String assumptions that are known to optimization passes should be placed in
  15. // the KnownAssumptionStrings set. This can be done in various ways, i.a.,
  16. // via a static KnownAssumptionString object.
  17. //
  18. //===----------------------------------------------------------------------===//
  19. #ifndef LLVM_IR_ASSUMPTIONS_H
  20. #define LLVM_IR_ASSUMPTIONS_H
  21. #include "llvm/ADT/DenseSet.h"
  22. #include "llvm/ADT/StringRef.h"
  23. #include "llvm/ADT/StringSet.h"
  24. namespace llvm {
  25. class Function;
  26. class CallBase;
  27. /// The key we use for assumption attributes.
  28. constexpr StringRef AssumptionAttrKey = "llvm.assume";
  29. /// A set of known assumption strings that are accepted without warning and
  30. /// which can be recommended as typo correction.
  31. extern StringSet<> KnownAssumptionStrings;
  32. /// Helper that allows to insert a new assumption string in the known assumption
  33. /// set by creating a (static) object.
  34. struct KnownAssumptionString {
  35. KnownAssumptionString(StringRef AssumptionStr)
  36. : AssumptionStr(AssumptionStr) {
  37. KnownAssumptionStrings.insert(AssumptionStr);
  38. }
  39. operator StringRef() const { return AssumptionStr; }
  40. private:
  41. StringRef AssumptionStr;
  42. };
  43. /// Return true if \p F has the assumption \p AssumptionStr attached.
  44. bool hasAssumption(const Function &F,
  45. const KnownAssumptionString &AssumptionStr);
  46. /// Return true if \p CB or the callee has the assumption \p AssumptionStr
  47. /// attached.
  48. bool hasAssumption(const CallBase &CB,
  49. const KnownAssumptionString &AssumptionStr);
  50. /// Return the set of all assumptions for the function \p F.
  51. DenseSet<StringRef> getAssumptions(const Function &F);
  52. /// Return the set of all assumptions for the call \p CB.
  53. DenseSet<StringRef> getAssumptions(const CallBase &CB);
  54. /// Appends the set of assumptions \p Assumptions to \F.
  55. bool addAssumptions(Function &F, const DenseSet<StringRef> &Assumptions);
  56. /// Appends the set of assumptions \p Assumptions to \CB.
  57. bool addAssumptions(CallBase &CB, const DenseSet<StringRef> &Assumptions);
  58. } // namespace llvm
  59. #endif
  60. #ifdef __GNUC__
  61. #pragma GCC diagnostic pop
  62. #endif