@@ -96,27 +96,14 @@ void SplitterStep::computeFollowupSteps(
96
96
CG.optimize ();
97
97
98
98
// Compute the connected components of the constraint graph.
99
- // FIXME: We're seeding typeVars with TypeVariables so that the
100
- // connected-components algorithm only considers those type variables within
101
- // our component. There are clearly better ways to do this.
102
- std::vector<TypeVariableType *> typeVars (CS.TypeVariables );
103
- std::vector<unsigned > components;
104
- unsigned numComponents = CG.computeConnectedComponents (typeVars, components);
99
+ auto components = CG.computeConnectedComponents (CS.TypeVariables );
100
+ unsigned numComponents = components.size ();
105
101
if (numComponents < 2 ) {
106
102
componentSteps.push_back (llvm::make_unique<ComponentStep>(
107
- CS, 0 , /* single= */ true , &CS.InactiveConstraints , Solutions));
103
+ CS, 0 , &CS.InactiveConstraints , Solutions));
108
104
return ;
109
105
}
110
106
111
- Components.resize (numComponents);
112
- PartialSolutions = std::unique_ptr<SmallVector<Solution, 4 >[]>(
113
- new SmallVector<Solution, 4 >[numComponents]);
114
-
115
- for (unsigned i = 0 , n = numComponents; i != n; ++i) {
116
- componentSteps.push_back (llvm::make_unique<ComponentStep>(
117
- CS, i, /* single=*/ false , &Components[i], PartialSolutions[i]));
118
- }
119
-
120
107
if (isDebugMode ()) {
121
108
auto &log = getDebugLogger ();
122
109
// Verify that the constraint graph is valid.
@@ -129,66 +116,20 @@ void SplitterStep::computeFollowupSteps(
129
116
CG.printConnectedComponents (CS.TypeVariables , log);
130
117
}
131
118
132
- // Map type variables and constraints into appropriate steps.
133
- llvm::DenseMap<TypeVariableType *, unsigned > typeVarComponent;
134
- llvm::DenseMap<Constraint *, unsigned > constraintComponent;
135
- for (unsigned i = 0 , n = typeVars.size (); i != n; ++i) {
136
- auto *typeVar = typeVars[i];
137
- // Record the component of this type variable.
138
- typeVarComponent[typeVar] = components[i];
139
-
140
- for (auto *constraint : CG[typeVar].getConstraints ())
141
- constraintComponent[constraint] = components[i];
142
- }
143
-
144
- // Add the orphaned components to the mapping from constraints to components.
145
- unsigned firstOrphanedComponent =
146
- numComponents - CG.getOrphanedConstraints ().size ();
147
- {
148
- unsigned component = firstOrphanedComponent;
149
- for (auto *constraint : CG.getOrphanedConstraints ()) {
150
- // Register this orphan constraint both as associated with
151
- // a given component as a regular constrant, as well as an
152
- // "orphan" constraint, so it can be proccessed correctly.
153
- constraintComponent[constraint] = component;
154
- componentSteps[component]->recordOrphan (constraint);
155
- ++component;
156
- }
157
- }
119
+ // Take the orphaned constraints, because they'll go into a component now.
120
+ OrphanedConstraints = CG.takeOrphanedConstraints ();
158
121
159
- for (auto *typeVar : CS.TypeVariables ) {
160
- auto known = typeVarComponent.find (typeVar);
161
- // If current type variable is associated with
162
- // a certain component step, record it as being so.
163
- if (known != typeVarComponent.end ()) {
164
- componentSteps[known->second ]->record (typeVar);
165
- continue ;
166
- }
167
- }
122
+ Components.resize (numComponents);
123
+ PartialSolutions = std::unique_ptr<SmallVector<Solution, 4 >[]>(
124
+ new SmallVector<Solution, 4 >[numComponents]);
168
125
169
- // Transfer all of the constraints from the work list to
170
- // the appropriate component.
171
- auto &workList = CS.InactiveConstraints ;
172
- while (!workList.empty ()) {
173
- auto *constraint = &workList.front ();
174
- workList.pop_front ();
175
- assert (constraintComponent.count (constraint) > 0 && " Missed a constraint" );
176
- componentSteps[constraintComponent[constraint]]->record (constraint);
126
+ // Add components.
127
+ for (unsigned i : indices (components)) {
128
+ unsigned solutionIndex = components[i].solutionIndex ;
129
+ componentSteps.push_back (llvm::make_unique<ComponentStep>(
130
+ CS, solutionIndex, &Components[i], std::move (components[i]),
131
+ PartialSolutions[solutionIndex]));
177
132
}
178
-
179
- // Remove all of the orphaned constraints; they'll be re-introduced
180
- // by each component independently.
181
- OrphanedConstraints = CG.takeOrphanedConstraints ();
182
-
183
- // Create component ordering based on the information associated
184
- // with constraints in each step - e.g. number of disjunctions,
185
- // since components are going to be executed in LIFO order, we'd
186
- // want to have smaller/faster components at the back of the list.
187
- std::sort (componentSteps.begin (), componentSteps.end (),
188
- [](const std::unique_ptr<ComponentStep> &lhs,
189
- const std::unique_ptr<ComponentStep> &rhs) {
190
- return lhs->disjunctionCount () > rhs->disjunctionCount ();
191
- });
192
133
}
193
134
194
135
bool SplitterStep::mergePartialSolutions () const {
0 commit comments