LLVM  14.0.0git
Assumptions.h
Go to the documentation of this file.
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 class CallBase;
25 
26 /// The key we use for assumption attributes.
27 constexpr StringRef AssumptionAttrKey = "llvm.assume";
28 
29 /// A set of known assumption strings that are accepted without warning and
30 /// which can be recommended as typo correction.
32 
33 /// Helper that allows to insert a new assumption string in the known assumption
34 /// set by creating a (static) object.
37  : AssumptionStr(AssumptionStr) {
38  KnownAssumptionStrings.insert(AssumptionStr);
39  }
40  operator StringRef() const { return AssumptionStr; }
41 
42 private:
43  StringRef AssumptionStr;
44 };
45 
46 /// Return true if \p F has the assumption \p AssumptionStr attached.
47 bool hasAssumption(Function &F, const KnownAssumptionString &AssumptionStr);
48 
49 /// Return true if \p CB or the callee has the assumption \p AssumptionStr
50 /// attached.
51 bool hasAssumption(CallBase &CB, const KnownAssumptionString &AssumptionStr);
52 
53 } // namespace llvm
54 
55 #endif
llvm
This file implements support for optimizing divisions by a constant.
Definition: AllocatorList.h:23
StringRef.h
llvm::StringSet::insert
std::pair< typename Base::iterator, bool > insert(StringRef key)
Definition: StringSet.h:33
F
#define F(x, y, z)
Definition: MD5.cpp:56
llvm::KnownAssumptionString::KnownAssumptionString
KnownAssumptionString(StringRef AssumptionStr)
Definition: Assumptions.h:36
llvm::KnownAssumptionStrings
StringSet KnownAssumptionStrings
A set of known assumption strings that are accepted without warning and which can be recommended as t...
llvm::KnownAssumptionString
Helper that allows to insert a new assumption string in the known assumption set by creating a (stati...
Definition: Assumptions.h:35
llvm::AssumptionAttrKey
constexpr StringRef AssumptionAttrKey
The key we use for assumption attributes.
Definition: Assumptions.h:27
llvm::StringSet
StringSet - A wrapper for StringMap that provides set-like functionality.
Definition: StringSet.h:22
llvm::ReplayInlineScope::Function
@ Function
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
StringSet.h
llvm::hasAssumption
bool hasAssumption(Function &F, const KnownAssumptionString &AssumptionStr)
Return true if F has the assumption AssumptionStr attached.
Definition: Assumptions.cpp:32