mirror of
https://github.com/zeek/zeek.git
synced 2025-10-06 08:38: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
62
src/script_opt/Inline.h
Normal file
62
src/script_opt/Inline.h
Normal file
|
@ -0,0 +1,62 @@
|
|||
// See the file "COPYING" in the main distribution directory for copyright.
|
||||
|
||||
// Class that manages the process of (recursively) inlining function bodies.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "zeek/Func.h"
|
||||
#include "zeek/Scope.h"
|
||||
|
||||
#include <unordered_set>
|
||||
|
||||
|
||||
namespace zeek::detail {
|
||||
|
||||
class FuncInfo;
|
||||
|
||||
class Inliner {
|
||||
public:
|
||||
// First argument is a collection of information about *all* of
|
||||
// the script functions. Second argument states whether to report
|
||||
// recursive functions (of interest as they're not in-lineable).
|
||||
Inliner(std::vector<FuncInfo*>& _funcs, bool _report_recursive)
|
||||
: funcs(_funcs), report_recursive(_report_recursive)
|
||||
{ Analyze(); }
|
||||
|
||||
// Either returns the original CallExpr if it's not inline-able,
|
||||
// or an InlineExpr if it is.
|
||||
ExprPtr CheckForInlining(IntrusivePtr<CallExpr> c);
|
||||
|
||||
// True if the given function has been inlined.
|
||||
bool WasInlined(Func* f) { return inline_ables.count(f) > 0; }
|
||||
|
||||
protected:
|
||||
// Driver routine that analyzes all of the script functions and
|
||||
// recursively inlines eligible ones.
|
||||
void Analyze();
|
||||
|
||||
// Recursively inlines any calls associated with the given function.
|
||||
void InlineFunction(FuncInfo* f);
|
||||
|
||||
// Information about all of the functions (and events/hooks) in
|
||||
// the full set of scripts.
|
||||
std::vector<FuncInfo*>& funcs;
|
||||
|
||||
// Functions that we've determined to be suitable for inlining.
|
||||
std::unordered_set<Func*> inline_ables;
|
||||
|
||||
// As we do inlining for a given function, this tracks the
|
||||
// largest frame size of any inlined function.
|
||||
int max_inlined_frame_size;
|
||||
|
||||
// The size of the frame of the currently-being-inlined function,
|
||||
// prior to increasing it to accommodate inlining.
|
||||
int curr_frame_size;
|
||||
|
||||
// Whether to generate a report about functions either directly and
|
||||
// indirectly recursive.
|
||||
bool report_recursive;
|
||||
};
|
||||
|
||||
|
||||
} // namespace zeek::detail
|
Loading…
Add table
Add a link
Reference in a new issue