13
13
// ===----------------------------------------------------------------------===//
14
14
15
15
#include " CodeGenDAGPatterns.h"
16
+ #include " llvm/ADT/DenseSet.h"
16
17
#include " llvm/ADT/STLExtras.h"
17
18
#include " llvm/ADT/SmallSet.h"
18
19
#include " llvm/ADT/SmallString.h"
19
20
#include " llvm/ADT/StringExtras.h"
21
+ #include " llvm/ADT/StringSet.h"
20
22
#include " llvm/ADT/Twine.h"
21
23
#include " llvm/Support/Debug.h"
22
24
#include " llvm/Support/ErrorHandling.h"
25
27
#include < algorithm>
26
28
#include < cstdio>
27
29
#include < set>
28
- #include < sstream>
29
30
using namespace llvm ;
30
31
31
32
#define DEBUG_TYPE " dag-patterns"
@@ -98,7 +99,7 @@ bool TypeSetByHwMode::isPossible() const {
98
99
99
100
bool TypeSetByHwMode::insert (const ValueTypeByHwMode &VVT) {
100
101
bool Changed = false ;
101
- std::set <unsigned > Modes;
102
+ SmallDenseSet <unsigned , 4 > Modes;
102
103
for (const auto &P : VVT) {
103
104
unsigned M = P.first ;
104
105
Modes.insert (M);
@@ -114,7 +115,6 @@ bool TypeSetByHwMode::insert(const ValueTypeByHwMode &VVT) {
114
115
if (!Modes.count (I.first ))
115
116
Changed |= I.second .insert (DT).second ;
116
117
}
117
-
118
118
return Changed;
119
119
}
120
120
@@ -164,40 +164,37 @@ bool TypeSetByHwMode::assign_if(const TypeSetByHwMode &VTS, Predicate P) {
164
164
return !empty ();
165
165
}
166
166
167
- std::string TypeSetByHwMode::getAsString ( ) const {
168
- std::stringstream str ;
169
- std::vector< unsigned > Modes;
167
+ void TypeSetByHwMode::writeToStream (raw_ostream &OS ) const {
168
+ SmallVector< unsigned , 4 > Modes ;
169
+ Modes. reserve (Map. size ()) ;
170
170
171
171
for (const auto &I : *this )
172
172
Modes.push_back (I.first );
173
- if (Modes.empty ())
174
- return " {}" ;
173
+ if (Modes.empty ()) {
174
+ OS << " {}" ;
175
+ return ;
176
+ }
175
177
array_pod_sort (Modes.begin (), Modes.end ());
176
178
177
- str << ' {' ;
179
+ OS << ' {' ;
178
180
for (unsigned M : Modes) {
179
- const SetType &S = get (M);
180
- str << ' ' << getModeName (M) << ' : ' << getAsString (S );
181
+ OS << ' ' << getModeName (M) << ' : ' ;
182
+ writeToStream ( get (M), OS );
181
183
}
182
- str << " }" ;
183
- return str.str ();
184
+ OS << " }" ;
184
185
}
185
186
186
- std::string TypeSetByHwMode::getAsString (const SetType &S) {
187
- std::vector<MVT> Types;
188
- for (MVT T : S)
189
- Types.push_back (T);
187
+ void TypeSetByHwMode::writeToStream (const SetType &S, raw_ostream &OS) {
188
+ SmallVector<MVT, 4 > Types (S.begin (), S.end ());
190
189
array_pod_sort (Types.begin (), Types.end ());
191
190
192
- std::stringstream str;
193
- str << ' [' ;
191
+ OS << ' [' ;
194
192
for (unsigned i = 0 , e = Types.size (); i != e; ++i) {
195
- str << ValueTypeByHwMode::getMVTName (Types[i]);
193
+ OS << ValueTypeByHwMode::getMVTName (Types[i]);
196
194
if (i != e-1 )
197
- str << ' ' ;
195
+ OS << ' ' ;
198
196
}
199
- str << ' ]' ;
200
- return str.str ();
197
+ OS << ' ]' ;
201
198
}
202
199
203
200
bool TypeSetByHwMode::operator ==(const TypeSetByHwMode &VTS) const {
@@ -211,7 +208,7 @@ bool TypeSetByHwMode::operator==(const TypeSetByHwMode &VTS) const {
211
208
return false ;
212
209
}
213
210
214
- std::set <unsigned > Modes;
211
+ SmallDenseSet <unsigned , 4 > Modes;
215
212
for (auto &I : *this )
216
213
Modes.insert (I.first );
217
214
for (const auto &I : VTS)
@@ -243,7 +240,8 @@ bool TypeSetByHwMode::operator==(const TypeSetByHwMode &VTS) const {
243
240
244
241
LLVM_DUMP_METHOD
245
242
void TypeSetByHwMode::dump () const {
246
- dbgs () << getAsString () << ' \n ' ;
243
+ writeToStream (dbgs ());
244
+ dbgs () << ' \n ' ;
247
245
}
248
246
249
247
bool TypeSetByHwMode::intersect (SetType &Out, const SetType &In) {
@@ -784,6 +782,7 @@ void TypeInfer::expandOverloads(TypeSetByHwMode::SetType &Out,
784
782
for (MVT T : Out) {
785
783
if (!T.isOverloaded ())
786
784
continue ;
785
+
787
786
Ovs.insert (T);
788
787
// MachineValueTypeSet allows iteration and erasing.
789
788
Out.erase (T);
@@ -1410,8 +1409,10 @@ void TreePatternNode::print(raw_ostream &OS) const {
1410
1409
else
1411
1410
OS << ' (' << getOperator ()->getName ();
1412
1411
1413
- for (unsigned i = 0 , e = Types.size (); i != e; ++i)
1414
- OS << ' :' << getExtType (i).getAsString ();
1412
+ for (unsigned i = 0 , e = Types.size (); i != e; ++i) {
1413
+ OS << ' :' ;
1414
+ getExtType (i).writeToStream (OS);
1415
+ }
1415
1416
1416
1417
if (!isLeaf ()) {
1417
1418
if (getNumChildren () != 0 ) {
@@ -2628,7 +2629,10 @@ void CodeGenDAGPatterns::ParsePatternFragments(bool OutFrags) {
2628
2629
2629
2630
// Validate the argument list, converting it to set, to discard duplicates.
2630
2631
std::vector<std::string> &Args = P->getArgList ();
2631
- std::set<std::string> OperandsSet (Args.begin (), Args.end ());
2632
+ // Copy the args so we can take StringRefs to them.
2633
+ auto ArgsCopy = Args;
2634
+ SmallDenseSet<StringRef, 4 > OperandsSet;
2635
+ OperandsSet.insert (ArgsCopy.begin (), ArgsCopy.end ());
2632
2636
2633
2637
if (OperandsSet.count (" " ))
2634
2638
P->error (" Cannot have unnamed 'node' values in pattern fragment!" );
@@ -3120,17 +3124,20 @@ const DAGInstruction &CodeGenDAGPatterns::parseInstructionPattern(
3120
3124
3121
3125
// Verify that the top-level forms in the instruction are of void type, and
3122
3126
// fill in the InstResults map.
3127
+ SmallString<32 > TypesString;
3123
3128
for (unsigned j = 0 , e = I->getNumTrees (); j != e; ++j) {
3129
+ TypesString.clear ();
3124
3130
TreePatternNode *Pat = I->getTree (j);
3125
3131
if (Pat->getNumTypes () != 0 ) {
3126
- std::string Types ;
3132
+ raw_svector_ostream OS (TypesString) ;
3127
3133
for (unsigned k = 0 , ke = Pat->getNumTypes (); k != ke; ++k) {
3128
3134
if (k > 0 )
3129
- Types += " , " ;
3130
- Types += Pat->getExtType (k).getAsString ( );
3135
+ OS << " , " ;
3136
+ Pat->getExtType (k).writeToStream (OS );
3131
3137
}
3132
3138
I->error (" Top-level forms in instruction pattern should have"
3133
- " void types, has types " + Types);
3139
+ " void types, has types " +
3140
+ OS.str ());
3134
3141
}
3135
3142
3136
3143
// Find inputs and outputs, and verify the structure of the uses/defs.
@@ -3812,11 +3819,11 @@ void CodeGenDAGPatterns::ExpandHwModeBasedTypes() {
3812
3819
}
3813
3820
3814
3821
// / Dependent variable map for CodeGenDAGPattern variant generation
3815
- typedef std::map<std::string, int > DepVarMap;
3822
+ typedef StringMap< int > DepVarMap;
3816
3823
3817
3824
static void FindDepVarsOf (TreePatternNode *N, DepVarMap &DepMap) {
3818
3825
if (N->isLeaf ()) {
3819
- if (isa<DefInit>(N->getLeafValue ()))
3826
+ if (N-> hasName () && isa<DefInit>(N->getLeafValue ()))
3820
3827
DepMap[N->getName ()]++;
3821
3828
} else {
3822
3829
for (size_t i = 0 , e = N->getNumChildren (); i != e; ++i)
@@ -3828,9 +3835,9 @@ static void FindDepVarsOf(TreePatternNode *N, DepVarMap &DepMap) {
3828
3835
static void FindDepVars (TreePatternNode *N, MultipleUseVarSet &DepVars) {
3829
3836
DepVarMap depcounts;
3830
3837
FindDepVarsOf (N, depcounts);
3831
- for (const std::pair<std::string, int > &Pair : depcounts) {
3832
- if (Pair.second > 1 )
3833
- DepVars.insert (Pair.first );
3838
+ for (const auto &Pair : depcounts) {
3839
+ if (Pair.getValue () > 1 )
3840
+ DepVars.insert (Pair.getKey () );
3834
3841
}
3835
3842
}
3836
3843
@@ -3841,8 +3848,8 @@ static void DumpDepVars(MultipleUseVarSet &DepVars) {
3841
3848
DEBUG (errs () << " <empty set>" );
3842
3849
} else {
3843
3850
DEBUG (errs () << " [ " );
3844
- for (const std::string &DepVar : DepVars) {
3845
- DEBUG (errs () << DepVar << " " );
3851
+ for (const auto &DepVar : DepVars) {
3852
+ DEBUG (errs () << DepVar. getKey () << " " );
3846
3853
}
3847
3854
DEBUG (errs () << " ]" );
3848
3855
}
0 commit comments