mirror of
https://github.com/VectorCamp/vectorscan.git
synced 2025-11-17 17:55:28 +03:00
rose: minor improvements to avoid unneeded program instructions
- strip out lonely check handled instructions - avoid producing programs for empty ghost roles
This commit is contained in:
@@ -639,6 +639,11 @@ OffsetMap makeOffsetMap(const RoseProgram &program, u32 *total_len) {
|
||||
return offset_map;
|
||||
}
|
||||
|
||||
RoseProgram::iterator RoseProgram::erase(RoseProgram::iterator first,
|
||||
RoseProgram::iterator last) {
|
||||
return prog.erase(first, last);
|
||||
}
|
||||
|
||||
bytecode_ptr<char> writeProgram(RoseEngineBlob &blob,
|
||||
const RoseProgram &program) {
|
||||
u32 total_len = 0;
|
||||
@@ -681,6 +686,28 @@ bool RoseProgramEquivalence::operator()(const RoseProgram &prog1,
|
||||
return std::equal(prog1.begin(), prog1.end(), prog2.begin(), is_equiv);
|
||||
}
|
||||
|
||||
void stripCheckHandledInstruction(RoseProgram &prog) {
|
||||
for (auto it = prog.begin(); it != prog.end();) {
|
||||
auto ins = dynamic_cast<const RoseInstrCheckNotHandled *>(it->get());
|
||||
if (!ins) {
|
||||
++it;
|
||||
continue;
|
||||
}
|
||||
|
||||
auto next_it = next(it);
|
||||
assert(next_it != prog.end()); /* there should always be an end ins */
|
||||
auto next_ins = next_it->get();
|
||||
|
||||
/* update all earlier instructions which point to ins to instead point
|
||||
* to the next instruction. Only need to look at earlier as we only ever
|
||||
* jump forward. */
|
||||
RoseProgram::update_targets(prog.begin(), it, ins, next_ins);
|
||||
|
||||
/* remove check handled instruction */
|
||||
it = prog.erase(it, next_it);
|
||||
}
|
||||
}
|
||||
|
||||
bool reads_work_done_flag(const RoseProgram &prog) {
|
||||
for (const auto &ri : prog) {
|
||||
if (dynamic_cast<const RoseInstrSquashGroups *>(ri.get())) {
|
||||
|
||||
Reference in New Issue
Block a user