From patchwork Wed Jul 21 13:00:08 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Jambor X-Patchwork-Id: 59438 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id E584AB70C0 for ; Wed, 21 Jul 2010 23:00:29 +1000 (EST) Received: (qmail 29594 invoked by alias); 21 Jul 2010 13:00:25 -0000 Received: (qmail 29569 invoked by uid 22791); 21 Jul 2010 13:00:23 -0000 X-SWARE-Spam-Status: No, hits=-6.3 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI X-Spam-Check-By: sourceware.org Received: from cantor.suse.de (HELO mx1.suse.de) (195.135.220.2) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 21 Jul 2010 13:00:13 +0000 Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.221.2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.suse.de (Postfix) with ESMTP id 63FB493987; Wed, 21 Jul 2010 15:00:10 +0200 (CEST) Date: Wed, 21 Jul 2010 15:00:08 +0200 From: Martin Jambor To: GCC Patches Cc: Jan Hubicka Subject: [PATCH] Fixup indirect edge frequencies Message-ID: <20100721130008.GA24181@virgil.arch.suse.de> Mail-Followup-To: GCC Patches , Jan Hubicka MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Hi, the patch below adds missing edge frequencies updates which are necessary for my devirtualization patches not to ICEs when it touches functions created with cgraph_function_versioning. Bootstrapped and tested on x86_64-linux. OK for trunk? Thanks, Martin 2010-07-20 Martin Jambor * cgraphunit.c (verify_edge_count_and_frequency): New function. (verify_cgraph_node): Verify frequencies of indirect edges. * tree-inline.c (tree_function_versioning): Update frequencies of indirect edges. Index: icln/gcc/cgraphunit.c =================================================================== --- icln.orig/gcc/cgraphunit.c +++ icln/gcc/cgraphunit.c @@ -570,6 +570,42 @@ clone_of_p (struct cgraph_node *node, st } #endif +/* Verify edge E count and frequency. */ + +static bool +verify_edge_count_and_frequency (struct cgraph_edge *e) +{ + bool error_found = false; + if (e->count < 0) + { + error ("caller edge count is negative"); + error_found = true; + } + if (e->frequency < 0) + { + error ("caller edge frequency is negative"); + error_found = true; + } + if (e->frequency > CGRAPH_FREQ_MAX) + { + error ("caller edge frequency is too large"); + error_found = true; + } + if (gimple_has_body_p (e->caller->decl) + && !e->caller->global.inlined_to + && (e->frequency + != compute_call_stmt_bb_frequency (e->caller->decl, + gimple_bb (e->call_stmt)))) + { + error ("caller edge frequency %i does not match BB freqency %i", + e->frequency, + compute_call_stmt_bb_frequency (e->caller->decl, + gimple_bb (e->call_stmt))); + error_found = true; + } + return error_found; +} + /* Verify cgraph nodes of given cgraph node. */ DEBUG_FUNCTION void verify_cgraph_node (struct cgraph_node *node) @@ -635,33 +671,8 @@ verify_cgraph_node (struct cgraph_node * } for (e = node->callers; e; e = e->next_caller) { - if (e->count < 0) - { - error ("caller edge count is negative"); - error_found = true; - } - if (e->frequency < 0) - { - error ("caller edge frequency is negative"); - error_found = true; - } - if (e->frequency > CGRAPH_FREQ_MAX) - { - error ("caller edge frequency is too large"); - error_found = true; - } - if (gimple_has_body_p (e->caller->decl) - && !e->caller->global.inlined_to - && (e->frequency - != compute_call_stmt_bb_frequency (e->caller->decl, - gimple_bb (e->call_stmt)))) - { - error ("caller edge frequency %i does not match BB freqency %i", - e->frequency, - compute_call_stmt_bb_frequency (e->caller->decl, - gimple_bb (e->call_stmt))); - error_found = true; - } + if (verify_edge_count_and_frequency (e)) + error_found = true; if (!e->inline_failed) { if (node->global.inlined_to @@ -684,6 +695,9 @@ verify_cgraph_node (struct cgraph_node * error_found = true; } } + for (e = node->indirect_calls; e; e = e->next_callee) + if (verify_edge_count_and_frequency (e)) + error_found = true; if (!node->callers && node->global.inlined_to) { error ("inlined_to pointer is set but no predecessors found"); Index: icln/gcc/tree-inline.c =================================================================== --- icln.orig/gcc/tree-inline.c +++ icln/gcc/tree-inline.c @@ -5184,7 +5184,15 @@ tree_function_versioning (tree old_decl, for (e = new_version_node->callees; e; e = e->next_callee) { basic_block bb = gimple_bb (e->call_stmt); - e->frequency = compute_call_stmt_bb_frequency (current_function_decl, bb); + e->frequency = compute_call_stmt_bb_frequency (current_function_decl, + bb); + e->count = bb->count; + } + for (e = new_version_node->indirect_calls; e; e = e->next_callee) + { + basic_block bb = gimple_bb (e->call_stmt); + e->frequency = compute_call_stmt_bb_frequency (current_function_decl, + bb); e->count = bb->count; } }