[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:27 PDT 2024
================
@@ -1614,6 +1773,33 @@ AttributeList AttributeList::addAllocSizeParamAttr(
return addParamAttributes(C, Index, B);
}
+std::optional<AttributeList>
+AttributeList::intersectAttributes(LLVMContext &C, AttributeList Other) const {
+ // Trivial case, the two lists are equal.
+ if (*this == Other)
+ return *this;
+
+ // At least for now, only intersect lists with same number of params.
+ if (getNumAttrSets() != Other.getNumAttrSets())
+ return std::nullopt;
+
+ SmallVector<std::pair<unsigned, AttributeSet>> IntersectedAttrs;
+ // AttributeList IntersectedAttrs{};
+ for (unsigned Idx : indexes()) {
+ auto IntersectedAS =
+ getAttributes(Idx).intersectWith(C, Other.getAttributes(Idx));
+ // If any index fails to intersect, fail.
+ if (!IntersectedAS)
+ return std::nullopt;
+ if (!IntersectedAS->hasAttributes())
+ continue;
+ IntersectedAttrs.push_back(std::make_pair(Idx, *IntersectedAS));
+ }
+
+ llvm::sort(IntersectedAttrs, llvm::less_first());
----------------
nikic wrote:
I don't think this is necessary? The indexes() should already be sorted, right?
https://github.com/llvm/llvm-project/pull/109719
More information about the llvm-commits
mailing list