tidy up args to builders

This commit is contained in:
Justin Viiret 2017-01-31 10:28:10 +11:00 committed by Matthew Barr
parent 3ae2fb417e
commit c2cac5009a
6 changed files with 57 additions and 79 deletions

View File

@ -848,7 +848,6 @@ vector<raw_dfa> buildAnchoredDfas(RoseBuildImpl &build) {
aligned_unique_ptr<anchored_matcher_info>
buildAnchoredMatcher(RoseBuildImpl &build, vector<raw_dfa> &dfas,
const map<u32, LitFragment> &final_to_frag_map,
size_t *asize) {
const CompileContext &cc = build.cc;
@ -859,7 +858,7 @@ buildAnchoredMatcher(RoseBuildImpl &build, vector<raw_dfa> &dfas,
}
for (auto &rdfa : dfas) {
remapIdsToPrograms(rdfa, final_to_frag_map);
remapIdsToPrograms(rdfa, build.final_to_frag_map);
}
vector<aligned_unique_ptr<NFA>> nfas;

View File

@ -59,7 +59,6 @@ std::vector<raw_dfa> buildAnchoredDfas(RoseBuildImpl &build);
*/
aligned_unique_ptr<anchored_matcher_info>
buildAnchoredMatcher(RoseBuildImpl &build, std::vector<raw_dfa> &dfas,
const std::map<u32, LitFragment> &final_to_frag_map,
size_t *asize);
u32 anchoredStateSize(const anchored_matcher_info &atable);

View File

@ -4707,12 +4707,11 @@ map<u32, LitFragment> groupByFragment(const RoseBuildImpl &build) {
* - total number of literal fragments
*/
static
tuple<u32, u32, u32>
buildLiteralPrograms(RoseBuildImpl &build, build_context &bc,
map<u32, LitFragment> &final_to_frag_map) {
tuple<u32, u32, u32> buildLiteralPrograms(RoseBuildImpl &build,
build_context &bc) {
// Build a reverse mapping from fragment -> final_id.
map<u32, flat_set<u32>> frag_to_final_map;
for (const auto &m : final_to_frag_map) {
for (const auto &m : build.final_to_frag_map) {
frag_to_final_map[m.second.fragment_id].insert(m.first);
}
@ -4736,7 +4735,7 @@ buildLiteralPrograms(RoseBuildImpl &build, build_context &bc,
}
// Update LitFragment entries.
for (auto &frag : final_to_frag_map | map_values) {
for (auto &frag : build.final_to_frag_map | map_values) {
frag.lit_program_offset = litPrograms[frag.fragment_id];
frag.delay_program_offset = delayRebuildPrograms[frag.fragment_id];
}
@ -5480,7 +5479,7 @@ aligned_unique_ptr<RoseEngine> RoseBuildImpl::buildFinalEngine(u32 minWidth) {
u32 litDelayRebuildProgramOffset;
u32 litProgramCount;
tie(litProgramOffset, litDelayRebuildProgramOffset, litProgramCount) =
buildLiteralPrograms(*this, bc, final_to_frag_map);
buildLiteralPrograms(*this, bc);
u32 delayProgramOffset = buildDelayPrograms(*this, bc);
u32 anchoredProgramOffset = buildAnchoredPrograms(*this, bc);
@ -5519,8 +5518,7 @@ aligned_unique_ptr<RoseEngine> RoseBuildImpl::buildFinalEngine(u32 minWidth) {
// Build anchored matcher.
size_t asize = 0;
u32 amatcherOffset = 0;
auto atable =
buildAnchoredMatcher(*this, anchored_dfas, final_to_frag_map, &asize);
auto atable = buildAnchoredMatcher(*this, anchored_dfas, &asize);
if (atable) {
currOffset = ROUNDUP_CL(currOffset);
amatcherOffset = currOffset;
@ -5531,8 +5529,7 @@ aligned_unique_ptr<RoseEngine> RoseBuildImpl::buildFinalEngine(u32 minWidth) {
rose_group fgroups = 0;
size_t fsize = 0;
auto ftable = buildFloatingMatcher(*this, bc.longLitLengthThreshold,
final_to_frag_map, &fgroups, &fsize,
&historyRequired);
&fgroups, &fsize, &historyRequired);
u32 fmatcherOffset = 0;
if (ftable) {
currOffset = ROUNDUP_CL(currOffset);
@ -5543,8 +5540,8 @@ aligned_unique_ptr<RoseEngine> RoseBuildImpl::buildFinalEngine(u32 minWidth) {
// Build delay rebuild HWLM matcher.
size_t drsize = 0;
auto drtable = buildDelayRebuildMatcher(*this, bc.longLitLengthThreshold,
final_to_frag_map, &drsize);
auto drtable =
buildDelayRebuildMatcher(*this, bc.longLitLengthThreshold, &drsize);
u32 drmatcherOffset = 0;
if (drtable) {
currOffset = ROUNDUP_CL(currOffset);
@ -5554,7 +5551,7 @@ aligned_unique_ptr<RoseEngine> RoseBuildImpl::buildFinalEngine(u32 minWidth) {
// Build EOD-anchored HWLM matcher.
size_t esize = 0;
auto etable = buildEodAnchoredMatcher(*this, final_to_frag_map, &esize);
auto etable = buildEodAnchoredMatcher(*this, &esize);
u32 ematcherOffset = 0;
if (etable) {
currOffset = ROUNDUP_CL(currOffset);
@ -5564,7 +5561,7 @@ aligned_unique_ptr<RoseEngine> RoseBuildImpl::buildFinalEngine(u32 minWidth) {
// Build small-block HWLM matcher.
size_t sbsize = 0;
auto sbtable = buildSmallBlockMatcher(*this, final_to_frag_map, &sbsize);
auto sbtable = buildSmallBlockMatcher(*this, &sbsize);
u32 sbmatcherOffset = 0;
if (sbtable) {
currOffset = ROUNDUP_CL(currOffset);

View File

@ -505,28 +505,24 @@ void dumpRoseTestLiterals(const RoseBuildImpl &build, const string &base) {
size_t longLitLengthThreshold =
calcLongLitThreshold(build, historyRequired);
auto mp = makeMatcherProto(build, build.final_to_frag_map, ROSE_ANCHORED,
false, longLitLengthThreshold);
auto mp =
makeMatcherProto(build, ROSE_ANCHORED, false, longLitLengthThreshold);
dumpTestLiterals(base + "rose_anchored_test_literals.txt", mp.lits);
mp = makeMatcherProto(build, build.final_to_frag_map, ROSE_FLOATING, false,
longLitLengthThreshold);
mp = makeMatcherProto(build, ROSE_FLOATING, false, longLitLengthThreshold);
dumpTestLiterals(base + "rose_float_test_literals.txt", mp.lits);
mp = makeMatcherProto(build, build.final_to_frag_map, ROSE_FLOATING, true,
longLitLengthThreshold);
mp = makeMatcherProto(build, ROSE_FLOATING, true, longLitLengthThreshold);
dumpTestLiterals(base + "rose_delay_rebuild_test_literals.txt", mp.lits);
mp = makeMatcherProto(build, build.final_to_frag_map, ROSE_EOD_ANCHORED,
false, build.ematcher_region_size);
mp = makeMatcherProto(build, ROSE_EOD_ANCHORED, false,
build.ematcher_region_size);
dumpTestLiterals(base + "rose_eod_test_literals.txt", mp.lits);
if (!build.cc.streaming) {
mp =
makeMatcherProto(build, build.final_to_frag_map, ROSE_FLOATING,
false, ROSE_SMALL_BLOCK_LEN, ROSE_SMALL_BLOCK_LEN);
auto mp2 = makeMatcherProto(build, build.final_to_frag_map,
ROSE_ANCHORED_SMALL_BLOCK, false,
mp = makeMatcherProto(build, ROSE_FLOATING, false, ROSE_SMALL_BLOCK_LEN,
ROSE_SMALL_BLOCK_LEN);
auto mp2 = makeMatcherProto(build, ROSE_ANCHORED_SMALL_BLOCK, false,
ROSE_SMALL_BLOCK_LEN, ROSE_SMALL_BLOCK_LEN);
mp.lits.insert(end(mp.lits), begin(mp2.lits), end(mp2.lits));
dumpTestLiterals(base + "rose_smallblock_test_literals.txt", mp.lits);

View File

@ -636,11 +636,10 @@ u64a literalMinReportOffset(const RoseBuildImpl &build,
}
static
map<u32, hwlm_group_t> makeFragGroupMap(const RoseBuildImpl &build,
const map<u32, LitFragment> &final_to_frag_map) {
map<u32, hwlm_group_t> makeFragGroupMap(const RoseBuildImpl &build) {
map<u32, hwlm_group_t> frag_to_group;
for (const auto &m : final_to_frag_map) {
for (const auto &m : build.final_to_frag_map) {
u32 final_id = m.first;
u32 frag_id = m.second.fragment_id;
hwlm_group_t groups = 0;
@ -665,7 +664,6 @@ void trim_to_suffix(Container &c, size_t len) {
}
MatcherProto makeMatcherProto(const RoseBuildImpl &build,
const map<u32, LitFragment> &final_to_frag_map,
rose_literal_table table, bool delay_rebuild,
size_t max_len, u32 max_offset) {
MatcherProto mp;
@ -753,12 +751,12 @@ MatcherProto makeMatcherProto(const RoseBuildImpl &build,
cmp);
}
auto frag_group_map = makeFragGroupMap(build, final_to_frag_map);
auto frag_group_map = makeFragGroupMap(build);
for (auto &lit : mp.lits) {
u32 final_id = lit.id;
assert(contains(final_to_frag_map, final_id));
const auto &frag = final_to_frag_map.at(final_id);
assert(contains(build.final_to_frag_map, final_id));
const auto &frag = build.final_to_frag_map.at(final_id);
lit.id = delay_rebuild ? frag.delay_program_offset
: frag.lit_program_offset;
assert(contains(frag_group_map, frag.fragment_id));
@ -805,14 +803,13 @@ void buildAccel(const RoseBuildImpl &build, const MatcherProto &mp,
aligned_unique_ptr<HWLM>
buildFloatingMatcher(const RoseBuildImpl &build, size_t longLitLengthThreshold,
const map<u32, LitFragment> &final_to_frag_map,
rose_group *fgroups, size_t *fsize,
size_t *historyRequired) {
*fsize = 0;
*fgroups = 0;
auto mp = makeMatcherProto(build, final_to_frag_map, ROSE_FLOATING, false,
longLitLengthThreshold);
auto mp =
makeMatcherProto(build, ROSE_FLOATING, false, longLitLengthThreshold);
if (mp.lits.empty()) {
DEBUG_PRINTF("empty floating matcher\n");
return nullptr;
@ -841,9 +838,9 @@ buildFloatingMatcher(const RoseBuildImpl &build, size_t longLitLengthThreshold,
return hwlm;
}
aligned_unique_ptr<HWLM> buildDelayRebuildMatcher(
const RoseBuildImpl &build, size_t longLitLengthThreshold,
const map<u32, LitFragment> &final_to_frag_map, size_t *drsize) {
aligned_unique_ptr<HWLM> buildDelayRebuildMatcher(const RoseBuildImpl &build,
size_t longLitLengthThreshold,
size_t *drsize) {
*drsize = 0;
if (!build.cc.streaming) {
@ -851,8 +848,8 @@ aligned_unique_ptr<HWLM> buildDelayRebuildMatcher(
return nullptr;
}
auto mp = makeMatcherProto(build, final_to_frag_map, ROSE_FLOATING, true,
longLitLengthThreshold);
auto mp =
makeMatcherProto(build, ROSE_FLOATING, true, longLitLengthThreshold);
if (mp.lits.empty()) {
DEBUG_PRINTF("empty delay rebuild matcher\n");
return nullptr;
@ -871,10 +868,8 @@ aligned_unique_ptr<HWLM> buildDelayRebuildMatcher(
return hwlm;
}
aligned_unique_ptr<HWLM>
buildSmallBlockMatcher(const RoseBuildImpl &build,
const map<u32, LitFragment> &final_to_frag_map,
size_t *sbsize) {
aligned_unique_ptr<HWLM> buildSmallBlockMatcher(const RoseBuildImpl &build,
size_t *sbsize) {
*sbsize = 0;
if (build.cc.streaming) {
@ -889,7 +884,7 @@ buildSmallBlockMatcher(const RoseBuildImpl &build,
return nullptr;
}
auto mp = makeMatcherProto(build, final_to_frag_map, ROSE_FLOATING, false,
auto mp = makeMatcherProto(build, ROSE_FLOATING, false,
ROSE_SMALL_BLOCK_LEN, ROSE_SMALL_BLOCK_LEN);
if (mp.lits.empty()) {
DEBUG_PRINTF("no floating table\n");
@ -900,8 +895,8 @@ buildSmallBlockMatcher(const RoseBuildImpl &build,
}
auto mp_anchored =
makeMatcherProto(build, final_to_frag_map, ROSE_ANCHORED_SMALL_BLOCK,
false, ROSE_SMALL_BLOCK_LEN, ROSE_SMALL_BLOCK_LEN);
makeMatcherProto(build, ROSE_ANCHORED_SMALL_BLOCK, false,
ROSE_SMALL_BLOCK_LEN, ROSE_SMALL_BLOCK_LEN);
if (mp_anchored.lits.empty()) {
DEBUG_PRINTF("no small-block anchored literals\n");
return nullptr;
@ -932,14 +927,12 @@ buildSmallBlockMatcher(const RoseBuildImpl &build,
return hwlm;
}
aligned_unique_ptr<HWLM>
buildEodAnchoredMatcher(const RoseBuildImpl &build,
const map<u32, LitFragment> &final_to_frag_map,
size_t *esize) {
aligned_unique_ptr<HWLM> buildEodAnchoredMatcher(const RoseBuildImpl &build,
size_t *esize) {
*esize = 0;
auto mp = makeMatcherProto(build, final_to_frag_map, ROSE_EOD_ANCHORED,
false, build.ematcher_region_size);
auto mp = makeMatcherProto(build, ROSE_EOD_ANCHORED, false,
build.ematcher_region_size);
if (mp.lits.empty()) {
DEBUG_PRINTF("no eod anchored literals\n");

View File

@ -67,31 +67,25 @@ struct MatcherProto {
* If max_offset is specified (and not ROSE_BOUND_INF), then literals that can
* only lead to a pattern match after max_offset may be excluded.
*/
MatcherProto
makeMatcherProto(const RoseBuildImpl &build,
const std::map<u32, LitFragment> &final_to_frag_map,
rose_literal_table table, bool delay_rebuild, size_t max_len,
u32 max_offset = ROSE_BOUND_INF);
MatcherProto makeMatcherProto(const RoseBuildImpl &build,
rose_literal_table table, bool delay_rebuild,
size_t max_len, u32 max_offset = ROSE_BOUND_INF);
aligned_unique_ptr<HWLM>
buildFloatingMatcher(const RoseBuildImpl &build, size_t longLitLengthThreshold,
const std::map<u32, LitFragment> &final_to_frag_map,
rose_group *fgroups, size_t *fsize,
size_t *historyRequired);
aligned_unique_ptr<HWLM> buildFloatingMatcher(const RoseBuildImpl &build,
size_t longLitLengthThreshold,
rose_group *fgroups,
size_t *fsize,
size_t *historyRequired);
aligned_unique_ptr<HWLM> buildDelayRebuildMatcher(
const RoseBuildImpl &build, size_t longLitLengthThreshold,
const std::map<u32, LitFragment> &final_to_frag_map, size_t *drsize);
aligned_unique_ptr<HWLM> buildDelayRebuildMatcher(const RoseBuildImpl &build,
size_t longLitLengthThreshold,
size_t *drsize);
aligned_unique_ptr<HWLM>
buildSmallBlockMatcher(const RoseBuildImpl &build,
const std::map<u32, LitFragment> &final_to_frag_map,
size_t *sbsize);
aligned_unique_ptr<HWLM> buildSmallBlockMatcher(const RoseBuildImpl &build,
size_t *sbsize);
aligned_unique_ptr<HWLM>
buildEodAnchoredMatcher(const RoseBuildImpl &build,
const std::map<u32, LitFragment> &final_to_frag_map,
size_t *esize);
aligned_unique_ptr<HWLM> buildEodAnchoredMatcher(const RoseBuildImpl &build,
size_t *esize);
void findMoreLiteralMasks(RoseBuildImpl &build);