diff options
Diffstat (limited to 'llvm/include')
-rw-r--r-- | llvm/include/llvm/ADT/BitmaskEnum.h | 7 | ||||
-rw-r--r-- | llvm/include/llvm/ADT/PointerUnion.h | 2 | ||||
-rw-r--r-- | llvm/include/llvm/ADT/bit.h | 17 | ||||
-rw-r--r-- | llvm/include/llvm/IR/ValueMap.h | 88 | ||||
-rw-r--r-- | llvm/include/llvm/Support/ScopedPrinter.h | 16 | ||||
-rw-r--r-- | llvm/include/llvm/TableGen/CodeGenHelpers.h | 67 | ||||
-rw-r--r-- | llvm/include/llvm/Target/TargetSchedule.td | 6 |
7 files changed, 123 insertions, 80 deletions
diff --git a/llvm/include/llvm/ADT/BitmaskEnum.h b/llvm/include/llvm/ADT/BitmaskEnum.h index 7214f25..d464cbc 100644 --- a/llvm/include/llvm/ADT/BitmaskEnum.h +++ b/llvm/include/llvm/ADT/BitmaskEnum.h @@ -14,6 +14,7 @@ #include <utility> #include "llvm/ADT/STLForwardCompat.h" +#include "llvm/ADT/bit.h" #include "llvm/Support/MathExtras.h" /// LLVM_MARK_AS_BITMASK_ENUM lets you opt in an individual enum type so you can @@ -138,10 +139,6 @@ template <typename E> constexpr std::underlying_type_t<E> Underlying(E Val) { return U; } -constexpr unsigned bitWidth(uint64_t Value) { - return Value ? 1 + bitWidth(Value >> 1) : 0; -} - template <typename E, typename = std::enable_if_t<is_bitmask_enum<E>::value>> constexpr bool operator!(E Val) { return Val == static_cast<E>(0); @@ -220,7 +217,7 @@ e &operator>>=(e &lhs, e rhs) { // Enable bitmask enums in namespace ::llvm and all nested namespaces. LLVM_ENABLE_BITMASK_ENUMS_IN_NAMESPACE(); template <typename E, typename = std::enable_if_t<is_bitmask_enum<E>::value>> -constexpr unsigned BitWidth = BitmaskEnumDetail::bitWidth( +constexpr unsigned BitWidth = llvm::bit_width_constexpr( uint64_t{llvm::to_underlying(E::LLVM_BITMASK_LARGEST_ENUMERATOR)}); } // namespace llvm diff --git a/llvm/include/llvm/ADT/PointerUnion.h b/llvm/include/llvm/ADT/PointerUnion.h index ca0e1ed..7b66177 100644 --- a/llvm/include/llvm/ADT/PointerUnion.h +++ b/llvm/include/llvm/ADT/PointerUnion.h @@ -31,7 +31,7 @@ namespace pointer_union_detail { /// Determine the number of bits required to store integers with values < n. /// This is ceil(log2(n)). constexpr int bitsRequired(unsigned n) { - return n > 1 ? 1 + bitsRequired((n + 1) / 2) : 0; + return n == 0 ? 0 : llvm::bit_width_constexpr(n - 1); } template <typename... Ts> constexpr int lowBitsAvailable() { diff --git a/llvm/include/llvm/ADT/bit.h b/llvm/include/llvm/ADT/bit.h index 67c0a1c..66c4f94 100644 --- a/llvm/include/llvm/ADT/bit.h +++ b/llvm/include/llvm/ADT/bit.h @@ -292,6 +292,23 @@ template <typename T> [[nodiscard]] int bit_width(T Value) { return std::numeric_limits<T>::digits - llvm::countl_zero(Value); } +/// Returns the number of bits needed to represent Value if Value is nonzero. +/// Returns 0 otherwise. +/// +/// A constexpr version of bit_width. +/// +/// Ex. bit_width_constexpr(5) == 3. +template <typename T> [[nodiscard]] constexpr int bit_width_constexpr(T Value) { + static_assert(std::is_unsigned_v<T>, + "Only unsigned integral types are allowed."); + int Width = 0; + while (Value > 0) { + Value >>= 1; + ++Width; + } + return Width; +} + /// Returns the largest integral power of two no greater than Value if Value is /// nonzero. Returns 0 otherwise. /// diff --git a/llvm/include/llvm/IR/ValueMap.h b/llvm/include/llvm/IR/ValueMap.h index 97653c2..9ab7d8b 100644 --- a/llvm/include/llvm/IR/ValueMap.h +++ b/llvm/include/llvm/IR/ValueMap.h @@ -44,8 +44,8 @@ namespace llvm { template <typename KeyT, typename ValueT, typename Config> class ValueMapCallbackVH; -template <typename DenseMapT, typename KeyT> class ValueMapIterator; -template <typename DenseMapT, typename KeyT> class ValueMapConstIterator; +template <typename DenseMapT, typename KeyT, bool IsConst> +class ValueMapIteratorImpl; /// This class defines the default behavior for configurable aspects of /// ValueMap<>. User Configs should inherit from this class to be as compatible @@ -132,8 +132,8 @@ public: return Where->second.get(); } - using iterator = ValueMapIterator<MapT, KeyT>; - using const_iterator = ValueMapConstIterator<MapT, KeyT>; + using iterator = ValueMapIteratorImpl<MapT, KeyT, false>; + using const_iterator = ValueMapIteratorImpl<MapT, KeyT, true>; inline iterator begin() { return iterator(Map.begin()); } inline iterator end() { return iterator(Map.end()); } @@ -318,8 +318,10 @@ struct DenseMapInfo<ValueMapCallbackVH<KeyT, ValueT, Config>> { } }; -template <typename DenseMapT, typename KeyT> class ValueMapIterator { - using BaseT = typename DenseMapT::iterator; +template <typename DenseMapT, typename KeyT, bool IsConst> +class ValueMapIteratorImpl { + using BaseT = std::conditional_t<IsConst, typename DenseMapT::const_iterator, + typename DenseMapT::iterator>; using ValueT = typename DenseMapT::mapped_type; BaseT I; @@ -331,14 +333,20 @@ public: using pointer = value_type *; using reference = value_type &; - ValueMapIterator() : I() {} - ValueMapIterator(BaseT I) : I(I) {} + ValueMapIteratorImpl() = default; + ValueMapIteratorImpl(BaseT I) : I(I) {} + + // Allow conversion from iterator to const_iterator. + template <bool C = IsConst, typename = std::enable_if_t<C>> + ValueMapIteratorImpl( + const ValueMapIteratorImpl<DenseMapT, KeyT, false> &Other) + : I(Other.base()) {} BaseT base() const { return I; } struct ValueTypeProxy { const KeyT first; - ValueT &second; + std::conditional_t<IsConst, const ValueT &, ValueT &> second; ValueTypeProxy *operator->() { return this; } @@ -354,69 +362,25 @@ public: ValueTypeProxy operator->() const { return operator*(); } - bool operator==(const ValueMapIterator &RHS) const { return I == RHS.I; } - bool operator!=(const ValueMapIterator &RHS) const { return I != RHS.I; } + bool operator==(const ValueMapIteratorImpl &RHS) const { return I == RHS.I; } + bool operator!=(const ValueMapIteratorImpl &RHS) const { return I != RHS.I; } - inline ValueMapIterator &operator++() { // Preincrement + inline ValueMapIteratorImpl &operator++() { // Preincrement ++I; return *this; } - ValueMapIterator operator++(int) { // Postincrement - ValueMapIterator tmp = *this; + ValueMapIteratorImpl operator++(int) { // Postincrement + ValueMapIteratorImpl tmp = *this; ++*this; return tmp; } }; -template <typename DenseMapT, typename KeyT> class ValueMapConstIterator { - using BaseT = typename DenseMapT::const_iterator; - using ValueT = typename DenseMapT::mapped_type; - - BaseT I; - -public: - using iterator_category = std::forward_iterator_tag; - using value_type = std::pair<KeyT, typename DenseMapT::mapped_type>; - using difference_type = std::ptrdiff_t; - using pointer = value_type *; - using reference = value_type &; - - ValueMapConstIterator() : I() {} - ValueMapConstIterator(BaseT I) : I(I) {} - ValueMapConstIterator(ValueMapIterator<DenseMapT, KeyT> Other) - : I(Other.base()) {} - - BaseT base() const { return I; } +template <typename DenseMapT, typename KeyT> +using ValueMapIterator = ValueMapIteratorImpl<DenseMapT, KeyT, false>; - struct ValueTypeProxy { - const KeyT first; - const ValueT &second; - ValueTypeProxy *operator->() { return this; } - operator std::pair<KeyT, ValueT>() const { - return std::make_pair(first, second); - } - }; - - ValueTypeProxy operator*() const { - ValueTypeProxy Result = {I->first.Unwrap(), I->second}; - return Result; - } - - ValueTypeProxy operator->() const { return operator*(); } - - bool operator==(const ValueMapConstIterator &RHS) const { return I == RHS.I; } - bool operator!=(const ValueMapConstIterator &RHS) const { return I != RHS.I; } - - inline ValueMapConstIterator &operator++() { // Preincrement - ++I; - return *this; - } - ValueMapConstIterator operator++(int) { // Postincrement - ValueMapConstIterator tmp = *this; - ++*this; - return tmp; - } -}; +template <typename DenseMapT, typename KeyT> +using ValueMapConstIterator = ValueMapIteratorImpl<DenseMapT, KeyT, true>; } // end namespace llvm diff --git a/llvm/include/llvm/Support/ScopedPrinter.h b/llvm/include/llvm/Support/ScopedPrinter.h index a08cc8f..94080e8 100644 --- a/llvm/include/llvm/Support/ScopedPrinter.h +++ b/llvm/include/llvm/Support/ScopedPrinter.h @@ -284,9 +284,11 @@ public: startLine() << Label << ": " << (Value ? "Yes" : "No") << '\n'; } - template <typename... T> void printVersion(StringRef Label, T... Version) { + template <typename T, typename... TArgs> + void printVersion(StringRef Label, T MajorVersion, TArgs... MinorVersions) { startLine() << Label << ": "; - printVersionInternal(Version...); + getOStream() << MajorVersion; + ((getOStream() << '.' << MinorVersions), ...); getOStream() << "\n"; } @@ -454,16 +456,6 @@ public: virtual raw_ostream &getOStream() { return OS; } private: - template <typename T> void printVersionInternal(T Value) { - getOStream() << Value; - } - - template <typename S, typename T, typename... TArgs> - void printVersionInternal(S Value, T Value2, TArgs... Args) { - getOStream() << Value << "."; - printVersionInternal(Value2, Args...); - } - static bool flagName(const FlagEntry &LHS, const FlagEntry &RHS) { return LHS.Name < RHS.Name; } diff --git a/llvm/include/llvm/TableGen/CodeGenHelpers.h b/llvm/include/llvm/TableGen/CodeGenHelpers.h new file mode 100644 index 0000000..7dca6a0 --- /dev/null +++ b/llvm/include/llvm/TableGen/CodeGenHelpers.h @@ -0,0 +1,67 @@ +//===----------------------------------------------------------------------===// +// +// 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 +// +//===----------------------------------------------------------------------===// +// +// This file defines common utilities for generating C++ code. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_TABLEGEN_CODEGENHELPERS_H +#define LLVM_TABLEGEN_CODEGENHELPERS_H + +#include "llvm/ADT/STLExtras.h" +#include "llvm/ADT/StringExtras.h" +#include "llvm/ADT/StringRef.h" +#include "llvm/Support/raw_ostream.h" +#include <string> + +namespace llvm { +// Simple RAII helper for emitting ifdef-undef-endif scope. +class IfDefEmitter { +public: + IfDefEmitter(raw_ostream &OS, StringRef Name) : Name(Name.str()), OS(OS) { + OS << "#ifdef " << Name << "\n" + << "#undef " << Name << "\n\n"; + } + ~IfDefEmitter() { OS << "\n#endif // " << Name << "\n\n"; } + +private: + std::string Name; + raw_ostream &OS; +}; + +// Simple RAII helper for emitting namespace scope. Name can be a single +// namespace (empty for anonymous namespace) or nested namespace. +class NamespaceEmitter { +public: + NamespaceEmitter(raw_ostream &OS, StringRef Name) : OS(OS) { + emitNamespaceStarts(Name); + } + + ~NamespaceEmitter() { close(); } + + // Explicit function to close the namespace scopes. + void close() { + for (StringRef NS : llvm::reverse(Namespaces)) + OS << "} // namespace " << NS << "\n"; + Namespaces.clear(); + } + +private: + void emitNamespaceStarts(StringRef Name) { + llvm::SplitString(Name, Namespaces, "::"); + for (StringRef NS : Namespaces) + OS << "namespace " << NS << " {\n"; + } + + SmallVector<StringRef, 2> Namespaces; + raw_ostream &OS; +}; + +} // end namespace llvm + +#endif // LLVM_TABLEGEN_CODEGENHELPERS_H diff --git a/llvm/include/llvm/Target/TargetSchedule.td b/llvm/include/llvm/Target/TargetSchedule.td index f55bff1..d6a4059 100644 --- a/llvm/include/llvm/Target/TargetSchedule.td +++ b/llvm/include/llvm/Target/TargetSchedule.td @@ -377,6 +377,12 @@ class MCSchedPredicate<MCInstPredicate P> : SchedPredicateBase { SchedMachineModel SchedModel = ?; } +// A scheduling predicate whose logic depends on a SubtargetFeature. +class FeatureSchedPredicate<SubtargetFeature SF> : SchedPredicateBase { + SubtargetFeature Feature = SF; + SchedMachineModel SchedModel = ?; +} + // Define a predicate to determine which SchedVariant applies to a // particular MachineInstr. The code snippet is used as an // if-statement's expression. Available variables are MI, SchedModel, |