From 3e4198ea4534a6f73495a089702f2d7d862a2f7c Mon Sep 17 00:00:00 2001 From: florian Date: Sat, 8 Feb 2014 21:47:46 +0000 Subject: [PATCH] * take care of dyn. arrays in cse git-svn-id: trunk@26740 - --- compiler/htypechk.pas | 3 +++ compiler/nbas.pas | 3 ++- compiler/optcse.pas | 17 ++++++++++++----- compiler/symdef.pas | 7 +++++++ 4 files changed, 24 insertions(+), 6 deletions(-) diff --git a/compiler/htypechk.pas b/compiler/htypechk.pas index b49734dfab..3524c9101b 100644 --- a/compiler/htypechk.pas +++ b/compiler/htypechk.pas @@ -1157,6 +1157,9 @@ implementation vecn: begin set_varstate(tbinarynode(p).right,vs_read,[vsf_must_be_valid]); + { dyn. arrays and dyn. strings are read } + if is_implicit_array_pointer(tunarynode(p).left.resultdef) then + newstate:=vs_read; if (newstate in [vs_read,vs_readwritten]) or not(tunarynode(p).left.resultdef.typ in [stringdef,arraydef]) then include(varstateflags,vsf_must_be_valid) diff --git a/compiler/nbas.pas b/compiler/nbas.pas index 3a5d22c31e..fb12f8649f 100644 --- a/compiler/nbas.pas +++ b/compiler/nbas.pas @@ -918,7 +918,8 @@ implementation begin result := nil; expectloc:=LOC_VOID; - if (tempinfo^.typedef.needs_inittable) then + { temps which are immutable do not need to be initialized/finalized } + if (tempinfo^.typedef.needs_inittable) and not(ti_const in tempinfo^.flags) then include(current_procinfo.flags,pi_needs_implicit_finally); if (cs_create_pic in current_settings.moduleswitches) and (tf_pic_uses_got in target_info.flags) and diff --git a/compiler/optcse.pas b/compiler/optcse.pas index 0634a213e7..e725ce8acb 100644 --- a/compiler/optcse.pas +++ b/compiler/optcse.pas @@ -152,9 +152,9 @@ unit optcse; ( { regable expressions } (actualtargetnode(@n)^.flags*[nf_write,nf_modify,nf_address_taken]=[]) and - ((tstoreddef(n.resultdef).is_intregable or tstoreddef(n.resultdef).is_fpuregable) and + ((((tstoreddef(n.resultdef).is_intregable or tstoreddef(n.resultdef).is_fpuregable) and { is_int/fpuregable allows arrays and records to be in registers, cse cannot handle this } - (not(n.resultdef.typ in [arraydef,recorddef])) and + (not(n.resultdef.typ in [arraydef,recorddef]))) or is_dynamic_array(n.resultdef)) and { same for voiddef } not(is_void(n.resultdef)) and { adding tempref and callpara nodes itself is worthless but @@ -374,14 +374,21 @@ unit optcse; def:=tstoreddef(tnode(lists.nodelist[i]).resultdef); { we cannot handle register stored records or array in CSE yet but we can store their reference } - addrstored:=(def.typ in [arraydef,recorddef]) or is_object(def); + addrstored:=((def.typ in [arraydef,recorddef]) or is_object(def)) and not(is_dynamic_array(def)); if addrstored then templist[i]:=ctempcreatenode.create_value(getpointerdef(def),voidpointertype.size,tt_persistent, true,caddrnode.create_internal(tnode(lists.nodelist[i]))) else templist[i]:=ctempcreatenode.create_value(def,def.size,tt_persistent, - def.is_intregable or def.is_fpuregable,tnode(lists.nodelist[i])); + def.is_intregable or def.is_fpuregable or is_dynamic_array(def),tnode(lists.nodelist[i])); + + { the value described by the temp. is immutable and the temp. can be always in register + + ttempcreatenode.create normally takes care of the register location but it does not + know about immutability so it cannot take care of managed types } + include(ttempcreatenode(templist[i]).tempinfo^.flags,ti_const); + include(ttempcreatenode(templist[i]).tempinfo^.flags,ti_may_be_in_reg); { make debugging easier and set temp. location to the original location } tnode(templist[i]).fileinfo:=tnode(lists.nodelist[i]).fileinfo; @@ -412,7 +419,7 @@ unit optcse; def:=tstoreddef(tnode(lists.nodelist[i]).resultdef); { we cannot handle register stored records or array in CSE yet but we can store their reference } - addrstored:=(def.typ in [arraydef,recorddef]) or is_object(def); + addrstored:=((def.typ in [arraydef,recorddef]) or is_object(def)) and not(is_dynamic_array(def)); {$if defined(csedebug) or defined(csestats)} writeln; diff --git a/compiler/symdef.pas b/compiler/symdef.pas index e157cdaed8..45de32a291 100644 --- a/compiler/symdef.pas +++ b/compiler/symdef.pas @@ -1088,6 +1088,8 @@ interface function is_class_or_interface_or_object(def: tdef): boolean; function is_class_or_interface_or_dispinterface(def: tdef): boolean; function is_implicit_pointer_object_type(def: tdef): boolean; + { returns true, if def is a type which is an implicit pointer to an array (dyn. array or dyn. string) } + function is_implicit_array_pointer(def: tdef): boolean; function is_class_or_object(def: tdef): boolean; function is_record(def: tdef): boolean; @@ -7321,6 +7323,11 @@ implementation (def.typ=recorddef))); end; + function is_implicit_array_pointer(def: tdef): boolean; + begin + result:=is_dynamic_array(def) or is_dynamicstring(def); + end; + function is_class_or_object(def: tdef): boolean; begin result:=