libFirm
Lowering

Lowering is the process of transforming a highlevel representation (a representation closer to the sourcecode) into a lower-level representation (something closer to the target machine). More...

Data Structures

struct  i_call_record
 An intrinsic call record. More...
struct  i_instr_record
 An intrinsic instruction record. More...
union  i_record
 An intrinsic record. More...
struct  runtime_rt
 A runtime routine description. More...

Typedefs

typedef int lower_mux_callback (ir_node *mux)
 Used as callback, whenever a lowerable mux is found.
typedef int(* i_mapper_func )(ir_node *node, void *ctx)
 An intrinsic mapper function.

Enumerations

enum  ikind { INTRINSIC_CALL = 0, INTRINSIC_INSTR }
 kind of an instruction record More...

Functions

void lower_CopyB (ir_graph *irg, unsigned max_small_size, unsigned min_large_size, int allow_misalignments)
 Lower small CopyB nodes to Load/Store nodes, preserve medium-sized CopyB nodes and replace large CopyBs by a call to memcpy, depending on the given parameters.
void lower_switch (ir_graph *irg, unsigned small_switch, unsigned spare_size, ir_mode *selector_mode)
 Lowers all Switches (Cond nodes with non-boolean mode) depending on spare_size.
void lower_highlevel_graph (ir_graph *irg)
 Replaces SymConsts by a real constant if possible.
ir_graph_pass_tlower_highlevel_graph_pass (const char *name)
 Creates an ir_graph pass for lower_highlevel_graph().
void lower_highlevel (void)
 Replaces SymConsts by a real constant if possible.
void lower_const_code (void)
 does the same as lower_highlevel for all nodes on the const code irg
ir_prog_pass_tlower_const_code_pass (const char *name)
 Creates an ir_prog pass for lower_const_code().
void lower_mux (ir_graph *irg, lower_mux_callback *cb_func)
 Lowers all mux nodes in the given graph.
ir_graph_pass_tlower_mux_pass (const char *name, lower_mux_callback *cb_func)
 Creates an ir_graph pass for lower_mux().
size_t lower_intrinsics (i_record *list, size_t length, int part_block_used)
 Go through all graphs and map calls to intrinsic functions and instructions.
ir_prog_pass_tlower_intrinsics_pass (const char *name, i_record *list, size_t length, int part_block_used)
 Creates an irprog pass for lower_intrinsics.
int i_mapper_abs (ir_node *call, void *ctx)
 A mapper for the integer/float absolute value: type abs(type v).
int i_mapper_bswap (ir_node *call, void *ctx)
 A mapper for the integer byte swap value: type bswap(type v).
int i_mapper_sqrt (ir_node *call, void *ctx)
 A mapper for the floating point sqrt(v): floattype sqrt(floattype v);.
int i_mapper_cbrt (ir_node *call, void *ctx)
 A mapper for the floating point cbrt(v): floattype sqrt(floattype v);.
int i_mapper_pow (ir_node *call, void *ctx)
 A mapper for the floating point pow(a, b): floattype pow(floattype a, floattype b);.
int i_mapper_exp (ir_node *call, void *ctx)
 A mapper for the floating point exp(a): floattype exp(floattype a);.
int i_mapper_exp2 (ir_node *call, void *ctx)
 A mapper for the floating point exp2(a): floattype exp2(floattype a);.
int i_mapper_exp10 (ir_node *call, void *ctx)
 A mapper for the floating point exp10(a): floattype exp10(floattype a);.
int i_mapper_log (ir_node *call, void *ctx)
 A mapper for the floating point log(a): floattype log(floattype a);.
int i_mapper_log2 (ir_node *call, void *ctx)
 A mapper for the floating point log(a): floattype log(floattype a);.
int i_mapper_log10 (ir_node *call, void *ctx)
 A mapper for the floating point log(a): floattype log(floattype a);.
int i_mapper_sin (ir_node *call, void *ctx)
 A mapper for the floating point sin(a): floattype sin(floattype a);.
int i_mapper_cos (ir_node *call, void *ctx)
 A mapper for the floating point sin(a): floattype cos(floattype a);.
int i_mapper_tan (ir_node *call, void *ctx)
 A mapper for the floating point tan(a): floattype tan(floattype a);.
int i_mapper_asin (ir_node *call, void *ctx)
 A mapper for the floating point asin(a): floattype asin(floattype a);.
int i_mapper_acos (ir_node *call, void *ctx)
 A mapper for the floating point acos(a): floattype acos(floattype a);.
int i_mapper_atan (ir_node *call, void *ctx)
 A mapper for the floating point atan(a): floattype atan(floattype a);.
int i_mapper_sinh (ir_node *call, void *ctx)
 A mapper for the floating point sinh(a): floattype sinh(floattype a);.
int i_mapper_cosh (ir_node *call, void *ctx)
 A mapper for the floating point cosh(a): floattype cosh(floattype a);.
int i_mapper_tanh (ir_node *call, void *ctx)
 A mapper for the floating point tanh(a): floattype tanh(floattype a);.
int i_mapper_strcmp (ir_node *call, void *ctx)
 A mapper for the strcmp-Function: inttype strcmp(char pointer a, char pointer b);.
int i_mapper_strncmp (ir_node *call, void *ctx)
 A mapper for the strncmp-Function: inttype strncmp(char pointer a, char pointer b, inttype len);.
int i_mapper_strcpy (ir_node *call, void *ctx)
 A mapper for the strcpy-Function: char pointer strcpy(char pointer a, char pointer b);.
int i_mapper_strlen (ir_node *call, void *ctx)
 A mapper for the strlen-Function: inttype strlen(char pointer a);.
int i_mapper_memcpy (ir_node *call, void *ctx)
 A mapper for the memcpy-Function: void pointer memcpy(void pointer d, void pointer s, inttype c);.
int i_mapper_mempcpy (ir_node *call, void *ctx)
 A mapper for the mempcpy-Function: void pointer mempcpy(void pointer d, void pointer s, inttype c);.
int i_mapper_memmove (ir_node *call, void *ctx)
 A mapper for the memmove-Function: void pointer memmove(void pointer d, void pointer s, inttype c);.
int i_mapper_memset (ir_node *call, void *ctx)
 A mapper for the memset-Function: void pointer memset(void pointer d, inttype C, inttype len);.
int i_mapper_memcmp (ir_node *call, void *ctx)
 A mapper for the strncmp-Function: inttype memcmp(void pointer a, void pointer b, inttype len);.
int i_mapper_alloca (ir_node *call, void *ctx)
 A mapper for the alloca() function: pointer alloca(inttype size) Replaces the call by a Alloca(stack_alloc) node.
int i_mapper_RuntimeCall (ir_node *node, runtime_rt *rt)
 A mapper for mapping unsupported instructions to runtime calls.

Detailed Description

Lowering is the process of transforming a highlevel representation (a representation closer to the sourcecode) into a lower-level representation (something closer to the target machine).

Typedef Documentation

typedef int(* i_mapper_func)(ir_node *node, void *ctx)

An intrinsic mapper function.

Parameters
nodethe IR-node that will be mapped
ctxa context
Returns
non-zero if the call was mapped

Definition at line 164 of file lowering.h.

typedef int lower_mux_callback(ir_node *mux)

Used as callback, whenever a lowerable mux is found.

The return value indicates, whether the mux should be lowered. This may be used, to lower floating point muxes, while keeping mux nodes for integers, for example.

Parameters
muxThe mux node that may be lowered.
Returns
A non-zero value indicates that the mux should be lowered.

Definition at line 132 of file lowering.h.

Enumeration Type Documentation

enum ikind

kind of an instruction record

See Also
i_record
Enumerator:
INTRINSIC_CALL 

the record represents an intrinsic call

INTRINSIC_INSTR 

the record represents an intrinsic instruction

Definition at line 168 of file lowering.h.

Function Documentation

int i_mapper_abs ( ir_node call,
void *  ctx 
)

A mapper for the integer/float absolute value: type abs(type v).

Replaces the call by a Abs node.

Returns
always 1
int i_mapper_acos ( ir_node call,
void *  ctx 
)

A mapper for the floating point acos(a): floattype acos(floattype a);.

Returns
1 if the tan call was removed, 0 else.
int i_mapper_alloca ( ir_node call,
void *  ctx 
)

A mapper for the alloca() function: pointer alloca(inttype size) Replaces the call by a Alloca(stack_alloc) node.

Returns
always 1
int i_mapper_asin ( ir_node call,
void *  ctx 
)

A mapper for the floating point asin(a): floattype asin(floattype a);.

Returns
1 if the asin call was removed, 0 else.
int i_mapper_atan ( ir_node call,
void *  ctx 
)

A mapper for the floating point atan(a): floattype atan(floattype a);.

Returns
1 if the atan call was removed, 0 else.
int i_mapper_bswap ( ir_node call,
void *  ctx 
)

A mapper for the integer byte swap value: type bswap(type v).

Replaces the call by a builtin[ir_bk_bswap] node.

Returns
always 1
int i_mapper_cbrt ( ir_node call,
void *  ctx 
)

A mapper for the floating point cbrt(v): floattype sqrt(floattype v);.

Returns
1 if the cbrt call was removed, 0 else.
int i_mapper_cos ( ir_node call,
void *  ctx 
)

A mapper for the floating point sin(a): floattype cos(floattype a);.

Returns
1 if the cos call was removed, 0 else.
int i_mapper_cosh ( ir_node call,
void *  ctx 
)

A mapper for the floating point cosh(a): floattype cosh(floattype a);.

Returns
1 if the cosh call was removed, 0 else.
int i_mapper_exp ( ir_node call,
void *  ctx 
)

A mapper for the floating point exp(a): floattype exp(floattype a);.

Returns
1 if the exp call was removed, 0 else.
int i_mapper_exp10 ( ir_node call,
void *  ctx 
)

A mapper for the floating point exp10(a): floattype exp10(floattype a);.

Returns
1 if the exp call was removed, 0 else.
int i_mapper_exp2 ( ir_node call,
void *  ctx 
)

A mapper for the floating point exp2(a): floattype exp2(floattype a);.

Returns
1 if the exp call was removed, 0 else.
int i_mapper_log ( ir_node call,
void *  ctx 
)

A mapper for the floating point log(a): floattype log(floattype a);.

Returns
1 if the log call was removed, 0 else.
int i_mapper_log10 ( ir_node call,
void *  ctx 
)

A mapper for the floating point log(a): floattype log(floattype a);.

Returns
1 if the log call was removed, 0 else.
int i_mapper_log2 ( ir_node call,
void *  ctx 
)

A mapper for the floating point log(a): floattype log(floattype a);.

Returns
1 if the log call was removed, 0 else.
int i_mapper_memcmp ( ir_node call,
void *  ctx 
)

A mapper for the strncmp-Function: inttype memcmp(void pointer a, void pointer b, inttype len);.

Returns
1 if the strncmp call was removed, 0 else.
int i_mapper_memcpy ( ir_node call,
void *  ctx 
)

A mapper for the memcpy-Function: void pointer memcpy(void pointer d, void pointer s, inttype c);.

Returns
1 if the memcpy call was removed, 0 else.
int i_mapper_memmove ( ir_node call,
void *  ctx 
)

A mapper for the memmove-Function: void pointer memmove(void pointer d, void pointer s, inttype c);.

Returns
1 if the memmove call was removed, 0 else.
int i_mapper_mempcpy ( ir_node call,
void *  ctx 
)

A mapper for the mempcpy-Function: void pointer mempcpy(void pointer d, void pointer s, inttype c);.

Returns
1 if the mempcpy call was removed, 0 else.
int i_mapper_memset ( ir_node call,
void *  ctx 
)

A mapper for the memset-Function: void pointer memset(void pointer d, inttype C, inttype len);.

Returns
1 if the memset call was removed, 0 else.
int i_mapper_pow ( ir_node call,
void *  ctx 
)

A mapper for the floating point pow(a, b): floattype pow(floattype a, floattype b);.

Returns
1 if the pow call was removed, 0 else.
int i_mapper_RuntimeCall ( ir_node node,
runtime_rt rt 
)

A mapper for mapping unsupported instructions to runtime calls.

Maps a op(arg_0, ..., arg_n) into a call to a runtime function rt(arg_0, ..., arg_n).

The mapping is only done, if the modes of all arguments matches the modes of rt's argument. Further, if op has a memory input, the generated Call uses it, else it gets a NoMem. The pinned state of the Call will be set to the pinned state of op.

Note that i_mapper_RuntimeCall() must be used with a i_instr_record.

Returns
1 if an op was mapped, 0 else

Some examples:

int i_mapper_sin ( ir_node call,
void *  ctx 
)

A mapper for the floating point sin(a): floattype sin(floattype a);.

Returns
1 if the sin call was removed, 0 else.
int i_mapper_sinh ( ir_node call,
void *  ctx 
)

A mapper for the floating point sinh(a): floattype sinh(floattype a);.

Returns
1 if the sinh call was removed, 0 else.
int i_mapper_sqrt ( ir_node call,
void *  ctx 
)

A mapper for the floating point sqrt(v): floattype sqrt(floattype v);.

Returns
1 if the sqrt call was removed, 0 else.
int i_mapper_strcmp ( ir_node call,
void *  ctx 
)

A mapper for the strcmp-Function: inttype strcmp(char pointer a, char pointer b);.

Returns
1 if the strcmp call was removed, 0 else.
int i_mapper_strcpy ( ir_node call,
void *  ctx 
)

A mapper for the strcpy-Function: char pointer strcpy(char pointer a, char pointer b);.

Returns
1 if the strcpy call was removed, 0 else.
int i_mapper_strlen ( ir_node call,
void *  ctx 
)

A mapper for the strlen-Function: inttype strlen(char pointer a);.

Returns
1 if the strlen call was removed, 0 else.
int i_mapper_strncmp ( ir_node call,
void *  ctx 
)

A mapper for the strncmp-Function: inttype strncmp(char pointer a, char pointer b, inttype len);.

Returns
1 if the strncmp call was removed, 0 else.
int i_mapper_tan ( ir_node call,
void *  ctx 
)

A mapper for the floating point tan(a): floattype tan(floattype a);.

Returns
1 if the tan call was removed, 0 else.
int i_mapper_tanh ( ir_node call,
void *  ctx 
)

A mapper for the floating point tanh(a): floattype tanh(floattype a);.

Returns
1 if the tanh call was removed, 0 else.
void lower_const_code ( void  )

does the same as lower_highlevel for all nodes on the const code irg

ir_prog_pass_t* lower_const_code_pass ( const char *  name)

Creates an ir_prog pass for lower_const_code().

Parameters
namethe name of this pass or NULL
Returns
the newly created ir_prog pass
void lower_CopyB ( ir_graph irg,
unsigned  max_small_size,
unsigned  min_large_size,
int  allow_misalignments 
)

Lower small CopyB nodes to Load/Store nodes, preserve medium-sized CopyB nodes and replace large CopyBs by a call to memcpy, depending on the given parameters.

Small CopyB nodes (size <= max_small_size) are turned into a series of loads and stores. Medium-sized CopyB nodes (max_small_size < size < min_large_size) are left untouched. Large CopyB nodes (size >= min_large_size) are turned into a memcpy call.

Parameters
irgThe graph to be lowered.
max_small_sizeThe maximum number of bytes for a CopyB node so that it is still considered 'small'.
min_large_sizeThe minimum number of bytes for a CopyB node so that it is regarded as 'large'.
allow_misalignmentsBackend can handle misaligned loads and stores.
void lower_highlevel ( void  )

Replaces SymConsts by a real constant if possible.

Replaces Sel nodes by address computation. Also resolves array access. Handle bit fields by added And/Or calculations. Lowers all graphs.

Note
There is NO lowering of objects oriented types. This is highly compiler and ABI specific and should be placed directly in the compiler.
void lower_highlevel_graph ( ir_graph irg)

Replaces SymConsts by a real constant if possible.

Replaces Sel nodes by address computation. Also resolves array access. Handle bit fields by added And/Or calculations.

Parameters
irgthe graph to lower
Note
: There is NO lowering ob objects oriented types. This is highly compiler and ABI specific and should be placed directly in the compiler.
ir_graph_pass_t* lower_highlevel_graph_pass ( const char *  name)

Creates an ir_graph pass for lower_highlevel_graph().

Parameters
namethe name of this pass or NULL
Returns
the newly created ir_graph pass
size_t lower_intrinsics ( i_record list,
size_t  length,
int  part_block_used 
)

Go through all graphs and map calls to intrinsic functions and instructions.

Every call or instruction is reported to its mapper function, which is responsible for rebuilding the graph.

current_ir_graph is always set.

Parameters
listan array of intrinsic map records
lengththe length of the array
part_block_usedset to true if part_block() must be using during lowering
Returns
number of found intrinsics.
ir_prog_pass_t* lower_intrinsics_pass ( const char *  name,
i_record list,
size_t  length,
int  part_block_used 
)

Creates an irprog pass for lower_intrinsics.

Parameters
namethe name of this pass or NULL
listan array of intrinsic map records
lengththe length of the array
part_block_usedset to true if part_block() must be using during lowering
void lower_mux ( ir_graph irg,
lower_mux_callback cb_func 
)

Lowers all mux nodes in the given graph.

A callback function may be given, to select the mux nodes to lower.

Parameters
irgThe graph to lower mux nodes in.
cb_funcThe callback function for mux selection. Can be NULL, to lower all mux nodes.
ir_graph_pass_t* lower_mux_pass ( const char *  name,
lower_mux_callback cb_func 
)

Creates an ir_graph pass for lower_mux().

Parameters
namethe name of this pass or NULL
cb_funcThe callback function for mux selection. Can be NULL, to lower all mux nodes.
Returns
the newly created ir_graph pass
void lower_switch ( ir_graph irg,
unsigned  small_switch,
unsigned  spare_size,
ir_mode selector_mode 
)

Lowers all Switches (Cond nodes with non-boolean mode) depending on spare_size.

They will either remain the same or be converted into if-cascades.

Parameters
irgThe ir graph to be lowered.
small_switchIf switch has <= cases then change it to an if-cascade.
spare_sizeAllowed spare size for table switches in machine words. (Default in edgfe: 128)
selector_modemode which must be used for Switch selector