From patchwork Mon Apr 25 11:58:10 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prathamesh Kulkarni X-Patchwork-Id: 66571 Delivered-To: patch@linaro.org Received: by 10.140.93.198 with SMTP id d64csp992232qge; Mon, 25 Apr 2016 04:58:37 -0700 (PDT) X-Received: by 10.67.2.41 with SMTP id bl9mr47792843pad.39.1461585517138; Mon, 25 Apr 2016 04:58:37 -0700 (PDT) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id y65si6465398pfa.146.2016.04.25.04.58.36 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 25 Apr 2016 04:58:37 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-425515-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org; spf=pass (google.com: domain of gcc-patches-return-425515-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-425515-patch=linaro.org@gcc.gnu.org; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; q=dns; s=default; b=rQCTGoGafha7JiFYJS uhD/XzouI+l0nbm/ER5VINmOdyY4o8kWYRvOTE9W89+VTUuFtEhuDEBF5cATCheU oRXOAcSyL5MAmP7TfLk3/JyMx7J57ZfNshKhteTJ+RdUkhjxfmy6pkX3ggehZDkn FD5GVk/tq5CHbCuopZ6XSe2p8= 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 :mime-version:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; s=default; bh=Un9VZNonRVdKV5J3cY8WYfhG +HY=; b=NWOA8JjTZaHdqw28Zg3CYh9LEc0rLPgYtlpeJ4mXCvr1ve3hxS9hTc/z ANwnX/MVpgz4nqmOUO/Fji2UjyrQvvw28TdmvE7rSjcOY/e2xgxyRnDbL9yF3igv Io+2GZQjywFsk/unQgja/QEXufYEogDzxpu5b5/eW4wJVZLXZgU= Received: (qmail 107633 invoked by alias); 25 Apr 2016 11:58:24 -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 107584 invoked by uid 89); 25 Apr 2016 11:58:23 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 spammy=1000000, balanced, UD:qsort, INT_MAX X-HELO: mail-io0-f174.google.com Received: from mail-io0-f174.google.com (HELO mail-io0-f174.google.com) (209.85.223.174) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Mon, 25 Apr 2016 11:58:13 +0000 Received: by mail-io0-f174.google.com with SMTP id 2so180622711ioy.1 for ; Mon, 25 Apr 2016 04:58:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc; bh=9kGFYsrAalR+u7r1wiM6K2OWN9alDJND18fCjTqTZgg=; b=h5w8n8+3Nid6Y+5JnCJqzfhVWbO7Ry05pP8HPPIVuTH4aVg/n493WC4X3w8g3zBmRD N7bBKLnBIBpWPGTk+gCHDjNPAoSGaqOT1HvpaBlClJ7tuuG7bHUeHEAVPHr6I5/V9unF hojA4q3FMQmgSzNOdzN9ByQGYI46fApshoUQPHLVXKV4DoeO3Qnox90dZADj+WrzqPuj zqeIVdkGmGrxiRCdlgaHFOY09g1Es64V4SCD8gLh5OTVSL3AUEE6HHbl9byzlCmA84tb D1Ym7Gukp9lG3KAxNd6r3LAZTIQNk7Y2ezBVOlC6OjadVUPqEeGHAfcc1KPY/VNrOqXG 2MvA== X-Gm-Message-State: AOPr4FW8nKaBhMsPIFWwCyA81vMVfNtHiRo4XhvJ04bb0dzBLh/Sy0g4iXeN4MWOTiYPAvan1apL/erRJW/id8KQ MIME-Version: 1.0 X-Received: by 10.107.159.137 with SMTP id i131mr36161565ioe.29.1461585491164; Mon, 25 Apr 2016 04:58:11 -0700 (PDT) Received: by 10.36.196.5 with HTTP; Mon, 25 Apr 2016 04:58:10 -0700 (PDT) In-Reply-To: References: <20160404120030.GD14122@kam.mff.cuni.cz> <20160404141436.GB95176@kam.mff.cuni.cz> Date: Mon, 25 Apr 2016 17:28:10 +0530 Message-ID: Subject: Re: [RFC] introduce --param max-lto-partition for having an upper bound on partition size From: Prathamesh Kulkarni To: Richard Biener Cc: Jan Hubicka , gcc Patches , Ramana Radhakrishnan X-IsSubscribed: yes On 6 April 2016 at 14:54, Richard Biener wrote: > On Wed, 6 Apr 2016, Richard Biener wrote: > >> On Wed, 6 Apr 2016, Prathamesh Kulkarni wrote: >> >> > On 6 April 2016 at 13:44, Richard Biener wrote: >> > > On Wed, 6 Apr 2016, Prathamesh Kulkarni wrote: >> > > >> > >> On 5 April 2016 at 18:28, Richard Biener wrote: >> > >> > On Tue, 5 Apr 2016, Prathamesh Kulkarni wrote: >> > >> > >> > >> >> On 5 April 2016 at 16:58, Richard Biener wrote: >> > >> >> > On Tue, 5 Apr 2016, Prathamesh Kulkarni wrote: >> > >> >> > >> > >> >> >> On 4 April 2016 at 19:44, Jan Hubicka wrote: >> > >> >> >> > >> > >> >> >> >> diff --git a/gcc/lto/lto-partition.c b/gcc/lto/lto-partition.c >> > >> >> >> >> index 9eb63c2..bc0c612 100644 >> > >> >> >> >> --- a/gcc/lto/lto-partition.c >> > >> >> >> >> +++ b/gcc/lto/lto-partition.c >> > >> >> >> >> @@ -511,9 +511,20 @@ lto_balanced_map (int n_lto_partitions) >> > >> >> >> >> varpool_order.qsort (varpool_node_cmp); >> > >> >> >> >> >> > >> >> >> >> /* Compute partition size and create the first partition. */ >> > >> >> >> >> + if (PARAM_VALUE (MIN_PARTITION_SIZE) > PARAM_VALUE (MAX_PARTITION_SIZE)) >> > >> >> >> >> + fatal_error (input_location, "min partition size cannot be greater than max partition size"); >> > >> >> >> >> + >> > >> >> >> >> partition_size = total_size / n_lto_partitions; >> > >> >> >> >> if (partition_size < PARAM_VALUE (MIN_PARTITION_SIZE)) >> > >> >> >> >> partition_size = PARAM_VALUE (MIN_PARTITION_SIZE); >> > >> >> >> >> + else if (partition_size > PARAM_VALUE (MAX_PARTITION_SIZE)) >> > >> >> >> >> + { >> > >> >> >> >> + n_lto_partitions = total_size / PARAM_VALUE (MAX_PARTITION_SIZE); >> > >> >> >> >> + if (total_size % PARAM_VALUE (MAX_PARTITION_SIZE)) >> > >> >> >> >> + n_lto_partitions++; >> > >> >> >> >> + partition_size = total_size / n_lto_partitions; >> > >> >> >> >> + } >> > >> >> >> > >> > >> >> >> > lto_balanced_map actually works in a way that looks for cheapest cutpoint in range >> > >> >> >> > 3/4*parittion_size to 2*partition_size and picks the cheapest range. >> > >> >> >> > Setting partition_size to this value will thus not cause partitioner to produce smaller >> > >> >> >> > partitions only. I suppose modify the conditional: >> > >> >> >> > >> > >> >> >> > /* Partition is too large, unwind into step when best cost was reached and >> > >> >> >> > start new partition. */ >> > >> >> >> > if (partition->insns > 2 * partition_size) >> > >> >> >> > >> > >> >> >> > and/or in the code above set the partition_size to half of total_size/max_size. >> > >> >> >> > >> > >> >> >> > I know this is somewhat sloppy. This was really just first cut implementation >> > >> >> >> > many years ago. I expected to reimplement it marter soon, but then there was >> > >> >> >> > never really a need for it (I am trying to avoid late IPA optimizations so the >> > >> >> >> > partitioning decisions should mostly affect compile time performance only). >> > >> >> >> > If ARM is more sensitive for partitining, perhaps it would make sense to try to >> > >> >> >> > look for something smarter. >> > >> >> >> > >> > >> >> >> >> + >> > >> >> >> >> npartitions = 1; >> > >> >> >> >> partition = new_partition (""); >> > >> >> >> >> if (symtab->dump_file) >> > >> >> >> >> diff --git a/gcc/lto/lto.c b/gcc/lto/lto.c >> > >> >> >> >> index 9dd513f..294b8a4 100644 >> > >> >> >> >> --- a/gcc/lto/lto.c >> > >> >> >> >> +++ b/gcc/lto/lto.c >> > >> >> >> >> @@ -3112,6 +3112,12 @@ do_whole_program_analysis (void) >> > >> >> >> >> timevar_pop (TV_WHOPR_WPA); >> > >> >> >> >> >> > >> >> >> >> timevar_push (TV_WHOPR_PARTITIONING); >> > >> >> >> >> + >> > >> >> >> >> + if (flag_lto_partition != LTO_PARTITION_BALANCED >> > >> >> >> >> + && PARAM_VALUE (MAX_PARTITION_SIZE) != INT_MAX) >> > >> >> >> >> + fatal_error (input_location, "--param max-lto-partition should only" >> > >> >> >> >> + " be used with balanced partitioning\n"); >> > >> >> >> >> + >> > >> >> >> > >> > >> >> >> > I think we should wire in resonable MAX_PARTITION_SIZE default. THe value you >> > >> >> >> > found experimentally may be a good start. For that reason we can't really >> > >> >> >> > refuse a value when !LTO_PARTITION_BALANCED. Just document it as parameter for >> > >> >> >> > balanced partitioning only and add a parameter to lto_balanced_map specifying whether >> > >> >> >> > this param should be honored (because the same path is used for partitioning to one partition) >> > >> >> >> > >> > >> >> >> > Otherwise the patch looks good to me modulo missing documentation. >> > >> >> >> Thanks for the review. I have updated the patch. >> > >> >> >> Does this version look OK ? >> > >> >> >> I had randomly chosen 10000, not sure if that's an appropriate value >> > >> >> >> for default. >> > >> >> > >> > >> >> > I think it's way too small. This is roughly the number of GIMPLE stmts >> > >> >> > (thus roughly the number of instructions). So with say a 8 byte >> > >> >> > instruction format it is on the order of 80kB. You'd want to have a >> > >> >> > default of at least several ten times of large-unit-insns (also 10000). >> > >> >> > I'd choose sth like 1000000 (one million). I find the lto-min-partition >> > >> >> > number quite small as well (and up it by a factor of 10). >> > >> >> Done in this version. >> > >> > >> > >> > I'd do that separately. >> > >> > >> > >> > Please no default parameter for lto_balanced_map (), instead change >> > >> > all callers. >> > >> > >> > >> >> Is it OK after bootstrap+test ? >> > >> > >> > >> > Note that this is for stage1 only. I'll leave approval to Honza >> > >> > (also verification of the default max param - not sure if for example >> > >> > chromium or firefox should/will be split to more than 32 partitions >> > >> > with the patch) >> > >> Removed default parameter in this version. I verified with the patch >> > >> for chromium LTO build: >> > >> n_lto_partitions == 32, ltrans_partitions.length() == 31 >> > > >> > > Just noticed that lto_balanced_map already gets PARAM_LTO_PARTITIONS, >> > > so why not pass it PARAM_MAX_PARTITION_SIZE or 0 (as magic value for >> > > unlimited) instead of a bool parameter? >> > Indeed. Instead of 0, would it be OK to pass INT_MAX as 2nd parameter in case >> > of single partition, since in that case partition->insns > >> > max_partition_size will never >> > be true, which would effectively ignore max_partition_size. >> >> You mean we are limited to INT_MAX partition size anyway, even on 64bit >> systems? ... (but yes, using a suitable large number works as well) > > Ah, even 'total_size' is an int ... I wonder what this means for LTOing > a -mcmodel=large app (that really needs the large model). Hi, Is the attached patch OK for trunk now ? Bootstrapped and tested on x86_64-unknown-linux-gnu. Cross tested on arm*-*-* and aarch64*-*-*. Thanks, Prathamesh > > Richard. diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 821f8fd..4afa32c 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -9477,6 +9477,11 @@ Size of minimal partition for WHOPR (in estimated instructions). This prevents expenses of splitting very small programs into too many partitions. +@item lto-max-partition +Size of max partition for WHOPR (in estimated instructions). +to provide an upper bound for individual size of partition. +Meant to be used only with balanced partitioning. + @item cxx-max-namespaces-for-diagnostic-help The maximum number of namespaces to consult for suggestions when C++ name lookup fails for an identifier. The default is 1000. diff --git a/gcc/lto/lto-partition.c b/gcc/lto/lto-partition.c index 9eb63c2..c191d24 100644 --- a/gcc/lto/lto-partition.c +++ b/gcc/lto/lto-partition.c @@ -447,7 +447,7 @@ add_sorted_nodes (vec &next_nodes, ltrans_partition partition) and in-partition calls was reached. */ void -lto_balanced_map (int n_lto_partitions) +lto_balanced_map (int n_lto_partitions, int max_partition_size) { int n_nodes = 0; int n_varpool_nodes = 0, varpool_pos = 0, best_varpool_pos = 0; @@ -511,6 +511,9 @@ lto_balanced_map (int n_lto_partitions) varpool_order.qsort (varpool_node_cmp); /* Compute partition size and create the first partition. */ + if (PARAM_VALUE (MIN_PARTITION_SIZE) > max_partition_size) + fatal_error (input_location, "min partition size cannot be greater than max partition size"); + partition_size = total_size / n_lto_partitions; if (partition_size < PARAM_VALUE (MIN_PARTITION_SIZE)) partition_size = PARAM_VALUE (MIN_PARTITION_SIZE); @@ -719,7 +722,8 @@ lto_balanced_map (int n_lto_partitions) best_cost, best_internal, best_i); /* Partition is too large, unwind into step when best cost was reached and start new partition. */ - if (partition->insns > 2 * partition_size) + if (partition->insns > 2 * partition_size + || partition->insns > max_partition_size) { if (best_i != i) { diff --git a/gcc/lto/lto-partition.h b/gcc/lto/lto-partition.h index 31e3764..f7abe62 100644 --- a/gcc/lto/lto-partition.h +++ b/gcc/lto/lto-partition.h @@ -35,7 +35,7 @@ extern vec ltrans_partitions; void lto_1_to_1_map (void); void lto_max_map (void); -void lto_balanced_map (int); +void lto_balanced_map (int, int); void lto_promote_cross_file_statics (void); void free_ltrans_partitions (void); void lto_promote_statics_nonwpa (void); diff --git a/gcc/lto/lto.c b/gcc/lto/lto.c index 9dd513f..af735cb 100644 --- a/gcc/lto/lto.c +++ b/gcc/lto/lto.c @@ -3117,9 +3117,10 @@ do_whole_program_analysis (void) else if (flag_lto_partition == LTO_PARTITION_MAX) lto_max_map (); else if (flag_lto_partition == LTO_PARTITION_ONE) - lto_balanced_map (1); + lto_balanced_map (1, INT_MAX); else if (flag_lto_partition == LTO_PARTITION_BALANCED) - lto_balanced_map (PARAM_VALUE (PARAM_LTO_PARTITIONS)); + lto_balanced_map (PARAM_VALUE (PARAM_LTO_PARTITIONS), + PARAM_VALUE (MAX_PARTITION_SIZE)); else gcc_unreachable (); diff --git a/gcc/params.def b/gcc/params.def index dbff305..eceee32 100644 --- a/gcc/params.def +++ b/gcc/params.def @@ -1029,6 +1029,11 @@ DEFPARAM (MIN_PARTITION_SIZE, "Minimal size of a partition for LTO (in estimated instructions).", 1000, 0, 0) +DEFPARAM (MAX_PARTITION_SIZE, + "lto-max-partition", + "Maximal size of a partition for LTO (in estimated instructions).", + 1000000, 0, INT_MAX) + /* Diagnostic parameters. */ DEFPARAM (CXX_MAX_NAMESPACES_FOR_DIAGNOSTIC_HELP,