From patchwork Fri Apr 15 13:20:22 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Froyd X-Patchwork-Id: 91371 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 EBDF4B6F08 for ; Fri, 15 Apr 2011 23:20:57 +1000 (EST) Received: (qmail 11638 invoked by alias); 15 Apr 2011 13:20:30 -0000 Received: (qmail 11482 invoked by uid 22791); 15 Apr 2011 13:20:28 -0000 X-SWARE-Spam-Status: No, hits=-1.7 required=5.0 tests=AWL, BAYES_00, TW_TM, 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, 15 Apr 2011 13:20:23 +0000 Received: (qmail 6912 invoked from network); 15 Apr 2011 13:20:22 -0000 Received: from unknown (HELO localhost) (froydnj@127.0.0.2) by mail.codesourcery.com with ESMTPA; 15 Apr 2011 13:20:22 -0000 Date: Fri, 15 Apr 2011 06:20:22 -0700 From: Nathan Froyd To: gcc-patches@gcc.gnu.org Subject: [PATCH] refactor gimple asm memory clobber checking Message-ID: <20110415132022.GY23480@codesourcery.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.17+20080114 (2008-01-14) X-IsSubscribed: yes 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 There are a couple places that check GIMPLE_ASMs for clobbering memory; this patch centralizes the logic in gimple.c. Tested on x86_64-unknown-linux-gnu. OK to commit? -Nathan * gimple.h (gimple_asm_clobbers_memory_p): Declare. * gimple.c (gimple_asm_clobbers_memory_p): Define. * ipa-pure-const.c (check_stmt): Call it. * tree-ssa-operands.c (get_asm_expr_operands): Likewise. diff --git a/gcc/gimple.c b/gcc/gimple.c index 090fc94..5dc62ea 100644 --- a/gcc/gimple.c +++ b/gcc/gimple.c @@ -5142,4 +5142,21 @@ gimple_call_builtin_p (gimple stmt, enum built_in_function code) && DECL_FUNCTION_CODE (fndecl) == code); } +/* Return true if STMT clobbers memory. STMT is required to be a + GIMPLE_ASM. */ + +bool +gimple_asm_clobbers_memory_p (const_gimple stmt) +{ + unsigned i; + + for (i = 0; i < gimple_asm_nclobbers (stmt); i++) + { + tree op = gimple_asm_clobber_op (stmt, i); + if (strcmp (TREE_STRING_POINTER (TREE_VALUE (op)), "memory") == 0) + return true; + } + + return false; +} #include "gt-gimple.h" diff --git a/gcc/gimple.h b/gcc/gimple.h index 572cabc..840e149 100644 --- a/gcc/gimple.h +++ b/gcc/gimple.h @@ -973,6 +973,7 @@ extern bool walk_stmt_load_store_ops (gimple, void *, bool (*)(gimple, tree, void *)); extern bool gimple_ior_addresses_taken (bitmap, gimple); extern bool gimple_call_builtin_p (gimple, enum built_in_function); +extern bool gimple_asm_clobbers_memory_p (const_gimple); /* In gimplify.c */ extern tree create_tmp_var_raw (tree, const char *); diff --git a/gcc/ipa-pure-const.c b/gcc/ipa-pure-const.c index b7deb57..eb5b0f6 100644 --- a/gcc/ipa-pure-const.c +++ b/gcc/ipa-pure-const.c @@ -639,7 +639,6 @@ static void check_stmt (gimple_stmt_iterator *gsip, funct_state local, bool ipa) { gimple stmt = gsi_stmt (*gsip); - unsigned int i = 0; if (is_gimple_debug (stmt)) return; @@ -693,16 +692,12 @@ check_stmt (gimple_stmt_iterator *gsip, funct_state local, bool ipa) } break; case GIMPLE_ASM: - for (i = 0; i < gimple_asm_nclobbers (stmt); i++) + if (gimple_asm_clobbers_memory_p (stmt)) { - tree op = gimple_asm_clobber_op (stmt, i); - if (strcmp (TREE_STRING_POINTER (TREE_VALUE (op)), "memory") == 0) - { - if (dump_file) - fprintf (dump_file, " memory asm clobber is not const/pure"); - /* Abandon all hope, ye who enter here. */ - local->pure_const_state = IPA_NEITHER; - } + if (dump_file) + fprintf (dump_file, " memory asm clobber is not const/pure"); + /* Abandon all hope, ye who enter here. */ + local->pure_const_state = IPA_NEITHER; } if (gimple_asm_volatile_p (stmt)) { diff --git a/gcc/tree-ssa-operands.c b/gcc/tree-ssa-operands.c index 57f443f..7f76cbf 100644 --- a/gcc/tree-ssa-operands.c +++ b/gcc/tree-ssa-operands.c @@ -832,15 +832,8 @@ get_asm_expr_operands (gimple stmt) } /* Clobber all memory and addressable symbols for asm ("" : : : "memory"); */ - for (i = 0; i < gimple_asm_nclobbers (stmt); i++) - { - tree link = gimple_asm_clobber_op (stmt, i); - if (strcmp (TREE_STRING_POINTER (TREE_VALUE (link)), "memory") == 0) - { - add_virtual_operand (stmt, opf_def); - break; - } - } + if (gimple_asm_clobbers_memory_p (stmt)) + add_virtual_operand (stmt, opf_def); }