LLVM  14.0.0git
Assumptions.cpp
Go to the documentation of this file.
1 //===- Assumptions.cpp ------ Collection of helpers for assumptions -------===//
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 //===----------------------------------------------------------------------===//
10 
11 #include "llvm/IR/Assumptions.h"
12 #include "llvm/IR/Attributes.h"
13 #include "llvm/IR/Function.h"
14 #include "llvm/IR/InstrTypes.h"
15 
16 using namespace llvm;
17 
18 namespace {
19 bool hasAssumption(const Attribute &A,
20  const KnownAssumptionString &AssumptionStr) {
21  if (!A.isValid())
22  return false;
23  assert(A.isStringAttribute() && "Expected a string attribute!");
24 
26  A.getValueAsString().split(Strings, ",");
27 
28  return llvm::any_of(Strings, [=](StringRef Assumption) {
29  return Assumption == AssumptionStr;
30  });
31 }
32 } // namespace
33 
35  const KnownAssumptionString &AssumptionStr) {
36  const Attribute &A = F.getFnAttribute(AssumptionAttrKey);
37  return ::hasAssumption(A, AssumptionStr);
38 }
39 
41  const KnownAssumptionString &AssumptionStr) {
42  if (Function *F = CB.getCalledFunction())
43  if (hasAssumption(*F, AssumptionStr))
44  return true;
45 
46  const Attribute &A = CB.getFnAttr(AssumptionAttrKey);
47  return ::hasAssumption(A, AssumptionStr);
48 }
49 
51  "omp_no_openmp", // OpenMP 5.1
52  "omp_no_openmp_routines", // OpenMP 5.1
53  "omp_no_parallelism", // OpenMP 5.1
54  "ompx_spmd_amenable", // OpenMPOpt extension
55 });
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
llvm::Function
Definition: Function.h:61
llvm::Attribute
Definition: Attributes.h:52
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1168
F
#define F(x, y, z)
Definition: MD5.cpp:56
llvm::KnownAssumptionStrings
StringSet KnownAssumptionStrings
A set of known assumption strings that are accepted without warning and which can be recommended as t...
llvm::ARM_PROC::A
@ A
Definition: ARMBaseInfo.h:34
InstrTypes.h
llvm::CallBase::getCalledFunction
Function * getCalledFunction() const
Returns the function called, or null if this is an indirect function invocation.
Definition: InstrTypes.h:1393
Assumptions.h
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
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::StringSet
StringSet - A wrapper for StringMap that provides set-like functionality.
Definition: StringSet.h:22
llvm::CallBase::getFnAttr
Attribute getFnAttr(StringRef Kind) const
Get the attribute of a given kind for the function.
Definition: InstrTypes.h:1609
llvm::any_of
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1556
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
Attributes.h
Function.h
llvm::hasAssumption
bool hasAssumption(Function &F, const KnownAssumptionString &AssumptionStr)
Return true if F has the assumption AssumptionStr attached.
Definition: Assumptions.cpp:34
llvm::CallBase
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
Definition: InstrTypes.h:1161