Assumptions.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. //===--- Assumptions.h - Assumption handling and organization ---*- C++ -*-===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. //
  9. // String assumptions that are known to optimization passes should be placed in
  10. // the KnownAssumptionStrings set. This can be done in various ways, i.a.,
  11. // via a static KnownAssumptionString object.
  12. //
  13. //===----------------------------------------------------------------------===//
  14. #ifndef LLVM_IR_ASSUMPTIONS_H
  15. #define LLVM_IR_ASSUMPTIONS_H
  16. #include "llvm/ADT/StringRef.h"
  17. #include "llvm/ADT/StringSet.h"
  18. namespace llvm {
  19. class Function;
  20. /// The key we use for assumption attributes.
  21. constexpr StringRef AssumptionAttrKey = "llvm.assume";
  22. /// A set of known assumption strings that are accepted without warning and
  23. /// which can be recommended as typo correction.
  24. extern StringSet<> KnownAssumptionStrings;
  25. /// Helper that allows to insert a new assumption string in the known assumption
  26. /// set by creating a (static) object.
  27. struct KnownAssumptionString {
  28. KnownAssumptionString(StringRef AssumptionStr)
  29. : AssumptionStr(AssumptionStr) {
  30. KnownAssumptionStrings.insert(AssumptionStr);
  31. }
  32. operator StringRef() const { return AssumptionStr; }
  33. private:
  34. StringRef AssumptionStr;
  35. };
  36. /// Return true if \p F has the assumption \p AssumptionStr attached.
  37. bool hasAssumption(Function &F, const KnownAssumptionString &AssumptionStr);
  38. } // namespace llvm
  39. #endif