mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-03-21 01:41:10 +00:00
Make operand->type actual type instead of low-level
And clean up the resulting mess. This fixes struct copy, but uncovers another bug :/
This commit is contained in:
parent
e0c8285f07
commit
b996fb7aa4
8 changed files with 44 additions and 45 deletions
|
@ -62,7 +62,7 @@ typedef struct dagnode_s {
|
|||
unsigned killed:1; ///< node is unavailable for cse
|
||||
st_type_t type; ///< type of node (st_none = leaf)
|
||||
daglabel_t *label; ///< ident/const if leaf node, or operator
|
||||
etype_t tl;
|
||||
struct type_s *tl;
|
||||
struct operand_s *value; ///< operand holding the value of this node
|
||||
/// \name child nodes
|
||||
/// if \a children[0] is null, the rest must be null as well. Similar for
|
||||
|
@ -75,7 +75,7 @@ typedef struct dagnode_s {
|
|||
/// topological sort of the DAG.
|
||||
//@{
|
||||
struct dagnode_s *children[3];
|
||||
etype_t types[3]; ///< desired type of each operand (to alias)
|
||||
struct type_s *types[3]; ///< desired type of each operand (to alias)
|
||||
struct set_s *edges; ///< includes nodes pointed to by \a children
|
||||
//@}
|
||||
struct set_s *identifiers; ///< set of identifiers attached to this node
|
||||
|
|
|
@ -190,14 +190,13 @@ void free_def (def_t *def);
|
|||
|
||||
\note ::current_func must be valid.
|
||||
|
||||
\param type The low-level type of the temporary variable.
|
||||
\param size The amount of space to allocate to the temp.
|
||||
\param type The type of the temporary variable.
|
||||
\return The def for the temparary variable.
|
||||
|
||||
\bug \a size is not checked for validity (must be 1-4).
|
||||
\bug size of type must be 1 to 4.
|
||||
\todo support arbitrary sizes
|
||||
*/
|
||||
def_t *temp_def (etype_t type, int size);
|
||||
def_t *temp_def (struct type_s *type);
|
||||
|
||||
/** Free a tempary def so it may be recycled.
|
||||
|
||||
|
|
|
@ -55,7 +55,7 @@ typedef struct {
|
|||
typedef struct operand_s {
|
||||
struct operand_s *next;
|
||||
op_type_e op_type;
|
||||
etype_t type; ///< possibly override def's type
|
||||
struct type_s *type; ///< possibly override def's type
|
||||
int size; ///< for structures
|
||||
union {
|
||||
struct def_s *def;
|
||||
|
@ -121,7 +121,7 @@ int tempop_overlap (tempop_t *t1, tempop_t *t2);
|
|||
operand_t *temp_operand (struct type_s *type);
|
||||
int tempop_visit_all (tempop_t *tempop, int overlap,
|
||||
int (*visit) (tempop_t *, void *), void *data);
|
||||
operand_t *alias_operand (etype_t type, operand_t *op);
|
||||
operand_t *alias_operand (struct type_s *type, operand_t *op);
|
||||
void free_operand (operand_t *op);
|
||||
|
||||
sblock_t *new_sblock (void);
|
||||
|
|
|
@ -818,7 +818,7 @@ dag_calc_node_costs (dagnode_t *dagnode)
|
|||
}
|
||||
#endif
|
||||
static operand_t *
|
||||
fix_op_type (operand_t *op, etype_t type)
|
||||
fix_op_type (operand_t *op, type_t *type)
|
||||
{
|
||||
if (op && op->op_type != op_label && op->type != type)
|
||||
op = alias_operand (type, op);
|
||||
|
@ -884,7 +884,7 @@ generate_moveps (dag_t *dag, sblock_t *block, dagnode_t *dagnode)
|
|||
|
||||
static operand_t *
|
||||
generate_assignments (dag_t *dag, sblock_t *block, operand_t *src,
|
||||
set_iter_t *var_iter, etype_t type)
|
||||
set_iter_t *var_iter, type_t *type)
|
||||
{
|
||||
statement_t *st;
|
||||
operand_t *dst = 0;
|
||||
|
@ -912,7 +912,7 @@ dag_gencode (dag_t *dag, sblock_t *block, dagnode_t *dagnode)
|
|||
statement_t *st;
|
||||
set_iter_t *var_iter;
|
||||
int i;
|
||||
etype_t type;
|
||||
type_t *type;
|
||||
|
||||
switch (dagnode->type) {
|
||||
case st_none:
|
||||
|
@ -928,7 +928,7 @@ dag_gencode (dag_t *dag, sblock_t *block, dagnode_t *dagnode)
|
|||
operands[0] = make_operand (dag, block, dagnode, 0);
|
||||
if (dagnode->children[1])
|
||||
operands[1] = make_operand (dag, block, dagnode, 1);
|
||||
type = low_level_type (get_type (dagnode->label->expr));
|
||||
type = get_type (dagnode->label->expr);
|
||||
if (!(var_iter = set_first (dagnode->identifiers))) {
|
||||
operands[2] = temp_operand (get_type (dagnode->label->expr));
|
||||
} else {
|
||||
|
|
|
@ -194,10 +194,11 @@ alias_def (def_t *def, type_t *type, int offset)
|
|||
}
|
||||
|
||||
def_t *
|
||||
temp_def (etype_t type, int size)
|
||||
temp_def (type_t *type)
|
||||
{
|
||||
def_t *temp;
|
||||
defspace_t *space = current_func->symtab->space;
|
||||
int size = type_size (type);
|
||||
|
||||
if (size < 1 || size > 4) {
|
||||
internal_error (0, "%d invalid size for temp def", size);
|
||||
|
@ -213,7 +214,7 @@ temp_def (etype_t type, int size)
|
|||
temp->name = save_string (va (".tmp%d", current_func->temp_num++));
|
||||
}
|
||||
temp->return_addr = __builtin_return_address (0);
|
||||
temp->type = ev_types[type];
|
||||
temp->type = type;
|
||||
temp->file = pr.source_file;
|
||||
temp->line = pr.source_line;
|
||||
set_storage_bits (temp, sc_local);
|
||||
|
|
|
@ -61,18 +61,18 @@
|
|||
static def_t zero_def;
|
||||
|
||||
static def_t *
|
||||
get_value_def (ex_value_t *value, etype_t type)
|
||||
get_value_def (ex_value_t *value, type_t *type)
|
||||
{
|
||||
def_t *def;
|
||||
|
||||
if (type == ev_short) {
|
||||
if (type == &type_short) {
|
||||
def = new_def (0, &type_short, 0, sc_extern);
|
||||
def->offset = value->v.short_val;
|
||||
return def;
|
||||
}
|
||||
def = emit_value (value, 0);
|
||||
if (type != def->type->type)
|
||||
return alias_def (def, ev_types[type], 0);
|
||||
if (type != def->type)
|
||||
return alias_def (def, type, 0);
|
||||
return def;
|
||||
}
|
||||
|
||||
|
@ -87,7 +87,7 @@ get_operand_def (expr_t *expr, operand_t *op)
|
|||
case op_value:
|
||||
return get_value_def (op->o.value, op->type);
|
||||
case op_label:
|
||||
op->type = ev_short;
|
||||
op->type = &type_short;
|
||||
zero_def.type = &type_short;
|
||||
return &zero_def; //FIXME
|
||||
case op_temp:
|
||||
|
@ -97,11 +97,11 @@ get_operand_def (expr_t *expr, operand_t *op)
|
|||
if (op->o.tempop.alias) {
|
||||
def_t *tdef = get_operand_def (expr, op->o.tempop.alias);
|
||||
int offset = op->o.tempop.offset;
|
||||
type_t *type = ev_types[op->type];
|
||||
type_t *type = op->type;
|
||||
op->o.tempop.def = alias_def (tdef, type, offset);
|
||||
}
|
||||
if (!op->o.tempop.def) {
|
||||
op->o.tempop.def = temp_def (op->type, op->size);
|
||||
op->o.tempop.def = temp_def (op->type);
|
||||
}
|
||||
return op->o.tempop.def;
|
||||
case op_alias:
|
||||
|
|
|
@ -102,9 +102,9 @@ opcode_find (const char *name, operand_t *op_a, operand_t *op_b,
|
|||
int i;
|
||||
|
||||
search_op.name = name;
|
||||
search_op.type_a = op_a ? op_a->type : ev_invalid;
|
||||
search_op.type_b = op_b ? op_b->type : ev_invalid;
|
||||
search_op.type_c = op_c ? op_c->type : ev_invalid;
|
||||
search_op.type_a = op_a ? low_level_type (op_a->type) : ev_invalid;
|
||||
search_op.type_b = op_b ? low_level_type (op_b->type) : ev_invalid;
|
||||
search_op.type_c = op_c ? low_level_type (op_c->type) : ev_invalid;
|
||||
op = Hash_FindElement (opcode_type_table, &search_op);
|
||||
if (op)
|
||||
return op;
|
||||
|
|
|
@ -127,7 +127,7 @@ operand_string (operand_t *op)
|
|||
case op_temp:
|
||||
if (op->o.tempop.alias)
|
||||
return va ("<tmp %s %p:%d:%p:%d:%d>",
|
||||
pr_type_name[op->type],
|
||||
pr_type_name[op->type->type],
|
||||
op, op->o.tempop.users,
|
||||
op->o.tempop.alias,
|
||||
op->o.tempop.offset,
|
||||
|
@ -139,7 +139,7 @@ operand_string (operand_t *op)
|
|||
const char *alias = operand_string (op->o.alias);
|
||||
char *buf = alloca (strlen (alias) + 1);
|
||||
strcpy (buf, alias);
|
||||
return va ("alias(%s,%s)", pr_type_name[op->type], buf);
|
||||
return va ("alias(%s,%s)", pr_type_name[op->type->type], buf);
|
||||
}
|
||||
}
|
||||
return ("??");
|
||||
|
@ -150,11 +150,11 @@ print_operand (operand_t *op)
|
|||
{
|
||||
switch (op->op_type) {
|
||||
case op_def:
|
||||
printf ("(%s) ", pr_type_name[op->type]);
|
||||
printf ("(%s) ", pr_type_name[op->type->type]);
|
||||
printf ("%s", op->o.def->name);
|
||||
break;
|
||||
case op_value:
|
||||
printf ("(%s) ", pr_type_name[op->type]);
|
||||
printf ("(%s) ", pr_type_name[op->type->type]);
|
||||
switch (op->o.value->lltype) {
|
||||
case ev_string:
|
||||
printf ("\"%s\"", op->o.value->v.string_val);
|
||||
|
@ -202,12 +202,12 @@ print_operand (operand_t *op)
|
|||
printf ("block %p", op->o.label->dest);
|
||||
break;
|
||||
case op_temp:
|
||||
printf ("tmp (%s) %p", pr_type_name[op->type], op);
|
||||
printf ("tmp (%s) %p", pr_type_name[op->type->type], op);
|
||||
if (op->o.tempop.def)
|
||||
printf (" %s", op->o.tempop.def->name);
|
||||
break;
|
||||
case op_alias:
|
||||
printf ("alias(%s,", pr_type_name[op->type]);
|
||||
printf ("alias(%s,", pr_type_name[op->type->type]);
|
||||
print_operand (op->o.alias);
|
||||
printf (")");
|
||||
}
|
||||
|
@ -307,7 +307,7 @@ def_operand (def_t *def, type_t *type)
|
|||
if (!type)
|
||||
type = def->type;
|
||||
op = new_operand (op_def);
|
||||
op->type = low_level_type (type);
|
||||
op->type = type;
|
||||
op->size = type_size (type);
|
||||
op->o.def = def;
|
||||
return op;
|
||||
|
@ -318,7 +318,7 @@ value_operand (ex_value_t *value)
|
|||
{
|
||||
operand_t *op;
|
||||
op = new_operand (op_value);
|
||||
op->type = value->lltype;
|
||||
op->type = value->type;
|
||||
op->o.value = value;
|
||||
return op;
|
||||
}
|
||||
|
@ -329,7 +329,7 @@ temp_operand (type_t *type)
|
|||
operand_t *op = new_operand (op_temp);
|
||||
|
||||
op->o.tempop.type = type;
|
||||
op->type = low_level_type (type);
|
||||
op->type = type;
|
||||
op->size = type_size (type);
|
||||
return op;
|
||||
}
|
||||
|
@ -384,19 +384,18 @@ tempop_visit_all (tempop_t *tempop, int overlap,
|
|||
}
|
||||
|
||||
operand_t *
|
||||
alias_operand (etype_t type, operand_t *op)
|
||||
alias_operand (type_t *type, operand_t *op)
|
||||
{
|
||||
operand_t *aop;
|
||||
|
||||
if (pr_type_size[type] != pr_type_size[op->type]) {
|
||||
if (type_size (type) != type_size (op->type)) {
|
||||
internal_error (0, "\naliasing operand with type of diffent size"
|
||||
" (%d, %d)", pr_type_size[type],
|
||||
pr_type_size[op->type]);
|
||||
" (%d, %d)", type_size (type), type_size (op->type));
|
||||
}
|
||||
aop = new_operand (op_alias);
|
||||
aop->o.alias = op;
|
||||
aop->type = type;
|
||||
aop->size = pr_type_size[type];
|
||||
aop->size = type_size (type);
|
||||
return aop;
|
||||
}
|
||||
|
||||
|
@ -860,14 +859,14 @@ expr_alias (sblock_t *sblock, expr_t *e, operand_t **op)
|
|||
{
|
||||
operand_t *aop = 0;
|
||||
operand_t *top;
|
||||
etype_t type;
|
||||
type_t *type;
|
||||
def_t *def;
|
||||
int offset = 0;
|
||||
|
||||
if (e->type == ex_expr) {
|
||||
offset = expr_integer (e->e.expr.e2);
|
||||
}
|
||||
type = low_level_type (e->e.expr.type);
|
||||
type = e->e.expr.type;
|
||||
sblock = statement_subexpr (sblock, e->e.expr.e1, &aop);
|
||||
if (aop->type == type) {
|
||||
if (offset) {
|
||||
|
@ -892,7 +891,7 @@ expr_alias (sblock_t *sblock, expr_t *e, operand_t **op)
|
|||
if (!top) {
|
||||
top = new_operand (op_temp);
|
||||
top->type = type;
|
||||
top->size = pr_type_size[type];
|
||||
top->size = type_size (type);
|
||||
top->o.tempop.alias = aop;
|
||||
top->o.tempop.offset = offset;
|
||||
top->next = aop->o.tempop.alias_ops;
|
||||
|
@ -903,7 +902,7 @@ expr_alias (sblock_t *sblock, expr_t *e, operand_t **op)
|
|||
def = aop->o.def;
|
||||
while (def->alias)
|
||||
def = def->alias;
|
||||
*op = def_operand (alias_def (def, ev_types[type], offset), 0);
|
||||
*op = def_operand (alias_def (def, type, offset), 0);
|
||||
} else {
|
||||
internal_error (e, "invalid alias target: %s: %s",
|
||||
optype_str (aop->op_type), operand_string (aop));
|
||||
|
@ -1037,7 +1036,7 @@ expr_symbol (sblock_t *sblock, expr_t *e, operand_t **op)
|
|||
*op = def_operand (sym->s.func->def, 0);
|
||||
} else {
|
||||
internal_error (e, "unexpected symbol type: %s for %s",
|
||||
symtype_str(sym->sy_type), sym->name);
|
||||
symtype_str (sym->sy_type), sym->name);
|
||||
}
|
||||
return sblock;
|
||||
}
|
||||
|
@ -1059,9 +1058,9 @@ expr_vector_e (sblock_t *sblock, expr_t *e, operand_t **op)
|
|||
expr_t *ax, *ay, *az, *aw;
|
||||
expr_t *as, *av;
|
||||
expr_t *tmp;
|
||||
type_t *vec_type = get_type(e);
|
||||
type_t *vec_type = get_type (e);
|
||||
|
||||
tmp = new_temp_def_expr(vec_type);
|
||||
tmp = new_temp_def_expr (vec_type);
|
||||
if (vec_type == &type_vector) {
|
||||
// guaranteed to have three elements
|
||||
x = e->e.vector.list;
|
||||
|
|
Loading…
Reference in a new issue