a number of low-level tweaks from code review

This commit is contained in:
Vern Paxson 2021-08-19 10:15:44 -07:00
parent c10737d168
commit b6daf14868
12 changed files with 79 additions and 80 deletions

View file

@ -15,7 +15,7 @@ using namespace std;
CPPCompile::CPPCompile(vector<FuncInfo>& _funcs, ProfileFuncs& _pfs,
const string& gen_name, const string& _addl_name,
CPPHashManager& _hm, bool _update, bool _standalone,
bool report_uncompilable)
bool report_uncompilable)
: funcs(_funcs), pfs(_pfs), hm(_hm),
update(_update), standalone(_standalone)
{

View file

@ -280,10 +280,7 @@ void CPPCompile::AddInit(const Obj* o, const string& init)
void CPPCompile::AddInit(const Obj* o)
{
if ( obj_inits.count(o) == 0 )
{
vector<string> empty;
obj_inits[o] = empty;
}
obj_inits[o] = {};
}
void CPPCompile::NoteInitDependency(const Obj* o1, const Obj* o2)

View file

@ -27,9 +27,7 @@ void GenIDDefs::TraverseFunction(const Func* f, ScopePtr scope, StmtPtr body)
// Establish the outermost barrior and associated set of
// identifiers.
barrier_blocks.push_back(0);
std::unordered_set<const ID*> empty_IDs;
modified_IDs.push_back(empty_IDs);
modified_IDs.push_back({});
for ( const auto& g : pf->Globals() )
{
@ -442,9 +440,7 @@ void GenIDDefs::StartConfluenceBlock(const Stmt* s)
barrier_blocks.push_back(confluence_blocks.size());
confluence_blocks.push_back(s);
std::unordered_set<const ID*> empty_IDs;
modified_IDs.push_back(empty_IDs);
modified_IDs.push_back({});
}
void GenIDDefs::EndConfluenceBlock(bool no_orig)

View file

@ -11,7 +11,7 @@ namespace zeek::detail {
RD_Decorate::RD_Decorate(std::shared_ptr<ProfileFunc> _pf, const Func* f,
ScopePtr scope, StmtPtr body)
ScopePtr scope, StmtPtr body)
: pf(std::move(_pf))
{
TraverseFunction(f, scope, body);

View file

@ -257,8 +257,7 @@ void IDOptInfo::StartConfluenceBlock(const Stmt* s)
}
}
ConfluenceSet empty_set;
pending_confluences[s] = empty_set;
pending_confluences[s] = {};
confluence_stmts.push_back(s);
block_has_orig_flow.push_back(s_oi->contains_branch_beyond);

View file

@ -281,7 +281,7 @@ protected:
// profile is compilable. Alternatively we could derive subclasses
// from ProfileFuncs and use a virtual method for this, but that seems
// heavier-weight for what's really a simple notion.
typedef bool (*is_compilable_pred)(const ProfileFunc*, const char** reason);
using is_compilable_pred = bool (*)(const ProfileFunc*, const char** reason);
// Collectively profile an entire collection of functions.
class ProfileFuncs {

View file

@ -11,8 +11,7 @@ namespace zeek::detail {
void ZAMCompiler::PushGoTos(GoToSets& gotos)
{
std::vector<ZAMStmt> vi;
gotos.push_back(vi);
gotos.push_back({});
}
void ZAMCompiler::ResolveGoTos(GoToSets& gotos, const InstLabel l)

View file

@ -79,7 +79,7 @@ void ZAMCompiler::InitArgs()
push_existing_scope(scope);
for ( auto a : args )
for ( auto& a : args )
{
if ( --nparam < 0 )
break;
@ -369,7 +369,7 @@ void ZAMCompiler::ConcretizeSwitchTables(const CaseMapsI<T>& abstract_cases,
CaseMap<T> cm;
for ( auto& targ : targs )
cm[targ.first] = targ.second->inst_num;
concrete_cases.push_back(cm);
concrete_cases.emplace_back(cm);
}
}

View file

@ -109,7 +109,7 @@ ArgsManager::ArgsManager(const vector<ZAM_OperandType>& ot, ZAM_InstClass zc)
int n = 0;
bool add_field = false;
for ( auto ot_i : ot )
for ( const auto& ot_i : ot )
{
if ( ot_i == ZAM_OT_NONE )
{ // it had better be the only operand type
@ -421,11 +421,10 @@ int ZAM_OpTemplate::ExtractTypeParam(const string& arg)
if ( arg == "$$" )
return 1;
auto param_str = arg.c_str();
if ( *param_str != '$' )
if ( arg[0] != '$' )
g->Gripe("bad set-type parameter, should be $n", arg);
int param = atoi(&param_str[1]);
int param = atoi(&arg[1]);
if ( param <= 0 || param > 2 )
g->Gripe("bad set-type parameter, should be $1 or $2", arg);
@ -571,10 +570,7 @@ void ZAM_OpTemplate::InstantiateMethodCore(const vector<ZAM_OperandType>& ot,
}
ArgsManager args(ot, zc);
auto params = args.Params();
BuildInstruction(ot, params, full_suffix, zc);
BuildInstruction(ot, args.Params(), full_suffix, zc);
auto tp = GetTypeParam();
if ( tp > 0 )

View file

@ -316,7 +316,7 @@ ValPtr ZBody::DoExec(Frame* f, int start_pc, StmtFlowType& flow)
if ( do_profile )
{
double dt = curr_CPU_time() - profile_CPU;
(*inst_CPU)[profile_pc] += dt;
inst_CPU->at(profile_pc) += dt;
ZOP_CPU[z.op] += dt;
}
#endif

View file

@ -137,64 +137,76 @@ void ZInst::Dump(const string& id1, const string& id2, const string& id3,
int ZInst::NumFrameSlots() const
{
switch ( op_type ) {
case OP_X: return 0;
case OP_V: return 1;
case OP_VV: return 2;
case OP_VVV: return 3;
case OP_VVVV: return 4;
case OP_VVVC: return 3;
case OP_C: return 0;
case OP_VC: return 1;
case OP_VVC: return 2;
case OP_X:
case OP_C:
case OP_V_I1:
case OP_VC_I1:
case OP_VV_I1_I2:
case OP_VVVC_I1_I2_I3:
return 0;
case OP_V_I1: return 0;
case OP_VC_I1: return 0;
case OP_VV_I1_I2: return 0;
case OP_VV_FRAME: return 1;
case OP_VV_I2: return 1;
case OP_VVC_I2: return 1;
case OP_VVV_I3: return 2;
case OP_VVV_I2_I3: return 1;
case OP_V:
case OP_VC:
case OP_VV_FRAME:
case OP_VV_I2:
case OP_VVC_I2:
case OP_VVV_I2_I3:
case OP_VVVC_I2_I3:
case OP_VVVV_I2_I3_I4:
return 1;
case OP_VVVV_I4: return 3;
case OP_VVVV_I3_I4: return 2;
case OP_VVVV_I2_I3_I4: return 1;
case OP_VVVC_I3: return 2;
case OP_VVVC_I2_I3: return 1;
case OP_VVVC_I1_I2_I3: return 0;
case OP_VV:
case OP_VVC:
case OP_VVV_I3:
case OP_VVVC_I3:
case OP_VVVV_I3_I4:
return 2;
case OP_VVV:
case OP_VVVC:
case OP_VVVV_I4:
return 3;
case OP_VVVV:
return 4;
}
}
int ZInst::NumSlots() const
{
switch ( op_type ) {
case OP_X: return 0;
case OP_C: return 0;
case OP_V: return 1;
case OP_VC: return 1;
case OP_VV: return 2;
case OP_VVC: return 2;
case OP_VVV: return 3;
case OP_VVVC: return 3;
case OP_VVVV: return 4;
case OP_C:
case OP_X:
return 0;
case OP_V_I1: return 1;
case OP_VC_I1: return 1;
case OP_V:
case OP_V_I1:
case OP_VC:
case OP_VC_I1:
return 1;
case OP_VV_I1_I2: return 2;
case OP_VV_FRAME: return 2;
case OP_VV_I2: return 2;
case OP_VVC_I2: return 2;
case OP_VV:
case OP_VVC:
case OP_VV_FRAME:
case OP_VV_I2:
case OP_VVC_I2:
case OP_VV_I1_I2:
return 2;
case OP_VVV_I3: return 3;
case OP_VVV_I2_I3: return 3;
case OP_VVVC_I3: return 3;
case OP_VVVC_I2_I3: return 3;
case OP_VVVC_I1_I2_I3: return 3;
case OP_VVV:
case OP_VVV_I3:
case OP_VVV_I2_I3:
case OP_VVVC:
case OP_VVVC_I3:
case OP_VVVC_I2_I3:
case OP_VVVC_I1_I2_I3:
return 3;
case OP_VVVV_I4: return 4;
case OP_VVVV_I3_I4: return 4;
case OP_VVVV_I2_I3_I4: return 4;
case OP_VVVV:
case OP_VVVV_I4:
case OP_VVVV_I3_I4:
case OP_VVVV_I2_I3_I4:
return 4;
}
}

View file

@ -7,10 +7,10 @@
namespace zeek::detail {
// Opcodes associated with ZAM instructions.
typedef enum {
enum ZOp {
#include "zeek/ZAM-OpsDefs.h"
OP_NOP,
} ZOp;
};
// Possible types of instruction operands in terms of which fields they use.
@ -22,7 +22,7 @@ typedef enum {
// I1/I2/I3/I4: the instruction's integer value, used directly (not as a slot)
// FRAME: a slot in the (intrepreter) Frame object
// X: no operands
typedef enum {
enum ZAMOpType {
OP_X, OP_C, OP_V, OP_V_I1, OP_VC_I1,
OP_VC,
@ -46,15 +46,15 @@ typedef enum {
OP_VVVV_I3_I4,
OP_VVVV_I2_I3_I4,
} ZAMOpType;
};
// Possible "flavors" for an operator's first slot.
typedef enum {
enum ZAMOp1Flavor {
OP1_READ, // the slot is read, not modified
OP1_WRITE, // the slot is modified, not read - the most common
OP1_READ_WRITE, // the slot is both read and then modified, e.g. "++"
OP1_INTERNAL, // we're doing some internal manipulation of the slot
} ZAMOp1Flavor;
};
// Maps an operand to its flavor.
extern ZAMOp1Flavor op1_flavor[];