mirror of
https://github.com/VectorCamp/vectorscan.git
synced 2025-09-29 19:24:25 +03:00
mcclellan, gough: native report remapping
This commit is contained in:
committed by
Matthew Barr
parent
611579511c
commit
1f41a921f2
@@ -41,8 +41,9 @@
|
||||
#include "util/graph_range.h"
|
||||
#include "util/make_unique.h"
|
||||
#include "util/order_check.h"
|
||||
#include "util/verify_types.h"
|
||||
#include "util/report_manager.h"
|
||||
#include "util/ue2_containers.h"
|
||||
#include "util/verify_types.h"
|
||||
|
||||
#include "ue2common.h"
|
||||
|
||||
@@ -77,9 +78,10 @@ namespace {
|
||||
|
||||
class gough_build_strat : public mcclellan_build_strat {
|
||||
public:
|
||||
gough_build_strat(raw_som_dfa &r, const GoughGraph &g,
|
||||
const map<dstate_id_t, gough_accel_state_info> &accel_info)
|
||||
: mcclellan_build_strat(r), rdfa(r), gg(g),
|
||||
gough_build_strat(
|
||||
raw_som_dfa &r, const GoughGraph &g, const ReportManager &rm,
|
||||
const map<dstate_id_t, gough_accel_state_info> &accel_info)
|
||||
: mcclellan_build_strat(r, rm), rdfa(r), gg(g),
|
||||
accel_gough_info(accel_info) {}
|
||||
unique_ptr<raw_report_info> gatherReports(vector<u32> &reports /* out */,
|
||||
vector<u32> &reports_eod /* out */,
|
||||
@@ -1035,7 +1037,8 @@ void update_accel_prog_offset(const gough_build_strat &gbs,
|
||||
}
|
||||
|
||||
aligned_unique_ptr<NFA> goughCompile(raw_som_dfa &raw, u8 somPrecision,
|
||||
const CompileContext &cc) {
|
||||
const CompileContext &cc,
|
||||
const ReportManager &rm) {
|
||||
assert(somPrecision == 2 || somPrecision == 4 || somPrecision == 8
|
||||
|| !cc.streaming);
|
||||
|
||||
@@ -1067,7 +1070,7 @@ aligned_unique_ptr<NFA> goughCompile(raw_som_dfa &raw, u8 somPrecision,
|
||||
|
||||
map<dstate_id_t, gough_accel_state_info> accel_allowed;
|
||||
find_allowed_accel_states(*cfg, blocks, &accel_allowed);
|
||||
gough_build_strat gbs(raw, *cfg, accel_allowed);
|
||||
gough_build_strat gbs(raw, *cfg, rm, accel_allowed);
|
||||
aligned_unique_ptr<NFA> basic_dfa = mcclellanCompile_i(raw, gbs, cc);
|
||||
assert(basic_dfa);
|
||||
if (!basic_dfa) {
|
||||
@@ -1195,10 +1198,11 @@ namespace {
|
||||
struct raw_gough_report_list {
|
||||
set<som_report> reports;
|
||||
|
||||
explicit raw_gough_report_list(
|
||||
const vector<pair<ReportID, GoughSSAVar *>> &raw_reports) {
|
||||
raw_gough_report_list(
|
||||
const vector<pair<ReportID, GoughSSAVar *>> &raw_reports,
|
||||
const ReportManager &rm, bool do_remap) {
|
||||
for (const auto &m : raw_reports) {
|
||||
ReportID r = m.first;
|
||||
ReportID r = do_remap ? rm.getProgramOffset(m.first) : m.first;
|
||||
u32 impl_slot = INVALID_SLOT;
|
||||
if (m.second) {
|
||||
impl_slot = m.second->slot;
|
||||
@@ -1227,11 +1231,13 @@ unique_ptr<raw_report_info> gough_build_strat::gatherReports(
|
||||
vector<u32> &reports_eod,
|
||||
u8 *isSingleReport,
|
||||
ReportID *arbReport) const {
|
||||
unique_ptr<raw_gough_report_info_impl> ri =
|
||||
ue2::make_unique<raw_gough_report_info_impl>();
|
||||
map<raw_gough_report_list, u32> rev;
|
||||
DEBUG_PRINTF("gathering reports\n");
|
||||
|
||||
const bool remap_reports = has_managed_reports(rdfa.kind);
|
||||
|
||||
auto ri = ue2::make_unique<raw_gough_report_info_impl>();
|
||||
map<raw_gough_report_list, u32> rev;
|
||||
|
||||
assert(!rdfa.states.empty());
|
||||
|
||||
vector<GoughVertex> verts(rdfa.states.size());
|
||||
@@ -1250,7 +1256,7 @@ unique_ptr<raw_report_info> gough_build_strat::gatherReports(
|
||||
continue;
|
||||
}
|
||||
|
||||
raw_gough_report_list rrl(gg[v].reports);
|
||||
raw_gough_report_list rrl(gg[v].reports, rm, remap_reports);
|
||||
DEBUG_PRINTF("non empty r %zu\n", reports.size());
|
||||
if (rev.find(rrl) != rev.end()) {
|
||||
reports.push_back(rev[rrl]);
|
||||
@@ -1269,7 +1275,7 @@ unique_ptr<raw_report_info> gough_build_strat::gatherReports(
|
||||
}
|
||||
|
||||
DEBUG_PRINTF("non empty r eod\n");
|
||||
raw_gough_report_list rrl(gg[v].reports_eod);
|
||||
raw_gough_report_list rrl(gg[v].reports_eod, rm, remap_reports);
|
||||
if (rev.find(rrl) != rev.end()) {
|
||||
reports_eod.push_back(rev[rrl]);
|
||||
continue;
|
||||
|
@@ -89,7 +89,8 @@ struct raw_som_dfa : public raw_dfa {
|
||||
};
|
||||
|
||||
aligned_unique_ptr<NFA> goughCompile(raw_som_dfa &raw, u8 somPrecision,
|
||||
const CompileContext &cc);
|
||||
const CompileContext &cc,
|
||||
const ReportManager &rm);
|
||||
|
||||
} // namespace ue2
|
||||
|
||||
|
@@ -1,68 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Intel Corporation
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of Intel Corporation nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "goughcompile.h"
|
||||
#include "goughcompile_util.h"
|
||||
#include "mcclellancompile_util.h"
|
||||
#include "util/report_manager.h"
|
||||
|
||||
#include "ue2common.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace ue2;
|
||||
|
||||
namespace ue2 {
|
||||
|
||||
static
|
||||
void remapReportsToPrograms(set<som_report> &reports,
|
||||
const ReportManager &rm) {
|
||||
if (reports.empty()) {
|
||||
return;
|
||||
}
|
||||
auto old_reports = reports;
|
||||
reports.clear();
|
||||
for (const auto &r : old_reports) {
|
||||
u32 program = rm.getProgramOffset(r.report);
|
||||
reports.emplace(program, r.slot);
|
||||
}
|
||||
}
|
||||
|
||||
void remapReportsToPrograms(raw_som_dfa &haig, const ReportManager &rm) {
|
||||
DEBUG_PRINTF("remap haig reports\n");
|
||||
|
||||
for (auto &ds : haig.state_som) {
|
||||
remapReportsToPrograms(ds.reports, rm);
|
||||
remapReportsToPrograms(ds.reports_eod, rm);
|
||||
}
|
||||
|
||||
// McClellan-style reports too.
|
||||
raw_dfa &rdfa = haig;
|
||||
remapReportsToPrograms(rdfa, rm);
|
||||
}
|
||||
|
||||
} // namespace ue2
|
@@ -1,41 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Intel Corporation
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of Intel Corporation nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef GOUGHCOMPILE_UTIL_H
|
||||
#define GOUGHCOMPILE_UTIL_H
|
||||
|
||||
namespace ue2 {
|
||||
|
||||
struct raw_som_dfa;
|
||||
class ReportManager;
|
||||
|
||||
void remapReportsToPrograms(raw_som_dfa &haig, const ReportManager &rm);
|
||||
|
||||
} // namespace ue2
|
||||
|
||||
#endif // GOUGHCOMPILE_UTIL_H
|
@@ -46,6 +46,7 @@
|
||||
#include "util/container.h"
|
||||
#include "util/make_unique.h"
|
||||
#include "util/order_check.h"
|
||||
#include "util/report_manager.h"
|
||||
#include "util/ue2_containers.h"
|
||||
#include "util/unaligned.h"
|
||||
#include "util/verify_types.h"
|
||||
@@ -356,8 +357,16 @@ namespace {
|
||||
struct raw_report_list {
|
||||
flat_set<ReportID> reports;
|
||||
|
||||
explicit raw_report_list(const flat_set<ReportID> &reports_in)
|
||||
: reports(reports_in) {}
|
||||
raw_report_list(const flat_set<ReportID> &reports_in,
|
||||
const ReportManager &rm, bool do_remap) {
|
||||
if (do_remap) {
|
||||
for (auto &id : reports_in) {
|
||||
reports.insert(rm.getProgramOffset(id));
|
||||
}
|
||||
} else {
|
||||
reports = reports_in;
|
||||
}
|
||||
}
|
||||
|
||||
bool operator<(const raw_report_list &b) const {
|
||||
return reports < b.reports;
|
||||
@@ -380,6 +389,8 @@ unique_ptr<raw_report_info> mcclellan_build_strat::gatherReports(
|
||||
ReportID *arbReport) const {
|
||||
DEBUG_PRINTF("gathering reports\n");
|
||||
|
||||
const bool remap_reports = has_managed_reports(rdfa.kind);
|
||||
|
||||
auto ri = ue2::make_unique<raw_report_info_impl>();
|
||||
map<raw_report_list, u32> rev;
|
||||
|
||||
@@ -389,7 +400,7 @@ unique_ptr<raw_report_info> mcclellan_build_strat::gatherReports(
|
||||
continue;
|
||||
}
|
||||
|
||||
raw_report_list rrl(s.reports);
|
||||
raw_report_list rrl(s.reports, rm, remap_reports);
|
||||
DEBUG_PRINTF("non empty r\n");
|
||||
if (rev.find(rrl) != rev.end()) {
|
||||
reports.push_back(rev[rrl]);
|
||||
@@ -408,7 +419,7 @@ unique_ptr<raw_report_info> mcclellan_build_strat::gatherReports(
|
||||
}
|
||||
|
||||
DEBUG_PRINTF("non empty r eod\n");
|
||||
raw_report_list rrl(s.reports_eod);
|
||||
raw_report_list rrl(s.reports_eod, rm, remap_reports);
|
||||
if (rev.find(rrl) != rev.end()) {
|
||||
reports_eod.push_back(rev[rrl]);
|
||||
continue;
|
||||
@@ -579,8 +590,7 @@ aligned_unique_ptr<NFA> mcclellanCompile16(dfa_info &info,
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
unique_ptr<raw_report_info> ri
|
||||
= info.strat.gatherReports(reports, reports_eod, &single, &arb);
|
||||
auto ri = info.strat.gatherReports(reports, reports_eod, &single, &arb);
|
||||
map<dstate_id_t, AccelScheme> accel_escape_info
|
||||
= populateAccelerationInfo(info.raw, info.strat, cc.grey);
|
||||
|
||||
@@ -799,8 +809,7 @@ aligned_unique_ptr<NFA> mcclellanCompile8(dfa_info &info,
|
||||
ReportID arb;
|
||||
u8 single;
|
||||
|
||||
unique_ptr<raw_report_info> ri
|
||||
= info.strat.gatherReports(reports, reports_eod, &single, &arb);
|
||||
auto ri = info.strat.gatherReports(reports, reports_eod, &single, &arb);
|
||||
map<dstate_id_t, AccelScheme> accel_escape_info
|
||||
= populateAccelerationInfo(info.raw, info.strat, cc.grey);
|
||||
|
||||
@@ -1086,8 +1095,9 @@ aligned_unique_ptr<NFA> mcclellanCompile_i(raw_dfa &raw, dfa_build_strat &strat,
|
||||
}
|
||||
|
||||
aligned_unique_ptr<NFA> mcclellanCompile(raw_dfa &raw, const CompileContext &cc,
|
||||
const ReportManager &rm,
|
||||
set<dstate_id_t> *accel_states) {
|
||||
mcclellan_build_strat mbs(raw);
|
||||
mcclellan_build_strat mbs(raw, rm);
|
||||
return mcclellanCompile_i(raw, mbs, cc, accel_states);
|
||||
}
|
||||
|
||||
|
@@ -44,6 +44,7 @@ struct NFA;
|
||||
|
||||
namespace ue2 {
|
||||
|
||||
class ReportManager;
|
||||
struct CompileContext;
|
||||
|
||||
struct raw_report_info {
|
||||
@@ -57,6 +58,7 @@ struct raw_report_info {
|
||||
|
||||
class dfa_build_strat {
|
||||
public:
|
||||
explicit dfa_build_strat(const ReportManager &rm_in) : rm(rm_in) {}
|
||||
virtual ~dfa_build_strat();
|
||||
virtual raw_dfa &get_raw() const = 0;
|
||||
virtual std::unique_ptr<raw_report_info> gatherReports(
|
||||
@@ -68,11 +70,14 @@ public:
|
||||
virtual size_t accelSize(void) const = 0;
|
||||
virtual void buildAccel(dstate_id_t this_idx, const AccelScheme &info,
|
||||
void *accel_out) = 0;
|
||||
protected:
|
||||
const ReportManager &rm;
|
||||
};
|
||||
|
||||
class mcclellan_build_strat : public dfa_build_strat {
|
||||
public:
|
||||
explicit mcclellan_build_strat(raw_dfa &r) : rdfa(r) {}
|
||||
mcclellan_build_strat(raw_dfa &rdfa_in, const ReportManager &rm_in)
|
||||
: dfa_build_strat(rm_in), rdfa(rdfa_in) {}
|
||||
raw_dfa &get_raw() const override { return rdfa; }
|
||||
std::unique_ptr<raw_report_info> gatherReports(
|
||||
std::vector<u32> &reports /* out */,
|
||||
@@ -93,6 +98,7 @@ private:
|
||||
* states */
|
||||
ue2::aligned_unique_ptr<NFA>
|
||||
mcclellanCompile(raw_dfa &raw, const CompileContext &cc,
|
||||
const ReportManager &rm,
|
||||
std::set<dstate_id_t> *accel_states = nullptr);
|
||||
|
||||
/* used internally by mcclellan/haig/gough compile process */
|
||||
|
@@ -395,27 +395,4 @@ dstate_id_t get_sds_or_proxy(const raw_dfa &raw) {
|
||||
}
|
||||
}
|
||||
|
||||
static
|
||||
void remapReportsToPrograms(flat_set<ReportID> &reports,
|
||||
const ReportManager &rm) {
|
||||
if (reports.empty()) {
|
||||
return;
|
||||
}
|
||||
auto old_reports = reports;
|
||||
reports.clear();
|
||||
for (const ReportID &id : old_reports) {
|
||||
u32 program = rm.getProgramOffset(id);
|
||||
reports.insert(program);
|
||||
}
|
||||
}
|
||||
|
||||
void remapReportsToPrograms(raw_dfa &rdfa, const ReportManager &rm) {
|
||||
DEBUG_PRINTF("remap dfa reports\n");
|
||||
for (auto &ds : rdfa.states) {
|
||||
remapReportsToPrograms(ds.reports, rm);
|
||||
remapReportsToPrograms(ds.reports_eod, rm);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} // namespace ue2
|
||||
|
@@ -31,7 +31,6 @@
|
||||
|
||||
#include "rdfa.h"
|
||||
#include "ue2common.h"
|
||||
#include "util/report_manager.h"
|
||||
|
||||
#include <set>
|
||||
|
||||
@@ -58,8 +57,6 @@ size_t hash_dfa(const raw_dfa &rdfa);
|
||||
|
||||
dstate_id_t get_sds_or_proxy(const raw_dfa &raw);
|
||||
|
||||
void remapReportsToPrograms(raw_dfa &rdfa, const ReportManager &rm);
|
||||
|
||||
} // namespace ue2
|
||||
|
||||
#endif
|
||||
|
@@ -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:
|
||||
@@ -39,17 +39,44 @@ enum nfa_kind {
|
||||
NFA_INFIX, //!< rose infix
|
||||
NFA_SUFFIX, //!< rose suffix
|
||||
NFA_OUTFIX, //!< "outfix" nfa not triggered by external events
|
||||
NFA_OUTFIX_RAW, //!< "outfix", but with unmanaged reports
|
||||
NFA_REV_PREFIX, //! reverse running prefixes (for som)
|
||||
};
|
||||
|
||||
static UNUSED
|
||||
inline
|
||||
bool is_triggered(enum nfa_kind k) {
|
||||
return k == NFA_INFIX || k == NFA_SUFFIX || k == NFA_REV_PREFIX;
|
||||
switch (k) {
|
||||
case NFA_INFIX:
|
||||
case NFA_SUFFIX:
|
||||
case NFA_REV_PREFIX:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
static UNUSED
|
||||
inline
|
||||
bool generates_callbacks(enum nfa_kind k) {
|
||||
return k == NFA_SUFFIX || k == NFA_OUTFIX || k == NFA_REV_PREFIX;
|
||||
switch (k) {
|
||||
case NFA_SUFFIX:
|
||||
case NFA_OUTFIX:
|
||||
case NFA_OUTFIX_RAW:
|
||||
case NFA_REV_PREFIX:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
inline
|
||||
bool has_managed_reports(enum nfa_kind k) {
|
||||
switch (k) {
|
||||
case NFA_SUFFIX:
|
||||
case NFA_OUTFIX:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace ue2
|
||||
|
Reference in New Issue
Block a user