1*b9c77542SJohannes Doerfert //===- Assumptions.cpp ------ Collection of helpers for assumptions -------===//
2*b9c77542SJohannes Doerfert //
3*b9c77542SJohannes Doerfert // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*b9c77542SJohannes Doerfert // See https://llvm.org/LICENSE.txt for license information.
5*b9c77542SJohannes Doerfert // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*b9c77542SJohannes Doerfert //
7*b9c77542SJohannes Doerfert //===----------------------------------------------------------------------===//
8*b9c77542SJohannes Doerfert //
9*b9c77542SJohannes Doerfert //===----------------------------------------------------------------------===//
10*b9c77542SJohannes Doerfert 
11*b9c77542SJohannes Doerfert #include "llvm/IR/Assumptions.h"
12*b9c77542SJohannes Doerfert #include "llvm/IR/Attributes.h"
13*b9c77542SJohannes Doerfert #include "llvm/IR/Function.h"
14*b9c77542SJohannes Doerfert 
15*b9c77542SJohannes Doerfert using namespace llvm;
16*b9c77542SJohannes Doerfert 
17*b9c77542SJohannes Doerfert bool llvm::hasAssumption(Function &F,
18*b9c77542SJohannes Doerfert                          const KnownAssumptionString &AssumptionStr) {
19*b9c77542SJohannes Doerfert   const Attribute &A = F.getFnAttribute(AssumptionAttrKey);
20*b9c77542SJohannes Doerfert   if (!A.isValid())
21*b9c77542SJohannes Doerfert     return false;
22*b9c77542SJohannes Doerfert   assert(A.isStringAttribute() && "Expected a string attribute!");
23*b9c77542SJohannes Doerfert 
24*b9c77542SJohannes Doerfert   SmallVector<StringRef, 8> Strings;
25*b9c77542SJohannes Doerfert   A.getValueAsString().split(Strings, ",");
26*b9c77542SJohannes Doerfert 
27*b9c77542SJohannes Doerfert   return llvm::any_of(Strings, [=](StringRef Assumption) {
28*b9c77542SJohannes Doerfert     return Assumption == AssumptionStr;
29*b9c77542SJohannes Doerfert   });
30*b9c77542SJohannes Doerfert }
31*b9c77542SJohannes Doerfert 
32*b9c77542SJohannes Doerfert StringSet<> llvm::KnownAssumptionStrings({
33*b9c77542SJohannes Doerfert     "omp_no_openmp",          // OpenMP 5.1
34*b9c77542SJohannes Doerfert     "omp_no_openmp_routines", // OpenMP 5.1
35*b9c77542SJohannes Doerfert     "omp_no_parallelism",     // OpenMP 5.1
36*b9c77542SJohannes Doerfert });
37