libFirm
Memory Disambiguator

A memory disambiguator checks whether 2 given SSA values representing addresses alias. More...

Typedefs

typedef ir_alias_relation(* DISAMBIGUATOR_FUNC )(const ir_node *adr1, const ir_mode *mode1, const ir_node *adr2, const ir_mode *mode2)
 A source language specific memory disambiguator function.

Enumerations

enum  ir_alias_relation { ir_no_alias, ir_may_alias, ir_sure_alias }
 The alias relation of two memory addresses. More...
enum  ir_entity_usage_computed_state { ir_entity_usage_not_computed, ir_entity_usage_computed }
 The state of the entity usage flags. More...
enum  ir_disambuigator_options {
  aa_opt_no_opt = 0, aa_opt_type_based = 1, aa_opt_byte_type_may_alias = 2, aa_opt_no_alias_args = 4,
  aa_opt_no_alias_args_global = 8, aa_opt_no_alias = 16, aa_opt_inherited = 128
}
 Possible options for the memory disambiguator. More...
enum  ir_storage_class_class_t {
  ir_sc_pointer = 0x0, ir_sc_globalvar = 0x1, ir_sc_localvar = 0x2, ir_sc_tls = 0x3,
  ir_sc_malloced = 0x4, ir_sc_globaladdr = 0x5, ir_sc_modifier_nottaken = 0x80, ir_sc_modifier_argument = 0x40,
  ir_sc_modifiers = ir_sc_modifier_nottaken | ir_sc_modifier_argument
}
 Classify storage locations. More...

Functions

ir_storage_class_class_t get_base_sc (ir_storage_class_class_t x)
 Returns the base storage class (ignore modifier)
ir_storage_class_class_t classify_pointer (const ir_node *irn, const ir_entity *ent)
 Classify a base pointer.
const char * get_ir_alias_relation_name (ir_alias_relation rel)
 Returns a human readable name for an alias relation.
ir_alias_relation get_alias_relation (const ir_node *adr1, const ir_mode *mode1, const ir_node *adr2, const ir_mode *mode2)
 Determine the alias relation between two addresses.
void set_language_memory_disambiguator (DISAMBIGUATOR_FUNC func)
 Sets a source language specific memory disambiguator function.
void mem_disambig_init (void)
 Initialize the relation cache.
ir_alias_relation get_alias_relation_ex (const ir_node *adr1, const ir_mode *mode1, const ir_node *adr2, const ir_mode *mode2)
 Determine the alias relation between two addresses and cache the result.
void mem_disambig_term (void)
 Free the relation cache.
void assure_irg_entity_usage_computed (ir_graph *irg)
 Assure that the entity usage flags have been computed for the given graph.
ir_entity_usage_computed_state get_irp_globals_entity_usage_state (void)
 Returns the current address taken state of the globals.
void set_irp_globals_entity_usage_state (ir_entity_usage_computed_state state)
 Sets the current address taken state of the globals.
void assure_irp_globals_entity_usage_computed (void)
 Assure that the address taken flag is computed for the global and TLS entities (variables).
unsigned get_irg_memory_disambiguator_options (const ir_graph *irg)
 Returns the memory disambiguator options for a graph.
void set_irg_memory_disambiguator_options (ir_graph *irg, unsigned options)
 Sets the memory disambiguator options for a graph.
void set_irp_memory_disambiguator_options (unsigned options)
 Sets the global disambiguator options for all graphs not having local options.
void mark_private_methods (void)
 Mark all private methods, i.e.
ir_prog_pass_tmark_private_methods_pass (const char *name)
 Creates an ir_prog pass for mark_private_methods().

Detailed Description

A memory disambiguator checks whether 2 given SSA values representing addresses alias.

Typedef Documentation

typedef ir_alias_relation(* DISAMBIGUATOR_FUNC)(const ir_node *adr1, const ir_mode *mode1, const ir_node *adr2, const ir_mode *mode2)

A source language specific memory disambiguator function.

Called by get_alias_relation().

Definition at line 93 of file irmemory.h.

Enumeration Type Documentation

The alias relation of two memory addresses.

Enumerator:
ir_no_alias 

No alias.

ir_may_alias 

Unknown state, may alias.

ir_sure_alias 

Sure alias.

Definition at line 42 of file irmemory.h.

Possible options for the memory disambiguator.

Enumerator:
aa_opt_no_opt 

no options: most conservative

aa_opt_type_based 

use type based alias analysis: strict typed source language

aa_opt_byte_type_may_alias 

if type based analysis is enabled: bytes types may alias other types

aa_opt_no_alias_args 

arguments do not alias each other but may alias global storage

aa_opt_no_alias_args_global 

arguments do not alias global storage

aa_opt_no_alias 

two addresses NEVER alias, use with CAUTION (gcc -fno-alias)

aa_opt_inherited 

only for implementation: options from a graph are inherited from global

Definition at line 55 of file irmemory.h.

The state of the entity usage flags.

Definition at line 49 of file irmemory.h.

Classify storage locations.

Except ir_sc_pointer they are all disjoint. ir_sc_pointer potentially aliases all classes which don't have a NOTTAKEN modifier.

Enumerator:
ir_sc_pointer 

generic pointer, may be anything

ir_sc_globalvar 

an address of a global variable

ir_sc_localvar 

an address of a local variable or method argument

ir_sc_tls 

an address of a thread local storage variable

ir_sc_malloced 

an allocated heap address

ir_sc_globaladdr 

a constant address of something

ir_sc_modifier_nottaken 

if set, the address of the variable was not taken

ir_sc_modifier_argument 

if set pointer was a function argument

Definition at line 72 of file irmemory.h.

Function Documentation

void assure_irg_entity_usage_computed ( ir_graph irg)

Assure that the entity usage flags have been computed for the given graph.

This analysis computes the entity usage state for all local variables.

Even then the information is not cleaned from the variables, call assure_irg_entity_usage_computed() again for recomputation.

void assure_irp_globals_entity_usage_computed ( void  )

Assure that the address taken flag is computed for the global and TLS entities (variables).

This is an interprocedural analysis that computes the address_taken state for all global and TLS variables.

Note that this is a conservative estimation that by no Firm transformation can be invalidated, so it's only recomputed if manually triggered by calling set_irp_globals_entity_usage_state(ir_entity_usage_not_computed). Even then the information is not cleaned from the variables, call assure_irp_globals_entity_usage_computed() again for recomputation.

ir_storage_class_class_t classify_pointer ( const ir_node irn,
const ir_entity ent 
)

Classify a base pointer.

Parameters
irnthe node representing the base address
entthe base entity of the base address iff any
ir_alias_relation get_alias_relation ( const ir_node adr1,
const ir_mode mode1,
const ir_node adr2,
const ir_mode mode2 
)

Determine the alias relation between two addresses.

Parameters
adr1The first address.
mode1The mode of the first memory access.
adr2The second address.
mode2The mode of the second memory access.

The memory disambiguator tries to determine the alias state between two memory addresses. The following rules are used:

  • different variable from the same segment never alias (R1 a)
  • variables from different segments never alias when:
    • a global variable and a local one never alias (R1 b)
    • a global variable and a TLS one never alias (R1 c)
    • a local variable and a TLS one never alias (R1 d)
    • a local variable and a parameter never alias (R1 e)
    • a global variable and the result of a malloc routine never alias (R1 f)
    • a local variable and the result of a malloc routine never alias (R1 g)
    • a TLS variable and the result of a malloc routine never alias (R1 h)
    • a parameter and the result of a malloc routine (obtained in the same routine as the parameter) never alias (R1 i)
  • two different variables never alias (R2)
  • if one is a variable whose address has never been taken there is no alias (R3)
  • if two memory addresses have the same base and their offsets do not describe overlapping regions there is no alias (R4)
  • if opt_strong_typed is set and both addresses describe entities, different types never alias (R5)

If none of these rules apply, the points-to framework must be interrogated to detect the alias relation.

ir_alias_relation get_alias_relation_ex ( const ir_node adr1,
const ir_mode mode1,
const ir_node adr2,
const ir_mode mode2 
)

Determine the alias relation between two addresses and cache the result.

Parameters
adr1The first address.
mode1The mode of the first memory access.
adr2The second address.
mode2The mode of the second memory access.
See Also
get_alias_relation()

Returns the base storage class (ignore modifier)

const char* get_ir_alias_relation_name ( ir_alias_relation  rel)

Returns a human readable name for an alias relation.

unsigned get_irg_memory_disambiguator_options ( const ir_graph irg)

Returns the memory disambiguator options for a graph.

Parameters
irgthe graph
ir_entity_usage_computed_state get_irp_globals_entity_usage_state ( void  )

Returns the current address taken state of the globals.

void mark_private_methods ( void  )

Mark all private methods, i.e.

those of which all call sites are known. We use a very convervative estimation yet: If the address of a method is never taken AND its visibility is visibility_local, then it's private.

ir_prog_pass_t* mark_private_methods_pass ( const char *  name)

Creates an ir_prog pass for mark_private_methods().

Parameters
namethe name of this pass or NULL
Returns
the newly created ir_prog pass
void mem_disambig_init ( void  )

Initialize the relation cache.

void mem_disambig_term ( void  )

Free the relation cache.

void set_irg_memory_disambiguator_options ( ir_graph irg,
unsigned  options 
)

Sets the memory disambiguator options for a graph.

Parameters
irgthe graph
optionsa set of options
void set_irp_globals_entity_usage_state ( ir_entity_usage_computed_state  state)

Sets the current address taken state of the globals.

Parameters
statethe new state
void set_irp_memory_disambiguator_options ( unsigned  options)

Sets the global disambiguator options for all graphs not having local options.

Parameters
optionsa set of options
void set_language_memory_disambiguator ( DISAMBIGUATOR_FUNC  func)

Sets a source language specific memory disambiguator function.

Parameters
funcThe callback.