libFirm
Type System

Datastructure to hold type information. More...

Modules

 Reverse Type Edges
 Trouts list all uses of types and entities.
 Type Opcodes
 This module specifies the kinds of types available in firm.
 Class
 If the type opcode is set to type_class the type represents class types.
 Struct
 A struct type represents aggregate types that consist of a list of fields.
 Union
 The union type represents union types.
 Method
 A method type represents a method, function or procedure type.
 Array
 The array type represents rectangular multi dimensional arrays.
 Enumeration
 Enumeration types need not necessarily be represented explicitly by Firm types, as the frontend can lower them to integer constants as well.
 Pointer
 Pointer types:
 Primitive
 Primitive types are types that represent atomic data values that map directly to modes.
 None
 This type is an auxiliary type dedicated to support type analyses.
 Code
 Unknown
 This type is an auxiliary type dedicated to support type analyses.
 Compound
 Frame
 Traversing

Macros

#define is_SuperClass_of(high, low)   is_SubClass_of(low, high)
 Returns true if high is superclass of low.
#define is_SuperClass_ptr_of(low, high)   is_SubClass_ptr_of(high, low)
 Superclass check for pointers to classes.

Typedefs

typedef struct ir_type ir_type
 Type.
typedef identmangle_inherited_name_func (const ir_entity *ent, const ir_type *clss)
 Type of argument functions for inheritance resolver.

Enumerations

enum  inh_transitive_closure_state { inh_transitive_closure_none, inh_transitive_closure_valid, inh_transitive_closure_invalid, inh_transitive_closure_max }
 The state of the transitive closure. More...
enum  ir_class_cast_state { ir_class_casts_any = 0, ir_class_casts_transitive = 1, ir_class_casts_normalized = 2, ir_class_casts_state_max }
 The state of Cast operations that cast class types or pointers to class types. More...
enum  ir_type_state { layout_undefined, layout_fixed }
 The state of the type layout. More...

Functions

int is_SubClass_of (ir_type *low, ir_type *high)
 Returns true if low is subclass of high.
int is_SubClass_ptr_of (ir_type *low, ir_type *high)
 Subclass check for pointers to classes.
int is_overwritten_by (ir_entity *high, ir_entity *low)
 Returns true if high is (transitive) overwritten by low.
ir_entityresolve_ent_polymorphy (ir_type *dynamic_class, ir_entity *static_ent)
 Resolve polymorphism in the inheritance relation.
identdefault_mangle_inherited_name (const ir_entity *ent, const ir_type *clss)
 Default name mangling for inherited entities.
void resolve_inheritance (mangle_inherited_name_func *mfunc)
 Resolve implicit inheritance.
void set_irp_inh_transitive_closure_state (inh_transitive_closure_state s)
 Sets the transitive closure of sub/superclass state for the whole program.
void invalidate_irp_inh_transitive_closure_state (void)
 Sets the transitive closure of sub/superclass state for the whole program to inh_transitive_closure_invalid.
inh_transitive_closure_state get_irp_inh_transitive_closure_state (void)
 Returns the transitive closure of sub/superclass state for the whole program.
void compute_inh_transitive_closure (void)
 Compute transitive closure of the subclass/superclass and overwrites/overwrittenby relation.
void free_inh_transitive_closure (void)
 Free memory occupied by the transitive closure information.
ir_typeget_class_trans_subtype_first (const ir_type *tp)
 Start iteration over all transitive subtypes of tp.
ir_typeget_class_trans_subtype_next (const ir_type *tp)
 Returns next type in a subtype iteration started by get_class_trans_subtype_first()
int is_class_trans_subtype (const ir_type *tp, const ir_type *subtp)
 Check if subtp is a subtype of tp.
ir_typeget_class_trans_supertype_first (const ir_type *tp)
 Start iteration over all transitive supertypes of tp.
ir_typeget_class_trans_supertype_next (const ir_type *tp)
 Returns next type in a supertype iteration started by get_class_trans_supertype_first()
ir_entityget_entity_trans_overwrittenby_first (const ir_entity *ent)
 Start iteration over all entities that transitive overwrite entity ent.
ir_entityget_entity_trans_overwrittenby_next (const ir_entity *ent)
 Returns next entity in a overwrittenby iteration started by get_entity_trans_overwrittenby_first()
ir_entityget_entity_trans_overwrites_first (const ir_entity *ent)
 Start iteration over all transitive overwritten entities, overwritten by entity ent.
ir_entityget_entity_trans_overwrites_next (const ir_entity *ent)
 Returns next entity in a overwrites iteration started by get_entity_trans_overwrites_first()
void set_irg_class_cast_state (ir_graph *irg, ir_class_cast_state state)
 Sets class cast state for graph irg to state.
ir_class_cast_state get_irg_class_cast_state (const ir_graph *irg)
 Returns class cast state for graph irg.
void set_irp_class_cast_state (ir_class_cast_state state)
 Sets class cast state for the whole program to state.
ir_class_cast_state get_irp_class_cast_state (void)
 Returns class cast state for the whole program.
int check_type (const ir_type *tp)
 Checks a type.
int tr_verify (void)
 Walks the type information and performs a set of sanity checks.
void free_type (ir_type *tp)
 Frees the memory used by the type.
const tp_opget_type_tpop (const ir_type *tp)
 Returns type opcode of type tp.
identget_type_tpop_nameid (const ir_type *tp)
 Returns name identifier of type opcode of type tp.
const char * get_type_tpop_name (const ir_type *tp)
 Returns name of type opcode of type tp.
tp_opcode get_type_tpop_code (const ir_type *tp)
 Returns opcode of type opcode of type tp.
void ir_print_type (char *buffer, size_t buffer_size, const ir_type *tp)
 construct a string representing the type.
const char * get_type_state_name (ir_type_state s)
 Returns a human readable string for the enum entry.
ir_type_state get_type_state (const ir_type *tp)
 Returns the type layout state of a type.
void set_type_state (ir_type *tp, ir_type_state state)
 Sets the type layout state of a type.
ir_modeget_type_mode (const ir_type *tp)
 Returns the mode of a type.
void set_type_mode (ir_type *tp, ir_mode *m)
 Sets the mode of a type.
unsigned get_type_size_bytes (const ir_type *tp)
 Returns the size of a type in bytes.
void set_type_size_bytes (ir_type *tp, unsigned size)
 Sets the size of a type in bytes.
unsigned get_type_alignment_bytes (ir_type *tp)
 Returns the alignment of a type in bytes.
void set_type_alignment_bytes (ir_type *tp, unsigned align)
 Sets the alignment of a type in bytes.
ir_visited_t get_type_visited (const ir_type *tp)
 Returns the visited counter of a type.
void set_type_visited (ir_type *tp, ir_visited_t num)
 Sets the visited counter of a type to num.
void mark_type_visited (ir_type *tp)
 Sets visited field in type to type_visited.
int type_visited (const ir_type *tp)
 Returns non-zero if the type is already visited.
int type_not_visited (const ir_type *tp)
 Returns non-zero if the type is not yet visited.
void * get_type_link (const ir_type *tp)
 Returns the associated link field of a type.
void set_type_link (ir_type *tp, void *l)
 Sets the associated link field of a type.
void inc_master_type_visited (void)
 Increments type visited reference counter by one.
void set_master_type_visited (ir_visited_t val)
 Sets type visited reference counter.
ir_visited_t get_master_type_visited (void)
 Returns type visited reference counter.
void set_type_dbg_info (ir_type *tp, type_dbg_info *db)
 Sets the debug information of a type.
type_dbg_infoget_type_dbg_info (const ir_type *tp)
 Returns the debug information of a type.
int is_type (const void *thing)
 Checks whether a pointer points to a type.
long get_type_nr (const ir_type *tp)
 Outputs a unique number for this type if libfirm is compiled for debugging, (configure with –enable-debug) else returns the address of the type cast to long.
int equal_type (ir_type *typ1, ir_type *typ2)
 Checks whether two types are structurally equal.
int smaller_type (ir_type *st, ir_type *lt)
 Checks whether two types are structural comparable.
int is_atomic_type (const ir_type *tp)
 Checks whether a type is atomic.

Detailed Description

Datastructure to hold type information.

This module supplies a datastructure to represent all types known in the compiled program. This includes types specified in the program as well as types defined by the language. In the view of the intermediate representation there is no difference between these types. Finally it specifies some auxiliary types.

There exist several kinds of types, arranged by the structure of the type. A type is described by a set of attributes. Some of these attributes are common to all types, others depend on the kind of the type.

Types are different from the modes defined in irmode: Types are on the level of the programming language, modes at the level of the target processor.

Macro Definition Documentation

#define is_SuperClass_of (   high,
  low 
)    is_SubClass_of(low, high)

Returns true if high is superclass of low.

Low is a subclass of high if low == high or if low is a subclass of a subclass of high. I.e, we search in all subtypes of high for low. @@ this can be implemented more efficient if we know the set of all subclasses of high.

Definition at line 856 of file typerep.h.

#define is_SuperClass_ptr_of (   low,
  high 
)    is_SubClass_ptr_of(high, low)

Superclass check for pointers to classes.

Dereferences at both types the same amount of pointer types (as many as possible). If the remaining types are both class types and superclasses, returns true, else false. Can also be called with two class types.

Definition at line 864 of file typerep.h.

Typedef Documentation

typedef struct ir_type ir_type

Type.

Definition at line 84 of file firm_types.h.

typedef ident* mangle_inherited_name_func(const ir_entity *ent, const ir_type *clss)

Type of argument functions for inheritance resolver.

Parameters
entThe entity in the super type that will be overwritten by the newly generated entity, for which this name is used.
clssThe class type in which the new entity will be placed.

Definition at line 893 of file typerep.h.

Enumeration Type Documentation

The state of the transitive closure.

Enumerator:
inh_transitive_closure_none 

Closure is not computed, can not be accessed.

inh_transitive_closure_valid 

Closure computed and valid.

inh_transitive_closure_invalid 

Closure invalid, but can be accessed.

inh_transitive_closure_max 

Invalid value.

Definition at line 931 of file typerep.h.

The state of Cast operations that cast class types or pointers to class types.

The state expresses, how far Cast operations conform with the class hierarchy.

class A {} class B1 extends A {} class B2 extends A {} class C extends B1 {} normalized: Cast operations conform with the inheritance relation. I.e., the type of the operand of a Cast is either a super= or a sub- type of the type casted to. Example: (A)((B2) (new C())). transitive: Cast operations conform with the transitive inheritance relation. Example: (A)(new C()). any: Cast operations do not conform with the transitive inheritance relation. Example: (B2)(new B1())

Flags for class cast state.

The state in irp is always smaller or equal to the state of any irg.

We rely on the ordering of the enum.

Enumerator:
ir_class_casts_any 

There are class casts that do not cast in conformance with the class hierarchy.

@@ So far this does not happen in Firm.

ir_class_casts_transitive 

Class casts conform to transitive inheritance edges.

Default.

ir_class_casts_normalized 

Class casts conform to inheritance edges.

Definition at line 1022 of file typerep.h.

The state of the type layout.

Enumerator:
layout_undefined 

The layout of this type is not defined.

Address computation to access fields is not possible, fields must be accessed by Sel nodes. Enumeration constants might be undefined. This is the default value except for pointer, primitive and method types.

layout_fixed 

The layout is fixed, all component/member entities have an offset assigned.

Size of the type is known. Arrays can be accessed by explicit address computation. Enumeration constants must be defined. Default for pointer, primitive and method types.

Definition at line 1089 of file typerep.h.

Function Documentation

int check_type ( const ir_type tp)

Checks a type.

Returns
non-zero if no errors were found
void compute_inh_transitive_closure ( void  )

Compute transitive closure of the subclass/superclass and overwrites/overwrittenby relation.

This function walks over the ir (O(#types+#entities)) to compute the transitive closure.

ident* default_mangle_inherited_name ( const ir_entity ent,
const ir_type clss 
)

Default name mangling for inherited entities.

Returns an ident that consists of the name of type followed by an underscore and the name (not ld_name) of the entity.

int equal_type ( ir_type typ1,
ir_type typ2 
)

Checks whether two types are structurally equal.

Parameters
typ1the first type
typ2the second type
Returns
true if the types are equal, else false.

Types are equal if :

  • they are the same type kind
  • they have the same name
  • they have the same mode (if applicable)
  • they have the same type_state and, ev., the same size
  • they are class types and have:
    • the same members (see same_entity in entity.h)
    • the same supertypes – the C-pointers are compared –> no recursive call.
    • the same number of subtypes. Subtypes are not compared, as this could cause a cyclic test.
  • they are structure types and have the same members
  • they are method types and have
    • the same parameter types
    • the same result types
  • they are union types and have the same members
  • they are array types and have
    • the same number of dimensions
    • the same dimension bounds
    • the same dimension order
    • the same element type
  • they are enumeration types and have the same enumerator names
  • they are pointer types and have the identical points_to type (i.e., the same C-struct to represent the type. This is to avoid endless recursions; with pointer types cyclic type graphs are possible.)
void free_inh_transitive_closure ( void  )

Free memory occupied by the transitive closure information.

void free_type ( ir_type tp)

Frees the memory used by the type.

Removes the type from the type list and frees all entities belonging to the type.

ir_type* get_class_trans_subtype_first ( const ir_type tp)

Start iteration over all transitive subtypes of tp.

ir_type* get_class_trans_subtype_next ( const ir_type tp)

Returns next type in a subtype iteration started by get_class_trans_subtype_first()

ir_type* get_class_trans_supertype_first ( const ir_type tp)

Start iteration over all transitive supertypes of tp.

ir_type* get_class_trans_supertype_next ( const ir_type tp)

Returns next type in a supertype iteration started by get_class_trans_supertype_first()

ir_entity* get_entity_trans_overwrites_first ( const ir_entity ent)

Start iteration over all transitive overwritten entities, overwritten by entity ent.

ir_entity* get_entity_trans_overwrites_next ( const ir_entity ent)

Returns next entity in a overwrites iteration started by get_entity_trans_overwrites_first()

ir_entity* get_entity_trans_overwrittenby_first ( const ir_entity ent)

Start iteration over all entities that transitive overwrite entity ent.

ir_entity* get_entity_trans_overwrittenby_next ( const ir_entity ent)

Returns next entity in a overwrittenby iteration started by get_entity_trans_overwrittenby_first()

ir_class_cast_state get_irg_class_cast_state ( const ir_graph irg)

Returns class cast state for graph irg.

ir_class_cast_state get_irp_class_cast_state ( void  )

Returns class cast state for the whole program.

inh_transitive_closure_state get_irp_inh_transitive_closure_state ( void  )

Returns the transitive closure of sub/superclass state for the whole program.

ir_visited_t get_master_type_visited ( void  )

Returns type visited reference counter.

See Also
Visited Counters
unsigned get_type_alignment_bytes ( ir_type tp)

Returns the alignment of a type in bytes.

type_dbg_info* get_type_dbg_info ( const ir_type tp)

Returns the debug information of a type.

Parameters
tpThe type.
void* get_type_link ( const ir_type tp)

Returns the associated link field of a type.

ir_mode* get_type_mode ( const ir_type tp)

Returns the mode of a type.

Returns NULL for all non atomic types.

long get_type_nr ( const ir_type tp)

Outputs a unique number for this type if libfirm is compiled for debugging, (configure with –enable-debug) else returns the address of the type cast to long.

unsigned get_type_size_bytes ( const ir_type tp)

Returns the size of a type in bytes.

ir_type_state get_type_state ( const ir_type tp)

Returns the type layout state of a type.

const char* get_type_state_name ( ir_type_state  s)

Returns a human readable string for the enum entry.

const tp_op* get_type_tpop ( const ir_type tp)

Returns type opcode of type tp.

tp_opcode get_type_tpop_code ( const ir_type tp)

Returns opcode of type opcode of type tp.

const char* get_type_tpop_name ( const ir_type tp)

Returns name of type opcode of type tp.

ident* get_type_tpop_nameid ( const ir_type tp)

Returns name identifier of type opcode of type tp.

ir_visited_t get_type_visited ( const ir_type tp)

Returns the visited counter of a type.

See Also
Visited Counters
void inc_master_type_visited ( void  )

Increments type visited reference counter by one.

See Also
Visited Counters, mark_type_visited(), type_visited()
void invalidate_irp_inh_transitive_closure_state ( void  )

Sets the transitive closure of sub/superclass state for the whole program to inh_transitive_closure_invalid.

void ir_print_type ( char *  buffer,
size_t  buffer_size,
const ir_type tp 
)

construct a string representing the type.

This uses the info retrieved by the type_dbg_info if available. Otherwise it tries to create an approximate textual representation of the type. Keep in mind that this representation is not unique for each type, might abstract away some details. The main intention of this is creating human redable strings giving an idea of the type.

int is_atomic_type ( const ir_type tp)

Checks whether a type is atomic.

Parameters
tpany type
Returns
true if type is primitive, pointer or enumeration
int is_class_trans_subtype ( const ir_type tp,
const ir_type subtp 
)

Check if subtp is a subtype of tp.

This function checks the full transitive closure of the subtype relation and not just direct subtyping.

Returns
1 if it is a subtype, 0 otherwise
int is_overwritten_by ( ir_entity high,
ir_entity low 
)

Returns true if high is (transitive) overwritten by low.

Returns false if high == low.

int is_SubClass_of ( ir_type low,
ir_type high 
)

Returns true if low is subclass of high.

Low is a subclass of high if low == high or if low is a subclass of a subclass of high. I.e, we search in all subtypes of high for low. @@ this can be implemented more efficient if we know the set of all subclasses of high.

int is_SubClass_ptr_of ( ir_type low,
ir_type high 
)

Subclass check for pointers to classes.

Dereferences at both types the same amount of pointer types (as many as possible). If the remaining types are both class types and subclasses, returns true, else false. Can also be called with two class types.

int is_type ( const void *  thing)

Checks whether a pointer points to a type.

Parameters
thingan arbitrary pointer
Returns
true if the thing is a type, else false
void mark_type_visited ( ir_type tp)

Sets visited field in type to type_visited.

See Also
Visited Counters
ir_entity* resolve_ent_polymorphy ( ir_type dynamic_class,
ir_entity static_ent 
)

Resolve polymorphism in the inheritance relation.

Returns the dynamically referenced entity if the static entity and the dynamic type are given. Searches downwards in overwritten tree.

void resolve_inheritance ( mangle_inherited_name_func mfunc)

Resolve implicit inheritance.

Resolves the implicit inheritance supplied by firm. Firm defines, that each entity that is not overwritten in a subclass is inherited to this subclass without change implicitly. This function generates entities that explicitly represent this inheritance. It generates for each entity overwriting entities in all subclasses of the owner of the entity, if the entity is not overwritten in that subclass.

The name of the new entity is generated with the function passed. If the function is NULL, the default_mangle_inherited_name() is used.

void set_irg_class_cast_state ( ir_graph irg,
ir_class_cast_state  state 
)

Sets class cast state for graph irg to state.

void set_irp_class_cast_state ( ir_class_cast_state  state)

Sets class cast state for the whole program to state.

void set_irp_inh_transitive_closure_state ( inh_transitive_closure_state  s)

Sets the transitive closure of sub/superclass state for the whole program.

void set_master_type_visited ( ir_visited_t  val)

Sets type visited reference counter.

See Also
Visited Counters
void set_type_alignment_bytes ( ir_type tp,
unsigned  align 
)

Sets the alignment of a type in bytes.

If the alignment of a type is not set, it is calculated here according to the following rules: -#.) if a type has a mode, the alignment is the mode size. -#.) compound types have the alignment of their biggest member. -#.) array types have the alignment of their element type. -#.) method types return 0 here. -#.) all other types return 1 here (i.e. aligned at byte).

void set_type_dbg_info ( ir_type tp,
type_dbg_info db 
)

Sets the debug information of a type.

Parameters
tpThe type.
dbThe debug info.
void set_type_link ( ir_type tp,
void *  l 
)

Sets the associated link field of a type.

void set_type_mode ( ir_type tp,
ir_mode m 
)

Sets the mode of a type.

Only has an effect on primitive, enumeration and pointer types.

void set_type_size_bytes ( ir_type tp,
unsigned  size 
)

Sets the size of a type in bytes.

For primitive, enumeration, pointer and method types the size is always fixed. This call is legal but has no effect.

void set_type_state ( ir_type tp,
ir_type_state  state 
)

Sets the type layout state of a type.

For primitives, pointer and method types the layout is always fixed. This call is legal but has no effect.

void set_type_visited ( ir_type tp,
ir_visited_t  num 
)

Sets the visited counter of a type to num.

See Also
Visited Counters
int smaller_type ( ir_type st,
ir_type lt 
)

Checks whether two types are structural comparable.

Parameters
stpointer type
ltpointer type
Returns
true if type st is smaller than type lt, i.e. whenever lt is expected a st can be used. This is true if
  • they are the same type kind
  • mode(st) < mode (lt) (if applicable)
  • they are class types and st is (transitive) subtype of lt,
  • they are structure types and
    • the members of st have exactly one counterpart in lt with the same name,
    • the counterpart has a bigger type.
  • they are method types and have
    • the same number of parameter and result types,
    • the parameter types of st are smaller than those of lt,
    • the result types of st are smaller than those of lt
  • they are union types and have the members of st have exactly one
counterpart in lt and the type is smaller
  • they are array types and have
    • the same number of dimensions
    • all bounds of lt are bound of st
    • the same dimension order
    • the same element type
or
  • the element type of st is smaller than that of lt
  • the element types have the same size and fixed layout.
  • they are enumeration types and have the same enumerator names
  • they are pointer types and have the points_to type of st is
    Returns
    smaller than the points_to type of lt.
int tr_verify ( void  )

Walks the type information and performs a set of sanity checks.

Currently, the following checks are executed:

  • values of initialized entities must be allocated on the constant IRG
  • class types: doesn't have NULL members
  • class types: all overwrites are existent in the super type
Returns
0 if no error encountered
int type_not_visited ( const ir_type tp)

Returns non-zero if the type is not yet visited.

See Also
Visited Counters
int type_visited ( const ir_type tp)

Returns non-zero if the type is already visited.

See Also
Visited Counters