libFirm
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
Switch node

Change control flow. More...

Typedefs

typedef struct ir_switch_table ir_switch_table
 A switch table mapping integer numbers to proj-numbers of a Switch-node. More...
 

Enumerations

enum  n_Switch { n_Switch_selector, n_Switch_max = n_Switch_selector }
 Input numbers for Switch node. More...
 
enum  pn_Switch { pn_Switch_default, pn_Switch_max = pn_Switch_default }
 Projection numbers for result of Switch node (use for Proj nodes) More...
 

Functions

ir_switch_tableir_new_switch_table (ir_graph *irg, size_t n_entries)
 Creates a new switch_table data structure with n_entries entries. More...
 
size_t ir_switch_table_get_n_entries (const ir_switch_table *table)
 Returns number of entries available in switch table table. More...
 
void ir_switch_table_set (ir_switch_table *table, size_t entry, ir_tarval *min, ir_tarval *max, unsigned pn)
 Sets entry number entry in the switch table table. More...
 
ir_tarvalir_switch_table_get_max (const ir_switch_table *table, size_t entry)
 Returns maximum tarval value of switch table entry entry. More...
 
ir_tarvalir_switch_table_get_min (const ir_switch_table *table, size_t entry)
 Returns minimum tarval value of switch table entry entry. More...
 
unsigned ir_switch_table_get_pn (const ir_switch_table *table, size_t entry)
 Returns proj number taken if switch table entry entry matches. More...
 
ir_switch_tableir_switch_table_duplicate (ir_graph *irg, const ir_switch_table *table)
 Duplicates switch table table on obstack of irg. More...
 
ir_nodenew_rd_Switch (dbg_info *dbgi, ir_node *block, ir_node *irn_selector, unsigned n_outs, ir_switch_table *table)
 Construct a Switch node. More...
 
ir_nodenew_r_Switch (ir_node *block, ir_node *irn_selector, unsigned n_outs, ir_switch_table *table)
 Construct a Switch node. More...
 
ir_nodenew_d_Switch (dbg_info *dbgi, ir_node *irn_selector, unsigned n_outs, ir_switch_table *table)
 Construct a Switch node. More...
 
ir_nodenew_Switch (ir_node *irn_selector, unsigned n_outs, ir_switch_table *table)
 Construct a Switch node. More...
 
int is_Switch (const ir_node *node)
 Test if node is a Switch. More...
 
ir_nodeget_Switch_selector (const ir_node *node)
 Returns selector input of a Switch node. More...
 
void set_Switch_selector (ir_node *node, ir_node *selector)
 Sets selector input of a Switch node. More...
 
unsigned get_Switch_n_outs (const ir_node *node)
 Returns n_outs attribute of a Switch node. More...
 
void set_Switch_n_outs (ir_node *node, unsigned n_outs)
 Sets n_outs attribute of a Switch node. More...
 
ir_switch_tableget_Switch_table (const ir_node *node)
 Returns table attribute of a Switch node. More...
 
void set_Switch_table (ir_node *node, ir_switch_table *table)
 Sets table attribute of a Switch node. More...
 
ir_opget_op_Switch (void)
 Returns opcode for Switch nodes. More...
 

Variables

ir_opop_Switch
 Switch opcode. More...
 

Detailed Description

Change control flow.

The destination is choosen based on an integer input value which is looked up in a table.

Backends can implement this efficiently using a jump table.

Typedef Documentation

A switch table mapping integer numbers to proj-numbers of a Switch-node.

Entries map a continuous range of integer numbers to a proj-number. There must never be two different entries matching the same integer number.

Definition at line 102 of file firm_types.h.

Enumeration Type Documentation

enum n_Switch

Input numbers for Switch node.

Enumerator
n_Switch_selector 

input selector

n_Switch_max 

Definition at line 4010 of file nodes.h.

enum pn_Switch

Projection numbers for result of Switch node (use for Proj nodes)

Enumerator
pn_Switch_default 

control flow if no other case matches

pn_Switch_max 

Definition at line 4018 of file nodes.h.

Function Documentation

ir_op* get_op_Switch ( void  )

Returns opcode for Switch nodes.

Definition at line 2746 of file gen_irnode.c.

References op_Switch.

unsigned get_Switch_n_outs ( const ir_node node)

Returns n_outs attribute of a Switch node.

Definition at line 3489 of file gen_irnode.c.

ir_node* get_Switch_selector ( const ir_node node)

Returns selector input of a Switch node.

Definition at line 2736 of file gen_irnode.c.

ir_switch_table* get_Switch_table ( const ir_node node)

Returns table attribute of a Switch node.

Definition at line 3499 of file gen_irnode.c.

ir_switch_table* ir_new_switch_table ( ir_graph irg,
size_t  n_entries 
)

Creates a new switch_table data structure with n_entries entries.

The data structure is allocated on the obstack of irg.

ir_switch_table* ir_switch_table_duplicate ( ir_graph irg,
const ir_switch_table table 
)

Duplicates switch table table on obstack of irg.

ir_tarval* ir_switch_table_get_max ( const ir_switch_table table,
size_t  entry 
)

Returns maximum tarval value of switch table entry entry.

ir_tarval* ir_switch_table_get_min ( const ir_switch_table table,
size_t  entry 
)

Returns minimum tarval value of switch table entry entry.

size_t ir_switch_table_get_n_entries ( const ir_switch_table table)

Returns number of entries available in switch table table.

unsigned ir_switch_table_get_pn ( const ir_switch_table table,
size_t  entry 
)

Returns proj number taken if switch table entry entry matches.

void ir_switch_table_set ( ir_switch_table table,
size_t  entry,
ir_tarval min,
ir_tarval max,
unsigned  pn 
)

Sets entry number entry in the switch table table.

Parameters
tablethe switch table
entryentry number to set
minThe minimum tarval that matches this entry
maxThe maximum tarval that matches this entry
pnProj number taken on match
int is_Switch ( const ir_node node)

Test if node is a Switch.

Returns
1 if the node is a Switch node, 0 otherwise

Definition at line 3484 of file gen_irnode.c.

ir_node* new_d_Switch ( dbg_info dbgi,
ir_node irn_selector,
unsigned  n_outs,
ir_switch_table table 
)

Construct a Switch node.

Parameters
dbgiA pointer to debug information.
irn_selectorselector
n_outsnumber of outputs (including pn_Switch_default)
tabletable describing mapping from input values to Proj numbers

Definition at line 2724 of file gen_irnode.c.

References current_ir_graph, get_cur_block(), IR_GRAPH_CONSTRAINT_CONSTRUCTION, irg_is_constrained(), and new_rd_Switch().

Referenced by new_Switch().

ir_node* new_r_Switch ( ir_node block,
ir_node irn_selector,
unsigned  n_outs,
ir_switch_table table 
)

Construct a Switch node.

Parameters
blockThe IR block the node belongs to.
irn_selectorselector
n_outsnumber of outputs (including pn_Switch_default)
tabletable describing mapping from input values to Proj numbers

Definition at line 2719 of file gen_irnode.c.

References new_rd_Switch().

ir_node* new_rd_Switch ( dbg_info dbgi,
ir_node block,
ir_node irn_selector,
unsigned  n_outs,
ir_switch_table table 
)

Construct a Switch node.

Parameters
dbgiA pointer to debug information.
blockThe IR block the node belongs to.
irn_selectorselector
n_outsnumber of outputs (including pn_Switch_default)
tabletable describing mapping from input values to Proj numbers

Definition at line 2702 of file gen_irnode.c.

References get_irn_irg(), mode_T, new_ir_node(), op_Switch, optimize_node(), and verify_new_node().

Referenced by new_d_Switch(), and new_r_Switch().

ir_node* new_Switch ( ir_node irn_selector,
unsigned  n_outs,
ir_switch_table table 
)

Construct a Switch node.

Parameters
irn_selectorselector
n_outsnumber of outputs (including pn_Switch_default)
tabletable describing mapping from input values to Proj numbers

Definition at line 2731 of file gen_irnode.c.

References new_d_Switch().

void set_Switch_n_outs ( ir_node node,
unsigned  n_outs 
)

Sets n_outs attribute of a Switch node.

Definition at line 3494 of file gen_irnode.c.

void set_Switch_selector ( ir_node node,
ir_node selector 
)

Sets selector input of a Switch node.

Definition at line 2741 of file gen_irnode.c.

void set_Switch_table ( ir_node node,
ir_switch_table table 
)

Sets table attribute of a Switch node.

Definition at line 3504 of file gen_irnode.c.

Variable Documentation

ir_op* op_Switch

Switch opcode.

Definition at line 4084 of file nodes.h.

Referenced by get_op_Switch(), and new_rd_Switch().