Index: llvm/utils/TableGen/CodeGenDAGPatterns.h =================================================================== --- llvm/utils/TableGen/CodeGenDAGPatterns.h +++ llvm/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 #include @@ -77,8 +78,8 @@ 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); } @@ -181,7 +182,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,8 +43,8 @@ return !VT.isVector(); } -template -static bool berase_if(std::set &S, Predicate P) { +template +static bool berase_if(SetType &S, Predicate P) { bool Erased = false; for (auto I = S.begin(); I != S.end(); ) { if (P(*I)) { @@ -97,7 +97,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 +113,6 @@ if (!Modes.count(I.first)) Changed |= I.second.insert(DT).second; } - return Changed; } @@ -163,38 +162,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 +201,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 +233,8 @@ LLVM_DUMP_METHOD void TypeSetByHwMode::dump() const { - dbgs() << getAsString() << '\n'; + writeToStream(dbgs()); + dbgs() << '\n'; } bool TypeSetByHwMode::intersect(SetType &Out, const SetType &In) { @@ -1386,8 +1386,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 +2606,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 +3101,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 +3796,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 +3812,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 +3825,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() << "]"); }