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 
15 using namespace llvm;
16 
17 bool llvm::hasAssumption(Function &F,
18                          const KnownAssumptionString &AssumptionStr) {
19   const Attribute &A = F.getFnAttribute(AssumptionAttrKey);
20   if (!A.isValid())
21     return false;
22   assert(A.isStringAttribute() && "Expected a string attribute!");
23 
24   SmallVector<StringRef, 8> Strings;
25   A.getValueAsString().split(Strings, ",");
26 
27   return llvm::any_of(Strings, [=](StringRef Assumption) {
28     return Assumption == AssumptionStr;
29   });
30 }
31 
32 StringSet<> llvm::KnownAssumptionStrings({
33     "omp_no_openmp",          // OpenMP 5.1
34     "omp_no_openmp_routines", // OpenMP 5.1
35     "omp_no_parallelism",     // OpenMP 5.1
36     "ompx_spmd_amenable",     // OpenMPOpt extension
37 });
38