mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 06:38:20 +00:00
switch simple loops that don't need indices to being iterator-based
This commit is contained in:
parent
ffd1905f90
commit
d609a11312
8 changed files with 34 additions and 52 deletions
|
@ -145,9 +145,8 @@ void CPPCompile::ExpandListTypeVar(const TypePtr& t, string& tn)
|
||||||
const auto& tl = t->AsTypeList()->GetTypes();
|
const auto& tl = t->AsTypeList()->GetTypes();
|
||||||
auto t_name = tn + "->AsTypeList()";
|
auto t_name = tn + "->AsTypeList()";
|
||||||
|
|
||||||
for ( auto i = 0u; i < tl.size(); ++i )
|
for ( auto& tl_i : tl )
|
||||||
AddInit(t, t_name + "->Append(" +
|
AddInit(t, t_name + "->Append(" + GenTypeName(tl_i) + ");");
|
||||||
GenTypeName(tl[i]) + ");");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CPPCompile::ExpandRecordTypeVar(const TypePtr& t, string& tn)
|
void CPPCompile::ExpandRecordTypeVar(const TypePtr& t, string& tn)
|
||||||
|
@ -459,10 +458,10 @@ void CPPCompile::RegisterListType(const TypePtr& t)
|
||||||
{
|
{
|
||||||
const auto& tl = t->AsTypeList()->GetTypes();
|
const auto& tl = t->AsTypeList()->GetTypes();
|
||||||
|
|
||||||
for ( auto i = 0u; i < tl.size(); ++i )
|
for ( auto& tl_i : tl )
|
||||||
{
|
{
|
||||||
NoteNonRecordInitDependency(t, tl[i]);
|
NoteNonRecordInitDependency(t, tl_i);
|
||||||
RegisterType(tl[i]);
|
RegisterType(tl_i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -489,10 +488,8 @@ void CPPCompile::RegisterRecordType(const TypePtr& t)
|
||||||
if ( ! r )
|
if ( ! r )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for ( auto i = 0; i < r->length(); ++i )
|
for ( const auto& r_i : *r )
|
||||||
{
|
{
|
||||||
const auto& r_i = (*r)[i];
|
|
||||||
|
|
||||||
NoteNonRecordInitDependency(t, r_i->type);
|
NoteNonRecordInitDependency(t, r_i->type);
|
||||||
RegisterType(r_i->type);
|
RegisterType(r_i->type);
|
||||||
|
|
||||||
|
|
|
@ -1107,8 +1107,8 @@ static ExprPtr build_disjunction(std::vector<ConstExprPtr>& patterns)
|
||||||
|
|
||||||
ExprPtr e = patterns[0];
|
ExprPtr e = patterns[0];
|
||||||
|
|
||||||
for ( unsigned int i = 1; i < patterns.size(); ++i )
|
for ( auto& p : patterns )
|
||||||
e = make_intrusive<BitExpr>(EXPR_OR, e, patterns[i]);
|
e = make_intrusive<BitExpr>(EXPR_OR, e, p);
|
||||||
|
|
||||||
return e;
|
return e;
|
||||||
}
|
}
|
||||||
|
|
|
@ -514,8 +514,8 @@ int IDOptInfo::ActiveRegionIndex()
|
||||||
|
|
||||||
void IDOptInfo::DumpBlocks() const
|
void IDOptInfo::DumpBlocks() const
|
||||||
{
|
{
|
||||||
for ( auto i = 0; i < usage_regions.size(); ++i )
|
for ( auto& ur : usage_regions )
|
||||||
usage_regions[i].Dump();
|
ur.Dump();
|
||||||
|
|
||||||
printf("<end>\n");
|
printf("<end>\n");
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,10 +79,8 @@ bool UseDefs::RemoveUnused(int iter)
|
||||||
|
|
||||||
bool did_omission = false;
|
bool did_omission = false;
|
||||||
|
|
||||||
for ( unsigned int i = 0; i < stmts.size(); ++i )
|
for ( const auto& s : stmts )
|
||||||
{
|
{
|
||||||
const auto& s = stmts[i];
|
|
||||||
|
|
||||||
if ( s->Tag() == STMT_INIT )
|
if ( s->Tag() == STMT_INIT )
|
||||||
{
|
{
|
||||||
auto init = s->AsInitStmt();
|
auto init = s->AsInitStmt();
|
||||||
|
|
|
@ -155,9 +155,8 @@ bool ZAMCompiler::RemoveDeadCode()
|
||||||
|
|
||||||
bool did_removal = false;
|
bool did_removal = false;
|
||||||
|
|
||||||
for ( unsigned int i = 0; i < insts1.size() - 1; ++i )
|
for ( auto& i0 : insts1 )
|
||||||
{
|
{
|
||||||
auto i0 = insts1[i];
|
|
||||||
if ( ! i0->live )
|
if ( ! i0->live )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
@ -205,9 +204,8 @@ bool ZAMCompiler::CollapseGoTos()
|
||||||
{
|
{
|
||||||
bool did_change = false;
|
bool did_change = false;
|
||||||
|
|
||||||
for ( unsigned int i = 0; i < insts1.size(); ++i )
|
for ( auto& i0 : insts1 )
|
||||||
{
|
{
|
||||||
auto i0 = insts1[i];
|
|
||||||
auto orig_t = i0->target;
|
auto orig_t = i0->target;
|
||||||
|
|
||||||
if ( ! i0->live || ! orig_t || orig_t == pending_inst )
|
if ( ! i0->live || ! orig_t || orig_t == pending_inst )
|
||||||
|
@ -524,9 +522,8 @@ void ZAMCompiler::ReMapFrame()
|
||||||
std::vector<GlobalInfo> used_globals;
|
std::vector<GlobalInfo> used_globals;
|
||||||
std::vector<int> remapped_globals;
|
std::vector<int> remapped_globals;
|
||||||
|
|
||||||
for ( unsigned int i = 0; i < globalsI.size(); ++i )
|
for ( auto& g : globalsI )
|
||||||
{
|
{
|
||||||
auto& g = globalsI[i];
|
|
||||||
g.slot = frame1_to_frame2[g.slot];
|
g.slot = frame1_to_frame2[g.slot];
|
||||||
if ( g.slot >= 0 )
|
if ( g.slot >= 0 )
|
||||||
{
|
{
|
||||||
|
@ -890,12 +887,9 @@ const ZInstI* ZAMCompiler::EndOfLoop(const ZInstI* inst, int depth) const
|
||||||
|
|
||||||
bool ZAMCompiler::VarIsAssigned(int slot) const
|
bool ZAMCompiler::VarIsAssigned(int slot) const
|
||||||
{
|
{
|
||||||
for ( unsigned int i = 0; i < insts1.size(); ++i )
|
for ( auto& inst : insts1 )
|
||||||
{
|
|
||||||
auto& inst = insts1[i];
|
|
||||||
if ( inst->live && VarIsAssigned(slot, inst) )
|
if ( inst->live && VarIsAssigned(slot, inst) )
|
||||||
return true;
|
return true;
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -932,9 +926,8 @@ bool ZAMCompiler::VarIsAssigned(int slot, const ZInstI* i) const
|
||||||
|
|
||||||
bool ZAMCompiler::VarIsUsed(int slot) const
|
bool ZAMCompiler::VarIsUsed(int slot) const
|
||||||
{
|
{
|
||||||
for ( unsigned int i = 0; i < insts1.size(); ++i )
|
for ( auto& inst : insts1 )
|
||||||
{
|
{
|
||||||
auto& inst = insts1[i];
|
|
||||||
if ( inst->live && inst->UsesSlot(slot) )
|
if ( inst->live && inst->UsesSlot(slot) )
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
|
|
@ -17,10 +17,8 @@ void ZAMCompiler::PushGoTos(GoToSets& gotos)
|
||||||
|
|
||||||
void ZAMCompiler::ResolveGoTos(GoToSets& gotos, const InstLabel l)
|
void ZAMCompiler::ResolveGoTos(GoToSets& gotos, const InstLabel l)
|
||||||
{
|
{
|
||||||
auto& g = gotos.back();
|
for ( auto& gi : gotos.back() )
|
||||||
|
SetGoTo(gi, l);
|
||||||
for ( auto i = 0U; i < g.size(); ++i )
|
|
||||||
SetGoTo(g[i], l);
|
|
||||||
|
|
||||||
gotos.pop_back();
|
gotos.pop_back();
|
||||||
}
|
}
|
||||||
|
|
|
@ -173,12 +173,12 @@ StmtPtr ZAMCompiler::CompileBody()
|
||||||
// Dead instructions map to -1.
|
// Dead instructions map to -1.
|
||||||
std::vector<int> inst1_to_inst2;
|
std::vector<int> inst1_to_inst2;
|
||||||
|
|
||||||
for ( auto i = 0U; i < insts1.size(); ++i )
|
for ( auto& i1 : insts1 )
|
||||||
{
|
{
|
||||||
if ( insts1[i]->live )
|
if ( i1->live )
|
||||||
{
|
{
|
||||||
inst1_to_inst2.push_back(insts2.size());
|
inst1_to_inst2.push_back(insts2.size());
|
||||||
insts2.push_back(insts1[i]);
|
insts2.push_back(i1);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
inst1_to_inst2.push_back(-1);
|
inst1_to_inst2.push_back(-1);
|
||||||
|
@ -284,9 +284,8 @@ void ZAMCompiler::ComputeLoopLevels()
|
||||||
void ZAMCompiler::AdjustBranches()
|
void ZAMCompiler::AdjustBranches()
|
||||||
{
|
{
|
||||||
// Move branches to dead code forward to their successor live code.
|
// Move branches to dead code forward to their successor live code.
|
||||||
for ( auto i = 0U; i < insts1.size(); ++i )
|
for ( auto& inst : insts1 )
|
||||||
{
|
{
|
||||||
auto inst = insts1[i];
|
|
||||||
if ( ! inst->live )
|
if ( ! inst->live )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
@ -301,9 +300,8 @@ void ZAMCompiler::AdjustBranches()
|
||||||
|
|
||||||
void ZAMCompiler::RetargetBranches()
|
void ZAMCompiler::RetargetBranches()
|
||||||
{
|
{
|
||||||
for ( auto i = 0U; i < insts2.size(); ++i )
|
for ( auto& inst : insts2 )
|
||||||
{
|
{
|
||||||
auto inst = insts2[i];
|
|
||||||
if ( ! inst->target )
|
if ( ! inst->target )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
@ -313,10 +311,8 @@ void ZAMCompiler::RetargetBranches()
|
||||||
|
|
||||||
void ZAMCompiler::RemapFrameDenizens(const std::vector<int>& inst1_to_inst2)
|
void ZAMCompiler::RemapFrameDenizens(const std::vector<int>& inst1_to_inst2)
|
||||||
{
|
{
|
||||||
for ( auto i = 0U; i < shared_frame_denizens.size(); ++i )
|
for ( auto& info : shared_frame_denizens )
|
||||||
{
|
{
|
||||||
auto& info = shared_frame_denizens[i];
|
|
||||||
|
|
||||||
for ( auto& start : info.id_start )
|
for ( auto& start : info.id_start )
|
||||||
{
|
{
|
||||||
// It can happen that the identifier's
|
// It can happen that the identifier's
|
||||||
|
@ -339,10 +335,10 @@ void ZAMCompiler::RemapFrameDenizens(const std::vector<int>& inst1_to_inst2)
|
||||||
|
|
||||||
void ZAMCompiler::CreateSharedFrameDenizens()
|
void ZAMCompiler::CreateSharedFrameDenizens()
|
||||||
{
|
{
|
||||||
for ( auto i = 0U; i < frame_denizens.size(); ++i )
|
for ( auto& fd : frame_denizens )
|
||||||
{
|
{
|
||||||
FrameSharingInfo info;
|
FrameSharingInfo info;
|
||||||
info.ids.push_back(frame_denizens[i]);
|
info.ids.push_back(fd);
|
||||||
info.id_start.push_back(0);
|
info.id_start.push_back(0);
|
||||||
info.scope_end = insts2.size();
|
info.scope_end = insts2.size();
|
||||||
|
|
||||||
|
|
|
@ -132,8 +132,8 @@ ZBody::ZBody(const char* _func_name, const ZAMCompiler* zc)
|
||||||
|
|
||||||
// Concretize the names of the frame denizens.
|
// Concretize the names of the frame denizens.
|
||||||
for ( auto& f : frame_denizens )
|
for ( auto& f : frame_denizens )
|
||||||
for ( auto i = 0U; i < f.ids.size(); ++i )
|
for ( auto& id : f.ids )
|
||||||
f.names.push_back(f.ids[i]->Name());
|
f.names.push_back(id->Name());
|
||||||
|
|
||||||
managed_slots = zc->ManagedSlots();
|
managed_slots = zc->ManagedSlots();
|
||||||
|
|
||||||
|
@ -149,8 +149,8 @@ ZBody::ZBody(const char* _func_name, const ZAMCompiler* zc)
|
||||||
{
|
{
|
||||||
fixed_frame = new ZVal[frame_size];
|
fixed_frame = new ZVal[frame_size];
|
||||||
|
|
||||||
for ( auto i = 0U; i < managed_slots.size(); ++i )
|
for ( auto& ms : managed_slots )
|
||||||
fixed_frame[managed_slots[i]].ClearManagedVal();
|
fixed_frame[ms].ClearManagedVal();
|
||||||
}
|
}
|
||||||
|
|
||||||
table_iters = zc->GetTableIters();
|
table_iters = zc->GetTableIters();
|
||||||
|
@ -334,9 +334,9 @@ ValPtr ZBody::DoExec(Frame* f, int start_pc, StmtFlowType& flow)
|
||||||
|
|
||||||
// Free slots for which we do explicit memory management,
|
// Free slots for which we do explicit memory management,
|
||||||
// preparing them for reuse.
|
// preparing them for reuse.
|
||||||
for ( auto i = 0U; i < managed_slots.size(); ++i )
|
for ( auto& ms : managed_slots )
|
||||||
{
|
{
|
||||||
auto& v = frame[managed_slots[i]];
|
auto& v = frame[ms];
|
||||||
ZVal::DeleteManagedType(v);
|
ZVal::DeleteManagedType(v);
|
||||||
v.ClearManagedVal();
|
v.ClearManagedVal();
|
||||||
}
|
}
|
||||||
|
@ -346,9 +346,9 @@ ValPtr ZBody::DoExec(Frame* f, int start_pc, StmtFlowType& flow)
|
||||||
// Free those slots for which we do explicit memory management.
|
// Free those slots for which we do explicit memory management.
|
||||||
// No need to then clear them, as we're about to throw away
|
// No need to then clear them, as we're about to throw away
|
||||||
// the entire frame.
|
// the entire frame.
|
||||||
for ( auto i = 0U; i < managed_slots.size(); ++i )
|
for ( auto& ms : managed_slots )
|
||||||
{
|
{
|
||||||
auto& v = frame[managed_slots[i]];
|
auto& v = frame[ms];
|
||||||
ZVal::DeleteManagedType(v);
|
ZVal::DeleteManagedType(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue