optdfa.pas 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. {
  2. DFA
  3. Copyright (c) 2007 by Florian Klaempfl
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. unit optdfa;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. node;
  22. procedure createoptinfo(node : tnode);
  23. implementation
  24. uses
  25. globtype,globals,
  26. cpuinfo,
  27. nutils,
  28. nbas,nflw,ncon,ninl,ncal,
  29. optutils;
  30. function initnodes(var n:tnode; arg: pointer) : foreachnoderesult;
  31. begin
  32. { node worth to add? }
  33. if (node_complexity(n)>1) and (tstoreddef(n.resultdef).is_intregable or tstoreddef(n.resultdef).is_fpuregable) then
  34. begin
  35. plists(arg)^.nodelist.Add(n);
  36. plists(arg)^.locationlist.Add(@n);
  37. result:=fen_false;
  38. end
  39. else
  40. result:=fen_norecurse_false;
  41. end;
  42. {
  43. x:=f; read: [f]
  44. while x do read: []
  45. a:=b; read: [a,b,d] def: [a] life: read*def=[a]
  46. c:=d; read: [a,d] def: [a,c] life: read*def=[a]
  47. e:=a; read: [a] def: [a,c,e] life: read*def=[a]
  48. function f(b,d,x : type) : type;
  49. begin
  50. while x do alive: b,d,x
  51. begin
  52. a:=b; alive: b,d,x
  53. c:=d; alive: a,d,x
  54. e:=a+c; alive: a,c,x
  55. dec(x); alive: c,e,x
  56. end;
  57. result:=c+e; alive: c,e
  58. end; alive: result
  59. }
  60. type
  61. tdfainfo = record
  62. definitionlist : tfplist;
  63. lifelist : tfplist;
  64. end;
  65. procedure createdfainfo(node : tnode);
  66. begin
  67. { first, add controll flow information }
  68. SetNodeSucessors(node);
  69. { now, collect life information }
  70. end;
  71. end.