mirror of
https://github.com/VectorCamp/vectorscan.git
synced 2025-06-28 16:41:01 +03:00
ng_violet: make calcSplitRatio operation faster
Implements count_reachable in a less malloc-happy way, improving compile performance. Adds a count() function to small_color_map.
This commit is contained in:
parent
cadc7028b1
commit
08bf909e2b
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2016-2017, Intel Corporation
|
* Copyright (c) 2016-2018, Intel Corporation
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions are met:
|
* modification, are permitted provided that the following conditions are met:
|
||||||
@ -60,6 +60,7 @@
|
|||||||
#include "util/flat_containers.h"
|
#include "util/flat_containers.h"
|
||||||
#include "util/graph.h"
|
#include "util/graph.h"
|
||||||
#include "util/graph_range.h"
|
#include "util/graph_range.h"
|
||||||
|
#include "util/graph_small_color_map.h"
|
||||||
#include "util/insertion_ordered.h"
|
#include "util/insertion_ordered.h"
|
||||||
#include "util/make_unique.h"
|
#include "util/make_unique.h"
|
||||||
#include "util/order_check.h"
|
#include "util/order_check.h"
|
||||||
@ -133,14 +134,21 @@ bool createsTransientLHS(const NGHolder &g, const vector<NFAVertex> &vv,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Counts the number of vertices that are reachable from the set of sources
|
||||||
|
* given.
|
||||||
|
*/
|
||||||
static
|
static
|
||||||
double calcSplitRatio(const NGHolder &g, const vector<NFAVertex> &vv) {
|
size_t count_reachable(const NGHolder &g, const vector<NFAVertex> &sources,
|
||||||
flat_set<NFAVertex> not_reachable;
|
small_color_map<decltype(get(vertex_index, g))> &color_map) {
|
||||||
find_unreachable(g, vv, ¬_reachable);
|
auto null_visitor = boost::make_dfs_visitor(boost::null_visitor());
|
||||||
double rv = (double)not_reachable.size() / num_vertices(g);
|
color_map.fill(small_color::white);
|
||||||
rv = rv > 0.5 ? 1 - rv : rv;
|
|
||||||
|
|
||||||
return rv;
|
for (auto v : sources) {
|
||||||
|
boost::depth_first_visit(g, v, null_visitor, color_map);
|
||||||
|
}
|
||||||
|
|
||||||
|
return color_map.count(small_color::black);
|
||||||
}
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
@ -687,8 +695,12 @@ unique_ptr<VertLitInfo> findBestSplit(const NGHolder &g,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (last_chance) {
|
if (last_chance) {
|
||||||
|
const size_t num_verts = num_vertices(g);
|
||||||
|
auto color_map = make_small_color_map(g);
|
||||||
for (auto &a : lits) {
|
for (auto &a : lits) {
|
||||||
a->split_ratio = calcSplitRatio(g, a->vv);
|
size_t num_reachable = count_reachable(g, a->vv, color_map);
|
||||||
|
double ratio = (double)num_reachable / (double)num_verts;
|
||||||
|
a->split_ratio = ratio > 0.5 ? 1 - ratio : ratio;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2017, Intel Corporation
|
* Copyright (c) 2017-2018, Intel Corporation
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions are met:
|
* modification, are permitted provided that the following conditions are met:
|
||||||
@ -114,6 +114,21 @@ public:
|
|||||||
std::memset(data->data(), val, data->size());
|
std::memset(data->data(), val, data->size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t count(small_color color) const {
|
||||||
|
assert(static_cast<u8>(color) < sizeof(fill_lut));
|
||||||
|
size_t num = 0;
|
||||||
|
for (size_t i = 0; i < n; i++) {
|
||||||
|
size_t byte = i / entries_per_byte;
|
||||||
|
assert(byte < data->size());
|
||||||
|
size_t bit = (i % entries_per_byte) * bit_size;
|
||||||
|
u8 val = ((*data)[byte] >> bit) & bit_mask;
|
||||||
|
if (static_cast<small_color>(val) == color) {
|
||||||
|
num++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return num;
|
||||||
|
}
|
||||||
|
|
||||||
small_color get_impl(key_type key) const {
|
small_color get_impl(key_type key) const {
|
||||||
auto i = get(index_map, key);
|
auto i = get(index_map, key);
|
||||||
assert(i < n);
|
assert(i < n);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user