Assumptions.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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/StringRef.h"
  22. #include "llvm/ADT/StringSet.h"
  23. namespace llvm {
  24. class Function;
  25. /// The key we use for assumption attributes.
  26. constexpr StringRef AssumptionAttrKey = "llvm.assume";
  27. /// A set of known assumption strings that are accepted without warning and
  28. /// which can be recommended as typo correction.
  29. extern StringSet<> KnownAssumptionStrings;
  30. /// Helper that allows to insert a new assumption string in the known assumption
  31. /// set by creating a (static) object.
  32. struct KnownAssumptionString {
  33. KnownAssumptionString(StringRef AssumptionStr)
  34. : AssumptionStr(AssumptionStr) {
  35. KnownAssumptionStrings.insert(AssumptionStr);
  36. }
  37. operator StringRef() const { return AssumptionStr; }
  38. private:
  39. StringRef AssumptionStr;
  40. };
  41. /// Return true if \p F has the assumption \p AssumptionStr attached.
  42. bool hasAssumption(Function &F, const KnownAssumptionString &AssumptionStr);
  43. } // namespace llvm
  44. #endif
  45. #ifdef __GNUC__
  46. #pragma GCC diagnostic pop
  47. #endif