+/* Insert BINFO to the list of known types of parameter number I of the
+ function described by CALLEE_INFO. Return true iff the type information
+ associated with the callee parameter changed in any way. */
+
+static bool
+ipcp_add_param_type (struct ipa_node_params *callee_info, int i, tree binfo)
+{
+ int j, count;
+
+ if (ipa_param_cannot_devirtualize_p (callee_info, i))
+ return false;
+
+ if (callee_info->params[i].types)
+ {
+ count = VEC_length (tree, callee_info->params[i].types);
+ for (j = 0; j < count; j++)
+ if (VEC_index (tree, callee_info->params[i].types, j) == binfo)
+ return false;
+ }
+
+ if (VEC_length (tree, callee_info->params[i].types)
+ == (unsigned) PARAM_VALUE (PARAM_DEVIRT_TYPE_LIST_SIZE))
+ return !ipa_set_param_cannot_devirtualize (callee_info, i);
+
+ VEC_safe_push (tree, heap, callee_info->params[i].types, binfo);
+ return true;
+}
+
+/* Copy known types information for parameter number CALLEE_IDX of CALLEE_INFO
+ from a parameter of CALLER_INFO as described by JF. Return true iff the
+ type information changed in any way. JF must be a pass-through or an
+ ancestor jump function. */
+
+static bool
+ipcp_copy_types (struct ipa_node_params *caller_info,
+ struct ipa_node_params *callee_info,
+ int callee_idx, struct ipa_jump_func *jf)
+{
+ int caller_idx, j, count;
+ bool res;
+
+ if (ipa_param_cannot_devirtualize_p (callee_info, callee_idx))
+ return false;
+
+ if (jf->type == IPA_JF_PASS_THROUGH)
+ {
+ if (jf->value.pass_through.operation != NOP_EXPR)
+ {
+ ipa_set_param_cannot_devirtualize (callee_info, callee_idx);
+ return true;
+ }
+ caller_idx = jf->value.pass_through.formal_id;
+ }
+ else
+ caller_idx = jf->value.ancestor.formal_id;
+
+ if (ipa_param_cannot_devirtualize_p (caller_info, caller_idx))
+ {
+ ipa_set_param_cannot_devirtualize (callee_info, callee_idx);
+ return true;
+ }
+
+ if (!caller_info->params[caller_idx].types)
+ return false;
+
+ res = false;
+ count = VEC_length (tree, caller_info->params[caller_idx].types);
+ for (j = 0; j < count; j++)
+ {
+ tree binfo = VEC_index (tree, caller_info->params[caller_idx].types, j);
+ if (jf->type == IPA_JF_ANCESTOR)
+ {
+ binfo = get_binfo_at_offset (binfo, jf->value.ancestor.offset,
+ jf->value.ancestor.type);
+ if (!binfo)
+ {
+ ipa_set_param_cannot_devirtualize (callee_info, callee_idx);
+ return true;
+ }
+ }
+ res |= ipcp_add_param_type (callee_info, callee_idx, binfo);
+ }
+ return res;
+}
+
+/* Propagate type information for parameter of CALLEE_INFO number I as
+ described by JF. CALLER_INFO describes the caller. Return true iff the
+ type information changed in any way. */
+
+static bool
+ipcp_propagate_types (struct ipa_node_params *caller_info,
+ struct ipa_node_params *callee_info,
+ struct ipa_jump_func *jf, int i)
+{
+ tree cst, binfo;
+
+ switch (jf->type)
+ {
+ case IPA_JF_UNKNOWN:
+ case IPA_JF_CONST_MEMBER_PTR:
+ break;
+
+ case IPA_JF_KNOWN_TYPE:
+ return ipcp_add_param_type (callee_info, i, jf->value.base_binfo);
+
+ case IPA_JF_CONST:
+ cst = jf->value.constant;
+ if (TREE_CODE (cst) != ADDR_EXPR)
+ break;
+ binfo = gimple_get_relevant_ref_binfo (TREE_OPERAND (cst, 0), NULL_TREE);
+ if (!binfo)
+ break;
+ return ipcp_add_param_type (callee_info, i, binfo);
+
+ case IPA_JF_PASS_THROUGH:
+ case IPA_JF_ANCESTOR:
+ return ipcp_copy_types (caller_info, callee_info, i, jf);
+ }
+
+ /* If we reach this we cannot use this parameter for devirtualization. */
+ return !ipa_set_param_cannot_devirtualize (callee_info, i);
+}
+