From patchwork Mon Aug 6 16:58:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 953991 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-483261-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=acm.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Fyldvggz"; dkim-atps=neutral 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 41kkPF3z5Gz9ryt for ; Tue, 7 Aug 2018 02:58:23 +1000 (AEST) Received: (qmail 76239 invoked by alias); 6 Aug 2018 16:58:18 -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 76228 invoked by uid 89); 6 Aug 2018 16:58:17 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-11.9 required=5.0 tests=BAYES_00, FREEMAIL_FROM, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=subsequent, Rather X-HELO: mail-yw1-f41.google.com Received: from mail-yw1-f41.google.com (HELO mail-yw1-f41.google.com) (209.85.161.41) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 06 Aug 2018 16:58:15 +0000 Received: by mail-yw1-f41.google.com with SMTP id r3-v6so3855020ywc.5 for ; Mon, 06 Aug 2018 09:58:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:to:cc:from:subject:message-id:date:user-agent:mime-version :content-language; bh=B04CS+63AE+eahz35S3q+fT751v1CxzAGXZaDjeoQqg=; b=FyldvggzVHlwvz0u/bXq0QzpiU5/QCxPc9LX+NsqOh62V24/tbPp5C9yUn5+dU2DgP +Kq6IEwqB8xFRphEaQWYdFSHE2h4z/3x2O59oagO1fraW9vxBPVg3frnosD2KDPu4W4s RYQL0g0nTbWWcCa5icT/3u42maff+Fn5hjyKyUFYPDqzV0HxndF2picfXeJXfhjk0rYF FF5P/BA649Yc2WBlggj3m6tsjBIj6Y5j/mjBJCUqkbevEVmp9+QfjJRP0C7dzhRql+6j ub4JAIosVc5vIoi219sRc2x54ocVIO4ZmJS8yxXddxc6cXWLP9BXy4g1wbo1DA+DmEMe SiqQ== Received: from ?IPv6:2620:10d:c0a3:20fb:7500:e7fb:4a6f:2254? ([2620:10d:c091:200::2:80bc]) by smtp.googlemail.com with ESMTPSA id z125-v6sm15986636ywg.57.2018.08.06.09.58.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 Aug 2018 09:58:13 -0700 (PDT) Sender: Nathan Sidwell To: David Malcolm Cc: GCC Patches From: Nathan Sidwell Subject: [PATCH] Line map table allocation Message-ID: <5e8d4a6f-7785-e4b2-1685-2483475c7cec@acm.org> Date: Mon, 6 Aug 2018 12:58:11 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 Here's a line-map patch to make the new_linemap logic simpler. On the modules branch I need to allocate blocks of linemaps, and found the current allocation scheme a little confusing to adjust. This'll make that subsequent change simpler. While there, I set the default allocator (xmalloc) in the init routine, rather than check it for each allocation. I doubt the loss of a devirtualization possibility is significant (we're doing allocation wrong if it is). booted & tested on x86_64-linux ok? nathan 2018-08-06 Nathan Sidwell * line-map.c: (linemap_init): Set default allocator here. (new_linemap): Rather than here. Refactor allocation logic. Index: line-map.c =================================================================== --- line-map.c (revision 263332) +++ line-map.c (working copy) @@ -346,6 +346,8 @@ linemap_init (struct line_maps *set, #else new (set) line_maps(); #endif + /* Set default allocator. */ + set->reallocator = (line_map_realloc) xrealloc; set->highest_location = RESERVED_LOCATION_COUNT - 1; set->highest_line = RESERVED_LOCATION_COUNT - 1; set->location_adhoc_data_map.htab = @@ -376,81 +378,58 @@ linemap_check_files_exited (struct line_ static struct line_map * new_linemap (struct line_maps *set, source_location start_location) { - struct line_map *result; - bool macro_map_p = start_location >= LINE_MAP_MAX_LOCATION; + bool macro_p = start_location >= LINE_MAP_MAX_LOCATION; + unsigned alloc = LINEMAPS_ALLOCATED (set, macro_p); + unsigned used = LINEMAPS_USED (set, macro_p); - if (LINEMAPS_USED (set, macro_map_p) == LINEMAPS_ALLOCATED (set, macro_map_p)) + if (used == alloc) { - /* We ran out of allocated line maps. Let's allocate more. */ - size_t alloc_size; - - /* Cast away extern "C" from the type of xrealloc. */ - line_map_realloc reallocator = (set->reallocator - ? set->reallocator - : (line_map_realloc) xrealloc); - line_map_round_alloc_size_func round_alloc_size = - set->round_alloc_size; - - size_t map_size = (macro_map_p - ? sizeof (line_map_macro) - : sizeof (line_map_ordinary)); + /* We need more space! */ + if (!alloc) + alloc = 128; + alloc *= 2; + + size_t map_size; + void *buffer; + if (macro_p) + { + map_size = sizeof (line_map_macro); + buffer = set->info_macro.maps; + } + else + { + map_size = sizeof (line_map_ordinary); + buffer = set->info_ordinary.maps; + } /* We are going to execute some dance to try to reduce the overhead of the memory allocator, in case we are using the ggc-page.c one. The actual size of memory we are going to get back from the - allocator is the smallest power of 2 that is greater than the - size we requested. So let's consider that size then. */ - - alloc_size = - (2 * LINEMAPS_ALLOCATED (set, macro_map_p) + 256) - * map_size; - - /* Get the actual size of memory that is going to be allocated - by the allocator. */ - alloc_size = round_alloc_size (alloc_size); + allocator may well be larger than what we ask for. Use this + hook to find what that size is. */ + size_t alloc_size = set->round_alloc_size (alloc * map_size); /* Now alloc_size contains the exact memory size we would get if we have asked for the initial alloc_size amount of memory. Let's get back to the number of macro map that amounts to. */ - LINEMAPS_ALLOCATED (set, macro_map_p) = - alloc_size / map_size; - - /* And now let's really do the re-allocation. */ - if (macro_map_p) - { - set->info_macro.maps - = (line_map_macro *) (*reallocator) (set->info_macro.maps, - (LINEMAPS_ALLOCATED (set, macro_map_p) - * map_size)); - result = &set->info_macro.maps[LINEMAPS_USED (set, macro_map_p)]; - } - else - { - set->info_ordinary.maps = - (line_map_ordinary *) (*reallocator) (set->info_ordinary.maps, - (LINEMAPS_ALLOCATED (set, macro_map_p) - * map_size)); - result = &set->info_ordinary.maps[LINEMAPS_USED (set, macro_map_p)]; - } - memset (result, 0, - ((LINEMAPS_ALLOCATED (set, macro_map_p) - - LINEMAPS_USED (set, macro_map_p)) - * map_size)); - } - else - { - if (macro_map_p) - result = &set->info_macro.maps[LINEMAPS_USED (set, macro_map_p)]; + unsigned num_maps = alloc_size / map_size; + buffer = set->reallocator (buffer, num_maps * map_size); + memset ((char *)buffer + used * map_size, 0, (num_maps - used) * map_size); + if (macro_p) + set->info_macro.maps = (line_map_macro *)buffer; else - result = &set->info_ordinary.maps[LINEMAPS_USED (set, macro_map_p)]; + set->info_ordinary.maps = (line_map_ordinary *)buffer; + LINEMAPS_ALLOCATED (set, macro_p) = num_maps; } - result->start_location = start_location; + line_map *result = (macro_p ? (line_map *)&set->info_macro.maps[used] + : (line_map *)&set->info_ordinary.maps[used]); + LINEMAPS_USED (set, macro_p)++; - LINEMAPS_USED (set, macro_map_p)++; + result->start_location = start_location; return result; }