Prevent trying to build smallwrite engine for large cases

This commit is contained in:
Alex Coyte 2016-05-30 14:00:31 +10:00 committed by Matthew Barr
parent b097cb1b53
commit cb7067f59d
7 changed files with 34 additions and 15 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, Intel Corporation
* Copyright (c) 2015-2016, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@ -126,6 +126,8 @@ Grey::Grey(void) :
// are given to rose &co
smallWriteLargestBufferBad(35),
limitSmallWriteOutfixSize(1048576), // 1 MB
smallWriteMaxPatterns(10000),
smallWriteMaxLiterals(10000),
dumpFlags(0),
limitPatternCount(8000000), // 8M patterns
limitPatternLength(16000), // 16K bytes
@ -273,6 +275,8 @@ void applyGreyOverrides(Grey *g, const string &s) {
G_UPDATE(smallWriteLargestBuffer);
G_UPDATE(smallWriteLargestBufferBad);
G_UPDATE(limitSmallWriteOutfixSize);
G_UPDATE(smallWriteMaxPatterns);
G_UPDATE(smallWriteMaxLiterals);
G_UPDATE(limitPatternCount);
G_UPDATE(limitPatternLength);
G_UPDATE(limitGraphVertices);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, Intel Corporation
* Copyright (c) 2015-2016, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@ -143,6 +143,8 @@ struct Grey {
u32 smallWriteLargestBuffer; // largest buffer that can be small write
u32 smallWriteLargestBufferBad;// largest buffer that can be small write
u32 limitSmallWriteOutfixSize; //!< max total size of outfix DFAs
u32 smallWriteMaxPatterns; // only try small writes if fewer patterns
u32 smallWriteMaxLiterals; // only try small writes if fewer literals
enum DumpFlags {
DUMP_NONE = 0,

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, Intel Corporation
* Copyright (c) 2015-2016, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@ -219,7 +219,7 @@ hs_compile_multi_int(const char *const *expressions, const unsigned *flags,
: get_current_target();
CompileContext cc(isStreaming, isVectored, target_info, g);
NG ng(cc, somPrecision);
NG ng(cc, elements, somPrecision);
try {
for (unsigned int i = 0; i < elements; i++) {

View File

@ -75,14 +75,15 @@ using namespace std;
namespace ue2 {
NG::NG(const CompileContext &in_cc, unsigned in_somPrecision)
NG::NG(const CompileContext &in_cc, size_t num_patterns,
unsigned in_somPrecision)
: maxSomRevHistoryAvailable(in_cc.grey.somMaxRevNfaLength),
minWidth(depth::infinity()),
rm(in_cc.grey),
ssm(in_somPrecision),
cc(in_cc),
rose(makeRoseBuilder(rm, ssm, cc, boundary)),
smwr(makeSmallWriteBuilder(rm, cc)) {
smwr(makeSmallWriteBuilder(num_patterns, rm, cc)) {
}
NG::~NG() {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, Intel Corporation
* Copyright (c) 2015-2016, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@ -87,7 +87,8 @@ class SmallWriteBuild;
class NG : boost::noncopyable {
public:
NG(const CompileContext &in_cc, unsigned in_somPrecision);
NG(const CompileContext &in_cc, size_t num_patterns,
unsigned in_somPrecision);
~NG();
/** \brief Consumes a pattern, returns false or throws a CompileError

View File

@ -65,7 +65,8 @@ namespace { // unnamed
// Concrete impl class
class SmallWriteBuildImpl : public SmallWriteBuild {
public:
SmallWriteBuildImpl(const ReportManager &rm, const CompileContext &cc);
SmallWriteBuildImpl(size_t num_patterns, const ReportManager &rm,
const CompileContext &cc);
// Construct a runtime implementation.
aligned_unique_ptr<SmallWriteEngine> build(u32 roseQuality) override;
@ -87,11 +88,14 @@ public:
SmallWriteBuild::~SmallWriteBuild() { }
SmallWriteBuildImpl::SmallWriteBuildImpl(const ReportManager &rm_in,
SmallWriteBuildImpl::SmallWriteBuildImpl(size_t num_patterns,
const ReportManager &rm_in,
const CompileContext &cc_in)
: rm(rm_in), cc(cc_in),
/* small write is block mode only */
poisoned(!cc.grey.allowSmallWrite || cc.streaming) {
poisoned(!cc.grey.allowSmallWrite
|| cc.streaming
|| num_patterns > cc.grey.smallWriteMaxPatterns) {
}
void SmallWriteBuildImpl::add(const NGWrapper &w) {
@ -163,6 +167,10 @@ void SmallWriteBuildImpl::add(const ue2_literal &literal, ReportID r) {
}
cand_literals.push_back(make_pair(literal, r));
if (cand_literals.size() > cc.grey.smallWriteMaxLiterals) {
poisoned = true;
}
}
static
@ -181,6 +189,7 @@ void lit_to_graph(NGHolder *h, const ue2_literal &literal, ReportID r) {
bool SmallWriteBuildImpl::determiniseLiterals() {
DEBUG_PRINTF("handling literals\n");
assert(!poisoned);
assert(cand_literals.size() <= cc.grey.smallWriteMaxLiterals);
if (cand_literals.empty()) {
return true; /* nothing to do */
@ -352,9 +361,10 @@ aligned_unique_ptr<NFA> prepEngine(raw_dfa &rdfa, u32 roseQuality,
}
// SmallWriteBuild factory
unique_ptr<SmallWriteBuild> makeSmallWriteBuilder(const ReportManager &rm,
unique_ptr<SmallWriteBuild> makeSmallWriteBuilder(size_t num_patterns,
const ReportManager &rm,
const CompileContext &cc) {
return ue2::make_unique<SmallWriteBuildImpl>(rm, cc);
return ue2::make_unique<SmallWriteBuildImpl>(num_patterns, rm, cc);
}
aligned_unique_ptr<SmallWriteEngine>

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, Intel Corporation
* Copyright (c) 2015-2016, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@ -64,7 +64,8 @@ public:
};
// Construct a usable SmallWrite builder.
std::unique_ptr<SmallWriteBuild> makeSmallWriteBuilder(const ReportManager &rm,
std::unique_ptr<SmallWriteBuild> makeSmallWriteBuilder(size_t num_patterns,
const ReportManager &rm,
const CompileContext &cc);
size_t smwrSize(const SmallWriteEngine *t);