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  

constantAnalyzer Class Reference

#include <constants.h>

List of all members.

Public Member Functions

 constantAnalyzer ()
 Create a new constant analysis.

 ~constantAnalyzer ()
 Destructor.

void clear ()
 Clear.

void set_null_object (memoryBlock *null_object)
 Set the null object.

const constant * top () const
 TOP value.

const constant * bottom () const
 BOTTOM value.

bool has_value (const constant *val)
 Has value.

bool has_truth_value (const constant *val, bool &value)
 Check for truth value.

const constant * lookup (const constant &value)
 Lookup a constant value.

const constant * lookup_flowvalue (memoryDef *def)
 Lookup a variable value.

bool update_flowvalue (const constant *val, memoryDef *def)
 Update a variable value.

const constant * meet (const constant *one, const constant *two)
 Meet function.

const constant * rebuild_flowvalue (pointerValue &pointer)
 Rebuild the flow value.

void record_expression (exprNode *expr, const constant *val)
 Record the value of an expression.

void record_stmt (stmtNode *stmt, const constant *val)
 Record the rhs value of an threeAddr.

const constant * evaluate_points_to (const memoryblock_set &points_to)
 Evaluate points-to set.

const constant * lookup_expression (exprNode *expr)
 Look up an expression.

const constant * lookup_stmt (stmtNode *expr)
void at_id (stmtLocation *current, idNode *id, pointerValue &value)
void at_unary (stmtLocation *current, stmtNode *t, pointerValue &operand, pointerValue &result)
void at_sizeof (stmtLocation *current, threeAddrNode *t, pointerValue &operand, pointerValue &result)
void at_binary (stmtLocation *current, stmtNode *s, pointerValue &left, pointerValue &right, pointerValue &result)
void at_const (stmtLocation *current, constNode *cons, pointerValue &result)
void at_address (stmtLocation *current, operandNode *operand, pointerValue &result)
void at_cast (stmtLocation *current, operandNode *operand, pointerValue &operand_val, pointerValue &result)
void at_dereference (stmtLocation *current, operandNode *operand, pointerValue &result)
void at_field_access (stmtLocation *current, operandNode *operand, pointerValue &result)
void at_index (stmtLocation *current, operandNode *operand, pointerValue &result)
void at_assignment (stmtLocation *current, pointerValue &left, pointerValue &right, pointerValue &result, memoryblock_set &changes)
void at_parameter_pass (Location *current, pointerValue &left, pointerValue &right, memoryblock_set &changes)
void at_self_assignment (Location *source, Location *target, memoryBlock *block, memoryblock_set &changes)
void at_return (stmtLocation *stmt, returnNode *ret, pointerValue &result, pointerValue &return_val)
void at_merge (Location *where, memoryBlock *block, memoryuse_list &phi_uses, pointerValue &result, memoryblock_set &changes)
void at_basicblock_entry (basicblockLocation *block, procedureInfo *info, pointerValue &initial)
void at_stmt_entry (stmtLocation *stmt, pointerValue &result)
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)
void print (ostream &o, const constant *val)
string to_string (const constant *val)

Private Types

typedef set< constant > constant_set
typedef constant_set::iterator constant_set_p
typedef map< exprNode *, const
constant * > 
expr_value_map
typedef expr_value_map::iterator expr_value_map_p
typedef map< stmtNode *, const
constant * > 
stmt_value_map
typedef stmt_value_map::iterator stmt_value_map_p

Private Member Functions

void record_change (memoryDef *def)
 Obsolete: Record a value change.


Private Attributes

TREE constant_set _schar_constants
 The set of all constants.

TREE constant_set _uchar_constants
TREE constant_set _sshort_constants
TREE constant_set _ushort_constants
TREE constant_set _sint_constants
TREE constant_set _uint_constants
TREE constant_set _slong_constants
TREE constant_set _ulong_constants
TREE constant_set _float_constants
TREE constant_set _double_constants
REF memoryBlock * _null
 Null object.

const constant * _top
 Unique lattice top element.

const constant * _bottom
 Unique lattice bottom element.

const constant * _non_null
 Special non-null element.

expr_value_map _expr_values
 Record the value of each expression.

stmt_value_map _stmt_values


Member Typedef Documentation

typedef set< constant > constantAnalyzer::constant_set [private]
 

Definition at line 53 of file constants.h.

typedef constant_set::iterator constantAnalyzer::constant_set_p [private]
 

Definition at line 54 of file constants.h.

Referenced by lookup().

typedef map< exprNode *, const constant * > constantAnalyzer::expr_value_map [private]
 

Definition at line 56 of file constants.h.

typedef expr_value_map::iterator constantAnalyzer::expr_value_map_p [private]
 

Definition at line 57 of file constants.h.

Referenced by lookup_expression(), and record_expression().

typedef map< stmtNode *, const constant * > constantAnalyzer::stmt_value_map [private]
 

Definition at line 59 of file constants.h.

typedef stmt_value_map::iterator constantAnalyzer::stmt_value_map_p [private]
 

Definition at line 60 of file constants.h.

Referenced by lookup_stmt(), and record_stmt().


Constructor & Destructor Documentation

constantAnalyzer::constantAnalyzer (    ) 
 

Create a new constant analysis.

Definition at line 44 of file constants.cc.

constantAnalyzer::~constantAnalyzer (    ) 
 

Destructor.

Definition at line 67 of file constants.cc.

References _bottom, _non_null, and _top.


Member Function Documentation

void constantAnalyzer::at_address (  stmtLocation *    current,
operandNode *    operand,
pointerValue &    result
) 
 

Definition at line 676 of file constants.cc.

References _bottom, operandNode::addr(), and pointerValue::constant_value.

Referenced by Pointers::eval().

void constantAnalyzer::at_assignment (  stmtLocation *    current,
pointerValue &    left,
pointerValue &    right,
pointerValue &    result,
memoryblock_set &    changes
) 
 

Definition at line 772 of file constants.cc.

References _bottom, _top, pointerValue::blocks, pointerValue::constant_value, memoryBlock::current_def(), memoryBlock::current_use(), def, vector_set< memoryBlock * >::insert(), lookup_flowvalue(), meet(), memoryblock_set_p, memoryUse::reaching_def(), update_flowvalue(), and memoryBlock::write_protected().

Referenced by Pointers::eval(), and Pointers::struct_union_assignment().

void constantAnalyzer::at_basicblock_entry (  basicblockLocation *    block,
procedureInfo *    info,
pointerValue &    initial
) 
 

Definition at line 943 of file constants.cc.

References _top, and pointerValue::constant_value.

void constantAnalyzer::at_binary (  stmtLocation *    current,
stmtNode *    s,
pointerValue &    left,
pointerValue &    right,
pointerValue &    result
) 
 

Definition at line 558 of file constants.cc.

References _bottom, _non_null, _top, Condition, pointerValue::constant_value, Operator::EQ, constant::eval(), Operator::id(), pointerValue::is_a_use, Operator::is_unary(), constant::is_zero(), lookup(), Operator::NE, record_stmt(), ThreeAddr, and Node::typ().

Referenced by Pointers::analyze_procedure(), and Pointers::eval().

void constantAnalyzer::at_cast (  stmtLocation *    current,
operandNode *    operand,
pointerValue &    operand_val,
pointerValue &    result
) 
 

Definition at line 683 of file constants.cc.

References _bottom, _non_null, _top, primNode::basic(), constant::cast(), operandNode::cast(), pointerValue::constant_value, pointerValue::is_a_use, lookup(), Prim, record_expression(), and Node::typ().

Referenced by Pointers::eval().

void constantAnalyzer::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
) 
 

Definition at line 958 of file constants.cc.

References bottom(), memoryBlock::current_def(), def, vector_set< memoryBlock * >::insert(), memoryblock_set_p, update_flowvalue(), and memoryBlock::write_protected().

Referenced by Pointers::procedure_call().

void constantAnalyzer::at_const (  stmtLocation *    current,
constNode *    cons,
pointerValue &    result
) 
 

Definition at line 652 of file constants.cc.

References _bottom, primNode::basic(), pointerValue::constant_value, constant::is_str(), lookup(), Prim, Node::typ(), exprNode::type(), and exprNode::value().

Referenced by Pointers::eval().

void constantAnalyzer::at_dereference (  stmtLocation *    current,
operandNode *    operand,
pointerValue &    result
) 
 

Definition at line 732 of file constants.cc.

References pointerValue::constant_value, pointerValue::is_a_use, rebuild_flowvalue(), record_expression(), and operandNode::star().

Referenced by Pointers::eval().

void constantAnalyzer::at_field_access (  stmtLocation *    current,
operandNode *    operand,
pointerValue &    result
) 
 

Definition at line 745 of file constants.cc.

References pointerValue::constant_value, operandNode::fields(), pointerValue::is_a_use, rebuild_flowvalue(), and record_expression().

Referenced by Pointers::eval().

void constantAnalyzer::at_id (  stmtLocation *    current,
idNode *    id,
pointerValue &    value
) 
 

Definition at line 476 of file constants.cc.

References pointerValue::constant_value, pointerValue::is_a_use, rebuild_flowvalue(), and record_expression().

Referenced by Pointers::eval().

void constantAnalyzer::at_index (  stmtLocation *    current,
operandNode *    operand,
pointerValue &    result
) 
 

Definition at line 758 of file constants.cc.

References pointerValue::constant_value, operandNode::index(), pointerValue::is_a_use, rebuild_flowvalue(), and record_expression().

Referenced by Pointers::eval().

void constantAnalyzer::at_merge (  Location *    where,
memoryBlock *    block,
memoryuse_list &    phi_uses,
pointerValue &    result,
memoryblock_set &    changes
) 
 

Definition at line 913 of file constants.cc.

References _top, memoryBlock::current_def(), def, vector_set< memoryBlock * >::insert(), lookup_flowvalue(), meet(), memoryuse_list_p, memoryUse::reaching_def(), and update_flowvalue().

Referenced by Pointers::process_merge_point().

void constantAnalyzer::at_parameter_pass (  Location *    current,
pointerValue &    left,
pointerValue &    right,
memoryblock_set &    changes
) 
 

Definition at line 866 of file constants.cc.

References _top, pointerValue::blocks, pointerValue::constant_value, memoryBlock::current_def(), def, vector_set< memoryBlock * >::insert(), pointerValue::is_address, memoryblock_set_p, and update_flowvalue().

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

void constantAnalyzer::at_return (  stmtLocation *    stmt,
returnNode *    ret,
pointerValue &    result,
pointerValue &    return_val
) 
 

Definition at line 903 of file constants.cc.

References pointerValue::constant_value.

void constantAnalyzer::at_self_assignment (  Location *    source,
Location *    target,
memoryBlock *    block,
memoryblock_set &    changes
) 
 

Definition at line 821 of file constants.cc.

References _top, memoryBlock::current_def(), memoryBlock::current_use(), def, vector_set< memoryBlock * >::insert(), lookup_flowvalue(), meet(), memoryUse::reaching_def(), rebuild_flowvalue(), update_flowvalue(), and memoryBlock::write_protected().

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

void constantAnalyzer::at_sizeof (  stmtLocation *    current,
threeAddrNode *    t,
pointerValue &    operand,
pointerValue &    result
) 
 

Definition at line 486 of file constants.cc.

References _bottom, primNode::basic(), lookup(), Prim, record_stmt(), threeAddrNode::rhs1(), basic_type::size(), threeAddrNode::sizeof_type(), and Node::typ().

Referenced by Pointers::eval().

void constantAnalyzer::at_stmt_entry (  stmtLocation *    stmt,
pointerValue &    result
) 
 

Definition at line 950 of file constants.cc.

References _top, and pointerValue::constant_value.

Referenced by Pointers::analyze_procedure().

void constantAnalyzer::at_unary (  stmtLocation *    current,
stmtNode *    t,
pointerValue &    operand,
pointerValue &    result
) 
 

Definition at line 505 of file constants.cc.

References _bottom, _non_null, _top, Condition, pointerValue::constant_value, constant::eval(), Operator::id(), pointerValue::is_a_use, Operator::is_unary(), lookup(), record_stmt(), Operator::SIZEOF, ThreeAddr, and Node::typ().

Referenced by Pointers::analyze_procedure(), and Pointers::eval().

const constant* constantAnalyzer::bottom (    )  const [inline]
 

BOTTOM value.

Definition at line 133 of file constants.h.

Referenced by Pointers::analyze_procedure(), at_conservative_procedure_call(), and rebuild_flowvalue().

void constantAnalyzer::clear (    ) 
 

Clear.

Prepare for a new analysis.

Definition at line 62 of file constants.cc.

References _expr_values.

const constant * constantAnalyzer::evaluate_points_to (  const memoryblock_set &    points_to ) 
 

Evaluate points-to set.

Determine the constant value of a pointer by looking at what it points to. There are basically three cases: (1) it only points to the NULL object, in which case it is zero, (2) it points to heap objects, which might fail to be allocated, so the value is bottom, or (3) it points to regular variables, whose addresses cannot be zero, so the value is non-null.

Definition at line 395 of file constants.cc.

References _bottom, _non_null, _null, memoryBlock::is_heap_object(), lookup(), and memoryblock_set_cp.

Referenced by lookup_flowvalue(), and rebuild_flowvalue().

bool constantAnalyzer::has_truth_value (  const constant *    val,
bool &    value
) 
 

Check for truth value.

Return true if the given constant is true (including non-null).

Definition at line 83 of file constants.cc.

References _bottom, _non_null, _top, and constant::Boolean().

Referenced by Pointers::analyze_procedure(), and constantsChanger::at_conditiongoto().

bool constantAnalyzer::has_value (  const constant *    val )  [inline]
 

Has value.

Return true if the constant is not top, bottom, or non-null

Definition at line 139 of file constants.h.

Referenced by constantsChanger::at_id(), and constantsChanger::at_threeAddr().

const constant * constantAnalyzer::lookup (  const constant &    value ) 
 

Lookup a constant value.

All constants are stored in a set so that there is only one constant object for each unique value.

Definition at line 101 of file constants.cc.

References _bottom, _double_constants, _float_constants, _schar_constants, _sint_constants, _slong_constants, _sshort_constants, _uchar_constants, _uint_constants, _ulong_constants, _ushort_constants, constant::basic(), constant_set_p, basic_type::Double, basic_type::Float, basic_type::SChar, basic_type::SInt, basic_type::SLong, basic_type::SShort, basic_type::UChar, basic_type::UInt, basic_type::ULong, and basic_type::UShort.

Referenced by at_binary(), at_cast(), at_const(), at_sizeof(), at_unary(), evaluate_points_to(), and rebuild_flowvalue().

const constant * constantAnalyzer::lookup_expression (  exprNode *    expr ) 
 

Look up an expression.

Definition at line 436 of file constants.cc.

References _bottom, _expr_values, expr_value_map_p, and to_string().

Referenced by constantsChanger::at_id().

const constant * constantAnalyzer::lookup_flowvalue (  memoryDef *    def ) 
 

Lookup a variable value.

Look for the constant value associated with a specific def. Default is TOP if none is found.

Definition at line 167 of file constants.cc.

References _bottom, def, and evaluate_points_to().

Referenced by at_assignment(), at_merge(), at_self_assignment(), and rebuild_flowvalue().

const constant * constantAnalyzer::lookup_stmt (  stmtNode *    expr ) 
 

Definition at line 455 of file constants.cc.

References _bottom, _stmt_values, stmt_value_map_p, and to_string().

Referenced by constantsChanger::at_conditiongoto(), and constantsChanger::at_threeAddr().

const constant * constantAnalyzer::meet (  const constant *    one,
const constant *    two
) 
 

Meet function.

Definition at line 230 of file constants.cc.

References _bottom, _non_null, _top, and constant::is_zero().

Referenced by at_assignment(), at_merge(), at_self_assignment(), rebuild_flowvalue(), record_expression(), record_stmt(), and update_flowvalue().

void constantAnalyzer::print (  ostream &    o,
const constant *    val
)  [inline]
 

Definition at line 313 of file constants.h.

References constant::to_string().

const constant * constantAnalyzer::rebuild_flowvalue (  pointerValue &    pointer ) 
 

Rebuild the flow value.

Collect the current values of the given pointer using the meet function

Definition at line 276 of file constants.cc.

References _bottom, _top, pointerValue::blocks, bottom(), memoryBlock::current_use(), memoryBlock::decl(), declNode::decl_location(), def, declNode::ENUM, evaluate_points_to(), declNode::init(), pointerValue::is_address, lookup(), lookup_flowvalue(), meet(), memoryblock_set_p, memoryBlock::name(), to_string(), use, and exprNode::value().

Referenced by at_dereference(), at_field_access(), at_id(), at_index(), and at_self_assignment().

void constantAnalyzer::record_change (  memoryDef *    def )  [private]
 

Obsolete: Record a value change.

void constantAnalyzer::record_expression (  exprNode *    expr,
const constant *    val
) 
 

Record the value of an expression.

Definition at line 348 of file constants.cc.

References _expr_values, _top, expr_value_map_p, meet(), and to_string().

Referenced by at_cast(), at_dereference(), at_field_access(), at_id(), and at_index().

void constantAnalyzer::record_stmt (  stmtNode *    stmt,
const constant *    val
) 
 

Record the rhs value of an threeAddr.

Definition at line 367 of file constants.cc.

References _stmt_values, _top, meet(), stmt_value_map_p, and to_string().

Referenced by at_binary(), at_sizeof(), and at_unary().

void constantAnalyzer::set_null_object (  memoryBlock *    null_object )  [inline]
 

Set the null object.

The pointer analyzer needs to provide this so that we can properly handle null pointers as constants.

Definition at line 125 of file constants.h.

Referenced by Pointers::Pointers().

string constantAnalyzer::to_string (  const constant *    val )  [inline]
 

Definition at line 325 of file constants.h.

References constant::to_string().

Referenced by Pointers::analyze_procedure(), lookup_expression(), lookup_stmt(), rebuild_flowvalue(), record_expression(), record_stmt(), and update_flowvalue().

const constant* constantAnalyzer::top (    )  const [inline]
 

TOP value.

Definition at line 129 of file constants.h.

bool constantAnalyzer::update_flowvalue (  const constant *    val,
memoryDef *    def
) 
 

Update a variable value.

Don't record any TOP values (because lookup_flowvalue() will return TOP by default). Also, return a boolean indicating if the update resulted in a change.

Definition at line 191 of file constants.cc.

References _top, def, meet(), and to_string().

Referenced by at_assignment(), at_conservative_procedure_call(), at_merge(), at_parameter_pass(), and at_self_assignment().


Member Data Documentation

const constant* constantAnalyzer::_bottom [private]
 

Unique lattice bottom element.

Definition at line 91 of file constants.h.

Referenced by at_address(), at_assignment(), at_binary(), at_cast(), at_const(), at_sizeof(), at_unary(), evaluate_points_to(), has_truth_value(), lookup(), lookup_expression(), lookup_flowvalue(), lookup_stmt(), meet(), rebuild_flowvalue(), and ~constantAnalyzer().

TREE constant_set constantAnalyzer::_double_constants [private]
 

Definition at line 77 of file constants.h.

Referenced by lookup().

expr_value_map constantAnalyzer::_expr_values [private]
 

Record the value of each expression.

This ends up as the context insensitive information

Definition at line 101 of file constants.h.

Referenced by clear(), lookup_expression(), and record_expression().

TREE constant_set constantAnalyzer::_float_constants [private]
 

Definition at line 76 of file constants.h.

Referenced by lookup().

const constant* constantAnalyzer::_non_null [private]
 

Special non-null element.

Definition at line 95 of file constants.h.

Referenced by at_binary(), at_cast(), at_unary(), evaluate_points_to(), has_truth_value(), meet(), and ~constantAnalyzer().

REF memoryBlock* constantAnalyzer::_null [private]
 

Null object.

Keep this around so that we handle null pointers properly.

Definition at line 83 of file constants.h.

Referenced by evaluate_points_to().

TREE constant_set constantAnalyzer::_schar_constants [private]
 

The set of all constants.

This set ensures that each unique constant value is represented by exactly one constant object. It "owns" all of the constant values. All other data structures refer to these.

Definition at line 68 of file constants.h.

Referenced by lookup().

TREE constant_set constantAnalyzer::_sint_constants [private]
 

Definition at line 72 of file constants.h.

Referenced by lookup().

TREE constant_set constantAnalyzer::_slong_constants [private]
 

Definition at line 74 of file constants.h.

Referenced by lookup().

TREE constant_set constantAnalyzer::_sshort_constants [private]
 

Definition at line 70 of file constants.h.

Referenced by lookup().

stmt_value_map constantAnalyzer::_stmt_values [private]
 

Definition at line 102 of file constants.h.

Referenced by lookup_stmt(), and record_stmt().

const constant* constantAnalyzer::_top [private]
 

Unique lattice top element.

Definition at line 87 of file constants.h.

Referenced by at_assignment(), at_basicblock_entry(), at_binary(), at_cast(), at_merge(), at_parameter_pass(), at_self_assignment(), at_stmt_entry(), at_unary(), has_truth_value(), meet(), rebuild_flowvalue(), record_expression(), record_stmt(), update_flowvalue(), and ~constantAnalyzer().

TREE constant_set constantAnalyzer::_uchar_constants [private]
 

Definition at line 69 of file constants.h.

Referenced by lookup().

TREE constant_set constantAnalyzer::_uint_constants [private]
 

Definition at line 73 of file constants.h.

Referenced by lookup().

TREE constant_set constantAnalyzer::_ulong_constants [private]
 

Definition at line 75 of file constants.h.

Referenced by lookup().

TREE constant_set constantAnalyzer::_ushort_constants [private]
 

Definition at line 71 of file constants.h.

Referenced by lookup().


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

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