diff options
author | John van Groningen | 2005-04-14 11:29:21 +0000 |
---|---|---|
committer | John van Groningen | 2005-04-14 11:29:21 +0000 |
commit | aa5590ea80cd080e495ff82f6da2fda75277b244 (patch) | |
tree | 5168a9364136795bc54094430b8cdadc3779dd64 | |
parent | use fmadd also when add uses indirect load (diff) |
add some optimizations for arrays of unboxed records:
on the PowerPC and Sparc if the offset!=0 and the index!=NULL
the index now contains the address of array + the offset of the
element,
the offset computation of r_select can be reused by r_update,
r_update tries to avoid unnecessary updates,
r_replace recognizes floating point stores, and sometimes
floating point loads
-rw-r--r-- | cgcode.c | 150 | ||||
-rw-r--r-- | cginstructions.c | 37 | ||||
-rw-r--r-- | cglin.c | 65 |
3 files changed, 165 insertions, 87 deletions
@@ -6013,25 +6013,18 @@ static void code_r_replace (int a_size,int b_size) offset=12; graph_3=multiply_by_constant ((a_size+b_size)<<2,graph_2); + +#if defined (sparc) || defined (G_POWER) + graph_3=g_add (graph_1,graph_3); +#endif } for (i=0; i<a_size; ++i){ INSTRUCTION_GRAPH graph_4,graph_5; graph_4=s_get_a (i+1); -#if defined (sparc) || defined (G_POWER) - if (offset+(i<<2)!=0 && graph_3!=NULL){ - INSTRUCTION_GRAPH graph_6; - - graph_6=g_add (g_load_i (offset+(i<<2)),graph_3); - graph_5=g_load_x (graph_1,0,0,graph_6); - graph_1=g_store_x (graph_4,graph_1,0,0,graph_6); - } else -#endif - { - graph_5=g_load_x (graph_1,offset+(i<<2),0,graph_3); - graph_1=g_store_x (graph_4,graph_1,offset+(i<<2),0,graph_3); - } + graph_5=g_load_x (graph_1,offset+(i<<2),0,graph_3); + graph_1=g_store_x (graph_4,graph_1,offset+(i<<2),0,graph_3); s_put_a (i,graph_5); } @@ -6040,19 +6033,30 @@ static void code_r_replace (int a_size,int b_size) INSTRUCTION_GRAPH graph_4,graph_5; graph_4=s_get_b (i); -#if defined (sparc) || defined (G_POWER) - if (offset+((a_size+i)<<2)!=0 && graph_3!=NULL){ - INSTRUCTION_GRAPH graph_6; + + if (graph_4->instruction_code==GFHIGH && i+1<b_size){ + INSTRUCTION_GRAPH graph_5; - graph_6=g_add (g_load_i (offset+((a_size+i)<<2)),graph_3); - graph_5=g_load_x (graph_1,0,0,graph_6); - graph_1=g_store_x (graph_4,graph_1,0,0,graph_6); - } else -#endif - { - graph_5=g_load_x (graph_1,offset+((a_size+i)<<2),0,graph_3); - graph_1=g_store_x (graph_4,graph_1,offset+((a_size+i)<<2),0,graph_3); + graph_5=s_get_b (i+1); + if (graph_5->instruction_code==GFLOW && graph_4->instruction_parameters[0].p==graph_5->instruction_parameters[0].p){ + INSTRUCTION_GRAPH graph_6,graph_7,graph_8,graph_9; + + graph_6=g_fjoin (graph_4,graph_5); + graph_7=g_fload_x (graph_1,offset+((a_size+i)<<2),0,graph_3); + graph_1=g_fstore_x (graph_6,graph_1,offset+((a_size+i)<<2),0,graph_3); + + g_fhighlow (graph_8,graph_9,graph_7); + + s_put_b (i+1,graph_9); + s_put_b (i,graph_8); + ++i; + + continue; + } } + + graph_5=g_load_x (graph_1,offset+((a_size+i)<<2),0,graph_3); + graph_1=g_store_x (graph_4,graph_1,offset+((a_size+i)<<2),0,graph_3); s_put_b (i,graph_5); } @@ -6676,16 +6680,15 @@ static void code_r_select (int a_size,int b_size) offset=12; graph_3=multiply_by_constant ((a_size+b_size)<<2,graph_2); + +#if defined (sparc) || defined (G_POWER) + graph_3=g_add (graph_1,graph_3); +#endif } for (i=a_size-1; i>=0; --i){ INSTRUCTION_GRAPH graph_4; -#if defined (sparc) || defined (G_POWER) - if (offset+(i<<2)!=0 && graph_3!=NULL) - graph_4=g_load_x (graph_1,0,0,g_add (g_load_i (offset+(i<<2)),graph_3)); - else -#endif graph_4=g_load_x (graph_1,offset+(i<<2),0,graph_3); s_push_a (graph_4); } @@ -6693,11 +6696,6 @@ static void code_r_select (int a_size,int b_size) for (i=b_size-1; i>=0; --i){ INSTRUCTION_GRAPH graph_4; -#if defined (sparc) || defined (G_POWER) - if (offset+((a_size+i)<<2)!=0 && graph_3!=NULL) - graph_4=g_load_x (graph_1,0,0,g_add (g_load_i (offset+((a_size+i)<<2)),graph_3)); - else -#endif graph_4=g_load_x (graph_1,offset+((a_size+i)<<2),0,graph_3); s_push_b (graph_4); } @@ -7236,9 +7234,28 @@ static void code_updateR (VOID) s_put_a (0,graph_8); } +static int equal_graph (INSTRUCTION_GRAPH graph_0,INSTRUCTION_GRAPH graph_1) +{ + if (graph_0==graph_1) + return 1; + + if (graph_0->instruction_code==graph_1->instruction_code){ + switch (graph_0->instruction_code){ + case GADD: + case GLSL: + return equal_graph (graph_0->instruction_parameters[0].p,graph_1->instruction_parameters[0].p) + && equal_graph (graph_0->instruction_parameters[1].p,graph_1->instruction_parameters[1].p); + case GLOAD_I: + return graph_0->instruction_parameters[0].i==graph_1->instruction_parameters[0].i; + } + } + + return 0; +} + static void code_r_update (int a_size,int b_size) { - INSTRUCTION_GRAPH graph_1,graph_2,graph_3; + INSTRUCTION_GRAPH graph_1,graph_2,graph_3,graph_7; int i,element_size,offset; graph_1=s_pop_a(); @@ -7252,22 +7269,42 @@ static void code_r_update (int a_size,int b_size) offset=12+graph_2->instruction_parameters[0].i*element_size; graph_3=NULL; } else { + INSTRUCTION_GRAPH select_graph; + if (check_index_flag) graph_2=g_bounds (graph_1,graph_2); offset=12; graph_3=multiply_by_constant (element_size,graph_2); + +#if defined (sparc) || defined (G_POWER) + graph_3=g_add (graph_1,graph_3); +#endif + + select_graph=load_indexed_list; + + while (select_graph!=NULL){ + if (select_graph->instruction_code==GLOAD_X || select_graph->instruction_code==GFLOAD_X){ + if (select_graph->instruction_parameters[0].p==graph_1){ + INSTRUCTION_GRAPH graph_4; + + graph_4=select_graph->instruction_parameters[2].p; + if (graph_4!=NULL && equal_graph (graph_4,graph_3)){ + graph_3=graph_4; + break; + } + } + } + select_graph=select_graph->instruction_parameters[3].p; + } } + graph_7=graph_1; + for (i=0; i<a_size; ++i){ INSTRUCTION_GRAPH graph_4; graph_4=s_pop_a(); -#if defined (sparc) || defined (G_POWER) - if (offset+(i<<2)!=0 && graph_3!=NULL) - graph_1=g_store_x (graph_4,graph_1,0,0,g_add (g_load_i (offset+(i<<2)),graph_3)); - else -#endif graph_1=g_store_x (graph_4,graph_1,offset+(i<<2),0,graph_3); } @@ -7276,36 +7313,35 @@ static void code_r_update (int a_size,int b_size) graph_4=s_pop_b(); - /* added 16-10-2001 */ if (graph_4->instruction_code==GFHIGH && i+1<b_size){ INSTRUCTION_GRAPH graph_5,graph_6; graph_5=s_get_b (0); if (graph_5->instruction_code==GFLOW && graph_4->instruction_parameters[0].p==graph_5->instruction_parameters[0].p){ - s_pop_b(); graph_6=g_fjoin (graph_4,graph_5); -#if defined (sparc) || defined (G_POWER) - if (offset+((a_size+i)<<2)!=0 && graph_3!=NULL) - graph_1=g_fstore_x (graph_6,graph_1,0,0,g_add (g_load_i (offset+((a_size+i)<<2)),graph_3)); - else -#endif - graph_1=g_fstore_x (graph_6,graph_1,offset+((a_size+i)<<2),0,graph_3); - ++i; + if (! ( graph_6->instruction_code==GFLOAD_X && + graph_6->instruction_parameters[0].p==graph_7 && + graph_6->instruction_parameters[1].i==((offset+((a_size+i)<<2))<<2) && + graph_6->instruction_parameters[2].p==graph_3)) + { + graph_1=g_fstore_x (graph_6,graph_1,offset+((a_size+i)<<2),0,graph_3); + } + ++i; continue; } } - /* */ - -#if defined (sparc) || defined (G_POWER) - if (offset+((a_size+i)<<2)!=0 && graph_3!=NULL) - graph_1=g_store_x (graph_4,graph_1,0,0,g_add (g_load_i (offset+((a_size+i)<<2)),graph_3)); - else -#endif - graph_1=g_store_x (graph_4,graph_1,offset+((a_size+i)<<2),0,graph_3); + + if (! ( graph_4->instruction_code==GLOAD_X && + graph_4->instruction_parameters[0].p==graph_7 && + graph_4->instruction_parameters[1].i==((offset+((a_size+i)<<2))<<2) && + graph_4->instruction_parameters[2].p==graph_3)) + { + graph_1=g_store_x (graph_4,graph_1,offset+((a_size+i)<<2),0,graph_3); + } } s_push_a (graph_1); diff --git a/cginstructions.c b/cginstructions.c index d1da2b3..3fe3ad8 100644 --- a/cginstructions.c +++ b/cginstructions.c @@ -498,9 +498,7 @@ INSTRUCTION_GRAPH g_fjoin (INSTRUCTION_GRAPH graph_1,INSTRUCTION_GRAPH graph_2) previous_loadx=&load_indexed_list; - /* added 25-10-2001 */ while (*previous_loadx!=NULL && *previous_loadx!=graph_1) - /* while (*previous_loadx!=graph_1) */ previous_loadx=&(*previous_loadx)->instruction_parameters[3].p; fload_graph=g_new_node (GFLOAD_X,0,4*sizeof (union instruction_parameter)); @@ -511,9 +509,7 @@ INSTRUCTION_GRAPH g_fjoin (INSTRUCTION_GRAPH graph_1,INSTRUCTION_GRAPH graph_2) fload_graph->instruction_parameters[3].p=graph_2->instruction_parameters[3].p; - /* added 25-10-2001 */ if (*previous_loadx!=NULL) - /* */ *previous_loadx=fload_graph; fload_graph->instruction_d_min_a_cost+=1; @@ -571,10 +567,9 @@ INSTRUCTION_GRAPH g_fload_id (int offset,INSTRUCTION_GRAPH graph_1) return instruction; } -INSTRUCTION_GRAPH g_fload_x - (INSTRUCTION_GRAPH graph_1,int offset,int shift,INSTRUCTION_GRAPH graph_2) +INSTRUCTION_GRAPH g_fload_x (INSTRUCTION_GRAPH graph_1,int offset,int shift,INSTRUCTION_GRAPH graph_2) { - register INSTRUCTION_GRAPH instruction; + INSTRUCTION_GRAPH instruction; instruction=g_new_node (GFLOAD_X,0,4*sizeof (union instruction_parameter)); @@ -582,7 +577,12 @@ INSTRUCTION_GRAPH g_fload_x instruction->instruction_parameters[1].i=(offset<<2) | shift; instruction->instruction_parameters[2].p=graph_2; instruction->instruction_parameters[3].p=load_indexed_list; - + +#if defined (sparc) || defined (G_POWER) + if (offset!=0 && graph_2!=NULL) + graph_2->instruction_d_min_a_cost+=1; + else +#endif graph_1->instruction_d_min_a_cost+=1; load_indexed_list=instruction; @@ -714,7 +714,12 @@ INSTRUCTION_GRAPH g_load_x (INSTRUCTION_GRAPH graph_1,int offset,int shift,INSTR instruction->instruction_parameters[1].i=(offset<<2) | shift; instruction->instruction_parameters[2].p=graph_2; instruction->instruction_parameters[3].p=load_indexed_list; - + +#if defined (sparc) || defined (G_POWER) + if (offset!=0 && graph_2!=NULL) + graph_2->instruction_d_min_a_cost+=1; + else +#endif graph_1->instruction_d_min_a_cost+=1; load_indexed_list=instruction; @@ -821,7 +826,12 @@ INSTRUCTION_GRAPH g_fstore_x (INSTRUCTION_GRAPH graph_1,INSTRUCTION_GRAPH graph_ instruction->instruction_parameters[2].i=(offset<<2) | shift; instruction->instruction_parameters[3].p=graph_3; instruction->instruction_parameters[4].p=load_indexed_list; - + +#if defined (sparc) || defined (G_POWER) + if (offset!=0 && graph_3!=NULL) + graph_3->instruction_d_min_a_cost+=1; + else +#endif graph_2->instruction_d_min_a_cost+=1; return instruction; @@ -902,7 +912,12 @@ INSTRUCTION_GRAPH g_store_x (INSTRUCTION_GRAPH graph_1,INSTRUCTION_GRAPH graph_2 instruction->instruction_parameters[2].i=(offset<<2) | shift; instruction->instruction_parameters[3].p=graph_3; instruction->instruction_parameters[4].p=load_indexed_list; - + +#if defined (sparc) || defined (G_POWER) + if (offset!=0 && graph_3!=NULL) + graph_3->instruction_d_min_a_cost+=1; + else +#endif graph_2->instruction_d_min_a_cost+=1; return instruction; @@ -6231,6 +6231,13 @@ static void linearize_fload_x_operator (INSTRUCTION_GRAPH graph,ADDRESS *ad_p) offset=graph->instruction_parameters[1].i; graph_2=graph->instruction_parameters[2].p; +#if defined (sparc) || defined (G_POWER) + if (offset!=0 && graph_2!=NULL){ + graph_1=graph_2; + graph_2=NULL; + } +#endif + if (graph_2!=NULL){ ADDRESS ad_1; @@ -6742,6 +6749,13 @@ static void linearize_load_x_operator (INSTRUCTION_GRAPH graph,ADDRESS *ad_p offset=graph->instruction_parameters[1].i; graph_2=graph->instruction_parameters[2].p; +#if defined (sparc) || defined (G_POWER) + if (offset!=0 && graph_2!=NULL){ + graph_1=graph_2; + graph_2=NULL; + } +#endif + if (graph_2!=NULL){ ADDRESS ad_1; @@ -7330,7 +7344,7 @@ static void linearize_store_x_operator (int i_instruction_code,register INSTRUCT INSTRUCTION_GRAPH graph_1,graph_2,graph_3; int offset; ADDRESS ad_1,ad_3; - + graph_1=graph->instruction_parameters[0].p; graph_2=graph->instruction_parameters[1].p; offset=graph->instruction_parameters[2].i; @@ -7380,7 +7394,7 @@ static void linearize_store_x_operator (int i_instruction_code,register INSTRUCT internal_error_in_function ("linearize_store_x_operator"); } } - + do_array_selects_before_update (graph->instruction_parameters[4].p,graph_1,graph_2); in_address_register (ad_p); @@ -7390,6 +7404,13 @@ static void linearize_store_x_operator (int i_instruction_code,register INSTRUCT in_data_register (&ad_1); instruction_ad_id (i_instruction_code,&ad_1,offset>>2,ad_p->ad_register); +#if defined (sparc) || defined (G_POWER) + } else if (offset!=0){ + if (i_instruction_code==IMOVEB && ad_1.ad_mode!=P_IMMEDIATE) + in_data_register (&ad_1); + + instruction_ad_id (i_instruction_code,&ad_1,offset>>2,ad_3.ad_register); +#endif } else { in_data_register (&ad_3); @@ -7410,32 +7431,23 @@ static void linearize_store_x_operator (int i_instruction_code,register INSTRUCT instruction_ad_x (i_instruction_code,&ad_1,offset,ad_p->ad_register,ad_3.ad_register); } - + if (graph->node_count>1){ -/* added 10-12-97 */ - /* changed 27-6-2001 */ - while (graph_2->instruction_code==GINDIRECTION) graph_2=graph_2->instruction_parameters[0].p; if (graph_2->instruction_code==GREGISTER){ - /* if (graph_2->instruction_code==GREGISTER || graph_2->instruction_code==GINDIRECTION){ */ - register_node (graph_2,ad_p->ad_register); graph_2->node_count += graph->node_count; ad_p->ad_count_p=&graph_2->node_count; graph->instruction_parameters[0].p=graph_2; graph->instruction_code=GINDIRECTION; - } else -/* */ - { + } else { register_node (graph,ad_p->ad_register); ad_p->ad_count_p=&graph->node_count; } - } -/* added 27-6-2001 */ - else { + } else { if (graph_2->instruction_code==GREGISTER){ graph->instruction_parameters[0].p=graph_2; graph->instruction_code=GINDIRECTION; @@ -7444,7 +7456,6 @@ static void linearize_store_x_operator (int i_instruction_code,register INSTRUCT graph->instruction_code=GINDIRECTION; } } -/**/ } static void linearize_bounds_operator (INSTRUCTION_GRAPH graph,ADDRESS *ad_p) @@ -8058,8 +8069,8 @@ static void linearize_graph (INSTRUCTION_GRAPH graph,ADDRESS *ad_p) static void linearize_fstore_x_operator (register INSTRUCTION_GRAPH graph,register ADDRESS *ad_p) { - register INSTRUCTION_GRAPH graph_1,graph_2,graph_3; - register int offset; + INSTRUCTION_GRAPH graph_1,graph_2,graph_3; + int offset; ADDRESS ad_1,ad_3; graph_1=graph->instruction_parameters[0].p; @@ -8111,7 +8122,7 @@ static void linearize_fstore_x_operator (register INSTRUCTION_GRAPH graph,regist internal_error_in_function ("linearize_fstore_x_operator"); } } - + do_array_selects_before_update (graph->instruction_parameters[4].p,graph_1,graph_2); in_address_register (ad_p); @@ -8129,6 +8140,22 @@ static void linearize_fstore_x_operator (register INSTRUCTION_GRAPH graph,regist } else #endif move_float_ad_id (&ad_1,offset>>2,ad_p->ad_register); +#if defined (sparc) || defined (G_POWER) + } else if (offset!=0){ + in_address_register (&ad_3); +# ifdef ALIGN_REAL_ARRAYS + if (ad_1.ad_mode==P_F_REGISTER){ + i_fmove_fr_id_f (ad_1.ad_register,offset>>2,ad_3.ad_register,graph->inode_arity & LOAD_STORE_ALIGNED_REAL); + if (--*ad_1.ad_count_p==0){ +# ifdef FP_STACK_OPTIMIZATIONS + last_instruction->instruction_parameters[0].parameter_flags |= FP_REG_LAST_USE; +# endif + free_fregister (ad_1.ad_register); + } + } else +# endif + move_float_ad_id (&ad_1,offset>>2,ad_3.ad_register); +#endif } else { in_data_register (&ad_3); @@ -8149,7 +8176,7 @@ static void linearize_fstore_x_operator (register INSTRUCTION_GRAPH graph,regist move_float_ad_x (&ad_1,offset,ad_p->ad_register,ad_3.ad_register); #endif } - + if (graph->node_count>1){ register_node (graph,ad_p->ad_register); ad_p->ad_count_p=&graph->node_count; |