Commit 8c557d88 authored by John van Groningen's avatar John van Groningen
Browse files

remove an unnecessary record copy in the abc code for some record updates

parent 3d61cca5
...@@ -698,12 +698,7 @@ void CoerceArgumentOnTopOfStack (int *asp_p,int *bsp_p,StateS argstate,StateS no ...@@ -698,12 +698,7 @@ void CoerceArgumentOnTopOfStack (int *asp_p,int *bsp_p,StateS argstate,StateS no
++*asp_p; ++*asp_p;
break; break;
} }
#if UPDATE_POP
GenUpdatePopA (0,asize); GenUpdatePopA (0,asize);
#else
GenUpdateA (0,asize);
GenPopA (asize);
#endif
*asp_p-=asize; *asp_p-=asize;
GenPopB (bsize); GenPopB (bsize);
*bsp_p-=bsize; *bsp_p-=bsize;
...@@ -3400,9 +3395,8 @@ void RemoveSelectorsFromUpdateNode (ArgS *previous_arg,ArgS *arg) ...@@ -3400,9 +3395,8 @@ void RemoveSelectorsFromUpdateNode (ArgS *previous_arg,ArgS *arg)
previous_arg->arg_next=NULL; previous_arg->arg_next=NULL;
} }
#if UPDATE_RECORD_NOT_ON_TOP
void UpdateRecordAndAddSelectorsToUpdateNode void UpdateRecordAndAddSelectorsToUpdateNode
(ArgS *record_arg,ArgS *first_field_arg,StateS *field_states,int record_a_size,int record_b_size,int *n_a_elements_above_record_p,int *n_b_elements_above_record_p) (ArgS *record_arg,ArgS *first_field_arg,StateS *field_states,int record_a_size,int record_b_size,int *end_args_a_offset_p,int *end_args_b_offset_p)
{ {
ArgS *arg,*previous_arg; ArgS *arg,*previous_arg;
int a_offset,b_offset,arg_a_offset,arg_b_offset,previous_field_number; int a_offset,b_offset,arg_a_offset,arg_b_offset,previous_field_number;
...@@ -3452,149 +3446,50 @@ void UpdateRecordAndAddSelectorsToUpdateNode ...@@ -3452,149 +3446,50 @@ void UpdateRecordAndAddSelectorsToUpdateNode
} }
previous_arg->arg_next=NULL; previous_arg->arg_next=NULL;
*n_a_elements_above_record_p = arg_a_offset-record_a_size; *end_args_a_offset_p = arg_a_offset;
*n_b_elements_above_record_p = arg_b_offset-record_b_size; *end_args_b_offset_p = arg_b_offset;
} }
void RemoveFieldsFromStackAfterUpdate (int n_a_elements_above_record,int n_b_elements_above_record,int record_a_size,int record_b_size,int *asp_p,int *bsp_p) void RemoveFieldsFromStackAfterUpdate (int arg_a_offset,int arg_b_offset,int record_a_size,int record_b_size,int *asp_p,int *bsp_p)
{
if (n_a_elements_above_record!=0){
int arg_a_offset,a_offset;
arg_a_offset=record_a_size+n_a_elements_above_record;
a_offset=record_a_size;
while (a_offset>0){
--a_offset;
--arg_a_offset;
#if UPDATE_POP
if (a_offset==0)
GenUpdatePopA (a_offset,arg_a_offset);
else
#endif
GenUpdateA (a_offset,arg_a_offset);
}
#if UPDATE_POP
if (record_a_size==0)
#endif
GenPopA (arg_a_offset);
*asp_p -= arg_a_offset;
}
if (n_b_elements_above_record!=0){
int arg_b_offset,b_offset;
arg_b_offset=record_b_size+n_b_elements_above_record;
b_offset=record_b_size;
while (b_offset>0){
--b_offset;
--arg_b_offset;
#if UPDATE_POP
if (b_offset==0)
GenUpdatePopB (b_offset,arg_b_offset);
else
#endif
GenUpdateB (b_offset,arg_b_offset);
}
#if UPDATE_POP
if (record_b_size==0)
#endif
GenPopB (arg_b_offset);
*bsp_p -= arg_b_offset;
}
}
#else
void UpdateNodeAndAddSelectorsToUpdateNode
(ArgS *record_arg,ArgS *first_field_arg,StateS *field_states,int record_a_size,int record_b_size,int *asp_p,int *bsp_p)
{ {
ArgS *arg,*previous_arg;
int a_offset,b_offset,arg_a_offset,arg_b_offset,previous_field_number;
a_offset=0;
b_offset=0;
arg_a_offset=record_a_size;
arg_b_offset=record_b_size;
previous_field_number=0;
previous_arg=record_arg;
for_l (arg,first_field_arg,arg_next){
int field_number,arg_a_size,arg_b_size;
Node field_node;
field_node=arg->arg_node;
field_node->node_arguments->arg_next=NULL;
field_number=field_node->node_symbol->symb_def->sdef_sel_field_number;
while (field_number!=previous_field_number){
AddSizeOfState (field_states[previous_field_number],&a_offset,&b_offset);
++previous_field_number;
}
DetermineSizeOfState (field_states[field_number],&arg_a_size,&arg_b_size);
while (arg_a_size){
GenUpdateA (arg_a_offset,a_offset);
++arg_a_offset;
++a_offset;
--arg_a_size;
}
while (arg_b_size){
GenUpdateB (arg_b_offset,b_offset);
++arg_b_offset;
++b_offset;
--arg_b_size;
}
++previous_field_number;
previous_arg->arg_next=arg;
previous_arg=arg;
}
previous_arg->arg_next=NULL;
if (arg_a_offset!=record_a_size){ if (arg_a_offset!=record_a_size){
a_offset=record_a_size; if (record_a_size!=0){
while (a_offset>0){ int a_offset;
--a_offset;
--arg_a_offset; a_offset=record_a_size;
#if UPDATE_POP while (a_offset>0){
if (a_offset==0) --a_offset;
GenUpdatePopA (a_offset,arg_a_offset); --arg_a_offset;
else if (a_offset==0)
#endif GenUpdatePopA (a_offset,arg_a_offset);
GenUpdateA (a_offset,arg_a_offset); else
} GenUpdateA (a_offset,arg_a_offset);
#if UPDATE_POP }
if (record_a_size==0) } else
#endif
GenPopA (arg_a_offset); GenPopA (arg_a_offset);
*asp_p -= arg_a_offset; *asp_p -= arg_a_offset;
} }
if (arg_b_offset!=record_b_size){ if (arg_b_offset!=record_b_size){
b_offset=record_b_size; if (record_b_size!=0){
while (b_offset>0){ int b_offset;
--b_offset;
--arg_b_offset; b_offset=record_b_size;
#if UPDATE_POP while (b_offset>0){
if (b_offset==0) --b_offset;
GenUpdatePopB (b_offset,arg_b_offset); --arg_b_offset;
else if (b_offset==0)
#endif GenUpdatePopB (b_offset,arg_b_offset);
GenUpdateB (b_offset,arg_b_offset); else
} GenUpdateB (b_offset,arg_b_offset);
#if UPDATE_POP }
if (record_b_size==0) } else
#endif
GenPopB (arg_b_offset); GenPopB (arg_b_offset);
*bsp_p -= arg_b_offset; *bsp_p -= arg_b_offset;
} }
} }
#endif
#ifdef DESTRUCTIVE_RECORD_UPDATES #ifdef DESTRUCTIVE_RECORD_UPDATES
void compute_bits_and_add_selectors_to_update_node void compute_bits_and_add_selectors_to_update_node
...@@ -4020,41 +3915,27 @@ static void FillUpdateNode (Node node,int *asp_p,int *bsp_p,NodeId update_node_i ...@@ -4020,41 +3915,27 @@ static void FillUpdateNode (Node node,int *asp_p,int *bsp_p,NodeId update_node_i
#endif #endif
DetermineSizeOfState (*record_state_p,&record_a_size,&record_b_size); DetermineSizeOfState (*record_state_p,&record_a_size,&record_b_size);
#if UPDATE_RECORD_NOT_ON_TOP
{ {
int n_a_elements_above_record,n_b_elements_above_record; int end_args_a_offset,end_args_b_offset;
UpdateRecordAndAddSelectorsToUpdateNode (record_arg,first_field_arg, UpdateRecordAndAddSelectorsToUpdateNode (record_arg,first_field_arg,
record_state_p->state_record_arguments,record_a_size,record_b_size,&n_a_elements_above_record,&n_b_elements_above_record); record_state_p->state_record_arguments,record_a_size,record_b_size,&end_args_a_offset,&end_args_b_offset);
#else
UpdateNodeAndAddSelectorsToUpdateNode (record_arg,first_field_arg,
record_state_p->state_record_arguments,record_a_size,record_b_size,asp_p,bsp_p);
#endif
if (update_node_id==NULL){ if (update_node_id==NULL){
BuildRecord (record_state_p->state_record_symbol,*asp_p,*bsp_p,*asp_p,*bsp_p,record_a_size,record_b_size, BuildRecord (record_state_p->state_record_symbol,*asp_p,*bsp_p,*asp_p,*bsp_p,record_a_size,record_b_size,
0,node->node_state.state_kind==SemiStrict ? PartialFill : NormalFill,True); 0,node->node_state.state_kind==SemiStrict ? PartialFill : NormalFill,True);
*asp_p+=1; GenUpdatePopA (0,end_args_a_offset);
#if UPDATE_RECORD_NOT_ON_TOP *asp_p+=1-end_args_a_offset;
GenUpdateA (0,record_a_size+n_a_elements_above_record); } else {
#else
GenUpdateA (0,record_a_size);
#endif
} else
BuildRecord (record_state_p->state_record_symbol,*asp_p,*bsp_p,*asp_p,*bsp_p,record_a_size,record_b_size, BuildRecord (record_state_p->state_record_symbol,*asp_p,*bsp_p,*asp_p,*bsp_p,record_a_size,record_b_size,
*asp_p-update_node_id->nid_a_index,node->node_state.state_kind==SemiStrict ? PartialFill : NormalFill,False); *asp_p-update_node_id->nid_a_index,node->node_state.state_kind==SemiStrict ? PartialFill : NormalFill,False);
GenPopA (end_args_a_offset);
#if UPDATE_RECORD_NOT_ON_TOP *asp_p-=end_args_a_offset;
GenPopA (record_a_size+n_a_elements_above_record);
*asp_p-=record_a_size+n_a_elements_above_record;
GenPopB (record_b_size+n_b_elements_above_record);
*bsp_p-=record_b_size+n_b_elements_above_record;
} }
#else GenPopB (end_args_b_offset);
GenPopA (record_a_size); *bsp_p-=end_args_b_offset;
*asp_p-=record_a_size; }
GenPopB (record_b_size);
*bsp_p-=record_b_size;
#endif
return; return;
#if DESTRUCTIVE_RECORD_UPDATES #if DESTRUCTIVE_RECORD_UPDATES
} }
...@@ -4264,9 +4145,7 @@ static void FillUpdateNode (Node node,int *asp_p,int *bsp_p,NodeId update_node_i ...@@ -4264,9 +4145,7 @@ static void FillUpdateNode (Node node,int *asp_p,int *bsp_p,NodeId update_node_i
*asp_p-=n_arguments; *asp_p-=n_arguments;
} }
} else { } else {
#if UPDATE_RECORD_NOT_ON_TOP int end_args_a_offset,end_args_b_offset;
int n_a_elements_above_record,n_b_elements_above_record;
#endif
#if BOXED_RECORDS #if BOXED_RECORDS
node->node_arguments->arg_state=node->node_symbol->symb_def->sdef_record_state; node->node_arguments->arg_state=node->node_symbol->symb_def->sdef_record_state;
...@@ -4274,14 +4153,9 @@ static void FillUpdateNode (Node node,int *asp_p,int *bsp_p,NodeId update_node_i ...@@ -4274,14 +4153,9 @@ static void FillUpdateNode (Node node,int *asp_p,int *bsp_p,NodeId update_node_i
BuildArgs (node->node_arguments,asp_p,bsp_p,code_gen_node_ids_p); BuildArgs (node->node_arguments,asp_p,bsp_p,code_gen_node_ids_p);
DetermineSizeOfState (node->node_state,&record_a_size,&record_b_size); DetermineSizeOfState (node->node_state,&record_a_size,&record_b_size);
#if UPDATE_RECORD_NOT_ON_TOP
UpdateRecordAndAddSelectorsToUpdateNode (record_arg,first_field_arg, UpdateRecordAndAddSelectorsToUpdateNode (record_arg,first_field_arg,
node->node_state.state_record_arguments,record_a_size,record_b_size,&n_a_elements_above_record,&n_b_elements_above_record); node->node_state.state_record_arguments,record_a_size,record_b_size,&end_args_a_offset,&end_args_b_offset);
RemoveFieldsFromStackAfterUpdate (n_a_elements_above_record,n_b_elements_above_record,record_a_size,record_b_size,asp_p,bsp_p); RemoveFieldsFromStackAfterUpdate (end_args_a_offset,end_args_b_offset,record_a_size,record_b_size,asp_p,bsp_p);
#else
UpdateNodeAndAddSelectorsToUpdateNode (record_arg,first_field_arg,
node->node_state.state_record_arguments,record_a_size,record_b_size,asp_p,bsp_p);
#endif
} }
} }
......
...@@ -127,8 +127,9 @@ void GenTypeError (void); ...@@ -127,8 +127,9 @@ void GenTypeError (void);
void BuildArg (Args arg,int *asp_p,int *bsp_p,CodeGenNodeIdsP code_gen_node_ids_p); void BuildArg (Args arg,int *asp_p,int *bsp_p,CodeGenNodeIdsP code_gen_node_ids_p);
Bool NodeOnACycleIsInRootNormalForm (Node node); Bool NodeOnACycleIsInRootNormalForm (Node node);
void UpdateStackPointers (int old_asp,int old_bsp,int new_asp,int new_bsp); void UpdateStackPointers (int old_asp,int old_bsp,int new_asp,int new_bsp);
void UpdateNodeAndAddSelectorsToUpdateNode void UpdateRecordAndAddSelectorsToUpdateNode
(ArgS *record_arg,ArgS *first_field_arg,StateS *field_states,int record_a_size,int record_b_size,int *asp_p,int *bsp_p); (ArgS *record_arg,ArgS *first_field_arg,StateS *field_states,int record_a_size,int record_b_size,int *end_args_a_offset_p,int *end_args_b_offset_p);
void RemoveFieldsFromStackAfterUpdate (int arg_a_offset,int arg_b_offset,int record_a_size,int record_b_size,int *asp_p,int *bsp_p);
void RemoveSelectorsFromUpdateNode (ArgS *previous_arg,ArgS *arg); void RemoveSelectorsFromUpdateNode (ArgS *previous_arg,ArgS *arg);
void BuildOrFillLazyFieldSelector (SymbDef selector_sdef,StateKind result_state_kind,int *asp_p,NodeId update_node_id); void BuildOrFillLazyFieldSelector (SymbDef selector_sdef,StateKind result_state_kind,int *asp_p,NodeId update_node_id);
void CoerceArgumentOnTopOfStack (int *asp_p,int *bsp_p,StateS argstate,StateS nodestate,int asize,int bsize); void CoerceArgumentOnTopOfStack (int *asp_p,int *bsp_p,StateS argstate,StateS nodestate,int asize,int bsize);
......
...@@ -249,7 +249,6 @@ void RedirectResultAndReturn (int asp,int bsp,int source_a_index,int source_b_in ...@@ -249,7 +249,6 @@ void RedirectResultAndReturn (int asp,int bsp,int source_a_index,int source_b_in
} }
} }
} else if (IsSimpleState (demstate)){ } else if (IsSimpleState (demstate)){
#if 1 /*JVG 29-5-2000 for Clean 2.0*/
if (demstate.state_kind==StrictRedirection){ if (demstate.state_kind==StrictRedirection){
switch (offstate.state_type){ switch (offstate.state_type){
case TupleState: case TupleState:
...@@ -267,25 +266,22 @@ void RedirectResultAndReturn (int asp,int bsp,int source_a_index,int source_b_in ...@@ -267,25 +266,22 @@ void RedirectResultAndReturn (int asp,int bsp,int source_a_index,int source_b_in
GenUpdatePopA (0,asp); GenUpdatePopA (0,asp);
GenPopB (bsp); GenPopB (bsp);
} else { } else {
#endif switch (offstate.state_type){
switch (offstate.state_type){ case TupleState:
case TupleState: BuildTuple (source_a_index,source_b_index,asp,bsp,
BuildTuple (source_a_index,source_b_index,asp,bsp, offstate.state_arity, offstate.state_tuple_arguments,
offstate.state_arity, offstate.state_tuple_arguments, offasize, offbsize, 0, ReleaseAndFill,False);
offasize, offbsize, 0, ReleaseAndFill,False); break;
break; case RecordState:
case RecordState: BuildRecord (offstate.state_record_symbol,source_a_index,source_b_index, asp, bsp,
BuildRecord (offstate.state_record_symbol,source_a_index,source_b_index, asp, bsp, offasize, offbsize, 0, ReleaseAndFill,False);
offasize, offbsize, 0, ReleaseAndFill,False); break;
break; case ArrayState:
case ArrayState: GenFillArray (asp-source_a_index,asp,ReleaseAndFill);
GenFillArray (asp-source_a_index,asp,ReleaseAndFill); }
} GenPopA (asp);
GenPopA (asp); GenPopB (bsp);
GenPopB (bsp);
#if 1 /*JVG 29-5-2000 for Clean 2.0*/
} }
#endif
} else { } else {
switch (demstate.state_type){ switch (demstate.state_type){
case RecordState: case RecordState:
...@@ -1404,11 +1400,13 @@ static void CodeRootUpdateNode (Node root,NodeId rootid,int asp,int bsp,CodeGenN ...@@ -1404,11 +1400,13 @@ static void CodeRootUpdateNode (Node root,NodeId rootid,int asp,int bsp,CodeGenN
if (IsSimpleState (root->node_state)){ if (IsSimpleState (root->node_state)){
LabDef record_label; LabDef record_label;
int end_args_a_offset,end_args_b_offset;
DetermineSizeOfState (*record_state_p,&record_a_size,&record_b_size); DetermineSizeOfState (*record_state_p,&record_a_size,&record_b_size);
UpdateNodeAndAddSelectorsToUpdateNode (record_arg,first_field_arg, UpdateRecordAndAddSelectorsToUpdateNode (record_arg,first_field_arg,
record_state_p->state_record_arguments,record_a_size,record_b_size,&asp,&bsp); record_state_p->state_record_arguments,record_a_size,record_b_size,&end_args_a_offset,&end_args_b_offset);
RemoveFieldsFromStackAfterUpdate (end_args_a_offset,end_args_b_offset,record_a_size,record_b_size,&asp,&bsp);
ConvertSymbolToRLabel (&record_label,record_sdef); ConvertSymbolToRLabel (&record_label,record_sdef);
...@@ -1418,10 +1416,13 @@ static void CodeRootUpdateNode (Node root,NodeId rootid,int asp,int bsp,CodeGenN ...@@ -1418,10 +1416,13 @@ static void CodeRootUpdateNode (Node root,NodeId rootid,int asp,int bsp,CodeGenN
GenPopB (bsp); GenPopB (bsp);
GenRtn (1,0, OnAState); GenRtn (1,0, OnAState);
} else { } else {
int end_args_a_offset,end_args_b_offset;
DetermineSizeOfState (result_state,&record_a_size,&record_b_size); DetermineSizeOfState (result_state,&record_a_size,&record_b_size);
UpdateNodeAndAddSelectorsToUpdateNode (record_arg,first_field_arg, UpdateRecordAndAddSelectorsToUpdateNode (record_arg,first_field_arg,
result_state.state_record_arguments,record_a_size,record_b_size,&asp,&bsp); result_state.state_record_arguments,record_a_size,record_b_size,&end_args_a_offset,&end_args_b_offset);
RemoveFieldsFromStackAfterUpdate (end_args_a_offset,end_args_b_offset,record_a_size,record_b_size,&asp,&bsp);
if (!function_called_only_curried_or_lazy_with_one_return) if (!function_called_only_curried_or_lazy_with_one_return)
GenRtn (record_a_size,record_b_size,result_state); GenRtn (record_a_size,record_b_size,result_state);
......
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