C-Breeze
C Compiler Infrastructure

[ Project home page]
Main Page   Modules   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

livenessAnalyzer Class Reference

Liveness analyzer. More...

#include <liveness.h>

Inheritance diagram for livenessAnalyzer:

analysisProblem List of all members.

Public Member Functions

 livenessAnalyzer ()
 Create a liveness analysis object.

virtual string name ()
 Name of the analysis.

void clear ()
 Reset liveness information.

bool isLive (stmtNode *stmt)
 Is a particular statement live.

const procedure_setvisited_procedures () const
virtual void at_index (stmtLocation *current, operandNode *operand, pointerValue &left, pointerValue &right, pointerValue &result)
virtual void at_call (stmtLocation *current, operandNode *call, pointerValue &call_target, procNode *callee, pointervalue_list &arguments, pointerValue &return_val)
virtual void at_assignment (stmtLocation *current, pointerValue &left, pointerValue &right, pointerValue &result, memoryblock_set &changes)
virtual void at_return (stmtLocation *stmt, returnNode *ret, pointerValue &result, pointerValue &return_val)
virtual void at_threeAddr (stmtLocation *stmt, threeAddrNode *threeaddr, pointerValue &result)
virtual void at_conditiongoto (stmtLocation *stmt, conditiongotoNode *c, pointerValue &result)
virtual void at_merge (Location *where, memoryBlock *block, memoryuse_list &phi_uses, pointerValue &result, memoryblock_set &changes)
virtual void at_allocation (stmtLocation *stmt, pointervalue_list &arguments, memoryBlock *block, memoryblock_set &changes)
virtual void at_deallocation (stmtLocation *stmt, pointerValue &to_deallocate, memoryblock_set &changes)
virtual void at_stmt_exit (stmtLocation *stmt, pointerValue &result)
virtual void at_basicblock_entry (basicblockLocation *block, procedureInfo *info, pointerValue &initial)
virtual void at_procedure_entry (procLocation *proc, procedureInfo *info, pointerValue &return_val)
virtual void at_procedure_exit (procLocation *proc, procedureInfo *info, pointerValue &return_val)
Direction direction () const
 Get the direction.

virtual bool compare_property_value (Location *where, memoryBlock *property_block, procedureInfo *callee)
 Compare current property value against the last input to callee.

virtual void record_input_to_value (procedureInfo *callee, memoryBlock *property_block, Location *where)
 Record the value of a property when it is used as an input_to/external_input value to a call to callee at a call site.

Transfer functions
The rest of these functions are hooks for the pointer analyzer to call at various points in the analysis. They serve as the transfer functions for the dataflow analysis problem.

virtual void at_id (stmtLocation *current, idNode *id, pointerValue &result)
virtual void at_unary (stmtLocation *current, threeAddrNode *r, pointerValue &operand, pointerValue &result)
virtual void at_sizeof (stmtLocation *current, threeAddrNode *r, pointerValue &operand, pointerValue &result)
virtual void at_binary (stmtLocation *current, stmtNode *r, pointerValue &left, pointerValue &right, pointerValue &result)
virtual void at_cast (stmtLocation *current, operandNode *operand, pointerValue &operand_value, pointerValue &result)
virtual void at_const (stmtLocation *current, constNode *cons, pointerValue &result)
virtual void at_field_access (stmtLocation *current, operandNode *operand, pointerValue &operand_value, pointerValue &result)
virtual void at_dereference (stmtLocation *current, operandNode *operand, pointerValue &operand_value, pointerValue &result)
virtual void at_address (stmtLocation *current, operandNode *operand, pointerValue &operand_value, pointerValue &result)
virtual void at_parameter_pass (Location *current, stmtLocation *parameter_callsite, pointerValue &left, pointerValue &right, memoryblock_set &changes)
virtual void at_self_assignment (Location *source, Location *target, memoryBlock *block, memoryblock_set &changes, bool is_input)
virtual void at_return (Location *current, pointerValue &left, pointerValue &right, memoryblock_set &changes)
virtual void at_stmt_entry (stmtLocation *stmt, pointerValue &result)
virtual void at_basicblock_exit (basicblockLocation *block, procedureInfo *info, pointerValue &final)
virtual void at_conservative_procedure_call (stmtLocation *current, operandNode *call, operand_list &args, pointerValue &call_target, pointervalue_list &arguments, memoryblock_set &reachable_blocks, pointerValue &return_val, memoryblock_set &changes)

Protected Member Functions

void collectDefs (pointerValue &pointer)
 Collect defs.

void addDef (memoryDef *def)
 Add one def.

bool determineLiveness ()
 Determine liveness.

bool isLive (memoryUse *use, memoryBlock *owner)
 Look up liveness.

void setLive (stmtLocation *where)
 Set live for statements.

void setLive (Location *where, memoryBlock *block)
 Set live for merge-points.


Protected Attributes

Direction _direction

Private Types

typedef set< stmtNode * > stmt_liveness_set
typedef stmt_liveness_set::iterator stmt_liveness_set_p
typedef set< stmtLocation * > stmtlocation_liveness_set
typedef stmtlocation_liveness_set::iterator stmtlocation_liveness_set_p
typedef pair< Location *,
memoryBlock * > 
mergepoint_pair
typedef set< mergepoint_pairmergepoint_liveness_set
typedef mergepoint_liveness_set::iterator mergepoint_liveness_set_p
typedef list< bool > change_stack
typedef change_stack::iterator change_stack_p

Private Attributes

stmt_liveness_set _live_stmts
 Live statements.

stmtlocation_liveness_set _live_stmtlocations
 Live statement locations.

mergepoint_liveness_set _live_mergepoints
 Live merge points.

memorydef_set _defs
 Collect defs.

bool _change
 Record changes.

change_stack _change_stack
 Change stack.

procedure_set _visited_procedures
 Set of visited procedures.


Detailed Description

Liveness analyzer.

Liveness is a property of statements in the program. A statement is live if any of the defs created by the statement are live. A def is live if it has uses, and at least one of it's uses is live. A use is live if the statement in which it occurs is live.

Definition at line 56 of file liveness.h.


Member Typedef Documentation

typedef list< bool > livenessAnalyzer::change_stack [private]
 

Definition at line 70 of file liveness.h.

typedef change_stack::iterator livenessAnalyzer::change_stack_p [private]
 

Definition at line 71 of file liveness.h.

typedef set< mergepoint_pair > livenessAnalyzer::mergepoint_liveness_set [private]
 

Definition at line 67 of file liveness.h.

typedef mergepoint_liveness_set::iterator livenessAnalyzer::mergepoint_liveness_set_p [private]
 

Definition at line 68 of file liveness.h.

Referenced by isLive().

typedef pair< Location *, memoryBlock * > livenessAnalyzer::mergepoint_pair [private]
 

Definition at line 66 of file liveness.h.

Referenced by isLive(), and setLive().

typedef set< stmtNode * > livenessAnalyzer::stmt_liveness_set [private]
 

Definition at line 60 of file liveness.h.

typedef stmt_liveness_set::iterator livenessAnalyzer::stmt_liveness_set_p [private]
 

Definition at line 61 of file liveness.h.

Referenced by isLive().

typedef set< stmtLocation * > livenessAnalyzer::stmtlocation_liveness_set [private]
 

Definition at line 63 of file liveness.h.

typedef stmtlocation_liveness_set::iterator livenessAnalyzer::stmtlocation_liveness_set_p [private]
 

Definition at line 64 of file liveness.h.

Referenced by isLive().


Constructor & Destructor Documentation

livenessAnalyzer::livenessAnalyzer  
 

Create a liveness analysis object.

Definition at line 43 of file liveness.cc.

References Backward.


Member Function Documentation

void livenessAnalyzer::addDef memoryDef   def [protected]
 

Add one def.

Definition at line 84 of file liveness.cc.

References _defs.

virtual void analysisProblem::at_address stmtLocation   current,
operandNode   operand,
pointerValue   operand_value,
pointerValue   result
[inline, virtual, inherited]
 

Definition at line 151 of file ipanalysis.h.

Referenced by Pointers::eval().

void livenessAnalyzer::at_allocation stmtLocation   stmt,
pointervalue_list   arguments,
memoryBlock   block,
memoryblock_set   changes
[virtual]
 

Reimplemented from analysisProblem.

Definition at line 290 of file liveness.cc.

References setLive().

void livenessAnalyzer::at_assignment stmtLocation   current,
pointerValue   left,
pointerValue   right,
pointerValue   result,
memoryblock_set   changes
[virtual]
 

Reimplemented from analysisProblem.

Definition at line 247 of file liveness.cc.

References collectDefs().

void livenessAnalyzer::at_basicblock_entry basicblockLocation   block,
procedureInfo   info,
pointerValue   initial
[virtual]
 

Reimplemented from analysisProblem.

Definition at line 332 of file liveness.cc.

References _change, procedureInfo::add_reachable_blocks(), Backward, and basicblockLocation::block().

virtual void analysisProblem::at_basicblock_exit basicblockLocation   block,
procedureInfo   info,
pointerValue   final
[inline, virtual, inherited]
 

Definition at line 241 of file ipanalysis.h.

Referenced by Pointers::analyze_procedure().

virtual void analysisProblem::at_binary stmtLocation   current,
stmtNode   r,
pointerValue   left,
pointerValue   right,
pointerValue   result
[inline, virtual, inherited]
 

Definition at line 112 of file ipanalysis.h.

Referenced by Pointers::eval().

void livenessAnalyzer::at_call stmtLocation   current,
operandNode   call,
pointerValue   call_target,
procNode   callee,
pointervalue_list   arguments,
pointerValue   return_val
[virtual]
 

Reimplemented from analysisProblem.

Definition at line 234 of file liveness.cc.

References setLive().

virtual void analysisProblem::at_cast stmtLocation   current,
operandNode   operand,
pointerValue   operand_value,
pointerValue   result
[inline, virtual, inherited]
 

Definition at line 119 of file ipanalysis.h.

Referenced by Pointers::eval().

void livenessAnalyzer::at_conditiongoto stmtLocation   stmt,
conditiongotoNode   c,
pointerValue   result
[virtual]
 

Reimplemented from analysisProblem.

Definition at line 279 of file liveness.cc.

References setLive().

virtual void analysisProblem::at_conservative_procedure_call stmtLocation   current,
operandNode   call,
operand_list   args,
pointerValue   call_target,
pointervalue_list   arguments,
memoryblock_set   reachable_blocks,
pointerValue   return_val,
memoryblock_set   changes
[inline, virtual, inherited]
 

Definition at line 248 of file ipanalysis.h.

Referenced by Pointers::procedure_call().

virtual void analysisProblem::at_const stmtLocation   current,
constNode   cons,
pointerValue   result
[inline, virtual, inherited]
 

Definition at line 124 of file ipanalysis.h.

Referenced by Pointers::eval().

void livenessAnalyzer::at_deallocation stmtLocation   stmt,
pointerValue   to_deallocate,
memoryblock_set   changes
[virtual]
 

Reimplemented from analysisProblem.

Definition at line 298 of file liveness.cc.

References setLive().

virtual void analysisProblem::at_dereference stmtLocation   current,
operandNode   operand,
pointerValue   operand_value,
pointerValue   result
[inline, virtual, inherited]
 

Reimplemented in precisionAnalyzer.

Definition at line 145 of file ipanalysis.h.

Referenced by Pointers::eval().

virtual void analysisProblem::at_field_access stmtLocation   current,
operandNode   operand,
pointerValue   operand_value,
pointerValue   result
[inline, virtual, inherited]
 

Reimplemented in precisionAnalyzer.

Definition at line 139 of file ipanalysis.h.

Referenced by Pointers::eval().

virtual void analysisProblem::at_id stmtLocation   current,
idNode   id,
pointerValue   result
[inline, virtual, inherited]
 

Definition at line 96 of file ipanalysis.h.

Referenced by Pointers::eval().

void livenessAnalyzer::at_index stmtLocation   current,
operandNode   operand,
pointerValue   left,
pointerValue   right,
pointerValue   result
[virtual]
 

Reimplemented from analysisProblem.

Definition at line 223 of file liveness.cc.

References setLive().

void livenessAnalyzer::at_merge Location   where,
memoryBlock   block,
memoryuse_list   phi_uses,
pointerValue   result,
memoryblock_set   changes
[virtual]
 

Reimplemented from analysisProblem.

Definition at line 307 of file liveness.cc.

References _defs, memoryBlock::current_def(), determineLiveness(), and setLive().

virtual void analysisProblem::at_parameter_pass Location   current,
stmtLocation   parameter_callsite,
pointerValue   left,
pointerValue   right,
memoryblock_set   changes
[inline, virtual, inherited]
 

Definition at line 173 of file ipanalysis.h.

Referenced by Pointers::pass_parameters(), and Pointers::setup_va_list_variables().

void livenessAnalyzer::at_procedure_entry procLocation   proc,
procedureInfo   info,
pointerValue   return_val
[virtual]
 

Reimplemented from analysisProblem.

Definition at line 347 of file liveness.cc.

References _change, _change_stack, _visited_procedures, and procedureInfo::proc().

void livenessAnalyzer::at_procedure_exit procLocation   proc,
procedureInfo   info,
pointerValue   return_val
[virtual]
 

Reimplemented from analysisProblem.

Definition at line 361 of file liveness.cc.

References _change, and _change_stack.

virtual void analysisProblem::at_return Location   current,
pointerValue   left,
pointerValue   right,
memoryblock_set   changes
[inline, virtual, inherited]
 

Definition at line 189 of file ipanalysis.h.

void livenessAnalyzer::at_return stmtLocation   stmt,
returnNode   ret,
pointerValue   result,
pointerValue   return_val
[virtual]
 

Definition at line 258 of file liveness.cc.

References setLive().

virtual void analysisProblem::at_self_assignment Location   source,
Location   target,
memoryBlock   block,
memoryblock_set   changes,
bool    is_input
[inline, virtual, inherited]
 

Definition at line 180 of file ipanalysis.h.

Referenced by Pointers::pass_one_external_input(), and Pointers::pass_one_external_output().

virtual void analysisProblem::at_sizeof stmtLocation   current,
threeAddrNode   r,
pointerValue   operand,
pointerValue   result
[inline, virtual, inherited]
 

Definition at line 106 of file ipanalysis.h.

Referenced by Pointers::eval().

virtual void analysisProblem::at_stmt_entry stmtLocation   stmt,
pointerValue   result
[inline, virtual, inherited]
 

Definition at line 233 of file ipanalysis.h.

Referenced by Pointers::analyze_procedure().

void livenessAnalyzer::at_stmt_exit stmtLocation   stmt,
pointerValue   result
[virtual]
 

Reimplemented from analysisProblem.

Definition at line 324 of file liveness.cc.

References _defs.

void livenessAnalyzer::at_threeAddr stmtLocation   stmt,
threeAddrNode   threeaddr,
pointerValue   result
[virtual]
 

Reimplemented from analysisProblem.

Definition at line 268 of file liveness.cc.

References determineLiveness(), and setLive().

virtual void analysisProblem::at_unary stmtLocation   current,
threeAddrNode   r,
pointerValue   operand,
pointerValue   result
[inline, virtual, inherited]
 

Definition at line 100 of file ipanalysis.h.

Referenced by Pointers::eval().

void livenessAnalyzer::clear  
 

Reset liveness information.

Allow the liveness analyzer to be run again.

Definition at line 54 of file liveness.cc.

References _change, _change_stack, _defs, _live_mergepoints, _live_stmtlocations, and _live_stmts.

void livenessAnalyzer::collectDefs pointerValue   pointer [protected]
 

Collect defs.

Definition at line 70 of file liveness.cc.

References _defs, pointerValue::blocks, memoryBlock::current_def(), def, memoryblock_set_p, and memoryBlock::write_protected().

Referenced by at_assignment().

virtual bool analysisProblem::compare_property_value Location   where,
memoryBlock   property_block,
procedureInfo   callee
[inline, virtual, inherited]
 

Compare current property value against the last input to callee.

Returns true if equal.

Definition at line 273 of file ipanalysis.h.

Referenced by Pointers::process_local_changes().

bool livenessAnalyzer::determineLiveness   [protected]
 

Determine liveness.

Given the set of defs collected earlier, visit each def and each use that it reaches to see if any of them are live.

Definition at line 89 of file liveness.cc.

References _defs, def, memoryBlock::def_uses(), isLive(), memorydef_set_p, memoryuse_list_p, memoryBlock::name(), and use.

Referenced by at_merge(), and at_threeAddr().

Direction analysisProblem::direction   const [inline, inherited]
 

Get the direction.

Definition at line 78 of file ipanalysis.h.

References Direction.

Referenced by analysisProblem::analysisProblem().

bool livenessAnalyzer::isLive memoryUse   use,
memoryBlock   owner
[protected]
 

Look up liveness.

Look up the liveness of a memoryUse. This depends on the kind of location it comes from. As a special case, procLocations are always considered live.

Definition at line 144 of file liveness.cc.

References _live_mergepoints, _live_stmtlocations, Location::BasicBlock, Location::kind(), mergepoint_liveness_set_p, mergepoint_pair, Location::Procedure, Location::Statement, stmtlocation_liveness_set_p, and use.

bool livenessAnalyzer::isLive stmtNode   stmt
 

Is a particular statement live.

This is the context insensitive query

Definition at line 64 of file liveness.cc.

References _live_stmts, and stmt_liveness_set_p.

Referenced by deadcodeChanger::at_threeAddr(), and determineLiveness().

virtual string livenessAnalyzer::name   [inline, virtual]
 

Name of the analysis.

Just for debug purposes.

Implements analysisProblem.

Definition at line 132 of file liveness.h.

virtual void analysisProblem::record_input_to_value procedureInfo   callee,
memoryBlock   property_block,
Location   where
[inline, virtual, inherited]
 

Record the value of a property when it is used as an input_to/external_input value to a call to callee at a call site.

Definition at line 280 of file ipanalysis.h.

Referenced by Pointers::pass_one_external_input().

void livenessAnalyzer::setLive Location   where,
memoryBlock   block
[protected]
 

Set live for merge-points.

Record the given merge-point as live. Since all blocks share a single merge-point location, we need to distinguish which ones are live by the specific block being merged.

Definition at line 194 of file liveness.cc.

References _change, _live_mergepoints, and mergepoint_pair.

void livenessAnalyzer::setLive stmtLocation   where [protected]
 

Set live for statements.

Record the given statement location as live.

Definition at line 205 of file liveness.cc.

References _change, _live_stmtlocations, _live_stmts, and stmtLocation::stmt().

Referenced by at_allocation(), at_call(), at_conditiongoto(), at_deallocation(), at_index(), at_merge(), at_return(), and at_threeAddr().

const procedure_set& livenessAnalyzer::visited_procedures   const [inline]
 

Definition at line 188 of file liveness.h.

References procedure_set.

Referenced by deadcodeChanger::optimize().


Member Data Documentation

bool livenessAnalyzer::_change [private]
 

Record changes.

Definition at line 106 of file liveness.h.

Referenced by at_basicblock_entry(), at_procedure_entry(), at_procedure_exit(), clear(), and setLive().

change_stack livenessAnalyzer::_change_stack [private]
 

Change stack.

We need to record the state of the change boolean in procedures above the current one.

Definition at line 113 of file liveness.h.

Referenced by at_procedure_entry(), at_procedure_exit(), and clear().

memorydef_set livenessAnalyzer::_defs [private]
 

Collect defs.

This set is used on a per-statement basis to collect memoryDef objects. Once we have the set of defs, we can decide whether or not the current statement is live.

Definition at line 102 of file liveness.h.

Referenced by addDef(), at_merge(), at_stmt_exit(), clear(), collectDefs(), and determineLiveness().

Direction analysisProblem::_direction [protected, inherited]
 

Definition at line 64 of file ipanalysis.h.

mergepoint_liveness_set livenessAnalyzer::_live_mergepoints [private]
 

Live merge points.

This set records which merge points are live. A merge point is specified by the basic block in which it occurs, and the memoryBlock being merged.

Definition at line 94 of file liveness.h.

Referenced by clear(), isLive(), and setLive().

stmtlocation_liveness_set livenessAnalyzer::_live_stmtlocations [private]
 

Live statement locations.

Set of live statements. Note that some kinds of statements are automatically live (for example, the return statement and all if statements.

Definition at line 86 of file liveness.h.

Referenced by clear(), isLive(), and setLive().

stmt_liveness_set livenessAnalyzer::_live_stmts [private]
 

Live statements.

This set records which statements are live. It is really context-insensitive summary of the live statement locations.

Definition at line 78 of file liveness.h.

Referenced by clear(), isLive(), and setLive().

procedure_set livenessAnalyzer::_visited_procedures [private]
 

Set of visited procedures.

We record the visited procedures so that we don't remove dead code from uncalled procedures.

Definition at line 120 of file liveness.h.

Referenced by at_procedure_entry().


The documentation for this class was generated from the following files:

Generated on August 27, 2003
Back to the C-Breeze home page