[llvm] [IR][Attribute] Add support for intersecting AttributeLists; NFC (PR #109719)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 26 12:49:26 PDT 2024


================
@@ -903,6 +956,112 @@ AttributeSet AttributeSet::removeAttributes(LLVMContext &C,
   return get(C, B);
 }
 
+std::optional<AttributeSet>
+AttributeSet::intersectWith(LLVMContext &C, AttributeSet Other) const {
+  if (*this == Other)
+    return *this;
+
+  AttrBuilder Intersected(C);
+  // Iterate over both attr sets at once.
+  auto ItBegin0 = begin();
+  auto ItEnd0 = end();
+  auto ItBegin1 = Other.begin();
+  auto ItEnd1 = Other.end();
+
+  while (ItBegin0 != ItEnd0 || ItBegin1 != ItEnd1) {
+    std::optional<Attribute> Attr0, Attr1;
----------------
nikic wrote:

`std::optional` here is kind of redundant, because Attribute is its own optional (isValid). Note that AttributeSet itself cannot contain invalid attributes.

https://github.com/llvm/llvm-project/pull/109719


More information about the llvm-commits mailing list