Back to home page

EIC code displayed by LXR

 
 

    


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

0001 //===- llvm/AttributeMask.h - Mask for Attributes ---------------*- 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 /// \file
0010 // This file declares the AttributeMask class.
0011 //
0012 //===----------------------------------------------------------------------===//
0013 
0014 #ifndef LLVM_IR_ATTRIBUTEMASK_H
0015 #define LLVM_IR_ATTRIBUTEMASK_H
0016 
0017 #include "llvm/ADT/SmallString.h"
0018 #include "llvm/IR/Attributes.h"
0019 #include <bitset>
0020 #include <cassert>
0021 #include <set>
0022 
0023 namespace llvm {
0024 
0025 //===----------------------------------------------------------------------===//
0026 /// \class
0027 /// This class stores enough information to efficiently remove some attributes
0028 /// from an existing AttrBuilder, AttributeSet or AttributeList.
0029 class AttributeMask {
0030   std::bitset<Attribute::EndAttrKinds> Attrs;
0031   std::set<SmallString<32>, std::less<>> TargetDepAttrs;
0032 
0033 public:
0034   AttributeMask() = default;
0035   AttributeMask(const AttributeMask &) = delete;
0036   AttributeMask(AttributeMask &&) = default;
0037 
0038   AttributeMask(AttributeSet AS) {
0039     for (Attribute A : AS)
0040       addAttribute(A);
0041   }
0042 
0043   /// Add an attribute to the mask.
0044   AttributeMask &addAttribute(Attribute::AttrKind Val) {
0045     assert((unsigned)Val < Attribute::EndAttrKinds &&
0046            "Attribute out of range!");
0047     Attrs[Val] = true;
0048     return *this;
0049   }
0050 
0051   /// Add the Attribute object to the builder.
0052   AttributeMask &addAttribute(Attribute A) {
0053     if (A.isStringAttribute())
0054       addAttribute(A.getKindAsString());
0055     else
0056       addAttribute(A.getKindAsEnum());
0057     return *this;
0058   }
0059 
0060   /// Add the target-dependent attribute to the builder.
0061   AttributeMask &addAttribute(StringRef A) {
0062     TargetDepAttrs.insert(A);
0063     return *this;
0064   }
0065 
0066   /// Return true if the builder has the specified attribute.
0067   bool contains(Attribute::AttrKind A) const {
0068     assert((unsigned)A < Attribute::EndAttrKinds && "Attribute out of range!");
0069     return Attrs[A];
0070   }
0071 
0072   /// Return true if the builder has the specified target-dependent
0073   /// attribute.
0074   bool contains(StringRef A) const { return TargetDepAttrs.count(A); }
0075 
0076   /// Return true if the mask contains the specified attribute.
0077   bool contains(Attribute A) const {
0078     if (A.isStringAttribute())
0079       return contains(A.getKindAsString());
0080     return contains(A.getKindAsEnum());
0081   }
0082 };
0083 
0084 } // end namespace llvm
0085 
0086 #endif // LLVM_IR_ATTRIBUTEMASK_H