[Sema] Add counter to track number of constraints considered by each edge contraction attempt

This commit is contained in:
Pavel Yaskevich
2018-05-11 22:50:52 -07:00
parent e021691bae
commit 3e254678a2
4 changed files with 33 additions and 1 deletions

View File

@@ -18,6 +18,7 @@
#include "ConstraintGraph.h"
#include "ConstraintGraphScope.h"
#include "ConstraintSystem.h"
#include "swift/Basic/Statistic.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/SaveAndRestore.h"
#include <algorithm>
@@ -27,6 +28,8 @@
using namespace swift;
using namespace constraints;
#define DEBUG_TYPE "ConstraintGraph"
#pragma mark Graph construction/destruction
ConstraintGraph::ConstraintGraph(ConstraintSystem &cs) : CS(cs) { }
@@ -650,7 +653,9 @@ static bool shouldContractEdge(ConstraintKind kind) {
bool ConstraintGraph::contractEdges() {
SmallVector<Constraint *, 16> constraints;
CS.findConstraints(constraints, [](const Constraint &constraint) {
CS.findConstraints(constraints, [&](const Constraint &constraint) {
// Track how many constraints did contraction algorithm iterated over.
incrementConstraintsPerContractionCounter();
return shouldContractEdge(constraint.getKind());
});
@@ -767,6 +772,14 @@ void ConstraintGraph::optimize() {
while (contractEdges()) {}
}
void ConstraintGraph::incrementConstraintsPerContractionCounter() {
SWIFT_FUNC_STAT;
auto &context = CS.getASTContext();
if (context.Stats)
context.Stats->getFrontendCounters()
.NumConstraintsConsideredForEdgeContraction++;
}
#pragma mark Debugging output
void ConstraintGraphNode::print(llvm::raw_ostream &out, unsigned indent) {