Index: llvm/include/llvm/ADT/DenseSet.h =================================================================== --- llvm/include/llvm/ADT/DenseSet.h +++ llvm/include/llvm/ADT/DenseSet.h @@ -189,6 +189,19 @@ return TheMap.try_emplace(V, Empty); } + bool operator==(const DenseSetImpl &Other) const { + if (size() != Other.size()) + return false; + for (const auto &I : *this) + if (Other.find(I) == Other.end()) + return false; + return true; + } + + bool operator!=(const DenseSetImpl &Other) const { + return !(*this == Other); + } + std::pair insert(ValueT &&V) { detail::DenseSetEmpty Empty; return TheMap.try_emplace(std::move(V), Empty); Index: llvm/include/llvm/CodeGen/MachineValueType.h =================================================================== --- llvm/include/llvm/CodeGen/MachineValueType.h +++ llvm/include/llvm/CodeGen/MachineValueType.h @@ -15,6 +15,7 @@ #ifndef LLVM_CODEGEN_MACHINEVALUETYPE_H #define LLVM_CODEGEN_MACHINEVALUETYPE_H +#include "llvm/ADT/DenseMapInfo.h" #include "llvm/ADT/iterator_range.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/MathExtras.h" @@ -36,108 +37,108 @@ // If you change this numbering, you must change the values in // ValueTypes.td as well! - Other = 1, // This is a non-standard value - i1 = 2, // This is a 1 bit integer value - i8 = 3, // This is an 8 bit integer value - i16 = 4, // This is a 16 bit integer value - i32 = 5, // This is a 32 bit integer value - i64 = 6, // This is a 64 bit integer value - i128 = 7, // This is a 128 bit integer value + Other = 1, // This is a non-standard value + i1 = 2, // This is a 1 bit integer value + i8 = 3, // This is an 8 bit integer value + i16 = 4, // This is a 16 bit integer value + i32 = 5, // This is a 32 bit integer value + i64 = 6, // This is a 64 bit integer value + i128 = 7, // This is a 128 bit integer value FIRST_INTEGER_VALUETYPE = i1, - LAST_INTEGER_VALUETYPE = i128, + LAST_INTEGER_VALUETYPE = i128, - f16 = 8, // This is a 16 bit floating point value - f32 = 9, // This is a 32 bit floating point value - f64 = 10, // This is a 64 bit floating point value - f80 = 11, // This is a 80 bit floating point value - f128 = 12, // This is a 128 bit floating point value - ppcf128 = 13, // This is a PPC 128-bit floating point value + f16 = 8, // This is a 16 bit floating point value + f32 = 9, // This is a 32 bit floating point value + f64 = 10, // This is a 64 bit floating point value + f80 = 11, // This is a 80 bit floating point value + f128 = 12, // This is a 128 bit floating point value + ppcf128 = 13, // This is a PPC 128-bit floating point value FIRST_FP_VALUETYPE = f16, - LAST_FP_VALUETYPE = ppcf128, - - v1i1 = 14, // 1 x i1 - v2i1 = 15, // 2 x i1 - v4i1 = 16, // 4 x i1 - v8i1 = 17, // 8 x i1 - v16i1 = 18, // 16 x i1 - v32i1 = 19, // 32 x i1 - v64i1 = 20, // 64 x i1 - v512i1 = 21, // 512 x i1 - v1024i1 = 22, // 1024 x i1 - - v1i8 = 23, // 1 x i8 - v2i8 = 24, // 2 x i8 - v4i8 = 25, // 4 x i8 - v8i8 = 26, // 8 x i8 - v16i8 = 27, // 16 x i8 - v32i8 = 28, // 32 x i8 - v64i8 = 29, // 64 x i8 - v128i8 = 30, //128 x i8 - v256i8 = 31, //256 x i8 - - v1i16 = 32, // 1 x i16 - v2i16 = 33, // 2 x i16 - v4i16 = 34, // 4 x i16 - v8i16 = 35, // 8 x i16 - v16i16 = 36, // 16 x i16 - v32i16 = 37, // 32 x i16 - v64i16 = 38, // 64 x i16 - v128i16 = 39, //128 x i16 - - v1i32 = 40, // 1 x i32 - v2i32 = 41, // 2 x i32 - v4i32 = 42, // 4 x i32 - v8i32 = 43, // 8 x i32 - v16i32 = 44, // 16 x i32 - v32i32 = 45, // 32 x i32 - v64i32 = 46, // 64 x i32 - - v1i64 = 47, // 1 x i64 - v2i64 = 48, // 2 x i64 - v4i64 = 49, // 4 x i64 - v8i64 = 50, // 8 x i64 - v16i64 = 51, // 16 x i64 - v32i64 = 52, // 32 x i64 - - v1i128 = 53, // 1 x i128 + LAST_FP_VALUETYPE = ppcf128, + + v1i1 = 14, // 1 x i1 + v2i1 = 15, // 2 x i1 + v4i1 = 16, // 4 x i1 + v8i1 = 17, // 8 x i1 + v16i1 = 18, // 16 x i1 + v32i1 = 19, // 32 x i1 + v64i1 = 20, // 64 x i1 + v512i1 = 21, // 512 x i1 + v1024i1 = 22, // 1024 x i1 + + v1i8 = 23, // 1 x i8 + v2i8 = 24, // 2 x i8 + v4i8 = 25, // 4 x i8 + v8i8 = 26, // 8 x i8 + v16i8 = 27, // 16 x i8 + v32i8 = 28, // 32 x i8 + v64i8 = 29, // 64 x i8 + v128i8 = 30, // 128 x i8 + v256i8 = 31, // 256 x i8 + + v1i16 = 32, // 1 x i16 + v2i16 = 33, // 2 x i16 + v4i16 = 34, // 4 x i16 + v8i16 = 35, // 8 x i16 + v16i16 = 36, // 16 x i16 + v32i16 = 37, // 32 x i16 + v64i16 = 38, // 64 x i16 + v128i16 = 39, // 128 x i16 + + v1i32 = 40, // 1 x i32 + v2i32 = 41, // 2 x i32 + v4i32 = 42, // 4 x i32 + v8i32 = 43, // 8 x i32 + v16i32 = 44, // 16 x i32 + v32i32 = 45, // 32 x i32 + v64i32 = 46, // 64 x i32 + + v1i64 = 47, // 1 x i64 + v2i64 = 48, // 2 x i64 + v4i64 = 49, // 4 x i64 + v8i64 = 50, // 8 x i64 + v16i64 = 51, // 16 x i64 + v32i64 = 52, // 32 x i64 + + v1i128 = 53, // 1 x i128 // Scalable integer types - nxv1i1 = 54, // n x 1 x i1 - nxv2i1 = 55, // n x 2 x i1 - nxv4i1 = 56, // n x 4 x i1 - nxv8i1 = 57, // n x 8 x i1 - nxv16i1 = 58, // n x 16 x i1 - nxv32i1 = 59, // n x 32 x i1 - - nxv1i8 = 60, // n x 1 x i8 - nxv2i8 = 61, // n x 2 x i8 - nxv4i8 = 62, // n x 4 x i8 - nxv8i8 = 63, // n x 8 x i8 - nxv16i8 = 64, // n x 16 x i8 - nxv32i8 = 65, // n x 32 x i8 - - nxv1i16 = 66, // n x 1 x i16 - nxv2i16 = 67, // n x 2 x i16 - nxv4i16 = 68, // n x 4 x i16 - nxv8i16 = 69, // n x 8 x i16 - nxv16i16 = 70, // n x 16 x i16 - nxv32i16 = 71, // n x 32 x i16 - - nxv1i32 = 72, // n x 1 x i32 - nxv2i32 = 73, // n x 2 x i32 - nxv4i32 = 74, // n x 4 x i32 - nxv8i32 = 75, // n x 8 x i32 - nxv16i32 = 76, // n x 16 x i32 - nxv32i32 = 77, // n x 32 x i32 - - nxv1i64 = 78, // n x 1 x i64 - nxv2i64 = 79, // n x 2 x i64 - nxv4i64 = 80, // n x 4 x i64 - nxv8i64 = 81, // n x 8 x i64 - nxv16i64 = 82, // n x 16 x i64 - nxv32i64 = 83, // n x 32 x i64 + nxv1i1 = 54, // n x 1 x i1 + nxv2i1 = 55, // n x 2 x i1 + nxv4i1 = 56, // n x 4 x i1 + nxv8i1 = 57, // n x 8 x i1 + nxv16i1 = 58, // n x 16 x i1 + nxv32i1 = 59, // n x 32 x i1 + + nxv1i8 = 60, // n x 1 x i8 + nxv2i8 = 61, // n x 2 x i8 + nxv4i8 = 62, // n x 4 x i8 + nxv8i8 = 63, // n x 8 x i8 + nxv16i8 = 64, // n x 16 x i8 + nxv32i8 = 65, // n x 32 x i8 + + nxv1i16 = 66, // n x 1 x i16 + nxv2i16 = 67, // n x 2 x i16 + nxv4i16 = 68, // n x 4 x i16 + nxv8i16 = 69, // n x 8 x i16 + nxv16i16 = 70, // n x 16 x i16 + nxv32i16 = 71, // n x 32 x i16 + + nxv1i32 = 72, // n x 1 x i32 + nxv2i32 = 73, // n x 2 x i32 + nxv4i32 = 74, // n x 4 x i32 + nxv8i32 = 75, // n x 8 x i32 + nxv16i32 = 76, // n x 16 x i32 + nxv32i32 = 77, // n x 32 x i32 + + nxv1i64 = 78, // n x 1 x i64 + nxv2i64 = 79, // n x 2 x i64 + nxv4i64 = 80, // n x 4 x i64 + nxv8i64 = 81, // n x 8 x i64 + nxv16i64 = 82, // n x 16 x i64 + nxv32i64 = 83, // n x 32 x i64 FIRST_INTEGER_VECTOR_VALUETYPE = v1i1, LAST_INTEGER_VECTOR_VALUETYPE = nxv32i64, @@ -145,31 +146,31 @@ FIRST_INTEGER_SCALABLE_VALUETYPE = nxv1i1, LAST_INTEGER_SCALABLE_VALUETYPE = nxv32i64, - v2f16 = 84, // 2 x f16 - v4f16 = 85, // 4 x f16 - v8f16 = 86, // 8 x f16 - v1f32 = 87, // 1 x f32 - v2f32 = 88, // 2 x f32 - v4f32 = 89, // 4 x f32 - v8f32 = 90, // 8 x f32 - v16f32 = 91, // 16 x f32 - v1f64 = 92, // 1 x f64 - v2f64 = 93, // 2 x f64 - v4f64 = 94, // 4 x f64 - v8f64 = 95, // 8 x f64 - - nxv2f16 = 96, // n x 2 x f16 - nxv4f16 = 97, // n x 4 x f16 - nxv8f16 = 98, // n x 8 x f16 - nxv1f32 = 99, // n x 1 x f32 - nxv2f32 = 100, // n x 2 x f32 - nxv4f32 = 101, // n x 4 x f32 - nxv8f32 = 102, // n x 8 x f32 - nxv16f32 = 103, // n x 16 x f32 - nxv1f64 = 104, // n x 1 x f64 - nxv2f64 = 105, // n x 2 x f64 - nxv4f64 = 106, // n x 4 x f64 - nxv8f64 = 107, // n x 8 x f64 + v2f16 = 84, // 2 x f16 + v4f16 = 85, // 4 x f16 + v8f16 = 86, // 8 x f16 + v1f32 = 87, // 1 x f32 + v2f32 = 88, // 2 x f32 + v4f32 = 89, // 4 x f32 + v8f32 = 90, // 8 x f32 + v16f32 = 91, // 16 x f32 + v1f64 = 92, // 1 x f64 + v2f64 = 93, // 2 x f64 + v4f64 = 94, // 4 x f64 + v8f64 = 95, // 8 x f64 + + nxv2f16 = 96, // n x 2 x f16 + nxv4f16 = 97, // n x 4 x f16 + nxv8f16 = 98, // n x 8 x f16 + nxv1f32 = 99, // n x 1 x f32 + nxv2f32 = 100, // n x 2 x f32 + nxv4f32 = 101, // n x 4 x f32 + nxv8f32 = 102, // n x 8 x f32 + nxv16f32 = 103, // n x 16 x f32 + nxv1f64 = 104, // n x 1 x f64 + nxv2f64 = 105, // n x 2 x f64 + nxv4f64 = 106, // n x 4 x f64 + nxv8f64 = 107, // n x 8 x f64 FIRST_FP_VECTOR_VALUETYPE = v2f16, LAST_FP_VECTOR_VALUETYPE = nxv8f64, @@ -178,59 +179,62 @@ LAST_FP_SCALABLE_VALUETYPE = nxv8f64, FIRST_VECTOR_VALUETYPE = v1i1, - LAST_VECTOR_VALUETYPE = nxv8f64, + LAST_VECTOR_VALUETYPE = nxv8f64, - x86mmx = 108, // This is an X86 MMX value + x86mmx = 108, // This is an X86 MMX value - Glue = 109, // This glues nodes together during pre-RA sched + Glue = 109, // This glues nodes together during pre-RA sched - isVoid = 110, // This has no value + isVoid = 110, // This has no value - Untyped = 111, // This value takes a register, but has - // unspecified type. The register class - // will be determined by the opcode. + Untyped = 111, // This value takes a register, but has + // unspecified type. The register class + // will be determined by the opcode. - FIRST_VALUETYPE = 1, // This is always the beginning of the list. - LAST_VALUETYPE = 112, // This always remains at the end of the list. + FIRST_VALUETYPE = 1, // This is always the beginning of the list. + LAST_VALUETYPE = 112, // This always remains at the end of the list. // This is the current maximum for LAST_VALUETYPE. // MVT::MAX_ALLOWED_VALUETYPE is used for asserts and to size bit vectors // This value must be a multiple of 32. MAX_ALLOWED_VALUETYPE = 128, + // Tombstone value used for DenseMapInfo + tombstone = 249, + // A value of type llvm::TokenTy - token = 248, + token = 248, // This is MDNode or MDString. - Metadata = 249, + Metadata = 249, // An int value the size of the pointer of the current // target to any address space. This must only be used internal to // tblgen. Other than for overloading, we treat iPTRAny the same as iPTR. - iPTRAny = 250, + iPTRAny = 250, // A vector with any length and element size. This is used // for intrinsics that have overloadings based on vector types. // This is only for tblgen's consumption! - vAny = 251, + vAny = 251, // Any floating-point or vector floating-point value. This is used // for intrinsics that have overloadings based on floating-point types. // This is only for tblgen's consumption! - fAny = 252, + fAny = 252, // An integer or vector integer value of any bit width. This is // used for intrinsics that have overloadings based on integer bit widths. // This is only for tblgen's consumption! - iAny = 253, + iAny = 253, // An int value the size of the pointer of the current // target. This should only be used internal to tblgen! - iPTR = 254, + iPTR = 254, // Any type. This is used for intrinsics that have overloadings. // This is only for tblgen's consumption! - Any = 255 + Any = 255 }; SimpleValueType SimpleTy = INVALID_SIMPLE_VALUE_TYPE; @@ -1044,6 +1048,17 @@ /// @} }; + template <> struct DenseMapInfo { + static inline MVT getEmptyKey() { + return MVT(MVT::INVALID_SIMPLE_VALUE_TYPE); + } + static inline MVT getTombstoneKey() { return MVT(MVT::tombstone); } + static unsigned getHashValue(const MVT &Val) { + return unsigned(Val.SimpleTy); + } + static bool isEqual(const MVT &LHS, const MVT &RHS) { return LHS == RHS; } + }; + } // end namespace llvm #endif // LLVM_CODEGEN_MACHINEVALUETYPE_H Index: llvm/utils/TableGen/CodeGenDAGPatterns.h =================================================================== --- llvm/utils/TableGen/CodeGenDAGPatterns.h +++ llvm/utils/TableGen/CodeGenDAGPatterns.h @@ -18,8 +18,10 @@ #include "CodeGenHwModes.h" #include "CodeGenIntrinsics.h" #include "CodeGenTarget.h" +#include "llvm/ADT/DenseSet.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringMap.h" +#include "llvm/ADT/StringSet.h" #include "llvm/Support/ErrorHandling.h" #include #include @@ -37,58 +39,59 @@ class CodeGenDAGPatterns; class ComplexPattern; -struct TypeSetByHwMode : public InfoByHwMode> { - typedef std::set SetType; - - TypeSetByHwMode() = default; - TypeSetByHwMode(const TypeSetByHwMode &VTS) = default; - TypeSetByHwMode(MVT::SimpleValueType VT) - : TypeSetByHwMode(ValueTypeByHwMode(VT)) {} - TypeSetByHwMode(ValueTypeByHwMode VT) - : TypeSetByHwMode(ArrayRef(&VT, 1)) {} - TypeSetByHwMode(ArrayRef VTList); - - SetType &getOrCreate(unsigned Mode) { - if (hasMode(Mode)) - return get(Mode); - return Map.insert({Mode,SetType()}).first->second; - } - - bool isValueTypeByHwMode(bool AllowEmpty) const; - ValueTypeByHwMode getValueTypeByHwMode() const; - bool isMachineValueType() const { - return isDefaultOnly() && Map.begin()->second.size() == 1; - } - - MVT getMachineValueType() const { - assert(isMachineValueType()); - return *Map.begin()->second.begin(); - } - - bool isPossible() const; - bool isDefaultOnly() const { - return Map.size() == 1 && - Map.begin()->first == DefaultMode; - } - - bool insert(const ValueTypeByHwMode &VVT); - bool constrain(const TypeSetByHwMode &VTS); - template bool constrain(Predicate P); - template bool assign_if(const TypeSetByHwMode &VTS, - Predicate P); - - std::string getAsString() const; - static std::string getAsString(const SetType &S); - - bool operator==(const TypeSetByHwMode &VTS) const; - bool operator!=(const TypeSetByHwMode &VTS) const { return !(*this == VTS); } - - void dump() const; - void validate() const; - -private: - /// Intersect two sets. Return true if anything has changed. - bool intersect(SetType &Out, const SetType &In); + struct TypeSetByHwMode : public InfoByHwMode> { + typedef DenseSet SetType; + + TypeSetByHwMode() = default; + TypeSetByHwMode(const TypeSetByHwMode &VTS) = default; + TypeSetByHwMode(MVT::SimpleValueType VT) + : TypeSetByHwMode(ValueTypeByHwMode(VT)) {} + TypeSetByHwMode(ValueTypeByHwMode VT) + : TypeSetByHwMode(ArrayRef(&VT, 1)) {} + TypeSetByHwMode(ArrayRef VTList); + + SetType &getOrCreate(unsigned Mode) { + if (hasMode(Mode)) + return get(Mode); + return Map.insert({Mode, SetType()}).first->second; + } + + bool isValueTypeByHwMode(bool AllowEmpty) const; + ValueTypeByHwMode getValueTypeByHwMode() const; + bool isMachineValueType() const { + return isDefaultOnly() && Map.begin()->second.size() == 1; + } + + MVT getMachineValueType() const { + assert(isMachineValueType()); + return *Map.begin()->second.begin(); + } + + bool isPossible() const; + bool isDefaultOnly() const { + return Map.size() == 1 && Map.begin()->first == DefaultMode; + } + + bool insert(const ValueTypeByHwMode &VVT); + bool constrain(const TypeSetByHwMode &VTS); + template bool constrain(Predicate P); + template + bool assign_if(const TypeSetByHwMode &VTS, Predicate P); + + void writeToStream(raw_ostream &OS) const; + static void writeToStream(const SetType &S, raw_ostream &OS); + + bool operator==(const TypeSetByHwMode &VTS) const; + bool operator!=(const TypeSetByHwMode &VTS) const { + return !(*this == VTS); + } + + void dump() const; + void validate() const; + + private: + /// Intersect two sets. Return true if anything has changed. + bool intersect(SetType &Out, const SetType &In); }; struct TypeInfer { @@ -181,7 +184,7 @@ }; /// Set type used to track multiply used variables in patterns -typedef std::set MultipleUseVarSet; +typedef llvm::StringSet<> MultipleUseVarSet; /// SDTypeConstraint - This is a discriminated union of constraints, /// corresponding to the SDTypeConstraint tablegen class in Target.td. Index: llvm/utils/TableGen/CodeGenDAGPatterns.cpp =================================================================== --- llvm/utils/TableGen/CodeGenDAGPatterns.cpp +++ llvm/utils/TableGen/CodeGenDAGPatterns.cpp @@ -17,6 +17,7 @@ #include "llvm/ADT/SmallSet.h" #include "llvm/ADT/SmallString.h" #include "llvm/ADT/StringExtras.h" +#include "llvm/ADT/StringSet.h" #include "llvm/ADT/Twine.h" #include "llvm/Support/Debug.h" #include "llvm/Support/ErrorHandling.h" @@ -25,7 +26,6 @@ #include #include #include -#include using namespace llvm; #define DEBUG_TYPE "dag-patterns" @@ -43,17 +43,16 @@ return !VT.isVector(); } -template -static bool berase_if(std::set &S, Predicate P) { - bool Erased = false; - for (auto I = S.begin(); I != S.end(); ) { - if (P(*I)) { - Erased = true; - I = S.erase(I); - } else - ++I; - } - return Erased; +template +static bool berase_if(SetType &S, Predicate P) { + llvm::SmallVector ToErase; + for (const auto &I : S) { + if (P(I)) + ToErase.push_back(I); + } + for (const auto &I : ToErase) + S.erase(I); + return !ToErase.empty(); } // --- TypeSetByHwMode @@ -97,7 +96,7 @@ bool TypeSetByHwMode::insert(const ValueTypeByHwMode &VVT) { bool Changed = false; - std::set Modes; + llvm::SmallDenseSet Modes; for (const auto &P : VVT) { unsigned M = P.first; Modes.insert(M); @@ -113,7 +112,6 @@ if (!Modes.count(I.first)) Changed |= I.second.insert(DT).second; } - return Changed; } @@ -163,38 +161,38 @@ return !empty(); } -std::string TypeSetByHwMode::getAsString() const { - std::stringstream str; - std::vector Modes; +void TypeSetByHwMode::writeToStream(raw_ostream &OS) const { + llvm::SmallVector Modes; + Modes.reserve(Map.size()); for (const auto &I : *this) Modes.push_back(I.first); - if (Modes.empty()) - return "{}"; + if (Modes.empty()) { + OS << "{}"; + return; + } array_pod_sort(Modes.begin(), Modes.end()); - str << '{'; + OS << '{'; for (unsigned M : Modes) { const SetType &S = get(M); - str << ' ' << getModeName(M) << ':' << getAsString(S); + OS << ' ' << getModeName(M) << ':'; + writeToStream(S, OS); } - str << " }"; - return str.str(); + OS << " }"; } -std::string TypeSetByHwMode::getAsString(const SetType &S) { - std::vector Types(S.begin(), S.end()); +void TypeSetByHwMode::writeToStream(const SetType &S, raw_ostream &OS) { + SmallVector Types(S.begin(), S.end()); array_pod_sort(Types.begin(), Types.end()); - std::stringstream str; - str << '['; + OS << '['; for (unsigned i = 0, e = Types.size(); i != e; ++i) { - str << ValueTypeByHwMode::getMVTName(Types[i]); + OS << ValueTypeByHwMode::getMVTName(Types[i]); if (i != e-1) - str << ' '; + OS << ' '; } - str << ']'; - return str.str(); + OS << ']'; } bool TypeSetByHwMode::operator==(const TypeSetByHwMode &VTS) const { @@ -202,7 +200,7 @@ if (HaveDefault != VTS.hasDefault()) return false; - std::set Modes; + SmallDenseSet Modes; for (auto &I : *this) Modes.insert(I.first); for (const auto &I : VTS) @@ -234,7 +232,8 @@ LLVM_DUMP_METHOD void TypeSetByHwMode::dump() const { - dbgs() << getAsString() << '\n'; + writeToStream(dbgs()); + dbgs() << '\n'; } bool TypeSetByHwMode::intersect(SetType &Out, const SetType &In) { @@ -254,14 +253,19 @@ // { iPTR } * { i32 } -> { i32 } // { iPTR } * { i32 i64 } -> { iPTR } - SetType Diff; + SmallVector Diff; if (InP) { - std::copy_if(Out.begin(), Out.end(), std::inserter(Diff, Diff.end()), - [&In](MVT T) { return !In.count(T); }); - berase_if(Out, [&Diff](MVT T) { return Diff.count(T); }); + for (const auto &T : Out) { + if (!In.count(T)) + Diff.push_back(T); + } + for (const auto &T : Diff) + Out.erase(T); } else { - std::copy_if(In.begin(), In.end(), std::inserter(Diff, Diff.end()), - [&Out](MVT T) { return !Out.count(T); }); + for (const auto &T : In) { + if (!Out.count(T)) + Diff.push_back(T); + } Out.erase(MVT::iPTR); } @@ -757,15 +761,13 @@ void TypeInfer::expandOverloads(TypeSetByHwMode::SetType &Out, const TypeSetByHwMode::SetType &Legal) { - std::set Ovs; - for (auto I = Out.begin(); I != Out.end(); ) { - if (I->isOverloaded()) { - Ovs.insert(*I); - I = Out.erase(I); - continue; - } - ++I; + SmallVector Ovs; + for (const auto &I : Out) { + if (I.isOverloaded()) + Ovs.push_back(I); } + for (const auto &M : Ovs) + Out.erase(M); for (MVT Ov : Ovs) { switch (Ov.SimpleTy) { @@ -1386,8 +1388,10 @@ else OS << '(' << getOperator()->getName(); - for (unsigned i = 0, e = Types.size(); i != e; ++i) - OS << ':' << getExtType(i).getAsString(); + for (unsigned i = 0, e = Types.size(); i != e; ++i) { + OS << ':'; + getExtType(i).writeToStream(OS); + } if (!isLeaf()) { if (getNumChildren() != 0) { @@ -2604,7 +2608,10 @@ // Validate the argument list, converting it to set, to discard duplicates. std::vector &Args = P->getArgList(); - std::set OperandsSet(Args.begin(), Args.end()); + // Copy the args so we can take StringRefs to them. + auto ArgsCopy = Args; + SmallDenseSet OperandsSet; + OperandsSet.insert(ArgsCopy.begin(), ArgsCopy.end()); if (OperandsSet.count("")) P->error("Cannot have unnamed 'node' values in pattern fragment!"); @@ -3096,17 +3103,20 @@ // Verify that the top-level forms in the instruction are of void type, and // fill in the InstResults map. + SmallString<32> TypesString; for (unsigned j = 0, e = I->getNumTrees(); j != e; ++j) { + TypesString.clear(); TreePatternNode *Pat = I->getTree(j); if (Pat->getNumTypes() != 0) { - std::string Types; + raw_svector_ostream OS(TypesString); for (unsigned k = 0, ke = Pat->getNumTypes(); k != ke; ++k) { if (k > 0) - Types += ", "; - Types += Pat->getExtType(k).getAsString(); + OS << ", "; + Pat->getExtType(k).writeToStream(OS); } I->error("Top-level forms in instruction pattern should have" - " void types, has types " + Types); + " void types, has types " + + OS.str()); } // Find inputs and outputs, and verify the structure of the uses/defs. @@ -3788,7 +3798,7 @@ } /// Dependent variable map for CodeGenDAGPattern variant generation -typedef std::map DepVarMap; +typedef StringMap DepVarMap; static void FindDepVarsOf(TreePatternNode *N, DepVarMap &DepMap) { if (N->isLeaf()) { @@ -3804,9 +3814,9 @@ static void FindDepVars(TreePatternNode *N, MultipleUseVarSet &DepVars) { DepVarMap depcounts; FindDepVarsOf(N, depcounts); - for (const std::pair &Pair : depcounts) { - if (Pair.second > 1) - DepVars.insert(Pair.first); + for (const auto &Pair : depcounts) { + if (Pair.getValue() > 1) + DepVars.insert(Pair.getKey()); } } @@ -3817,8 +3827,8 @@ DEBUG(errs() << ""); } else { DEBUG(errs() << "[ "); - for (const std::string &DepVar : DepVars) { - DEBUG(errs() << DepVar << " "); + for (const auto &DepVar : DepVars) { + DEBUG(errs() << DepVar.getKey() << " "); } DEBUG(errs() << "]"); }