wpobase.pas 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807
  1. {
  2. Copyright (c) 2008 by Jonas Maebe
  3. Whole program optimisation information collection base class
  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 wpobase;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. globtype,
  22. cclasses,
  23. symtype;
  24. type
  25. { the types of available whole program optimization }
  26. twpotype = (wpo_devirtualization_context_insensitive,wpo_live_symbol_information);
  27. const
  28. wpo2str: array[twpotype] of string[16] = ('devirtualization','symbol liveness');
  29. type
  30. { ************************************************************************* }
  31. { ******************** General base classes/interfaces ******************** }
  32. { ************************************************************************* }
  33. { interface to reading a section from a file with wpo info }
  34. twposectionreaderintf = interface
  35. ['{51BE3F89-C9C5-4965-9C83-AE7490C92E3E}']
  36. function sectiongetnextline(out s: string): boolean;
  37. end;
  38. { interface to writing sections to a file with wpoinfo }
  39. twposectionwriterintf = interface
  40. ['{C056F0DD-62B1-4612-86C7-2D39944C4437}']
  41. procedure startsection(const name: string);
  42. procedure sectionputline(const s: string);
  43. end;
  44. { base class for wpo information stores }
  45. { twpocomponentbase }
  46. twpocomponentbase = class
  47. public
  48. constructor create; reintroduce; virtual;
  49. { type of whole program optimization information collected/provided by
  50. this class
  51. }
  52. class function getwpotype: twpotype; virtual; abstract;
  53. { whole program optimizations for which this class generates information }
  54. class function generatesinfoforwposwitches: twpoptimizerswitches; virtual; abstract;
  55. { whole program optimizations performed by this class }
  56. class function performswpoforswitches: twpoptimizerswitches; virtual; abstract;
  57. { returns the name of the section parsed by this class }
  58. class function sectionname: shortstring; virtual; abstract;
  59. { checks whether the compiler options are compatible with this
  60. optimization (default: don't check anything)
  61. }
  62. class procedure checkoptions; virtual;
  63. { loads the information pertinent to this whole program optimization from
  64. the current section being processed by reader
  65. }
  66. procedure loadfromwpofilesection(reader: twposectionreaderintf); virtual; abstract;
  67. { stores the information of this component to a file in a format that can
  68. be loaded again using loadfromwpofilesection()
  69. }
  70. procedure storewpofilesection(writer: twposectionwriterintf); virtual; abstract;
  71. { extracts the information pertinent to this whole program optimization
  72. from the current compiler state (loaded units, ...)
  73. }
  74. procedure constructfromcompilerstate; virtual; abstract;
  75. end;
  76. twpocomponentbaseclass = class of twpocomponentbase;
  77. { forward declaration of overall wpo info manager class }
  78. twpoinfomanagerbase = class;
  79. { ************************************************************************* }
  80. { ** Information created per unit for use during subsequent compilation *** }
  81. { ************************************************************************* }
  82. { information about called vmt entries for a class }
  83. tcalledvmtentries = class
  84. protected
  85. { the class }
  86. fobjdef: tdef;
  87. fobjdefderef: tderef;
  88. { the vmt entries }
  89. fcalledentries: tbitset;
  90. public
  91. constructor create(_objdef: tdef; nentries: longint);
  92. constructor ppuload(ppufile: tcompilerppufile);
  93. destructor destroy; override;
  94. procedure ppuwrite(ppufile: tcompilerppufile);
  95. procedure buildderef;
  96. procedure buildderefimpl;
  97. procedure deref;
  98. procedure derefimpl;
  99. property objdef: tdef read fobjdef write fobjdef;
  100. property objdefderef: tderef read fobjdefderef write fobjdefderef;
  101. property calledentries: tbitset read fcalledentries write fcalledentries;
  102. end;
  103. { base class of information collected per unit. Still needs to be
  104. generalised for different kinds of wpo information, currently specific
  105. to devirtualization.
  106. }
  107. tunitwpoinfobase = class
  108. protected
  109. { created object types }
  110. fcreatedobjtypes: tfpobjectlist;
  111. { objectdefs pointed to by created classrefdefs }
  112. fcreatedclassrefobjtypes: tfpobjectlist;
  113. { objtypes potentially instantiated by fcreatedclassrefobjtypes
  114. (objdectdefs pointed to by classrefdefs that are
  115. passed as a regular parameter, loaded in a variable, ...
  116. so they can end up in a classrefdef var and be instantiated)
  117. }
  118. fmaybecreatedbyclassrefdeftypes: tfpobjectlist;
  119. { called virtual methods for all classes (hashed by mangled classname,
  120. entries bitmaps indicating which vmt entries per class are called --
  121. tcalledvmtentries)
  122. }
  123. fcalledvmtentries: tfphashlist;
  124. public
  125. constructor create; reintroduce; virtual;
  126. destructor destroy; override;
  127. property createdobjtypes: tfpobjectlist read fcreatedobjtypes;
  128. property createdclassrefobjtypes: tfpobjectlist read fcreatedclassrefobjtypes;
  129. property maybecreatedbyclassrefdeftypes: tfpobjectlist read fmaybecreatedbyclassrefdeftypes;
  130. property calledvmtentries: tfphashlist read fcalledvmtentries;
  131. procedure addcreatedobjtype(def: tdef);
  132. procedure addcreatedobjtypeforclassref(def: tdef);
  133. procedure addmaybecreatedbyclassref(def: tdef);
  134. procedure addcalledvmtentry(def: tdef; index: longint);
  135. end;
  136. { ************************************************************************* }
  137. { **** Total information created for use during subsequent compilation **** }
  138. { ************************************************************************* }
  139. { class to create a file with wpo information }
  140. { tavailablewpofilewriter }
  141. twpofilewriter = class(tobject,twposectionwriterintf)
  142. private
  143. { array of class *instances* that wish to be written out to the
  144. whole program optimization feedback file
  145. }
  146. fsectioncontents: tfpobjectlist;
  147. ffilename: tcmdstr;
  148. foutputfile: text;
  149. public
  150. constructor create(const fn: tcmdstr);
  151. destructor destroy; override;
  152. procedure writefile;
  153. { starts a new section with name "name" }
  154. procedure startsection(const name: string);
  155. { writes s to the wpo file }
  156. procedure sectionputline(const s: string);
  157. { register a component instance that needs to be written
  158. to the wpo feedback file
  159. }
  160. procedure registerwpocomponent(component: twpocomponentbase);
  161. end;
  162. { ************************************************************************* }
  163. { ************ Information for use during current compilation ************* }
  164. { ************************************************************************* }
  165. { class to read a file with wpo information }
  166. twpofilereader = class(tobject,twposectionreaderintf)
  167. private
  168. ffilename: tcmdstr;
  169. flinenr: longint;
  170. finputfile: text;
  171. fcurline: string;
  172. fusecurline: boolean;
  173. { destination for the read information }
  174. fdest: twpoinfomanagerbase;
  175. function getnextnoncommentline(out s: string): boolean;
  176. public
  177. constructor create(const fn: tcmdstr; dest: twpoinfomanagerbase);
  178. destructor destroy; override;
  179. { processes the wpo info in the file }
  180. procedure processfile;
  181. { returns next line of the current section in s, and false if no more
  182. lines in the current section
  183. }
  184. function sectiongetnextline(out s: string): boolean;
  185. end;
  186. { ************************************************************************* }
  187. { ******* Specific kinds of whole program optimization components ********* }
  188. { ************************************************************************* }
  189. { method devirtualisation }
  190. twpodevirtualisationhandler = class(twpocomponentbase)
  191. { checks whether procdef (a procdef for a virtual method) can be replaced with
  192. a static call when it's called as objdef.procdef, and if so returns the
  193. mangled name in staticname.
  194. }
  195. function staticnameforcallingvirtualmethod(objdef, procdef: tdef; out staticname: string): boolean; virtual; abstract;
  196. { checks whether procdef (a procdef for a virtual method) can be replaced with
  197. a different procname in the vmt of objdef, and if so returns the new
  198. mangledname in staticname
  199. }
  200. function staticnameforvmtentry(objdef, procdef: tdef; out staticname: string): boolean; virtual; abstract;
  201. end;
  202. twpodeadcodehandler = class(twpocomponentbase)
  203. { checks whether a mangledname was removed as dead code from the final
  204. binary (WARNING: must *not* be called for functions marked as inline,
  205. since if all call sites are inlined, it won't appear in the final
  206. binary but nevertheless is still necessary!)
  207. }
  208. function symbolinfinalbinary(const s: shortstring): boolean; virtual; abstract;
  209. end;
  210. { ************************************************************************* }
  211. { ************ Collection of all instances of wpo components ************** }
  212. { ************************************************************************* }
  213. { class doing all the bookkeeping for everything }
  214. twpoinfomanagerbase = class
  215. private
  216. { array of classrefs of handler classes for the various kinds of whole
  217. program optimizations that we support
  218. }
  219. fwpocomponents: tfphashlist;
  220. freader: twpofilereader;
  221. fwriter: twpofilewriter;
  222. public
  223. { instances of the various optimizers/information collectors (for
  224. information used during this compilation)
  225. }
  226. wpoinfouse: array[twpotype] of twpocomponentbase;
  227. { register a whole program optimization class type }
  228. procedure registerwpocomponentclass(wpocomponent: twpocomponentbaseclass);
  229. { get the program optimization class type that can parse the contents
  230. of the section with name "secname" in the wpo feedback file
  231. }
  232. function gethandlerforsection(const secname: string): twpocomponentbaseclass;
  233. { tell all instantiated wpo component classes to collect the information
  234. from the global compiler state that they need (done at the very end of
  235. the compilation process)
  236. }
  237. procedure extractwpoinfofromprogram;
  238. { set the name of the feedback file from which all whole-program information
  239. to be used during the current compilation will be read
  240. }
  241. procedure setwpoinputfile(const fn: tcmdstr);
  242. { set the name of the feedback file to which all whole-program information
  243. collected during the current compilation will be written
  244. }
  245. procedure setwpooutputfile(const fn: tcmdstr);
  246. { check whether the specified wpo options (-FW/-Fw/-OW/-Ow) are complete
  247. and sensical, and parse the wpo feedback file specified with
  248. setwpoinputfile
  249. }
  250. procedure parseandcheckwpoinfo;
  251. { routines accessing the optimizer information }
  252. { 1) devirtualization at the symbol name level }
  253. function can_be_devirtualized(objdef, procdef: tdef; out name: shortstring): boolean; virtual; abstract;
  254. { 2) optimal replacement method name in vmt }
  255. function optimized_name_for_vmt(objdef, procdef: tdef; out name: shortstring): boolean; virtual; abstract;
  256. { 3) does a symbol appear in the final binary (i.e., not removed by dead code stripping/smart linking).
  257. WARNING: do *not* call for inline functions/procedures/methods/...
  258. }
  259. function symbol_live(const name: shortstring): boolean; virtual; abstract;
  260. constructor create; reintroduce;
  261. destructor destroy; override;
  262. end;
  263. var
  264. wpoinfomanager: twpoinfomanagerbase;
  265. implementation
  266. uses
  267. globals,
  268. cutils,
  269. sysutils,
  270. symdef,
  271. verbose;
  272. { tcreatedwpoinfobase }
  273. constructor tunitwpoinfobase.create;
  274. begin
  275. fcreatedobjtypes:=tfpobjectlist.create(false);
  276. fcreatedclassrefobjtypes:=tfpobjectlist.create(false);
  277. fmaybecreatedbyclassrefdeftypes:=tfpobjectlist.create(false);
  278. fcalledvmtentries:=tfphashlist.create;
  279. end;
  280. destructor tunitwpoinfobase.destroy;
  281. var
  282. i: longint;
  283. begin
  284. fcreatedobjtypes.free;
  285. fcreatedobjtypes:=nil;
  286. fcreatedclassrefobjtypes.free;
  287. fcreatedclassrefobjtypes:=nil;
  288. fmaybecreatedbyclassrefdeftypes.free;
  289. fmaybecreatedbyclassrefdeftypes:=nil;
  290. { may not be assigned in case the info was loaded from a ppu and we
  291. are not generating a wpo feedback file (see tunitwpoinfo.ppuload)
  292. }
  293. if assigned(fcalledvmtentries) then
  294. begin
  295. for i:=0 to fcalledvmtentries.count-1 do
  296. tcalledvmtentries(fcalledvmtentries[i]).free;
  297. fcalledvmtentries.free;
  298. fcalledvmtentries:=nil;
  299. end;
  300. inherited destroy;
  301. end;
  302. procedure tunitwpoinfobase.addcreatedobjtype(def: tdef);
  303. begin
  304. fcreatedobjtypes.add(def);
  305. end;
  306. procedure tunitwpoinfobase.addcreatedobjtypeforclassref(def: tdef);
  307. begin
  308. fcreatedclassrefobjtypes.add(def);
  309. end;
  310. procedure tunitwpoinfobase.addmaybecreatedbyclassref(def: tdef);
  311. begin
  312. fmaybecreatedbyclassrefdeftypes.add(def);
  313. end;
  314. procedure tunitwpoinfobase.addcalledvmtentry(def: tdef; index: longint);
  315. var
  316. entries: tcalledvmtentries;
  317. key: shortstring;
  318. begin
  319. key:=tobjectdef(def).vmt_mangledname;
  320. entries:=tcalledvmtentries(fcalledvmtentries.find(key));
  321. if not assigned(entries) then
  322. begin
  323. entries:=tcalledvmtentries.create(def,tobjectdef(def).vmtentries.count);
  324. fcalledvmtentries.add(key,entries);
  325. end;
  326. entries.calledentries.include(index);
  327. end;
  328. { twpofilereader }
  329. function twpofilereader.getnextnoncommentline(out s: string):
  330. boolean;
  331. begin
  332. if (fusecurline) then
  333. begin
  334. s:=fcurline;
  335. fusecurline:=false;
  336. result:=true;
  337. exit;
  338. end;
  339. repeat
  340. readln(finputfile,s);
  341. if (s='') and
  342. eof(finputfile) then
  343. begin
  344. result:=false;
  345. exit;
  346. end;
  347. inc(flinenr);
  348. until (s='') or
  349. (s[1]<>'#');
  350. result:=true;
  351. end;
  352. constructor twpofilereader.create(const fn: tcmdstr; dest: twpoinfomanagerbase);
  353. begin
  354. if not FileExists(fn) or
  355. { FileExists also returns true for directories }
  356. DirectoryExists(fn) then
  357. begin
  358. cgmessage1(wpo_cant_find_file,fn);
  359. exit;
  360. end;
  361. assign(finputfile,fn);
  362. ffilename:=fn;
  363. fdest:=dest;
  364. end;
  365. destructor twpofilereader.destroy;
  366. begin
  367. inherited destroy;
  368. end;
  369. procedure twpofilereader.processfile;
  370. var
  371. sectionhandler: twpocomponentbaseclass;
  372. i: longint;
  373. wpotype: twpotype;
  374. s,
  375. sectionname: string;
  376. begin
  377. cgmessage1(wpo_begin_processing,ffilename);
  378. reset(finputfile);
  379. flinenr:=0;
  380. while getnextnoncommentline(s) do
  381. begin
  382. if (s='') then
  383. continue;
  384. { format: "% sectionname" }
  385. if (s[1]<>'%') then
  386. begin
  387. cgmessage2(wpo_expected_section,tostr(flinenr),s);
  388. break;
  389. end;
  390. for i:=2 to length(s) do
  391. if (s[i]<>' ') then
  392. break;
  393. sectionname:=copy(s,i,255);
  394. { find handler for section and process }
  395. sectionhandler:=fdest.gethandlerforsection(sectionname);
  396. if assigned(sectionhandler) then
  397. begin
  398. wpotype:=sectionhandler.getwpotype;
  399. cgmessage2(wpo_found_section,sectionname,wpo2str[wpotype]);
  400. { do we need this information? }
  401. if ((sectionhandler.performswpoforswitches * init_settings.dowpoptimizerswitches) <> []) then
  402. begin
  403. { did some other section already generate this type of information? }
  404. if assigned(fdest.wpoinfouse[wpotype]) then
  405. begin
  406. cgmessage2(wpo_duplicate_wpotype,wpo2str[wpotype],sectionname);
  407. fdest.wpoinfouse[wpotype].free;
  408. end;
  409. { process the section }
  410. fdest.wpoinfouse[wpotype]:=sectionhandler.create;
  411. twpocomponentbase(fdest.wpoinfouse[wpotype]).loadfromwpofilesection(self);
  412. end
  413. else
  414. begin
  415. cgmessage1(wpo_skipping_unnecessary_section,sectionname);
  416. { skip the current section }
  417. while sectiongetnextline(s) do
  418. ;
  419. end;
  420. end
  421. else
  422. begin
  423. cgmessage1(wpo_no_section_handler,sectionname);
  424. { skip the current section }
  425. while sectiongetnextline(s) do
  426. ;
  427. end;
  428. end;
  429. close(finputfile);
  430. cgmessage1(wpo_end_processing,ffilename);
  431. end;
  432. function twpofilereader.sectiongetnextline(out s: string): boolean;
  433. begin
  434. result:=getnextnoncommentline(s);
  435. if not result then
  436. exit;
  437. { start of new section? }
  438. if (s<>'') and
  439. (s[1]='%') then
  440. begin
  441. { keep read line for next call to getnextnoncommentline() }
  442. fcurline:=s;
  443. fusecurline:=true;
  444. result:=false;
  445. end;
  446. end;
  447. { twpocomponentbase }
  448. constructor twpocomponentbase.create;
  449. begin
  450. { do nothing }
  451. end;
  452. class procedure twpocomponentbase.checkoptions;
  453. begin
  454. { do nothing }
  455. end;
  456. { twpofilewriter }
  457. constructor twpofilewriter.create(const fn: tcmdstr);
  458. begin
  459. assign(foutputfile,fn);
  460. ffilename:=fn;
  461. fsectioncontents:=tfpobjectlist.create(true);
  462. end;
  463. destructor twpofilewriter.destroy;
  464. begin
  465. fsectioncontents.free;
  466. inherited destroy;
  467. end;
  468. procedure twpofilewriter.writefile;
  469. var
  470. i: longint;
  471. begin
  472. {$i-}
  473. rewrite(foutputfile);
  474. {$i+}
  475. if (ioresult <> 0) then
  476. begin
  477. cgmessage1(wpo_cant_create_feedback_file,ffilename);
  478. exit;
  479. end;
  480. for i:=0 to fsectioncontents.count-1 do
  481. twpocomponentbase(fsectioncontents[i]).storewpofilesection(self);
  482. close(foutputfile);
  483. end;
  484. procedure twpofilewriter.startsection(const name: string);
  485. begin
  486. writeln(foutputfile,'% ',name);
  487. end;
  488. procedure twpofilewriter.sectionputline(const s: string);
  489. begin
  490. writeln(foutputfile,s);
  491. end;
  492. procedure twpofilewriter.registerwpocomponent(
  493. component: twpocomponentbase);
  494. begin
  495. fsectioncontents.add(component);
  496. end;
  497. { twpoinfomanagerbase }
  498. procedure twpoinfomanagerbase.registerwpocomponentclass(wpocomponent: twpocomponentbaseclass);
  499. begin
  500. fwpocomponents.add(wpocomponent.sectionname,wpocomponent);
  501. end;
  502. function twpoinfomanagerbase.gethandlerforsection(const secname: string
  503. ): twpocomponentbaseclass;
  504. begin
  505. result:=twpocomponentbaseclass(fwpocomponents.find(secname));
  506. end;
  507. procedure twpoinfomanagerbase.setwpoinputfile(const fn: tcmdstr);
  508. begin
  509. freader:=twpofilereader.create(fn,self);
  510. end;
  511. procedure twpoinfomanagerbase.setwpooutputfile(const fn: tcmdstr);
  512. begin
  513. fwriter:=twpofilewriter.create(fn);
  514. end;
  515. procedure twpoinfomanagerbase.parseandcheckwpoinfo;
  516. var
  517. i: longint;
  518. begin
  519. { error if we don't have to optimize yet have an input feedback file }
  520. if (init_settings.dowpoptimizerswitches=[]) and
  521. assigned(freader) then
  522. begin
  523. cgmessage(wpo_input_without_info_use);
  524. exit;
  525. end;
  526. { error if we have to optimize yet don't have an input feedback file }
  527. if (init_settings.dowpoptimizerswitches<>[]) and
  528. not assigned(freader) then
  529. begin
  530. cgmessage(wpo_no_input_specified);
  531. exit;
  532. end;
  533. { if we have to generate wpo information, check that a file has been
  534. specified and that we have something to write to it
  535. }
  536. if (init_settings.genwpoptimizerswitches<>[]) and
  537. not assigned(fwriter) then
  538. begin
  539. cgmessage(wpo_no_output_specified);
  540. exit;
  541. end;
  542. if (init_settings.genwpoptimizerswitches=[]) and
  543. assigned(fwriter) then
  544. begin
  545. cgmessage(wpo_output_without_info_gen);
  546. exit;
  547. end;
  548. { now read the input feedback file }
  549. if assigned(freader) then
  550. begin
  551. freader.processfile;
  552. freader.free;
  553. freader:=nil;
  554. end;
  555. { and for each specified optimization check whether the input feedback
  556. file contained the necessary information
  557. }
  558. if (([cs_wpo_devirtualize_calls,cs_wpo_optimize_vmts] * init_settings.dowpoptimizerswitches) <> []) and
  559. not assigned(wpoinfouse[wpo_devirtualization_context_insensitive]) then
  560. begin
  561. cgmessage1(wpo_not_enough_info,wpo2str[wpo_devirtualization_context_insensitive]);
  562. exit;
  563. end;
  564. if (cs_wpo_symbol_liveness in init_settings.dowpoptimizerswitches) and
  565. not assigned(wpoinfouse[wpo_live_symbol_information]) then
  566. begin
  567. cgmessage1(wpo_not_enough_info,wpo2str[wpo_live_symbol_information]);
  568. exit;
  569. end;
  570. { perform pre-checking to ensure there are no known incompatibilities between
  571. the selected optimizations and other switches
  572. }
  573. for i:=0 to fwpocomponents.count-1 do
  574. if (twpocomponentbaseclass(fwpocomponents[i]).generatesinfoforwposwitches*init_settings.genwpoptimizerswitches)<>[] then
  575. twpocomponentbaseclass(fwpocomponents[i]).checkoptions
  576. end;
  577. procedure twpoinfomanagerbase.extractwpoinfofromprogram;
  578. var
  579. i: longint;
  580. info: twpocomponentbase;
  581. begin
  582. { if don't have to write anything, fwriter has not been created }
  583. if not assigned(fwriter) then
  584. exit;
  585. { let all wpo components gather the necessary info from the compiler state }
  586. for i:=0 to fwpocomponents.count-1 do
  587. if (twpocomponentbaseclass(fwpocomponents[i]).generatesinfoforwposwitches*current_settings.genwpoptimizerswitches)<>[] then
  588. begin
  589. info:=twpocomponentbaseclass(fwpocomponents[i]).create;
  590. info.constructfromcompilerstate;
  591. fwriter.registerwpocomponent(info);
  592. end;
  593. { and write their info to disk }
  594. fwriter.writefile;
  595. fwriter.free;
  596. fwriter:=nil;
  597. end;
  598. constructor twpoinfomanagerbase.create;
  599. begin
  600. inherited create;
  601. fwpocomponents:=tfphashlist.create;
  602. end;
  603. destructor twpoinfomanagerbase.destroy;
  604. var
  605. i: twpotype;
  606. begin
  607. freader.free;
  608. freader:=nil;
  609. fwriter.free;
  610. fwriter:=nil;
  611. fwpocomponents.free;
  612. fwpocomponents:=nil;
  613. for i:=low(wpoinfouse) to high(wpoinfouse) do
  614. if assigned(wpoinfouse[i]) then
  615. wpoinfouse[i].free;
  616. inherited destroy;
  617. end;
  618. { tcalledvmtentries }
  619. constructor tcalledvmtentries.create(_objdef: tdef; nentries: longint);
  620. begin
  621. objdef:=_objdef;
  622. calledentries:=tbitset.create(nentries);
  623. end;
  624. constructor tcalledvmtentries.ppuload(ppufile: tcompilerppufile);
  625. var
  626. len: longint;
  627. begin
  628. ppufile.getderef(fobjdefderef);
  629. len:=ppufile.getlongint;
  630. calledentries:=tbitset.create_bytesize(len);
  631. if (len <> calledentries.datasize) then
  632. internalerror(2009060301);
  633. ppufile.readdata(calledentries.data^,len);
  634. end;
  635. destructor tcalledvmtentries.destroy;
  636. begin
  637. fcalledentries.free;
  638. inherited destroy;
  639. end;
  640. procedure tcalledvmtentries.ppuwrite(ppufile: tcompilerppufile);
  641. begin
  642. ppufile.putderef(objdefderef);
  643. ppufile.putlongint(calledentries.datasize);
  644. ppufile.putdata(calledentries.data^,calledentries.datasize);
  645. end;
  646. procedure tcalledvmtentries.buildderef;
  647. begin
  648. objdefderef.build(objdef);
  649. end;
  650. procedure tcalledvmtentries.buildderefimpl;
  651. begin
  652. end;
  653. procedure tcalledvmtentries.deref;
  654. begin
  655. objdef:=tdef(objdefderef.resolve);
  656. end;
  657. procedure tcalledvmtentries.derefimpl;
  658. begin
  659. end;
  660. end.