2 * This file is part of libFirm.
3 * Copyright (C) 2012 University of Karlsruhe.
8 * @brief doubleword lowering operations
9 * @author Michael Beck, Matthias Braun
11 #ifndef FIRM_LOWER_LOWER_DW_H
12 #define FIRM_LOWER_LOWER_DW_H
14 #include "firm_types.h"
17 * Every double word node will be replaced,
18 * we need some store to hold the replacement:
20 typedef struct lower64_entry_t {
21 ir_node *low_word; /**< the low word */
22 ir_node *high_word; /**< the high word */
27 * A callback type for creating an intrinsic entity for a given opcode.
29 * @param method the method type of the emulation function entity
30 * @param op the emulated ir_op
31 * @param imode the input mode of the emulated opcode
32 * @param omode the output mode of the emulated opcode
33 * @param context the context parameter
35 typedef ir_entity *(create_intrinsic_fkt)(ir_type *method, const ir_op *op,
37 const ir_mode *omode, void *context);
40 * The lowering parameter description.
42 typedef struct lwrdw_param_t {
43 unsigned little_endian : 1; /**< if true should be lowered for little endian, else big endian */
44 unsigned doubleword_size; /**< bitsize of the doubleword mode */
45 create_intrinsic_fkt *create_intrinsic; /**< callback that creates the intrinsic entity */
46 void *ctx; /**< context parameter for the creator function */
50 * Prepare the doubleword lowering algorithm. Creates an environment
51 * which can be used to register custom lowering functions
53 void ir_prepare_dw_lowering(const lwrdw_param_t *param);
56 * Lower all doubleword operations in the program.
57 * Must be called after ir_prepare_dw_lowering()
59 void ir_lower_dw_ops(void);
61 typedef void (*lower_dw_func)(ir_node *node, ir_mode *mode);
64 * register a custom lowering function.
65 * After lowering the custom function should call ir_set_dw_lowered()
67 void ir_register_dw_lower_function(ir_op *op, lower_dw_func func);
70 * After lowering a node a custom doubleword lowering function has to call this.
71 * It registers 2 new values for the high and low part of the lowered value.
73 void ir_set_dw_lowered(ir_node *old, ir_node *new_low,
77 * Query lowering results of a node. In a lowering callback you can use this
78 * on all predecessors of a node. The only exception are block and phi nodes.
79 * Their predecessors are not necessarily transformed yet.
81 lower64_entry_t *get_node_entry(ir_node *node);
83 static inline ir_node *get_lowered_low(ir_node *node)
85 return get_node_entry(node)->low_word;
88 static inline ir_node *get_lowered_high(ir_node *node)
90 return get_node_entry(node)->high_word;
94 * Return the unsigned variant of the lowered mode
95 * Note: you must only call this during a dw_lowering (= in a lowering callback)
97 ir_mode *ir_get_low_unsigned_mode(void);
100 * Default implementation. Context is unused.
102 ir_entity *def_create_intrinsic_fkt(ir_type *method, const ir_op *op,
103 const ir_mode *imode, const ir_mode *omode,