mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 22:58:20 +00:00
inlining of Zeek script functions
This commit is contained in:
parent
3c39f11726
commit
c42586af2c
63 changed files with 21807 additions and 171 deletions
79
src/script_opt/ScriptOpt.h
Normal file
79
src/script_opt/ScriptOpt.h
Normal file
|
@ -0,0 +1,79 @@
|
|||
// See the file "COPYING" in the main distribution directory for copyright.
|
||||
|
||||
// Classes for controlling/orchestrating script optimization & compilation.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "zeek/Func.h"
|
||||
#include "zeek/Expr.h"
|
||||
#include "zeek/Scope.h"
|
||||
|
||||
namespace zeek { struct Options; }
|
||||
|
||||
namespace zeek::detail {
|
||||
|
||||
|
||||
// Flags controlling what sorts of analysis to do.
|
||||
|
||||
struct AnalyOpt {
|
||||
// If true, do global inlining.
|
||||
bool inliner = false;
|
||||
|
||||
// If true, report which functions are directly and indirectly
|
||||
// recursive, and exit. Only germane if running the inliner.
|
||||
bool report_recursive = false;
|
||||
};
|
||||
|
||||
|
||||
class ProfileFunc;
|
||||
|
||||
using ScriptFuncPtr = IntrusivePtr<ScriptFunc>;
|
||||
|
||||
// Info we need for tracking an instance of a function.
|
||||
class FuncInfo {
|
||||
public:
|
||||
FuncInfo(ScriptFuncPtr _func, ScopePtr _scope, StmtPtr _body)
|
||||
{
|
||||
func = _func;
|
||||
scope = _scope;
|
||||
body = _body;
|
||||
}
|
||||
|
||||
~FuncInfo();
|
||||
|
||||
ScriptFunc* Func() { return func.get(); }
|
||||
ScriptFuncPtr FuncPtr() { return func; }
|
||||
ScopePtr Scope() { return scope; }
|
||||
StmtPtr Body() { return body; }
|
||||
ProfileFunc* Profile() { return pf; }
|
||||
const char* SaveFile() { return save_file; }
|
||||
|
||||
void SetProfile(ProfileFunc* _pf) { pf = _pf; }
|
||||
void SetSaveFile(const char* _sf);
|
||||
|
||||
protected:
|
||||
ScriptFuncPtr func;
|
||||
ScopePtr scope;
|
||||
StmtPtr body;
|
||||
ProfileFunc* pf = nullptr;
|
||||
|
||||
// If we're saving this function in a file, this is the name
|
||||
// of the file to use.
|
||||
char* save_file = nullptr;
|
||||
};
|
||||
|
||||
|
||||
// We track which functions are definitely not recursive. We do this
|
||||
// as the negative, rather than tracking functions known to be recursive,
|
||||
// so that if we don't do the analysis at all (it's driven by inlining),
|
||||
// we err on the conservative side and assume every function is recursive.
|
||||
extern std::unordered_set<const Func*> non_recursive_funcs;
|
||||
|
||||
// Analyze a given function for optimization.
|
||||
extern void analyze_func(ScriptFuncPtr f);
|
||||
|
||||
// Analyze all of the parsed scripts collectively for optimization.
|
||||
extern void analyze_scripts(Options& opts);
|
||||
|
||||
|
||||
} // namespace zeek::detail
|
Loading…
Add table
Add a link
Reference in a new issue