diff options
author | shadchin <shadchin@yandex-team.ru> | 2022-02-10 16:44:30 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:44:30 +0300 |
commit | 2598ef1d0aee359b4b6d5fdd1758916d5907d04f (patch) | |
tree | 012bb94d777798f1f56ac1cec429509766d05181 /contrib/libs/llvm12/include/llvm/ADT | |
parent | 6751af0b0c1b952fede40b19b71da8025b5d8bcf (diff) | |
download | ydb-2598ef1d0aee359b4b6d5fdd1758916d5907d04f.tar.gz |
Restoring authorship annotation for <shadchin@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'contrib/libs/llvm12/include/llvm/ADT')
30 files changed, 1273 insertions, 1273 deletions
diff --git a/contrib/libs/llvm12/include/llvm/ADT/APFixedPoint.h b/contrib/libs/llvm12/include/llvm/ADT/APFixedPoint.h index baa8b34993..ae31489b2a 100644 --- a/contrib/libs/llvm12/include/llvm/ADT/APFixedPoint.h +++ b/contrib/libs/llvm12/include/llvm/ADT/APFixedPoint.h @@ -1,248 +1,248 @@ -#pragma once - -#ifdef __GNUC__ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wunused-parameter" -#endif - -//===- APFixedPoint.h - Fixed point constant handling -----------*- 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 -/// Defines the fixed point number interface. -/// This is a class for abstracting various operations performed on fixed point -/// types. -// -//===----------------------------------------------------------------------===// - -#ifndef LLVM_ADT_APFIXEDPOINT_H -#define LLVM_ADT_APFIXEDPOINT_H - -#include "llvm/ADT/APSInt.h" -#include "llvm/ADT/SmallString.h" -#include "llvm/Support/raw_ostream.h" - -namespace llvm { - -class APFloat; -struct fltSemantics; - -/// The fixed point semantics work similarly to fltSemantics. The width -/// specifies the whole bit width of the underlying scaled integer (with padding -/// if any). The scale represents the number of fractional bits in this type. -/// When HasUnsignedPadding is true and this type is unsigned, the first bit -/// in the value this represents is treated as padding. -class FixedPointSemantics { -public: - FixedPointSemantics(unsigned Width, unsigned Scale, bool IsSigned, - bool IsSaturated, bool HasUnsignedPadding) - : Width(Width), Scale(Scale), IsSigned(IsSigned), - IsSaturated(IsSaturated), HasUnsignedPadding(HasUnsignedPadding) { - assert(Width >= Scale && "Not enough room for the scale"); - assert(!(IsSigned && HasUnsignedPadding) && - "Cannot have unsigned padding on a signed type."); - } - - unsigned getWidth() const { return Width; } - unsigned getScale() const { return Scale; } - bool isSigned() const { return IsSigned; } - bool isSaturated() const { return IsSaturated; } - bool hasUnsignedPadding() const { return HasUnsignedPadding; } - - void setSaturated(bool Saturated) { IsSaturated = Saturated; } - - /// Return the number of integral bits represented by these semantics. These - /// are separate from the fractional bits and do not include the sign or - /// padding bit. - unsigned getIntegralBits() const { - if (IsSigned || (!IsSigned && HasUnsignedPadding)) - return Width - Scale - 1; - else - return Width - Scale; - } - - /// Return the FixedPointSemantics that allows for calculating the full - /// precision semantic that can precisely represent the precision and ranges - /// of both input values. This does not compute the resulting semantics for a - /// given binary operation. - FixedPointSemantics - getCommonSemantics(const FixedPointSemantics &Other) const; - - /// Returns true if this fixed-point semantic with its value bits interpreted - /// as an integer can fit in the given floating point semantic without - /// overflowing to infinity. - /// For example, a signed 8-bit fixed-point semantic has a maximum and - /// minimum integer representation of 127 and -128, respectively. If both of - /// these values can be represented (possibly inexactly) in the floating - /// point semantic without overflowing, this returns true. - bool fitsInFloatSemantics(const fltSemantics &FloatSema) const; - - /// Return the FixedPointSemantics for an integer type. - static FixedPointSemantics GetIntegerSemantics(unsigned Width, - bool IsSigned) { - return FixedPointSemantics(Width, /*Scale=*/0, IsSigned, - /*IsSaturated=*/false, - /*HasUnsignedPadding=*/false); - } - -private: - unsigned Width : 16; - unsigned Scale : 13; - unsigned IsSigned : 1; - unsigned IsSaturated : 1; - unsigned HasUnsignedPadding : 1; -}; - -/// The APFixedPoint class works similarly to APInt/APSInt in that it is a -/// functional replacement for a scaled integer. It is meant to replicate the -/// fixed point types proposed in ISO/IEC JTC1 SC22 WG14 N1169. The class carries -/// info about the fixed point type's width, sign, scale, and saturation, and -/// provides different operations that would normally be performed on fixed point -/// types. -class APFixedPoint { -public: - APFixedPoint(const APInt &Val, const FixedPointSemantics &Sema) - : Val(Val, !Sema.isSigned()), Sema(Sema) { - assert(Val.getBitWidth() == Sema.getWidth() && - "The value should have a bit width that matches the Sema width"); - } - - APFixedPoint(uint64_t Val, const FixedPointSemantics &Sema) - : APFixedPoint(APInt(Sema.getWidth(), Val, Sema.isSigned()), Sema) {} - - // Zero initialization. - APFixedPoint(const FixedPointSemantics &Sema) : APFixedPoint(0, Sema) {} - - APSInt getValue() const { return APSInt(Val, !Sema.isSigned()); } - inline unsigned getWidth() const { return Sema.getWidth(); } - inline unsigned getScale() const { return Sema.getScale(); } - inline bool isSaturated() const { return Sema.isSaturated(); } - inline bool isSigned() const { return Sema.isSigned(); } - inline bool hasPadding() const { return Sema.hasUnsignedPadding(); } - FixedPointSemantics getSemantics() const { return Sema; } - - bool getBoolValue() const { return Val.getBoolValue(); } - - // Convert this number to match the semantics provided. If the overflow - // parameter is provided, set this value to true or false to indicate if this - // operation results in an overflow. - APFixedPoint convert(const FixedPointSemantics &DstSema, - bool *Overflow = nullptr) const; - - // Perform binary operations on a fixed point type. The resulting fixed point - // value will be in the common, full precision semantics that can represent - // the precision and ranges of both input values. See convert() for an - // explanation of the Overflow parameter. - APFixedPoint add(const APFixedPoint &Other, bool *Overflow = nullptr) const; - APFixedPoint sub(const APFixedPoint &Other, bool *Overflow = nullptr) const; - APFixedPoint mul(const APFixedPoint &Other, bool *Overflow = nullptr) const; - APFixedPoint div(const APFixedPoint &Other, bool *Overflow = nullptr) const; - - // Perform shift operations on a fixed point type. Unlike the other binary - // operations, the resulting fixed point value will be in the original - // semantic. - APFixedPoint shl(unsigned Amt, bool *Overflow = nullptr) const; - APFixedPoint shr(unsigned Amt, bool *Overflow = nullptr) const { - // Right shift cannot overflow. - if (Overflow) - *Overflow = false; - return APFixedPoint(Val >> Amt, Sema); - } - - /// Perform a unary negation (-X) on this fixed point type, taking into - /// account saturation if applicable. - APFixedPoint negate(bool *Overflow = nullptr) const; - - /// Return the integral part of this fixed point number, rounded towards - /// zero. (-2.5k -> -2) - APSInt getIntPart() const { - if (Val < 0 && Val != -Val) // Cover the case when we have the min val - return -(-Val >> getScale()); - else - return Val >> getScale(); - } - - /// Return the integral part of this fixed point number, rounded towards - /// zero. The value is stored into an APSInt with the provided width and sign. - /// If the overflow parameter is provided, and the integral value is not able - /// to be fully stored in the provided width and sign, the overflow parameter - /// is set to true. - APSInt convertToInt(unsigned DstWidth, bool DstSign, - bool *Overflow = nullptr) const; - - /// Convert this fixed point number to a floating point value with the - /// provided semantics. - APFloat convertToFloat(const fltSemantics &FloatSema) const; - - void toString(SmallVectorImpl<char> &Str) const; - std::string toString() const { - SmallString<40> S; - toString(S); - return std::string(S.str()); - } - - // If LHS > RHS, return 1. If LHS == RHS, return 0. If LHS < RHS, return -1. - int compare(const APFixedPoint &Other) const; - bool operator==(const APFixedPoint &Other) const { - return compare(Other) == 0; - } - bool operator!=(const APFixedPoint &Other) const { - return compare(Other) != 0; - } - bool operator>(const APFixedPoint &Other) const { return compare(Other) > 0; } - bool operator<(const APFixedPoint &Other) const { return compare(Other) < 0; } - bool operator>=(const APFixedPoint &Other) const { - return compare(Other) >= 0; - } - bool operator<=(const APFixedPoint &Other) const { - return compare(Other) <= 0; - } - - static APFixedPoint getMax(const FixedPointSemantics &Sema); - static APFixedPoint getMin(const FixedPointSemantics &Sema); - - /// Given a floating point semantic, return the next floating point semantic - /// with a larger exponent and larger or equal mantissa. - static const fltSemantics *promoteFloatSemantics(const fltSemantics *S); - - /// Create an APFixedPoint with a value equal to that of the provided integer, - /// and in the same semantics as the provided target semantics. If the value - /// is not able to fit in the specified fixed point semantics, and the - /// overflow parameter is provided, it is set to true. - static APFixedPoint getFromIntValue(const APSInt &Value, - const FixedPointSemantics &DstFXSema, - bool *Overflow = nullptr); - - /// Create an APFixedPoint with a value equal to that of the provided - /// floating point value, in the provided target semantics. If the value is - /// not able to fit in the specified fixed point semantics and the overflow - /// parameter is specified, it is set to true. - /// For NaN, the Overflow flag is always set. For +inf and -inf, if the - /// semantic is saturating, the value saturates. Otherwise, the Overflow flag - /// is set. - static APFixedPoint getFromFloatValue(const APFloat &Value, - const FixedPointSemantics &DstFXSema, - bool *Overflow = nullptr); - -private: - APSInt Val; - FixedPointSemantics Sema; -}; - -inline raw_ostream &operator<<(raw_ostream &OS, const APFixedPoint &FX) { - OS << FX.toString(); - return OS; -} - -} // namespace llvm - -#endif - -#ifdef __GNUC__ -#pragma GCC diagnostic pop -#endif +#pragma once + +#ifdef __GNUC__ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wunused-parameter" +#endif + +//===- APFixedPoint.h - Fixed point constant handling -----------*- 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 +/// Defines the fixed point number interface. +/// This is a class for abstracting various operations performed on fixed point +/// types. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_ADT_APFIXEDPOINT_H +#define LLVM_ADT_APFIXEDPOINT_H + +#include "llvm/ADT/APSInt.h" +#include "llvm/ADT/SmallString.h" +#include "llvm/Support/raw_ostream.h" + +namespace llvm { + +class APFloat; +struct fltSemantics; + +/// The fixed point semantics work similarly to fltSemantics. The width +/// specifies the whole bit width of the underlying scaled integer (with padding +/// if any). The scale represents the number of fractional bits in this type. +/// When HasUnsignedPadding is true and this type is unsigned, the first bit +/// in the value this represents is treated as padding. +class FixedPointSemantics { +public: + FixedPointSemantics(unsigned Width, unsigned Scale, bool IsSigned, + bool IsSaturated, bool HasUnsignedPadding) + : Width(Width), Scale(Scale), IsSigned(IsSigned), + IsSaturated(IsSaturated), HasUnsignedPadding(HasUnsignedPadding) { + assert(Width >= Scale && "Not enough room for the scale"); + assert(!(IsSigned && HasUnsignedPadding) && + "Cannot have unsigned padding on a signed type."); + } + + unsigned getWidth() const { return Width; } + unsigned getScale() const { return Scale; } + bool isSigned() const { return IsSigned; } + bool isSaturated() const { return IsSaturated; } + bool hasUnsignedPadding() const { return HasUnsignedPadding; } + + void setSaturated(bool Saturated) { IsSaturated = Saturated; } + + /// Return the number of integral bits represented by these semantics. These + /// are separate from the fractional bits and do not include the sign or + /// padding bit. + unsigned getIntegralBits() const { + if (IsSigned || (!IsSigned && HasUnsignedPadding)) + return Width - Scale - 1; + else + return Width - Scale; + } + + /// Return the FixedPointSemantics that allows for calculating the full + /// precision semantic that can precisely represent the precision and ranges + /// of both input values. This does not compute the resulting semantics for a + /// given binary operation. + FixedPointSemantics + getCommonSemantics(const FixedPointSemantics &Other) const; + + /// Returns true if this fixed-point semantic with its value bits interpreted + /// as an integer can fit in the given floating point semantic without + /// overflowing to infinity. + /// For example, a signed 8-bit fixed-point semantic has a maximum and + /// minimum integer representation of 127 and -128, respectively. If both of + /// these values can be represented (possibly inexactly) in the floating + /// point semantic without overflowing, this returns true. + bool fitsInFloatSemantics(const fltSemantics &FloatSema) const; + + /// Return the FixedPointSemantics for an integer type. + static FixedPointSemantics GetIntegerSemantics(unsigned Width, + bool IsSigned) { + return FixedPointSemantics(Width, /*Scale=*/0, IsSigned, + /*IsSaturated=*/false, + /*HasUnsignedPadding=*/false); + } + +private: + unsigned Width : 16; + unsigned Scale : 13; + unsigned IsSigned : 1; + unsigned IsSaturated : 1; + unsigned HasUnsignedPadding : 1; +}; + +/// The APFixedPoint class works similarly to APInt/APSInt in that it is a +/// functional replacement for a scaled integer. It is meant to replicate the +/// fixed point types proposed in ISO/IEC JTC1 SC22 WG14 N1169. The class carries +/// info about the fixed point type's width, sign, scale, and saturation, and +/// provides different operations that would normally be performed on fixed point +/// types. +class APFixedPoint { +public: + APFixedPoint(const APInt &Val, const FixedPointSemantics &Sema) + : Val(Val, !Sema.isSigned()), Sema(Sema) { + assert(Val.getBitWidth() == Sema.getWidth() && + "The value should have a bit width that matches the Sema width"); + } + + APFixedPoint(uint64_t Val, const FixedPointSemantics &Sema) + : APFixedPoint(APInt(Sema.getWidth(), Val, Sema.isSigned()), Sema) {} + + // Zero initialization. + APFixedPoint(const FixedPointSemantics &Sema) : APFixedPoint(0, Sema) {} + + APSInt getValue() const { return APSInt(Val, !Sema.isSigned()); } + inline unsigned getWidth() const { return Sema.getWidth(); } + inline unsigned getScale() const { return Sema.getScale(); } + inline bool isSaturated() const { return Sema.isSaturated(); } + inline bool isSigned() const { return Sema.isSigned(); } + inline bool hasPadding() const { return Sema.hasUnsignedPadding(); } + FixedPointSemantics getSemantics() const { return Sema; } + + bool getBoolValue() const { return Val.getBoolValue(); } + + // Convert this number to match the semantics provided. If the overflow + // parameter is provided, set this value to true or false to indicate if this + // operation results in an overflow. + APFixedPoint convert(const FixedPointSemantics &DstSema, + bool *Overflow = nullptr) const; + + // Perform binary operations on a fixed point type. The resulting fixed point + // value will be in the common, full precision semantics that can represent + // the precision and ranges of both input values. See convert() for an + // explanation of the Overflow parameter. + APFixedPoint add(const APFixedPoint &Other, bool *Overflow = nullptr) const; + APFixedPoint sub(const APFixedPoint &Other, bool *Overflow = nullptr) const; + APFixedPoint mul(const APFixedPoint &Other, bool *Overflow = nullptr) const; + APFixedPoint div(const APFixedPoint &Other, bool *Overflow = nullptr) const; + + // Perform shift operations on a fixed point type. Unlike the other binary + // operations, the resulting fixed point value will be in the original + // semantic. + APFixedPoint shl(unsigned Amt, bool *Overflow = nullptr) const; + APFixedPoint shr(unsigned Amt, bool *Overflow = nullptr) const { + // Right shift cannot overflow. + if (Overflow) + *Overflow = false; + return APFixedPoint(Val >> Amt, Sema); + } + + /// Perform a unary negation (-X) on this fixed point type, taking into + /// account saturation if applicable. + APFixedPoint negate(bool *Overflow = nullptr) const; + + /// Return the integral part of this fixed point number, rounded towards + /// zero. (-2.5k -> -2) + APSInt getIntPart() const { + if (Val < 0 && Val != -Val) // Cover the case when we have the min val + return -(-Val >> getScale()); + else + return Val >> getScale(); + } + + /// Return the integral part of this fixed point number, rounded towards + /// zero. The value is stored into an APSInt with the provided width and sign. + /// If the overflow parameter is provided, and the integral value is not able + /// to be fully stored in the provided width and sign, the overflow parameter + /// is set to true. + APSInt convertToInt(unsigned DstWidth, bool DstSign, + bool *Overflow = nullptr) const; + + /// Convert this fixed point number to a floating point value with the + /// provided semantics. + APFloat convertToFloat(const fltSemantics &FloatSema) const; + + void toString(SmallVectorImpl<char> &Str) const; + std::string toString() const { + SmallString<40> S; + toString(S); + return std::string(S.str()); + } + + // If LHS > RHS, return 1. If LHS == RHS, return 0. If LHS < RHS, return -1. + int compare(const APFixedPoint &Other) const; + bool operator==(const APFixedPoint &Other) const { + return compare(Other) == 0; + } + bool operator!=(const APFixedPoint &Other) const { + return compare(Other) != 0; + } + bool operator>(const APFixedPoint &Other) const { return compare(Other) > 0; } + bool operator<(const APFixedPoint &Other) const { return compare(Other) < 0; } + bool operator>=(const APFixedPoint &Other) const { + return compare(Other) >= 0; + } + bool operator<=(const APFixedPoint &Other) const { + return compare(Other) <= 0; + } + + static APFixedPoint getMax(const FixedPointSemantics &Sema); + static APFixedPoint getMin(const FixedPointSemantics &Sema); + + /// Given a floating point semantic, return the next floating point semantic + /// with a larger exponent and larger or equal mantissa. + static const fltSemantics *promoteFloatSemantics(const fltSemantics *S); + + /// Create an APFixedPoint with a value equal to that of the provided integer, + /// and in the same semantics as the provided target semantics. If the value + /// is not able to fit in the specified fixed point semantics, and the + /// overflow parameter is provided, it is set to true. + static APFixedPoint getFromIntValue(const APSInt &Value, + const FixedPointSemantics &DstFXSema, + bool *Overflow = nullptr); + + /// Create an APFixedPoint with a value equal to that of the provided + /// floating point value, in the provided target semantics. If the value is + /// not able to fit in the specified fixed point semantics and the overflow + /// parameter is specified, it is set to true. + /// For NaN, the Overflow flag is always set. For +inf and -inf, if the + /// semantic is saturating, the value saturates. Otherwise, the Overflow flag + /// is set. + static APFixedPoint getFromFloatValue(const APFloat &Value, + const FixedPointSemantics &DstFXSema, + bool *Overflow = nullptr); + +private: + APSInt Val; + FixedPointSemantics Sema; +}; + +inline raw_ostream &operator<<(raw_ostream &OS, const APFixedPoint &FX) { + OS << FX.toString(); + return OS; +} + +} // namespace llvm + +#endif + +#ifdef __GNUC__ +#pragma GCC diagnostic pop +#endif diff --git a/contrib/libs/llvm12/include/llvm/ADT/APFloat.h b/contrib/libs/llvm12/include/llvm/ADT/APFloat.h index 14f63fb8a1..2afb3070c3 100644 --- a/contrib/libs/llvm12/include/llvm/ADT/APFloat.h +++ b/contrib/libs/llvm12/include/llvm/ADT/APFloat.h @@ -256,7 +256,7 @@ public: /// \name Constructors /// @{ - IEEEFloat(const fltSemantics &); // Default construct to +0.0 + IEEEFloat(const fltSemantics &); // Default construct to +0.0 IEEEFloat(const fltSemantics &, integerPart); IEEEFloat(const fltSemantics &, uninitializedTag); IEEEFloat(const fltSemantics &, const APInt &); @@ -546,9 +546,9 @@ private: roundingMode) const; opStatus roundSignificandWithExponent(const integerPart *, unsigned int, int, roundingMode); - ExponentType exponentNaN() const; - ExponentType exponentInf() const; - ExponentType exponentZero() const; + ExponentType exponentNaN() const; + ExponentType exponentInf() const; + ExponentType exponentZero() const; /// @} diff --git a/contrib/libs/llvm12/include/llvm/ADT/APInt.h b/contrib/libs/llvm12/include/llvm/ADT/APInt.h index 8d378a25d1..2d8ff21c6e 100644 --- a/contrib/libs/llvm12/include/llvm/ADT/APInt.h +++ b/contrib/libs/llvm12/include/llvm/ADT/APInt.h @@ -38,7 +38,7 @@ class raw_ostream; template <typename T> class SmallVectorImpl; template <typename T> class ArrayRef; template <typename T> class Optional; -template <typename T> struct DenseMapInfo; +template <typename T> struct DenseMapInfo; class APInt; @@ -104,7 +104,7 @@ private: unsigned BitWidth; ///< The number of bits in this APInt. - friend struct DenseMapInfo<APInt>; + friend struct DenseMapInfo<APInt>; friend class APSInt; @@ -772,8 +772,8 @@ public: /// Move assignment operator. APInt &operator=(APInt &&that) { -#ifdef EXPENSIVE_CHECKS - // Some std::shuffle implementations still do self-assignment. +#ifdef EXPENSIVE_CHECKS + // Some std::shuffle implementations still do self-assignment. if (this == &that) return *this; #endif @@ -801,10 +801,10 @@ public: APInt &operator=(uint64_t RHS) { if (isSingleWord()) { U.VAL = RHS; - return clearUnusedBits(); + return clearUnusedBits(); } - U.pVal[0] = RHS; - memset(U.pVal + 1, 0, (getNumWords() - 1) * APINT_WORD_SIZE); + U.pVal[0] = RHS; + memset(U.pVal + 1, 0, (getNumWords() - 1) * APINT_WORD_SIZE); return *this; } @@ -861,9 +861,9 @@ public: APInt &operator|=(uint64_t RHS) { if (isSingleWord()) { U.VAL |= RHS; - return clearUnusedBits(); + return clearUnusedBits(); } - U.pVal[0] |= RHS; + U.pVal[0] |= RHS; return *this; } @@ -890,9 +890,9 @@ public: APInt &operator^=(uint64_t RHS) { if (isSingleWord()) { U.VAL ^= RHS; - return clearUnusedBits(); + return clearUnusedBits(); } - U.pVal[0] ^= RHS; + U.pVal[0] ^= RHS; return *this; } @@ -1410,12 +1410,12 @@ public: /// extended, truncated, or left alone to make it that width. APInt zextOrTrunc(unsigned width) const; - /// Truncate to width - /// - /// Make this APInt have the bit width given by \p width. The value is - /// truncated or left alone to make it that width. - APInt truncOrSelf(unsigned width) const; - + /// Truncate to width + /// + /// Make this APInt have the bit width given by \p width. The value is + /// truncated or left alone to make it that width. + APInt truncOrSelf(unsigned width) const; + /// Sign extend or truncate to width /// /// Make this APInt have the bit width given by \p width. The value is sign @@ -1460,14 +1460,14 @@ public: setBit(BitWidth - 1); } - /// Set a given bit to a given value. - void setBitVal(unsigned BitPosition, bool BitValue) { - if (BitValue) - setBit(BitPosition); - else - clearBit(BitPosition); - } - + /// Set a given bit to a given value. + void setBitVal(unsigned BitPosition, bool BitValue) { + if (BitValue) + setBit(BitPosition); + else + clearBit(BitPosition); + } + /// Set the bits from loBit (inclusive) to hiBit (exclusive) to 1. /// This function handles "wrap" case when \p loBit >= \p hiBit, and calls /// setBits when \p loBit < \p hiBit. @@ -1628,7 +1628,7 @@ public: /// returns the smallest bit width that will retain the negative value. For /// example, -1 can be written as 0b1 or 0xFFFFFFFFFF. 0b1 is shorter and so /// for -1, this function will always return 1. - unsigned getMinSignedBits() const { return BitWidth - getNumSignBits() + 1; } + unsigned getMinSignedBits() const { return BitWidth - getNumSignBits() + 1; } /// Get zero extended value /// diff --git a/contrib/libs/llvm12/include/llvm/ADT/APSInt.h b/contrib/libs/llvm12/include/llvm/ADT/APSInt.h index 0a07d2ec0c..e2f9ccf863 100644 --- a/contrib/libs/llvm12/include/llvm/ADT/APSInt.h +++ b/contrib/libs/llvm12/include/llvm/ADT/APSInt.h @@ -25,7 +25,7 @@ namespace llvm { -/// An arbitrary precision integer that knows its signedness. +/// An arbitrary precision integer that knows its signedness. class LLVM_NODISCARD APSInt : public APInt { bool IsUnsigned; @@ -33,7 +33,7 @@ public: /// Default constructor that creates an uninitialized APInt. explicit APSInt() : IsUnsigned(false) {} - /// Create an APSInt with the specified width, default to unsigned. + /// Create an APSInt with the specified width, default to unsigned. explicit APSInt(uint32_t BitWidth, bool isUnsigned = true) : APInt(BitWidth, 0), IsUnsigned(isUnsigned) {} @@ -85,11 +85,11 @@ public: void setIsUnsigned(bool Val) { IsUnsigned = Val; } void setIsSigned(bool Val) { IsUnsigned = !Val; } - /// Append this APSInt to the specified SmallString. + /// Append this APSInt to the specified SmallString. void toString(SmallVectorImpl<char> &Str, unsigned Radix = 10) const { APInt::toString(Str, Radix, isSigned()); } - /// Converts an APInt to a std::string. This is an inefficient + /// Converts an APInt to a std::string. This is an inefficient /// method; you should prefer passing in a SmallString instead. std::string toString(unsigned Radix) const { return APInt::toString(Radix, isSigned()); @@ -289,15 +289,15 @@ public: return APSInt(~static_cast<const APInt&>(*this), IsUnsigned); } - /// Return the APSInt representing the maximum integer value with the given - /// bit width and signedness. + /// Return the APSInt representing the maximum integer value with the given + /// bit width and signedness. static APSInt getMaxValue(uint32_t numBits, bool Unsigned) { return APSInt(Unsigned ? APInt::getMaxValue(numBits) : APInt::getSignedMaxValue(numBits), Unsigned); } - /// Return the APSInt representing the minimum integer value with the given - /// bit width and signedness. + /// Return the APSInt representing the minimum integer value with the given + /// bit width and signedness. static APSInt getMinValue(uint32_t numBits, bool Unsigned) { return APSInt(Unsigned ? APInt::getMinValue(numBits) : APInt::getSignedMinValue(numBits), Unsigned); @@ -338,8 +338,8 @@ public: static APSInt get(int64_t X) { return APSInt(APInt(64, X), false); } static APSInt getUnsigned(uint64_t X) { return APSInt(APInt(64, X), true); } - /// Used to insert APSInt objects, or objects that contain APSInt objects, - /// into FoldingSets. + /// Used to insert APSInt objects, or objects that contain APSInt objects, + /// into FoldingSets. void Profile(FoldingSetNodeID& ID) const; }; diff --git a/contrib/libs/llvm12/include/llvm/ADT/Any.h b/contrib/libs/llvm12/include/llvm/ADT/Any.h index adb8f22b95..66c6f25981 100644 --- a/contrib/libs/llvm12/include/llvm/ADT/Any.h +++ b/contrib/libs/llvm12/include/llvm/ADT/Any.h @@ -30,12 +30,12 @@ namespace llvm { -class LLVM_EXTERNAL_VISIBILITY Any { - - // The `Typeid<T>::Id` static data member below is a globally unique - // identifier for the type `T`. It is explicitly marked with default - // visibility so that when `-fvisibility=hidden` is used, the loader still - // merges duplicate definitions across DSO boundaries. +class LLVM_EXTERNAL_VISIBILITY Any { + + // The `Typeid<T>::Id` static data member below is a globally unique + // identifier for the type `T`. It is explicitly marked with default + // visibility so that when `-fvisibility=hidden` is used, the loader still + // merges duplicate definitions across DSO boundaries. template <typename T> struct TypeId { static const char Id; }; struct StorageBase { diff --git a/contrib/libs/llvm12/include/llvm/ADT/BitVector.h b/contrib/libs/llvm12/include/llvm/ADT/BitVector.h index c1806c6d23..69a00a99b6 100644 --- a/contrib/libs/llvm12/include/llvm/ADT/BitVector.h +++ b/contrib/libs/llvm12/include/llvm/ADT/BitVector.h @@ -210,10 +210,10 @@ public: return !any(); } - /// find_first_in - Returns the index of the first set / unset bit, - /// depending on \p Set, in the range [Begin, End). - /// Returns -1 if all bits in the range are unset / set. - int find_first_in(unsigned Begin, unsigned End, bool Set = true) const { + /// find_first_in - Returns the index of the first set / unset bit, + /// depending on \p Set, in the range [Begin, End). + /// Returns -1 if all bits in the range are unset / set. + int find_first_in(unsigned Begin, unsigned End, bool Set = true) const { assert(Begin <= End && End <= Size); if (Begin == End) return -1; @@ -222,14 +222,14 @@ public: unsigned LastWord = (End - 1) / BITWORD_SIZE; // Check subsequent words. - // The code below is based on search for the first _set_ bit. If - // we're searching for the first _unset_, we just take the - // complement of each word before we use it and apply - // the same method. + // The code below is based on search for the first _set_ bit. If + // we're searching for the first _unset_, we just take the + // complement of each word before we use it and apply + // the same method. for (unsigned i = FirstWord; i <= LastWord; ++i) { BitWord Copy = Bits[i]; - if (!Set) - Copy = ~Copy; + if (!Set) + Copy = ~Copy; if (i == FirstWord) { unsigned FirstBit = Begin % BITWORD_SIZE; @@ -280,7 +280,7 @@ public: /// find_first_unset_in - Returns the index of the first unset bit in the /// range [Begin, End). Returns -1 if all bits in the range are set. int find_first_unset_in(unsigned Begin, unsigned End) const { - return find_first_in(Begin, End, /* Set = */ false); + return find_first_in(Begin, End, /* Set = */ false); } /// find_last_unset_in - Returns the index of the last unset bit in the diff --git a/contrib/libs/llvm12/include/llvm/ADT/DenseMap.h b/contrib/libs/llvm12/include/llvm/ADT/DenseMap.h index bcc503ee21..96839b7288 100644 --- a/contrib/libs/llvm12/include/llvm/ADT/DenseMap.h +++ b/contrib/libs/llvm12/include/llvm/ADT/DenseMap.h @@ -433,8 +433,8 @@ protected: setNumEntries(other.getNumEntries()); setNumTombstones(other.getNumTombstones()); - if (std::is_trivially_copyable<KeyT>::value && - std::is_trivially_copyable<ValueT>::value) + if (std::is_trivially_copyable<KeyT>::value && + std::is_trivially_copyable<ValueT>::value) memcpy(reinterpret_cast<void *>(getBuckets()), other.getBuckets(), getNumBuckets() * sizeof(BucketT)); else @@ -961,7 +961,7 @@ public: std::swap(*LHSB, *RHSB); continue; } - // Swap separately and handle any asymmetry. + // Swap separately and handle any asymmetry. std::swap(LHSB->getFirst(), RHSB->getFirst()); if (hasLHSValue) { ::new (&RHSB->getSecond()) ValueT(std::move(LHSB->getSecond())); @@ -1049,7 +1049,7 @@ public: if (Small) { // First move the inline buckets into a temporary storage. AlignedCharArrayUnion<BucketT[InlineBuckets]> TmpStorage; - BucketT *TmpBegin = reinterpret_cast<BucketT *>(&TmpStorage); + BucketT *TmpBegin = reinterpret_cast<BucketT *>(&TmpStorage); BucketT *TmpEnd = TmpBegin; // Loop over the buckets, moving non-empty, non-tombstones into the @@ -1139,8 +1139,8 @@ private: assert(Small); // Note that this cast does not violate aliasing rules as we assert that // the memory's dynamic type is the small, inline bucket buffer, and the - // 'storage' is a POD containing a char buffer. - return reinterpret_cast<const BucketT *>(&storage); + // 'storage' is a POD containing a char buffer. + return reinterpret_cast<const BucketT *>(&storage); } BucketT *getInlineBuckets() { @@ -1151,7 +1151,7 @@ private: const LargeRep *getLargeRep() const { assert(!Small); // Note, same rule about aliasing as with getInlineBuckets. - return reinterpret_cast<const LargeRep *>(&storage); + return reinterpret_cast<const LargeRep *>(&storage); } LargeRep *getLargeRep() { diff --git a/contrib/libs/llvm12/include/llvm/ADT/DenseMapInfo.h b/contrib/libs/llvm12/include/llvm/ADT/DenseMapInfo.h index 03ef6ea0b0..98af8ca088 100644 --- a/contrib/libs/llvm12/include/llvm/ADT/DenseMapInfo.h +++ b/contrib/libs/llvm12/include/llvm/ADT/DenseMapInfo.h @@ -20,8 +20,8 @@ #ifndef LLVM_ADT_DENSEMAPINFO_H #define LLVM_ADT_DENSEMAPINFO_H -#include "llvm/ADT/APInt.h" -#include "llvm/ADT/APSInt.h" +#include "llvm/ADT/APInt.h" +#include "llvm/ADT/APSInt.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/Hashing.h" #include "llvm/ADT/StringRef.h" @@ -356,49 +356,49 @@ template <> struct DenseMapInfo<hash_code> { static bool isEqual(hash_code LHS, hash_code RHS) { return LHS == RHS; } }; -/// Provide DenseMapInfo for APInt. -template <> struct DenseMapInfo<APInt> { - static inline APInt getEmptyKey() { - APInt V(nullptr, 0); - V.U.VAL = 0; - return V; - } - - static inline APInt getTombstoneKey() { - APInt V(nullptr, 0); - V.U.VAL = 1; - return V; - } - - static unsigned getHashValue(const APInt &Key) { - return static_cast<unsigned>(hash_value(Key)); - } - - static bool isEqual(const APInt &LHS, const APInt &RHS) { - return LHS.getBitWidth() == RHS.getBitWidth() && LHS == RHS; - } -}; - -/// Provide DenseMapInfo for APSInt, using the DenseMapInfo for APInt. -template <> struct DenseMapInfo<APSInt> { - static inline APSInt getEmptyKey() { - return APSInt(DenseMapInfo<APInt>::getEmptyKey()); - } - - static inline APSInt getTombstoneKey() { - return APSInt(DenseMapInfo<APInt>::getTombstoneKey()); - } - - static unsigned getHashValue(const APSInt &Key) { - return static_cast<unsigned>(hash_value(Key)); - } - - static bool isEqual(const APSInt &LHS, const APSInt &RHS) { - return LHS.getBitWidth() == RHS.getBitWidth() && - LHS.isUnsigned() == RHS.isUnsigned() && LHS == RHS; - } -}; - +/// Provide DenseMapInfo for APInt. +template <> struct DenseMapInfo<APInt> { + static inline APInt getEmptyKey() { + APInt V(nullptr, 0); + V.U.VAL = 0; + return V; + } + + static inline APInt getTombstoneKey() { + APInt V(nullptr, 0); + V.U.VAL = 1; + return V; + } + + static unsigned getHashValue(const APInt &Key) { + return static_cast<unsigned>(hash_value(Key)); + } + + static bool isEqual(const APInt &LHS, const APInt &RHS) { + return LHS.getBitWidth() == RHS.getBitWidth() && LHS == RHS; + } +}; + +/// Provide DenseMapInfo for APSInt, using the DenseMapInfo for APInt. +template <> struct DenseMapInfo<APSInt> { + static inline APSInt getEmptyKey() { + return APSInt(DenseMapInfo<APInt>::getEmptyKey()); + } + + static inline APSInt getTombstoneKey() { + return APSInt(DenseMapInfo<APInt>::getTombstoneKey()); + } + + static unsigned getHashValue(const APSInt &Key) { + return static_cast<unsigned>(hash_value(Key)); + } + + static bool isEqual(const APSInt &LHS, const APSInt &RHS) { + return LHS.getBitWidth() == RHS.getBitWidth() && + LHS.isUnsigned() == RHS.isUnsigned() && LHS == RHS; + } +}; + } // end namespace llvm #endif // LLVM_ADT_DENSEMAPINFO_H diff --git a/contrib/libs/llvm12/include/llvm/ADT/DenseSet.h b/contrib/libs/llvm12/include/llvm/ADT/DenseSet.h index a0a79f6fdc..d6fac1f323 100644 --- a/contrib/libs/llvm12/include/llvm/ADT/DenseSet.h +++ b/contrib/libs/llvm12/include/llvm/ADT/DenseSet.h @@ -188,11 +188,11 @@ public: return ConstIterator(TheMap.find(V)); } - /// Check if the set contains the given element. - bool contains(const_arg_type_t<ValueT> V) const { - return TheMap.find(V) != TheMap.end(); - } - + /// Check if the set contains the given element. + bool contains(const_arg_type_t<ValueT> V) const { + return TheMap.find(V) != TheMap.end(); + } + /// Alternative version of find() which allows a different, and possibly less /// expensive, key type. /// The DenseMapInfo is responsible for supplying methods diff --git a/contrib/libs/llvm12/include/llvm/ADT/DepthFirstIterator.h b/contrib/libs/llvm12/include/llvm/ADT/DepthFirstIterator.h index 71b6e6d158..fce66034e3 100644 --- a/contrib/libs/llvm12/include/llvm/ADT/DepthFirstIterator.h +++ b/contrib/libs/llvm12/include/llvm/ADT/DepthFirstIterator.h @@ -205,7 +205,7 @@ public: // nodes that a depth first iteration did not find: ie unreachable nodes. // bool nodeVisited(NodeRef Node) const { - return this->Visited.contains(Node); + return this->Visited.contains(Node); } /// getPathLength - Return the length of the path from the entry node to the diff --git a/contrib/libs/llvm12/include/llvm/ADT/DirectedGraph.h b/contrib/libs/llvm12/include/llvm/ADT/DirectedGraph.h index 49c6a73148..acc4460c74 100644 --- a/contrib/libs/llvm12/include/llvm/ADT/DirectedGraph.h +++ b/contrib/libs/llvm12/include/llvm/ADT/DirectedGraph.h @@ -236,7 +236,7 @@ public: if (*Node == N) continue; Node->findEdgesTo(N, TempList); - llvm::append_range(EL, TempList); + llvm::append_range(EL, TempList); TempList.clear(); } return !EL.empty(); diff --git a/contrib/libs/llvm12/include/llvm/ADT/FloatingPointMode.h b/contrib/libs/llvm12/include/llvm/ADT/FloatingPointMode.h index dc71c475da..b1ef7f1ba5 100644 --- a/contrib/libs/llvm12/include/llvm/ADT/FloatingPointMode.h +++ b/contrib/libs/llvm12/include/llvm/ADT/FloatingPointMode.h @@ -51,24 +51,24 @@ enum class RoundingMode : int8_t { Invalid = -1 ///< Denotes invalid value. }; -/// Returns text representation of the given rounding mode. -inline StringRef spell(RoundingMode RM) { - switch (RM) { - case RoundingMode::TowardZero: return "towardzero"; - case RoundingMode::NearestTiesToEven: return "tonearest"; - case RoundingMode::TowardPositive: return "upward"; - case RoundingMode::TowardNegative: return "downward"; - case RoundingMode::NearestTiesToAway: return "tonearestaway"; - case RoundingMode::Dynamic: return "dynamic"; - default: return "invalid"; - } -} - -inline raw_ostream &operator << (raw_ostream &OS, RoundingMode RM) { - OS << spell(RM); - return OS; -} - +/// Returns text representation of the given rounding mode. +inline StringRef spell(RoundingMode RM) { + switch (RM) { + case RoundingMode::TowardZero: return "towardzero"; + case RoundingMode::NearestTiesToEven: return "tonearest"; + case RoundingMode::TowardPositive: return "upward"; + case RoundingMode::TowardNegative: return "downward"; + case RoundingMode::NearestTiesToAway: return "tonearestaway"; + case RoundingMode::Dynamic: return "dynamic"; + default: return "invalid"; + } +} + +inline raw_ostream &operator << (raw_ostream &OS, RoundingMode RM) { + OS << spell(RM); + return OS; +} + /// Represent subnormal handling kind for floating point instruction inputs and /// outputs. struct DenormalMode { diff --git a/contrib/libs/llvm12/include/llvm/ADT/FunctionExtras.h b/contrib/libs/llvm12/include/llvm/ADT/FunctionExtras.h index 8eae5fb1cc..aed288cf0a 100644 --- a/contrib/libs/llvm12/include/llvm/ADT/FunctionExtras.h +++ b/contrib/libs/llvm12/include/llvm/ADT/FunctionExtras.h @@ -71,13 +71,13 @@ template <typename ReturnT, typename... ParamTs> class UniqueFunctionBase { protected: static constexpr size_t InlineStorageSize = sizeof(void *) * 3; - template <typename T, class = void> - struct IsSizeLessThanThresholdT : std::false_type {}; - - template <typename T> - struct IsSizeLessThanThresholdT< - T, std::enable_if_t<sizeof(T) <= 2 * sizeof(void *)>> : std::true_type {}; + template <typename T, class = void> + struct IsSizeLessThanThresholdT : std::false_type {}; + template <typename T> + struct IsSizeLessThanThresholdT< + T, std::enable_if_t<sizeof(T) <= 2 * sizeof(void *)>> : std::true_type {}; + // Provide a type function to map parameters that won't observe extra copies // or moves and which are small enough to likely pass in register to values // and all other types to l-value reference types. We use this to compute the diff --git a/contrib/libs/llvm12/include/llvm/ADT/Hashing.h b/contrib/libs/llvm12/include/llvm/ADT/Hashing.h index d6d956afaf..da16cbb67a 100644 --- a/contrib/libs/llvm12/include/llvm/ADT/Hashing.h +++ b/contrib/libs/llvm12/include/llvm/ADT/Hashing.h @@ -59,7 +59,7 @@ #include <cassert> #include <cstring> #include <string> -#include <tuple> +#include <tuple> #include <utility> namespace llvm { @@ -120,10 +120,10 @@ template <typename T> hash_code hash_value(const T *ptr); template <typename T, typename U> hash_code hash_value(const std::pair<T, U> &arg); -/// Compute a hash_code for a tuple. -template <typename... Ts> -hash_code hash_value(const std::tuple<Ts...> &arg); - +/// Compute a hash_code for a tuple. +template <typename... Ts> +hash_code hash_value(const std::tuple<Ts...> &arg); + /// Compute a hash_code for a standard string. template <typename T> hash_code hash_value(const std::basic_string<T> &arg); @@ -657,26 +657,26 @@ hash_code hash_value(const std::pair<T, U> &arg) { return hash_combine(arg.first, arg.second); } -// Implementation details for the hash_value overload for std::tuple<...>(...). -namespace hashing { -namespace detail { - -template <typename... Ts, std::size_t... Indices> -hash_code hash_value_tuple_helper(const std::tuple<Ts...> &arg, - std::index_sequence<Indices...> indices) { - return hash_combine(std::get<Indices>(arg)...); -} - -} // namespace detail -} // namespace hashing - -template <typename... Ts> -hash_code hash_value(const std::tuple<Ts...> &arg) { - // TODO: Use std::apply when LLVM starts using C++17. - return ::llvm::hashing::detail::hash_value_tuple_helper( - arg, typename std::index_sequence_for<Ts...>()); -} - +// Implementation details for the hash_value overload for std::tuple<...>(...). +namespace hashing { +namespace detail { + +template <typename... Ts, std::size_t... Indices> +hash_code hash_value_tuple_helper(const std::tuple<Ts...> &arg, + std::index_sequence<Indices...> indices) { + return hash_combine(std::get<Indices>(arg)...); +} + +} // namespace detail +} // namespace hashing + +template <typename... Ts> +hash_code hash_value(const std::tuple<Ts...> &arg) { + // TODO: Use std::apply when LLVM starts using C++17. + return ::llvm::hashing::detail::hash_value_tuple_helper( + arg, typename std::index_sequence_for<Ts...>()); +} + // Declared and documented above, but defined here so that any of the hashing // infrastructure is available. template <typename T> diff --git a/contrib/libs/llvm12/include/llvm/ADT/IntervalMap.h b/contrib/libs/llvm12/include/llvm/ADT/IntervalMap.h index efe8149cc2..d2dd871692 100644 --- a/contrib/libs/llvm12/include/llvm/ADT/IntervalMap.h +++ b/contrib/libs/llvm12/include/llvm/ADT/IntervalMap.h @@ -970,7 +970,7 @@ public: private: // The root data is either a RootLeaf or a RootBranchData instance. - AlignedCharArrayUnion<RootLeaf, RootBranchData> data; + AlignedCharArrayUnion<RootLeaf, RootBranchData> data; // Tree height. // 0: Leaves in root. @@ -985,7 +985,7 @@ private: Allocator &allocator; /// Represent data as a node type without breaking aliasing rules. - template <typename T> T &dataAs() const { return *bit_cast<T *>(&data); } + template <typename T> T &dataAs() const { return *bit_cast<T *>(&data); } const RootLeaf &rootLeaf() const { assert(!branched() && "Cannot acces leaf data in branched root"); @@ -1043,7 +1043,7 @@ private: public: explicit IntervalMap(Allocator &a) : height(0), rootSize(0), allocator(a) { - assert((uintptr_t(&data) & (alignof(RootLeaf) - 1)) == 0 && + assert((uintptr_t(&data) & (alignof(RootLeaf) - 1)) == 0 && "Insufficient alignment"); new(&rootLeaf()) RootLeaf(); } diff --git a/contrib/libs/llvm12/include/llvm/ADT/IntrusiveRefCntPtr.h b/contrib/libs/llvm12/include/llvm/ADT/IntrusiveRefCntPtr.h index 28bfb913ca..4f44fc927a 100644 --- a/contrib/libs/llvm12/include/llvm/ADT/IntrusiveRefCntPtr.h +++ b/contrib/libs/llvm12/include/llvm/ADT/IntrusiveRefCntPtr.h @@ -65,7 +65,7 @@ #include <atomic> #include <cassert> #include <cstddef> -#include <memory> +#include <memory> namespace llvm { @@ -78,23 +78,23 @@ namespace llvm { template <class Derived> class RefCountedBase { mutable unsigned RefCount = 0; -protected: +protected: RefCountedBase() = default; RefCountedBase(const RefCountedBase &) {} - RefCountedBase &operator=(const RefCountedBase &) = delete; - -#ifndef NDEBUG - ~RefCountedBase() { - assert(RefCount == 0 && - "Destruction occured when there are still references to this."); - } -#else - // Default the destructor in release builds, A trivial destructor may enable - // better codegen. - ~RefCountedBase() = default; -#endif - -public: + RefCountedBase &operator=(const RefCountedBase &) = delete; + +#ifndef NDEBUG + ~RefCountedBase() { + assert(RefCount == 0 && + "Destruction occured when there are still references to this."); + } +#else + // Default the destructor in release builds, A trivial destructor may enable + // better codegen. + ~RefCountedBase() = default; +#endif + +public: void Retain() const { ++RefCount; } void Release() const { @@ -106,25 +106,25 @@ public: /// A thread-safe version of \c RefCountedBase. template <class Derived> class ThreadSafeRefCountedBase { - mutable std::atomic<int> RefCount{0}; + mutable std::atomic<int> RefCount{0}; protected: - ThreadSafeRefCountedBase() = default; - ThreadSafeRefCountedBase(const ThreadSafeRefCountedBase &) {} - ThreadSafeRefCountedBase & - operator=(const ThreadSafeRefCountedBase &) = delete; - -#ifndef NDEBUG - ~ThreadSafeRefCountedBase() { - assert(RefCount == 0 && - "Destruction occured when there are still references to this."); - } -#else - // Default the destructor in release builds, A trivial destructor may enable - // better codegen. - ~ThreadSafeRefCountedBase() = default; -#endif - + ThreadSafeRefCountedBase() = default; + ThreadSafeRefCountedBase(const ThreadSafeRefCountedBase &) {} + ThreadSafeRefCountedBase & + operator=(const ThreadSafeRefCountedBase &) = delete; + +#ifndef NDEBUG + ~ThreadSafeRefCountedBase() { + assert(RefCount == 0 && + "Destruction occured when there are still references to this."); + } +#else + // Default the destructor in release builds, A trivial destructor may enable + // better codegen. + ~ThreadSafeRefCountedBase() = default; +#endif + public: void Retain() const { RefCount.fetch_add(1, std::memory_order_relaxed); } @@ -184,11 +184,11 @@ public: } template <class X> - IntrusiveRefCntPtr(std::unique_ptr<X> S) : Obj(S.release()) { - retain(); - } - - template <class X> + IntrusiveRefCntPtr(std::unique_ptr<X> S) : Obj(S.release()) { + retain(); + } + + template <class X> IntrusiveRefCntPtr(const IntrusiveRefCntPtr<X> &S) : Obj(S.get()) { retain(); } @@ -304,12 +304,12 @@ template <class T> struct simplify_type<const IntrusiveRefCntPtr<T>> { } }; -/// Factory function for creating intrusive ref counted pointers. -template <typename T, typename... Args> -IntrusiveRefCntPtr<T> makeIntrusiveRefCnt(Args &&...A) { - return IntrusiveRefCntPtr<T>(new T(std::forward<Args>(A)...)); -} - +/// Factory function for creating intrusive ref counted pointers. +template <typename T, typename... Args> +IntrusiveRefCntPtr<T> makeIntrusiveRefCnt(Args &&...A) { + return IntrusiveRefCntPtr<T>(new T(std::forward<Args>(A)...)); +} + } // end namespace llvm #endif // LLVM_ADT_INTRUSIVEREFCNTPTR_H diff --git a/contrib/libs/llvm12/include/llvm/ADT/Optional.h b/contrib/libs/llvm12/include/llvm/ADT/Optional.h index 0f0725c73e..e3d9ea6eef 100644 --- a/contrib/libs/llvm12/include/llvm/ADT/Optional.h +++ b/contrib/libs/llvm12/include/llvm/ADT/Optional.h @@ -22,7 +22,7 @@ #ifndef LLVM_ADT_OPTIONAL_H #define LLVM_ADT_OPTIONAL_H -#include "llvm/ADT/Hashing.h" +#include "llvm/ADT/Hashing.h" #include "llvm/ADT/None.h" #include "llvm/Support/Compiler.h" #include "llvm/Support/type_traits.h" @@ -40,30 +40,30 @@ namespace optional_detail { struct in_place_t {}; /// Storage for any type. -// -// The specialization condition intentionally uses -// llvm::is_trivially_copy_constructible instead of -// std::is_trivially_copy_constructible. GCC versions prior to 7.4 may -// instantiate the copy constructor of `T` when -// std::is_trivially_copy_constructible is instantiated. This causes -// compilation to fail if we query the trivially copy constructible property of -// a class which is not copy constructible. -// -// The current implementation of OptionalStorage insists that in order to use -// the trivial specialization, the value_type must be trivially copy -// constructible and trivially copy assignable due to =default implementations -// of the copy/move constructor/assignment. It does not follow that this is -// necessarily the case std::is_trivially_copyable is true (hence the expanded -// specialization condition). -// -// The move constructible / assignable conditions emulate the remaining behavior -// of std::is_trivially_copyable. -template <typename T, bool = (llvm::is_trivially_copy_constructible<T>::value && - std::is_trivially_copy_assignable<T>::value && - (std::is_trivially_move_constructible<T>::value || - !std::is_move_constructible<T>::value) && - (std::is_trivially_move_assignable<T>::value || - !std::is_move_assignable<T>::value))> +// +// The specialization condition intentionally uses +// llvm::is_trivially_copy_constructible instead of +// std::is_trivially_copy_constructible. GCC versions prior to 7.4 may +// instantiate the copy constructor of `T` when +// std::is_trivially_copy_constructible is instantiated. This causes +// compilation to fail if we query the trivially copy constructible property of +// a class which is not copy constructible. +// +// The current implementation of OptionalStorage insists that in order to use +// the trivial specialization, the value_type must be trivially copy +// constructible and trivially copy assignable due to =default implementations +// of the copy/move constructor/assignment. It does not follow that this is +// necessarily the case std::is_trivially_copyable is true (hence the expanded +// specialization condition). +// +// The move constructible / assignable conditions emulate the remaining behavior +// of std::is_trivially_copyable. +template <typename T, bool = (llvm::is_trivially_copy_constructible<T>::value && + std::is_trivially_copy_assignable<T>::value && + (std::is_trivially_move_constructible<T>::value || + !std::is_move_constructible<T>::value) && + (std::is_trivially_move_assignable<T>::value || + !std::is_move_assignable<T>::value))> class OptionalStorage { union { char empty; @@ -74,21 +74,21 @@ class OptionalStorage { public: ~OptionalStorage() { reset(); } - constexpr OptionalStorage() noexcept : empty(), hasVal(false) {} + constexpr OptionalStorage() noexcept : empty(), hasVal(false) {} - constexpr OptionalStorage(OptionalStorage const &other) : OptionalStorage() { + constexpr OptionalStorage(OptionalStorage const &other) : OptionalStorage() { if (other.hasValue()) { emplace(other.value); } } - constexpr OptionalStorage(OptionalStorage &&other) : OptionalStorage() { + constexpr OptionalStorage(OptionalStorage &&other) : OptionalStorage() { if (other.hasValue()) { emplace(std::move(other.value)); } } template <class... Args> - constexpr explicit OptionalStorage(in_place_t, Args &&... args) + constexpr explicit OptionalStorage(in_place_t, Args &&... args) : value(std::forward<Args>(args)...), hasVal(true) {} void reset() noexcept { @@ -98,13 +98,13 @@ public: } } - constexpr bool hasValue() const noexcept { return hasVal; } + constexpr bool hasValue() const noexcept { return hasVal; } T &getValue() LLVM_LVALUE_FUNCTION noexcept { assert(hasVal); return value; } - constexpr T const &getValue() const LLVM_LVALUE_FUNCTION noexcept { + constexpr T const &getValue() const LLVM_LVALUE_FUNCTION noexcept { assert(hasVal); return value; } @@ -179,16 +179,16 @@ template <typename T> class OptionalStorage<T, true> { public: ~OptionalStorage() = default; - constexpr OptionalStorage() noexcept : empty{} {} + constexpr OptionalStorage() noexcept : empty{} {} - constexpr OptionalStorage(OptionalStorage const &other) = default; - constexpr OptionalStorage(OptionalStorage &&other) = default; + constexpr OptionalStorage(OptionalStorage const &other) = default; + constexpr OptionalStorage(OptionalStorage &&other) = default; OptionalStorage &operator=(OptionalStorage const &other) = default; OptionalStorage &operator=(OptionalStorage &&other) = default; template <class... Args> - constexpr explicit OptionalStorage(in_place_t, Args &&... args) + constexpr explicit OptionalStorage(in_place_t, Args &&... args) : value(std::forward<Args>(args)...), hasVal(true) {} void reset() noexcept { @@ -198,13 +198,13 @@ public: } } - constexpr bool hasValue() const noexcept { return hasVal; } + constexpr bool hasValue() const noexcept { return hasVal; } T &getValue() LLVM_LVALUE_FUNCTION noexcept { assert(hasVal); return value; } - constexpr T const &getValue() const LLVM_LVALUE_FUNCTION noexcept { + constexpr T const &getValue() const LLVM_LVALUE_FUNCTION noexcept { assert(hasVal); return value; } @@ -252,12 +252,12 @@ public: constexpr Optional() {} constexpr Optional(NoneType) {} - constexpr Optional(const T &y) : Storage(optional_detail::in_place_t{}, y) {} - constexpr Optional(const Optional &O) = default; + constexpr Optional(const T &y) : Storage(optional_detail::in_place_t{}, y) {} + constexpr Optional(const Optional &O) = default; - constexpr Optional(T &&y) - : Storage(optional_detail::in_place_t{}, std::move(y)) {} - constexpr Optional(Optional &&O) = default; + constexpr Optional(T &&y) + : Storage(optional_detail::in_place_t{}, std::move(y)) {} + constexpr Optional(Optional &&O) = default; Optional &operator=(T &&y) { Storage = std::move(y); @@ -270,7 +270,7 @@ public: Storage.emplace(std::forward<ArgTypes>(Args)...); } - static constexpr Optional create(const T *y) { + static constexpr Optional create(const T *y) { return y ? Optional(*y) : Optional(); } @@ -282,20 +282,20 @@ public: void reset() { Storage.reset(); } - constexpr const T *getPointer() const { return &Storage.getValue(); } + constexpr const T *getPointer() const { return &Storage.getValue(); } T *getPointer() { return &Storage.getValue(); } - constexpr const T &getValue() const LLVM_LVALUE_FUNCTION { - return Storage.getValue(); - } + constexpr const T &getValue() const LLVM_LVALUE_FUNCTION { + return Storage.getValue(); + } T &getValue() LLVM_LVALUE_FUNCTION { return Storage.getValue(); } - constexpr explicit operator bool() const { return hasValue(); } - constexpr bool hasValue() const { return Storage.hasValue(); } - constexpr const T *operator->() const { return getPointer(); } + constexpr explicit operator bool() const { return hasValue(); } + constexpr bool hasValue() const { return Storage.hasValue(); } + constexpr const T *operator->() const { return getPointer(); } T *operator->() { return getPointer(); } - constexpr const T &operator*() const LLVM_LVALUE_FUNCTION { - return getValue(); - } + constexpr const T &operator*() const LLVM_LVALUE_FUNCTION { + return getValue(); + } T &operator*() LLVM_LVALUE_FUNCTION { return getValue(); } template <typename U> @@ -330,157 +330,157 @@ public: #endif }; -template <class T> llvm::hash_code hash_value(const Optional<T> &O) { - return O ? hash_combine(true, *O) : hash_value(false); -} - +template <class T> llvm::hash_code hash_value(const Optional<T> &O) { + return O ? hash_combine(true, *O) : hash_value(false); +} + template <typename T, typename U> -constexpr bool operator==(const Optional<T> &X, const Optional<U> &Y) { +constexpr bool operator==(const Optional<T> &X, const Optional<U> &Y) { if (X && Y) return *X == *Y; return X.hasValue() == Y.hasValue(); } template <typename T, typename U> -constexpr bool operator!=(const Optional<T> &X, const Optional<U> &Y) { +constexpr bool operator!=(const Optional<T> &X, const Optional<U> &Y) { return !(X == Y); } template <typename T, typename U> -constexpr bool operator<(const Optional<T> &X, const Optional<U> &Y) { +constexpr bool operator<(const Optional<T> &X, const Optional<U> &Y) { if (X && Y) return *X < *Y; return X.hasValue() < Y.hasValue(); } template <typename T, typename U> -constexpr bool operator<=(const Optional<T> &X, const Optional<U> &Y) { +constexpr bool operator<=(const Optional<T> &X, const Optional<U> &Y) { return !(Y < X); } template <typename T, typename U> -constexpr bool operator>(const Optional<T> &X, const Optional<U> &Y) { +constexpr bool operator>(const Optional<T> &X, const Optional<U> &Y) { return Y < X; } template <typename T, typename U> -constexpr bool operator>=(const Optional<T> &X, const Optional<U> &Y) { +constexpr bool operator>=(const Optional<T> &X, const Optional<U> &Y) { return !(X < Y); } -template <typename T> -constexpr bool operator==(const Optional<T> &X, NoneType) { +template <typename T> +constexpr bool operator==(const Optional<T> &X, NoneType) { return !X; } -template <typename T> -constexpr bool operator==(NoneType, const Optional<T> &X) { +template <typename T> +constexpr bool operator==(NoneType, const Optional<T> &X) { return X == None; } -template <typename T> -constexpr bool operator!=(const Optional<T> &X, NoneType) { +template <typename T> +constexpr bool operator!=(const Optional<T> &X, NoneType) { return !(X == None); } -template <typename T> -constexpr bool operator!=(NoneType, const Optional<T> &X) { +template <typename T> +constexpr bool operator!=(NoneType, const Optional<T> &X) { return X != None; } -template <typename T> constexpr bool operator<(const Optional<T> &X, NoneType) { +template <typename T> constexpr bool operator<(const Optional<T> &X, NoneType) { return false; } -template <typename T> constexpr bool operator<(NoneType, const Optional<T> &X) { +template <typename T> constexpr bool operator<(NoneType, const Optional<T> &X) { return X.hasValue(); } -template <typename T> -constexpr bool operator<=(const Optional<T> &X, NoneType) { +template <typename T> +constexpr bool operator<=(const Optional<T> &X, NoneType) { return !(None < X); } -template <typename T> -constexpr bool operator<=(NoneType, const Optional<T> &X) { +template <typename T> +constexpr bool operator<=(NoneType, const Optional<T> &X) { return !(X < None); } -template <typename T> constexpr bool operator>(const Optional<T> &X, NoneType) { +template <typename T> constexpr bool operator>(const Optional<T> &X, NoneType) { return None < X; } -template <typename T> constexpr bool operator>(NoneType, const Optional<T> &X) { +template <typename T> constexpr bool operator>(NoneType, const Optional<T> &X) { return X < None; } -template <typename T> -constexpr bool operator>=(const Optional<T> &X, NoneType) { +template <typename T> +constexpr bool operator>=(const Optional<T> &X, NoneType) { return None <= X; } -template <typename T> -constexpr bool operator>=(NoneType, const Optional<T> &X) { +template <typename T> +constexpr bool operator>=(NoneType, const Optional<T> &X) { return X <= None; } -template <typename T> -constexpr bool operator==(const Optional<T> &X, const T &Y) { +template <typename T> +constexpr bool operator==(const Optional<T> &X, const T &Y) { return X && *X == Y; } -template <typename T> -constexpr bool operator==(const T &X, const Optional<T> &Y) { +template <typename T> +constexpr bool operator==(const T &X, const Optional<T> &Y) { return Y && X == *Y; } -template <typename T> -constexpr bool operator!=(const Optional<T> &X, const T &Y) { +template <typename T> +constexpr bool operator!=(const Optional<T> &X, const T &Y) { return !(X == Y); } -template <typename T> -constexpr bool operator!=(const T &X, const Optional<T> &Y) { +template <typename T> +constexpr bool operator!=(const T &X, const Optional<T> &Y) { return !(X == Y); } -template <typename T> -constexpr bool operator<(const Optional<T> &X, const T &Y) { +template <typename T> +constexpr bool operator<(const Optional<T> &X, const T &Y) { return !X || *X < Y; } -template <typename T> -constexpr bool operator<(const T &X, const Optional<T> &Y) { +template <typename T> +constexpr bool operator<(const T &X, const Optional<T> &Y) { return Y && X < *Y; } -template <typename T> -constexpr bool operator<=(const Optional<T> &X, const T &Y) { +template <typename T> +constexpr bool operator<=(const Optional<T> &X, const T &Y) { return !(Y < X); } -template <typename T> -constexpr bool operator<=(const T &X, const Optional<T> &Y) { +template <typename T> +constexpr bool operator<=(const T &X, const Optional<T> &Y) { return !(Y < X); } -template <typename T> -constexpr bool operator>(const Optional<T> &X, const T &Y) { +template <typename T> +constexpr bool operator>(const Optional<T> &X, const T &Y) { return Y < X; } -template <typename T> -constexpr bool operator>(const T &X, const Optional<T> &Y) { +template <typename T> +constexpr bool operator>(const T &X, const Optional<T> &Y) { return Y < X; } -template <typename T> -constexpr bool operator>=(const Optional<T> &X, const T &Y) { +template <typename T> +constexpr bool operator>=(const Optional<T> &X, const T &Y) { return !(X < Y); } -template <typename T> -constexpr bool operator>=(const T &X, const Optional<T> &Y) { +template <typename T> +constexpr bool operator>=(const T &X, const Optional<T> &Y) { return !(X < Y); } diff --git a/contrib/libs/llvm12/include/llvm/ADT/STLExtras.h b/contrib/libs/llvm12/include/llvm/ADT/STLExtras.h index ba115875ce..a6fa02e0f6 100644 --- a/contrib/libs/llvm12/include/llvm/ADT/STLExtras.h +++ b/contrib/libs/llvm12/include/llvm/ADT/STLExtras.h @@ -200,15 +200,15 @@ public: template <typename Callable> function_ref( Callable &&callable, - // This is not the copy-constructor. + // This is not the copy-constructor. std::enable_if_t< !std::is_same<std::remove_cv_t<std::remove_reference_t<Callable>>, - function_ref>::value> * = nullptr, - // Functor must be callable and return a suitable type. - std::enable_if_t<std::is_void<Ret>::value || - std::is_convertible<decltype(std::declval<Callable>()( - std::declval<Params>()...)), - Ret>::value> * = nullptr) + function_ref>::value> * = nullptr, + // Functor must be callable and return a suitable type. + std::enable_if_t<std::is_void<Ret>::value || + std::is_convertible<decltype(std::declval<Callable>()( + std::declval<Params>()...)), + Ret>::value> * = nullptr) : callback(callback_fn<typename std::remove_reference<Callable>::type>), callable(reinterpret_cast<intptr_t>(&callable)) {} @@ -279,7 +279,7 @@ template <typename ContainerTy> bool hasSingleElement(ContainerTy &&C) { /// Return a range covering \p RangeOrContainer with the first N elements /// excluded. -template <typename T> auto drop_begin(T &&RangeOrContainer, size_t N = 1) { +template <typename T> auto drop_begin(T &&RangeOrContainer, size_t N = 1) { return make_range(std::next(adl_begin(RangeOrContainer), N), adl_end(RangeOrContainer)); } @@ -545,7 +545,7 @@ public: early_inc_iterator_impl(WrappedIteratorT I) : BaseT(I) {} using BaseT::operator*; - decltype(*std::declval<WrappedIteratorT>()) operator*() { + decltype(*std::declval<WrappedIteratorT>()) operator*() { #if LLVM_ENABLE_ABI_BREAKING_CHECKS assert(!IsEarlyIncremented && "Cannot dereference twice!"); IsEarlyIncremented = true; @@ -1250,15 +1250,15 @@ public: } }; -/// Given a container of pairs, return a range over the first elements. -template <typename ContainerTy> auto make_first_range(ContainerTy &&c) { - return llvm::map_range( - std::forward<ContainerTy>(c), - [](decltype((*std::begin(c))) elt) -> decltype((elt.first)) { - return elt.first; - }); -} - +/// Given a container of pairs, return a range over the first elements. +template <typename ContainerTy> auto make_first_range(ContainerTy &&c) { + return llvm::map_range( + std::forward<ContainerTy>(c), + [](decltype((*std::begin(c))) elt) -> decltype((elt.first)) { + return elt.first; + }); +} + /// Given a container of pairs, return a range over the second elements. template <typename ContainerTy> auto make_second_range(ContainerTy &&c) { return llvm::map_range( @@ -1435,7 +1435,7 @@ template <typename T> // is trivially copyable. using sort_trivially_copyable = conjunction< std::is_pointer<T>, - std::is_trivially_copyable<typename std::iterator_traits<T>::value_type>>; + std::is_trivially_copyable<typename std::iterator_traits<T>::value_type>>; } // namespace detail // Provide wrappers to std::sort which shuffle the elements before sorting @@ -1484,19 +1484,19 @@ inline void sort(Container &&C, Compare Comp) { /// which is only enabled when the operation is O(1). template <typename R> auto size(R &&Range, - std::enable_if_t< - std::is_base_of<std::random_access_iterator_tag, - typename std::iterator_traits<decltype( - Range.begin())>::iterator_category>::value, - void> * = nullptr) { + std::enable_if_t< + std::is_base_of<std::random_access_iterator_tag, + typename std::iterator_traits<decltype( + Range.begin())>::iterator_category>::value, + void> * = nullptr) { return std::distance(Range.begin(), Range.end()); } /// Provide wrappers to std::for_each which take ranges instead of having to /// pass begin/end explicitly. -template <typename R, typename UnaryFunction> -UnaryFunction for_each(R &&Range, UnaryFunction F) { - return std::for_each(adl_begin(Range), adl_end(Range), F); +template <typename R, typename UnaryFunction> +UnaryFunction for_each(R &&Range, UnaryFunction F) { + return std::for_each(adl_begin(Range), adl_end(Range), F); } /// Provide wrappers to std::all_of which take ranges instead of having to pass @@ -1557,13 +1557,13 @@ OutputIt copy(R &&Range, OutputIt Out) { return std::copy(adl_begin(Range), adl_end(Range), Out); } -/// Provide wrappers to std::move which take ranges instead of having to -/// pass begin/end explicitly. -template <typename R, typename OutputIt> -OutputIt move(R &&Range, OutputIt Out) { - return std::move(adl_begin(Range), adl_end(Range), Out); -} - +/// Provide wrappers to std::move which take ranges instead of having to +/// pass begin/end explicitly. +template <typename R, typename OutputIt> +OutputIt move(R &&Range, OutputIt Out) { + return std::move(adl_begin(Range), adl_end(Range), Out); +} + /// Wrapper function around std::find to detect if an element exists /// in a container. template <typename R, typename E> @@ -1598,9 +1598,9 @@ auto count_if(R &&Range, UnaryPredicate P) { /// Wrapper function around std::transform to apply a function to a range and /// store the result elsewhere. -template <typename R, typename OutputIt, typename UnaryFunction> -OutputIt transform(R &&Range, OutputIt d_first, UnaryFunction F) { - return std::transform(adl_begin(Range), adl_end(Range), d_first, F); +template <typename R, typename OutputIt, typename UnaryFunction> +OutputIt transform(R &&Range, OutputIt d_first, UnaryFunction F) { + return std::transform(adl_begin(Range), adl_end(Range), d_first, F); } /// Provide wrappers to std::partition which take ranges instead of having to @@ -1675,22 +1675,22 @@ void erase_if(Container &C, UnaryPredicate P) { C.erase(remove_if(C, P), C.end()); } -/// Wrapper function to remove a value from a container: -/// -/// C.erase(remove(C.begin(), C.end(), V), C.end()); -template <typename Container, typename ValueType> -void erase_value(Container &C, ValueType V) { - C.erase(std::remove(C.begin(), C.end(), V), C.end()); -} - -/// Wrapper function to append a range to a container. -/// -/// C.insert(C.end(), R.begin(), R.end()); -template <typename Container, typename Range> -inline void append_range(Container &C, Range &&R) { - C.insert(C.end(), R.begin(), R.end()); -} - +/// Wrapper function to remove a value from a container: +/// +/// C.erase(remove(C.begin(), C.end(), V), C.end()); +template <typename Container, typename ValueType> +void erase_value(Container &C, ValueType V) { + C.erase(std::remove(C.begin(), C.end(), V), C.end()); +} + +/// Wrapper function to append a range to a container. +/// +/// C.insert(C.end(), R.begin(), R.end()); +template <typename Container, typename Range> +inline void append_range(Container &C, Range &&R) { + C.insert(C.end(), R.begin(), R.end()); +} + /// Given a sequence container Cont, replace the range [ContIt, ContEnd) with /// the range [ValIt, ValEnd) (which is not from the same container). template<typename Container, typename RandomAccessIterator> @@ -1948,16 +1948,16 @@ decltype(auto) apply_tuple(F &&f, Tuple &&t) { /// Return true if the sequence [Begin, End) has exactly N items. Runs in O(N) /// time. Not meant for use with random-access iterators. /// Can optionally take a predicate to filter lazily some items. -template <typename IterTy, - typename Pred = bool (*)(const decltype(*std::declval<IterTy>()) &)> +template <typename IterTy, + typename Pred = bool (*)(const decltype(*std::declval<IterTy>()) &)> bool hasNItems( IterTy &&Begin, IterTy &&End, unsigned N, Pred &&ShouldBeCounted = [](const decltype(*std::declval<IterTy>()) &) { return true; }, std::enable_if_t< - !std::is_base_of<std::random_access_iterator_tag, - typename std::iterator_traits<std::remove_reference_t< - decltype(Begin)>>::iterator_category>::value, + !std::is_base_of<std::random_access_iterator_tag, + typename std::iterator_traits<std::remove_reference_t< + decltype(Begin)>>::iterator_category>::value, void> * = nullptr) { for (; N; ++Begin) { if (Begin == End) @@ -1973,16 +1973,16 @@ bool hasNItems( /// Return true if the sequence [Begin, End) has N or more items. Runs in O(N) /// time. Not meant for use with random-access iterators. /// Can optionally take a predicate to lazily filter some items. -template <typename IterTy, - typename Pred = bool (*)(const decltype(*std::declval<IterTy>()) &)> +template <typename IterTy, + typename Pred = bool (*)(const decltype(*std::declval<IterTy>()) &)> bool hasNItemsOrMore( IterTy &&Begin, IterTy &&End, unsigned N, Pred &&ShouldBeCounted = [](const decltype(*std::declval<IterTy>()) &) { return true; }, std::enable_if_t< - !std::is_base_of<std::random_access_iterator_tag, - typename std::iterator_traits<std::remove_reference_t< - decltype(Begin)>>::iterator_category>::value, + !std::is_base_of<std::random_access_iterator_tag, + typename std::iterator_traits<std::remove_reference_t< + decltype(Begin)>>::iterator_category>::value, void> * = nullptr) { for (; N; ++Begin) { if (Begin == End) diff --git a/contrib/libs/llvm12/include/llvm/ADT/Sequence.h b/contrib/libs/llvm12/include/llvm/ADT/Sequence.h index ec540fb18d..93f7a10888 100644 --- a/contrib/libs/llvm12/include/llvm/ADT/Sequence.h +++ b/contrib/libs/llvm12/include/llvm/ADT/Sequence.h @@ -49,10 +49,10 @@ public: value_sequence_iterator(const value_sequence_iterator &) = default; value_sequence_iterator(value_sequence_iterator &&Arg) : Value(std::move(Arg.Value)) {} - value_sequence_iterator &operator=(const value_sequence_iterator &Arg) { - Value = Arg.Value; - return *this; - } + value_sequence_iterator &operator=(const value_sequence_iterator &Arg) { + Value = Arg.Value; + return *this; + } template <typename U, typename Enabler = decltype(ValueT(std::declval<U>()))> value_sequence_iterator(U &&Value) : Value(std::forward<U>(Value)) {} diff --git a/contrib/libs/llvm12/include/llvm/ADT/SetVector.h b/contrib/libs/llvm12/include/llvm/ADT/SetVector.h index 5dc64ecb31..77210aaf7b 100644 --- a/contrib/libs/llvm12/include/llvm/ADT/SetVector.h +++ b/contrib/libs/llvm12/include/llvm/ADT/SetVector.h @@ -212,11 +212,11 @@ public: return true; } - /// Check if the SetVector contains the given key. - bool contains(const key_type &key) const { - return set_.find(key) != set_.end(); - } - + /// Check if the SetVector contains the given key. + bool contains(const key_type &key) const { + return set_.find(key) != set_.end(); + } + /// Count the number of elements of a given key in the SetVector. /// \returns 0 if the element is not in the SetVector, 1 if it is. size_type count(const key_type &key) const { diff --git a/contrib/libs/llvm12/include/llvm/ADT/SmallSet.h b/contrib/libs/llvm12/include/llvm/ADT/SmallSet.h index 6b0f3efb09..1601146115 100644 --- a/contrib/libs/llvm12/include/llvm/ADT/SmallSet.h +++ b/contrib/libs/llvm12/include/llvm/ADT/SmallSet.h @@ -239,13 +239,13 @@ public: return {Set.end()}; } - /// Check if the SmallSet contains the given element. - bool contains(const T &V) const { - if (isSmall()) - return vfind(V) != Vector.end(); - return Set.find(V) != Set.end(); - } - + /// Check if the SmallSet contains the given element. + bool contains(const T &V) const { + if (isSmall()) + return vfind(V) != Vector.end(); + return Set.find(V) != Set.end(); + } + private: bool isSmall() const { return Set.empty(); } diff --git a/contrib/libs/llvm12/include/llvm/ADT/SmallString.h b/contrib/libs/llvm12/include/llvm/ADT/SmallString.h index 889e6c8f78..0a4b60df10 100644 --- a/contrib/libs/llvm12/include/llvm/ADT/SmallString.h +++ b/contrib/libs/llvm12/include/llvm/ADT/SmallString.h @@ -37,12 +37,12 @@ public: /// Initialize from a StringRef. SmallString(StringRef S) : SmallVector<char, InternalLen>(S.begin(), S.end()) {} - /// Initialize by concatenating a list of StringRefs. - SmallString(std::initializer_list<StringRef> Refs) - : SmallVector<char, InternalLen>() { - this->append(Refs); - } - + /// Initialize by concatenating a list of StringRefs. + SmallString(std::initializer_list<StringRef> Refs) + : SmallVector<char, InternalLen>() { + this->append(Refs); + } + /// Initialize with a range. template<typename ItTy> SmallString(ItTy S, ItTy E) : SmallVector<char, InternalLen>(S, E) {} @@ -51,42 +51,42 @@ public: /// @name String Assignment /// @{ - using SmallVector<char, InternalLen>::assign; + using SmallVector<char, InternalLen>::assign; /// Assign from a StringRef. void assign(StringRef RHS) { - SmallVectorImpl<char>::assign(RHS.begin(), RHS.end()); + SmallVectorImpl<char>::assign(RHS.begin(), RHS.end()); } - /// Assign from a list of StringRefs. - void assign(std::initializer_list<StringRef> Refs) { + /// Assign from a list of StringRefs. + void assign(std::initializer_list<StringRef> Refs) { this->clear(); - append(Refs); + append(Refs); } /// @} /// @name String Concatenation /// @{ - using SmallVector<char, InternalLen>::append; + using SmallVector<char, InternalLen>::append; /// Append from a StringRef. void append(StringRef RHS) { SmallVectorImpl<char>::append(RHS.begin(), RHS.end()); } - /// Append from a list of StringRefs. - void append(std::initializer_list<StringRef> Refs) { - size_t SizeNeeded = this->size(); - for (const StringRef &Ref : Refs) - SizeNeeded += Ref.size(); - this->reserve(SizeNeeded); - auto CurEnd = this->end(); - for (const StringRef &Ref : Refs) { - this->uninitialized_copy(Ref.begin(), Ref.end(), CurEnd); - CurEnd += Ref.size(); - } - this->set_size(SizeNeeded); + /// Append from a list of StringRefs. + void append(std::initializer_list<StringRef> Refs) { + size_t SizeNeeded = this->size(); + for (const StringRef &Ref : Refs) + SizeNeeded += Ref.size(); + this->reserve(SizeNeeded); + auto CurEnd = this->end(); + for (const StringRef &Ref : Refs) { + this->uninitialized_copy(Ref.begin(), Ref.end(), CurEnd); + CurEnd += Ref.size(); + } + this->set_size(SizeNeeded); } /// @} @@ -280,9 +280,9 @@ public: } // Extra operators. - SmallString &operator=(StringRef RHS) { - this->assign(RHS); - return *this; + SmallString &operator=(StringRef RHS) { + this->assign(RHS); + return *this; } SmallString &operator+=(StringRef RHS) { diff --git a/contrib/libs/llvm12/include/llvm/ADT/SmallVector.h b/contrib/libs/llvm12/include/llvm/ADT/SmallVector.h index 1794e51433..636a3f872b 100644 --- a/contrib/libs/llvm12/include/llvm/ADT/SmallVector.h +++ b/contrib/libs/llvm12/include/llvm/ADT/SmallVector.h @@ -63,15 +63,15 @@ protected: SmallVectorBase(void *FirstEl, size_t TotalCapacity) : BeginX(FirstEl), Capacity(TotalCapacity) {} - /// This is a helper for \a grow() that's out of line to reduce code - /// duplication. This function will report a fatal error if it can't grow at - /// least to \p MinSize. - void *mallocForGrow(size_t MinSize, size_t TSize, size_t &NewCapacity); - + /// This is a helper for \a grow() that's out of line to reduce code + /// duplication. This function will report a fatal error if it can't grow at + /// least to \p MinSize. + void *mallocForGrow(size_t MinSize, size_t TSize, size_t &NewCapacity); + /// This is an implementation of the grow() method which only works /// on POD-like data types and is out of line to reduce code duplication. /// This function will report a fatal error if it cannot increase capacity. - void grow_pod(void *FirstEl, size_t MinSize, size_t TSize); + void grow_pod(void *FirstEl, size_t MinSize, size_t TSize); public: size_t size() const { return Size; } @@ -101,9 +101,9 @@ using SmallVectorSizeType = /// Figure out the offset of the first element. template <class T, typename = void> struct SmallVectorAlignmentAndSize { - alignas(SmallVectorBase<SmallVectorSizeType<T>>) char Base[sizeof( - SmallVectorBase<SmallVectorSizeType<T>>)]; - alignas(T) char FirstEl[sizeof(T)]; + alignas(SmallVectorBase<SmallVectorSizeType<T>>) char Base[sizeof( + SmallVectorBase<SmallVectorSizeType<T>>)]; + alignas(T) char FirstEl[sizeof(T)]; }; /// This is the part of SmallVectorTemplateBase which does not depend on whether @@ -127,8 +127,8 @@ class SmallVectorTemplateCommon protected: SmallVectorTemplateCommon(size_t Size) : Base(getFirstEl(), Size) {} - void grow_pod(size_t MinSize, size_t TSize) { - Base::grow_pod(getFirstEl(), MinSize, TSize); + void grow_pod(size_t MinSize, size_t TSize) { + Base::grow_pod(getFirstEl(), MinSize, TSize); } /// Return true if this is a smallvector which has not had dynamic @@ -141,102 +141,102 @@ protected: this->Size = this->Capacity = 0; // FIXME: Setting Capacity to 0 is suspect. } - /// Return true if V is an internal reference to the given range. - bool isReferenceToRange(const void *V, const void *First, const void *Last) const { - // Use std::less to avoid UB. - std::less<> LessThan; - return !LessThan(V, First) && LessThan(V, Last); - } - - /// Return true if V is an internal reference to this vector. - bool isReferenceToStorage(const void *V) const { - return isReferenceToRange(V, this->begin(), this->end()); - } - - /// Return true if First and Last form a valid (possibly empty) range in this - /// vector's storage. - bool isRangeInStorage(const void *First, const void *Last) const { - // Use std::less to avoid UB. - std::less<> LessThan; - return !LessThan(First, this->begin()) && !LessThan(Last, First) && - !LessThan(this->end(), Last); - } - - /// Return true unless Elt will be invalidated by resizing the vector to - /// NewSize. - bool isSafeToReferenceAfterResize(const void *Elt, size_t NewSize) { - // Past the end. - if (LLVM_LIKELY(!isReferenceToStorage(Elt))) - return true; - - // Return false if Elt will be destroyed by shrinking. - if (NewSize <= this->size()) - return Elt < this->begin() + NewSize; - - // Return false if we need to grow. - return NewSize <= this->capacity(); - } - - /// Check whether Elt will be invalidated by resizing the vector to NewSize. - void assertSafeToReferenceAfterResize(const void *Elt, size_t NewSize) { - assert(isSafeToReferenceAfterResize(Elt, NewSize) && - "Attempting to reference an element of the vector in an operation " - "that invalidates it"); - } - - /// Check whether Elt will be invalidated by increasing the size of the - /// vector by N. - void assertSafeToAdd(const void *Elt, size_t N = 1) { - this->assertSafeToReferenceAfterResize(Elt, this->size() + N); - } - - /// Check whether any part of the range will be invalidated by clearing. - void assertSafeToReferenceAfterClear(const T *From, const T *To) { - if (From == To) - return; - this->assertSafeToReferenceAfterResize(From, 0); - this->assertSafeToReferenceAfterResize(To - 1, 0); - } - template < - class ItTy, - std::enable_if_t<!std::is_same<std::remove_const_t<ItTy>, T *>::value, - bool> = false> - void assertSafeToReferenceAfterClear(ItTy, ItTy) {} - - /// Check whether any part of the range will be invalidated by growing. - void assertSafeToAddRange(const T *From, const T *To) { - if (From == To) - return; - this->assertSafeToAdd(From, To - From); - this->assertSafeToAdd(To - 1, To - From); - } - template < - class ItTy, - std::enable_if_t<!std::is_same<std::remove_const_t<ItTy>, T *>::value, - bool> = false> - void assertSafeToAddRange(ItTy, ItTy) {} - - /// Reserve enough space to add one element, and return the updated element - /// pointer in case it was a reference to the storage. - template <class U> - static const T *reserveForParamAndGetAddressImpl(U *This, const T &Elt, - size_t N) { - size_t NewSize = This->size() + N; - if (LLVM_LIKELY(NewSize <= This->capacity())) - return &Elt; - - bool ReferencesStorage = false; - int64_t Index = -1; - if (!U::TakesParamByValue) { - if (LLVM_UNLIKELY(This->isReferenceToStorage(&Elt))) { - ReferencesStorage = true; - Index = &Elt - This->begin(); - } - } - This->grow(NewSize); - return ReferencesStorage ? This->begin() + Index : &Elt; - } - + /// Return true if V is an internal reference to the given range. + bool isReferenceToRange(const void *V, const void *First, const void *Last) const { + // Use std::less to avoid UB. + std::less<> LessThan; + return !LessThan(V, First) && LessThan(V, Last); + } + + /// Return true if V is an internal reference to this vector. + bool isReferenceToStorage(const void *V) const { + return isReferenceToRange(V, this->begin(), this->end()); + } + + /// Return true if First and Last form a valid (possibly empty) range in this + /// vector's storage. + bool isRangeInStorage(const void *First, const void *Last) const { + // Use std::less to avoid UB. + std::less<> LessThan; + return !LessThan(First, this->begin()) && !LessThan(Last, First) && + !LessThan(this->end(), Last); + } + + /// Return true unless Elt will be invalidated by resizing the vector to + /// NewSize. + bool isSafeToReferenceAfterResize(const void *Elt, size_t NewSize) { + // Past the end. + if (LLVM_LIKELY(!isReferenceToStorage(Elt))) + return true; + + // Return false if Elt will be destroyed by shrinking. + if (NewSize <= this->size()) + return Elt < this->begin() + NewSize; + + // Return false if we need to grow. + return NewSize <= this->capacity(); + } + + /// Check whether Elt will be invalidated by resizing the vector to NewSize. + void assertSafeToReferenceAfterResize(const void *Elt, size_t NewSize) { + assert(isSafeToReferenceAfterResize(Elt, NewSize) && + "Attempting to reference an element of the vector in an operation " + "that invalidates it"); + } + + /// Check whether Elt will be invalidated by increasing the size of the + /// vector by N. + void assertSafeToAdd(const void *Elt, size_t N = 1) { + this->assertSafeToReferenceAfterResize(Elt, this->size() + N); + } + + /// Check whether any part of the range will be invalidated by clearing. + void assertSafeToReferenceAfterClear(const T *From, const T *To) { + if (From == To) + return; + this->assertSafeToReferenceAfterResize(From, 0); + this->assertSafeToReferenceAfterResize(To - 1, 0); + } + template < + class ItTy, + std::enable_if_t<!std::is_same<std::remove_const_t<ItTy>, T *>::value, + bool> = false> + void assertSafeToReferenceAfterClear(ItTy, ItTy) {} + + /// Check whether any part of the range will be invalidated by growing. + void assertSafeToAddRange(const T *From, const T *To) { + if (From == To) + return; + this->assertSafeToAdd(From, To - From); + this->assertSafeToAdd(To - 1, To - From); + } + template < + class ItTy, + std::enable_if_t<!std::is_same<std::remove_const_t<ItTy>, T *>::value, + bool> = false> + void assertSafeToAddRange(ItTy, ItTy) {} + + /// Reserve enough space to add one element, and return the updated element + /// pointer in case it was a reference to the storage. + template <class U> + static const T *reserveForParamAndGetAddressImpl(U *This, const T &Elt, + size_t N) { + size_t NewSize = This->size() + N; + if (LLVM_LIKELY(NewSize <= This->capacity())) + return &Elt; + + bool ReferencesStorage = false; + int64_t Index = -1; + if (!U::TakesParamByValue) { + if (LLVM_UNLIKELY(This->isReferenceToStorage(&Elt))) { + ReferencesStorage = true; + Index = &Elt - This->begin(); + } + } + This->grow(NewSize); + return ReferencesStorage ? This->begin() + Index : &Elt; + } + public: using size_type = size_t; using difference_type = ptrdiff_t; @@ -320,12 +320,12 @@ template <typename T, bool = (is_trivially_copy_constructible<T>::value) && (is_trivially_move_constructible<T>::value) && std::is_trivially_destructible<T>::value> class SmallVectorTemplateBase : public SmallVectorTemplateCommon<T> { - friend class SmallVectorTemplateCommon<T>; - + friend class SmallVectorTemplateCommon<T>; + protected: - static constexpr bool TakesParamByValue = false; - using ValueParamT = const T &; - + static constexpr bool TakesParamByValue = false; + using ValueParamT = const T &; + SmallVectorTemplateBase(size_t Size) : SmallVectorTemplateCommon<T>(Size) {} static void destroy_range(T *S, T *E) { @@ -355,68 +355,68 @@ protected: /// element, or MinSize more elements if specified. void grow(size_t MinSize = 0); - /// Create a new allocation big enough for \p MinSize and pass back its size - /// in \p NewCapacity. This is the first section of \a grow(). - T *mallocForGrow(size_t MinSize, size_t &NewCapacity) { - return static_cast<T *>( - SmallVectorBase<SmallVectorSizeType<T>>::mallocForGrow( - MinSize, sizeof(T), NewCapacity)); - } - - /// Move existing elements over to the new allocation \p NewElts, the middle - /// section of \a grow(). - void moveElementsForGrow(T *NewElts); - - /// Transfer ownership of the allocation, finishing up \a grow(). - void takeAllocationForGrow(T *NewElts, size_t NewCapacity); - - /// Reserve enough space to add one element, and return the updated element - /// pointer in case it was a reference to the storage. - const T *reserveForParamAndGetAddress(const T &Elt, size_t N = 1) { - return this->reserveForParamAndGetAddressImpl(this, Elt, N); - } - - /// Reserve enough space to add one element, and return the updated element - /// pointer in case it was a reference to the storage. - T *reserveForParamAndGetAddress(T &Elt, size_t N = 1) { - return const_cast<T *>( - this->reserveForParamAndGetAddressImpl(this, Elt, N)); - } - - static T &&forward_value_param(T &&V) { return std::move(V); } - static const T &forward_value_param(const T &V) { return V; } - - void growAndAssign(size_t NumElts, const T &Elt) { - // Grow manually in case Elt is an internal reference. - size_t NewCapacity; - T *NewElts = mallocForGrow(NumElts, NewCapacity); - std::uninitialized_fill_n(NewElts, NumElts, Elt); - this->destroy_range(this->begin(), this->end()); - takeAllocationForGrow(NewElts, NewCapacity); - this->set_size(NumElts); - } - - template <typename... ArgTypes> T &growAndEmplaceBack(ArgTypes &&... Args) { - // Grow manually in case one of Args is an internal reference. - size_t NewCapacity; - T *NewElts = mallocForGrow(0, NewCapacity); - ::new ((void *)(NewElts + this->size())) T(std::forward<ArgTypes>(Args)...); - moveElementsForGrow(NewElts); - takeAllocationForGrow(NewElts, NewCapacity); - this->set_size(this->size() + 1); - return this->back(); - } - + /// Create a new allocation big enough for \p MinSize and pass back its size + /// in \p NewCapacity. This is the first section of \a grow(). + T *mallocForGrow(size_t MinSize, size_t &NewCapacity) { + return static_cast<T *>( + SmallVectorBase<SmallVectorSizeType<T>>::mallocForGrow( + MinSize, sizeof(T), NewCapacity)); + } + + /// Move existing elements over to the new allocation \p NewElts, the middle + /// section of \a grow(). + void moveElementsForGrow(T *NewElts); + + /// Transfer ownership of the allocation, finishing up \a grow(). + void takeAllocationForGrow(T *NewElts, size_t NewCapacity); + + /// Reserve enough space to add one element, and return the updated element + /// pointer in case it was a reference to the storage. + const T *reserveForParamAndGetAddress(const T &Elt, size_t N = 1) { + return this->reserveForParamAndGetAddressImpl(this, Elt, N); + } + + /// Reserve enough space to add one element, and return the updated element + /// pointer in case it was a reference to the storage. + T *reserveForParamAndGetAddress(T &Elt, size_t N = 1) { + return const_cast<T *>( + this->reserveForParamAndGetAddressImpl(this, Elt, N)); + } + + static T &&forward_value_param(T &&V) { return std::move(V); } + static const T &forward_value_param(const T &V) { return V; } + + void growAndAssign(size_t NumElts, const T &Elt) { + // Grow manually in case Elt is an internal reference. + size_t NewCapacity; + T *NewElts = mallocForGrow(NumElts, NewCapacity); + std::uninitialized_fill_n(NewElts, NumElts, Elt); + this->destroy_range(this->begin(), this->end()); + takeAllocationForGrow(NewElts, NewCapacity); + this->set_size(NumElts); + } + + template <typename... ArgTypes> T &growAndEmplaceBack(ArgTypes &&... Args) { + // Grow manually in case one of Args is an internal reference. + size_t NewCapacity; + T *NewElts = mallocForGrow(0, NewCapacity); + ::new ((void *)(NewElts + this->size())) T(std::forward<ArgTypes>(Args)...); + moveElementsForGrow(NewElts); + takeAllocationForGrow(NewElts, NewCapacity); + this->set_size(this->size() + 1); + return this->back(); + } + public: void push_back(const T &Elt) { - const T *EltPtr = reserveForParamAndGetAddress(Elt); - ::new ((void *)this->end()) T(*EltPtr); + const T *EltPtr = reserveForParamAndGetAddress(Elt); + ::new ((void *)this->end()) T(*EltPtr); this->set_size(this->size() + 1); } void push_back(T &&Elt) { - T *EltPtr = reserveForParamAndGetAddress(Elt); - ::new ((void *)this->end()) T(::std::move(*EltPtr)); + T *EltPtr = reserveForParamAndGetAddress(Elt); + ::new ((void *)this->end()) T(::std::move(*EltPtr)); this->set_size(this->size() + 1); } @@ -429,27 +429,27 @@ public: // Define this out-of-line to dissuade the C++ compiler from inlining it. template <typename T, bool TriviallyCopyable> void SmallVectorTemplateBase<T, TriviallyCopyable>::grow(size_t MinSize) { - size_t NewCapacity; - T *NewElts = mallocForGrow(MinSize, NewCapacity); - moveElementsForGrow(NewElts); - takeAllocationForGrow(NewElts, NewCapacity); -} - -// Define this out-of-line to dissuade the C++ compiler from inlining it. -template <typename T, bool TriviallyCopyable> -void SmallVectorTemplateBase<T, TriviallyCopyable>::moveElementsForGrow( - T *NewElts) { + size_t NewCapacity; + T *NewElts = mallocForGrow(MinSize, NewCapacity); + moveElementsForGrow(NewElts); + takeAllocationForGrow(NewElts, NewCapacity); +} + +// Define this out-of-line to dissuade the C++ compiler from inlining it. +template <typename T, bool TriviallyCopyable> +void SmallVectorTemplateBase<T, TriviallyCopyable>::moveElementsForGrow( + T *NewElts) { // Move the elements over. this->uninitialized_move(this->begin(), this->end(), NewElts); // Destroy the original elements. destroy_range(this->begin(), this->end()); -} +} -// Define this out-of-line to dissuade the C++ compiler from inlining it. -template <typename T, bool TriviallyCopyable> -void SmallVectorTemplateBase<T, TriviallyCopyable>::takeAllocationForGrow( - T *NewElts, size_t NewCapacity) { +// Define this out-of-line to dissuade the C++ compiler from inlining it. +template <typename T, bool TriviallyCopyable> +void SmallVectorTemplateBase<T, TriviallyCopyable>::takeAllocationForGrow( + T *NewElts, size_t NewCapacity) { // If this wasn't grown from the inline copy, deallocate the old space. if (!this->isSmall()) free(this->begin()); @@ -464,18 +464,18 @@ void SmallVectorTemplateBase<T, TriviallyCopyable>::takeAllocationForGrow( /// skipping destruction. template <typename T> class SmallVectorTemplateBase<T, true> : public SmallVectorTemplateCommon<T> { - friend class SmallVectorTemplateCommon<T>; - + friend class SmallVectorTemplateCommon<T>; + protected: - /// True if it's cheap enough to take parameters by value. Doing so avoids - /// overhead related to mitigations for reference invalidation. - static constexpr bool TakesParamByValue = sizeof(T) <= 2 * sizeof(void *); - - /// Either const T& or T, depending on whether it's cheap enough to take - /// parameters by value. - using ValueParamT = - typename std::conditional<TakesParamByValue, T, const T &>::type; - + /// True if it's cheap enough to take parameters by value. Doing so avoids + /// overhead related to mitigations for reference invalidation. + static constexpr bool TakesParamByValue = sizeof(T) <= 2 * sizeof(void *); + + /// Either const T& or T, depending on whether it's cheap enough to take + /// parameters by value. + using ValueParamT = + typename std::conditional<TakesParamByValue, T, const T &>::type; + SmallVectorTemplateBase(size_t Size) : SmallVectorTemplateCommon<T>(Size) {} // No need to do a destroy loop for POD's. @@ -516,43 +516,43 @@ protected: /// least one more element or MinSize if specified. void grow(size_t MinSize = 0) { this->grow_pod(MinSize, sizeof(T)); } - /// Reserve enough space to add one element, and return the updated element - /// pointer in case it was a reference to the storage. - const T *reserveForParamAndGetAddress(const T &Elt, size_t N = 1) { - return this->reserveForParamAndGetAddressImpl(this, Elt, N); - } - - /// Reserve enough space to add one element, and return the updated element - /// pointer in case it was a reference to the storage. - T *reserveForParamAndGetAddress(T &Elt, size_t N = 1) { - return const_cast<T *>( - this->reserveForParamAndGetAddressImpl(this, Elt, N)); - } - - /// Copy \p V or return a reference, depending on \a ValueParamT. - static ValueParamT forward_value_param(ValueParamT V) { return V; } - - void growAndAssign(size_t NumElts, T Elt) { - // Elt has been copied in case it's an internal reference, side-stepping - // reference invalidation problems without losing the realloc optimization. - this->set_size(0); - this->grow(NumElts); - std::uninitialized_fill_n(this->begin(), NumElts, Elt); - this->set_size(NumElts); - } - - template <typename... ArgTypes> T &growAndEmplaceBack(ArgTypes &&... Args) { - // Use push_back with a copy in case Args has an internal reference, - // side-stepping reference invalidation problems without losing the realloc - // optimization. - push_back(T(std::forward<ArgTypes>(Args)...)); - return this->back(); - } - + /// Reserve enough space to add one element, and return the updated element + /// pointer in case it was a reference to the storage. + const T *reserveForParamAndGetAddress(const T &Elt, size_t N = 1) { + return this->reserveForParamAndGetAddressImpl(this, Elt, N); + } + + /// Reserve enough space to add one element, and return the updated element + /// pointer in case it was a reference to the storage. + T *reserveForParamAndGetAddress(T &Elt, size_t N = 1) { + return const_cast<T *>( + this->reserveForParamAndGetAddressImpl(this, Elt, N)); + } + + /// Copy \p V or return a reference, depending on \a ValueParamT. + static ValueParamT forward_value_param(ValueParamT V) { return V; } + + void growAndAssign(size_t NumElts, T Elt) { + // Elt has been copied in case it's an internal reference, side-stepping + // reference invalidation problems without losing the realloc optimization. + this->set_size(0); + this->grow(NumElts); + std::uninitialized_fill_n(this->begin(), NumElts, Elt); + this->set_size(NumElts); + } + + template <typename... ArgTypes> T &growAndEmplaceBack(ArgTypes &&... Args) { + // Use push_back with a copy in case Args has an internal reference, + // side-stepping reference invalidation problems without losing the realloc + // optimization. + push_back(T(std::forward<ArgTypes>(Args)...)); + return this->back(); + } + public: - void push_back(ValueParamT Elt) { - const T *EltPtr = reserveForParamAndGetAddress(Elt); - memcpy(reinterpret_cast<void *>(this->end()), EltPtr, sizeof(T)); + void push_back(ValueParamT Elt) { + const T *EltPtr = reserveForParamAndGetAddress(Elt); + memcpy(reinterpret_cast<void *>(this->end()), EltPtr, sizeof(T)); this->set_size(this->size() + 1); } @@ -572,9 +572,9 @@ public: using size_type = typename SuperClass::size_type; protected: - using SmallVectorTemplateBase<T>::TakesParamByValue; - using ValueParamT = typename SuperClass::ValueParamT; - + using SmallVectorTemplateBase<T>::TakesParamByValue; + using ValueParamT = typename SuperClass::ValueParamT; + // Default ctor - Initialize to empty. explicit SmallVectorImpl(unsigned N) : SmallVectorTemplateBase<T>(N) {} @@ -594,38 +594,38 @@ public: this->Size = 0; } -private: - template <bool ForOverwrite> void resizeImpl(size_type N) { +private: + template <bool ForOverwrite> void resizeImpl(size_type N) { if (N < this->size()) { - this->pop_back_n(this->size() - N); + this->pop_back_n(this->size() - N); } else if (N > this->size()) { - this->reserve(N); + this->reserve(N); for (auto I = this->end(), E = this->begin() + N; I != E; ++I) - if (ForOverwrite) - new (&*I) T; - else - new (&*I) T(); + if (ForOverwrite) + new (&*I) T; + else + new (&*I) T(); this->set_size(N); } } -public: - void resize(size_type N) { resizeImpl<false>(N); } - - /// Like resize, but \ref T is POD, the new values won't be initialized. - void resize_for_overwrite(size_type N) { resizeImpl<true>(N); } - - void resize(size_type N, ValueParamT NV) { - if (N == this->size()) - return; - +public: + void resize(size_type N) { resizeImpl<false>(N); } + + /// Like resize, but \ref T is POD, the new values won't be initialized. + void resize_for_overwrite(size_type N) { resizeImpl<true>(N); } + + void resize(size_type N, ValueParamT NV) { + if (N == this->size()) + return; + if (N < this->size()) { - this->pop_back_n(this->size() - N); - return; + this->pop_back_n(this->size() - N); + return; } - - // N > this->size(). Defer to append. - this->append(N - this->size(), NV); + + // N > this->size(). Defer to append. + this->append(N - this->size(), NV); } void reserve(size_type N) { @@ -633,12 +633,12 @@ public: this->grow(N); } - void pop_back_n(size_type NumItems) { - assert(this->size() >= NumItems); - this->destroy_range(this->end() - NumItems, this->end()); - this->set_size(this->size() - NumItems); - } - + void pop_back_n(size_type NumItems) { + assert(this->size() >= NumItems); + this->destroy_range(this->end() - NumItems, this->end()); + this->set_size(this->size() - NumItems); + } + LLVM_NODISCARD T pop_back_val() { T Result = ::std::move(this->back()); this->pop_back(); @@ -653,17 +653,17 @@ public: typename std::iterator_traits<in_iter>::iterator_category, std::input_iterator_tag>::value>> void append(in_iter in_start, in_iter in_end) { - this->assertSafeToAddRange(in_start, in_end); + this->assertSafeToAddRange(in_start, in_end); size_type NumInputs = std::distance(in_start, in_end); - this->reserve(this->size() + NumInputs); + this->reserve(this->size() + NumInputs); this->uninitialized_copy(in_start, in_end, this->end()); this->set_size(this->size() + NumInputs); } /// Append \p NumInputs copies of \p Elt to the end. - void append(size_type NumInputs, ValueParamT Elt) { - const T *EltPtr = this->reserveForParamAndGetAddress(Elt, NumInputs); - std::uninitialized_fill_n(this->end(), NumInputs, *EltPtr); + void append(size_type NumInputs, ValueParamT Elt) { + const T *EltPtr = this->reserveForParamAndGetAddress(Elt, NumInputs); + std::uninitialized_fill_n(this->end(), NumInputs, *EltPtr); this->set_size(this->size() + NumInputs); } @@ -671,33 +671,33 @@ public: append(IL.begin(), IL.end()); } - void append(const SmallVectorImpl &RHS) { append(RHS.begin(), RHS.end()); } - - void assign(size_type NumElts, ValueParamT Elt) { - // Note that Elt could be an internal reference. - if (NumElts > this->capacity()) { - this->growAndAssign(NumElts, Elt); - return; - } - - // Assign over existing elements. - std::fill_n(this->begin(), std::min(NumElts, this->size()), Elt); - if (NumElts > this->size()) - std::uninitialized_fill_n(this->end(), NumElts - this->size(), Elt); - else if (NumElts < this->size()) - this->destroy_range(this->begin() + NumElts, this->end()); + void append(const SmallVectorImpl &RHS) { append(RHS.begin(), RHS.end()); } + + void assign(size_type NumElts, ValueParamT Elt) { + // Note that Elt could be an internal reference. + if (NumElts > this->capacity()) { + this->growAndAssign(NumElts, Elt); + return; + } + + // Assign over existing elements. + std::fill_n(this->begin(), std::min(NumElts, this->size()), Elt); + if (NumElts > this->size()) + std::uninitialized_fill_n(this->end(), NumElts - this->size(), Elt); + else if (NumElts < this->size()) + this->destroy_range(this->begin() + NumElts, this->end()); this->set_size(NumElts); } - // FIXME: Consider assigning over existing elements, rather than clearing & - // re-initializing them - for all assign(...) variants. - + // FIXME: Consider assigning over existing elements, rather than clearing & + // re-initializing them - for all assign(...) variants. + template <typename in_iter, typename = std::enable_if_t<std::is_convertible< typename std::iterator_traits<in_iter>::iterator_category, std::input_iterator_tag>::value>> void assign(in_iter in_start, in_iter in_end) { - this->assertSafeToReferenceAfterClear(in_start, in_end); + this->assertSafeToReferenceAfterClear(in_start, in_end); clear(); append(in_start, in_end); } @@ -707,13 +707,13 @@ public: append(IL); } - void assign(const SmallVectorImpl &RHS) { assign(RHS.begin(), RHS.end()); } - + void assign(const SmallVectorImpl &RHS) { assign(RHS.begin(), RHS.end()); } + iterator erase(const_iterator CI) { // Just cast away constness because this is a non-const member function. iterator I = const_cast<iterator>(CI); - assert(this->isReferenceToStorage(CI) && "Iterator to erase is out of bounds."); + assert(this->isReferenceToStorage(CI) && "Iterator to erase is out of bounds."); iterator N = I; // Shift all elts down one. @@ -728,7 +728,7 @@ public: iterator S = const_cast<iterator>(CS); iterator E = const_cast<iterator>(CE); - assert(this->isRangeInStorage(S, E) && "Range to erase is out of bounds."); + assert(this->isRangeInStorage(S, E) && "Range to erase is out of bounds."); iterator N = S; // Shift all elts down. @@ -739,26 +739,26 @@ public: return(N); } -private: - template <class ArgType> iterator insert_one_impl(iterator I, ArgType &&Elt) { - // Callers ensure that ArgType is derived from T. - static_assert( - std::is_same<std::remove_const_t<std::remove_reference_t<ArgType>>, - T>::value, - "ArgType must be derived from T!"); - +private: + template <class ArgType> iterator insert_one_impl(iterator I, ArgType &&Elt) { + // Callers ensure that ArgType is derived from T. + static_assert( + std::is_same<std::remove_const_t<std::remove_reference_t<ArgType>>, + T>::value, + "ArgType must be derived from T!"); + if (I == this->end()) { // Important special case for empty vector. - this->push_back(::std::forward<ArgType>(Elt)); + this->push_back(::std::forward<ArgType>(Elt)); return this->end()-1; } - assert(this->isReferenceToStorage(I) && "Insertion iterator is out of bounds."); + assert(this->isReferenceToStorage(I) && "Insertion iterator is out of bounds."); - // Grow if necessary. - size_t Index = I - this->begin(); - std::remove_reference_t<ArgType> *EltPtr = - this->reserveForParamAndGetAddress(Elt); - I = this->begin() + Index; + // Grow if necessary. + size_t Index = I - this->begin(); + std::remove_reference_t<ArgType> *EltPtr = + this->reserveForParamAndGetAddress(Elt); + I = this->begin() + Index; ::new ((void*) this->end()) T(::std::move(this->back())); // Push everything else over. @@ -766,26 +766,26 @@ private: this->set_size(this->size() + 1); // If we just moved the element we're inserting, be sure to update - // the reference (never happens if TakesParamByValue). - static_assert(!TakesParamByValue || std::is_same<ArgType, T>::value, - "ArgType must be 'T' when taking by value!"); - if (!TakesParamByValue && this->isReferenceToRange(EltPtr, I, this->end())) + // the reference (never happens if TakesParamByValue). + static_assert(!TakesParamByValue || std::is_same<ArgType, T>::value, + "ArgType must be 'T' when taking by value!"); + if (!TakesParamByValue && this->isReferenceToRange(EltPtr, I, this->end())) ++EltPtr; - *I = ::std::forward<ArgType>(*EltPtr); + *I = ::std::forward<ArgType>(*EltPtr); return I; } -public: - iterator insert(iterator I, T &&Elt) { - return insert_one_impl(I, this->forward_value_param(std::move(Elt))); - } - +public: + iterator insert(iterator I, T &&Elt) { + return insert_one_impl(I, this->forward_value_param(std::move(Elt))); + } + iterator insert(iterator I, const T &Elt) { - return insert_one_impl(I, this->forward_value_param(Elt)); + return insert_one_impl(I, this->forward_value_param(Elt)); } - iterator insert(iterator I, size_type NumToInsert, ValueParamT Elt) { + iterator insert(iterator I, size_type NumToInsert, ValueParamT Elt) { // Convert iterator to elt# to avoid invalidating iterator when we reserve() size_t InsertElt = I - this->begin(); @@ -794,11 +794,11 @@ public: return this->begin()+InsertElt; } - assert(this->isReferenceToStorage(I) && "Insertion iterator is out of bounds."); + assert(this->isReferenceToStorage(I) && "Insertion iterator is out of bounds."); - // Ensure there is enough space, and get the (maybe updated) address of - // Elt. - const T *EltPtr = this->reserveForParamAndGetAddress(Elt, NumToInsert); + // Ensure there is enough space, and get the (maybe updated) address of + // Elt. + const T *EltPtr = this->reserveForParamAndGetAddress(Elt, NumToInsert); // Uninvalidate the iterator. I = this->begin()+InsertElt; @@ -815,12 +815,12 @@ public: // Copy the existing elements that get replaced. std::move_backward(I, OldEnd-NumToInsert, OldEnd); - // If we just moved the element we're inserting, be sure to update - // the reference (never happens if TakesParamByValue). - if (!TakesParamByValue && I <= EltPtr && EltPtr < this->end()) - EltPtr += NumToInsert; - - std::fill_n(I, NumToInsert, *EltPtr); + // If we just moved the element we're inserting, be sure to update + // the reference (never happens if TakesParamByValue). + if (!TakesParamByValue && I <= EltPtr && EltPtr < this->end()) + EltPtr += NumToInsert; + + std::fill_n(I, NumToInsert, *EltPtr); return I; } @@ -833,16 +833,16 @@ public: size_t NumOverwritten = OldEnd-I; this->uninitialized_move(I, OldEnd, this->end()-NumOverwritten); - // If we just moved the element we're inserting, be sure to update - // the reference (never happens if TakesParamByValue). - if (!TakesParamByValue && I <= EltPtr && EltPtr < this->end()) - EltPtr += NumToInsert; - + // If we just moved the element we're inserting, be sure to update + // the reference (never happens if TakesParamByValue). + if (!TakesParamByValue && I <= EltPtr && EltPtr < this->end()) + EltPtr += NumToInsert; + // Replace the overwritten part. - std::fill_n(I, NumOverwritten, *EltPtr); + std::fill_n(I, NumOverwritten, *EltPtr); // Insert the non-overwritten middle part. - std::uninitialized_fill_n(OldEnd, NumToInsert - NumOverwritten, *EltPtr); + std::uninitialized_fill_n(OldEnd, NumToInsert - NumOverwritten, *EltPtr); return I; } @@ -859,11 +859,11 @@ public: return this->begin()+InsertElt; } - assert(this->isReferenceToStorage(I) && "Insertion iterator is out of bounds."); - - // Check that the reserve that follows doesn't invalidate the iterators. - this->assertSafeToAddRange(From, To); + assert(this->isReferenceToStorage(I) && "Insertion iterator is out of bounds."); + // Check that the reserve that follows doesn't invalidate the iterators. + this->assertSafeToAddRange(From, To); + size_t NumToInsert = std::distance(From, To); // Ensure there is enough space. @@ -914,8 +914,8 @@ public: template <typename... ArgTypes> reference emplace_back(ArgTypes &&... Args) { if (LLVM_UNLIKELY(this->size() >= this->capacity())) - return this->growAndEmplaceBack(std::forward<ArgTypes>(Args)...); - + return this->growAndEmplaceBack(std::forward<ArgTypes>(Args)...); + ::new ((void *)this->end()) T(std::forward<ArgTypes>(Args)...); this->set_size(this->size() + 1); return this->back(); @@ -950,8 +950,8 @@ void SmallVectorImpl<T>::swap(SmallVectorImpl<T> &RHS) { std::swap(this->Capacity, RHS.Capacity); return; } - this->reserve(RHS.size()); - RHS.reserve(this->size()); + this->reserve(RHS.size()); + RHS.reserve(this->size()); // Swap the shared elements. size_t NumShared = this->size(); @@ -1006,7 +1006,7 @@ SmallVectorImpl<T> &SmallVectorImpl<T>:: // FIXME: don't do this if they're efficiently moveable. if (this->capacity() < RHSSize) { // Destroy current elements. - this->clear(); + this->clear(); CurSize = 0; this->grow(RHSSize); } else if (CurSize) { @@ -1065,7 +1065,7 @@ SmallVectorImpl<T> &SmallVectorImpl<T>::operator=(SmallVectorImpl<T> &&RHS) { // elements. if (this->capacity() < RHSSize) { // Destroy current elements. - this->clear(); + this->clear(); CurSize = 0; this->grow(RHSSize); } else if (CurSize) { @@ -1088,90 +1088,90 @@ SmallVectorImpl<T> &SmallVectorImpl<T>::operator=(SmallVectorImpl<T> &&RHS) { /// to avoid allocating unnecessary storage. template <typename T, unsigned N> struct SmallVectorStorage { - alignas(T) char InlineElts[N * sizeof(T)]; + alignas(T) char InlineElts[N * sizeof(T)]; }; /// We need the storage to be properly aligned even for small-size of 0 so that /// the pointer math in \a SmallVectorTemplateCommon::getFirstEl() is /// well-defined. -template <typename T> struct alignas(T) SmallVectorStorage<T, 0> {}; - -/// Forward declaration of SmallVector so that -/// calculateSmallVectorDefaultInlinedElements can reference -/// `sizeof(SmallVector<T, 0>)`. -template <typename T, unsigned N> class LLVM_GSL_OWNER SmallVector; - -/// Helper class for calculating the default number of inline elements for -/// `SmallVector<T>`. -/// -/// This should be migrated to a constexpr function when our minimum -/// compiler support is enough for multi-statement constexpr functions. -template <typename T> struct CalculateSmallVectorDefaultInlinedElements { - // Parameter controlling the default number of inlined elements - // for `SmallVector<T>`. - // - // The default number of inlined elements ensures that - // 1. There is at least one inlined element. - // 2. `sizeof(SmallVector<T>) <= kPreferredSmallVectorSizeof` unless - // it contradicts 1. - static constexpr size_t kPreferredSmallVectorSizeof = 64; - - // static_assert that sizeof(T) is not "too big". - // - // Because our policy guarantees at least one inlined element, it is possible - // for an arbitrarily large inlined element to allocate an arbitrarily large - // amount of inline storage. We generally consider it an antipattern for a - // SmallVector to allocate an excessive amount of inline storage, so we want - // to call attention to these cases and make sure that users are making an - // intentional decision if they request a lot of inline storage. - // - // We want this assertion to trigger in pathological cases, but otherwise - // not be too easy to hit. To accomplish that, the cutoff is actually somewhat - // larger than kPreferredSmallVectorSizeof (otherwise, - // `SmallVector<SmallVector<T>>` would be one easy way to trip it, and that - // pattern seems useful in practice). - // - // One wrinkle is that this assertion is in theory non-portable, since - // sizeof(T) is in general platform-dependent. However, we don't expect this - // to be much of an issue, because most LLVM development happens on 64-bit - // hosts, and therefore sizeof(T) is expected to *decrease* when compiled for - // 32-bit hosts, dodging the issue. The reverse situation, where development - // happens on a 32-bit host and then fails due to sizeof(T) *increasing* on a - // 64-bit host, is expected to be very rare. - static_assert( - sizeof(T) <= 256, - "You are trying to use a default number of inlined elements for " - "`SmallVector<T>` but `sizeof(T)` is really big! Please use an " - "explicit number of inlined elements with `SmallVector<T, N>` to make " - "sure you really want that much inline storage."); - - // Discount the size of the header itself when calculating the maximum inline - // bytes. - static constexpr size_t PreferredInlineBytes = - kPreferredSmallVectorSizeof - sizeof(SmallVector<T, 0>); - static constexpr size_t NumElementsThatFit = PreferredInlineBytes / sizeof(T); - static constexpr size_t value = - NumElementsThatFit == 0 ? 1 : NumElementsThatFit; -}; - +template <typename T> struct alignas(T) SmallVectorStorage<T, 0> {}; + +/// Forward declaration of SmallVector so that +/// calculateSmallVectorDefaultInlinedElements can reference +/// `sizeof(SmallVector<T, 0>)`. +template <typename T, unsigned N> class LLVM_GSL_OWNER SmallVector; + +/// Helper class for calculating the default number of inline elements for +/// `SmallVector<T>`. +/// +/// This should be migrated to a constexpr function when our minimum +/// compiler support is enough for multi-statement constexpr functions. +template <typename T> struct CalculateSmallVectorDefaultInlinedElements { + // Parameter controlling the default number of inlined elements + // for `SmallVector<T>`. + // + // The default number of inlined elements ensures that + // 1. There is at least one inlined element. + // 2. `sizeof(SmallVector<T>) <= kPreferredSmallVectorSizeof` unless + // it contradicts 1. + static constexpr size_t kPreferredSmallVectorSizeof = 64; + + // static_assert that sizeof(T) is not "too big". + // + // Because our policy guarantees at least one inlined element, it is possible + // for an arbitrarily large inlined element to allocate an arbitrarily large + // amount of inline storage. We generally consider it an antipattern for a + // SmallVector to allocate an excessive amount of inline storage, so we want + // to call attention to these cases and make sure that users are making an + // intentional decision if they request a lot of inline storage. + // + // We want this assertion to trigger in pathological cases, but otherwise + // not be too easy to hit. To accomplish that, the cutoff is actually somewhat + // larger than kPreferredSmallVectorSizeof (otherwise, + // `SmallVector<SmallVector<T>>` would be one easy way to trip it, and that + // pattern seems useful in practice). + // + // One wrinkle is that this assertion is in theory non-portable, since + // sizeof(T) is in general platform-dependent. However, we don't expect this + // to be much of an issue, because most LLVM development happens on 64-bit + // hosts, and therefore sizeof(T) is expected to *decrease* when compiled for + // 32-bit hosts, dodging the issue. The reverse situation, where development + // happens on a 32-bit host and then fails due to sizeof(T) *increasing* on a + // 64-bit host, is expected to be very rare. + static_assert( + sizeof(T) <= 256, + "You are trying to use a default number of inlined elements for " + "`SmallVector<T>` but `sizeof(T)` is really big! Please use an " + "explicit number of inlined elements with `SmallVector<T, N>` to make " + "sure you really want that much inline storage."); + + // Discount the size of the header itself when calculating the maximum inline + // bytes. + static constexpr size_t PreferredInlineBytes = + kPreferredSmallVectorSizeof - sizeof(SmallVector<T, 0>); + static constexpr size_t NumElementsThatFit = PreferredInlineBytes / sizeof(T); + static constexpr size_t value = + NumElementsThatFit == 0 ? 1 : NumElementsThatFit; +}; + /// This is a 'vector' (really, a variable-sized array), optimized /// for the case when the array is small. It contains some number of elements /// in-place, which allows it to avoid heap allocation when the actual number of /// elements is below that threshold. This allows normal "small" cases to be /// fast without losing generality for large inputs. /// -/// \note -/// In the absence of a well-motivated choice for the number of inlined -/// elements \p N, it is recommended to use \c SmallVector<T> (that is, -/// omitting the \p N). This will choose a default number of inlined elements -/// reasonable for allocation on the stack (for example, trying to keep \c -/// sizeof(SmallVector<T>) around 64 bytes). -/// -/// \warning This does not attempt to be exception safe. +/// \note +/// In the absence of a well-motivated choice for the number of inlined +/// elements \p N, it is recommended to use \c SmallVector<T> (that is, +/// omitting the \p N). This will choose a default number of inlined elements +/// reasonable for allocation on the stack (for example, trying to keep \c +/// sizeof(SmallVector<T>) around 64 bytes). /// -/// \see https://llvm.org/docs/ProgrammersManual.html#llvm-adt-smallvector-h -template <typename T, - unsigned N = CalculateSmallVectorDefaultInlinedElements<T>::value> +/// \warning This does not attempt to be exception safe. +/// +/// \see https://llvm.org/docs/ProgrammersManual.html#llvm-adt-smallvector-h +template <typename T, + unsigned N = CalculateSmallVectorDefaultInlinedElements<T>::value> class LLVM_GSL_OWNER SmallVector : public SmallVectorImpl<T>, SmallVectorStorage<T, N> { public: @@ -1210,7 +1210,7 @@ public: SmallVectorImpl<T>::operator=(RHS); } - SmallVector &operator=(const SmallVector &RHS) { + SmallVector &operator=(const SmallVector &RHS) { SmallVectorImpl<T>::operator=(RHS); return *this; } @@ -1225,17 +1225,17 @@ public: SmallVectorImpl<T>::operator=(::std::move(RHS)); } - SmallVector &operator=(SmallVector &&RHS) { + SmallVector &operator=(SmallVector &&RHS) { SmallVectorImpl<T>::operator=(::std::move(RHS)); return *this; } - SmallVector &operator=(SmallVectorImpl<T> &&RHS) { + SmallVector &operator=(SmallVectorImpl<T> &&RHS) { SmallVectorImpl<T>::operator=(::std::move(RHS)); return *this; } - SmallVector &operator=(std::initializer_list<T> IL) { + SmallVector &operator=(std::initializer_list<T> IL) { this->assign(IL); return *this; } diff --git a/contrib/libs/llvm12/include/llvm/ADT/SparseSet.h b/contrib/libs/llvm12/include/llvm/ADT/SparseSet.h index f1cec90a3c..c4f9a19ef7 100644 --- a/contrib/libs/llvm12/include/llvm/ADT/SparseSet.h +++ b/contrib/libs/llvm12/include/llvm/ADT/SparseSet.h @@ -236,15 +236,15 @@ public: return const_cast<SparseSet*>(this)->findIndex(KeyIndexOf(Key)); } - /// Check if the set contains the given \c Key. - /// - /// @param Key A valid key to find. - bool contains(const KeyT &Key) const { return find(Key) == end() ? 0 : 1; } - + /// Check if the set contains the given \c Key. + /// + /// @param Key A valid key to find. + bool contains(const KeyT &Key) const { return find(Key) == end() ? 0 : 1; } + /// count - Returns 1 if this set contains an element identified by Key, /// 0 otherwise. /// - size_type count(const KeyT &Key) const { return contains(Key) ? 1 : 0; } + size_type count(const KeyT &Key) const { return contains(Key) ? 1 : 0; } /// insert - Attempts to insert a new element. /// diff --git a/contrib/libs/llvm12/include/llvm/ADT/Statistic.h b/contrib/libs/llvm12/include/llvm/ADT/Statistic.h index ad584c447e..b8625958c8 100644 --- a/contrib/libs/llvm12/include/llvm/ADT/Statistic.h +++ b/contrib/libs/llvm12/include/llvm/ADT/Statistic.h @@ -43,8 +43,8 @@ // configure time. #if !defined(NDEBUG) || LLVM_FORCE_ENABLE_STATS #define LLVM_ENABLE_STATS 1 -#else -#define LLVM_ENABLE_STATS 0 +#else +#define LLVM_ENABLE_STATS 0 #endif namespace llvm { diff --git a/contrib/libs/llvm12/include/llvm/ADT/StringExtras.h b/contrib/libs/llvm12/include/llvm/ADT/StringExtras.h index 1ddaf13978..d7332d08a6 100644 --- a/contrib/libs/llvm12/include/llvm/ADT/StringExtras.h +++ b/contrib/libs/llvm12/include/llvm/ADT/StringExtras.h @@ -73,29 +73,29 @@ inline ArrayRef<uint8_t> arrayRefFromStringRef(StringRef Input) { /// /// If \p C is not a valid hex digit, -1U is returned. inline unsigned hexDigitValue(char C) { - struct HexTable { - unsigned LUT[255] = {}; - constexpr HexTable() { - // Default initialize everything to invalid. - for (int i = 0; i < 255; ++i) - LUT[i] = ~0U; - // Initialize `0`-`9`. - for (int i = 0; i < 10; ++i) - LUT['0' + i] = i; - // Initialize `A`-`F` and `a`-`f`. - for (int i = 0; i < 6; ++i) - LUT['A' + i] = LUT['a' + i] = 10 + i; - } - }; - constexpr HexTable Table; - return Table.LUT[static_cast<unsigned char>(C)]; + struct HexTable { + unsigned LUT[255] = {}; + constexpr HexTable() { + // Default initialize everything to invalid. + for (int i = 0; i < 255; ++i) + LUT[i] = ~0U; + // Initialize `0`-`9`. + for (int i = 0; i < 10; ++i) + LUT['0' + i] = i; + // Initialize `A`-`F` and `a`-`f`. + for (int i = 0; i < 6; ++i) + LUT['A' + i] = LUT['a' + i] = 10 + i; + } + }; + constexpr HexTable Table; + return Table.LUT[static_cast<unsigned char>(C)]; } /// Checks if character \p C is one of the 10 decimal digits. inline bool isDigit(char C) { return C >= '0' && C <= '9'; } /// Checks if character \p C is a hexadecimal numeric character. -inline bool isHexDigit(char C) { return hexDigitValue(C) != ~0U; } +inline bool isHexDigit(char C) { return hexDigitValue(C) != ~0U; } /// Checks if character \p C is a valid letter as classified by "C" locale. inline bool isAlpha(char C) { @@ -184,70 +184,70 @@ inline std::string toHex(ArrayRef<uint8_t> Input, bool LowerCase = false) { return toHex(toStringRef(Input), LowerCase); } -/// Store the binary representation of the two provided values, \p MSB and -/// \p LSB, that make up the nibbles of a hexadecimal digit. If \p MSB or \p LSB -/// do not correspond to proper nibbles of a hexadecimal digit, this method -/// returns false. Otherwise, returns true. -inline bool tryGetHexFromNibbles(char MSB, char LSB, uint8_t &Hex) { +/// Store the binary representation of the two provided values, \p MSB and +/// \p LSB, that make up the nibbles of a hexadecimal digit. If \p MSB or \p LSB +/// do not correspond to proper nibbles of a hexadecimal digit, this method +/// returns false. Otherwise, returns true. +inline bool tryGetHexFromNibbles(char MSB, char LSB, uint8_t &Hex) { unsigned U1 = hexDigitValue(MSB); unsigned U2 = hexDigitValue(LSB); - if (U1 == ~0U || U2 == ~0U) - return false; - - Hex = static_cast<uint8_t>((U1 << 4) | U2); - return true; -} - -/// Return the binary representation of the two provided values, \p MSB and -/// \p LSB, that make up the nibbles of a hexadecimal digit. -inline uint8_t hexFromNibbles(char MSB, char LSB) { - uint8_t Hex = 0; - bool GotHex = tryGetHexFromNibbles(MSB, LSB, Hex); - (void)GotHex; - assert(GotHex && "MSB and/or LSB do not correspond to hex digits"); - return Hex; -} - -/// Convert hexadecimal string \p Input to its binary representation and store -/// the result in \p Output. Returns true if the binary representation could be -/// converted from the hexadecimal string. Returns false if \p Input contains -/// non-hexadecimal digits. The output string is half the size of \p Input. -inline bool tryGetFromHex(StringRef Input, std::string &Output) { + if (U1 == ~0U || U2 == ~0U) + return false; + + Hex = static_cast<uint8_t>((U1 << 4) | U2); + return true; +} + +/// Return the binary representation of the two provided values, \p MSB and +/// \p LSB, that make up the nibbles of a hexadecimal digit. +inline uint8_t hexFromNibbles(char MSB, char LSB) { + uint8_t Hex = 0; + bool GotHex = tryGetHexFromNibbles(MSB, LSB, Hex); + (void)GotHex; + assert(GotHex && "MSB and/or LSB do not correspond to hex digits"); + return Hex; +} + +/// Convert hexadecimal string \p Input to its binary representation and store +/// the result in \p Output. Returns true if the binary representation could be +/// converted from the hexadecimal string. Returns false if \p Input contains +/// non-hexadecimal digits. The output string is half the size of \p Input. +inline bool tryGetFromHex(StringRef Input, std::string &Output) { if (Input.empty()) - return true; + return true; Output.reserve((Input.size() + 1) / 2); if (Input.size() % 2 == 1) { - uint8_t Hex = 0; - if (!tryGetHexFromNibbles('0', Input.front(), Hex)) - return false; - - Output.push_back(Hex); + uint8_t Hex = 0; + if (!tryGetHexFromNibbles('0', Input.front(), Hex)) + return false; + + Output.push_back(Hex); Input = Input.drop_front(); } assert(Input.size() % 2 == 0); while (!Input.empty()) { - uint8_t Hex = 0; - if (!tryGetHexFromNibbles(Input[0], Input[1], Hex)) - return false; - + uint8_t Hex = 0; + if (!tryGetHexFromNibbles(Input[0], Input[1], Hex)) + return false; + Output.push_back(Hex); Input = Input.drop_front(2); } - return true; -} - -/// Convert hexadecimal string \p Input to its binary representation. -/// The return string is half the size of \p Input. -inline std::string fromHex(StringRef Input) { - std::string Hex; - bool GotHex = tryGetFromHex(Input, Hex); - (void)GotHex; - assert(GotHex && "Input contains non hex digits"); - return Hex; -} - + return true; +} + +/// Convert hexadecimal string \p Input to its binary representation. +/// The return string is half the size of \p Input. +inline std::string fromHex(StringRef Input) { + std::string Hex; + bool GotHex = tryGetFromHex(Input, Hex); + (void)GotHex; + assert(GotHex && "Input contains non hex digits"); + return Hex; +} + /// Convert the string \p S to an integer of the specified type using /// the radix \p Base. If \p Base is 0, auto-detects the radix. /// Returns true if the number was successfully converted, false otherwise. @@ -298,7 +298,7 @@ inline std::string utostr(uint64_t X, bool isNeg = false) { inline std::string itostr(int64_t X) { if (X < 0) - return utostr(static_cast<uint64_t>(1) + ~static_cast<uint64_t>(X), true); + return utostr(static_cast<uint64_t>(1) + ~static_cast<uint64_t>(X), true); else return utostr(static_cast<uint64_t>(X)); } @@ -391,16 +391,16 @@ inline std::string join_impl(IteratorT Begin, IteratorT End, size_t Len = (std::distance(Begin, End) - 1) * Separator.size(); for (IteratorT I = Begin; I != End; ++I) - Len += (*I).size(); + Len += (*I).size(); S.reserve(Len); - size_t PrevCapacity = S.capacity(); - (void)PrevCapacity; + size_t PrevCapacity = S.capacity(); + (void)PrevCapacity; S += (*Begin); while (++Begin != End) { S += Separator; S += (*Begin); } - assert(PrevCapacity == S.capacity() && "String grew during building"); + assert(PrevCapacity == S.capacity() && "String grew during building"); return S; } @@ -472,30 +472,30 @@ inline std::string join_items(Sep Separator, Args &&... Items) { return Result; } -/// A helper class to return the specified delimiter string after the first -/// invocation of operator StringRef(). Used to generate a comma-separated -/// list from a loop like so: -/// -/// \code -/// ListSeparator LS; -/// for (auto &I : C) -/// OS << LS << I.getName(); -/// \end -class ListSeparator { - bool First = true; - StringRef Separator; - -public: - ListSeparator(StringRef Separator = ", ") : Separator(Separator) {} - operator StringRef() { - if (First) { - First = false; - return {}; - } - return Separator; - } -}; - +/// A helper class to return the specified delimiter string after the first +/// invocation of operator StringRef(). Used to generate a comma-separated +/// list from a loop like so: +/// +/// \code +/// ListSeparator LS; +/// for (auto &I : C) +/// OS << LS << I.getName(); +/// \end +class ListSeparator { + bool First = true; + StringRef Separator; + +public: + ListSeparator(StringRef Separator = ", ") : Separator(Separator) {} + operator StringRef() { + if (First) { + First = false; + return {}; + } + return Separator; + } +}; + } // end namespace llvm #endif // LLVM_ADT_STRINGEXTRAS_H diff --git a/contrib/libs/llvm12/include/llvm/ADT/StringMap.h b/contrib/libs/llvm12/include/llvm/ADT/StringMap.h index 155a60fd2c..7e45f1b079 100644 --- a/contrib/libs/llvm12/include/llvm/ADT/StringMap.h +++ b/contrib/libs/llvm12/include/llvm/ADT/StringMap.h @@ -85,12 +85,12 @@ protected: void init(unsigned Size); public: - static constexpr uintptr_t TombstoneIntVal = - static_cast<uintptr_t>(-1) - << PointerLikeTypeTraits<StringMapEntryBase *>::NumLowBitsAvailable; - + static constexpr uintptr_t TombstoneIntVal = + static_cast<uintptr_t>(-1) + << PointerLikeTypeTraits<StringMapEntryBase *>::NumLowBitsAvailable; + static StringMapEntryBase *getTombstoneVal() { - return reinterpret_cast<StringMapEntryBase *>(TombstoneIntVal); + return reinterpret_cast<StringMapEntryBase *>(TombstoneIntVal); } unsigned getNumBuckets() const { return NumBuckets; } diff --git a/contrib/libs/llvm12/include/llvm/ADT/StringSet.h b/contrib/libs/llvm12/include/llvm/ADT/StringSet.h index 8e957f7bc7..c61360c61b 100644 --- a/contrib/libs/llvm12/include/llvm/ADT/StringSet.h +++ b/contrib/libs/llvm12/include/llvm/ADT/StringSet.h @@ -52,9 +52,9 @@ public: insert(const StringMapEntry<ValueTy> &mapEntry) { return insert(mapEntry.getKey()); } - - /// Check if the set contains the given \c key. - bool contains(StringRef key) const { return Base::FindKey(key) != -1; } + + /// Check if the set contains the given \c key. + bool contains(StringRef key) const { return Base::FindKey(key) != -1; } }; } // end namespace llvm diff --git a/contrib/libs/llvm12/include/llvm/ADT/Triple.h b/contrib/libs/llvm12/include/llvm/ADT/Triple.h index 32587a9fc5..ebfabb9374 100644 --- a/contrib/libs/llvm12/include/llvm/ADT/Triple.h +++ b/contrib/libs/llvm12/include/llvm/ADT/Triple.h @@ -63,7 +63,7 @@ public: avr, // AVR: Atmel AVR microcontroller bpfel, // eBPF or extended BPF or 64-bit BPF (little endian) bpfeb, // eBPF or extended BPF or 64-bit BPF (big endian) - csky, // CSKY: csky + csky, // CSKY: csky hexagon, // Hexagon: hexagon mips, // MIPS: mips, mipsallegrex, mipsr6 mipsel, // MIPSEL: mipsel, mipsallegrexe, mipsr6el @@ -71,7 +71,7 @@ public: mips64el, // MIPS64EL: mips64el, mips64r6el, mipsn32el, mipsn32r6el msp430, // MSP430: msp430 ppc, // PPC: powerpc - ppcle, // PPCLE: powerpc (little endian) + ppcle, // PPCLE: powerpc (little endian) ppc64, // PPC64: powerpc64, ppu ppc64le, // PPC64LE: powerpc64le r600, // R600: AMD GPUs HD2XXX - HD6XXX @@ -112,7 +112,7 @@ public: enum SubArchType { NoSubArch, - ARMSubArch_v8_7a, + ARMSubArch_v8_7a, ARMSubArch_v8_6a, ARMSubArch_v8_5a, ARMSubArch_v8_4a, @@ -138,8 +138,8 @@ public: ARMSubArch_v5te, ARMSubArch_v4t, - AArch64SubArch_arm64e, - + AArch64SubArch_arm64e, + KalimbaSubArch_v3, KalimbaSubArch_v4, KalimbaSubArch_v5, @@ -185,7 +185,7 @@ public: OpenBSD, Solaris, Win32, - ZOS, + ZOS, Haiku, Minix, RTEMS, @@ -216,7 +216,7 @@ public: GNUEABI, GNUEABIHF, GNUX32, - GNUILP32, + GNUILP32, CODE16, EABI, EABIHF, @@ -238,7 +238,7 @@ public: COFF, ELF, - GOFF, + GOFF, MachO, Wasm, XCOFF, @@ -483,8 +483,8 @@ public: return getSubArch() == Triple::ARMSubArch_v7k; } - bool isOSzOS() const { return getOS() == Triple::ZOS; } - + bool isOSzOS() const { return getOS() == Triple::ZOS; } + /// isOSDarwin - Is this a "Darwin" OS (macOS, iOS, tvOS or watchOS). bool isOSDarwin() const { return isMacOSX() || isiOS() || isWatchOS(); @@ -498,12 +498,12 @@ public: return getEnvironment() == Triple::MacABI; } - /// Returns true for targets that run on a macOS machine. - bool isTargetMachineMac() const { - return isMacOSX() || (isOSDarwin() && (isSimulatorEnvironment() || - isMacCatalystEnvironment())); - } - + /// Returns true for targets that run on a macOS machine. + bool isTargetMachineMac() const { + return isMacOSX() || (isOSDarwin() && (isSimulatorEnvironment() || + isMacCatalystEnvironment())); + } + bool isOSNetBSD() const { return getOS() == Triple::NetBSD; } @@ -643,9 +643,9 @@ public: return getObjectFormat() == Triple::COFF; } - /// Tests whether the OS uses the GOFF binary format. - bool isOSBinFormatGOFF() const { return getObjectFormat() == Triple::GOFF; } - + /// Tests whether the OS uses the GOFF binary format. + bool isOSBinFormatGOFF() const { return getObjectFormat() == Triple::GOFF; } + /// Tests whether the environment is MachO. bool isOSBinFormatMachO() const { return getObjectFormat() == Triple::MachO; @@ -726,22 +726,22 @@ public: /// Tests whether the target is AArch64 (little and big endian). bool isAArch64() const { - return getArch() == Triple::aarch64 || getArch() == Triple::aarch64_be || - getArch() == Triple::aarch64_32; - } - - /// Tests whether the target is AArch64 and pointers are the size specified by - /// \p PointerWidth. - bool isAArch64(int PointerWidth) const { - assert(PointerWidth == 64 || PointerWidth == 32); - if (!isAArch64()) - return false; - return getArch() == Triple::aarch64_32 || - getEnvironment() == Triple::GNUILP32 - ? PointerWidth == 32 - : PointerWidth == 64; - } - + return getArch() == Triple::aarch64 || getArch() == Triple::aarch64_be || + getArch() == Triple::aarch64_32; + } + + /// Tests whether the target is AArch64 and pointers are the size specified by + /// \p PointerWidth. + bool isAArch64(int PointerWidth) const { + assert(PointerWidth == 64 || PointerWidth == 32); + if (!isAArch64()) + return false; + return getArch() == Triple::aarch64_32 || + getEnvironment() == Triple::GNUILP32 + ? PointerWidth == 32 + : PointerWidth == 64; + } + /// Tests whether the target is MIPS 32-bit (little and big endian). bool isMIPS32() const { return getArch() == Triple::mips || getArch() == Triple::mipsel; @@ -757,17 +757,17 @@ public: return isMIPS32() || isMIPS64(); } - /// Tests whether the target is PowerPC (32- or 64-bit LE or BE). - bool isPPC() const { - return getArch() == Triple::ppc || getArch() == Triple::ppc64 || - getArch() == Triple::ppcle || getArch() == Triple::ppc64le; - } - - /// Tests whether the target is 32-bit PowerPC (little and big endian). - bool isPPC32() const { - return getArch() == Triple::ppc || getArch() == Triple::ppcle; - } - + /// Tests whether the target is PowerPC (32- or 64-bit LE or BE). + bool isPPC() const { + return getArch() == Triple::ppc || getArch() == Triple::ppc64 || + getArch() == Triple::ppcle || getArch() == Triple::ppc64le; + } + + /// Tests whether the target is 32-bit PowerPC (little and big endian). + bool isPPC32() const { + return getArch() == Triple::ppc || getArch() == Triple::ppcle; + } + /// Tests whether the target is 64-bit PowerPC (little and big endian). bool isPPC64() const { return getArch() == Triple::ppc64 || getArch() == Triple::ppc64le; @@ -798,17 +798,17 @@ public: return getArch() == Triple::wasm32 || getArch() == Triple::wasm64; } - // Tests whether the target is CSKY - bool isCSKY() const { - return getArch() == Triple::csky; - } - - /// Tests whether the target is the Apple "arm64e" AArch64 subarch. - bool isArm64e() const { - return getArch() == Triple::aarch64 && - getSubArch() == Triple::AArch64SubArch_arm64e; - } - + // Tests whether the target is CSKY + bool isCSKY() const { + return getArch() == Triple::csky; + } + + /// Tests whether the target is the Apple "arm64e" AArch64 subarch. + bool isArm64e() const { + return getArch() == Triple::aarch64 && + getSubArch() == Triple::AArch64SubArch_arm64e; + } + /// Tests whether the target supports comdat bool supportsCOMDAT() const { return !(isOSBinFormatMachO() || isOSBinFormatXCOFF()); @@ -819,14 +819,14 @@ public: return isAndroid() || isOSOpenBSD() || isWindowsCygwinEnvironment(); } - /// Tests whether the target uses -data-sections as default. - bool hasDefaultDataSections() const { - return isOSBinFormatXCOFF() || isWasm(); - } - - /// Tests if the environment supports dllimport/export annotations. - bool hasDLLImportExport() const { return isOSWindows() || isPS4CPU(); } - + /// Tests whether the target uses -data-sections as default. + bool hasDefaultDataSections() const { + return isOSBinFormatXCOFF() || isWasm(); + } + + /// Tests if the environment supports dllimport/export annotations. + bool hasDLLImportExport() const { return isOSWindows() || isPS4CPU(); } + /// @} /// @name Mutators /// @{ diff --git a/contrib/libs/llvm12/include/llvm/ADT/simple_ilist.h b/contrib/libs/llvm12/include/llvm/ADT/simple_ilist.h index 619f3f466b..8d06d0c899 100644 --- a/contrib/libs/llvm12/include/llvm/ADT/simple_ilist.h +++ b/contrib/libs/llvm12/include/llvm/ADT/simple_ilist.h @@ -35,8 +35,8 @@ namespace llvm { /// This is a simple intrusive list for a \c T that inherits from \c /// ilist_node<T>. The list never takes ownership of anything inserted in it. /// -/// Unlike \a iplist<T> and \a ilist<T>, \a simple_ilist<T> never deletes -/// values, and has no callback traits. +/// Unlike \a iplist<T> and \a ilist<T>, \a simple_ilist<T> never deletes +/// values, and has no callback traits. /// /// The API for adding nodes include \a push_front(), \a push_back(), and \a /// insert(). These all take values by reference (not by pointer), except for @@ -59,7 +59,7 @@ namespace llvm { /// to calling \a std::for_each() on the range to be discarded. /// /// The currently available \p Options customize the nodes in the list. The -/// same options must be specified in the \a ilist_node instantiation for +/// same options must be specified in the \a ilist_node instantiation for /// compatibility (although the order is irrelevant). /// \li Use \a ilist_tag to designate which ilist_node for a given \p T this /// list should use. This is useful if a type \p T is part of multiple, |