Index: llvm/trunk/utils/TableGen/CodeGenDAGPatterns.h =================================================================== --- llvm/trunk/utils/TableGen/CodeGenDAGPatterns.h +++ llvm/trunk/utils/TableGen/CodeGenDAGPatterns.h @@ -20,6 +20,7 @@ #include "CodeGenTarget.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringMap.h" +#include "llvm/ADT/StringSet.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/MathExtras.h" #include @@ -222,11 +223,11 @@ bool insert(const ValueTypeByHwMode &VVT); bool constrain(const TypeSetByHwMode &VTS); template bool constrain(Predicate P); - template bool assign_if(const TypeSetByHwMode &VTS, - Predicate P); + template + bool assign_if(const TypeSetByHwMode &VTS, Predicate P); - std::string getAsString() const; - static std::string getAsString(const SetType &S); + 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); } @@ -333,7 +334,7 @@ }; /// Set type used to track multiply used variables in patterns -typedef std::set MultipleUseVarSet; +typedef StringSet<> MultipleUseVarSet; /// SDTypeConstraint - This is a discriminated union of constraints, /// corresponding to the SDTypeConstraint tablegen class in Target.td. Index: llvm/trunk/utils/TableGen/CodeGenDAGPatterns.cpp =================================================================== --- llvm/trunk/utils/TableGen/CodeGenDAGPatterns.cpp +++ llvm/trunk/utils/TableGen/CodeGenDAGPatterns.cpp @@ -13,10 +13,12 @@ //===----------------------------------------------------------------------===// #include "CodeGenDAGPatterns.h" +#include "llvm/ADT/DenseSet.h" #include "llvm/ADT/STLExtras.h" #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 +27,6 @@ #include #include #include -#include using namespace llvm; #define DEBUG_TYPE "dag-patterns" @@ -98,7 +99,7 @@ bool TypeSetByHwMode::insert(const ValueTypeByHwMode &VVT) { bool Changed = false; - std::set Modes; + SmallDenseSet Modes; for (const auto &P : VVT) { unsigned M = P.first; Modes.insert(M); @@ -114,7 +115,6 @@ if (!Modes.count(I.first)) Changed |= I.second.insert(DT).second; } - return Changed; } @@ -164,40 +164,37 @@ return !empty(); } -std::string TypeSetByHwMode::getAsString() const { - std::stringstream str; - std::vector Modes; +void TypeSetByHwMode::writeToStream(raw_ostream &OS) const { + 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(get(M), OS); } - str << " }"; - return str.str(); + OS << " }"; } -std::string TypeSetByHwMode::getAsString(const SetType &S) { - std::vector Types; - for (MVT T : S) - Types.push_back(T); +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 { @@ -211,7 +208,7 @@ return false; } - std::set Modes; + SmallDenseSet Modes; for (auto &I : *this) Modes.insert(I.first); for (const auto &I : VTS) @@ -243,7 +240,8 @@ LLVM_DUMP_METHOD void TypeSetByHwMode::dump() const { - dbgs() << getAsString() << '\n'; + writeToStream(dbgs()); + dbgs() << '\n'; } bool TypeSetByHwMode::intersect(SetType &Out, const SetType &In) { @@ -784,6 +782,7 @@ for (MVT T : Out) { if (!T.isOverloaded()) continue; + Ovs.insert(T); // MachineValueTypeSet allows iteration and erasing. Out.erase(T); @@ -1410,8 +1409,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) { @@ -2628,7 +2629,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!"); @@ -3120,17 +3124,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. @@ -3812,11 +3819,11 @@ } /// Dependent variable map for CodeGenDAGPattern variant generation -typedef std::map DepVarMap; +typedef StringMap DepVarMap; static void FindDepVarsOf(TreePatternNode *N, DepVarMap &DepMap) { if (N->isLeaf()) { - if (isa(N->getLeafValue())) + if (N->hasName() && isa(N->getLeafValue())) DepMap[N->getName()]++; } else { for (size_t i = 0, e = N->getNumChildren(); i != e; ++i) @@ -3828,9 +3835,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()); } } @@ -3841,8 +3848,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() << "]"); }