Re[4]: [fpc-pascal] Remove unused functions in a class

2009-04-05 Thread JoshyFun
Hello Jonas,

Sunday, April 5, 2009, 2:09:33 PM, you wrote:

JM If you have a class hierarchy tbase-tderived1-tderived2 with a
JM virtual method called vmethod, and nowhere in the program there is a
JM call to vmethod, then it is unused. Or if it is only called using
JM tderived2 instances, then if the linker does not find any direct  
JM references to tderived1.vmethod or tbase.vmethod (e.g., via  
JM inherited calls from tderived2 methods), it knows that the VMT  
JM entries for vmethod in tderived1 and tbase can be set to nil.

In fact I was thinking in something like this:

TCustomFoo=class(TObject);
TDerivedFoo=class(TCustomFoo)
 procedure Myprocedure(); virtual;
end;
TDeDerivedFoo=class(TDerivedFoo)
 procedure MyProcedure(); override;
end;

And in the code:

var
  MyObj: TCustomFoo;
begin
  MyObj:=TDeDerivedFoo.Create();
  TDerivedFoo(MyObj).Myprocedure();
end;

Something like this could kill the dead code detection ? A simple
yes/no is enoght :)


 JM that produces an error if you try to link a unit compiled with the
 JM option using the external linker), but that hasn't been done yet.

 Just for curiosity which is the parameter set ?

JM Compile the compiler with -dvtentry. It's not been tested for a while
JM though, as far as I know.

I'll play with it just for fun...

JM I also made a mistake in my previous explanation: currently, the WPO
JM does not yet perform the optimization the -dvtentry does. -dvtentry
JM looks at which VMT entries of a class hierarchy are never accessed,
JM and replaces those by nil. As a result, if those methods are not  
JM referred directly, then they can be removed by the linker.

I understand it in that way already.

JM The WPO looks at which class types can be instantiated in the program
JM and at the inheritance tree, and based on this determines which  
[...]
JM referenced directly, then they can be removed by the linker (and the
JM ones that are referenced can be turned into normal function calls).

More or less I understand the WPO way of work. Thank you again.

-- 
Best regards,
 JoshyFun


___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: Re[4]: [fpc-pascal] Remove unused functions in a class

2009-04-05 Thread Jonas Maebe


On 05 Apr 2009, at 17:12, JoshyFun wrote:


TCustomFoo=class(TObject);
TDerivedFoo=class(TCustomFoo)
procedure Myprocedure(); virtual;
end;
TDeDerivedFoo=class(TDerivedFoo)
procedure MyProcedure(); override;
end;

And in the code:

var
 MyObj: TCustomFoo;
begin
 MyObj:=TDeDerivedFoo.Create();
 TDerivedFoo(MyObj).Myprocedure();
end;

Something like this could kill the dead code detection ? A simple
yes/no is enoght :)


Not in case of whole-program optimization:

--- dead.sorg   2009-04-05 17:24:25.0 +0200
+++ dead.s  2009-04-05 17:24:32.0 +0200
@@ -91,10 +91,7 @@
 # [29] TDerivedFoo(MyObj).Myprocedure();
movlL_U_P$PROGRAM_MYOBJ$non_lazy_ptr-Lj2(%ebx),%eax
movl(%eax),%eax
-   movlL_U_P$PROGRAM_MYOBJ$non_lazy_ptr-Lj2(%ebx),%edx
-   movl(%edx),%edx
-   movl(%edx),%edx
-   call*80(%edx)
+   callL_P$PROGRAM_TDEDERIVEDFOO_$__MYPROCEDURE$stub

I'm not sure about -dvtentry.


Jonas
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal