From patchwork Fri Nov 13 20:33:48 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bernd Schmidt X-Patchwork-Id: 544452 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 0CBAA141450 for ; Sat, 14 Nov 2015 07:34:03 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=Ln8g6grE; 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 :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=ZsUi0B6KTNV78IkLi6qrIHK/zY/LWVekkHfXc+j6Ub/kt3wZI2 Utzp6L0MleWbo0svYbbdwkOViv8XjloAupPnRyJlNZJcHeGwA/bdHOdn42y9bXId +IqMqtrZymsXM0eJG+3btubrLNC5rglWp0hhEBYe7oMNxFbQwxWGg68uk= 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 :from:subject:message-id:date:mime-version:content-type; s= default; bh=YECGaoNH/LqXCd2znc52EHA2VEw=; b=Ln8g6grE2ctP2MRaMwWk JfN1kzDJ/8RJXQ1heGx5NAmHa6En0t9zsfFrNHGt7RRObied5mc70I0XWhdLO7D7 qO2Yc2cvWLzeml6LUooeLgbkI1gBwKMHuSQ7kYd3qa4s7+cKVvp3JBrR5KjHpY8x ZmSs2vewAagM+PKZ1ji3G/4= Received: (qmail 112878 invoked by alias); 13 Nov 2015 20:33:56 -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 112864 invoked by uid 89); 13 Nov 2015 20:33:56 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=1.0 required=5.0 tests=AWL, BAYES_05, KAM_LAZY_DOMAIN_SECURITY, RCVD_IN_BL_SPAMCOP_NET, RCVD_IN_DNSWL_NONE, RP_MATCHES_RCVD autolearn=no version=3.3.2 X-HELO: mailout03.t-online.de Received: from mailout03.t-online.de (HELO mailout03.t-online.de) (194.25.134.81) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Fri, 13 Nov 2015 20:33:54 +0000 Received: from fwd18.aul.t-online.de (fwd18.aul.t-online.de [172.20.26.244]) by mailout03.t-online.de (Postfix) with SMTP id EEE6A60EA31 for ; Fri, 13 Nov 2015 21:33:50 +0100 (CET) Received: from [192.168.2.105] (TWtOP0ZEYhzoUOrX5rd-ySsg-w7U2UYJZ1szay+sMMy7xbPIGQKcqVFVsAmugTJgwG@[84.167.116.215]) by fwd18.t-online.de with (TLSv1.2:ECDHE-RSA-AES256-SHA encrypted) esmtp id 1ZxL2c-2URA0G0; Fri, 13 Nov 2015 21:33:50 +0100 To: GCC Patches From: Bernd Schmidt Subject: [1/2] i386 ROP mitigation: make more of regrename callable Message-ID: <5646492C.4070607@t-online.de> Date: Fri, 13 Nov 2015 21:33:48 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 MIME-Version: 1.0 X-IsSubscribed: yes This just creates a new function in regrename.c, which I need for the 2/2 patch that I'll submit in a moment. Bootstrapped and tested on x86_64-linux. Ok? Bernd * regrename.h (regrename_find_superclass): Declare. (regrename_find_superclass): New function, code moved from ... (rename_chains): ... here. Call it. diff --git a/gcc/regrename.c b/gcc/regrename.c index c328c1b..788c8fd 100644 --- a/gcc/regrename.c +++ b/gcc/regrename.c @@ -409,6 +416,33 @@ find_rename_reg (du_head_p this_head, enum reg_class super_class, return best_new_reg; } +/* Iterate over elements in the chain HEAD in order to: + 1. Count number of uses, storing it in *PN_USES. + 2. Narrow the set of registers we can use for renaming, adding + unavailable registers to *PUNAVAILABLE, which must be + initialized by the caller. + 3. Compute the superunion of register classes in this chain + and return it. */ +reg_class +regrename_find_superclass (du_head_p head, int *pn_uses, + HARD_REG_SET *punavailable) +{ + int n_uses = 0; + reg_class super_class = NO_REGS; + for (du_chain *tmp = head->first; tmp; tmp = tmp->next_use) + { + if (DEBUG_INSN_P (tmp->insn)) + continue; + n_uses++; + IOR_COMPL_HARD_REG_SET (*punavailable, + reg_class_contents[tmp->cl]); + super_class + = reg_class_superunion[(int) super_class][(int) tmp->cl]; + } + *pn_uses = n_uses; + return super_class; +} + /* Perform register renaming on the current function. */ static void rename_chains (void) @@ -432,10 +466,8 @@ rename_chains (void) { int best_new_reg; int n_uses; - struct du_chain *tmp; HARD_REG_SET this_unavailable; int reg = this_head->regno; - enum reg_class super_class = NO_REGS; if (this_head->cannot_rename) continue; @@ -449,23 +481,8 @@ rename_chains (void) COPY_HARD_REG_SET (this_unavailable, unavailable); - /* Iterate over elements in the chain in order to: - 1. Count number of uses, and narrow the set of registers we can - use for renaming. - 2. Compute the superunion of register classes in this chain. */ - n_uses = 0; - super_class = NO_REGS; - for (tmp = this_head->first; tmp; tmp = tmp->next_use) - { - if (DEBUG_INSN_P (tmp->insn)) - continue; - n_uses++; - IOR_COMPL_HARD_REG_SET (this_unavailable, - reg_class_contents[tmp->cl]); - super_class - = reg_class_superunion[(int) super_class][(int) tmp->cl]; - } - + reg_class super_class = regrename_find_superclass (this_head, &n_uses, + &this_unavailable); if (n_uses < 2) continue; diff --git a/gcc/regrename.h b/gcc/regrename.h index bbe156d..f9f9481 100644 --- a/gcc/regrename.h +++ b/gcc/regrename.h @@ -92,5 +96,7 @@ extern du_head_p regrename_chain_from_id (unsigned int); extern int find_rename_reg (du_head_p, enum reg_class, HARD_REG_SET *, int, bool); extern bool regrename_do_replace (du_head_p, int); +extern reg_class regrename_find_superclass (du_head_p, int *, + HARD_REG_SET *); #endif