From patchwork Fri Jun 9 12:17:51 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Martin_Li=C5=A1ka?= X-Patchwork-Id: 773837 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]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3wkhC66rB5z9s7v for ; Fri, 9 Jun 2017 22:18:09 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="QccDda5W"; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to:cc :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=qqkD0uEUKduh74DFoJcn6PS9XAGp8cupu4BhiX2dTFIILHcPsB YXBRadBnhQZMdL2ClZKl7LxcN/UglvJE4l1+zIhusvASBkuritLVSjadgc4Scs90 lN+QQTnU1FVVqzqmw48gzNianIZklMKCxj9Z6ZZORephPY+TvxHmnMxRQ= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to:cc :from:subject:message-id:date:mime-version:content-type; s= default; bh=wnkErpVKoUZSsRVuRpVmNJlRF1w=; b=QccDda5WcAtSuhlwlBTb cZS9KC5Wy49Lbiz6ssVSLhcx3E0+It5ryZrosqv5x9pE/A9nOWLJ1XeDt1wkg10g iKCvFPDYYBat/rfJzEzs+NN6HRnE8zgZQlQ4kjxkzT63R5lX+XDr6RAb6l7cubpm rbSxdUkFbs2j/hdheeQyv54= Received: (qmail 121475 invoked by alias); 9 Jun 2017 12:17:54 -0000 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 Received: (qmail 119309 invoked by uid 89); 9 Jun 2017 12:17:50 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_PASS autolearn=ham version=3.3.2 spammy=63s X-HELO: mx1.suse.de Received: from mx2.suse.de (HELO mx1.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 09 Jun 2017 12:17:49 +0000 Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id B6755ADFF; Fri, 9 Jun 2017 12:17:51 +0000 (UTC) To: GCC Patches Cc: Jan Hubicka From: =?UTF-8?Q?Martin_Li=c5=a1ka?= Subject: [PATCH] Speed-up indirect-call instrumentation Message-ID: Date: Fri, 9 Jun 2017 14:17:51 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.1.1 MIME-Version: 1.0 X-IsSubscribed: yes Hello. I discussed with Honza possibility to speed-up instrumentation that we do for indirect call target tracking. By direct emission of: if (__gcov_indirect_call_callee != NULL) __gcov_indirect_call_profiler_v2 (profile_id, ¤t_function_decl); we can save reduce # of execution of __gcov_indirect_call_profiler_v2 function. I measured that tramp3d (-O2 -fprofile-generate) goes from 7.1s to 6.3s. Apart from that I slightly change probability for direct instrumentation of time profiler. Patch can bootstrap on ppc64le-redhat-linux and survives regression tests. Ready to be installed? Martin From 178b505b99499bb620492507684f85dd604172c9 Mon Sep 17 00:00:00 2001 From: marxin Date: Fri, 9 Jun 2017 11:18:44 +0200 Subject: [PATCH] Speed-up indirect-call instrumentation gcc/ChangeLog: 2017-06-09 Martin Liska * tree-profile.c (gimple_gen_ic_profiler): Update comment. (gimple_gen_ic_func_profiler): Emit direct comparison of __gcov_indirect_call_callee with NULL. (gimple_gen_time_profiler): Change probability from PROB_VERY_UNLIKELY to PROB_UNLIKELY. libgcc/ChangeLog: 2017-06-09 Martin Liska * libgcov-profiler.c (__gcov_indirect_call_profiler_v2): Reset __gcov_indirect_call_callee to NULL. --- gcc/tree-profile.c | 59 ++++++++++++++++++++++++++++++++++------------- libgcc/libgcov-profiler.c | 2 ++ 2 files changed, 45 insertions(+), 16 deletions(-) diff --git a/gcc/tree-profile.c b/gcc/tree-profile.c index a49ec37f8bb..f5c06684402 100644 --- a/gcc/tree-profile.c +++ b/gcc/tree-profile.c @@ -388,6 +388,13 @@ gimple_gen_ic_profiler (histogram_value value, unsigned tag, unsigned base) stmt1: __gcov_indirect_call_counters = get_relevant_counter_ptr (); stmt2: tmp1 = (void *) (indirect call argument value) stmt3: __gcov_indirect_call_callee = tmp1; + + Example: + f_1 = foo; + __gcov_indirect_call_counters = &__gcov4.main[0]; + PROF_9 = f_1; + __gcov_indirect_call_callee = PROF_9; + _4 = f_1 (); */ stmt1 = gimple_build_assign (ic_gcov_type_ptr_var, ref_ptr); @@ -410,9 +417,7 @@ void gimple_gen_ic_func_profiler (void) { struct cgraph_node * c_node = cgraph_node::get (current_function_decl); - gimple_stmt_iterator gsi; gcall *stmt1; - gassign *stmt2; tree tree_uid, cur_func, void0; if (c_node->only_called_directly_p ()) @@ -420,13 +425,43 @@ gimple_gen_ic_func_profiler (void) gimple_init_gcov_profiler (); + basic_block entry = ENTRY_BLOCK_PTR_FOR_FN (cfun); + basic_block cond_bb = split_edge (single_succ_edge (entry)); + basic_block update_bb = split_edge (single_succ_edge (cond_bb)); + + edge true_edge = single_succ_edge (cond_bb); + true_edge->flags = EDGE_TRUE_VALUE; + + int probability; + if (DECL_VIRTUAL_P (current_function_decl)) + probability = PROB_VERY_LIKELY; + else + probability = PROB_UNLIKELY; + + true_edge->probability = probability; + edge e = make_edge (cond_bb, single_succ_edge (update_bb)->dest, + EDGE_FALSE_VALUE); + e->probability = REG_BR_PROB_BASE - true_edge->probability; + /* Insert code: - stmt1: __gcov_indirect_call_profiler_v2 (profile_id, - ¤t_function_decl) - */ - gsi = gsi_after_labels (split_edge (single_succ_edge - (ENTRY_BLOCK_PTR_FOR_FN (cfun)))); + if (__gcov_indirect_call_callee != NULL) + __gcov_indirect_call_profiler_v2 (profile_id, ¤t_function_decl); + + The function __gcov_indirect_call_profiler_v2 is responsible for + resetting __gcov_indirect_call_callee to NULL. */ + + gimple_stmt_iterator gsi = gsi_start_bb (cond_bb); + void0 = build_int_cst (build_pointer_type (void_type_node), 0); + + tree ref = force_gimple_operand_gsi (&gsi, ic_void_ptr_var, true, NULL_TREE, + true, GSI_SAME_STMT); + + gcond *cond = gimple_build_cond (NE_EXPR, ref, + void0, NULL, NULL); + gsi_insert_before (&gsi, cond, GSI_NEW_STMT); + + gsi = gsi_after_labels (update_bb); cur_func = force_gimple_operand_gsi (&gsi, build_addr (current_function_decl), @@ -438,13 +473,6 @@ gimple_gen_ic_func_profiler (void) stmt1 = gimple_build_call (tree_indirect_call_profiler_fn, 2, tree_uid, cur_func); gsi_insert_before (&gsi, stmt1, GSI_SAME_STMT); - - /* Set __gcov_indirect_call_callee to 0, - so that calls from other modules won't get misattributed - to the last caller of the current callee. */ - void0 = build_int_cst (build_pointer_type (void_type_node), 0); - stmt2 = gimple_build_assign (ic_void_ptr_var, void0); - gsi_insert_before (&gsi, stmt2, GSI_SAME_STMT); } /* Output instructions as GIMPLE tree at the beginning for each function. @@ -458,11 +486,10 @@ gimple_gen_time_profiler (unsigned tag, unsigned base) basic_block entry = ENTRY_BLOCK_PTR_FOR_FN (cfun); basic_block cond_bb = split_edge (single_succ_edge (entry)); basic_block update_bb = split_edge (single_succ_edge (cond_bb)); - split_edge (single_succ_edge (update_bb)); edge true_edge = single_succ_edge (cond_bb); true_edge->flags = EDGE_TRUE_VALUE; - true_edge->probability = PROB_VERY_UNLIKELY; + true_edge->probability = PROB_UNLIKELY; edge e = make_edge (cond_bb, single_succ_edge (update_bb)->dest, EDGE_FALSE_VALUE); e->probability = REG_BR_PROB_BASE - true_edge->probability; diff --git a/libgcc/libgcov-profiler.c b/libgcc/libgcov-profiler.c index 067d762c2af..e4570a01318 100644 --- a/libgcc/libgcov-profiler.c +++ b/libgcc/libgcov-profiler.c @@ -336,6 +336,8 @@ __gcov_indirect_call_profiler_v2 (gcov_type value, void* cur_func) || (__LIBGCC_VTABLE_USES_DESCRIPTORS__ && __gcov_indirect_call_callee && *(void **) cur_func == *(void **) __gcov_indirect_call_callee)) __gcov_one_value_profiler_body (__gcov_indirect_call_counters, value, 0); + + __gcov_indirect_call_callee = NULL; } #endif -- 2.13.0