mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00
checking CFT info when doing optimization pruning
This commit is contained in:
parent
9b32d3f494
commit
6ad14dec3e
6 changed files with 66 additions and 23 deletions
|
@ -190,8 +190,7 @@ event krb_as_response(c: connection, msg: KDC_Response) &priority=-5
|
||||||
|
|
||||||
event krb_ap_request(c: connection, ticket: KRB::Ticket, opts: KRB::AP_Options) &priority=5
|
event krb_ap_request(c: connection, ticket: KRB::Ticket, opts: KRB::AP_Options) &priority=5
|
||||||
{
|
{
|
||||||
if ( set_session(c) )
|
set_session(c);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
event krb_tgs_request(c: connection, msg: KDC_Request) &priority=5
|
event krb_tgs_request(c: connection, msg: KDC_Request) &priority=5
|
||||||
|
|
|
@ -941,16 +941,54 @@ void ZAMCompiler::KillInst(zeek_uint_t i) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( num_labels == 0 )
|
ZInstI* succ = nullptr;
|
||||||
// No labels to propagate.
|
|
||||||
return;
|
|
||||||
|
|
||||||
for ( auto j = i + 1; j < insts1.size(); ++j ) {
|
if ( num_labels > 0 ) {
|
||||||
auto succ = insts1[j];
|
for ( auto j = i + 1; j < insts1.size(); ++j ) {
|
||||||
if ( succ->live ) {
|
if ( insts1[j]->live ) {
|
||||||
succ->num_labels += num_labels;
|
succ = insts1[j];
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
if ( succ )
|
||||||
|
succ->num_labels += num_labels;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Look into propagating control flow info.
|
||||||
|
if ( inst->aux && ! inst->aux->cft.empty() ) {
|
||||||
|
auto& cft = inst->aux->cft;
|
||||||
|
|
||||||
|
if ( cft.count(CFT_BLOCK_END) > 0 ) {
|
||||||
|
// Propagate block-ends backwards.
|
||||||
|
int j = i;
|
||||||
|
while ( --j >= 0 )
|
||||||
|
if ( insts1[j]->live )
|
||||||
|
break;
|
||||||
|
|
||||||
|
ASSERT(j >= 0);
|
||||||
|
|
||||||
|
// Make sure the CFT entry is created.
|
||||||
|
AddCFT(insts1[j], CFT_BLOCK_END);
|
||||||
|
|
||||||
|
auto be_cnt = cft[CFT_BLOCK_END];
|
||||||
|
--be_cnt; // we already did one above
|
||||||
|
insts1[j]->aux->cft[CFT_BLOCK_END] += be_cnt;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( cft.count(CFT_ELSE) > 0 ) {
|
||||||
|
// Push forward unless this was the end of the block.
|
||||||
|
if ( cft.count(CFT_BLOCK_END) == 0 ) {
|
||||||
|
ASSERT(succ);
|
||||||
|
AddCFT(succ, CFT_ELSE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If's can be killed because their bodies become empty,
|
||||||
|
// and break's because they just lead to their following instruction.
|
||||||
|
// However, loop's and next's should not be killed.
|
||||||
|
ASSERT(cft.count(CFT_LOOP) == 0);
|
||||||
|
ASSERT(cft.count(CFT_LOOP_COND) == 0);
|
||||||
|
ASSERT(cft.count(CFT_NEXT) == 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,9 +10,12 @@ namespace zeek::detail {
|
||||||
|
|
||||||
void ZAMCompiler::PushGoTos(GoToSets& gotos) { gotos.emplace_back(); }
|
void ZAMCompiler::PushGoTos(GoToSets& gotos) { gotos.emplace_back(); }
|
||||||
|
|
||||||
void ZAMCompiler::ResolveGoTos(GoToSets& gotos, const InstLabel l) {
|
void ZAMCompiler::ResolveGoTos(GoToSets& gotos, const InstLabel l, ControlFlowType cft) {
|
||||||
for ( auto& gi : gotos.back() )
|
for ( auto& gi : gotos.back() ) {
|
||||||
SetGoTo(gi, l);
|
SetGoTo(gi, l);
|
||||||
|
if ( cft != CFT_NONE )
|
||||||
|
AddCFT(insts1[gi.stmt_num], cft);
|
||||||
|
}
|
||||||
|
|
||||||
gotos.pop_back();
|
gotos.pop_back();
|
||||||
}
|
}
|
||||||
|
|
|
@ -167,14 +167,8 @@ private:
|
||||||
void PushFallThroughs() { PushGoTos(fallthroughs); }
|
void PushFallThroughs() { PushGoTos(fallthroughs); }
|
||||||
void PushCatchReturns() { PushGoTos(catches); }
|
void PushCatchReturns() { PushGoTos(catches); }
|
||||||
|
|
||||||
void ResolveNexts(const InstLabel l) {
|
void ResolveNexts(const InstLabel l) { ResolveGoTos(nexts, l, CFT_NEXT); }
|
||||||
ResolveGoTos(nexts, l);
|
void ResolveBreaks(const InstLabel l) { ResolveGoTos(breaks, l, CFT_BREAK); }
|
||||||
AddCFT(l, CFT_NEXT);
|
|
||||||
}
|
|
||||||
void ResolveBreaks(const InstLabel l) {
|
|
||||||
ResolveGoTos(breaks, l);
|
|
||||||
AddCFT(l, CFT_BREAK);
|
|
||||||
}
|
|
||||||
void ResolveFallThroughs(const InstLabel l) { ResolveGoTos(fallthroughs, l); }
|
void ResolveFallThroughs(const InstLabel l) { ResolveGoTos(fallthroughs, l); }
|
||||||
void ResolveCatchReturns(const InstLabel l) { ResolveGoTos(catches, l); }
|
void ResolveCatchReturns(const InstLabel l) { ResolveGoTos(catches, l); }
|
||||||
|
|
||||||
|
@ -280,7 +274,7 @@ private:
|
||||||
using GoToSets = std::vector<GoToSet>;
|
using GoToSets = std::vector<GoToSet>;
|
||||||
|
|
||||||
void PushGoTos(GoToSets& gotos);
|
void PushGoTos(GoToSets& gotos);
|
||||||
void ResolveGoTos(GoToSets& gotos, const InstLabel l);
|
void ResolveGoTos(GoToSets& gotos, const InstLabel l, ControlFlowType cft = CFT_NONE);
|
||||||
|
|
||||||
ZAMStmt GenGoTo(GoToSet& v);
|
ZAMStmt GenGoTo(GoToSet& v);
|
||||||
ZAMStmt GoToStub();
|
ZAMStmt GoToStub();
|
||||||
|
|
|
@ -27,7 +27,14 @@ const ZAMStmt ZAMCompiler::LastInst() { return ZAMStmt(insts1.size() - 1); }
|
||||||
void ZAMCompiler::AddCFT(ZInstI* inst, ControlFlowType cft) {
|
void ZAMCompiler::AddCFT(ZInstI* inst, ControlFlowType cft) {
|
||||||
if ( ! inst->aux )
|
if ( ! inst->aux )
|
||||||
inst->aux = new ZInstAux(0);
|
inst->aux = new ZInstAux(0);
|
||||||
inst->aux->cft.insert(cft);
|
|
||||||
|
auto cft_entry = inst->aux->cft.find(cft);
|
||||||
|
if ( cft_entry == inst->aux->cft.end() )
|
||||||
|
inst->aux->cft[cft] = 1;
|
||||||
|
else {
|
||||||
|
ASSERT(cft == CFT_BLOCK_END);
|
||||||
|
++cft_entry->second;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
OpaqueVals* ZAMCompiler::BuildVals(const ListExprPtr& l) { return new OpaqueVals(InternalBuildVals(l.get())); }
|
OpaqueVals* ZAMCompiler::BuildVals(const ListExprPtr& l) { return new OpaqueVals(InternalBuildVals(l.get())); }
|
||||||
|
|
|
@ -385,6 +385,8 @@ enum ControlFlowType {
|
||||||
CFT_LOOP_COND,
|
CFT_LOOP_COND,
|
||||||
CFT_NEXT,
|
CFT_NEXT,
|
||||||
CFT_BREAK,
|
CFT_BREAK,
|
||||||
|
|
||||||
|
CFT_NONE,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Auxiliary information, used when the fixed ZInst layout lacks
|
// Auxiliary information, used when the fixed ZInst layout lacks
|
||||||
|
@ -506,7 +508,7 @@ public:
|
||||||
bool is_BiF_call = false;
|
bool is_BiF_call = false;
|
||||||
|
|
||||||
// Associated control flow information.
|
// Associated control flow information.
|
||||||
std::set<ControlFlowType> cft;
|
std::map<ControlFlowType, int> cft;
|
||||||
|
|
||||||
// Used for referring to events.
|
// Used for referring to events.
|
||||||
EventHandler* event_handler = nullptr;
|
EventHandler* event_handler = nullptr;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue