1 /* file "for_normalize.cc" */
5 Copyright (C) 1994 Stanford University
9 NOTICE: This software is provided ``as is'', without any
10 warranty, including any implied warranty for merchantability or
11 fitness for a particular purpose. Under no circumstances shall
12 Stanford University or its agents be liable for any use of, misuse
13 of, or inability to use this software, including incidental and
14 consequential damages.
16 License is hereby given to use, modify, and redistribute this
17 software, in whole or in part, for any purpose, commercial or
18 non-commercial, provided that the user agrees to the terms of this
19 copyright notice, including disclaimer of warranty, and provided
20 that this copyright notice, including disclaimer of warranty, is
21 preserved in the source code and documentation of anything derived
22 from this software. Any redistributor of this software or
23 anything derived from this software assumes responsibility for
24 ensuring that any parties to whom such a redistribution is made
25 are fully aware of the terms of this license and disclaimer.
27 "SUIF" is a trademark of Stanford University.
32 /* code to normalize for loops to have zero lower bound and step size
33 * of one for the porky program for SUIF */
35 #include "for_normalize.h"
37 static instruction_list
*normalized
;
39 static void normalize_fors_on_node(tree_node
*the_node
, void *);
41 extern instruction_list
*normalized_fors_on_proc(tree_proc
*the_proc
)
43 normalized
= new instruction_list
;
44 the_proc
->map(&normalize_fors_on_node
, NULL
);
45 if (normalized
->is_empty()) {
52 static void normalize_fors_on_node(tree_node
*the_node
, void *)
54 if (!the_node
->is_for())
57 tree_for
*the_for
= (tree_for
*)the_node
;
60 boolean step_is_int
= operand_is_int_const(the_for
->step_op(), &step_int
);
62 if (step_is_int
&& (step_int
== 1))
67 if (!operand_is_int_const(the_for
->lb_op()))
68 make_lb_temp(the_for
);
69 if (!operand_is_int_const(the_for
->step_op()))
70 make_step_temp(the_for
);
72 operand old_lb_op
= the_for
->lb_op();
73 operand old_step_op
= the_for
->step_op();
75 if (!operand_is_int_const(the_for
->ub_op()))
76 make_ub_temp(the_for
);
78 tree_for_test new_test
;
79 switch (the_for
->test())
97 var_sym
*old_index
= the_for
->index();
98 type_node
*index_type
= old_index
->type()->unqual();
99 var_sym
*new_index
= the_for
->scope()->new_unique_var(index_type
);
101 operand new_ub_op
= cast_op(iteration_count(the_for
) - 1, index_type
);
104 old_step_op
.remove();
106 operand old_ub_op
= the_for
->ub_op();
108 if (old_ub_op
.is_expr())
109 delete old_ub_op
.instr();
111 the_for
->set_lb_op(operand_int(index_type
, 0));
112 the_for
->set_ub_op(new_ub_op
);
113 the_for
->set_step_op(operand_int(index_type
, 1));
115 the_for
->set_test(new_test
);
117 the_for
->set_index(new_index
);
120 #ifndef DEAL_WITH_SOLARIS_BRAIN_DAMAGE
121 cast_op((new_index
* old_step_op
) + old_lb_op
, index_type
);
123 cast_op(fold_mul(new_index
, old_step_op
) + old_lb_op
, index_type
);
125 tree_node
*assign_node
= assign(old_index
, old_ind_op
);
126 tree_node
*assign_node2
= assign_node
->clone();
127 the_for
->body()->push(assign_node2
);
128 the_for
->parent()->insert_after(assign_node
, the_for
->list_e());
129 normalized
->push(((tree_instr
*)assign_node
)->instr());
130 normalized
->push(((tree_instr
*)assign_node2
)->instr());
133 /*----------------------------------------------------------------------*
134 End Private Function Implementations
135 *----------------------------------------------------------------------*/