3 * File name: ir/lower/lower_intrinsics.h
4 * Purpose: lowering of Calls of intrinsic functions
8 * Copyright: (c) 1998-2005 Universität Karlsruhe
9 * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
13 * @file lower_intrinsics.h
15 * Lowering of Calls of intrinsic functions.
17 * @author Michael Beck
19 #ifndef _LOWER_INTRINSICS_H_
20 #define _LOWER_INTRINSICS_H_
22 #include "firm_types.h"
25 * An intrinsic mapper function.
27 * @param node the IR-node that will be mapped
28 * @param ctx a context
30 * @return non-zero if the call was mapped
32 typedef int (*i_mapper_func)(ir_node *node, void *ctx);
35 INTRINSIC_CALL = 0, /**< the record represents an intrinsic call */
36 INTRINSIC_INSTR /**< the record represents an intrinsic instruction */
40 * An intrinsic record.
42 typedef struct _i_call_record {
43 enum ikind kind; /**< must be INTRINSIC_CALL */
44 entity *i_ent; /**< the entity representing an intrinsic call */
45 i_mapper_func i_mapper; /**< the mapper function to call */
46 void *ctx; /**< mapper context */
50 * An intrinsic instruction record.
52 typedef struct _i_instr_record {
53 enum ikind kind; /**< must be INTRINSIC_INSTR */
54 ir_op *op; /**< the opcode that must be mapped. */
55 i_mapper_func i_mapper; /**< the mapper function to call */
56 void *ctx; /**< mapper context */
60 * An intrinsic record.
62 typedef union _i_record {
64 i_instr_record i_instr;
68 * Go through all graphs and map calls to intrinsic functions and instructions.
70 * Every call or instruction is reported to its mapper function,
71 * which is responsible for rebuilding the graph.
73 * current_ir_graph is always set.
75 * @param list an array of intrinsic map records
76 * @param length the length of the array
78 * @return number of found intrinsics.
80 unsigned lower_intrinsics(const i_record *list, int length);
83 * A mapper for the integer absolute value: inttype abs(inttype v).
84 * Replaces the call by a Abs node.
88 int i_mapper_Abs(ir_node *call, void *ctx);
91 * A mapper for the alloca() function: pointer alloca(inttype size)
92 * Replaces the call by a Alloca(stack_alloc) node.
96 int i_mapper_Alloca(ir_node *call, void *ctx);
99 * A runtime routine description.
101 typedef struct _runtime_rt {
102 entity *ent; /**< The entity representing the runtime routine. */
103 ir_mode *mode; /**< The operation mode of the mapped instruction. */
104 long mem_proj_nr; /**< if >= 0, create a memory ProjM() */
105 long exc_proj_nr; /**< if >= 0, create a exception ProjX() */
106 long exc_mem_proj_nr; /**< if >= 0, create a exception memory ProjM() */
107 long res_proj_nr; /**< if >= 0, first result projection number */
111 * A mapper for mapping unsupported instructions to runtime calls.
112 * Maps a op(arg_0, ..., arg_n) into a call to a runtime function
113 * rt(arg_0, ..., arg_n).
115 * The mapping is only done, if the modes of all arguments matches the
116 * modes of rt's argument.
117 * Further, if op has a memory input, the generated Call uses it, else
119 * The pinned state of the Call will be set to the pinned state of op.
121 * Note that i_mapper_RuntimeCall() must be used with a i_instr_record.
123 * @return 1 if an op was mapped, 0 else
127 * - Maps Div nodes to calls to rt_Div():
129 runtime_rt rt_Div = {
130 ent("int rt_Div(int, int)"),
137 i_instr_record map_Div = {
140 i_mapper_RuntimeCall,
145 * - Maps ConvD(F) to calls to rt_Float2Div():
147 runtime_rt rt_Float2Double = {
148 ent("double rt_Float2Div(float)"),
149 get_type_mode("double"),
155 i_instr_record map_Float2Double = {
158 i_mapper_RuntimeCall,
163 int i_mapper_RuntimeCall(ir_node *node, runtime_rt *rt);
165 #endif /* _LOWER_INTRINSICS_H_ */