Mercurial > hg > CbC > CbC_gcc
comparison gcc/doc/tree-ssa.texi @ 111:04ced10e8804
gcc 7
author | kono |
---|---|
date | Fri, 27 Oct 2017 22:46:09 +0900 |
parents | b7f97abdc517 |
children | 84e7813d76e9 |
comparison
equal
deleted
inserted
replaced
68:561a7518be6b | 111:04ced10e8804 |
---|---|
1 @c Copyright (c) 2004, 2005, 2007, 2008, 2010 | 1 @c Copyright (C) 2004-2017 Free Software Foundation, Inc. |
2 @c Free Software Foundation, Inc. | |
3 @c This is part of the GCC manual. | 2 @c This is part of the GCC manual. |
4 @c For copying conditions, see the file gcc.texi. | 3 @c For copying conditions, see the file gcc.texi. |
5 | 4 |
6 @c --------------------------------------------------------------------- | 5 @c --------------------------------------------------------------------- |
7 @c Tree SSA | 6 @c Tree SSA |
51 The optimizers need to associate attributes with variables during the | 50 The optimizers need to associate attributes with variables during the |
52 optimization process. For instance, we need to know whether a | 51 optimization process. For instance, we need to know whether a |
53 variable has aliases. All these attributes are stored in data | 52 variable has aliases. All these attributes are stored in data |
54 structures called annotations which are then linked to the field | 53 structures called annotations which are then linked to the field |
55 @code{ann} in @code{struct tree_common}. | 54 @code{ann} in @code{struct tree_common}. |
56 | |
57 Presently, we define annotations for variables (@code{var_ann_t}). | |
58 Annotations are defined and documented in @file{tree-flow.h}. | |
59 | 55 |
60 | 56 |
61 @node SSA Operands | 57 @node SSA Operands |
62 @section SSA Operands | 58 @section SSA Operands |
63 @cindex operands | 59 @cindex operands |
182 must be made to @code{update_stmt} when complete. Calling one of the | 178 must be made to @code{update_stmt} when complete. Calling one of the |
183 @code{bsi_insert} routines or @code{bsi_replace} performs an implicit | 179 @code{bsi_insert} routines or @code{bsi_replace} performs an implicit |
184 call to @code{update_stmt}. | 180 call to @code{update_stmt}. |
185 | 181 |
186 @subsection Operand Iterators And Access Routines | 182 @subsection Operand Iterators And Access Routines |
187 @cindex Operand Iterators | 183 @cindex Operand Iterators |
188 @cindex Operand Access Routines | 184 @cindex Operand Access Routines |
189 | 185 |
190 Operands are collected by @file{tree-ssa-operands.c}. They are stored | 186 Operands are collected by @file{tree-ssa-operands.c}. They are stored |
191 inside each statement's annotation and can be accessed through either the | 187 inside each statement's annotation and can be accessed through either the |
192 operand iterators or an access routine. | 188 operand iterators or an access routine. |
193 | 189 |
194 The following access routines are available for examining operands: | 190 The following access routines are available for examining operands: |
195 | 191 |
196 @enumerate | 192 @enumerate |
197 @item @code{SINGLE_SSA_@{USE,DEF,TREE@}_OPERAND}: These accessors will return | 193 @item @code{SINGLE_SSA_@{USE,DEF,TREE@}_OPERAND}: These accessors will return |
198 NULL unless there is exactly one operand matching the specified flags. If | 194 NULL unless there is exactly one operand matching the specified flags. If |
199 there is exactly one operand, the operand is returned as either a @code{tree}, | 195 there is exactly one operand, the operand is returned as either a @code{tree}, |
200 @code{def_operand_p}, or @code{use_operand_p}. | 196 @code{def_operand_p}, or @code{use_operand_p}. |
201 | 197 |
202 @smallexample | 198 @smallexample |
203 tree t = SINGLE_SSA_TREE_OPERAND (stmt, flags); | 199 tree t = SINGLE_SSA_TREE_OPERAND (stmt, flags); |
204 use_operand_p u = SINGLE_SSA_USE_OPERAND (stmt, SSA_ALL_VIRTUAL_USES); | 200 use_operand_p u = SINGLE_SSA_USE_OPERAND (stmt, SSA_ALL_VIRTUAL_USES); |
205 def_operand_p d = SINGLE_SSA_DEF_OPERAND (stmt, SSA_OP_ALL_DEFS); | 201 def_operand_p d = SINGLE_SSA_DEF_OPERAND (stmt, SSA_OP_ALL_DEFS); |
206 @end smallexample | 202 @end smallexample |
207 | 203 |
208 @item @code{ZERO_SSA_OPERANDS}: This macro returns true if there are no | 204 @item @code{ZERO_SSA_OPERANDS}: This macro returns true if there are no |
209 operands matching the specified flags. | 205 operands matching the specified flags. |
210 | 206 |
211 @smallexample | 207 @smallexample |
212 if (ZERO_SSA_OPERANDS (stmt, SSA_OP_ALL_VIRTUALS)) | 208 if (ZERO_SSA_OPERANDS (stmt, SSA_OP_ALL_VIRTUALS)) |
213 return; | 209 return; |
214 @end smallexample | 210 @end smallexample |
215 | 211 |
216 @item @code{NUM_SSA_OPERANDS}: This macro Returns the number of operands | 212 @item @code{NUM_SSA_OPERANDS}: This macro Returns the number of operands |
217 matching 'flags'. This actually executes a loop to perform the count, so | 213 matching 'flags'. This actually executes a loop to perform the count, so |
218 only use this if it is really needed. | 214 only use this if it is really needed. |
219 | 215 |
220 @smallexample | 216 @smallexample |
221 int count = NUM_SSA_OPERANDS (stmt, flags) | 217 int count = NUM_SSA_OPERANDS (stmt, flags) |
222 @end smallexample | 218 @end smallexample |
264 | 260 |
265 @smallexample | 261 @smallexample |
266 #define SSA_OP_USE 0x01 /* @r{Real USE operands.} */ | 262 #define SSA_OP_USE 0x01 /* @r{Real USE operands.} */ |
267 #define SSA_OP_DEF 0x02 /* @r{Real DEF operands.} */ | 263 #define SSA_OP_DEF 0x02 /* @r{Real DEF operands.} */ |
268 #define SSA_OP_VUSE 0x04 /* @r{VUSE operands.} */ | 264 #define SSA_OP_VUSE 0x04 /* @r{VUSE operands.} */ |
269 #define SSA_OP_VMAYUSE 0x08 /* @r{USE portion of VDEFS.} */ | 265 #define SSA_OP_VDEF 0x08 /* @r{VDEF operands.} */ |
270 #define SSA_OP_VDEF 0x10 /* @r{DEF portion of VDEFS.} */ | |
271 | 266 |
272 /* @r{These are commonly grouped operand flags.} */ | 267 /* @r{These are commonly grouped operand flags.} */ |
273 #define SSA_OP_VIRTUAL_USES (SSA_OP_VUSE | SSA_OP_VMAYUSE) | 268 #define SSA_OP_VIRTUAL_USES (SSA_OP_VUSE) |
274 #define SSA_OP_VIRTUAL_DEFS (SSA_OP_VDEF) | 269 #define SSA_OP_VIRTUAL_DEFS (SSA_OP_VDEF) |
275 #define SSA_OP_ALL_USES (SSA_OP_VIRTUAL_USES | SSA_OP_USE) | 270 #define SSA_OP_ALL_VIRTUALS (SSA_OP_VIRTUAL_USES | SSA_OP_VIRTUAL_DEFS) |
276 #define SSA_OP_ALL_DEFS (SSA_OP_VIRTUAL_DEFS | SSA_OP_DEF) | 271 #define SSA_OP_ALL_USES (SSA_OP_VIRTUAL_USES | SSA_OP_USE) |
277 #define SSA_OP_ALL_OPERANDS (SSA_OP_ALL_USES | SSA_OP_ALL_DEFS) | 272 #define SSA_OP_ALL_DEFS (SSA_OP_VIRTUAL_DEFS | SSA_OP_DEF) |
273 #define SSA_OP_ALL_OPERANDS (SSA_OP_ALL_USES | SSA_OP_ALL_DEFS) | |
278 @end smallexample | 274 @end smallexample |
279 @end enumerate | 275 @end enumerate |
280 | 276 |
281 So if you want to look at the use pointers for all the @code{USE} and | 277 So if you want to look at the use pointers for all the @code{USE} and |
282 @code{VUSE} operands, you would do something like: | 278 @code{VUSE} operands, you would do something like: |
306 @} | 302 @} |
307 @end smallexample | 303 @end smallexample |
308 | 304 |
309 @code{VDEF}s are broken into two flags, one for the | 305 @code{VDEF}s are broken into two flags, one for the |
310 @code{DEF} portion (@code{SSA_OP_VDEF}) and one for the USE portion | 306 @code{DEF} portion (@code{SSA_OP_VDEF}) and one for the USE portion |
311 (@code{SSA_OP_VMAYUSE}). If all you want to look at are the | 307 (@code{SSA_OP_VUSE}). |
312 @code{VDEF}s together, there is a fourth iterator macro for this, | 308 |
313 which returns both a def_operand_p and a use_operand_p for each | 309 There are many examples in the code, in addition to the documentation |
314 @code{VDEF} in the statement. Note that you don't need any flags for | 310 in @file{tree-ssa-operands.h} and @file{ssa-iterators.h}. |
315 this one. | |
316 | |
317 @smallexample | |
318 use_operand_p use_p; | |
319 def_operand_p def_p; | |
320 ssa_op_iter iter; | |
321 | |
322 FOR_EACH_SSA_MAYDEF_OPERAND (def_p, use_p, stmt, iter) | |
323 @{ | |
324 my_code; | |
325 @} | |
326 @end smallexample | |
327 | |
328 There are many examples in the code as well, as well as the | |
329 documentation in @file{tree-ssa-operands.h}. | |
330 | 311 |
331 There are also a couple of variants on the stmt iterators regarding PHI | 312 There are also a couple of variants on the stmt iterators regarding PHI |
332 nodes. | 313 nodes. |
333 | 314 |
334 @code{FOR_EACH_PHI_ARG} Works exactly like | 315 @code{FOR_EACH_PHI_ARG} Works exactly like |
335 @code{FOR_EACH_SSA_USE_OPERAND}, except it works over @code{PHI} arguments | 316 @code{FOR_EACH_SSA_USE_OPERAND}, except it works over @code{PHI} arguments |
336 instead of statement operands. | 317 instead of statement operands. |
337 | 318 |
338 @smallexample | 319 @smallexample |
339 /* Look at every virtual PHI use. */ | 320 /* Look at every virtual PHI use. */ |
340 FOR_EACH_PHI_ARG (use_p, phi_stmt, iter, SSA_OP_VIRTUAL_USES) | 321 FOR_EACH_PHI_ARG (use_p, phi_stmt, iter, SSA_OP_VIRTUAL_USES) |
349 /* Look at every PHI use. */ | 330 /* Look at every PHI use. */ |
350 FOR_EACH_PHI_ARG (use_p, phi_stmt, iter, SSA_OP_ALL_USES) | 331 FOR_EACH_PHI_ARG (use_p, phi_stmt, iter, SSA_OP_ALL_USES) |
351 my_code; | 332 my_code; |
352 @end smallexample | 333 @end smallexample |
353 | 334 |
354 @code{FOR_EACH_PHI_OR_STMT_@{USE,DEF@}} works exactly like | 335 @code{FOR_EACH_PHI_OR_STMT_@{USE,DEF@}} works exactly like |
355 @code{FOR_EACH_SSA_@{USE,DEF@}_OPERAND}, except it will function on | 336 @code{FOR_EACH_SSA_@{USE,DEF@}_OPERAND}, except it will function on |
356 either a statement or a @code{PHI} node. These should be used when it is | 337 either a statement or a @code{PHI} node. These should be used when it is |
357 appropriate but they are not quite as efficient as the individual | 338 appropriate but they are not quite as efficient as the individual |
358 @code{FOR_EACH_PHI} and @code{FOR_EACH_SSA} routines. | 339 @code{FOR_EACH_PHI} and @code{FOR_EACH_SSA} routines. |
359 | 340 |
360 @smallexample | 341 @smallexample |
361 FOR_EACH_PHI_OR_STMT_USE (use_operand_p, stmt, iter, flags) | 342 FOR_EACH_PHI_OR_STMT_USE (use_operand_p, stmt, iter, flags) |
362 @{ | 343 @{ |
370 @end smallexample | 351 @end smallexample |
371 | 352 |
372 @subsection Immediate Uses | 353 @subsection Immediate Uses |
373 @cindex Immediate Uses | 354 @cindex Immediate Uses |
374 | 355 |
375 Immediate use information is now always available. Using the immediate use | 356 Immediate use information is now always available. Using the immediate use |
376 iterators, you may examine every use of any @code{SSA_NAME}. For instance, | 357 iterators, you may examine every use of any @code{SSA_NAME}. For instance, |
377 to change each use of @code{ssa_var} to @code{ssa_var2} and call fold_stmt on | 358 to change each use of @code{ssa_var} to @code{ssa_var2} and call fold_stmt on |
378 each stmt after that is done: | 359 each stmt after that is done: |
379 | 360 |
380 @smallexample | 361 @smallexample |
391 @} | 372 @} |
392 @end smallexample | 373 @end smallexample |
393 | 374 |
394 There are 2 iterators which can be used. @code{FOR_EACH_IMM_USE_FAST} is | 375 There are 2 iterators which can be used. @code{FOR_EACH_IMM_USE_FAST} is |
395 used when the immediate uses are not changed, i.e., you are looking at the | 376 used when the immediate uses are not changed, i.e., you are looking at the |
396 uses, but not setting them. | 377 uses, but not setting them. |
397 | 378 |
398 If they do get changed, then care must be taken that things are not changed | 379 If they do get changed, then care must be taken that things are not changed |
399 under the iterators, so use the @code{FOR_EACH_IMM_USE_STMT} and | 380 under the iterators, so use the @code{FOR_EACH_IMM_USE_STMT} and |
400 @code{FOR_EACH_IMM_USE_ON_STMT} iterators. They attempt to preserve the | 381 @code{FOR_EACH_IMM_USE_ON_STMT} iterators. They attempt to preserve the |
401 sanity of the use list by moving all the uses for a statement into | 382 sanity of the use list by moving all the uses for a statement into |
402 a controlled position, and then iterating over those uses. Then the | 383 a controlled position, and then iterating over those uses. Then the |
403 optimization can manipulate the stmt when all the uses have been | 384 optimization can manipulate the stmt when all the uses have been |
404 processed. This is a little slower than the FAST version since it adds a | 385 processed. This is a little slower than the FAST version since it adds a |
405 placeholder element and must sort through the list a bit for each statement. | 386 placeholder element and must sort through the list a bit for each statement. |
406 This placeholder element must be also be removed if the loop is | 387 This placeholder element must be also be removed if the loop is |
407 terminated early. The macro @code{BREAK_FROM_IMM_USE_SAFE} is provided | 388 terminated early. The macro @code{BREAK_FROM_IMM_USE_SAFE} is provided |
408 to do this : | 389 to do this : |
409 | 390 |
410 @smallexample | 391 @smallexample |
411 FOR_EACH_IMM_USE_STMT (stmt, iterator, ssa_var) | 392 FOR_EACH_IMM_USE_STMT (stmt, iterator, ssa_var) |
412 @{ | 393 @{ |
418 fold_stmt (stmt); | 399 fold_stmt (stmt); |
419 @} | 400 @} |
420 @end smallexample | 401 @end smallexample |
421 | 402 |
422 There are checks in @code{verify_ssa} which verify that the immediate use list | 403 There are checks in @code{verify_ssa} which verify that the immediate use list |
423 is up to date, as well as checking that an optimization didn't break from the | 404 is up to date, as well as checking that an optimization didn't break from the |
424 loop without using this macro. It is safe to simply 'break'; from a | 405 loop without using this macro. It is safe to simply 'break'; from a |
425 @code{FOR_EACH_IMM_USE_FAST} traverse. | 406 @code{FOR_EACH_IMM_USE_FAST} traverse. |
426 | 407 |
427 Some useful functions and macros: | 408 Some useful functions and macros: |
428 @enumerate | 409 @enumerate |
429 @item @code{has_zero_uses (ssa_var)} : Returns true if there are no uses of | 410 @item @code{has_zero_uses (ssa_var)} : Returns true if there are no uses of |
430 @code{ssa_var}. | 411 @code{ssa_var}. |
431 @item @code{has_single_use (ssa_var)} : Returns true if there is only a | 412 @item @code{has_single_use (ssa_var)} : Returns true if there is only a |
432 single use of @code{ssa_var}. | 413 single use of @code{ssa_var}. |
433 @item @code{single_imm_use (ssa_var, use_operand_p *ptr, tree *stmt)} : | 414 @item @code{single_imm_use (ssa_var, use_operand_p *ptr, tree *stmt)} : |
434 Returns true if there is only a single use of @code{ssa_var}, and also returns | 415 Returns true if there is only a single use of @code{ssa_var}, and also returns |
435 the use pointer and statement it occurs in, in the second and third parameters. | 416 the use pointer and statement it occurs in, in the second and third parameters. |
436 @item @code{num_imm_uses (ssa_var)} : Returns the number of immediate uses of | 417 @item @code{num_imm_uses (ssa_var)} : Returns the number of immediate uses of |
441 isn't located in a @code{PHI} node. | 422 isn't located in a @code{PHI} node. |
442 @item @code{USE_STMT (use_p)} : Return the statement a use occurs in. | 423 @item @code{USE_STMT (use_p)} : Return the statement a use occurs in. |
443 @end enumerate | 424 @end enumerate |
444 | 425 |
445 Note that uses are not put into an immediate use list until their statement is | 426 Note that uses are not put into an immediate use list until their statement is |
446 actually inserted into the instruction stream via a @code{bsi_*} routine. | 427 actually inserted into the instruction stream via a @code{bsi_*} routine. |
447 | 428 |
448 It is also still possible to utilize lazy updating of statements, but this | 429 It is also still possible to utilize lazy updating of statements, but this |
449 should be used only when absolutely required. Both alias analysis and the | 430 should be used only when absolutely required. Both alias analysis and the |
450 dominator optimizations currently do this. | 431 dominator optimizations currently do this. |
451 | 432 |
452 When lazy updating is being used, the immediate use information is out of date | 433 When lazy updating is being used, the immediate use information is out of date |
453 and cannot be used reliably. Lazy updating is achieved by simply marking | 434 and cannot be used reliably. Lazy updating is achieved by simply marking |
454 statements modified via calls to @code{mark_stmt_modified} instead of | 435 statements modified via calls to @code{gimple_set_modified} instead of |
455 @code{update_stmt}. When lazy updating is no longer required, all the | 436 @code{update_stmt}. When lazy updating is no longer required, all the |
456 modified statements must have @code{update_stmt} called in order to bring them | 437 modified statements must have @code{update_stmt} called in order to bring them |
457 up to date. This must be done before the optimization is finished, or | 438 up to date. This must be done before the optimization is finished, or |
458 @code{verify_ssa} will trigger an abort. | 439 @code{verify_ssa} will trigger an abort. |
459 | 440 |
460 This is done with a simple loop over the instruction stream: | 441 This is done with a simple loop over the instruction stream: |
461 @smallexample | 442 @smallexample |
462 block_stmt_iterator bsi; | 443 block_stmt_iterator bsi; |
525 SSA renamer creates a new version @code{a_4} which is assigned | 506 SSA renamer creates a new version @code{a_4} which is assigned |
526 the result of ``merging'' @code{a_1}, @code{a_2} and @code{a_3}. | 507 the result of ``merging'' @code{a_1}, @code{a_2} and @code{a_3}. |
527 Hence, PHI nodes mean ``one of these operands. I don't know | 508 Hence, PHI nodes mean ``one of these operands. I don't know |
528 which''. | 509 which''. |
529 | 510 |
530 The following macros can be used to examine PHI nodes | 511 The following functions can be used to examine PHI nodes |
531 | 512 |
532 @defmac PHI_RESULT (@var{phi}) | 513 @defun gimple_phi_result (@var{phi}) |
533 Returns the @code{SSA_NAME} created by PHI node @var{phi} (i.e., | 514 Returns the @code{SSA_NAME} created by PHI node @var{phi} (i.e., |
534 @var{phi}'s LHS)@. | 515 @var{phi}'s LHS)@. |
535 @end defmac | 516 @end defun |
536 | 517 |
537 @defmac PHI_NUM_ARGS (@var{phi}) | 518 @defun gimple_phi_num_args (@var{phi}) |
538 Returns the number of arguments in @var{phi}. This number is exactly | 519 Returns the number of arguments in @var{phi}. This number is exactly |
539 the number of incoming edges to the basic block holding @var{phi}@. | 520 the number of incoming edges to the basic block holding @var{phi}@. |
540 @end defmac | 521 @end defun |
541 | 522 |
542 @defmac PHI_ARG_ELT (@var{phi}, @var{i}) | 523 @defun gimple_phi_arg (@var{phi}, @var{i}) |
543 Returns a tuple representing the @var{i}th argument of @var{phi}@. | 524 Returns @var{i}th argument of @var{phi}@. |
544 Each element of this tuple contains an @code{SSA_NAME} @var{var} and | 525 @end defun |
545 the incoming edge through which @var{var} flows. | 526 |
546 @end defmac | 527 @defun gimple_phi_arg_edge (@var{phi}, @var{i}) |
547 | |
548 @defmac PHI_ARG_EDGE (@var{phi}, @var{i}) | |
549 Returns the incoming edge for the @var{i}th argument of @var{phi}. | 528 Returns the incoming edge for the @var{i}th argument of @var{phi}. |
550 @end defmac | 529 @end defun |
551 | 530 |
552 @defmac PHI_ARG_DEF (@var{phi}, @var{i}) | 531 @defun gimple_phi_arg_def (@var{phi}, @var{i}) |
553 Returns the @code{SSA_NAME} for the @var{i}th argument of @var{phi}. | 532 Returns the @code{SSA_NAME} for the @var{i}th argument of @var{phi}. |
554 @end defmac | 533 @end defun |
555 | 534 |
556 | 535 |
557 @subsection Preserving the SSA form | 536 @subsection Preserving the SSA form |
558 @findex update_ssa | 537 @findex update_ssa |
559 @cindex preserving SSA form | 538 @cindex preserving SSA form |
560 Some optimization passes make changes to the function that | 539 Some optimization passes make changes to the function that |
561 invalidate the SSA property. This can happen when a pass has | 540 invalidate the SSA property. This can happen when a pass has |
562 added new symbols or changed the program so that variables that | 541 added new symbols or changed the program so that variables that |
563 were previously aliased aren't anymore. Whenever something like this | 542 were previously aliased aren't anymore. Whenever something like this |
564 happens, the affected symbols must be renamed into SSA form again. | 543 happens, the affected symbols must be renamed into SSA form again. |
565 Transformations that emit new code or replicate existing statements | 544 Transformations that emit new code or replicate existing statements |
566 will also need to update the SSA form@. | 545 will also need to update the SSA form@. |
567 | 546 |
568 Since GCC implements two different SSA forms for register and virtual | 547 Since GCC implements two different SSA forms for register and virtual |
569 variables, keeping the SSA form up to date depends on whether you are | 548 variables, keeping the SSA form up to date depends on whether you are |
626 be renamed into SSA form for the first time. When new names are | 605 be renamed into SSA form for the first time. When new names are |
627 introduced to replace existing names in the program, the mapping | 606 introduced to replace existing names in the program, the mapping |
628 between the old and the new names are registered by calling | 607 between the old and the new names are registered by calling |
629 @code{register_new_name_mapping} (note that if your pass creates new | 608 @code{register_new_name_mapping} (note that if your pass creates new |
630 code by duplicating basic blocks, the call to @code{tree_duplicate_bb} | 609 code by duplicating basic blocks, the call to @code{tree_duplicate_bb} |
631 will set up the necessary mappings automatically). On the other hand, | 610 will set up the necessary mappings automatically). |
632 if your pass exposes a new symbol that should be put in SSA form for | |
633 the first time, the new symbol should be registered with | |
634 @code{mark_sym_for_renaming}. | |
635 | 611 |
636 After the replacement mappings have been registered and new symbols | 612 After the replacement mappings have been registered and new symbols |
637 marked for renaming, a call to @code{update_ssa} makes the registered | 613 marked for renaming, a call to @code{update_ssa} makes the registered |
638 changes. This can be done with an explicit call or by creating | 614 changes. This can be done with an explicit call or by creating |
639 @code{TODO} flags in the @code{tree_opt_pass} structure for your pass. | 615 @code{TODO} flags in the @code{tree_opt_pass} structure for your pass. |
676 NOTE: If this flag is used, any OLD->NEW mappings for real names | 652 NOTE: If this flag is used, any OLD->NEW mappings for real names |
677 are explicitly destroyed and only the symbols marked for | 653 are explicitly destroyed and only the symbols marked for |
678 renaming are processed@. | 654 renaming are processed@. |
679 @end itemize | 655 @end itemize |
680 | 656 |
681 @subsection Preserving the virtual SSA form | |
682 @cindex preserving virtual SSA form | |
683 | |
684 The virtual SSA form is harder to preserve than the non-virtual SSA form | |
685 mainly because the set of virtual operands for a statement may change at | |
686 what some would consider unexpected times. In general, statement | |
687 modifications should be bracketed between calls to | |
688 @code{push_stmt_changes} and @code{pop_stmt_changes}. For example, | |
689 | |
690 @smallexample | |
691 munge_stmt (tree stmt) | |
692 @{ | |
693 push_stmt_changes (&stmt); | |
694 @dots{} rewrite STMT @dots{} | |
695 pop_stmt_changes (&stmt); | |
696 @} | |
697 @end smallexample | |
698 | |
699 The call to @code{push_stmt_changes} saves the current state of the | |
700 statement operands and the call to @code{pop_stmt_changes} compares | |
701 the saved state with the current one and does the appropriate symbol | |
702 marking for the SSA renamer. | |
703 | |
704 It is possible to modify several statements at a time, provided that | |
705 @code{push_stmt_changes} and @code{pop_stmt_changes} are called in | |
706 LIFO order, as when processing a stack of statements. | |
707 | |
708 Additionally, if the pass discovers that it did not need to make | |
709 changes to the statement after calling @code{push_stmt_changes}, it | |
710 can simply discard the topmost change buffer by calling | |
711 @code{discard_stmt_changes}. This will avoid the expensive operand | |
712 re-scan operation and the buffer comparison that determines if symbols | |
713 need to be marked for renaming. | |
714 | |
715 @subsection Examining @code{SSA_NAME} nodes | 657 @subsection Examining @code{SSA_NAME} nodes |
716 @cindex examining SSA_NAMEs | 658 @cindex examining SSA_NAMEs |
717 | 659 |
718 The following macros can be used to examine @code{SSA_NAME} nodes | 660 The following macros can be used to examine @code{SSA_NAME} nodes |
719 | 661 |
726 | 668 |
727 @defmac SSA_NAME_VERSION (@var{var}) | 669 @defmac SSA_NAME_VERSION (@var{var}) |
728 Returns the version number of the @code{SSA_NAME} object @var{var}. | 670 Returns the version number of the @code{SSA_NAME} object @var{var}. |
729 @end defmac | 671 @end defmac |
730 | 672 |
731 | |
732 @subsection Walking use-def chains | |
733 | |
734 @deftypefn {Tree SSA function} void walk_use_def_chains (@var{var}, @var{fn}, @var{data}) | |
735 | |
736 Walks use-def chains starting at the @code{SSA_NAME} node @var{var}. | |
737 Calls function @var{fn} at each reaching definition found. Function | |
738 @var{FN} takes three arguments: @var{var}, its defining statement | |
739 (@var{def_stmt}) and a generic pointer to whatever state information | |
740 that @var{fn} may want to maintain (@var{data}). Function @var{fn} is | |
741 able to stop the walk by returning @code{true}, otherwise in order to | |
742 continue the walk, @var{fn} should return @code{false}. | |
743 | |
744 Note, that if @var{def_stmt} is a @code{PHI} node, the semantics are | |
745 slightly different. For each argument @var{arg} of the PHI node, this | |
746 function will: | |
747 | |
748 @enumerate | |
749 @item Walk the use-def chains for @var{arg}. | |
750 @item Call @code{FN (@var{arg}, @var{phi}, @var{data})}. | |
751 @end enumerate | |
752 | |
753 Note how the first argument to @var{fn} is no longer the original | |
754 variable @var{var}, but the PHI argument currently being examined. | |
755 If @var{fn} wants to get at @var{var}, it should call | |
756 @code{PHI_RESULT} (@var{phi}). | |
757 @end deftypefn | |
758 | 673 |
759 @subsection Walking the dominator tree | 674 @subsection Walking the dominator tree |
760 | 675 |
761 @deftypefn {Tree SSA function} void walk_dominator_tree (@var{walk_data}, @var{bb}) | 676 @deftypefn {Tree SSA function} void walk_dominator_tree (@var{walk_data}, @var{bb}) |
762 | 677 |