ZAM internals have a notion of "captures" as global-like variables

This commit is contained in:
Vern Paxson 2023-06-16 16:02:10 -07:00 committed by Arne Welzel
parent 110ba7a0a1
commit 0a40aec4a6
3 changed files with 101 additions and 10 deletions

View file

@ -5,6 +5,7 @@
#pragma once
#include "zeek/Desc.h"
#include "zeek/Func.h"
#include "zeek/script_opt/ZAM/BuiltInSupport.h"
#include "zeek/script_opt/ZAM/Support.h"
#include "zeek/script_opt/ZAM/ZOp.h"
@ -220,6 +221,9 @@ public:
// True if this instruction is of the form "v1 = v2".
bool IsDirectAssignment() const;
// True if this instruction includes captures in its aux slots.
bool HasCaptures() const;
// True if this instruction has side effects when executed, so
// should not be pruned even if it has a dead assignment.
bool HasSideEffects() const;
@ -247,9 +251,17 @@ public:
// the ZAM frame.
bool IsGlobalLoad() const;
// True if the instruction corresponds to loading a capture into
// the ZAM frame.
bool IsCaptureLoad() const;
// True if the instruction does not correspond to a load from the
// ZAM frame.
bool IsNonLocalLoad() const { return IsGlobalLoad() || IsCaptureLoad(); }
// True if the instruction corresponds to some sort of load,
// either from the interpreter frame or of a global.
bool IsLoad() const { return op_type == OP_VV_FRAME || IsGlobalLoad(); }
// either from the interpreter frame or of a global/capture.
bool IsLoad() const { return op_type == OP_VV_FRAME || IsNonLocalLoad(); }
// True if the instruction corresponds to storing a global.
bool IsGlobalStore() const { return op == OP_STORE_GLOBAL_V; }
@ -317,6 +329,7 @@ public:
slots = ints = new int[n];
constants = new ValPtr[n];
types = new TypePtr[n];
is_managed = new bool[n];
}
}
@ -325,6 +338,7 @@ public:
delete[] ints;
delete[] constants;
delete[] types;
delete[] is_managed;
delete[] cat_args;
}
@ -384,6 +398,7 @@ public:
ints[i] = slot;
constants[i] = nullptr;
types[i] = t;
is_managed[i] = t ? ZVal::IsManagedType(t) : false;
}
// Same but for constants.
@ -392,6 +407,7 @@ public:
ints[i] = -1;
constants[i] = c;
types[i] = nullptr;
is_managed[i] = false;
}
// Member variables. We could add accessors for manipulating
@ -404,13 +420,26 @@ public:
// if not, it's nil).
//
// We track associated types, too, enabling us to use
// ZVal::ToVal to convert frame slots or constants to ValPtr's.
// ZVal::ToVal to convert frame slots or constants to ValPtr's;
// and, as a performance optimization, whether those types
// indicate the slot needs to be managed.
int n; // size of arrays
int* slots = nullptr; // either nil or points to ints
int* ints = nullptr;
ValPtr* constants = nullptr;
TypePtr* types = nullptr;
bool* is_managed = nullptr;
// Ingredients associated with lambdas ...
ScriptFuncPtr master_func;
// ... and its name.
std::string lambda_name;
// For "when" statements. Needs to be non-const so we can
// Instantiate() it as needed.
WhenInfo* wi;
// A parallel array for the cat() built-in replacement.
std::unique_ptr<CatArg>* cat_args = nullptr;
@ -418,10 +447,10 @@ public:
// Used for accessing function names.
const ID* id_val = nullptr;
// Whether the instruction can lead to globals changing.
// Currently only needed by the optimizer, but convenient
// to store here.
bool can_change_globals = false;
// Whether the instruction can lead to globals/captures changing.
// Currently only needed by the optimizer, but convenient to
// store here.
bool can_change_non_locals = false;
// The following is only used for OP_CONSTRUCT_KNOWN_RECORD_V,
// to map elements in slots/constants/types to record field offsets.