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::is_contained(Strings, AssumptionStr);
29 }
30 } // namespace
31 
33  const KnownAssumptionString &AssumptionStr) {
34  const Attribute &A = F.getFnAttribute(AssumptionAttrKey);
35  return ::hasAssumption(A, AssumptionStr);
36 }
37 
39  const KnownAssumptionString &AssumptionStr) {
40  if (Function *F = CB.getCalledFunction())
41  if (hasAssumption(*F, AssumptionStr))
42  return true;
43 
44  const Attribute &A = CB.getFnAttr(AssumptionAttrKey);
45  return ::hasAssumption(A, AssumptionStr);
46 }
47 
49  "omp_no_openmp", // OpenMP 5.1
50  "omp_no_openmp_routines", // OpenMP 5.1
51  "omp_no_parallelism", // OpenMP 5.1
52  "ompx_spmd_amenable", // OpenMPOpt extension
53 });
llvm
This file implements support for optimizing divisions by a constant.
Definition: AllocatorList.h:23
llvm::Function
Definition: Function.h:62
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:1383
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::is_contained
bool is_contained(R &&Range, const E &Element)
Wrapper function around std::find to detect if an element exists in a container.
Definition: STLExtras.h:1616
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:1599
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:32
llvm::CallBase
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
Definition: InstrTypes.h:1161