[Constraint graph] Handle orphaned constraints within connected components

Move the logic for creating connected components of orphaned
constraints into the connected-components algorithm code, rather than
making it a special part of SplitterStep.
This commit is contained in:
Doug Gregor
2019-08-07 15:34:21 -07:00
parent 5a4af23a63
commit ab38be128d
4 changed files with 32 additions and 35 deletions

View File

@@ -97,32 +97,13 @@ void SplitterStep::computeFollowupSteps(
// Compute the connected components of the constraint graph.
auto components = CG.computeConnectedComponents(CS.TypeVariables);
unsigned numComponents =
components.size() + CG.getOrphanedConstraints().size();
unsigned numComponents = components.size();
if (numComponents < 2) {
componentSteps.push_back(llvm::make_unique<ComponentStep>(
CS, 0, &CS.InactiveConstraints, Solutions));
return;
}
Components.resize(numComponents);
PartialSolutions = std::unique_ptr<SmallVector<Solution, 4>[]>(
new SmallVector<Solution, 4>[numComponents]);
// Add components.
for (unsigned i : indices(components)) {
componentSteps.push_back(llvm::make_unique<ComponentStep>(
CS, i, &Components[i], std::move(components[i]), PartialSolutions[i]));
}
// Add components for the orphaned constraints.
OrphanedConstraints = CG.takeOrphanedConstraints();
for (unsigned i : range(components.size(), numComponents)) {
auto orphaned = OrphanedConstraints[i - components.size()];
componentSteps.push_back(llvm::make_unique<ComponentStep>(
CS, i, &Components[i], orphaned, PartialSolutions[i]));
}
if (isDebugMode()) {
auto &log = getDebugLogger();
// Verify that the constraint graph is valid.
@@ -135,6 +116,19 @@ void SplitterStep::computeFollowupSteps(
CG.printConnectedComponents(CS.TypeVariables, log);
}
// Take the orphaned constraints, because they'll go into a component now.
OrphanedConstraints = CG.takeOrphanedConstraints();
Components.resize(numComponents);
PartialSolutions = std::unique_ptr<SmallVector<Solution, 4>[]>(
new SmallVector<Solution, 4>[numComponents]);
// Add components.
for (unsigned i : indices(components)) {
componentSteps.push_back(llvm::make_unique<ComponentStep>(
CS, i, &Components[i], std::move(components[i]), PartialSolutions[i]));
}
// Create component ordering based on the information associated
// with constraints in each step - e.g. number of disjunctions,
// since components are going to be executed in LIFO order, we'd