From patchwork Fri Jun 18 14:06:19 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bernd Schmidt X-Patchwork-Id: 56185 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]) by ozlabs.org (Postfix) with SMTP id 6D7901007D4 for ; Sat, 19 Jun 2010 00:06:39 +1000 (EST) Received: (qmail 4440 invoked by alias); 18 Jun 2010 14:06:35 -0000 Received: (qmail 4328 invoked by uid 22791); 18 Jun 2010 14:06:33 -0000 X-SWARE-Spam-Status: No, hits=-1.9 required=5.0 tests=AWL, BAYES_00, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mail.codesourcery.com (HELO mail.codesourcery.com) (38.113.113.100) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 18 Jun 2010 14:06:27 +0000 Received: (qmail 31107 invoked from network); 18 Jun 2010 14:06:25 -0000 Received: from unknown (HELO ?84.152.216.85?) (bernds@127.0.0.2) by mail.codesourcery.com with ESMTPA; 18 Jun 2010 14:06:25 -0000 Message-ID: <4C1B7D5B.6060803@codesourcery.com> Date: Fri, 18 Jun 2010 14:06:19 +0000 From: Bernd Schmidt User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.9) Gecko/20100604 Thunderbird/3.0.4 MIME-Version: 1.0 To: GCC Patches Subject: Patch 3/9: create some more small helper functions References: <4C1B7BC0.7010803@codesourcery.com> In-Reply-To: <4C1B7BC0.7010803@codesourcery.com> 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 This is purely a cleanup patch that creates small helper functions for some ugly if statements with side effects that occur in several places. None of the subsequent patches depend on this, but I think it's a useful cleanup. * ira-int.h (ira_parent_allocno, ira_parent_or_cap_allocno): Declare. * ira-build.c (ira_parent_allocno, ira_parent_or_cap_allocno): New functions. (ira_flattening): Use ira_parent_allocno. * ira-conflicts.c (process_regs_for_copy, propagate_copies) build_allocno_conflicts): Use ira_parent_or_cap_allocno. (Index: gcc/ira-build.c =================================================================== --- gcc.orig/ira-build.c +++ gcc/ira-build.c @@ -2416,6 +2416,34 @@ create_caps (void) IR with one region. */ static ira_allocno_t *regno_top_level_allocno_map; +/* Find the allocno that corresponds to A at a level one higher up in the + loop tree. Returns NULL if A is a cap, or if it has no parent. */ +ira_allocno_t +ira_parent_allocno (ira_allocno_t a) +{ + ira_loop_tree_node_t parent; + + if (ALLOCNO_CAP (a) != NULL) + return NULL; + + parent = ALLOCNO_LOOP_TREE_NODE (a)->parent; + if (parent == NULL) + return NULL; + + return parent->regno_allocno_map[ALLOCNO_REGNO (a)]; +} + +/* Find the allocno that corresponds to A at a level one higher up in the + loop tree. If ALLOCNO_CAP is set for A, return that. */ +ira_allocno_t +ira_parent_or_cap_allocno (ira_allocno_t a) +{ + if (ALLOCNO_CAP (a) != NULL) + return ALLOCNO_CAP (a); + + return ira_parent_allocno (a); +} + /* Process all allocnos originated from pseudo REGNO and copy live ranges, hard reg conflicts, and allocno stack reg attributes from low level allocnos to final allocnos which are destinations of @@ -2478,7 +2506,7 @@ ira_flattening (int max_regno_before_emi enum reg_class cover_class; ira_allocno_t a, parent_a, first, second, node_first, node_second; ira_copy_t cp; - ira_loop_tree_node_t parent, node; + ira_loop_tree_node_t node; allocno_live_range_t r; ira_allocno_iterator ai; ira_copy_iterator ci; @@ -2513,10 +2541,8 @@ ira_flattening (int max_regno_before_emi ira_assert (ALLOCNO_CAP_MEMBER (a) == NULL); if (ALLOCNO_SOMEWHERE_RENAMED_P (a)) new_pseudos_p = true; - if (ALLOCNO_CAP (a) != NULL - || (parent = ALLOCNO_LOOP_TREE_NODE (a)->parent) == NULL - || ((parent_a = parent->regno_allocno_map[ALLOCNO_REGNO (a)]) - == NULL)) + parent_a = ira_parent_allocno (a); + if (parent_a == NULL) { ALLOCNO_COPIES (a) = NULL; regno_top_level_allocno_map[REGNO (ALLOCNO_REG (a))] = a; @@ -2564,11 +2590,8 @@ ira_flattening (int max_regno_before_emi ALLOCNO_COVER_CLASS_COST (parent_a) -= ALLOCNO_COVER_CLASS_COST (a); ALLOCNO_MEMORY_COST (parent_a) -= ALLOCNO_MEMORY_COST (a); - if (ALLOCNO_CAP (parent_a) != NULL - || (parent - = ALLOCNO_LOOP_TREE_NODE (parent_a)->parent) == NULL - || (parent_a = (parent->regno_allocno_map - [ALLOCNO_REGNO (parent_a)])) == NULL) + parent_a = ira_parent_allocno (parent_a); + if (parent_a == NULL) break; } ALLOCNO_COPIES (a) = NULL; Index: gcc/ira-conflicts.c =================================================================== --- gcc.orig/ira-conflicts.c +++ gcc/ira-conflicts.c @@ -346,7 +346,6 @@ process_regs_for_copy (rtx reg1, rtx reg enum reg_class rclass, cover_class; enum machine_mode mode; ira_copy_t cp; - ira_loop_tree_node_t parent; gcc_assert (REG_SUBREG_P (reg1) && REG_SUBREG_P (reg2)); only_regs_p = REG_P (reg1) && REG_P (reg2); @@ -397,7 +396,7 @@ process_regs_for_copy (rtx reg1, rtx reg cost = ira_get_register_move_cost (mode, cover_class, rclass) * freq; else cost = ira_get_register_move_cost (mode, rclass, cover_class) * freq; - for (;;) + do { ira_allocate_and_set_costs (&ALLOCNO_HARD_REG_COSTS (a), cover_class, @@ -408,12 +407,9 @@ process_regs_for_copy (rtx reg1, rtx reg ALLOCNO_CONFLICT_HARD_REG_COSTS (a)[index] -= cost; if (ALLOCNO_HARD_REG_COSTS (a)[index] < ALLOCNO_COVER_CLASS_COST (a)) ALLOCNO_COVER_CLASS_COST (a) = ALLOCNO_HARD_REG_COSTS (a)[index]; - if (ALLOCNO_CAP (a) != NULL) - a = ALLOCNO_CAP (a); - else if ((parent = ALLOCNO_LOOP_TREE_NODE (a)->parent) == NULL - || (a = parent->regno_allocno_map[ALLOCNO_REGNO (a)]) == NULL) - break; + a = ira_parent_or_cap_allocno (a); } + while (a != NULL); return true; } @@ -533,7 +529,6 @@ propagate_copies (void) ira_copy_t cp; ira_copy_iterator ci; ira_allocno_t a1, a2, parent_a1, parent_a2; - ira_loop_tree_node_t parent; FOR_EACH_COPY (cp, ci) { @@ -542,11 +537,8 @@ propagate_copies (void) if (ALLOCNO_LOOP_TREE_NODE (a1) == ira_loop_tree_root) continue; ira_assert ((ALLOCNO_LOOP_TREE_NODE (a2) != ira_loop_tree_root)); - parent = ALLOCNO_LOOP_TREE_NODE (a1)->parent; - if ((parent_a1 = ALLOCNO_CAP (a1)) == NULL) - parent_a1 = parent->regno_allocno_map[ALLOCNO_REGNO (a1)]; - if ((parent_a2 = ALLOCNO_CAP (a2)) == NULL) - parent_a2 = parent->regno_allocno_map[ALLOCNO_REGNO (a2)]; + parent_a1 = ira_parent_or_cap_allocno (a1); + parent_a2 = ira_parent_or_cap_allocno (a2); ira_assert (parent_a1 != NULL && parent_a2 != NULL); if (! CONFLICT_ALLOCNO_P (parent_a1, parent_a2)) ira_add_allocno_copy (parent_a1, parent_a2, cp->freq, @@ -565,7 +557,6 @@ build_allocno_conflicts (ira_allocno_t a { int i, px, parent_num; int conflict_bit_vec_words_num; - ira_loop_tree_node_t parent; ira_allocno_t parent_a, another_a, another_parent_a; ira_allocno_t *vec; IRA_INT_TYPE *allocno_conflicts; @@ -601,13 +592,9 @@ build_allocno_conflicts (ira_allocno_t a ALLOCNO_CONFLICT_ALLOCNO_ARRAY_SIZE (a) = conflict_bit_vec_words_num * sizeof (IRA_INT_TYPE); } - parent = ALLOCNO_LOOP_TREE_NODE (a)->parent; - if ((parent_a = ALLOCNO_CAP (a)) == NULL - && (parent == NULL - || (parent_a = parent->regno_allocno_map[ALLOCNO_REGNO (a)]) - == NULL)) + parent_a = ira_parent_or_cap_allocno (a); + if (parent_a == NULL) return; - ira_assert (parent != NULL); ira_assert (ALLOCNO_COVER_CLASS (a) == ALLOCNO_COVER_CLASS (parent_a)); parent_num = ALLOCNO_NUM (parent_a); FOR_EACH_ALLOCNO_IN_SET (allocno_conflicts, @@ -616,9 +603,8 @@ build_allocno_conflicts (ira_allocno_t a another_a = ira_conflict_id_allocno_map[i]; ira_assert (ira_reg_classes_intersect_p [ALLOCNO_COVER_CLASS (a)][ALLOCNO_COVER_CLASS (another_a)]); - if ((another_parent_a = ALLOCNO_CAP (another_a)) == NULL - && (another_parent_a = (parent->regno_allocno_map - [ALLOCNO_REGNO (another_a)])) == NULL) + another_parent_a = ira_parent_or_cap_allocno (another_a); + if (another_parent_a == NULL) continue; ira_assert (ALLOCNO_NUM (another_parent_a) >= 0); ira_assert (ALLOCNO_COVER_CLASS (another_a) Index: gcc/ira-int.h =================================================================== --- gcc.orig/ira-int.h +++ gcc/ira-int.h @@ -838,6 +838,8 @@ extern void ira_debug_allocno_copies (ir extern void ira_traverse_loop_tree (bool, ira_loop_tree_node_t, void (*) (ira_loop_tree_node_t), void (*) (ira_loop_tree_node_t)); +extern ira_allocno_t ira_parent_allocno (ira_allocno_t); +extern ira_allocno_t ira_parent_or_cap_allocno (ira_allocno_t); extern ira_allocno_t ira_create_allocno (int, bool, ira_loop_tree_node_t); extern void ira_set_allocno_cover_class (ira_allocno_t, enum reg_class); extern bool ira_conflict_vector_profitable_p (ira_allocno_t, int);