procedureDB Class ReferenceDatabase of procedures.
More...
#include <proceduredb.h>
Inheritance diagram for procedureDB:
List of all members.
|
Public Types |
enum | Order { Preorder,
Postorder,
Both
} |
| The order in which AST Nodes should be visited. More...
|
enum | Depth { Subtree,
NodeOnly
} |
| Which Nodes in the AST tree should be visited. More...
|
Public Member Functions |
| procedureDB () |
| Create a new procedureDB.
|
| ~procedureDB () |
| Destroy the procedure database.
|
void | build (procNode *root, Linker &linker) |
| Build database.
|
void | clear () |
| Clear.
|
void | add_procedure (procNode *proc) |
| Add a procedure to the database.
|
procedureInfo * | lookup (procNode *proc) |
| Lookup procedure-specific information.
|
const procedurecall_stack & | callstack () const |
| Call stack.
|
bool | is_recursive_call (procedureInfo *callee, int &num_instances) |
| Is recursive call?
|
void | setup_analysis () |
| Set up analysis.
|
procedureInfo * | next_procedure_on_worklist () |
| Next procedure.
|
bool | is_procedure_on_worklist (procedureInfo *info) |
| Is procedure on the worklist?
|
void | add_procedure_to_worklist (procedureInfo *info) |
| Add a procedure to the worklist.
|
void | call_to (stmtLocation *callsite, procedureInfo *callee) |
| Call a procedure.
|
void | return_from () |
| Return from a procedure.
|
bool | is_visible_to_caller (procedureInfo *info, memoryBlock *block) |
| Is variable in the caller's scope.
|
bool | is_visible_to (procedureInfo *info, memoryBlock *block) |
| Is variable visible?
|
stmtLocation * | current_callsite () |
| Return the current callsite.
|
procedureInfo * | current_caller () |
| Return the current caller.
|
void | clear_call_stack () |
| Clear the call stack.
|
void | print_call_stack (ostream &out) |
| Print call stack.
|
void | progress_meter (ostream &out) |
| Progress meter.
|
void | mark_for_reanalysis (procedureInfo *info, stmtLocation *callsite, bool include_self) |
| Mark procedure for reanalysis.
|
void | mark_one_for_reanalysis (procedureInfo *info) |
| Mark one procedure for reanalysis.
|
bool | is_reanalysis_required (procedureInfo *info) |
| Has reanalysis been forced?
|
void | print_leftovers () |
| Print left-overs.
|
int | times_called (procedureInfo *info) |
| Times called.
|
void | stats (ostream &out) |
| Print some statistics.
|
int | size () const |
| Return the number of procedures.
|
void | number_of_procedures (int &total, int &analyzed, int &context_insensitive, int &recursive, int &unanalyzed, int &program_size) |
| Get the number of procedures.
|
proc_info_map | procedures () const |
| Return all the procedures.
|
|
Methods to get and set fields in the class.
|
Order | order () const |
| Return the order in which Nodes of an AST should be visited.
|
Depth | depth () const |
| Return which Nodes of an AST should be visited.
|
|
These methods define the functions that should be performed when different classes of Nodes are encountered in the AST. The most specific "at_" method that matches a given Node's class will be called.
|
virtual void | at_node (Node *the_node, Order ord) |
virtual void | at_unit (unitNode *the_unit, Order ord) |
virtual void | at_def (defNode *the_def, Order ord) |
virtual void | at_decl (declNode *the_decl, Order ord) |
virtual void | at_subdecl (subdeclNode *the_subdecl, Order ord) |
virtual void | at_proc (procNode *the_proc, Order ord) |
virtual void | at_type (typeNode *the_type, Order ord) |
virtual void | at_prim (primNode *the_prim, Order ord) |
virtual void | at_tdef (tdefNode *the_tdef, Order ord) |
virtual void | at_ptr (ptrNode *the_ptr, Order ord) |
virtual void | at_array (arrayNode *the_array, Order ord) |
virtual void | at_func (funcNode *the_func, Order ord) |
virtual void | at_sue (sueNode *the_sue, Order ord) |
virtual void | at_struct (structNode *the_struct, Order ord) |
virtual void | at_union (unionNode *the_union, Order ord) |
virtual void | at_enum (enumNode *the_enum, Order ord) |
virtual void | at_suespec (suespecNode *the_suespec, Order ord) |
virtual void | at_expr (exprNode *the_expr, Order ord) |
virtual void | at_index (indexNode *the_index, Order ord) |
virtual void | at_const (constNode *the_const, Order ord) |
virtual void | at_id (idNode *the_id, Order ord) |
virtual void | at_binary (binaryNode *the_binary, Order ord) |
virtual void | at_unary (unaryNode *the_unary, Order ord) |
virtual void | at_cast (castNode *the_cast, Order ord) |
virtual void | at_comma (commaNode *the_comma, Order ord) |
virtual void | at_ternary (ternaryNode *the_ternary, Order ord) |
virtual void | at_call (callNode *the_call, Order ord) |
virtual void | at_initializer (initializerNode *the_initializer, Order ord) |
virtual void | at_stmt (stmtNode *the_stmt, Order ord) |
virtual void | at_block (blockNode *the_block, Order ord) |
virtual void | at_basicblock (basicblockNode *the_basicblock, Order ord) |
virtual void | at_exprstmt (exprstmtNode *the_exprstmt, Order ord) |
virtual void | at_target (targetNode *the_target, Order ord) |
virtual void | at_label (labelNode *the_label, Order ord) |
virtual void | at_case (caseNode *the_case, Order ord) |
virtual void | at_selection (selectionNode *the_selection, Order ord) |
virtual void | at_if (ifNode *the_if, Order ord) |
virtual void | at_switch (switchNode *the_switch, Order ord) |
virtual void | at_loop (loopNode *the_loop, Order ord) |
virtual void | at_while (whileNode *the_while, Order ord) |
virtual void | at_do (doNode *the_do, Order ord) |
virtual void | at_for (forNode *the_for, Order ord) |
virtual void | at_jump (jumpNode *the_jump, Order ord) |
virtual void | at_goto (gotoNode *the_goto, Order ord) |
virtual void | at_continue (continueNode *the_continue, Order ord) |
virtual void | at_break (breakNode *the_break, Order ord) |
virtual void | at_return (returnNode *the_return, Order ord) |
virtual void | at_attrib (attribNode *the_attrib, Order ord) |
virtual void | at_operand (operandNode *the_oper, Order ord) |
virtual void | at_conditiongoto (conditiongotoNode *the_condgoto, Order ord) |
virtual void | at_threeAddr (threeAddrNode *the_3addr, Order ord) |
virtual void | at_text (textNode *the_text, Order ord) |
Private Attributes |
proc_info_map | _procedures |
| All procedures.
|
callGraph * | _callgraph |
| Call graph.
|
procedureinfo_set | _need_reanalysis |
| Need reanalysis.
|
procedureInfo * | _root |
| Root procedure.
|
procedurecall_stack | _callstack |
| Call stack.
|
proc_info_list | _worklist |
| Procedure worklist.
|
Detailed Description
Database of procedures.
This class holds all of the procedureInfo instances. It also contains an instance of the Linker class, which connects up declarations across translation units. We also use it to look up procNodes given their declarations.
Definition at line 870 of file proceduredb.h.
Member Enumeration Documentation
|
Which Nodes in the AST tree should be visited.
- Enumeration values:
-
Subtree |
The entire AST should be traversed. |
NodeOnly |
Only the root Node should be visited. |
Definition at line 155 of file walker.h. |
|
The order in which AST Nodes should be visited.
- Enumeration values:
-
Preorder |
Nodes should be visited before their children. |
Postorder |
Nodes should be visited after their children. |
Both |
Nodes should be visited both before and after their children. |
Definition at line 147 of file walker.h. |
Constructor & Destructor Documentation
procedureDB::procedureDB |
( |
|
) |
|
|
|
Create a new procedureDB.
The constructor does not create the database |
procedureDB::~procedureDB |
( |
|
) |
|
|
|
Destroy the procedure database.
|
Member Function Documentation
void procedureDB::add_procedure |
( |
procNode * |
proc |
) |
|
|
|
Add a procedure to the database.
|
void procedureDB::add_procedure_to_worklist |
( |
procedureInfo * |
info |
) |
|
|
|
Add a procedure to the worklist.
|
virtual void Walker::at_array |
( |
arrayNode * |
the_array, |
|
|
Order |
ord |
|
) |
[inline, virtual, inherited] |
|
virtual void Walker::at_attrib |
( |
attribNode * |
the_attrib, |
|
|
Order |
ord |
|
) |
[inline, virtual, inherited] |
|
virtual void Walker::at_basicblock |
( |
basicblockNode * |
the_basicblock, |
|
|
Order |
ord |
|
) |
[inline, virtual, inherited] |
|
virtual void Walker::at_binary |
( |
binaryNode * |
the_binary, |
|
|
Order |
ord |
|
) |
[inline, virtual, inherited] |
|
virtual void Walker::at_block |
( |
blockNode * |
the_block, |
|
|
Order |
ord |
|
) |
[inline, virtual, inherited] |
|
virtual void Walker::at_break |
( |
breakNode * |
the_break, |
|
|
Order |
ord |
|
) |
[inline, virtual, inherited] |
|
virtual void Walker::at_call |
( |
callNode * |
the_call, |
|
|
Order |
ord |
|
) |
[inline, virtual, inherited] |
|
virtual void Walker::at_case |
( |
caseNode * |
the_case, |
|
|
Order |
ord |
|
) |
[inline, virtual, inherited] |
|
virtual void Walker::at_cast |
( |
castNode * |
the_cast, |
|
|
Order |
ord |
|
) |
[inline, virtual, inherited] |
|
virtual void Walker::at_comma |
( |
commaNode * |
the_comma, |
|
|
Order |
ord |
|
) |
[inline, virtual, inherited] |
|
virtual void Walker::at_conditiongoto |
( |
conditiongotoNode * |
the_condgoto, |
|
|
Order |
ord |
|
) |
[inline, virtual, inherited] |
|
virtual void Walker::at_const |
( |
constNode * |
the_const, |
|
|
Order |
ord |
|
) |
[inline, virtual, inherited] |
|
virtual void Walker::at_continue |
( |
continueNode * |
the_continue, |
|
|
Order |
ord |
|
) |
[inline, virtual, inherited] |
|
virtual void Walker::at_decl |
( |
declNode * |
the_decl, |
|
|
Order |
ord |
|
) |
[inline, virtual, inherited] |
|
virtual void Walker::at_def |
( |
defNode * |
the_def, |
|
|
Order |
ord |
|
) |
[inline, virtual, inherited] |
|
virtual void Walker::at_do |
( |
doNode * |
the_do, |
|
|
Order |
ord |
|
) |
[inline, virtual, inherited] |
|
virtual void Walker::at_enum |
( |
enumNode * |
the_enum, |
|
|
Order |
ord |
|
) |
[inline, virtual, inherited] |
|
virtual void Walker::at_expr |
( |
exprNode * |
the_expr, |
|
|
Order |
ord |
|
) |
[inline, virtual, inherited] |
|
virtual void Walker::at_exprstmt |
( |
exprstmtNode * |
the_exprstmt, |
|
|
Order |
ord |
|
) |
[inline, virtual, inherited] |
|
virtual void Walker::at_for |
( |
forNode * |
the_for, |
|
|
Order |
ord |
|
) |
[inline, virtual, inherited] |
|
virtual void Walker::at_func |
( |
funcNode * |
the_func, |
|
|
Order |
ord |
|
) |
[inline, virtual, inherited] |
|
virtual void Walker::at_goto |
( |
gotoNode * |
the_goto, |
|
|
Order |
ord |
|
) |
[inline, virtual, inherited] |
|
virtual void Walker::at_id |
( |
idNode * |
the_id, |
|
|
Order |
ord |
|
) |
[inline, virtual, inherited] |
|
virtual void Walker::at_if |
( |
ifNode * |
the_if, |
|
|
Order |
ord |
|
) |
[inline, virtual, inherited] |
|
virtual void Walker::at_index |
( |
indexNode * |
the_index, |
|
|
Order |
ord |
|
) |
[inline, virtual, inherited] |
|
virtual void Walker::at_initializer |
( |
initializerNode * |
the_initializer, |
|
|
Order |
ord |
|
) |
[inline, virtual, inherited] |
|
virtual void Walker::at_jump |
( |
jumpNode * |
the_jump, |
|
|
Order |
ord |
|
) |
[inline, virtual, inherited] |
|
virtual void Walker::at_label |
( |
labelNode * |
the_label, |
|
|
Order |
ord |
|
) |
[inline, virtual, inherited] |
|
virtual void Walker::at_loop |
( |
loopNode * |
the_loop, |
|
|
Order |
ord |
|
) |
[inline, virtual, inherited] |
|
virtual void Walker::at_node |
( |
Node * |
the_node, |
|
|
Order |
ord |
|
) |
[inline, virtual, inherited] |
|
|
Reimplemented in gcWalker, goto_label_walker, set_container_walker, sue_complete_walker, TreeChecker, and df_number_walker.
Definition at line 223 of file walker.h.
Referenced by Walker::at_def(), Walker::at_expr(), Walker::at_stmt(), Walker::at_text(), Walker::at_type(), and Walker::at_unit(). |
virtual void Walker::at_operand |
( |
operandNode * |
the_oper, |
|
|
Order |
ord |
|
) |
[inline, virtual, inherited] |
|
virtual void Walker::at_prim |
( |
primNode * |
the_prim, |
|
|
Order |
ord |
|
) |
[inline, virtual, inherited] |
|
virtual void Walker::at_proc |
( |
procNode * |
the_proc, |
|
|
Order |
ord |
|
) |
[inline, virtual, inherited] |
|
|
Reimplemented in vcgWalker, id_lookup_walker, name_mangle_walker, ref_fix_walker, scope_walker, set_container_walker, TreeChecker, UnitWalker, print_walker, init_flowproblem_walker, LivenessWalker, LivenessComments, reachingDefinitionsWalker, and UnificationBasedPtr.
Definition at line 239 of file walker.h.
References Walker::at_def(). |
virtual void Walker::at_ptr |
( |
ptrNode * |
the_ptr, |
|
|
Order |
ord |
|
) |
[inline, virtual, inherited] |
|
virtual void Walker::at_return |
( |
returnNode * |
the_return, |
|
|
Order |
ord |
|
) |
[inline, virtual, inherited] |
|
virtual void Walker::at_selection |
( |
selectionNode * |
the_selection, |
|
|
Order |
ord |
|
) |
[inline, virtual, inherited] |
|
virtual void Walker::at_stmt |
( |
stmtNode * |
the_stmt, |
|
|
Order |
ord |
|
) |
[inline, virtual, inherited] |
|
virtual void Walker::at_struct |
( |
structNode * |
the_struct, |
|
|
Order |
ord |
|
) |
[inline, virtual, inherited] |
|
virtual void Walker::at_subdecl |
( |
subdeclNode * |
the_subdecl, |
|
|
Order |
ord |
|
) |
[inline, virtual, inherited] |
|
virtual void Walker::at_sue |
( |
sueNode * |
the_sue, |
|
|
Order |
ord |
|
) |
[inline, virtual, inherited] |
|
virtual void Walker::at_suespec |
( |
suespecNode * |
the_suespec, |
|
|
Order |
ord |
|
) |
[inline, virtual, inherited] |
|
virtual void Walker::at_switch |
( |
switchNode * |
the_switch, |
|
|
Order |
ord |
|
) |
[inline, virtual, inherited] |
|
virtual void Walker::at_target |
( |
targetNode * |
the_target, |
|
|
Order |
ord |
|
) |
[inline, virtual, inherited] |
|
virtual void Walker::at_tdef |
( |
tdefNode * |
the_tdef, |
|
|
Order |
ord |
|
) |
[inline, virtual, inherited] |
|
virtual void Walker::at_ternary |
( |
ternaryNode * |
the_ternary, |
|
|
Order |
ord |
|
) |
[inline, virtual, inherited] |
|
virtual void Walker::at_text |
( |
textNode * |
the_text, |
|
|
Order |
ord |
|
) |
[inline, virtual, inherited] |
|
virtual void Walker::at_threeAddr |
( |
threeAddrNode * |
the_3addr, |
|
|
Order |
ord |
|
) |
[inline, virtual, inherited] |
|
virtual void Walker::at_type |
( |
typeNode * |
the_type, |
|
|
Order |
ord |
|
) |
[inline, virtual, inherited] |
|
virtual void Walker::at_unary |
( |
unaryNode * |
the_unary, |
|
|
Order |
ord |
|
) |
[inline, virtual, inherited] |
|
virtual void Walker::at_union |
( |
unionNode * |
the_union, |
|
|
Order |
ord |
|
) |
[inline, virtual, inherited] |
|
virtual void Walker::at_unit |
( |
unitNode * |
the_unit, |
|
|
Order |
ord |
|
) |
[inline, virtual, inherited] |
|
virtual void Walker::at_while |
( |
whileNode * |
the_while, |
|
|
Order |
ord |
|
) |
[inline, virtual, inherited] |
|
|
Build database.
This method first visits all the procedures currently parsed and builds a procedureInfo object for each. It uses the Linker object, which has already traversed the entire system and fixed the linkages between symbol references and externally defined symbols. |
|
Call a procedure.
This method is called when analysis is entering a new procedure. It pushes the procedure on the stack and sets up the procedure for analysis. |
void procedureDB::clear |
( |
|
) |
|
|
void procedureDB::clear_call_stack |
( |
|
) |
|
|
|
Clear the call stack.
WARNING: Only use this routine at the end of an analysis pass. |
|
Return the current caller.
Return the caller of the current procedure in the call stack. |
Depth Walker::depth |
( |
|
) |
const [inline, inherited] |
|
|
Return which Nodes of an AST should be visited.
A value of SubTree specifies that the entire AST should be traversed. A value of NodeOnly specifies that only the root Node in the AST should be visited.
Definition at line 211 of file walker.h.
References Walker::_depth. |
bool procedureDB::is_procedure_on_worklist |
( |
procedureInfo * |
info |
) |
|
|
|
Is procedure on the worklist?
If so, remove it and return true. |
bool procedureDB::is_reanalysis_required |
( |
procedureInfo * |
info |
) |
|
|
|
Has reanalysis been forced?
At a procedure call, check to see if this particular procedure is on the _needs_reanalysis list, indicating that we cannot skip analyzing it, even if the inputs appear not to have changed. |
bool procedureDB::is_recursive_call |
( |
procedureInfo * |
callee, |
|
|
int & |
num_instances |
|
) |
|
|
|
Is recursive call?
Return true if calling the given procedure would create a recursive cycle in the call stack. |
|
Is variable visible?
Check to see if the given variable could be accessed in the given procedure, or in any of its ancestors in the callgraph. If it is, then we need to pass it as an external output. |
|
Is variable in the caller's scope.
Check to see if the variable is visible to procedures earlier in the call stack. |
|
Lookup procedure-specific information.
|
|
Mark procedure for reanalysis.
Record that particular procedure needs to be reanalyzed. Add all of it's ancestors to the list as well to ensure that we actually reach it again. This method does not add the given procedure itself unless the include_self flag is true. |
void procedureDB::mark_one_for_reanalysis |
( |
procedureInfo * |
info |
) |
|
|
|
Mark one procedure for reanalysis.
Add the given procedure to the list of those needing reanalysis. |
|
Next procedure.
Grab the next procedure from the work-list. |
void procedureDB::number_of_procedures |
( |
int & |
total, |
|
|
int & |
analyzed, |
|
|
int & |
context_insensitive, |
|
|
int & |
recursive, |
|
|
int & |
unanalyzed, |
|
|
int & |
program_size |
|
) |
|
|
|
Get the number of procedures.
This version only counts procedures that have been analyzed. |
Order Walker::order |
( |
|
) |
const [inline, inherited] |
|
|
Return the order in which Nodes of an AST should be visited.
Nodes can be visited before their children (Preorder), after their children (Postorder), or both (Both).
Definition at line 203 of file walker.h.
References Walker::_order.
Referenced by df_number_walker::at_node(). |
void procedureDB::print_call_stack |
( |
ostream & |
out |
) |
|
|
void procedureDB::print_leftovers |
( |
|
) |
|
|
void procedureDB::progress_meter |
( |
ostream & |
out |
) |
|
|
void procedureDB::return_from |
( |
|
) |
|
|
|
Return from a procedure.
This method is called when analysis of a procedure is complete. It just pops the current procedure off the stack. |
void procedureDB::setup_analysis |
( |
|
) |
|
|
|
Set up analysis.
Add all procedures to the _needs_analysis list. |
int procedureDB::size |
( |
void |
|
) |
const [inline] |
|
void procedureDB::stats |
( |
ostream & |
out |
) |
|
|
|
Times called.
Use the callgraph to estimate the number of paths from main down to the given procedure. We'll use this to decide when to make a procedure context insensitive. The basic heuristic is that if a procedure is small, and called in many places, then leave it context sensitive. |
Member Data Documentation
|
Need reanalysis.
In context-insensitive mode, we may need to revisit procedures because of changes in other calling contexts. Whenever a non-local change occurs, we add the procedure and all of it's ancestors back on this list. This ensures that we will revisit the procedure at some point.
Definition at line 891 of file proceduredb.h. |
The documentation for this class was generated from the following file:
|