From patchwork Tue Nov 15 10:56:14 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bernd Edlinger X-Patchwork-Id: 82296 Delivered-To: patch@linaro.org Received: by 10.182.1.168 with SMTP id 8csp1629180obn; Tue, 15 Nov 2016 02:56:44 -0800 (PST) X-Received: by 10.98.29.205 with SMTP id d196mr45705992pfd.111.1479207404209; Tue, 15 Nov 2016 02:56:44 -0800 (PST) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id fl6si16002217pab.78.2016.11.15.02.56.43 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 15 Nov 2016 02:56:44 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-return-441432-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-441432-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-441432-patch=linaro.org@gcc.gnu.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:content-type:mime-version; q=dns; s=default; b=s972NzoUA/OEEzqx3JTFxoldzq+eja/haXcJwygMKTutRkbOzz ZUAsBYJAvGlMelHBt7y2up/Lhf4qI6d46r4YMQrZutIev/6smhaTju2OGLfhh+PK 2CLmyroVMY49MmoBd6osfsI3Yw7tAWmVWvmbVC5O02qxknoW+IbKLjBDs= 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:from :to:cc:subject:date:message-id:content-type:mime-version; s= default; bh=wD6j23gO9D3y/Kgu4lod3Zk9gtY=; b=gP8aYyf5j3j/jEB3s4Ex VhRflNEF4dxXe4caOOhTpfyxHjcI/kFlmEvq/lDy+7GUfj3Vgi699qhwKpZTxrxv 4M5r5IXbLoLpGozvQ9bWyukM4pj7m0DY4mmSR1aEU223s0tfJHQ/w/YFQ9XPiTo4 d8zhDblMhgyYg8lN1rEnK2A= Received: (qmail 9339 invoked by alias); 15 Nov 2016 10:56:30 -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 9324 invoked by uid 89); 15 Nov 2016 10:56:28 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.8 required=5.0 tests=AWL, BAYES_20, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 spammy=latency, HX-HELO:sk:SNT004-, Hx-spam-relays-external:sk:SNT004-, H*RU:sk:SNT004- X-HELO: SNT004-OMC3S5.hotmail.com Received: from snt004-omc3s5.hotmail.com (HELO SNT004-OMC3S5.hotmail.com) (65.55.90.144) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 15 Nov 2016 10:56:18 +0000 Received: from EUR02-AM5-obe.outbound.protection.outlook.com ([65.55.90.137]) by SNT004-OMC3S5.hotmail.com over TLS secured channel with Microsoft SMTPSVC(7.5.7601.23008); Tue, 15 Nov 2016 02:56:16 -0800 Received: from AM5EUR02FT012.eop-EUR02.prod.protection.outlook.com (10.152.8.55) by AM5EUR02HT112.eop-EUR02.prod.protection.outlook.com (10.152.8.253) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.721.5; Tue, 15 Nov 2016 10:56:15 +0000 Received: from AM4PR0701MB2162.eurprd07.prod.outlook.com (10.152.8.57) by AM5EUR02FT012.mail.protection.outlook.com (10.152.8.82) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.721.5 via Frontend Transport; Tue, 15 Nov 2016 10:56:15 +0000 Received: from AM4PR0701MB2162.eurprd07.prod.outlook.com ([10.167.132.147]) by AM4PR0701MB2162.eurprd07.prod.outlook.com ([10.167.132.147]) with mapi id 15.01.0734.004; Tue, 15 Nov 2016 10:56:14 +0000 From: Bernd Edlinger To: GCC Patches CC: Bernd Schmidt Subject: [PATCH] Significantly reduce memory usage of genattrtab Date: Tue, 15 Nov 2016 10:56:14 +0000 Message-ID: authentication-results: redhat.com; dkim=none (message not signed) header.d=none; redhat.com; dmarc=none action=none header.from=hotmail.de; x-incomingtopheadermarker: OriginalChecksum:; UpperCasedChecksum:; SizeAsReceived:7362; Count:38 x-ms-exchange-messagesentrepresentingtype: 1 x-tmn: [LziOX4kXUt3GcssS28u/A+b2b2mAjGIc] x-incomingheadercount: 38 x-eopattributedmessage: 0 x-microsoft-exchange-diagnostics: 1; AM5EUR02HT112; 7:rQlncfXuc0DhS3Nh/C57/maci2CqXCHbSk8t132kHyvygd0G/k2JOPqmWXN40bb5z0rukm2sb+d1M6ZXHruwqkvq/BcapL7HyF1Gx1FTE6aEnOG5/K8l9JvL7x6gQgRMHyLbLSDbIeM4KY5JUFuPa+QPdw8XU2Jbfy2TdnicksO8w4ZO8NoAqZ+3qhwjhZOHk1YrqUz0bl8pXyDGKLvBv6SA6AfdCS44fO73CtOkmnS6kVXTSiVOsdNiM20XOHItVmow3RX0T4qaa6oFXO4CalXrrqDLGOv++H1N6YzMT9fdK5o1V3FJ/ENlI2Y0755nsSL9FoONyXfaPrT3S3qKLgIYbIqDPXhoIfRZHIU5mSU= x-forefront-antispam-report: EFV:NLI; SFV:NSPM; SFS:(10019020)(98900003); DIR:OUT; SFP:1102; SCL:1; SRVR:AM5EUR02HT112; H:AM4PR0701MB2162.eurprd07.prod.outlook.com; FPR:; SPF:None; LANG:en; x-ms-office365-filtering-correlation-id: d1ad10bc-3695-426c-37ee-08d40d4604f5 x-microsoft-antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(1601124038)(1603103113)(1601125047); SRVR:AM5EUR02HT112; x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(432015012)(102415395)(82015046); SRVR:AM5EUR02HT112; BCL:0; PCL:0; RULEID:; SRVR:AM5EUR02HT112; x-forefront-prvs: 012792EC17 spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-originalarrivaltime: 15 Nov 2016 10:56:14.6512 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Internet X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM5EUR02HT112 Hi! The genattrtab build-tool uses way too much memory in general. I think there is no other build step that uses more memory. On the currently trunk it takes around 700MB to build the ARM latency tab files. I debugged that yesterday and found that this can be reduced to 8MB (!). Yes, really. So the attached patch does try really hard to hash and re-use all ever created rtx objects. Bootstrapped and reg-tested on x86_64-pc-linux-gnu and ARM. Is it OK for trunk? Thanks Bernd. 2016-11-15 Bernd Edlinger * genattrtab.c (attr_rtx_1): Ignore ATTR_PERMANENT_P on arguments. Use DEF_ATTR_STRING for string arguments. Use RTL_HASH for integer arguments. (attr_eq): Simplify. (attr_copy_rtx): Remove. (make_canonical, get_attr_value): Use attr_equal_p. (copy_boolean): Rehash NOT. (simplify_test_exp_in_temp, optimize_attrs): Remove call to attr_copy_rtx. (attr_alt_intersection, attr_alt_union, attr_alt_complement, mk_attr_alt): Rehash EQ_ATTR_ALT. (make_automaton_attrs): Use attr_eq. Index: gcc/genattrtab.c =================================================================== --- gcc/genattrtab.c (revision 242335) +++ gcc/genattrtab.c (working copy) @@ -395,14 +395,6 @@ attr_rtx_1 (enum rtx_code code, va_list p) { rtx arg0 = va_arg (p, rtx); - /* A permanent object cannot point to impermanent ones. */ - if (! ATTR_PERMANENT_P (arg0)) - { - rt_val = rtx_alloc (code); - XEXP (rt_val, 0) = arg0; - return rt_val; - } - hashcode = ((HOST_WIDE_INT) code + RTL_HASH (arg0)); for (h = attr_hash_table[hashcode % RTL_HASH_SIZE]; h; h = h->next) if (h->hashcode == hashcode @@ -425,15 +417,6 @@ attr_rtx_1 (enum rtx_code code, va_list p) rtx arg0 = va_arg (p, rtx); rtx arg1 = va_arg (p, rtx); - /* A permanent object cannot point to impermanent ones. */ - if (! ATTR_PERMANENT_P (arg0) || ! ATTR_PERMANENT_P (arg1)) - { - rt_val = rtx_alloc (code); - XEXP (rt_val, 0) = arg0; - XEXP (rt_val, 1) = arg1; - return rt_val; - } - hashcode = ((HOST_WIDE_INT) code + RTL_HASH (arg0) + RTL_HASH (arg1)); for (h = attr_hash_table[hashcode % RTL_HASH_SIZE]; h; h = h->next) if (h->hashcode == hashcode @@ -481,6 +464,9 @@ attr_rtx_1 (enum rtx_code code, va_list p) char *arg0 = va_arg (p, char *); char *arg1 = va_arg (p, char *); + arg0 = DEF_ATTR_STRING (arg0); + arg1 = DEF_ATTR_STRING (arg1); + hashcode = ((HOST_WIDE_INT) code + RTL_HASH (arg0) + RTL_HASH (arg1)); for (h = attr_hash_table[hashcode % RTL_HASH_SIZE]; h; h = h->next) if (h->hashcode == hashcode @@ -497,6 +483,29 @@ attr_rtx_1 (enum rtx_code code, va_list p) XSTR (rt_val, 1) = arg1; } } + else if (GET_RTX_LENGTH (code) == 2 + && GET_RTX_FORMAT (code)[0] == 'i' + && GET_RTX_FORMAT (code)[1] == 'i') + { + int arg0 = va_arg (p, int); + int arg1 = va_arg (p, int); + + hashcode = ((HOST_WIDE_INT) code + RTL_HASH (arg0) + RTL_HASH (arg1)); + for (h = attr_hash_table[hashcode % RTL_HASH_SIZE]; h; h = h->next) + if (h->hashcode == hashcode + && GET_CODE (h->u.rtl) == code + && XINT (h->u.rtl, 0) == arg0 + && XINT (h->u.rtl, 1) == arg1) + return h->u.rtl; + + if (h == 0) + { + rtl_obstack = hash_obstack; + rt_val = rtx_alloc (code); + XINT (rt_val, 0) = arg0; + XINT (rt_val, 1) = arg1; + } + } else if (code == CONST_INT) { HOST_WIDE_INT arg0 = va_arg (p, HOST_WIDE_INT); @@ -592,7 +601,7 @@ attr_printf (unsigned int len, const char *fmt, .. static rtx attr_eq (const char *name, const char *value) { - return attr_rtx (EQ_ATTR, DEF_ATTR_STRING (name), DEF_ATTR_STRING (value)); + return attr_rtx (EQ_ATTR, name, value); } static const char * @@ -646,89 +655,6 @@ attr_equal_p (rtx x, rtx y) && rtx_equal_p (x, y))); } -/* Copy an attribute value expression, - descending to all depths, but not copying any - permanent hashed subexpressions. */ - -static rtx -attr_copy_rtx (rtx orig) -{ - rtx copy; - int i, j; - RTX_CODE code; - const char *format_ptr; - - /* No need to copy a permanent object. */ - if (ATTR_PERMANENT_P (orig)) - return orig; - - code = GET_CODE (orig); - - switch (code) - { - case REG: - CASE_CONST_ANY: - case SYMBOL_REF: - case MATCH_TEST: - case CODE_LABEL: - case PC: - case CC0: - return orig; - - default: - break; - } - - copy = rtx_alloc (code); - PUT_MODE (copy, GET_MODE (orig)); - ATTR_IND_SIMPLIFIED_P (copy) = ATTR_IND_SIMPLIFIED_P (orig); - ATTR_CURR_SIMPLIFIED_P (copy) = ATTR_CURR_SIMPLIFIED_P (orig); - ATTR_PERMANENT_P (copy) = ATTR_PERMANENT_P (orig); - - format_ptr = GET_RTX_FORMAT (GET_CODE (copy)); - - for (i = 0; i < GET_RTX_LENGTH (GET_CODE (copy)); i++) - { - switch (*format_ptr++) - { - case 'e': - XEXP (copy, i) = XEXP (orig, i); - if (XEXP (orig, i) != NULL) - XEXP (copy, i) = attr_copy_rtx (XEXP (orig, i)); - break; - - case 'E': - case 'V': - XVEC (copy, i) = XVEC (orig, i); - if (XVEC (orig, i) != NULL) - { - XVEC (copy, i) = rtvec_alloc (XVECLEN (orig, i)); - for (j = 0; j < XVECLEN (copy, i); j++) - XVECEXP (copy, i, j) = attr_copy_rtx (XVECEXP (orig, i, j)); - } - break; - - case 'n': - case 'i': - XINT (copy, i) = XINT (orig, i); - break; - - case 'w': - XWINT (copy, i) = XWINT (orig, i); - break; - - case 's': - case 'S': - XSTR (copy, i) = XSTR (orig, i); - break; - - default: - gcc_unreachable (); - } - } - return copy; -} - /* Given a test expression EXP for attribute ATTR, ensure it is validly formed. LOC is the location of the .md construct that contains EXP. @@ -1236,7 +1162,7 @@ make_canonical (file_location loc, struct attr_des XVECEXP (exp, 0, i) = copy_boolean (XVECEXP (exp, 0, i)); XVECEXP (exp, 0, i + 1) = make_canonical (loc, attr, XVECEXP (exp, 0, i + 1)); - if (! rtx_equal_p (XVECEXP (exp, 0, i + 1), defval)) + if (! attr_equal_p (XVECEXP (exp, 0, i + 1), defval)) allsame = 0; } if (allsame) @@ -1257,6 +1183,8 @@ copy_boolean (rtx exp) if (GET_CODE (exp) == AND || GET_CODE (exp) == IOR) return attr_rtx (GET_CODE (exp), copy_boolean (XEXP (exp, 0)), copy_boolean (XEXP (exp, 1))); + else if (GET_CODE (exp) == NOT) + return attr_rtx (NOT, copy_boolean (XEXP (exp, 0))); if (GET_CODE (exp) == MATCH_OPERAND) { XSTR (exp, 1) = DEF_ATTR_STRING (XSTR (exp, 1)); @@ -1298,7 +1226,7 @@ get_attr_value (file_location loc, rtx value, stru } for (av = attr->first_value; av; av = av->next) - if (rtx_equal_p (value, av->value) + if (attr_equal_p (value, av->value) && (num_alt == 0 || av->first_insn == NULL || insn_alternatives[av->first_insn->def->insn_code])) return av; @@ -2339,9 +2267,7 @@ simplify_test_exp_in_temp (rtx exp, int insn_code, rtl_obstack = temp_obstack; x = simplify_test_exp (exp, insn_code, insn_index); rtl_obstack = old; - if (x == exp || rtl_obstack == temp_obstack) - return x; - return attr_copy_rtx (x); + return x; } /* Returns true if S1 is a subset of S2. */ @@ -2397,28 +2323,27 @@ attr_alt_subset_of_compl_p (rtx s1, rtx s2) static rtx attr_alt_intersection (rtx s1, rtx s2) { - rtx result = rtx_alloc (EQ_ATTR_ALT); + int result; switch ((XINT (s1, 1) << 1) | XINT (s2, 1)) { case (0 << 1) | 0: - XINT (result, 0) = XINT (s1, 0) & XINT (s2, 0); + result = XINT (s1, 0) & XINT (s2, 0); break; case (0 << 1) | 1: - XINT (result, 0) = XINT (s1, 0) & ~XINT (s2, 0); + result = XINT (s1, 0) & ~XINT (s2, 0); break; case (1 << 1) | 0: - XINT (result, 0) = XINT (s2, 0) & ~XINT (s1, 0); + result = XINT (s2, 0) & ~XINT (s1, 0); break; case (1 << 1) | 1: - XINT (result, 0) = XINT (s1, 0) | XINT (s2, 0); + result = XINT (s1, 0) | XINT (s2, 0); break; default: gcc_unreachable (); } - XINT (result, 1) = XINT (s1, 1) & XINT (s2, 1); - return result; + return attr_rtx (EQ_ATTR_ALT, result, XINT (s1, 1) & XINT (s2, 1)); } /* Return EQ_ATTR_ALT expression representing union of S1 and S2. */ @@ -2426,28 +2351,27 @@ attr_alt_intersection (rtx s1, rtx s2) static rtx attr_alt_union (rtx s1, rtx s2) { - rtx result = rtx_alloc (EQ_ATTR_ALT); + int result; switch ((XINT (s1, 1) << 1) | XINT (s2, 1)) { case (0 << 1) | 0: - XINT (result, 0) = XINT (s1, 0) | XINT (s2, 0); + result = XINT (s1, 0) | XINT (s2, 0); break; case (0 << 1) | 1: - XINT (result, 0) = XINT (s2, 0) & ~XINT (s1, 0); + result = XINT (s2, 0) & ~XINT (s1, 0); break; case (1 << 1) | 0: - XINT (result, 0) = XINT (s1, 0) & ~XINT (s2, 0); + result = XINT (s1, 0) & ~XINT (s2, 0); break; case (1 << 1) | 1: - XINT (result, 0) = XINT (s1, 0) & XINT (s2, 0); + result = XINT (s1, 0) & XINT (s2, 0); break; default: gcc_unreachable (); } - XINT (result, 1) = XINT (s1, 1) | XINT (s2, 1); - return result; + return attr_rtx (EQ_ATTR_ALT, result, XINT (s1, 1) | XINT (s2, 1)); } /* Return EQ_ATTR_ALT expression representing complement of S. */ @@ -2455,12 +2379,7 @@ attr_alt_union (rtx s1, rtx s2) static rtx attr_alt_complement (rtx s) { - rtx result = rtx_alloc (EQ_ATTR_ALT); - - XINT (result, 0) = XINT (s, 0); - XINT (result, 1) = 1 - XINT (s, 1); - - return result; + return attr_rtx (EQ_ATTR_ALT, XINT (s, 0), 1 - XINT (s, 1)); } /* Return EQ_ATTR_ALT expression representing set containing elements set @@ -2469,12 +2388,7 @@ attr_alt_complement (rtx s) static rtx mk_attr_alt (uint64_t e) { - rtx result = rtx_alloc (EQ_ATTR_ALT); - - XINT (result, 0) = e; - XINT (result, 1) = 0; - - return result; + return attr_rtx (EQ_ATTR_ALT, (int)e, 0); } /* Given an expression, see if it can be simplified for a particular insn @@ -3045,7 +2959,6 @@ optimize_attrs (int num_insn_codes) && attr_rtx_cost (newexp) < 26 ) { - newexp = attr_copy_rtx (newexp); remove_insn_ent (av, ie); av = get_attr_value (ie->def->loc, newexp, attr, ie->def->insn_code); @@ -5004,7 +4917,7 @@ make_automaton_attrs (void) { int j; char *name; - rtx test = attr_rtx (EQ_ATTR, tune_attr->name, XSTR (val->value, 0)); + rtx test = attr_eq (tune_attr->name, XSTR (val->value, 0)); if (val == tune_attr->default_val) continue;