+2013-08-18 Jan Hubicka <jh@suse.cz>
+
+ * cgraph.c (cgraph_create_indirect_edge): Discover
+ polymorphic calls and record basic info into indirect_info.
+ * gimple-fold.c (gimple_fold_call): When doing BINFO based
+ devirtualization, ignore objc function calls.
+ * ipa-cp.c (initialize_node_lattices): Be ready for polymorphic
+ call with no parm index info.
+ * ipa-prop.c (ipa_analyze_call_uses): Likewise.
+ * tree.c (virtual_method_call_p): New function.
+ * tree.h (virtual_method_call_p): Declare.
+
2013-08-16 Jan Hubicka <jh@suse.cz>
PR middle-end/58179
{
struct cgraph_edge *edge = cgraph_create_edge_1 (caller, NULL, call_stmt,
count, freq);
+ tree target;
edge->indirect_unknown_callee = 1;
initialize_inline_failed (edge);
edge->indirect_info = cgraph_allocate_init_indirect_info ();
edge->indirect_info->ecf_flags = ecf_flags;
+ /* Record polymorphic call info. */
+ if (call_stmt
+ && (target = gimple_call_fn (call_stmt))
+ && virtual_method_call_p (target))
+ {
+ tree type = obj_type_ref_class (target);
+
+
+ /* Only record types can have virtual calls. */
+ gcc_assert (TREE_CODE (type) == RECORD_TYPE);
+ edge->indirect_info->param_index = -1;
+ edge->indirect_info->otr_token
+ = tree_low_cst (OBJ_TYPE_REF_TOKEN (target), 1);
+ edge->indirect_info->otr_type = type;
+ edge->indirect_info->polymorphic = 1;
+ }
+
edge->next_callee = caller->indirect_calls;
if (caller->indirect_calls)
caller->indirect_calls->prev_callee = edge;
gimple_call_set_fn (stmt, OBJ_TYPE_REF_EXPR (callee));
changed = true;
}
- else
+ else if (virtual_method_call_p (callee))
{
tree obj = OBJ_TYPE_REF_OBJECT (callee);
tree binfo = gimple_extract_devirt_binfo_from_cst
}
for (ie = node->indirect_calls; ie; ie = ie->next_callee)
- if (ie->indirect_info->polymorphic)
+ if (ie->indirect_info->polymorphic
+ && ie->indirect_info->param_index >= 0)
{
gcc_checking_assert (ie->indirect_info->param_index >= 0);
ipa_get_parm_lattices (info,
return;
if (TREE_CODE (target) == SSA_NAME)
ipa_analyze_indirect_call_uses (node, info, parms_ainfo, call, target);
- else if (TREE_CODE (target) == OBJ_TYPE_REF)
+ else if (virtual_method_call_p (target))
ipa_analyze_virtual_call_uses (node, info, call, target);
}
return true;
}
+/* TARGET is a call target of GIMPLE call statement
+ (obtained by gimple_call_fn). Return true if it is
+ OBJ_TYPE_REF representing an virtual call of C++ method.
+ (As opposed to OBJ_TYPE_REF representing objc calls
+ through a cast where middle-end devirtualization machinery
+ can't apply.) */
+
+bool
+virtual_method_call_p (tree target)
+{
+ if (TREE_CODE (target) != OBJ_TYPE_REF)
+ return false;
+ target = TREE_TYPE (target);
+ gcc_checking_assert (TREE_CODE (target) == POINTER_TYPE);
+ target = TREE_TYPE (target);
+ if (TREE_CODE (target) == FUNCTION_TYPE)
+ return false;
+ gcc_checking_assert (TREE_CODE (target) == METHOD_TYPE);
+ return true;
+}
+
/* REF is OBJ_TYPE_REF, return the class the ref corresponds to. */
tree
extern tree block_ultimate_origin (const_tree);
extern tree get_binfo_at_offset (tree, HOST_WIDE_INT, tree);
+extern bool virtual_method_call_p (tree);
extern tree obj_type_ref_class (tree ref);
extern bool types_same_for_odr (tree type1, tree type2);
extern tree get_ref_base_and_extent (tree, HOST_WIDE_INT *,