소스 검색

* get rid of calls to empty procedures having parameters without side effect

git-svn-id: trunk@23274 -
florian 12 년 전
부모
커밋
4d6471fef6
5개의 변경된 파일45개의 추가작업 그리고 1개의 파일을 삭제
  1. 32 0
      compiler/ncal.pas
  2. 1 1
      compiler/ppu.pas
  3. 5 0
      compiler/psub.pas
  4. 6 0
      compiler/symdef.pas
  5. 1 0
      compiler/utils/ppudump.pp

+ 32 - 0
compiler/ncal.pas

@@ -3417,9 +3417,41 @@ implementation
 
 
     function tcallnode.pass_1 : tnode;
+      var
+        para: tcallparanode;
       begin
          result:=nil;
 
+         { can we get rid of the call? }
+         if not(cnf_return_value_used in callnodeflags) and
+           (procdefinition.typ=procdef) and
+           tprocdef(procdefinition).isempty and
+           { allow only certain proc options }
+           ((tprocdef(procdefinition).procoptions-[po_none,po_classmethod,po_staticmethod,
+             po_interrupt,po_iocheck,po_assembler,po_msgstr,po_msgint,po_exports,po_external,po_overload,po_varargs,
+             po_nostackframe,po_has_mangledname,po_has_public_name,po_forward,po_global,po_has_inlininginfo,
+             po_inline,po_compilerproc,po_has_importdll,po_has_importname,po_kylixlocal,po_dispid,po_delphi_nested_cc,
+             po_rtlproc,po_ignore_for_overload_resolution,po_auto_raised_visibility])=[]) then
+           begin
+             { check parameters for side effects }
+             para:=tcallparanode(left);
+             while assigned(para) do
+               begin
+                 if (para.parasym.typ = paravarsym) and
+                    ((para.parasym.refs>0) or
+                     not(cs_opt_dead_values in current_settings.optimizerswitches) or
+                     might_have_sideeffects(para.left)) then
+                     break;
+                  para:=tcallparanode(para.right);
+               end;
+             { finally, remove it if no parameter with side effect has been found }
+             if para=nil then
+               begin
+                 result:=cnothingnode.create;
+                 exit;
+               end;
+           end;
+
          { as pass_1 is never called on the methodpointer node, we must check
            here that it's not a helper type }
          if assigned(methodpointer) and

+ 1 - 1
compiler/ppu.pas

@@ -43,7 +43,7 @@ type
 {$endif Test_Double_checksum}
 
 const
-  CurrentPPUVersion = 156;
+  CurrentPPUVersion = 157;
 
 { buffer sizes }
   maxentrysize = 1024;

+ 5 - 0
compiler/psub.pas

@@ -1185,6 +1185,7 @@ implementation
         { firstpass everything }
         flowcontrol:=[];
         do_firstpass(code);
+
 {$ifdef i386}
         procdef.fpu_used:=node_resources_fpu(code);
         if procdef.fpu_used>0 then
@@ -1250,6 +1251,10 @@ implementation
         if cs_opt_nodecse in current_settings.optimizerswitches then
           do_optcse(code);
 
+        if (procdef.proctypeoption in [potype_operator,potype_procedure,potype_function]) and
+          (code.nodetype=blockn) and (tblocknode(code).statements=nil) then
+          procdef.isempty:=true;
+
         { add implicit entry and exit code }
         add_entry_exit_code;
 

+ 6 - 0
compiler/symdef.pas

@@ -631,6 +631,8 @@ interface
           synthetickind : tsynthetickind;
           { optional parameter for the synthetic routine generation logic }
           skpara: pointer;
+          { true, if the procedure contains no code }
+          isempty,
           { true, if the procedure is only declared
             (forward procedure) }
           forwarddef,
@@ -4123,6 +4125,8 @@ implementation
          for i:=1 to aliasnamescount do
            aliasnames.insert(ppufile.getstring);
 
+         isempty:=ppufile.getbyte<>0;
+
          { load para symtable }
          parast:=tparasymtable.create(self,level);
          tparasymtable(parast).ppuload(ppufile);
@@ -4278,6 +4282,8 @@ implementation
             item:=TCmdStrListItem(item.next);
           end;
 
+         ppufile.putbyte(ord(isempty));
+
          ppufile.do_crc:=oldintfcrc;
 
          { write this entry }

+ 1 - 0
compiler/utils/ppudump.pp

@@ -2389,6 +2389,7 @@ begin
                    end;
                  writeln;
                end;
+             writeln(space,'            Empty : ',getbyte<>0);
              if not EndOfEntry then
                HasMoreInfos;
              space:='    '+space;