Assumptions.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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(const char *AssumptionStr)
  36. : AssumptionStr(AssumptionStr) {
  37. KnownAssumptionStrings.insert(AssumptionStr);
  38. }
  39. KnownAssumptionString(StringRef AssumptionStr)
  40. : AssumptionStr(AssumptionStr) {
  41. KnownAssumptionStrings.insert(AssumptionStr);
  42. }
  43. operator StringRef() const { return AssumptionStr; }
  44. private:
  45. StringRef AssumptionStr;
  46. };
  47. /// Return true if \p F has the assumption \p AssumptionStr attached.
  48. bool hasAssumption(const Function &F,
  49. const KnownAssumptionString &AssumptionStr);
  50. /// Return true if \p CB or the callee has the assumption \p AssumptionStr
  51. /// attached.
  52. bool hasAssumption(const CallBase &CB,
  53. const KnownAssumptionString &AssumptionStr);
  54. /// Return the set of all assumptions for the function \p F.
  55. DenseSet<StringRef> getAssumptions(const Function &F);
  56. /// Return the set of all assumptions for the call \p CB.
  57. DenseSet<StringRef> getAssumptions(const CallBase &CB);
  58. /// Appends the set of assumptions \p Assumptions to \F.
  59. bool addAssumptions(Function &F, const DenseSet<StringRef> &Assumptions);
  60. /// Appends the set of assumptions \p Assumptions to \CB.
  61. bool addAssumptions(CallBase &CB, const DenseSet<StringRef> &Assumptions);
  62. } // namespace llvm
  63. #endif
  64. #ifdef __GNUC__
  65. #pragma GCC diagnostic pop
  66. #endif