Compare commits

...

17 Commits

Author SHA1 Message Date
3a3f147cd2 fix compile issue again 2025-11-11 12:11:59 -08:00
137c5c4457 fix lint 2025-11-10 13:38:35 -08:00
d8ed3c065e fix compile 2025-11-09 07:09:01 -08:00
5219604712 Merge branch 'main' into feature/migrate-constexpr-function-for-smallvector 2025-11-09 06:51:28 -08:00
867a3767ad fix compile issue 2025-11-07 14:13:50 -08:00
cbd72e46ec Merge branch 'main' into feature/migrate-constexpr-function-for-smallvector 2025-11-07 13:42:44 -08:00
4e18b15966 fix compile error in windows 2025-11-05 16:54:54 -08:00
10302df3a2 Merge branch 'pytorch:main' into feature/migrate-constexpr-function-for-smallvector 2025-11-04 10:55:04 -05:00
bfa41e91b0 fix ; error 2025-10-16 08:52:41 -07:00
77f0a9c8fb Merge branch 'pytorch:main' into feature/migrate-constexpr-function-for-smallvector 2025-10-15 15:19:46 -04:00
97088cc945 Merge branch 'pytorch:main' into feature/migrate-constexpr-function-for-smallvector 2024-12-31 19:09:59 -05:00
6c3cb80b43 Merge branch 'pytorch:main' into feature/migrate-constexpr-function-for-smallvector 2024-11-01 11:20:07 -04:00
e001ed29e0 Merge branch 'pytorch:main' into feature/migrate-constexpr-function-for-smallvector 2024-09-27 20:07:37 -04:00
a73b32fa54 Merge branch 'pytorch:main' into feature/migrate-constexpr-function-for-smallvector 2024-08-07 20:46:35 +08:00
94b7032de4 Merge remote-tracking branch 'origin/main' into feature/migrate-constexpr-function-for-smallvector 2024-05-31 14:20:05 +08:00
21793e3070 fix: no template named 'CalculateSmallVectorDefaultInlinedElements' 2024-05-29 10:50:08 +08:00
0ba4e70dac Migrate CalculateSmallVectorDefaultInlinedElements to constexpr Function for SmallVector 2024-05-29 10:04:57 +08:00

View File

@ -1192,19 +1192,13 @@ struct SmallVectorStorage {
template <typename T>
struct alignas(T) SmallVectorStorage<T, 0> {};
/// Forward declaration of SmallVector so that
/// calculateSmallVectorDefaultInlinedElements can reference
/// `sizeof(SmallVector<T, 0>)`.
/// Forward declaration of SmallVector.
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.
/// Calculating the default number of inline elements for `SmallVector<T>`.
template <typename T>
struct CalculateSmallVectorDefaultInlinedElements {
constexpr size_t calculateSmallVectorDefaultInlinedElements() {
// Parameter controlling the default number of inlined elements
// for `SmallVector<T>`.
//
@ -1212,7 +1206,7 @@ struct CalculateSmallVectorDefaultInlinedElements {
// 1. There is at least one inlined element.
// 2. `sizeof(SmallVector<T>) <= kPreferredSmallVectorSizeof` unless
// it contradicts 1.
static constexpr size_t kPreferredSmallVectorSizeof = 64;
constexpr size_t kPreferredSmallVectorSizeof = 64;
// static_assert that sizeof(T) is not "too big".
//
@ -1245,12 +1239,15 @@ struct CalculateSmallVectorDefaultInlinedElements {
// 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;
};
constexpr size_t HeaderOffset =
offsetof(SmallVectorAlignmentAndSize<T>, FirstEl);
constexpr size_t PreferredInlineBytes =
(HeaderOffset >= kPreferredSmallVectorSizeof)
? size_t(0)
: (kPreferredSmallVectorSizeof - HeaderOffset);
constexpr size_t NumElementsThatFit = PreferredInlineBytes / sizeof(T);
return 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
@ -1270,7 +1267,7 @@ struct CalculateSmallVectorDefaultInlinedElements {
/// \see https://llvm.org/docs/ProgrammersManual.html#llvm-adt-smallvector-h
template <
typename T,
unsigned N = CalculateSmallVectorDefaultInlinedElements<T>::value>
unsigned N = calculateSmallVectorDefaultInlinedElements<T>()>
class /* LLVM_GSL_OWNER */ SmallVector : public SmallVectorImpl<T>,
SmallVectorStorage<T, N> {
public:
@ -1437,9 +1434,7 @@ SmallVector<ValueTypeFromRangeType<R>, Size> to_vector(R&& Range) {
template <typename R>
SmallVector<
ValueTypeFromRangeType<R>,
CalculateSmallVectorDefaultInlinedElements<
ValueTypeFromRangeType<R>>::value>
// NOLINTNEXTLINE(cppcoreguidelines-missing-std-forward)
calculateSmallVectorDefaultInlinedElements<ValueTypeFromRangeType<R>>()>
to_vector(R&& Range) {
return {std::begin(Range), std::end(Range)};
}