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