LLVM 19.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/DenseSet.h"
19#include "llvm/ADT/StringRef.h"
20#include "llvm/ADT/StringSet.h"
21
22namespace llvm {
23
24class Function;
25class CallBase;
26
27/// The key we use for assumption attributes.
28constexpr StringRef AssumptionAttrKey = "llvm.assume";
29
30/// A set of known assumption strings that are accepted without warning and
31/// which can be recommended as typo correction.
33
34/// Helper that allows to insert a new assumption string in the known assumption
35/// set by creating a (static) object.
37 KnownAssumptionString(const char *AssumptionStr)
38 : AssumptionStr(AssumptionStr) {
39 KnownAssumptionStrings.insert(AssumptionStr);
40 }
42 : AssumptionStr(AssumptionStr) {
43 KnownAssumptionStrings.insert(AssumptionStr);
44 }
45 operator StringRef() const { return AssumptionStr; }
46
47private:
48 StringRef AssumptionStr;
49};
50
51/// Return true if \p F has the assumption \p AssumptionStr attached.
52bool hasAssumption(const Function &F,
53 const KnownAssumptionString &AssumptionStr);
54
55/// Return true if \p CB or the callee has the assumption \p AssumptionStr
56/// attached.
57bool hasAssumption(const CallBase &CB,
58 const KnownAssumptionString &AssumptionStr);
59
60/// Return the set of all assumptions for the function \p F.
61DenseSet<StringRef> getAssumptions(const Function &F);
62
63/// Return the set of all assumptions for the call \p CB.
64DenseSet<StringRef> getAssumptions(const CallBase &CB);
65
66/// Appends the set of assumptions \p Assumptions to \F.
67bool addAssumptions(Function &F, const DenseSet<StringRef> &Assumptions);
68
69/// Appends the set of assumptions \p Assumptions to \CB.
70bool addAssumptions(CallBase &CB, const DenseSet<StringRef> &Assumptions);
71
72} // namespace llvm
73
74#endif
This file defines the DenseSet and SmallDenseSet classes.
#define F(x, y, z)
Definition: MD5.cpp:55
StringSet - A set-like wrapper for the StringMap.
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
StringSet - A wrapper for StringMap that provides set-like functionality.
Definition: StringSet.h:23
std::pair< typename Base::iterator, bool > insert(StringRef key)
Definition: StringSet.h:38
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
bool addAssumptions(Function &F, const DenseSet< StringRef > &Assumptions)
Appends the set of assumptions Assumptions to \F.
Definition: Assumptions.cpp:96
bool hasAssumption(const Function &F, const KnownAssumptionString &AssumptionStr)
Return true if F has the assumption AssumptionStr attached.
Definition: Assumptions.cpp:70
StringSet KnownAssumptionStrings
A set of known assumption strings that are accepted without warning and which can be recommended as t...
DenseSet< StringRef > getAssumptions(const Function &F)
Return the set of all assumptions for the function F.
Definition: Assumptions.cpp:86
constexpr StringRef AssumptionAttrKey
The key we use for assumption attributes.
Definition: Assumptions.h:28
Helper that allows to insert a new assumption string in the known assumption set by creating a (stati...
Definition: Assumptions.h:36
KnownAssumptionString(StringRef AssumptionStr)
Definition: Assumptions.h:41
KnownAssumptionString(const char *AssumptionStr)
Definition: Assumptions.h:37