Commit 473aaab7 authored by Matthias Braun's avatar Matthias Braun
Browse files

cleanup, use C99

parent be694a40
......@@ -28,7 +28,8 @@
static bitset_t *non_address_mode_nodes;
/**
* Recursive worker for checking if a DAG with root node can be represented as a simple immediate,
* Recursive worker for checking if a DAG with root node can be represented as
* a simple immediate.
*
* @param node the node
* @param symconsts number of symconsts found so far
......@@ -38,9 +39,6 @@ static bitset_t *non_address_mode_nodes;
*/
static bool do_is_immediate(const ir_node *node, int *symconsts, bool negate)
{
ir_node *left;
ir_node *right;
switch (get_irn_opcode(node)) {
case iro_Const:
/* Consts are typically immediates */
......@@ -74,10 +72,10 @@ static bool do_is_immediate(const ir_node *node, int *symconsts, bool negate)
if (ia32_is_non_address_mode_node(node))
return false;
left = get_binop_left(node);
ir_node *left = get_binop_left(node);
if (!do_is_immediate(left, symconsts, negate))
return false;
right = get_binop_right(node);
ir_node *right = get_binop_right(node);
if (!do_is_immediate(right, symconsts, is_Sub(node) ? !negate : negate))
return false;
......@@ -111,48 +109,46 @@ static int is_immediate(ia32_address_t *addr, const ir_node *node, bool negate)
*/
static void eat_immediate(ia32_address_t *addr, ir_node *node, bool negate)
{
ir_tarval *tv;
ir_node *left;
ir_node *right;
long val;
switch (get_irn_opcode(node)) {
case iro_Const:
case iro_Const: {
/* simply add the value to the offset */
tv = get_Const_tarval(node);
val = get_tarval_long(tv);
ir_tarval *tv = get_Const_tarval(node);
long val = get_tarval_long(tv);
if (negate) {
addr->offset -= val;
} else {
addr->offset += val;
}
break;
}
case iro_SymConst:
/* place the entity into the symconst */
if (addr->symconst_ent != NULL) {
panic("Internal error: more than 1 symconst in address calculation");
}
addr->symconst_ent = get_SymConst_entity(node);
addr->symconst_ent = get_SymConst_entity(node);
if (get_entity_owner(addr->symconst_ent) == get_tls_type())
addr->tls_segment = true;
assert(!negate);
break;
case iro_Unknown:
break;
case iro_Add:
case iro_Add: {
assert(!ia32_is_non_address_mode_node(node));
left = get_Add_left(node);
ir_node *left = get_Add_left(node);
eat_immediate(addr, left, negate);
right = get_Add_right(node);
ir_node *right = get_Add_right(node);
eat_immediate(addr, right, negate);
break;
case iro_Sub:
}
case iro_Sub: {
assert(!ia32_is_non_address_mode_node(node));
left = get_Sub_left(node);
ir_node *left = get_Sub_left(node);
eat_immediate(addr, left, negate);
right = get_Sub_right(node);
ir_node *right = get_Sub_right(node);
eat_immediate(addr, right, !negate);
break;
}
default:
panic("Internal error in immediate address calculation");
}
......@@ -211,9 +207,8 @@ static bool eat_shl(ia32_address_t *addr, ir_node *node)
{
ir_node *shifted_val;
long val;
if (is_Shl(node)) {
/* we can use shl with 1, 2 or 3 shift */
/* we can use shl with 0,1,2 or 3 shift */
ir_node *right = get_Shl_right(node);
if (!is_Const(right))
return false;
......@@ -260,11 +255,9 @@ static bool eat_shl(ia32_address_t *addr, ir_node *node)
return true;
}
/* Create an address mode for a given node. */
void ia32_create_address_mode(ia32_address_t *addr, ir_node *node, ia32_create_am_flags_t flags)
void ia32_create_address_mode(ia32_address_t *addr, ir_node *node,
ia32_create_am_flags_t flags)
{
ir_node *eat_imms;
if (is_immediate(addr, node, 0)) {
eat_immediate(addr, node, 0);
return;
......@@ -277,14 +270,14 @@ void ia32_create_address_mode(ia32_address_t *addr, ir_node *node, ia32_create_a
}
#endif
if (!(flags & ia32_create_am_force) &&
ia32_is_non_address_mode_node(node) &&
(!(flags & ia32_create_am_double_use) || get_irn_n_edges(node) > 2)) {
if (!(flags & ia32_create_am_force)
&& ia32_is_non_address_mode_node(node)
&& (!(flags & ia32_create_am_double_use) || get_irn_n_edges(node) > 2)) {
addr->base = node;
return;
}
eat_imms = eat_immediates(addr, node, flags);
ir_node *eat_imms = eat_immediates(addr, node, flags);
if (eat_imms != node) {
if (flags & ia32_create_am_force) {
eat_imms = ia32_skip_downconv(eat_imms);
......@@ -336,18 +329,16 @@ void ia32_create_address_mode(ia32_address_t *addr, ir_node *node, ia32_create_a
} else if (eat_shl(addr, right)) {
right = NULL;
}
if (left != NULL &&
be_is_FrameAddr(left) &&
!ia32_is_non_address_mode_node(left)) {
if (left != NULL && be_is_FrameAddr(left)
&& !ia32_is_non_address_mode_node(left)) {
assert(addr->base == NULL);
assert(addr->frame_entity == NULL);
addr->base = be_get_FrameAddr_frame(left);
addr->use_frame = 1;
addr->frame_entity = be_get_FrameAddr_entity(left);
left = NULL;
} else if (right != NULL &&
be_is_FrameAddr(right) &&
!ia32_is_non_address_mode_node(right)) {
} else if (right != NULL && be_is_FrameAddr(right)
&& !ia32_is_non_address_mode_node(right)) {
assert(addr->base == NULL);
assert(addr->frame_entity == NULL);
addr->base = be_get_FrameAddr_frame(right);
......@@ -384,7 +375,7 @@ void ia32_mark_non_am(ir_node *node)
bitset_set(non_address_mode_nodes, get_irn_idx(node));
}
int ia32_is_non_address_mode_node(ir_node const *node)
bool ia32_is_non_address_mode_node(ir_node const *node)
{
return bitset_is_set(non_address_mode_nodes, get_irn_idx(node));
}
......@@ -393,12 +384,13 @@ int ia32_is_non_address_mode_node(ir_node const *node)
* Check if a given value is last used (i.e. die after) the block of some
* other node.
*/
static int value_last_used_here(be_lv_t *lv, ir_node *here, ir_node *value)
static bool value_last_used_here(be_lv_t *lv, ir_node *here, ir_node *value)
{
ir_node *block = get_nodes_block(here);
/* If the value is live end it is for sure it does not die here */
if (be_is_live_end(lv, block, value)) return 0;
if (be_is_live_end(lv, block, value))
return false;
/* if multiple nodes in this block use the value, then we cannot decide
* whether the value will die here (because there is no schedule yet).
......@@ -406,11 +398,11 @@ static int value_last_used_here(be_lv_t *lv, ir_node *here, ir_node *value)
foreach_out_edge(value, edge) {
ir_node *user = get_edge_src_irn(edge);
if (user != here && get_nodes_block(user) == block) {
return 0;
return false;
}
}
return 1;
return true;
}
static bool simple_is_immediate(const ir_node *node)
......@@ -426,14 +418,8 @@ static bool simple_is_immediate(const ir_node *node)
static void mark_non_address_nodes(ir_node *node, void *env)
{
be_lv_t *lv = (be_lv_t*)env;
int arity;
int i;
ir_node *val;
ir_node *left;
ir_node *right;
ir_mode *mode;
mode = get_irn_mode(node);
ir_mode *mode = get_irn_mode(node);
if (!mode_is_int(mode) && !mode_is_reference(mode) && mode != mode_b)
return;
......@@ -443,14 +429,15 @@ static void mark_non_address_nodes(ir_node *node, void *env)
* turn it into AM. */
break;
case iro_Store:
case iro_Store: {
/* Do not mark the pointer, because we want to turn it into AM. */
val = get_Store_value(node);
ir_node *val = get_Store_value(node);
ia32_mark_non_am(val);
break;
}
case iro_Shl:
case iro_Add:
case iro_Add: {
/* only 1 user: AM folding is always beneficial */
if (get_irn_n_edges(node) <= 1)
break;
......@@ -461,8 +448,8 @@ static void mark_non_address_nodes(ir_node *node, void *env)
* pressure. Otherwise we fold them in aggressively in the hope, that
* the node itself doesn't exist anymore and we were able to save the
* register for the result */
left = get_binop_left(node);
right = get_binop_right(node);
ir_node *left = get_binop_left(node);
ir_node *right = get_binop_right(node);
/* if any of the operands is an immediate then this will not
* increase register pressure */
......@@ -483,11 +470,10 @@ static void mark_non_address_nodes(ir_node *node, void *env)
* else neutral) and ALU use to not fold AM. */
ia32_mark_non_am(node);
break;
}
default:
arity = get_irn_arity(node);
for (i = 0; i < arity; ++i) {
for (int i = 0, arity = get_irn_arity(node); i < arity; ++i) {
ir_node *in = get_irn_n(node, i);
ia32_mark_non_am(in);
}
......@@ -497,10 +483,8 @@ static void mark_non_address_nodes(ir_node *node, void *env)
void ia32_calculate_non_address_mode_nodes(ir_graph *irg)
{
be_lv_t *lv;
be_assure_live_chk(irg);
lv = be_get_irg_liveness(irg);
be_lv_t *lv = be_get_irg_liveness(irg);
non_address_mode_nodes = bitset_malloc(get_irg_last_idx(irg));
......
......@@ -13,23 +13,23 @@
#define IA32_ADDRESS_MODE_H
#include <stdbool.h>
#include <stdint.h>
#include "irtypes.h"
/**
* The address mode data: Used to construct (memory) address modes.
*/
typedef struct ia32_address_t ia32_address_t;
struct ia32_address_t {
ir_node *base; /**< The base register (if any) */
ir_node *index; /**< The index register (if any). */
ir_node *mem; /**< The memory value (if any). */
int offset; /**< An integer offset. */
int scale; /**< An integer scale. {0,1,2,3} */
ir_entity *symconst_ent; /**< A SynConst entity if any. */
bool use_frame; /**< Set, if the frame is accessed */
bool tls_segment; /**< Set if AM is relative to TLS */
ir_entity *frame_entity; /**< The accessed frame entity if any. */
};
typedef struct ia32_address_t {
ir_node *base; /**< value for base register (if any) */
ir_node *index; /**< value for index register (if any). */
ir_node *mem; /**< value for memory input (if any). */
int32_t offset; /**< An integer offset. */
unsigned scale : 8; /**< An integer scale. {0,1,2,3} */
bool use_frame : 1; /**< Set, if the frame is accessed */
bool tls_segment : 1; /**< Set if AM is relative to TLS */
ir_entity *symconst_ent; /**< A SymConst entity if any. */
ir_entity *frame_entity; /**< The accessed frame entity if any. */
} ia32_address_t;
/**
* Additional flags for the address mode creation.
......@@ -46,7 +46,8 @@ typedef enum ia32_create_am_flags_t {
/**
* Create an address mode for a given node.
*/
void ia32_create_address_mode(ia32_address_t *addr, ir_node *node, ia32_create_am_flags_t);
void ia32_create_address_mode(ia32_address_t *addr, ir_node *node,
ia32_create_am_flags_t);
/**
* Mark those nodes of the given graph that cannot be used inside an
......@@ -62,7 +63,7 @@ void ia32_free_non_address_mode_nodes(void);
/**
* Tells whether the given node is a non address mode node.
*/
int ia32_is_non_address_mode_node(ir_node const *node);
bool ia32_is_non_address_mode_node(ir_node const *node);
/**
* mark a node so it will not be used as part of address modes
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment