//===- llvm/Attributes.h - Container for Attributes -------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // /// \file /// This file contains the simple types necessary to represent the /// attributes associated with functions and their calls. // //===----------------------------------------------------------------------===// #ifndef LLVM_IR_ATTRIBUTES_H #define LLVM_IR_ATTRIBUTES_H #include "llvm-c/Types.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/BitmaskEnum.h" #include "llvm/ADT/StringRef.h" #include "llvm/Config/llvm-config.h" #include "llvm/Support/Alignment.h" #include "llvm/Support/CodeGen.h" #include "llvm/Support/ModRef.h" #include "llvm/Support/PointerLikeTypeTraits.h" #include <cassert> #include <cstdint> #include <optional> #include <string> #include <utility> namespace llvm { class AttrBuilder; class AttributeMask; class AttributeImpl; class AttributeListImpl; class AttributeSetNode; class ConstantRange; class ConstantRangeList; class FoldingSetNodeID; class Function; class LLVMContext; class Type; class raw_ostream; enum FPClassTest : unsigned; enum class AllocFnKind : uint64_t { … }; //===----------------------------------------------------------------------===// /// \class /// Functions, function parameters, and return types can have attributes /// to indicate how they should be treated by optimizations and code /// generation. This class represents one of those attributes. It's light-weight /// and should be passed around by-value. class Attribute { … }; // Specialized opaque value conversions. inline LLVMAttributeRef wrap(Attribute Attr) { … } // Specialized opaque value conversions. inline Attribute unwrap(LLVMAttributeRef Attr) { … } //===----------------------------------------------------------------------===// /// \class /// This class holds the attributes for a particular argument, parameter, /// function, or return value. It is an immutable value type that is cheap to /// copy. Adding and removing enum attributes is intended to be fast, but adding /// and removing string or integer attributes involves a FoldingSet lookup. class AttributeSet { … }; //===----------------------------------------------------------------------===// /// \class /// Provide DenseMapInfo for AttributeSet. template <> struct DenseMapInfo<AttributeSet, void> { … }; //===----------------------------------------------------------------------===// /// \class /// This class holds the attributes for a function, its return value, and /// its parameters. You access the attributes for each of them via an index into /// the AttributeList object. The function attributes are at index /// `AttributeList::FunctionIndex', the return value is at index /// `AttributeList::ReturnIndex', and the attributes for the parameters start at /// index `AttributeList::FirstArgIndex'. class AttributeList { … }; //===----------------------------------------------------------------------===// /// \class /// Provide DenseMapInfo for AttributeList. template <> struct DenseMapInfo<AttributeList, void> { … }; //===----------------------------------------------------------------------===// /// \class /// This class is used in conjunction with the Attribute::get method to /// create an Attribute object. The object itself is uniquified. The Builder's /// value, however, is not. So this can be used as a quick way to test for /// equality, presence of attributes, etc. class AttrBuilder { … }; namespace AttributeFuncs { enum AttributeSafetyKind : uint8_t { … }; /// Returns true if this is a type legal for the 'nofpclass' attribute. This /// follows the same type rules as FPMathOperator. bool isNoFPClassCompatibleType(Type *Ty); /// Which attributes cannot be applied to a type. The argument \p ASK indicates, /// if only attributes that are known to be safely droppable are contained in /// the mask; only attributes that might be unsafe to drop (e.g., ABI-related /// attributes) are in the mask; or both. AttributeMask typeIncompatible(Type *Ty, AttributeSafetyKind ASK = ASK_ALL); /// Get param/return attributes which imply immediate undefined behavior if an /// invalid value is passed. For example, this includes noundef (where undef /// implies UB), but not nonnull (where null implies poison). It also does not /// include attributes like nocapture, which constrain the function /// implementation rather than the passed value. AttributeMask getUBImplyingAttributes(); /// \returns Return true if the two functions have compatible target-independent /// attributes for inlining purposes. bool areInlineCompatible(const Function &Caller, const Function &Callee); /// Checks if there are any incompatible function attributes between /// \p A and \p B. /// /// \param [in] A - The first function to be compared with. /// \param [in] B - The second function to be compared with. /// \returns true if the functions have compatible attributes. bool areOutlineCompatible(const Function &A, const Function &B); /// Merge caller's and callee's attributes. void mergeAttributesForInlining(Function &Caller, const Function &Callee); /// Merges the functions attributes from \p ToMerge into function \p Base. /// /// \param [in,out] Base - The function being merged into. /// \param [in] ToMerge - The function to merge attributes from. void mergeAttributesForOutlining(Function &Base, const Function &ToMerge); /// Update min-legal-vector-width if it is in Attribute and less than Width. void updateMinLegalVectorWidthAttr(Function &Fn, uint64_t Width); } // end namespace AttributeFuncs } // end namespace llvm #endif // LLVM_IR_ATTRIBUTES_H