Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame] | 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 | |
| 15 | #ifndef LLVM_IR_ASSUMPTIONS_H |
| 16 | #define LLVM_IR_ASSUMPTIONS_H |
| 17 | |
| 18 | #include "llvm/ADT/StringRef.h" |
| 19 | #include "llvm/ADT/StringSet.h" |
| 20 | |
| 21 | namespace llvm { |
| 22 | |
| 23 | class Function; |
| 24 | |
| 25 | /// The key we use for assumption attributes. |
| 26 | constexpr StringRef AssumptionAttrKey = "llvm.assume"; |
| 27 | |
| 28 | /// A set of known assumption strings that are accepted without warning and |
| 29 | /// which can be recommended as typo correction. |
| 30 | extern StringSet<> KnownAssumptionStrings; |
| 31 | |
| 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 | |
| 41 | private: |
| 42 | StringRef AssumptionStr; |
| 43 | }; |
| 44 | |
| 45 | /// Return true if \p F has the assumption \p AssumptionStr attached. |
| 46 | bool hasAssumption(Function &F, const KnownAssumptionString &AssumptionStr); |
| 47 | |
| 48 | } // namespace llvm |
| 49 | |
| 50 | #endif |