[fpc-devel] Tail recursion optimization

Florian Klaempfl florian at freepascal.org
Tue Oct 10 14:29:28 CEST 2006


Jonas Maebe wrote:

[...]

Well, basically I agree with all your points ;) That's why I said the
optimization is almost useless for real world programs. Nevertheless it helps
for the benchmarks and gcc does it to. I'll try to find out the influence on the
compiler/rtl, there are some examples where it applies (from ftl\inc\objpas.inc):

      class function TObject.getinterfaceentry(const iid : tguid) : pinterfaceentry;
        var
          i: integer;
          intftable: pinterfacetable;
          Res: pinterfaceentry;
        begin
          getinterfaceentry:=nil;
          intftable:=pinterfacetable((pointer(Self)+vmtIntfTable)^);
          if assigned(intftable) then begin
            i:=intftable^.EntryCount;
            Res:=@intftable^.Entries[0];
            while (i>0) and
               not (assigned(Res^.iid) and IsGUIDEqual(Res^.iid^,iid)) do begin
              inc(Res);
              dec(i);
            end;
            if (i>0) then
              getinterfaceentry:=Res;
          end;
          if (getinterfaceentry=nil)and not(classparent=nil) then
            getinterfaceentry:=classparent.getinterfaceentry(iid)
        end;




More information about the fpc-devel mailing list