Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:43:56

0001 //===--- Assumptions.h - Assumption handling and organization ---*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 //
0009 // String assumptions that are known to optimization passes should be placed in
0010 // the KnownAssumptionStrings set. This can be done in various ways, i.a.,
0011 // via a static KnownAssumptionString object.
0012 //
0013 //===----------------------------------------------------------------------===//
0014 
0015 #ifndef LLVM_IR_ASSUMPTIONS_H
0016 #define LLVM_IR_ASSUMPTIONS_H
0017 
0018 #include "llvm/ADT/DenseSet.h"
0019 #include "llvm/ADT/StringRef.h"
0020 #include "llvm/ADT/StringSet.h"
0021 
0022 namespace llvm {
0023 
0024 class Function;
0025 class CallBase;
0026 
0027 /// The key we use for assumption attributes.
0028 constexpr StringRef AssumptionAttrKey = "llvm.assume";
0029 
0030 /// A set of known assumption strings that are accepted without warning and
0031 /// which can be recommended as typo correction.
0032 extern StringSet<> KnownAssumptionStrings;
0033 
0034 /// Helper that allows to insert a new assumption string in the known assumption
0035 /// set by creating a (static) object.
0036 struct KnownAssumptionString {
0037   KnownAssumptionString(const char *AssumptionStr)
0038       : AssumptionStr(AssumptionStr) {
0039     KnownAssumptionStrings.insert(AssumptionStr);
0040   }
0041   KnownAssumptionString(StringRef AssumptionStr)
0042       : AssumptionStr(AssumptionStr) {
0043     KnownAssumptionStrings.insert(AssumptionStr);
0044   }
0045   operator StringRef() const { return AssumptionStr; }
0046 
0047 private:
0048   StringRef AssumptionStr;
0049 };
0050 
0051 /// Return true if \p F has the assumption \p AssumptionStr attached.
0052 bool hasAssumption(const Function &F,
0053                    const KnownAssumptionString &AssumptionStr);
0054 
0055 /// Return true if \p CB or the callee has the assumption \p AssumptionStr
0056 /// attached.
0057 bool hasAssumption(const CallBase &CB,
0058                    const KnownAssumptionString &AssumptionStr);
0059 
0060 /// Return the set of all assumptions for the function \p F.
0061 DenseSet<StringRef> getAssumptions(const Function &F);
0062 
0063 /// Return the set of all assumptions for the call \p CB.
0064 DenseSet<StringRef> getAssumptions(const CallBase &CB);
0065 
0066 /// Appends the set of assumptions \p Assumptions to \F.
0067 bool addAssumptions(Function &F, const DenseSet<StringRef> &Assumptions);
0068 
0069 /// Appends the set of assumptions \p Assumptions to \CB.
0070 bool addAssumptions(CallBase &CB, const DenseSet<StringRef> &Assumptions);
0071 
0072 } // namespace llvm
0073 
0074 #endif