00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef _TREE_FLOW_INLINE_H
00023 #define _TREE_FLOW_INLINE_H 1
00024
00025
00026
00027
00028
00029
00030 static inline void *
00031 first_htab_element (htab_iterator *hti, htab_t table)
00032 {
00033 hti->htab = table;
00034 hti->slot = table->entries;
00035 hti->limit = hti->slot + htab_size (table);
00036 do
00037 {
00038 PTR x = *(hti->slot);
00039 if (x != HTAB_EMPTY_ENTRY && x != HTAB_DELETED_ENTRY)
00040 break;
00041 } while (++(hti->slot) < hti->limit);
00042
00043 if (hti->slot < hti->limit)
00044 return *(hti->slot);
00045 return NULL;
00046 }
00047
00048
00049
00050
00051 static inline bool
00052 end_htab_p (htab_iterator *hti)
00053 {
00054 if (hti->slot >= hti->limit)
00055 return true;
00056 return false;
00057 }
00058
00059
00060
00061
00062 static inline void *
00063 next_htab_element (htab_iterator *hti)
00064 {
00065 while (++(hti->slot) < hti->limit)
00066 {
00067 PTR x = *(hti->slot);
00068 if (x != HTAB_EMPTY_ENTRY && x != HTAB_DELETED_ENTRY)
00069 return x;
00070 };
00071 return NULL;
00072 }
00073
00074
00075
00076
00077 static inline tree
00078 first_referenced_var (referenced_var_iterator *iter)
00079 {
00080 struct int_tree_map *itm;
00081 itm = (struct int_tree_map *) first_htab_element (&iter->hti,
00082 referenced_vars);
00083 if (!itm)
00084 return NULL;
00085 return itm->to;
00086 }
00087
00088
00089
00090
00091 static inline bool
00092 end_referenced_vars_p (referenced_var_iterator *iter)
00093 {
00094 return end_htab_p (&iter->hti);
00095 }
00096
00097
00098
00099
00100 static inline tree
00101 next_referenced_var (referenced_var_iterator *iter)
00102 {
00103 struct int_tree_map *itm;
00104 itm = (struct int_tree_map *) next_htab_element (&iter->hti);
00105 if (!itm)
00106 return NULL;
00107 return itm->to;
00108 }
00109
00110
00111
00112 static inline void
00113 fill_referenced_var_vec (VEC (tree, heap) **vec)
00114 {
00115 referenced_var_iterator rvi;
00116 tree var;
00117 *vec = NULL;
00118 FOR_EACH_REFERENCED_VAR (var, rvi)
00119 VEC_safe_push (tree, heap, *vec, var);
00120 }
00121
00122
00123
00124 static inline var_ann_t
00125 var_ann (tree t)
00126 {
00127 gcc_assert (t);
00128 gcc_assert (DECL_P (t));
00129 gcc_assert (TREE_CODE (t) != FUNCTION_DECL);
00130 gcc_assert (!t->common.ann || t->common.ann->common.type == VAR_ANN);
00131
00132 return (var_ann_t) t->common.ann;
00133 }
00134
00135
00136
00137 static inline var_ann_t
00138 get_var_ann (tree var)
00139 {
00140 var_ann_t ann = var_ann (var);
00141 return (ann) ? ann : create_var_ann (var);
00142 }
00143
00144
00145
00146 static inline function_ann_t
00147 function_ann (tree t)
00148 {
00149 gcc_assert (t);
00150 gcc_assert (TREE_CODE (t) == FUNCTION_DECL);
00151 gcc_assert (!t->common.ann || t->common.ann->common.type == FUNCTION_ANN);
00152
00153 return (function_ann_t) t->common.ann;
00154 }
00155
00156
00157
00158 static inline function_ann_t
00159 get_function_ann (tree var)
00160 {
00161 function_ann_t ann = function_ann (var);
00162 gcc_assert (!var->common.ann || var->common.ann->common.type == FUNCTION_ANN);
00163 return (ann) ? ann : create_function_ann (var);
00164 }
00165
00166
00167
00168 static inline stmt_ann_t
00169 stmt_ann (tree t)
00170 {
00171 #ifdef ENABLE_CHECKING
00172 gcc_assert (is_gimple_stmt (t));
00173 #endif
00174 gcc_assert (!t->common.ann || t->common.ann->common.type == STMT_ANN);
00175 return (stmt_ann_t) t->common.ann;
00176 }
00177
00178
00179
00180 static inline stmt_ann_t
00181 get_stmt_ann (tree stmt)
00182 {
00183 stmt_ann_t ann = stmt_ann (stmt);
00184 return (ann) ? ann : create_stmt_ann (stmt);
00185 }
00186
00187
00188 static inline enum tree_ann_type
00189 ann_type (tree_ann_t ann)
00190 {
00191 return ann->common.type;
00192 }
00193
00194
00195 static inline basic_block
00196 bb_for_stmt (tree t)
00197 {
00198 stmt_ann_t ann;
00199
00200 if (TREE_CODE (t) == PHI_NODE)
00201 return PHI_BB (t);
00202
00203 ann = stmt_ann (t);
00204 return ann ? ann->bb : NULL;
00205 }
00206
00207
00208
00209 static inline VEC(tree, gc) *
00210 may_aliases (tree var)
00211 {
00212 var_ann_t ann = var_ann (var);
00213 return ann ? ann->may_aliases : NULL;
00214 }
00215
00216
00217
00218 static inline int
00219 get_lineno (tree expr)
00220 {
00221 if (expr == NULL_TREE)
00222 return -1;
00223
00224 if (TREE_CODE (expr) == COMPOUND_EXPR)
00225 expr = TREE_OPERAND (expr, 0);
00226
00227 if (! EXPR_HAS_LOCATION (expr))
00228 return -1;
00229
00230 return EXPR_LINENO (expr);
00231 }
00232
00233
00234
00235 static inline const char *
00236 get_filename (tree expr)
00237 {
00238 const char *filename;
00239 if (expr == NULL_TREE)
00240 return "???";
00241
00242 if (TREE_CODE (expr) == COMPOUND_EXPR)
00243 expr = TREE_OPERAND (expr, 0);
00244
00245 if (EXPR_HAS_LOCATION (expr) && (filename = EXPR_FILENAME (expr)))
00246 return filename;
00247 else
00248 return "???";
00249 }
00250
00251
00252 static inline bool
00253 noreturn_call_p (tree t)
00254 {
00255 tree call = get_call_expr_in (t);
00256 return call != 0 && (call_expr_flags (call) & ECF_NORETURN) != 0;
00257 }
00258
00259
00260 static inline void
00261 mark_stmt_modified (tree t)
00262 {
00263 stmt_ann_t ann;
00264 if (TREE_CODE (t) == PHI_NODE)
00265 return;
00266
00267 ann = stmt_ann (t);
00268 if (ann == NULL)
00269 ann = create_stmt_ann (t);
00270 else if (noreturn_call_p (t))
00271 VEC_safe_push (tree, gc, modified_noreturn_calls, t);
00272 ann->modified = 1;
00273 }
00274
00275
00276 static inline void
00277 update_stmt (tree t)
00278 {
00279 if (TREE_CODE (t) == PHI_NODE)
00280 return;
00281 mark_stmt_modified (t);
00282 update_stmt_operands (t);
00283 }
00284
00285 static inline void
00286 update_stmt_if_modified (tree t)
00287 {
00288 if (stmt_modified_p (t))
00289 update_stmt_operands (t);
00290 }
00291
00292
00293 static inline bool
00294 stmt_modified_p (tree t)
00295 {
00296 stmt_ann_t ann = stmt_ann (t);
00297
00298
00299
00300
00301 return ann ? ann->modified : true;
00302 }
00303
00304
00305 static inline void
00306 delink_imm_use (ssa_use_operand_t *linknode)
00307 {
00308
00309 if (linknode->prev == NULL)
00310 return;
00311
00312 linknode->prev->next = linknode->next;
00313 linknode->next->prev = linknode->prev;
00314 linknode->prev = NULL;
00315 linknode->next = NULL;
00316 }
00317
00318
00319 static inline void
00320 link_imm_use_to_list (ssa_use_operand_t *linknode, ssa_use_operand_t *list)
00321 {
00322
00323
00324 linknode->prev = list;
00325 linknode->next = list->next;
00326 list->next->prev = linknode;
00327 list->next = linknode;
00328 }
00329
00330
00331 static inline void
00332 link_imm_use (ssa_use_operand_t *linknode, tree def)
00333 {
00334 ssa_use_operand_t *root;
00335
00336 if (!def || TREE_CODE (def) != SSA_NAME)
00337 linknode->prev = NULL;
00338 else
00339 {
00340 root = &(SSA_NAME_IMM_USE_NODE (def));
00341 #ifdef ENABLE_CHECKING
00342 if (linknode->use)
00343 gcc_assert (*(linknode->use) == def);
00344 #endif
00345 link_imm_use_to_list (linknode, root);
00346 }
00347 }
00348
00349
00350 static inline void
00351 set_ssa_use_from_ptr (use_operand_p use, tree val)
00352 {
00353 delink_imm_use (use);
00354 *(use->use) = val;
00355 link_imm_use (use, val);
00356 }
00357
00358
00359
00360 static inline void
00361 link_imm_use_stmt (ssa_use_operand_t *linknode, tree def, tree stmt)
00362 {
00363 if (stmt)
00364 link_imm_use (linknode, def);
00365 else
00366 link_imm_use (linknode, NULL);
00367 linknode->stmt = stmt;
00368 }
00369
00370
00371 static inline void
00372 relink_imm_use (ssa_use_operand_t *node, ssa_use_operand_t *old)
00373 {
00374
00375 gcc_assert (*(old->use) == *(node->use));
00376 node->prev = old->prev;
00377 node->next = old->next;
00378 if (old->prev)
00379 {
00380 old->prev->next = node;
00381 old->next->prev = node;
00382
00383 old->prev = NULL;
00384 }
00385 }
00386
00387
00388
00389 static inline void
00390 relink_imm_use_stmt (ssa_use_operand_t *linknode, ssa_use_operand_t *old, tree stmt)
00391 {
00392 if (stmt)
00393 relink_imm_use (linknode, old);
00394 else
00395 link_imm_use (linknode, NULL);
00396 linknode->stmt = stmt;
00397 }
00398
00399
00400
00401 static inline bool
00402 end_readonly_imm_use_p (imm_use_iterator *imm)
00403 {
00404 return (imm->imm_use == imm->end_p);
00405 }
00406
00407
00408 static inline use_operand_p
00409 first_readonly_imm_use (imm_use_iterator *imm, tree var)
00410 {
00411 gcc_assert (TREE_CODE (var) == SSA_NAME);
00412
00413 imm->end_p = &(SSA_NAME_IMM_USE_NODE (var));
00414 imm->imm_use = imm->end_p->next;
00415 #ifdef ENABLE_CHECKING
00416 imm->iter_node.next = imm->imm_use->next;
00417 #endif
00418 if (end_readonly_imm_use_p (imm))
00419 return NULL_USE_OPERAND_P;
00420 return imm->imm_use;
00421 }
00422
00423
00424 static inline use_operand_p
00425 next_readonly_imm_use (imm_use_iterator *imm)
00426 {
00427 use_operand_p old = imm->imm_use;
00428
00429 #ifdef ENABLE_CHECKING
00430
00431
00432
00433
00434 gcc_assert (imm->iter_node.next == old->next);
00435 imm->iter_node.next = old->next->next;
00436 #endif
00437
00438 imm->imm_use = old->next;
00439 if (end_readonly_imm_use_p (imm))
00440 return old;
00441 return imm->imm_use;
00442 }
00443
00444
00445 static inline bool
00446 has_zero_uses (tree var)
00447 {
00448 ssa_use_operand_t *ptr;
00449 ptr = &(SSA_NAME_IMM_USE_NODE (var));
00450
00451 return (ptr == ptr->next);
00452 }
00453
00454
00455 static inline bool
00456 has_single_use (tree var)
00457 {
00458 ssa_use_operand_t *ptr;
00459 ptr = &(SSA_NAME_IMM_USE_NODE (var));
00460
00461 return (ptr != ptr->next && ptr == ptr->next->next);
00462 }
00463
00464
00465
00466 static inline bool
00467 single_imm_use (tree var, use_operand_p *use_p, tree *stmt)
00468 {
00469 ssa_use_operand_t *ptr;
00470
00471 ptr = &(SSA_NAME_IMM_USE_NODE (var));
00472 if (ptr != ptr->next && ptr == ptr->next->next)
00473 {
00474 *use_p = ptr->next;
00475 *stmt = ptr->next->stmt;
00476 return true;
00477 }
00478 *use_p = NULL_USE_OPERAND_P;
00479 *stmt = NULL_TREE;
00480 return false;
00481 }
00482
00483
00484 static inline unsigned int
00485 num_imm_uses (tree var)
00486 {
00487 ssa_use_operand_t *ptr, *start;
00488 unsigned int num;
00489
00490 start = &(SSA_NAME_IMM_USE_NODE (var));
00491 num = 0;
00492 for (ptr = start->next; ptr != start; ptr = ptr->next)
00493 num++;
00494
00495 return num;
00496 }
00497
00498
00499
00500 static inline tree
00501 get_use_from_ptr (use_operand_p use)
00502 {
00503 return *(use->use);
00504 }
00505
00506
00507 static inline tree
00508 get_def_from_ptr (def_operand_p def)
00509 {
00510 return *def;
00511 }
00512
00513
00514 static inline def_operand_p
00515 get_phi_result_ptr (tree phi)
00516 {
00517 return &(PHI_RESULT_TREE (phi));
00518 }
00519
00520
00521 static inline use_operand_p
00522 get_phi_arg_def_ptr (tree phi, int i)
00523 {
00524 return &(PHI_ARG_IMM_USE_NODE (phi,i));
00525 }
00526
00527
00528
00529
00530 static inline bitmap
00531 addresses_taken (tree stmt)
00532 {
00533 stmt_ann_t ann = stmt_ann (stmt);
00534 return ann ? ann->addresses_taken : NULL;
00535 }
00536
00537
00538
00539 static inline tree
00540 phi_nodes (basic_block bb)
00541 {
00542 return bb->phi_nodes;
00543 }
00544
00545
00546
00547 static inline void
00548 set_phi_nodes (basic_block bb, tree l)
00549 {
00550 tree phi;
00551
00552 bb->phi_nodes = l;
00553 for (phi = l; phi; phi = PHI_CHAIN (phi))
00554 set_bb_for_stmt (phi, bb);
00555 }
00556
00557
00558
00559 static inline int
00560 phi_arg_index_from_use (use_operand_p use)
00561 {
00562 struct phi_arg_d *element, *root;
00563 int index;
00564 tree phi;
00565
00566
00567
00568
00569
00570 phi = USE_STMT (use);
00571 gcc_assert (TREE_CODE (phi) == PHI_NODE);
00572
00573 element = (struct phi_arg_d *)use;
00574 root = &(PHI_ARG_ELT (phi, 0));
00575 index = element - root;
00576
00577 #ifdef ENABLE_CHECKING
00578
00579
00580 gcc_assert (
00581 (((char *)element - (char *)root) % sizeof (struct phi_arg_d)) == 0);
00582 gcc_assert (index >= 0 && index < PHI_ARG_CAPACITY (phi));
00583 #endif
00584
00585 return index;
00586 }
00587
00588
00589
00590 static inline void
00591 set_is_used (tree var)
00592 {
00593 var_ann_t ann = get_var_ann (var);
00594 ann->used = 1;
00595 }
00596
00597
00598
00599
00600
00601 static inline bool
00602 is_exec_stmt (tree t)
00603 {
00604 return (t && !IS_EMPTY_STMT (t) && t != error_mark_node);
00605 }
00606
00607
00608
00609
00610 static inline bool
00611 is_label_stmt (tree t)
00612 {
00613 if (t)
00614 switch (TREE_CODE (t))
00615 {
00616 case LABEL_DECL:
00617 case LABEL_EXPR:
00618 case CASE_LABEL_EXPR:
00619 return true;
00620 default:
00621 return false;
00622 }
00623 return false;
00624 }
00625
00626
00627
00628
00629
00630 static inline bool
00631 phi_ssa_name_p (tree t)
00632 {
00633 if (TREE_CODE (t) == SSA_NAME)
00634 return true;
00635 #ifdef ENABLE_CHECKING
00636 gcc_assert (is_gimple_min_invariant (t));
00637 #endif
00638 return false;
00639 }
00640
00641
00642
00643
00644
00645 static inline block_stmt_iterator
00646 bsi_start (basic_block bb)
00647 {
00648 block_stmt_iterator bsi;
00649 if (bb->stmt_list)
00650 bsi.tsi = tsi_start (bb->stmt_list);
00651 else
00652 {
00653 gcc_assert (bb->index < NUM_FIXED_BLOCKS);
00654 bsi.tsi.ptr = NULL;
00655 bsi.tsi.container = NULL;
00656 }
00657 bsi.bb = bb;
00658 return bsi;
00659 }
00660
00661
00662
00663
00664 static inline block_stmt_iterator
00665 bsi_after_labels (basic_block bb)
00666 {
00667 block_stmt_iterator bsi = bsi_start (bb);
00668
00669 while (!bsi_end_p (bsi) && TREE_CODE (bsi_stmt (bsi)) == LABEL_EXPR)
00670 bsi_next (&bsi);
00671
00672 return bsi;
00673 }
00674
00675
00676
00677 static inline block_stmt_iterator
00678 bsi_last (basic_block bb)
00679 {
00680 block_stmt_iterator bsi;
00681 if (bb->stmt_list)
00682 bsi.tsi = tsi_last (bb->stmt_list);
00683 else
00684 {
00685 gcc_assert (bb->index < NUM_FIXED_BLOCKS);
00686 bsi.tsi.ptr = NULL;
00687 bsi.tsi.container = NULL;
00688 }
00689 bsi.bb = bb;
00690 return bsi;
00691 }
00692
00693
00694
00695 static inline bool
00696 bsi_end_p (block_stmt_iterator i)
00697 {
00698 return tsi_end_p (i.tsi);
00699 }
00700
00701
00702
00703 static inline void
00704 bsi_next (block_stmt_iterator *i)
00705 {
00706 tsi_next (&i->tsi);
00707 }
00708
00709
00710
00711 static inline void
00712 bsi_prev (block_stmt_iterator *i)
00713 {
00714 tsi_prev (&i->tsi);
00715 }
00716
00717
00718
00719 static inline tree
00720 bsi_stmt (block_stmt_iterator i)
00721 {
00722 return tsi_stmt (i.tsi);
00723 }
00724
00725
00726
00727 static inline tree *
00728 bsi_stmt_ptr (block_stmt_iterator i)
00729 {
00730 return tsi_stmt_ptr (i.tsi);
00731 }
00732
00733
00734
00735 static inline struct loop *
00736 loop_containing_stmt (tree stmt)
00737 {
00738 basic_block bb = bb_for_stmt (stmt);
00739 if (!bb)
00740 return NULL;
00741
00742 return bb->loop_father;
00743 }
00744
00745
00746 static inline bool
00747 is_call_clobbered (tree var)
00748 {
00749 if (!MTAG_P (var))
00750 return DECL_CALL_CLOBBERED (var);
00751 else
00752 return bitmap_bit_p (call_clobbered_vars, DECL_UID (var));
00753 }
00754
00755
00756 static inline void
00757 mark_call_clobbered (tree var, unsigned int escape_type)
00758 {
00759 var_ann (var)->escape_mask |= escape_type;
00760 if (!MTAG_P (var))
00761 DECL_CALL_CLOBBERED (var) = true;
00762 bitmap_set_bit (call_clobbered_vars, DECL_UID (var));
00763 }
00764
00765
00766 static inline void
00767 clear_call_clobbered (tree var)
00768 {
00769 var_ann_t ann = var_ann (var);
00770 ann->escape_mask = 0;
00771 if (MTAG_P (var) && TREE_CODE (var) != STRUCT_FIELD_TAG)
00772 MTAG_GLOBAL (var) = 0;
00773 if (!MTAG_P (var))
00774 DECL_CALL_CLOBBERED (var) = false;
00775 bitmap_clear_bit (call_clobbered_vars, DECL_UID (var));
00776 }
00777
00778
00779 static inline void
00780 mark_non_addressable (tree var)
00781 {
00782 if (!MTAG_P (var))
00783 DECL_CALL_CLOBBERED (var) = false;
00784 bitmap_clear_bit (call_clobbered_vars, DECL_UID (var));
00785 TREE_ADDRESSABLE (var) = 0;
00786 }
00787
00788
00789
00790 static inline tree_ann_common_t
00791 tree_common_ann (tree t)
00792 {
00793 return &t->common.ann->common;
00794 }
00795
00796
00797
00798 static inline tree_ann_common_t
00799 get_tree_common_ann (tree t)
00800 {
00801 tree_ann_common_t ann = tree_common_ann (t);
00802 return (ann) ? ann : create_tree_common_ann (t);
00803 }
00804
00805
00806
00807
00808
00809
00810
00811 static inline bool
00812 op_iter_done (ssa_op_iter *ptr)
00813 {
00814 return ptr->done;
00815 }
00816
00817
00818 static inline use_operand_p
00819 op_iter_next_use (ssa_op_iter *ptr)
00820 {
00821 use_operand_p use_p;
00822 #ifdef ENABLE_CHECKING
00823 gcc_assert (ptr->iter_type == ssa_op_iter_use);
00824 #endif
00825 if (ptr->uses)
00826 {
00827 use_p = USE_OP_PTR (ptr->uses);
00828 ptr->uses = ptr->uses->next;
00829 return use_p;
00830 }
00831 if (ptr->vuses)
00832 {
00833 use_p = VUSE_OP_PTR (ptr->vuses);
00834 ptr->vuses = ptr->vuses->next;
00835 return use_p;
00836 }
00837 if (ptr->mayuses)
00838 {
00839 use_p = MAYDEF_OP_PTR (ptr->mayuses);
00840 ptr->mayuses = ptr->mayuses->next;
00841 return use_p;
00842 }
00843 if (ptr->mustkills)
00844 {
00845 use_p = MUSTDEF_KILL_PTR (ptr->mustkills);
00846 ptr->mustkills = ptr->mustkills->next;
00847 return use_p;
00848 }
00849 if (ptr->phi_i < ptr->num_phi)
00850 {
00851 return PHI_ARG_DEF_PTR (ptr->phi_stmt, (ptr->phi_i)++);
00852 }
00853 ptr->done = true;
00854 return NULL_USE_OPERAND_P;
00855 }
00856
00857
00858 static inline def_operand_p
00859 op_iter_next_def (ssa_op_iter *ptr)
00860 {
00861 def_operand_p def_p;
00862 #ifdef ENABLE_CHECKING
00863 gcc_assert (ptr->iter_type == ssa_op_iter_def);
00864 #endif
00865 if (ptr->defs)
00866 {
00867 def_p = DEF_OP_PTR (ptr->defs);
00868 ptr->defs = ptr->defs->next;
00869 return def_p;
00870 }
00871 if (ptr->mustdefs)
00872 {
00873 def_p = MUSTDEF_RESULT_PTR (ptr->mustdefs);
00874 ptr->mustdefs = ptr->mustdefs->next;
00875 return def_p;
00876 }
00877 if (ptr->maydefs)
00878 {
00879 def_p = MAYDEF_RESULT_PTR (ptr->maydefs);
00880 ptr->maydefs = ptr->maydefs->next;
00881 return def_p;
00882 }
00883 ptr->done = true;
00884 return NULL_DEF_OPERAND_P;
00885 }
00886
00887
00888 static inline tree
00889 op_iter_next_tree (ssa_op_iter *ptr)
00890 {
00891 tree val;
00892 #ifdef ENABLE_CHECKING
00893 gcc_assert (ptr->iter_type == ssa_op_iter_tree);
00894 #endif
00895 if (ptr->uses)
00896 {
00897 val = USE_OP (ptr->uses);
00898 ptr->uses = ptr->uses->next;
00899 return val;
00900 }
00901 if (ptr->vuses)
00902 {
00903 val = VUSE_OP (ptr->vuses);
00904 ptr->vuses = ptr->vuses->next;
00905 return val;
00906 }
00907 if (ptr->mayuses)
00908 {
00909 val = MAYDEF_OP (ptr->mayuses);
00910 ptr->mayuses = ptr->mayuses->next;
00911 return val;
00912 }
00913 if (ptr->mustkills)
00914 {
00915 val = MUSTDEF_KILL (ptr->mustkills);
00916 ptr->mustkills = ptr->mustkills->next;
00917 return val;
00918 }
00919 if (ptr->defs)
00920 {
00921 val = DEF_OP (ptr->defs);
00922 ptr->defs = ptr->defs->next;
00923 return val;
00924 }
00925 if (ptr->mustdefs)
00926 {
00927 val = MUSTDEF_RESULT (ptr->mustdefs);
00928 ptr->mustdefs = ptr->mustdefs->next;
00929 return val;
00930 }
00931 if (ptr->maydefs)
00932 {
00933 val = MAYDEF_RESULT (ptr->maydefs);
00934 ptr->maydefs = ptr->maydefs->next;
00935 return val;
00936 }
00937
00938 ptr->done = true;
00939 return NULL_TREE;
00940
00941 }
00942
00943
00944
00945
00946
00947
00948 static inline void
00949 clear_and_done_ssa_iter (ssa_op_iter *ptr)
00950 {
00951 ptr->defs = NULL;
00952 ptr->uses = NULL;
00953 ptr->vuses = NULL;
00954 ptr->maydefs = NULL;
00955 ptr->mayuses = NULL;
00956 ptr->mustdefs = NULL;
00957 ptr->mustkills = NULL;
00958 ptr->iter_type = ssa_op_iter_none;
00959 ptr->phi_i = 0;
00960 ptr->num_phi = 0;
00961 ptr->phi_stmt = NULL_TREE;
00962 ptr->done = true;
00963 }
00964
00965
00966 static inline void
00967 op_iter_init (ssa_op_iter *ptr, tree stmt, int flags)
00968 {
00969 #ifdef ENABLE_CHECKING
00970 gcc_assert (stmt_ann (stmt));
00971 #endif
00972
00973 ptr->defs = (flags & SSA_OP_DEF) ? DEF_OPS (stmt) : NULL;
00974 ptr->uses = (flags & SSA_OP_USE) ? USE_OPS (stmt) : NULL;
00975 ptr->vuses = (flags & SSA_OP_VUSE) ? VUSE_OPS (stmt) : NULL;
00976 ptr->maydefs = (flags & SSA_OP_VMAYDEF) ? MAYDEF_OPS (stmt) : NULL;
00977 ptr->mayuses = (flags & SSA_OP_VMAYUSE) ? MAYDEF_OPS (stmt) : NULL;
00978 ptr->mustdefs = (flags & SSA_OP_VMUSTDEF) ? MUSTDEF_OPS (stmt) : NULL;
00979 ptr->mustkills = (flags & SSA_OP_VMUSTKILL) ? MUSTDEF_OPS (stmt) : NULL;
00980 ptr->done = false;
00981
00982 ptr->phi_i = 0;
00983 ptr->num_phi = 0;
00984 ptr->phi_stmt = NULL_TREE;
00985 }
00986
00987
00988
00989 static inline use_operand_p
00990 op_iter_init_use (ssa_op_iter *ptr, tree stmt, int flags)
00991 {
00992 gcc_assert ((flags & SSA_OP_ALL_DEFS) == 0);
00993 op_iter_init (ptr, stmt, flags);
00994 ptr->iter_type = ssa_op_iter_use;
00995 return op_iter_next_use (ptr);
00996 }
00997
00998
00999
01000 static inline def_operand_p
01001 op_iter_init_def (ssa_op_iter *ptr, tree stmt, int flags)
01002 {
01003 gcc_assert ((flags & (SSA_OP_ALL_USES | SSA_OP_VIRTUAL_KILLS)) == 0);
01004 op_iter_init (ptr, stmt, flags);
01005 ptr->iter_type = ssa_op_iter_def;
01006 return op_iter_next_def (ptr);
01007 }
01008
01009
01010
01011 static inline tree
01012 op_iter_init_tree (ssa_op_iter *ptr, tree stmt, int flags)
01013 {
01014 op_iter_init (ptr, stmt, flags);
01015 ptr->iter_type = ssa_op_iter_tree;
01016 return op_iter_next_tree (ptr);
01017 }
01018
01019
01020
01021 static inline void
01022 op_iter_next_maymustdef (use_operand_p *use, def_operand_p *def,
01023 ssa_op_iter *ptr)
01024 {
01025 #ifdef ENABLE_CHECKING
01026 gcc_assert (ptr->iter_type == ssa_op_iter_maymustdef);
01027 #endif
01028 if (ptr->mayuses)
01029 {
01030 *def = MAYDEF_RESULT_PTR (ptr->mayuses);
01031 *use = MAYDEF_OP_PTR (ptr->mayuses);
01032 ptr->mayuses = ptr->mayuses->next;
01033 return;
01034 }
01035
01036 if (ptr->mustkills)
01037 {
01038 *def = MUSTDEF_RESULT_PTR (ptr->mustkills);
01039 *use = MUSTDEF_KILL_PTR (ptr->mustkills);
01040 ptr->mustkills = ptr->mustkills->next;
01041 return;
01042 }
01043
01044 *def = NULL_DEF_OPERAND_P;
01045 *use = NULL_USE_OPERAND_P;
01046 ptr->done = true;
01047 return;
01048 }
01049
01050
01051
01052
01053 static inline void
01054 op_iter_init_maydef (ssa_op_iter *ptr, tree stmt, use_operand_p *use,
01055 def_operand_p *def)
01056 {
01057 gcc_assert (TREE_CODE (stmt) != PHI_NODE);
01058
01059 op_iter_init (ptr, stmt, SSA_OP_VMAYUSE);
01060 ptr->iter_type = ssa_op_iter_maymustdef;
01061 op_iter_next_maymustdef (use, def, ptr);
01062 }
01063
01064
01065
01066
01067 static inline void
01068 op_iter_init_mustdef (ssa_op_iter *ptr, tree stmt, use_operand_p *kill,
01069 def_operand_p *def)
01070 {
01071 gcc_assert (TREE_CODE (stmt) != PHI_NODE);
01072
01073 op_iter_init (ptr, stmt, SSA_OP_VMUSTKILL);
01074 ptr->iter_type = ssa_op_iter_maymustdef;
01075 op_iter_next_maymustdef (kill, def, ptr);
01076 }
01077
01078
01079
01080 static inline void
01081 op_iter_init_must_and_may_def (ssa_op_iter *ptr, tree stmt,
01082 use_operand_p *kill, def_operand_p *def)
01083 {
01084 gcc_assert (TREE_CODE (stmt) != PHI_NODE);
01085
01086 op_iter_init (ptr, stmt, SSA_OP_VMUSTKILL|SSA_OP_VMAYUSE);
01087 ptr->iter_type = ssa_op_iter_maymustdef;
01088 op_iter_next_maymustdef (kill, def, ptr);
01089 }
01090
01091
01092
01093
01094 static inline tree
01095 single_ssa_tree_operand (tree stmt, int flags)
01096 {
01097 tree var;
01098 ssa_op_iter iter;
01099
01100 var = op_iter_init_tree (&iter, stmt, flags);
01101 if (op_iter_done (&iter))
01102 return NULL_TREE;
01103 op_iter_next_tree (&iter);
01104 if (op_iter_done (&iter))
01105 return var;
01106 return NULL_TREE;
01107 }
01108
01109
01110
01111
01112 static inline use_operand_p
01113 single_ssa_use_operand (tree stmt, int flags)
01114 {
01115 use_operand_p var;
01116 ssa_op_iter iter;
01117
01118 var = op_iter_init_use (&iter, stmt, flags);
01119 if (op_iter_done (&iter))
01120 return NULL_USE_OPERAND_P;
01121 op_iter_next_use (&iter);
01122 if (op_iter_done (&iter))
01123 return var;
01124 return NULL_USE_OPERAND_P;
01125 }
01126
01127
01128
01129
01130
01131 static inline def_operand_p
01132 single_ssa_def_operand (tree stmt, int flags)
01133 {
01134 def_operand_p var;
01135 ssa_op_iter iter;
01136
01137 var = op_iter_init_def (&iter, stmt, flags);
01138 if (op_iter_done (&iter))
01139 return NULL_DEF_OPERAND_P;
01140 op_iter_next_def (&iter);
01141 if (op_iter_done (&iter))
01142 return var;
01143 return NULL_DEF_OPERAND_P;
01144 }
01145
01146
01147
01148
01149 static inline bool
01150 zero_ssa_operands (tree stmt, int flags)
01151 {
01152 ssa_op_iter iter;
01153
01154 op_iter_init_tree (&iter, stmt, flags);
01155 return op_iter_done (&iter);
01156 }
01157
01158
01159
01160 static inline int
01161 num_ssa_operands (tree stmt, int flags)
01162 {
01163 ssa_op_iter iter;
01164 tree t;
01165 int num = 0;
01166
01167 FOR_EACH_SSA_TREE_OPERAND (t, stmt, iter, flags)
01168 num++;
01169 return num;
01170 }
01171
01172
01173
01174 static inline void
01175 delink_stmt_imm_use (tree stmt)
01176 {
01177 ssa_op_iter iter;
01178 use_operand_p use_p;
01179
01180 if (ssa_operands_active ())
01181 FOR_EACH_SSA_USE_OPERAND (use_p, stmt, iter,
01182 (SSA_OP_ALL_USES | SSA_OP_ALL_KILLS))
01183 delink_imm_use (use_p);
01184 }
01185
01186
01187
01188
01189 static inline bool
01190 compare_ssa_operands_equal (tree stmt1, tree stmt2, int flags)
01191 {
01192 ssa_op_iter iter1, iter2;
01193 tree op1 = NULL_TREE;
01194 tree op2 = NULL_TREE;
01195 bool look1, look2;
01196
01197 if (stmt1 == stmt2)
01198 return true;
01199
01200 look1 = stmt1 && stmt_ann (stmt1);
01201 look2 = stmt2 && stmt_ann (stmt2);
01202
01203 if (look1)
01204 {
01205 op1 = op_iter_init_tree (&iter1, stmt1, flags);
01206 if (!look2)
01207 return op_iter_done (&iter1);
01208 }
01209 else
01210 clear_and_done_ssa_iter (&iter1);
01211
01212 if (look2)
01213 {
01214 op2 = op_iter_init_tree (&iter2, stmt2, flags);
01215 if (!look1)
01216 return op_iter_done (&iter2);
01217 }
01218 else
01219 clear_and_done_ssa_iter (&iter2);
01220
01221 while (!op_iter_done (&iter1) && !op_iter_done (&iter2))
01222 {
01223 if (op1 != op2)
01224 return false;
01225 op1 = op_iter_next_tree (&iter1);
01226 op2 = op_iter_next_tree (&iter2);
01227 }
01228
01229 return (op_iter_done (&iter1) && op_iter_done (&iter2));
01230 }
01231
01232
01233
01234
01235 static inline tree
01236 single_phi_def (tree stmt, int flags)
01237 {
01238 tree def = PHI_RESULT (stmt);
01239 if ((flags & SSA_OP_DEF) && is_gimple_reg (def))
01240 return def;
01241 if ((flags & SSA_OP_VIRTUAL_DEFS) && !is_gimple_reg (def))
01242 return def;
01243 return NULL_TREE;
01244 }
01245
01246
01247
01248 static inline use_operand_p
01249 op_iter_init_phiuse (ssa_op_iter *ptr, tree phi, int flags)
01250 {
01251 tree phi_def = PHI_RESULT (phi);
01252 int comp;
01253
01254 clear_and_done_ssa_iter (ptr);
01255 ptr->done = false;
01256
01257 gcc_assert ((flags & (SSA_OP_USE | SSA_OP_VIRTUAL_USES)) != 0);
01258
01259 comp = (is_gimple_reg (phi_def) ? SSA_OP_USE : SSA_OP_VIRTUAL_USES);
01260
01261
01262 if ((flags & comp) == 0)
01263 {
01264 ptr->done = true;
01265 return NULL_USE_OPERAND_P;
01266 }
01267
01268 ptr->phi_stmt = phi;
01269 ptr->num_phi = PHI_NUM_ARGS (phi);
01270 ptr->iter_type = ssa_op_iter_use;
01271 return op_iter_next_use (ptr);
01272 }
01273
01274
01275
01276
01277 static inline def_operand_p
01278 op_iter_init_phidef (ssa_op_iter *ptr, tree phi, int flags)
01279 {
01280 tree phi_def = PHI_RESULT (phi);
01281 int comp;
01282
01283 clear_and_done_ssa_iter (ptr);
01284 ptr->done = false;
01285
01286 gcc_assert ((flags & (SSA_OP_DEF | SSA_OP_VIRTUAL_DEFS)) != 0);
01287
01288 comp = (is_gimple_reg (phi_def) ? SSA_OP_DEF : SSA_OP_VIRTUAL_DEFS);
01289
01290
01291 if ((flags & comp) == 0)
01292 {
01293 ptr->done = true;
01294 return NULL_USE_OPERAND_P;
01295 }
01296
01297 ptr->iter_type = ssa_op_iter_def;
01298
01299
01300
01301 return PHI_RESULT_PTR (phi);
01302 }
01303
01304
01305
01306 static inline bool
01307 end_imm_use_stmt_p (imm_use_iterator *imm)
01308 {
01309 return (imm->imm_use == imm->end_p);
01310 }
01311
01312
01313
01314
01315 static inline void
01316 end_imm_use_stmt_traverse (imm_use_iterator *imm)
01317 {
01318 delink_imm_use (&(imm->iter_node));
01319 }
01320
01321
01322
01323
01324
01325
01326
01327 static inline use_operand_p
01328 move_use_after_head (use_operand_p use_p, use_operand_p head,
01329 use_operand_p last_p)
01330 {
01331 gcc_assert (USE_FROM_PTR (use_p) == USE_FROM_PTR (head));
01332
01333 if (use_p != head)
01334 {
01335
01336 if (last_p->next == use_p)
01337 last_p = use_p;
01338 else
01339 {
01340
01341 delink_imm_use (use_p);
01342 link_imm_use_to_list (use_p, last_p);
01343 last_p = use_p;
01344 }
01345 }
01346 return last_p;
01347 }
01348
01349
01350
01351
01352
01353 static inline void
01354 link_use_stmts_after (use_operand_p head, imm_use_iterator *imm)
01355 {
01356 use_operand_p use_p;
01357 use_operand_p last_p = head;
01358 tree head_stmt = USE_STMT (head);
01359 tree use = USE_FROM_PTR (head);
01360 ssa_op_iter op_iter;
01361 int flag;
01362
01363
01364 flag = (is_gimple_reg (use) ? SSA_OP_USE : SSA_OP_VIRTUAL_USES);
01365
01366 if (TREE_CODE (head_stmt) == PHI_NODE)
01367 {
01368 FOR_EACH_PHI_ARG (use_p, head_stmt, op_iter, flag)
01369 if (USE_FROM_PTR (use_p) == use)
01370 last_p = move_use_after_head (use_p, head, last_p);
01371 }
01372 else
01373 {
01374 FOR_EACH_SSA_USE_OPERAND (use_p, head_stmt, op_iter, flag)
01375 if (USE_FROM_PTR (use_p) == use)
01376 last_p = move_use_after_head (use_p, head, last_p);
01377 }
01378
01379 if (imm->iter_node.prev != NULL)
01380 delink_imm_use (&imm->iter_node);
01381 link_imm_use_to_list (&(imm->iter_node), last_p);
01382 }
01383
01384
01385 static inline tree
01386 first_imm_use_stmt (imm_use_iterator *imm, tree var)
01387 {
01388 gcc_assert (TREE_CODE (var) == SSA_NAME);
01389
01390 imm->end_p = &(SSA_NAME_IMM_USE_NODE (var));
01391 imm->imm_use = imm->end_p->next;
01392 imm->next_imm_name = NULL_USE_OPERAND_P;
01393
01394
01395
01396
01397 imm->iter_node.prev = NULL_USE_OPERAND_P;
01398 imm->iter_node.next = NULL_USE_OPERAND_P;
01399 imm->iter_node.stmt = NULL_TREE;
01400 imm->iter_node.use = NULL_USE_OPERAND_P;
01401
01402 if (end_imm_use_stmt_p (imm))
01403 return NULL_TREE;
01404
01405 link_use_stmts_after (imm->imm_use, imm);
01406
01407 return USE_STMT (imm->imm_use);
01408 }
01409
01410
01411
01412 static inline tree
01413 next_imm_use_stmt (imm_use_iterator *imm)
01414 {
01415 imm->imm_use = imm->iter_node.next;
01416 if (end_imm_use_stmt_p (imm))
01417 {
01418 if (imm->iter_node.prev != NULL)
01419 delink_imm_use (&imm->iter_node);
01420 return NULL_TREE;
01421 }
01422
01423 link_use_stmts_after (imm->imm_use, imm);
01424 return USE_STMT (imm->imm_use);
01425
01426 }
01427
01428
01429
01430
01431 static inline use_operand_p
01432 first_imm_use_on_stmt (imm_use_iterator *imm)
01433 {
01434 imm->next_imm_name = imm->imm_use->next;
01435 return imm->imm_use;
01436 }
01437
01438
01439
01440 static inline bool
01441 end_imm_use_on_stmt_p (imm_use_iterator *imm)
01442 {
01443 return (imm->imm_use == &(imm->iter_node));
01444 }
01445
01446
01447
01448 static inline use_operand_p
01449 next_imm_use_on_stmt (imm_use_iterator *imm)
01450 {
01451 imm->imm_use = imm->next_imm_name;
01452 if (end_imm_use_on_stmt_p (imm))
01453 return NULL_USE_OPERAND_P;
01454 else
01455 {
01456 imm->next_imm_name = imm->imm_use->next;
01457 return imm->imm_use;
01458 }
01459 }
01460
01461
01462
01463 static inline bool
01464 unmodifiable_var_p (tree var)
01465 {
01466 if (TREE_CODE (var) == SSA_NAME)
01467 var = SSA_NAME_VAR (var);
01468
01469 if (MTAG_P (var))
01470 return TREE_READONLY (var) && (TREE_STATIC (var) || MTAG_GLOBAL (var));
01471
01472 return TREE_READONLY (var) && (TREE_STATIC (var) || DECL_EXTERNAL (var));
01473 }
01474
01475
01476
01477 static inline bool
01478 array_ref_contains_indirect_ref (tree ref)
01479 {
01480 gcc_assert (TREE_CODE (ref) == ARRAY_REF);
01481
01482 do {
01483 ref = TREE_OPERAND (ref, 0);
01484 } while (handled_component_p (ref));
01485
01486 return TREE_CODE (ref) == INDIRECT_REF;
01487 }
01488
01489
01490
01491
01492 static inline bool
01493 ref_contains_array_ref (tree ref)
01494 {
01495 gcc_assert (handled_component_p (ref));
01496
01497 do {
01498 if (TREE_CODE (ref) == ARRAY_REF)
01499 return true;
01500 ref = TREE_OPERAND (ref, 0);
01501 } while (handled_component_p (ref));
01502
01503 return false;
01504 }
01505
01506
01507
01508
01509 static inline subvar_t *
01510 lookup_subvars_for_var (tree var)
01511 {
01512 var_ann_t ann = var_ann (var);
01513 gcc_assert (ann);
01514 return &ann->subvars;
01515 }
01516
01517
01518
01519
01520 static inline subvar_t
01521 get_subvars_for_var (tree var)
01522 {
01523 subvar_t subvars;
01524
01525 gcc_assert (SSA_VAR_P (var));
01526
01527 if (TREE_CODE (var) == SSA_NAME)
01528 subvars = *(lookup_subvars_for_var (SSA_NAME_VAR (var)));
01529 else
01530 subvars = *(lookup_subvars_for_var (var));
01531 return subvars;
01532 }
01533
01534
01535
01536 static inline tree
01537 get_subvar_at (tree var, unsigned HOST_WIDE_INT offset)
01538 {
01539 subvar_t sv;
01540
01541 for (sv = get_subvars_for_var (var); sv; sv = sv->next)
01542 if (SFT_OFFSET (sv->var) == offset)
01543 return sv->var;
01544
01545 return NULL_TREE;
01546 }
01547
01548
01549
01550
01551
01552 static inline bool
01553 var_can_have_subvars (tree v)
01554 {
01555
01556 if (TREE_THIS_VOLATILE (v))
01557 return false;
01558
01559
01560 if (!DECL_P (v) || MTAG_P (v))
01561 return false;
01562
01563
01564 if (AGGREGATE_TYPE_P (TREE_TYPE (v)))
01565 return true;
01566
01567
01568
01569 if (TREE_CODE (TREE_TYPE (v)) == COMPLEX_TYPE
01570 && !DECL_COMPLEX_GIMPLE_REG_P (v))
01571 return true;
01572
01573 return false;
01574 }
01575
01576
01577
01578
01579
01580
01581 static inline bool
01582 overlap_subvar (unsigned HOST_WIDE_INT offset, unsigned HOST_WIDE_INT size,
01583 tree sv, bool *exact)
01584 {
01585
01586
01587
01588
01589
01590
01591
01592
01593
01594
01595
01596
01597
01598
01599
01600
01601 if (exact)
01602 *exact = false;
01603 if (offset == SFT_OFFSET (sv) && size == SFT_SIZE (sv))
01604 {
01605 if (exact)
01606 *exact = true;
01607 return true;
01608 }
01609 else if (offset >= SFT_OFFSET (sv)
01610 && offset < (SFT_OFFSET (sv) + SFT_SIZE (sv)))
01611 {
01612 return true;
01613 }
01614 else if (offset < SFT_OFFSET (sv)
01615 && (size > SFT_OFFSET (sv) - offset))
01616 {
01617 return true;
01618 }
01619 return false;
01620
01621 }
01622
01623 #endif