From patchwork Sun Oct 21 20:03:45 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joern Rennecke X-Patchwork-Id: 193055 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 10C612C008B for ; Mon, 22 Oct 2012 07:03:59 +1100 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1351454641; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Message-ID:Date:From:To:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding:User-Agent:Mailing-List:Precedence: List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender: Delivered-To; bh=3JuhUDjAG5g2t9O2KJAbBd6b2Tw=; b=cWdCxCqDJA1CIXr 8vf3b1xK0U1de0hPnPX8NH0luwAoTbOKvSt3gvmhRfJey7Z7UsmAXlJdeumE8+R8 Du+JCrR4eqGvnvf6iw2NxEfz6jDwvUY/YiQW0D67mnbuVwlOVn8aEwmcx6Tte8u8 2E6scLe8qygcxkhZ28QSh9BTWxK0= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:Message-ID:Date:From:To:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding:User-Agent:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=qw2sLBBRB3hj64g7rxD/8X2Yjh0MPeBekljGSDrkJqfUl+a/okE4DG0TTBoTsj Vx5yuKp8iYDGYqIHS/6QUJSaRmJk13bDShHpVMgqpfnJdr+NoVEdyok9TSMCeUyD pbjoOlfBnarjBJM3j1QdhfsO9gHkAgPdx8j7/AiTZSKNw=; Received: (qmail 2099 invoked by alias); 21 Oct 2012 20:03:56 -0000 Received: (qmail 2085 invoked by uid 22791); 21 Oct 2012 20:03:55 -0000 X-SWARE-Spam-Status: No, hits=-2.1 required=5.0 tests=AWL, BAYES_00, MIME_QP_LONG_LINE, RCVD_IN_HOSTKARMA_NO X-Spam-Check-By: sourceware.org Received: from c62.cesmail.net (HELO c62.cesmail.net) (216.154.195.54) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sun, 21 Oct 2012 20:03:47 +0000 Received: from unknown (HELO delta2) ([192.168.1.50]) by c62.cesmail.net with ESMTP; 21 Oct 2012 16:03:46 -0400 Received: from cust213-dsl91-135-11.idnet.net (cust213-dsl91-135-11.idnet.net [91.135.11.213]) by webmail.spamcop.net (Horde MIME library) with HTTP; Sun, 21 Oct 2012 16:03:45 -0400 Message-ID: <20121021160345.z3jgi3w4mcw4wsco-nzlynne@webmail.spamcop.net> Date: Sun, 21 Oct 2012 16:03:45 -0400 From: Joern Rennecke To: gcc-patches@gcc.gnu.org Subject: RFA: replace #ifdef with if/#if for HAVE_ATTR_* MIME-Version: 1.0 User-Agent: Internet Messaging Program (IMP) H3 (4.1.4) 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 As discussed on the gcc mailing list ("RFD: HAVE_* pattern flags"), we would like to have fewer #ifdefs littered throughout our functions. And in order to get there, we first need flags with values that are suitable for the C / C++ parsers, i.e. values 1 or 0 instead of defined or not. This patch addresses the HAVE_ATTR_length and HAVE_ATTR_enabled flags generated by gen_attr, and also uses the new defintion of HAVE_ATTR_length to clean up final.c a bit; that required also some further changes in the generator files so that certain symbols are always available. It should also make it easier to further change the generated insn length bits into hooks (or whatever C++ concept might take their place), should we decide that we want to go in that direction. Bootstrapped on i686-pc-linux-gnu. regression tested on i686-pc-linux-gnu X mipsel-elf build tested (incl. libgcc,newlib,libobjc,libstdc++-v3) for i686-pc-linux-gnu X mmix-knuth-mmixware 2012-10-21 Joern Rennecke * doc/md.texi (Defining Attributes): Document that we are defining HAVE_ATTR_name macors as 1 for defined attributes, and as 0 for undefined special attributes. * final.c (asm_insn_count, align_fuzz): Always define. (insn_current_reference_address): Likewise. (init_insn_lengths): Use if (HAVE_ATTR_length) instead of #ifdef HAVE_ATTR_length. (get_attr_length_1, shorten_branches, final): Likewise. (final_scan_insn, output_asm_name): Likewise. * genattr.c (gen_attr): Define HAVE_ATTR_name macros for defined attributes as 1. Remove ancient get_attr_alternative compatibility code. For special purpose attributes not provided, define HAVE_ATTR_name as 0. In case no length attribute is given, provide stub definitions for insn_*_length* functions, and also include insn-addr.h. * genattrtab.c (write_length_unit_log): Always write a definition. * recog.c: Use #if instead of #ifndef / #if defined for HAVE_ATTR_enabled and HAVE_ATTR_length. Index: doc/md.texi =================================================================== --- doc/md.texi (revision 192654) +++ doc/md.texi (working copy) @@ -7496,7 +7496,7 @@ (define_attr "type" "branch,fp,load,stor the following lines will be written to the file @file{insn-attr.h}. @smallexample -#define HAVE_ATTR_type +#define HAVE_ATTR_type 1 enum attr_type @{TYPE_BRANCH, TYPE_FP, TYPE_LOAD, TYPE_STORE, TYPE_ARITH@}; extern enum attr_type get_attr_type (); @@ -7521,6 +7521,10 @@ extern enum attr_type get_attr_type (); generation. @xref{Disable Insn Alternatives}. @end table +For each of these special attributes, the corresponding +@samp{HAVE_ATTR_@var{name}} @samp{#define} is also written when the +attribute is not defined; in that case, it is defined as @samp{0}. + @findex define_enum_attr @anchor{define_enum_attr} Another way of defining an attribute is to use: Index: final.c =================================================================== --- final.c (revision 192654) +++ final.c (working copy) @@ -204,9 +204,7 @@ Software Foundation; either version 3, o /* True if printing into -fdump-final-insns= dump. */ bool final_insns_dump_p; -#ifdef HAVE_ATTR_length static int asm_insn_count (rtx); -#endif static void profile_function (FILE *); static void profile_after_prologue (FILE *); static bool notice_source_line (rtx, bool *); @@ -224,9 +222,7 @@ static int alter_cond (rtx); #ifndef ADDR_VEC_ALIGN static int final_addr_vec_align (rtx); #endif -#ifdef HAVE_ATTR_length static int align_fuzz (rtx, rtx, int, unsigned); -#endif /* Initialize data in final at the beginning of a compilation. */ @@ -362,9 +358,8 @@ init_insn_lengths (void) insn_lengths = 0; insn_lengths_max_uid = 0; } -#ifdef HAVE_ATTR_length - INSN_ADDRESSES_FREE (); -#endif + if (HAVE_ATTR_length) + INSN_ADDRESSES_FREE (); if (uid_align) { free (uid_align); @@ -376,14 +371,15 @@ init_insn_lengths (void) get its actual length. Otherwise, use FALLBACK_FN to calculate the length. */ static inline int -get_attr_length_1 (rtx insn ATTRIBUTE_UNUSED, - int (*fallback_fn) (rtx) ATTRIBUTE_UNUSED) +get_attr_length_1 (rtx insn, int (*fallback_fn) (rtx)) { -#ifdef HAVE_ATTR_length rtx body; int i; int length = 0; + if (!HAVE_ATTR_length) + return 0; + if (insn_lengths_max_uid > INSN_UID (insn)) return insn_lengths[INSN_UID (insn)]; else @@ -432,11 +428,6 @@ get_attr_length_1 (rtx insn ATTRIBUTE_UN ADJUST_INSN_LENGTH (insn, length); #endif return length; -#else /* not HAVE_ATTR_length */ - return 0; -#define insn_default_length 0 -#define insn_min_length 0 -#endif /* not HAVE_ATTR_length */ } /* Obtain the current length of an insn. If branch shortening has been done, @@ -583,7 +574,6 @@ label_to_max_skip (rtx label) return 0; } -#ifdef HAVE_ATTR_length /* The differences in addresses between a branch and its target might grow or shrink depending on the alignment the start insn of the range (the branch for a forward @@ -686,7 +676,6 @@ insn_current_reference_address (rtx bran + align_fuzz (dest, seq, length_unit_log, ~0)); } } -#endif /* HAVE_ATTR_length */ /* Compute branch alignments based on frequency information in the CFG. */ @@ -850,14 +839,13 @@ struct rtl_opt_pass pass_compute_alignme slots. */ void -shorten_branches (rtx first ATTRIBUTE_UNUSED) +shorten_branches (rtx first) { rtx insn; int max_uid; int i; int max_log; int max_skip; -#ifdef HAVE_ATTR_length #define MAX_CODE_ALIGN 16 rtx seq; int something_changed = 1; @@ -866,8 +854,6 @@ shorten_branches (rtx first ATTRIBUTE_UN int uid; rtx align_tab[MAX_CODE_ALIGN]; -#endif - /* Compute maximum UID and allocate label_align / uid_shuid. */ max_uid = get_max_uid (); @@ -974,7 +960,8 @@ shorten_branches (rtx first ATTRIBUTE_UN } } } -#ifdef HAVE_ATTR_length + if (!HAVE_ATTR_length) + return; /* Allocate the rest of the arrays. */ insn_lengths = XNEWVEC (int, max_uid); @@ -1420,11 +1407,8 @@ shorten_branches (rtx first ATTRIBUTE_UN } free (varying_length); - -#endif /* HAVE_ATTR_length */ } -#ifdef HAVE_ATTR_length /* Given the body of an INSN known to be generated by an ASM statement, return the number of machine instructions likely to be generated for this insn. This is used to compute its length. */ @@ -1441,7 +1425,6 @@ asm_insn_count (rtx body) return asm_str_count (templ); } -#endif /* Return the number of machine instructions likely to be generated for the inline-asm template. */ @@ -1902,17 +1885,18 @@ final (rtx first, FILE *file, int optimi /* Output the insns. */ for (insn = first; insn;) { -#ifdef HAVE_ATTR_length - if ((unsigned) INSN_UID (insn) >= INSN_ADDRESSES_SIZE ()) + if (HAVE_ATTR_length) { - /* This can be triggered by bugs elsewhere in the compiler if - new insns are created after init_insn_lengths is called. */ - gcc_assert (NOTE_P (insn)); - insn_current_address = -1; + if ((unsigned) INSN_UID (insn) >= INSN_ADDRESSES_SIZE ()) + { + /* This can be triggered by bugs elsewhere in the compiler if + new insns are created after init_insn_lengths is called. */ + gcc_assert (NOTE_P (insn)); + insn_current_address = -1; + } + else + insn_current_address = INSN_ADDRESSES (INSN_UID (insn)); } - else - insn_current_address = INSN_ADDRESSES (INSN_UID (insn)); -#endif /* HAVE_ATTR_length */ dump_basic_block_info (file, insn, start_to_bb, end_to_bb, bb_map_size, &bb_seqn); @@ -2853,12 +2837,13 @@ final_scan_insn (rtx insn, FILE *file, i if (new_rtx == insn && PATTERN (new_rtx) == body) fatal_insn ("could not split insn", insn); -#ifdef HAVE_ATTR_length - /* This instruction should have been split in shorten_branches, - to ensure that we would have valid length info for the - splitees. */ - gcc_unreachable (); -#endif + if (HAVE_ATTR_length) + { + /* This instruction should have been split in shorten_branches, + to ensure that we would have valid length info for the + splitees. */ + gcc_unreachable (); + } return new_rtx; } @@ -3289,10 +3274,11 @@ output_asm_name (void) insn_data[num].name); if (insn_data[num].n_alternatives > 1) fprintf (asm_out_file, "/%d", which_alternative + 1); -#ifdef HAVE_ATTR_length - fprintf (asm_out_file, "\t[length = %d]", - get_attr_length (debug_insn)); -#endif + + if (HAVE_ATTR_length) + fprintf (asm_out_file, "\t[length = %d]", + get_attr_length (debug_insn)); + /* Clear this so only the first assembler insn of any rtl insn will get the special comment for -dp. */ debug_insn = 0; Index: genattr.c =================================================================== --- genattr.c (revision 192654) +++ genattr.c (working copy) @@ -44,7 +44,7 @@ gen_attr (rtx attr) if (is_const) VEC_safe_push (rtx, heap, const_attrs, attr); - printf ("#define HAVE_ATTR_%s\n", XSTR (attr, 0)); + printf ("#define HAVE_ATTR_%s 1\n", XSTR (attr, 0)); /* If numeric attribute, don't need to write an enum. */ if (GET_CODE (attr) == DEFINE_ENUM_ATTR) @@ -159,12 +159,6 @@ main (int argc, char **argv) puts ("#include \"insn-attr-common.h\"\n"); - /* For compatibility, define the attribute `alternative', which is just - a reference to the variable `which_alternative'. */ - - puts ("#define HAVE_ATTR_alternative"); - puts ("#define get_attr_alternative(insn) which_alternative"); - /* Read the machine description. */ while (1) @@ -342,6 +336,25 @@ main (int argc, char **argv) printf ("typedef void *state_t;\n\n"); } + /* Special-purpose atributes should be tested with if, not #ifdef. */ + const char * const special_attrs[] = { "length", "enabled", 0 }; + for (const char * const *p = special_attrs; *p; p++) + { + printf ("#ifndef HAVE_ATTR_%s\n" + "#define HAVE_ATTR_%s 0\n" + "#endif\n", *p, *p); + } + /* We make an exception here to provide stub definitions for + insn_*_length* functions. */ + puts ("#if !HAVE_ATTR_length\n" + "extern int hook_int_rtx_0 (rtx);\n" + "#define insn_default_length hook_int_rtx_0\n" + "#define insn_min_length hook_int_rtx_0\n" + "#define insn_variable_length_p hook_int_rtx_0\n" + "#define insn_current_length hook_int_rtx_0\n" + "#include \"insn-addr.h\"\n" + "#endif\n"); + /* Output flag masks for use by reorg. Flags are used to hold branch direction for use by eligible_for_... */ Index: genattrtab.c =================================================================== --- genattrtab.c (revision 192654) +++ genattrtab.c (working copy) @@ -1636,14 +1636,15 @@ write_length_unit_log (FILE *outf) unsigned int length_unit_log, length_or; int unknown = 0; - if (length_attr == 0) - return; - length_or = or_attr_value (length_attr->default_val->value, &unknown); - for (av = length_attr->first_value; av; av = av->next) - for (ie = av->first_insn; ie; ie = ie->next) - length_or |= or_attr_value (av->value, &unknown); + if (length_attr) + { + length_or = or_attr_value (length_attr->default_val->value, &unknown); + for (av = length_attr->first_value; av; av = av->next) + for (ie = av->first_insn; ie; ie = ie->next) + length_or |= or_attr_value (av->value, &unknown); + } - if (unknown) + if (length_attr == NULL || unknown) length_unit_log = 0; else { Index: recog.c =================================================================== --- recog.c (revision 192654) +++ recog.c (working copy) @@ -57,7 +57,7 @@ Software Foundation; either version 3, o #endif #endif -#ifndef HAVE_ATTR_enabled +#if !HAVE_ATTR_enabled static inline bool get_attr_enabled (rtx insn ATTRIBUTE_UNUSED) { @@ -3804,7 +3804,7 @@ struct rtl_opt_pass pass_split_after_rel static bool gate_handle_split_before_regstack (void) { -#if defined (HAVE_ATTR_length) && defined (STACK_REGS) +#if (HAVE_ATTR_length) && defined (STACK_REGS) /* If flow2 creates new instructions which need splitting and scheduling after reload is not done, they might not be split until final which doesn't allow splitting @@ -3888,7 +3888,7 @@ struct rtl_opt_pass pass_split_before_sc static bool gate_do_final_split (void) { -#if defined (HAVE_ATTR_length) && !defined (STACK_REGS) +#if (HAVE_ATTR_length) && !defined (STACK_REGS) return 1; #else return 0;