Commit 3f189875 authored by John van Groningen's avatar John van Groningen
Browse files

optimize apply of unknown function with two or more arguments, not yet enabled

parent 107c615a
......@@ -1619,7 +1619,7 @@ Bool NodeEntryUnboxed (StateS *const function_state_p,NodeP call_node_p,int args
void ApplyEntry (StateS *const function_state_p,int arity,Label ea_lab,int ea_label_follows)
{
CurrentAltLabel.lab_pref = l_pref;
CurrentAltLabel.lab_pref = l_pref;
if (arity==0){
GenOAStackLayout (1);
......@@ -1635,6 +1635,30 @@ void ApplyEntry (StateS *const function_state_p,int arity,Label ea_lab,int ea_la
GenPL();
}
#ifdef NEW_APPLY
if (arity>=2){
if (IsSimpleState (function_state_p[-1])){
if (function_state_p[-1].state_kind==OnB){
LabDef a_lab;
a_lab=*ea_lab;
a_lab.lab_pref="a";
GenApplyEntryDirective (0,&a_lab);
} else if (function_state_p[-1].state_kind==StrictRedirection || function_state_p[-1].state_kind==LazyRedirection){
GenApplyEntryDirective (0,ea_lab);
} else {
GenApplyEntryDirective (arity,ea_lab);
}
} else {
LabDef a_lab;
a_lab=*ea_lab;
a_lab.lab_pref="a";
GenApplyEntryDirective (0,&a_lab);
}
}
#endif
GenOAStackLayout (2);
GenLabelDefinition (&CurrentAltLabel);
......@@ -1645,17 +1669,26 @@ void ApplyEntry (StateS *const function_state_p,int arity,Label ea_lab,int ea_la
#endif
GenReplArgs (arity-1,arity-1);
#ifdef NEW_APPLY
if (arity>=2){
LabDef a_lab;
a_lab=*ea_lab;
a_lab.lab_pref="a";
GenOAStackLayout (arity);
if (DoTimeProfiling)
GenPN();
GenLabelDefinition (&a_lab);
}
#endif
if (function_called_only_curried_or_lazy_with_one_return)
return;
CallEvalArgsEntry (arity,function_state_p,0,ObjectSizes [function_state_p[-1].state_object],ea_lab);
#if SHARE_UPDATE_CODE
# if 1
result=get_label_number_from_result_state_database (&function_state_p[-1],2,&label_number);
# else
result=get_label_number_from_result_state_database (type,2,&label_number);
# endif
if (result==2){
LabDef update_label;
......@@ -1699,6 +1732,19 @@ void ApplyEntry (StateS *const function_state_p,int arity,Label ea_lab,int ea_la
#endif
GenReplArgs (arity-1, arity-1);
#ifdef NEW_APPLY
if (arity>=2){
LabDef a_lab;
a_lab=*ea_lab;
a_lab.lab_pref="a";
GenOAStackLayout (arity);
if (DoTimeProfiling)
GenPN();
GenLabelDefinition (&a_lab);
}
#endif
if (function_called_only_curried_or_lazy_with_one_return)
return;
......@@ -1706,11 +1752,7 @@ void ApplyEntry (StateS *const function_state_p,int arity,Label ea_lab,int ea_la
CallEvalArgsEntry (arity,function_state_p,asize,bsize,ea_lab);
#if SHARE_UPDATE_CODE
# if 1
result=get_label_number_from_result_state_database (&function_state_p[-1],2,&label_number);
# else
result=get_label_number_from_result_state_database (type,2,&label_number);
# endif
if (result==2){
LabDef update_label;
......
......@@ -2166,6 +2166,14 @@ static void SubSizeOfArguments (ArgS *args,int *a_offset_p,int *b_offset_p)
SubSizeOfState (arg->arg_state,a_offset_p,b_offset_p);
}
static void AddSizeOfArguments (ArgS *args,int *a_offset_p,int *b_offset_p)
{
ArgS *arg;
for_l (arg,args,arg_next)
AddSizeOfState (arg->arg_state,a_offset_p,b_offset_p);
}
void DetermineSizeOfArguments (ArgS *args,int *a_offset_p,int *b_offset_p)
{
ArgS *arg;
......@@ -2368,7 +2376,7 @@ static void FillSymbol (Node node,SymbDef sdef,int *asp_p,int *bsp_p,NodeId upda
BuildArgs (node->node_arguments,asp_p,bsp_p,code_gen_node_ids_p);
*asp_p-=a_size+1; /* changed 20-7-1999, was a_size */
*asp_p-=a_size+1;
*bsp_p-=b_size;
if (! (sdef->sdef_kind==SYSRULE
......@@ -2566,6 +2574,93 @@ static void FillSymbol (Node node,SymbDef sdef,int *asp_p,int *bsp_p,NodeId upda
}
}
#ifdef NEW_APPLY
int build_apply_arguments (ArgP node_args,int *a_size_p,int *b_size_p,int *asp_p,int *bsp_p,CodeGenNodeIdsP code_gen_node_ids_p)
{
if (node_args->arg_node->node_kind==NormalNode && node_args->arg_node->node_symbol->symb_kind==apply_symb){
ArgP next_arg;
next_arg=node_args->arg_next;
AddSizeOfState (next_arg->arg_state,a_size_p,b_size_p);
BuildArg (next_arg,asp_p,bsp_p,code_gen_node_ids_p);
return 1+build_apply_arguments (node_args->arg_node->node_arguments,a_size_p,b_size_p,asp_p,bsp_p,code_gen_node_ids_p);
} else {
AddSizeOfArguments (node_args,a_size_p,b_size_p);
BuildArgs (node_args,asp_p,bsp_p,code_gen_node_ids_p);
return 1;
}
}
static void generate_code_for_apply_in_strict_context (NodeP node,int *asp_p,int *bsp_p,CodeGenNodeIdsP code_gen_node_ids_p)
{
int a_size,b_size,n_apply_args;
ArgP node_args;
node_args=node->node_arguments;
a_size=0;
b_size=0;
n_apply_args=build_apply_arguments (node_args,&a_size,&b_size,asp_p,bsp_p,code_gen_node_ids_p);
*asp_p-=a_size;
*bsp_p-=b_size;
cleanup_stack (asp_p,bsp_p,a_size,b_size,&code_gen_node_ids_p->a_node_ids,&code_gen_node_ids_p->b_node_ids,
&code_gen_node_ids_p->free_node_ids,code_gen_node_ids_p->moved_node_ids_l,
code_gen_node_ids_p->doesnt_fail);
GenJsrAp (n_apply_args);
AddSizeOfState (node->node_state,asp_p,bsp_p);
}
static void FillApply (Node node,int *asp_p,int *bsp_p,NodeId update_node_id,CodeGenNodeIdsP code_gen_node_ids_p)
{
LabDef name;
if (IsLazyState (node->node_state)){
LabDef codelab;
ConvertSymbolToDandNLabel (&name,&codelab,ApplyDef);
BuildArgs (node->node_arguments,asp_p,bsp_p,code_gen_node_ids_p);
if (update_node_id==NULL){
*asp_p += 1-2;
GenBuild (&name,2,&codelab);
} else {
GenFill (&name,2,&codelab,*asp_p-update_node_id->nid_a_index,node->node_state.state_kind==SemiStrict ? PartialFill : NormalFill);
*asp_p -= 2;
}
} else {
if (update_node_id!=NULL && update_node_id->nid_a_index!=*asp_p){
int a_size,b_size;
DetermineSizeOfArguments (node->node_arguments,&a_size,&b_size);
GenPushA (*asp_p-update_node_id->nid_a_index);
*asp_p += SizeOfAStackElem;
BuildArgs (node->node_arguments,asp_p,bsp_p,code_gen_node_ids_p);
*asp_p-=a_size+1;
*bsp_p-=b_size;
cleanup_stack (asp_p,bsp_p,a_size+1,b_size,&code_gen_node_ids_p->a_node_ids,&code_gen_node_ids_p->b_node_ids,
&code_gen_node_ids_p->free_node_ids,code_gen_node_ids_p->moved_node_ids_l,
code_gen_node_ids_p->doesnt_fail);
GenJsrAp (1);
AddSizeOfState (node->node_state,asp_p,bsp_p);
GenPopA (1);
*asp_p-=1;
} else
generate_code_for_apply_in_strict_context (node,asp_p,bsp_p,code_gen_node_ids_p);
}
}
#endif
void GenTypeError (void)
{
GenDAStackLayout (0);
......@@ -2927,7 +3022,11 @@ static void FillNormalNode (Node node,int *asp_p,int *bsp_p,NodeId update_node_i
FillOrReduceSelectSymbol (node,asp_p,bsp_p,update_node_id,code_gen_node_ids_p);
return;
case apply_symb:
#ifdef NEW_APPLY
FillApply (node,asp_p,bsp_p,update_node_id,code_gen_node_ids_p);
#else
FillSymbol (node,ApplyDef,asp_p,bsp_p,update_node_id,code_gen_node_ids_p);
#endif
return;
case if_symb:
#ifdef FASTER_STRICT_IF
......@@ -4734,8 +4833,16 @@ void build_and_cleanup (Node node,int *asp_p,int *bsp_p,CodeGenNodeIdsP code_gen
sdef=node->node_symbol->symb_def;
break;
case apply_symb:
#ifdef NEW_APPLY
if (!IsLazyState (node->node_state))
generate_code_for_apply_in_strict_context (node,asp_p,bsp_p,code_gen_node_ids_p);
else
Build (node,asp_p,bsp_p,code_gen_node_ids_p);
return;
#else
sdef=ApplyDef;
break;
#endif
#ifndef FASTER_STRICT_IF
case if_symb:
sdef=IfDef;
......@@ -4760,17 +4867,11 @@ void build_and_cleanup (Node node,int *asp_p,int *bsp_p,CodeGenNodeIdsP code_gen
node_args=node->node_arguments;
DetermineSizeOfArguments (node_args,&a_size,&b_size);
#if 1
if (ExpectsResultNode (node->node_state))
BuildArgsWithNewResultNode (node_args,asp_p,bsp_p,code_gen_node_ids_p,&a_size,&b_size);
else
#else
if (ExpectsResultNode (node->node_state)){
NewEmptyNode (asp_p,-1);
++a_size;
}
#endif
BuildArgs (node_args,asp_p,bsp_p,code_gen_node_ids_p);
BuildArgs (node_args,asp_p,bsp_p,code_gen_node_ids_p);
*asp_p-=a_size;
*bsp_p-=b_size;
......
......@@ -597,6 +597,43 @@ static void CodeRootSymbolApplication (Node root,NodeId rootid,SymbDef def,int a
}
}
#ifdef NEW_APPLY
extern int build_apply_arguments (ArgP node_args,int *a_size_p,int *b_size_p,int *asp_p,int *bsp_p,CodeGenNodeIdsP code_gen_node_ids_p);
static void CodeRootApply (Node root,NodeId rootid,int asp,int bsp,CodeGenNodeIdsP code_gen_node_ids_p,StateS resultstate)
{
if (IsSemiStrictState (root->node_state)){
LabDef name,codelab;
ConvertSymbolToDandNLabel (&name,&codelab,ApplyDef);
CreateSemiStrictRootNode (&name,&codelab,root,rootid,asp,bsp,code_gen_node_ids_p,resultstate);
} else {
int a_size,b_size,n_apply_args;
a_size=0;
b_size=0;
n_apply_args=build_apply_arguments (root->node_arguments,&a_size,&b_size,&asp,&bsp,code_gen_node_ids_p);
UpdateAAndBStack (asp,bsp,a_size,b_size,&asp,&bsp);
if (!IsSimpleState (resultstate) || resultstate.state_kind!=StrictRedirection){
int result_a_size,result_b_size;
GenJsrAp (n_apply_args);
DetermineSizeOfState (root->node_state,&result_a_size,&result_b_size);
asp+=result_a_size-a_size;
bsp+=result_b_size-b_size;
RedirectResultAndReturn (asp,bsp,asp,bsp,root->node_state,resultstate,result_a_size,result_b_size);
} else
GenJmpAp (n_apply_args);
}
}
#endif
static void CodeRootSelection (Node root, NodeId rootid,int asp,int bsp,CodeGenNodeIdsP code_gen_node_ids_p,StateS demstate)
{
Args args;
......@@ -844,7 +881,11 @@ static void CodeNormalRootNode (Node root,NodeId rootid,int asp,int bsp,CodeGenN
FillRhsRoot (&nil_lab, root, asp, bsp,code_gen_node_ids_p);
return;
case apply_symb:
#ifdef NEW_APPLY
CodeRootApply (root, rootid, asp, bsp,code_gen_node_ids_p,resultstate);
#else
CodeRootSymbolApplication (root, rootid, ApplyDef, asp, bsp,code_gen_node_ids_p,resultstate);
#endif
return;
case if_symb:
#ifdef FASTER_STRICT_IF
......
......@@ -23,4 +23,6 @@
#define STRICT_LISTS 1
#define BOXED_RECORDS 1
#undef NEW_APPLY
#define KARBON
......@@ -2648,12 +2648,14 @@ void GenNodeEntryDirective (int arity,Label label,Label label2)
}
}
#ifdef NEW_APPLY
void GenApplyEntryDirective (int arity,Label label)
{
put_directive_b (a);
put_arguments_n__b (arity);
GenLabel (label);
}
#endif
void GenLazyRecordNodeEntryDirective (int arity,Label label)
{
......
......@@ -159,6 +159,9 @@ void GenNodeEntryDirective (int arity,Label label,Label label2);
void GenNodeEntryDirectiveForLabelWithoutSymbol (int arity,Label label,Label label2);
void GenNodeEntryDirectiveUnboxed (int a_size,int b_size,Label label,Label label2);
void GenApplyEntryDirective (int arity,Label label);
#ifdef NEW_APPLY
void GenApplyEntryDirective (int arity,Label label);
#endif
void GenLazyRecordNodeEntryDirective (int arity,Label label);
void GenFieldNodeEntryDirective (int arity, Label label, Label label2,char *record_name);
void GenConstructorDescriptorAndExport (SymbDef sdef);
......
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