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