================ @@ -4181,6 +4185,127 @@ class FunctionNoProtoType : public FunctionType, public llvm::FoldingSetNode { } }; +class FunctionEffect; +class FunctionEffectSet; + +// It is the user's responsibility to keep this in set form: elements are +// ordered and unique. +// We could hide the mutating methods which are capable of breaking the +// invariant, but they're needed and safe when used with STL set algorithms. +class MutableFunctionEffectSet : public SmallVector<const FunctionEffect *, 4> { +public: + using SmallVector::insert; + using SmallVector::SmallVector; + + /// Maintains order/uniquenesss. + void insert(const FunctionEffect *effect); + + MutableFunctionEffectSet &operator|=(FunctionEffectSet rhs); +}; + +class FunctionEffectSet { +public: + // These sets will tend to be very small (1 element), so represent them as + // sorted vectors, which are compatible with the STL set algorithms. Using an + // array or vector also means the elements are contiguous, keeping iterators + // simple. + +private: + // 'Uniqued' refers to the set itself being uniqued. Storage is allocated + // separately. Use ArrayRef for its iterators. Subclass so as to be able to + // compare (it seems ArrayRef would silently convert itself to a vector for + // comparison?!). + class UniquedAndSortedFX : public llvm::ArrayRef<const FunctionEffect *> { + public: + using Base = llvm::ArrayRef<const FunctionEffect *>; + + UniquedAndSortedFX(Base Array) : Base(Array) {} + UniquedAndSortedFX(const FunctionEffect **Ptr, size_t Len) + : Base(Ptr, Len) {} + + bool operator<(const UniquedAndSortedFX &rhs) const; + }; + + // Could have used a TinyPtrVector if it were unique-able. + // Empty set has a null Impl. + llvm::PointerUnion<const FunctionEffect *, const UniquedAndSortedFX *> Impl; + + explicit FunctionEffectSet(const FunctionEffect *Single) : Impl(Single) {} + explicit FunctionEffectSet(const UniquedAndSortedFX *Multi) : Impl(Multi) {} + +public: + using Differences = + SmallVector<std::pair<const FunctionEffect *, bool /*added*/>>; ---------------- shafik wrote:
This is consistent with [bugprone-argument-comment](https://clang.llvm.org/extra/clang-tidy/checks/bugprone/argument-comment.html) which we use. I don't think it catches this case but consistency is nice. https://github.com/llvm/llvm-project/pull/84983 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits