GCC Wikia
Advertisement

このページを編集する際は,編集に関する方針に従ってください.[]

概要[]

引数[]

実装[]

 2603 /* A helper function for build1 and constant folders.  Set TREE_CONSTANT,
 2604    TREE_INVARIANT, and TREE_SIDE_EFFECTS for an ADDR_EXPR.  */
2605 
2606 void
2607 recompute_tree_invarant_for_addr_expr (tree t)
2608 {
2609   tree node;
2610   bool tc = true, ti = true, se = false;
2611 
 2612   /* We started out assuming this address is both invariant and constant, but
 2613      does not have side effects.  Now go down any handled components and see if
 2614      any of them involve offsets that are either non-constant or non-invariant.
 2615      Also check for side-effects.
 2616 
 2617      ??? Note that this code makes no attempt to deal with the case where
 2618      taking the address of something causes a copy due to misalignment.  */
2619 

~

2620 #define UPDATE_TITCSE(NODE)  \

*なぜ一旦_nodeにNODEを代入するようにしてるんだろうか
**今後拡張することを考えてこういう風にしているとかか

2621 do { tree _node = (NODE); \
2622      if (_node && !TREE_INVARIANT (_node)) ti = false; \
2623      if (_node && !TREE_CONSTANT (_node)) tc = false; \
2624      if (_node && TREE_SIDE_EFFECTS (_node)) se = true; } while (0)

~

2625 
2626   for (node = TREE_OPERAND (t, 0); handled_component_p (node);
2627        node = TREE_OPERAND (node, 0))
2628     {
 2629       /* If the first operand doesn't have an ARRAY_TYPE, this is a bogus
 2630          array reference (probably made temporarily by the G++ front end),
 2631          so ignore all the operands.  */
2632       if ((TREE_CODE (node) == [[ARRAY_REF>enum tree_code]]
2633            || TREE_CODE (node) == [[ARRAY_RANGE_REF>enum tree_code]])
2634           && TREE_CODE (TREE_TYPE (TREE_OPERAND (node, 0))) == [[ARRAY_TYPE> enum tree_code]])
2635         {
2636           UPDATE_TITCSE (TREE_OPERAND (node, 1));
2637           if (TREE_OPERAND (node, 2))
2638             UPDATE_TITCSE (TREE_OPERAND (node, 2));
2639           if (TREE_OPERAND (node, 3))
2640             UPDATE_TITCSE (TREE_OPERAND (node, 3));
2641         }
 2642       /* Likewise, just because this is a COMPONENT_REF doesn't mean we have a
 2643          FIELD_DECL, apparently.  The G++ front end can put something else
 2644          there, at least temporarily.  */
2645       else if (TREE_CODE (node) == [[COMPONENT_REF>enum tree_code]]
2646                && TREE_CODE (TREE_OPERAND (node, 1)) == [[FIELD_DECL>enum tree_code]])
2647         {
2648           if (TREE_OPERAND (node, 2))
2649             UPDATE_TITCSE (TREE_OPERAND (node, 2));
2650         }
2651       else if (TREE_CODE (node) == [[BIT_FIELD_REF>enum tree_code]])
2652         UPDATE_TITCSE (TREE_OPERAND (node, 2));
2653     }
2654 

~
*ここがよくわかってない
**expressionからdeclに変換する
**tc,ti,seの値にも影響があるっぽい

2655   node = lang_hooks.expr_to_decl (node, &tc, &ti, &se);
2656 

~

 2657   /* Now see what's inside.  If it's an INDIRECT_REF, copy our properties from
 2658      the address, since &(*a)->b is a form of addition.  If it's a decl, it's
 2659      invariant and constant if the decl is static.  It's also invariant if it's
 2660      a decl in the current function.  Taking the address of a volatile variable
 2661      is not volatile.  If it's a constant, the address is both invariant and
 2662      constant.  Otherwise it's neither.  */
2663   if (TREE_CODE (node) == [[INDIRECT_REF>enum tree_code]])
2664     UPDATE_TITCSE (TREE_OPERAND (node, 0));
2665   else if (DECL_P (node))
2666     {
2667       if (staticp (node))
2668         ;
2669       else if (decl_function_context (node) == current_function_decl
 2670                /* Addresses of thread-local variables are invariant.  */
2671                || (TREE_CODE (node) == [[VAR_DECL>enum tree_code]]
2672                    && DECL_THREAD_LOCAL_P (node)))
2673         tc = false;
2674       else
2675         ti = tc = false;
2676     }
2677   else if (CONSTANT_CLASS_P (node))
2678     ;
2679   else
2680     {
2681       ti = tc = false;
2682       se |= TREE_SIDE_EFFECTS (node);
2683     }
2684 

~
*求めたtc,ti,seを代入

2685   TREE_CONSTANT (t) = tc;
2686   TREE_INVARIANT (t) = ti;
2687   TREE_SIDE_EFFECTS (t) = se;
2688 #undef UPDATE_TITCSE
2689 }


リンク元

Advertisement