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  

memoryModel Class Reference

#include <memorymodel.h>

List of all members.

Public Types

typedef pair< Location *,
declNode * > 
memorymodel_key
typedef map< memorymodel_key,
memoryBlock * > 
memorymodel_map
typedef memorymodel_map::iterator memorymodel_map_p
typedef memorymodel_map::const_iterator memorymodel_map_cp
typedef map< procNode *, memorymodel_mapproc_memorymodel_map
typedef proc_memorymodel_map::iterator proc_memorymodel_map_p
typedef proc_memorymodel_map::const_iterator proc_memorymodel_map_cp
typedef pair< stmtNode *,
declNode * > 
ci_memorymodel_key
typedef map< ci_memorymodel_key,
memoryBlock * > 
ci_memorymodel_map
typedef ci_memorymodel_map::iterator ci_memorymodel_map_p
typedef ci_memorymodel_map::const_iterator ci_memorymodel_map_cp
typedef map< constNode *,
memoryBlock * > 
string_constant_map
typedef string_constant_map::iterator string_constant_map_p

Public Member Functions

 memoryModel ()
 Create a new memory model.

 ~memoryModel ()
 Delete the memory model.

void clear ()
 Clear.

int size ()
 Get the number of memory blocks.

memoryBlocknull () const
 Get the list of memoryBlocks Return the null object.

UnificationBasedPtrunification () const
 Get unification-based analyzer.

void unification (UnificationBasedPtr *u)
 Set unification-based analyzer.

memoryBlocklookup (Location *location, declNode *decl)
 Look up a memoryBLock.

memoryBlocklookup (stmtNode *location, declNode *decl)
 Look up a CI memoryBLock.

memoryBlocklookup_variable (Location *location, declNode *decl, procNode *local_to)
 Look up a variable.

memoryBlocklookup_heap_object (const string &name, stmtLocation *allocation_site, stmtNode *allocation_stmt, declNode *decl, bool synthetic_decl)
 Look up or create a heap object.

memoryBlocklookup_string_constant (constNode *the_string)
 Look up string constant.

memoryBlockgenerate_su_field (const string &field_name, declNode *field_decl, memoryBlock *container)
 Generate a struct/union field.

void update_def_use_chains ()
 Update def-use chains.

int counter ()
 Counter.

void stats (ostream &out)
 Print statistics.

void print (ostream &o) const

Static Public Member Functions

bool is_in_non_unify_list (UnifyTypes &non_unify_types, UnifyType *obj)
 Find in unify list.


Private Member Functions

memoryBlockcreate_memory_object (Location *location, declNode *decl, bool synthetic_decl, memoryBlock *container, procNode *local_to, declNode *org_field_decl=0, bool is_alloc=false, bool is_array_elt=false)
 Create a new memory object.

memoryBlockcreate_memory_object (stmtNode *location, declNode *decl, bool synthetic_decl, memoryBlock *container, procNode *local_to, bool is_alloc=false)
 Create a CI memory block.

void generate_array_elements_for (memoryBlock *array_object)
 Generate array elements.

void initialize_struct (memoryBlock *struct_object, sueNode *sue_type, expr_list &inits)
 Initialize struct.


Private Attributes

TREE proc_memorymodel_map _memory_blocks
 the memoryBlocks

TREE ci_memorymodel_map _ci_memory_blocks
 Context-insensitive memory.

string_constant_map _string_constants
 String constants.

int Counter
 a counter to generate unique names

memoryBlockNull
 special "null" object

memoryBlock_string_constant
 String constant object.

UnificationBasedPtr_unification_based
 Unification-based analyzer.

map< declNode *, declNode * > _copy_decl
 Remember where a copy declaration originates from.


Member Typedef Documentation

typedef pair< stmtNode *, declNode * > memoryModel::ci_memorymodel_key
 

Definition at line 61 of file memorymodel.h.

Referenced by create_memory_object(), and lookup().

typedef map< ci_memorymodel_key , memoryBlock *> memoryModel::ci_memorymodel_map
 

Definition at line 63 of file memorymodel.h.

typedef ci_memorymodel_map::const_iterator memoryModel::ci_memorymodel_map_cp
 

Definition at line 65 of file memorymodel.h.

Referenced by print().

typedef ci_memorymodel_map::iterator memoryModel::ci_memorymodel_map_p
 

Definition at line 64 of file memorymodel.h.

Referenced by clear(), lookup(), update_def_use_chains(), and ~memoryModel().

typedef pair< Location *, declNode * > memoryModel::memorymodel_key
 

Definition at line 51 of file memorymodel.h.

Referenced by create_memory_object(), and lookup().

typedef map< memorymodel_key , memoryBlock *> memoryModel::memorymodel_map
 

Definition at line 53 of file memorymodel.h.

Referenced by clear(), create_memory_object(), lookup(), print(), size(), stats(), update_def_use_chains(), and ~memoryModel().

typedef memorymodel_map::const_iterator memoryModel::memorymodel_map_cp
 

Definition at line 55 of file memorymodel.h.

Referenced by print(), and stats().

typedef memorymodel_map::iterator memoryModel::memorymodel_map_p
 

Definition at line 54 of file memorymodel.h.

Referenced by clear(), lookup(), update_def_use_chains(), and ~memoryModel().

typedef map< procNode *, memorymodel_map > memoryModel::proc_memorymodel_map
 

Definition at line 57 of file memorymodel.h.

typedef proc_memorymodel_map::const_iterator memoryModel::proc_memorymodel_map_cp
 

Definition at line 59 of file memorymodel.h.

Referenced by print().

typedef proc_memorymodel_map::iterator memoryModel::proc_memorymodel_map_p
 

Definition at line 58 of file memorymodel.h.

Referenced by clear(), size(), stats(), update_def_use_chains(), and ~memoryModel().

typedef map< constNode *, memoryBlock *> memoryModel::string_constant_map
 

Definition at line 68 of file memorymodel.h.

typedef string_constant_map::iterator memoryModel::string_constant_map_p
 

Definition at line 69 of file memorymodel.h.

Referenced by lookup_string_constant().


Constructor & Destructor Documentation

memoryModel::memoryModel  
 

Create a new memory model.

Definition at line 47 of file memorymodel.cc.

References Null, memoryBlock::set_write_protected(), and pointerOptions::Unify_objects.

memoryModel::~memoryModel  
 

Delete the memory model.

This also deallocates all memoryBlock objects created in this model.

Definition at line 73 of file memorymodel.cc.

References _ci_memory_blocks, _memory_blocks, _unification_based, UnifyType::block(), ci_memorymodel_map_p, memorymodel_map, memorymodel_map_p, Null, proc_memorymodel_map_p, and UnificationBasedPtr::proctype().


Member Function Documentation

void memoryModel::clear  
 

Clear.

Visit all memoryBlocks and call clear, preparing for reanalysis.

Definition at line 113 of file memorymodel.cc.

References _ci_memory_blocks, _memory_blocks, ci_memorymodel_map_p, memoryBlock::clear(), memorymodel_map, memorymodel_map_p, Null, and proc_memorymodel_map_p.

Referenced by Pointers::analyze().

int memoryModel::counter   [inline]
 

Counter.

Get the counter and increment it.

Definition at line 231 of file memorymodel.h.

Referenced by Pointers::at_allocation().

memoryBlock * memoryModel::create_memory_object stmtNode   location,
declNode   decl,
bool    synthetic_decl,
memoryBlock   container,
procNode   local_to,
bool    is_alloc = false
[private]
 

Create a CI memory block.

Definition at line 659 of file memorymodel.cc.

References _ci_memory_blocks, _unification_based, UnifyType::block(), ci_memorymodel_key, declNode::decl_location(), UnificationBasedPtr::ecr(), Func, is_in_non_unify_list(), memoryBlock::local_to(), typeNode::no_tdef_type(), declNode::no_tdef_type(), declNode::PROC, Ptr, Node::typ(), Unify_ECR::type(), pointerOptions::Unification, and memoryBlock::unifyType().

memoryBlock * memoryModel::create_memory_object Location   location,
declNode   decl,
bool    synthetic_decl,
memoryBlock   container,
procNode   local_to,
declNode   org_field_decl = 0,
bool    is_alloc = false,
bool    is_array_elt = false
[private]
 

Create a new memory object.

Create a new object that represents some entity in memory. These objects are indexed by the location and Node given. For regular variables, this Node will be the same as the declNode. However, for heap objects and strings constants, we will use other kinds of nodes to distinguish them. In addition, we need the declaration node for built-in arrays, so that we can create the objects to represent the elements.

This is the only function that creates new memoryBlocks and stores them in the memory model.

The synthetic_decl flag indicates that the declNode passed was created just to distinguish this object.

Definition at line 510 of file memorymodel.cc.

References _memory_blocks, _unification_based, UnifyType::block(), declNode::decl_location(), UnificationBasedPtr::ecr(), UnificationBasedPtr::ecrDeref(), UnificationBasedPtr::ecrField(), UnificationBasedPtr::ensure_no_bottom(), Func, UnifyType::is_bottom(), is_in_non_unify_list(), UnificationBasedPtr::isField(), Location::kind(), memoryBlock::local_to(), memorymodel_key, memorymodel_map, memoryBlock::name(), declNode::name(), typeNode::no_tdef_type(), declNode::no_tdef_type(), procLocation::proc(), declNode::PROC, Location::procedure(), Ptr, pointerOptions::Show_stack, Location::Statement, ThreeAddr, Node::typ(), Unify_ECR::type(), pointerOptions::Unification, memoryBlock::unifyType(), and pointerOptions::Verbose.

Referenced by generate_array_elements_for(), generate_su_field(), lookup_heap_object(), and lookup_variable().

void memoryModel::generate_array_elements_for memoryBlock   array_object [private]
 

Generate array elements.

For built-in arrays, we generate a single object for each dimension of the array. For example,

int A[3][4][5]

Results in

A --> A_el_1 --> A_el_2 --> A_el_3

That way A[1][3] evaluates to A_el_2, as does *(A[1]) and **A.

This structure is represented by storing the element as a field of the array object. We then add a special def that also causes the array to point-to it's element.

Definition at line 744 of file memorymodel.cc.

References _copy_decl, _unification_based, Operator::ADDRESS, Array, UnifyType::block(), ref_clone_changer::clone(), create_memory_object(), memoryBlock::current_use(), idNode::decl(), memoryBlock::decl(), def, memoryBlock::def_at(), UnificationBasedPtr::ecrDeref(), unaryNode::expr(), expr_list, expr_list_p, initializerNode::exprs(), Func, Operator::id(), Id, declNode::init(), initialize_struct(), Initializer, vector_set< memoryBlock * >::insert(), lookup_variable(), memoryBlock::name(), declNode::name(), typeNode::no_tdef_type(), declNode::no_tdef_type(), declNode::NONE, OBJECT, UnifyType::objTyp(), unaryNode::op(), memoryDef::points_to(), memoryUse::reaching_def(), memoryBlock::set_array_element(), memoryBlock::set_flow_sensitivity(), memoryBlock::set_indexed(), memoryBlock::set_unification(), SIMPLE, Struct, Node::typ(), Unify_ECR::type(), declNode::type(), typeNode::type(), Unary, pointerOptions::Unification, memoryBlock::unifyType(), and memoryBlock::use_at().

Referenced by generate_su_field(), and lookup_variable().

memoryBlock * memoryModel::generate_su_field const string &    field_name,
declNode   field_decl,
memoryBlock   container
 

Generate a struct/union field.

Given a field declaration and the container object, generate an object for the field. We use the type information from the field declaration to detect and handle fields that are arrays.

The field_decl can be ommited.

The method actually generates a new unique declNode for the object.

Definition at line 408 of file memorymodel.cc.

References _copy_decl, _unification_based, Array, ref_clone_changer::clone(), memoryBlock::container(), create_memory_object(), memoryBlock::decl(), UnificationBasedPtr::ecr(), generate_array_elements_for(), memoryBlock::name(), declNode::name(), declNode::NONE, memoryBlock::set_flow_sensitivity(), memoryBlock::set_unification(), declNode::SU, declNode::type(), pointerOptions::Unification, memoryBlock::unifyType(), and pointerOptions::Verbose.

Referenced by memoryBlock::dot(), and memoryBlock::get_allocation_object().

void memoryModel::initialize_struct memoryBlock   struct_object,
sueNode   sue_type,
expr_list   inits
[private]
 

Initialize struct.

Assign static initializers to a newly created struct.

Definition at line 1093 of file memorymodel.cc.

References _unification_based, Operator::ADDRESS, UnifyType::block(), memoryBlock::current_use(), idNode::decl(), decl_list, decl_list_p, def, memoryBlock::def_at(), memoryBlock::dot(), UnificationBasedPtr::ecrDeref(), unaryNode::expr(), expr_list, expr_list_p, initializerNode::exprs(), suespecNode::fields(), Func, Operator::id(), Id, Initializer, vector_set< memoryBlock * >::insert(), lookup_variable(), declNode::name(), memoryBlock::name(), OBJECT, UnifyType::objTyp(), unaryNode::op(), memoryDef::points_to(), memoryUse::reaching_def(), SIMPLE, sueNode::spec(), Node::typ(), Unify_ECR::type(), declNode::type(), Unary, pointerOptions::Unification, memoryBlock::unifyType(), and memoryBlock::use_at().

Referenced by generate_array_elements_for(), and lookup_variable().

bool memoryModel::is_in_non_unify_list UnifyTypes   non_unify_types,
UnifyType   obj
[static]
 

Find in unify list.

Return true if the block is identified in the given list.

Definition at line 946 of file memorymodel.cc.

References UnificationBasedPtr::reachable(), and UnifyTypes.

Referenced by create_memory_object(), and memoryBlock::set_unification().

memoryBlock * memoryModel::lookup stmtNode   location,
declNode   decl
 

Look up a CI memoryBLock.

Look up a memoryblock, returning "null" if it's not found.

Definition at line 935 of file memorymodel.cc.

References _ci_memory_blocks, ci_memorymodel_key, and ci_memorymodel_map_p.

memoryBlock * memoryModel::lookup Location   location,
declNode   decl
 

Look up a memoryBLock.

Look up a memoryblock, returning "null" if it's not found.

Definition at line 917 of file memorymodel.cc.

References _memory_blocks, memorymodel_key, memorymodel_map, memorymodel_map_p, procLocation::proc(), and Location::procedure().

Referenced by lookup_heap_object(), and lookup_variable().

memoryBlock * memoryModel::lookup_heap_object const string &    name,
stmtLocation   allocation_site,
stmtNode   allocation_stmt,
declNode   decl,
bool    synthetic_decl
 

Look up or create a heap object.

Lookup a heap object based on the given location and Node key. If it's not found, create a new one. The declaration can be NULL, in which case a synthetic declNode will be created using the name.

Definition at line 239 of file memorymodel.cc.

References _unification_based, create_memory_object(), lookup(), and pointerOptions::Unification.

Referenced by Pointers::at_allocation().

memoryBlock * memoryModel::lookup_string_constant constNode   the_string
 

Look up string constant.

String constants are indexed by their constNode.

Definition at line 307 of file memorymodel.cc.

References _string_constant, _string_constants, _unification_based, UnifyType::block(), Counter, declNode::NONE, memoryBlock::set_flow_insensitive(), memoryBlock::set_write_protected(), UnificationBasedPtr::string_alpha(), string_constant_map_p, Alpha::tao(), Unify_ECR::type(), and memoryBlock::unifyType().

Referenced by Pointers::eval().

memoryBlock * memoryModel::lookup_variable Location   location,
declNode   decl,
procNode   local_to
 

Look up a variable.

Create the memory block if it's not found. Also, when creating a new memory block, if it's a built-in array, then create objects for the elements.

Definition at line 155 of file memorymodel.cc.

References _unification_based, Array, declNode::BLOCK, create_memory_object(), declNode::decl_location(), expr_list, declNode::FORMAL, generate_array_elements_for(), declNode::init(), initialize_struct(), lookup(), declNode::no_tdef_type(), declNode::STATIC, declNode::storage_class(), Struct, Node::typ(), and pointerOptions::Unification.

Referenced by UnificationBasedPtr::createProcBlock(), Pointers::eval(), generate_array_elements_for(), initialize_struct(), Pointers::pass_parameters(), Pointers::record_external_inputs_and_outputs(), and Pointers::setup_va_list_variables().

memoryBlock* memoryModel::null   const [inline]
 

Get the list of memoryBlocks Return the null object.

Definition at line 148 of file memorymodel.h.

Referenced by Pointers::conservative_procedure_call(), Pointers::dot_operator(), Pointers::Pointers(), Pointers::reachable_blocks(), and Pointers::star_operator().

void memoryModel::print ostream &    o const
 

Definition at line 1069 of file memorymodel.cc.

References _ci_memory_blocks, _memory_blocks, ci_memorymodel_map_cp, memorymodel_map, memorymodel_map_cp, and proc_memorymodel_map_cp.

Referenced by Pointers::uses_and_defs().

int memoryModel::size  
 

Get the number of memory blocks.

Definition at line 135 of file memorymodel.cc.

References _memory_blocks, memorymodel_map, proc_memorymodel_map_p, and size().

Referenced by size().

void memoryModel::stats ostream &    out
 

Print statistics.

Definition at line 993 of file memorymodel.cc.

References _ci_memory_blocks, _memory_blocks, memorymodel_map, memorymodel_map_cp, proc_memorymodel_map_p, and memoryBlock::stats().

Referenced by Pointers::stats().

void memoryModel::unification UnificationBasedPtr   u [inline]
 

Set unification-based analyzer.

Definition at line 156 of file memorymodel.h.

UnificationBasedPtr* memoryModel::unification   const [inline]
 

Get unification-based analyzer.

Definition at line 152 of file memorymodel.h.

Referenced by memoryBlock::dot(), Pointers::run_unification(), and Pointers::use_unification_analyzer().

void memoryModel::update_def_use_chains  
 

Update def-use chains.

At the end of pointer analysis, call this method to populate the definition uses on each memoryDef. Only call this once!

Definition at line 959 of file memorymodel.cc.

References _ci_memory_blocks, _memory_blocks, ci_memorymodel_map_p, memorymodel_map, memorymodel_map_p, and proc_memorymodel_map_p.

Referenced by Pointers::analyze().


Member Data Documentation

TREE ci_memorymodel_map memoryModel::_ci_memory_blocks [private]
 

Context-insensitive memory.

We use this map to store memoryBlocks that are indexed by the stmtNode, not the location. This is only used in Context_insensitive_memory mode.

Definition at line 88 of file memorymodel.h.

Referenced by clear(), create_memory_object(), lookup(), print(), stats(), update_def_use_chains(), and ~memoryModel().

map<declNode*,declNode*> memoryModel::_copy_decl [private]
 

Remember where a copy declaration originates from.

Definition at line 116 of file memorymodel.h.

Referenced by generate_array_elements_for(), and generate_su_field().

TREE proc_memorymodel_map memoryModel::_memory_blocks [private]
 

the memoryBlocks

All memoryBlocks are stored and managed by the memoryModel object. They are indexed by combining their declaration with a program location. A synthetic declaration is generated for dynamic objects.

Definition at line 80 of file memorymodel.h.

Referenced by clear(), create_memory_object(), lookup(), print(), size(), stats(), update_def_use_chains(), and ~memoryModel().

memoryBlock* memoryModel::_string_constant [private]
 

String constant object.

When we have the one-string-constant option trurned on, this holds a pointer to that object.

Definition at line 110 of file memorymodel.h.

Referenced by lookup_string_constant().

string_constant_map memoryModel::_string_constants [private]
 

String constants.

Create a separate repository of string constants, indexed by their constNodes

Definition at line 95 of file memorymodel.h.

Referenced by lookup_string_constant().

UnificationBasedPtr* memoryModel::_unification_based [private]
 

Unification-based analyzer.

Definition at line 113 of file memorymodel.h.

Referenced by create_memory_object(), generate_array_elements_for(), generate_su_field(), initialize_struct(), lookup_heap_object(), lookup_string_constant(), lookup_variable(), and ~memoryModel().

int memoryModel::Counter [private]
 

a counter to generate unique names

Definition at line 99 of file memorymodel.h.

Referenced by lookup_string_constant().

memoryBlock* memoryModel::Null [private]
 

special "null" object

Definition at line 103 of file memorymodel.h.

Referenced by clear(), memoryModel(), and ~memoryModel().


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

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