From: Zack Weinberg <zack@codesourcery.com>
To: gcc-patches@gcc.gnu.org
Subject: RFC: Improvements to alternate-entry-point handling
Date: Wed, 17 Jul 2002 17:50:00 -0000 [thread overview]
Message-ID: <20020718004720.GF8656@codesourcery.com> (raw)
This patch accomplishes some improvements to the alternate entry point
handling code (not currently used for anything, but I have plans for
it in the near future).
First, the LABEL_NAME and LABEL_ALTERNATE_NAME fields are mutually
exclusive; they will never be set at the same time. Collapse them
together, and use a flag bit to indicate whether a CODE_LABEL is an
alternate entry point. This also obviates the need for the special
ASM_OUTPUT_ALTERNATE_LABEL_NAME macro. (It is not currently a space
win; a CODE_LABEL rtx is still one word too big for the size-32 GC
bucket.)
Second, add the ability to generate global and weak symbol definitions
for alternate entry points. This is needed for any use of alternate
entries other than optimizing intra-compilation-unit call sequences.
For instance, C++ would like to use alternate entry points to generate
this-pointer adjustment thunks, and Fortran has a general facility for
creating multiple-entry functions. Both are useless if the alternate
entries are only visible to a single file.
I have compiled this, but I have not tested it at all - to do that I
have to write some code that _uses_ it, first. At this point I'm only
looking for criticism of the patch. Am I being too clever building a
two-bit field out of two RTL flags? Is there some non-obvious reason
why we need ASM_OUTPUT_ALTERNATE_LABEL_NAME? That sort of thing.
zw
* rtl.def (CODE_LABEL): Remove slot 8.
* rtl.h (struct rtx_def): Document new uses of jump and call fields.
(LABEL_ALTERNATE_NAME): Delete.
(LABEL_KIND, SET_LABEL_KIND, LABEL_ALT_ENTRY_P): New.
* defaults.h: Remove default for ASM_OUTPUT_ALTERNATE_LABEL_NAME.
* final.c (output_alternate_entry_point): New.
(final_scan_insn): Use it instead of
ASM_OUTPUT_ALTERNATE_LABEL_NAME. Do not consider possibility
of a case label being an alternate entry point.
* cfgbuild.c (make_edges, find_bb_boundaries): Use LABEL_ALT_ENTRY_P.
* emit-rtl.c (gen_label_rtx): Adjust call to gen_rtx_CODE_LABEL.
Do not clear LABEL_NUSES (unnecessary) or LABEL_ALTERNATE_NAME
(field deleted).
* print-rtl.c, ra-debug.c: Update code to output CODE_LABELs.
* doc/rtl.texi: Document LABEL_KIND, SET_LABEL_KIND, and
LABEL_ALT_ENTRY_P; not LABEL_ALTERNATE_NAME.
* doc/tm.texi: Delete documentation of
ASM_OUTPUT_ALTERNATE_LABEL_NAME.
===================================================================
Index: rtl.def
--- rtl.def 18 Jun 2002 16:18:12 -0000 1.57
+++ rtl.def 18 Jul 2002 00:38:34 -0000
@@ -573,10 +573,9 @@ DEF_RTL_EXPR(BARRIER, "barrier", "iuu",
4: is used in jump.c for the use-count of the label.
5: is used in flow.c to point to the chain of label_ref's to this label.
6: is a number that is unique in the entire compilation.
- 7: is the user-given name of the label, if any.
- 8: is the alternate label name. */
-DEF_RTL_EXPR(CODE_LABEL, "code_label", "iuuB00iss", 'x')
-
+ 7: is the user-given name of the label, if any. */
+DEF_RTL_EXPR(CODE_LABEL, "code_label", "iuuB00is", 'x')
+
/* Say where in the code a source line starts, for symbol table's sake.
Operand:
4: filename, if line number > 0, note-specific data otherwise.
===================================================================
Index: rtl.h
--- rtl.h 11 Jul 2002 10:32:53 -0000 1.364
+++ rtl.h 18 Jul 2002 00:38:34 -0000
@@ -130,9 +130,10 @@ struct rtx_def
/* 1 in a MEM if we should keep the alias set for this mem unchanged
when we access a component.
1 in a CALL_INSN if it is a sibling call.
- 1 in a SET that is for a return. */
+ 1 in a SET that is for a return.
+ In a CODE_LABEL, part of the two-bit alternate entry field. */
unsigned int jump : 1;
- /* This flag is currently unused. */
+ /* In a CODE_LABEL, part of the two-bit alternate entry field. */
unsigned int call : 1;
/* 1 in a REG, MEM, or CONCAT if the value is set at most once, anywhere.
1 in a SUBREG if it references an unsigned object whose mode has been
@@ -876,8 +877,55 @@ extern const char * const note_insn_name
of LABEL_REFs that point at it, so unused labels can be deleted. */
#define LABEL_NUSES(RTX) XCINT (RTX, 4, CODE_LABEL)
-/* Associate a name with a CODE_LABEL. */
-#define LABEL_ALTERNATE_NAME(RTX) XCSTR (RTX, 8, CODE_LABEL)
+/* Labels carry a two-bit field composed of the ->jump and ->call
+ bits. This field indicates whether the label is an alternate
+ entry point, and if so, what kind. */
+enum label_kind
+{
+ LABEL_NORMAL = 0, /* ordinary label */
+ LABEL_STATIC_ENTRY, /* alternate entry point, not exported */
+ LABEL_GLOBAL_ENTRY, /* alternate entry point, exported */
+ LABEL_WEAK_ENTRY /* alternate entry point, exported as weak symbol */
+};
+
+#if defined ENABLE_RTL_FLAG_CHECKING && (GCC_VERSION > 2007)
+
+/* Retrieve the kind of LABEL. */
+#define LABEL_KIND(LABEL) __extension__ \
+({ rtx const _label = (LABEL); \
+ if (GET_CODE (_label) != CODE_LABEL) \
+ rtl_check_failed_flag ("LABEL_KIND", _label, __FILE__, __LINE__, \
+ __FUNCTION__); \
+ (enum label_kind) ((_label->jump << 1) & _label->call); })
+
+/* Set the kind of LABEL. */
+#define SET_LABEL_KIND(LABEL, KIND) do { \
+ rtx _label = (LABEL); \
+ unsigned int _kind = (KIND); \
+ if (GET_CODE (_label) != CODE_LABEL) \
+ rtl_check_failed_flag ("SET_LABEL_KIND", _label, __FILE__, __LINE__, \
+ __FUNCTION__); \
+ _label->jump = ((kind >> 1) & 1); \
+ _label->call = (kind & 1); \
+} while (0)
+
+#else
+
+/* Retrieve the kind of LABEL. */
+#define LABEL_KIND(LABEL) \
+ (enum label_kind) (((LABEL)->jump << 1) & (LABEL)->call); })
+
+/* Set the kind of LABEL. */
+#define SET_LABEL_KIND(LABEL, KIND) do { \
+ rtx _label = (LABEL); \
+ unsigned int _kind = (KIND); \
+ _label->jump = ((kind >> 1) & 1); \
+ _label->call = (kind & 1); \
+} while (0)
+
+#endif /* rtl flag checking */
+
+#define LABEL_ALT_ENTRY_P(LABEL) (LABEL_KIND (LABEL) != LABEL_NORMAL)
/* The original regno this ADDRESSOF was built for. */
#define ADDRESSOF_REGNO(RTX) XCUINT (RTX, 1, ADDRESSOF)
===================================================================
Index: defaults.h
--- defaults.h 18 Jun 2002 01:35:30 -0000 1.80
+++ defaults.h 18 Jul 2002 00:38:31 -0000
@@ -80,12 +80,6 @@ do { fputs (integer_asm_op (POINTER_SIZE
} while (0)
#endif
-/* Provide default for ASM_OUTPUT_ALTERNATE_LABEL_NAME. */
-#ifndef ASM_OUTPUT_ALTERNATE_LABEL_NAME
-#define ASM_OUTPUT_ALTERNATE_LABEL_NAME(FILE,INSN) \
-do { ASM_OUTPUT_LABEL(FILE,LABEL_ALTERNATE_NAME (INSN)); } while (0)
-#endif
-
/* choose a reasonable default for ASM_OUTPUT_ASCII. */
#ifndef ASM_OUTPUT_ASCII
===================================================================
Index: cfgbuild.c
--- cfgbuild.c 12 Jun 2002 14:51:02 -0000 1.25
+++ cfgbuild.c 18 Jul 2002 00:38:30 -0000
@@ -321,7 +321,7 @@ make_edges (label_value_list, min, max,
enum rtx_code code;
int force_fallthru = 0;
- if (GET_CODE (bb->head) == CODE_LABEL && LABEL_ALTERNATE_NAME (bb->head))
+ if (GET_CODE (bb->head) == CODE_LABEL && LABEL_ALT_ENTRY_P (bb->head))
cached_make_edge (NULL, ENTRY_BLOCK_PTR, bb, 0);
/* Examine the last instruction of the block, and discover the
@@ -699,7 +699,7 @@ find_bb_boundaries (bb)
bb = fallthru->dest;
remove_edge (fallthru);
flow_transfer_insn = NULL_RTX;
- if (LABEL_ALTERNATE_NAME (insn))
+ if (LABEL_ALT_ENTRY_P (insn))
make_edge (ENTRY_BLOCK_PTR, bb, 0);
}
===================================================================
Index: emit-rtl.c
--- emit-rtl.c 11 Jul 2002 10:32:54 -0000 1.284
+++ emit-rtl.c 18 Jul 2002 00:38:32 -0000
@@ -2185,14 +2185,8 @@ widen_memory_access (memref, mode, offse
rtx
gen_label_rtx ()
{
- rtx label;
-
- label = gen_rtx_CODE_LABEL (VOIDmode, 0, NULL_RTX, NULL_RTX,
- NULL, label_num++, NULL, NULL);
-
- LABEL_NUSES (label) = 0;
- LABEL_ALTERNATE_NAME (label) = NULL;
- return label;
+ return gen_rtx_CODE_LABEL (VOIDmode, 0, NULL_RTX, NULL_RTX,
+ NULL, label_num++, NULL);
}
\f
/* For procedure integration. */
===================================================================
Index: final.c
--- final.c 17 Jun 2002 17:47:20 -0000 1.262
+++ final.c 18 Jul 2002 00:38:32 -0000
@@ -222,6 +222,7 @@ static void profile_after_prologue PARAM
static void notice_source_line PARAMS ((rtx));
static rtx walk_alter_subreg PARAMS ((rtx *));
static void output_asm_name PARAMS ((void));
+static void output_alternate_entry_point PARAMS ((FILE *, rtx));
static tree get_mem_expr_from_op PARAMS ((rtx, int *));
static void output_asm_operand_names PARAMS ((rtx *, int *, int));
static void output_operand PARAMS ((rtx, int));
@@ -1952,6 +1953,37 @@ get_insn_template (code, insn)
}
}
+/* Emit the appropriate declaration for an alternate-entry-point
+ symbol represented by INSN, to FILE. INSN is a CODE_LABEL with
+ LABEL_KIND != LABEL_NORMAL.
+
+ The case fall-through in this function is intentional. */
+static void
+output_alternate_entry_point (file, insn)
+ FILE *file;
+ rtx insn;
+{
+ const char *name = LABEL_NAME (insn);
+
+ switch (LABEL_KIND (insn))
+ {
+ case LABEL_WEAK_ENTRY:
+#ifdef ASM_WEAKEN_LABEL
+ ASM_WEAKEN_LABEL (file, name);
+#endif
+ case LABEL_GLOBAL_ENTRY:
+ ASM_GLOBALIZE_LABEL (file, name);
+ case LABEL_STATIC_ENTRY:
+ /* FIXME output a .type directive here if appropriate. */
+ ASM_OUTPUT_LABEL (file, name);
+ break;
+
+ case LABEL_NORMAL:
+ default:
+ abort ();
+ }
+}
+
/* The final scan for one insn, INSN.
Args are same as in `final', except that INSN
is the insn being scanned.
@@ -2242,17 +2274,14 @@ final_scan_insn (insn, file, optimize, p
ASM_OUTPUT_CASE_LABEL (file, "L", CODE_LABEL_NUMBER (insn),
NEXT_INSN (insn));
#else
- if (LABEL_ALTERNATE_NAME (insn))
- ASM_OUTPUT_ALTERNATE_LABEL_NAME (file, insn);
- else
- ASM_OUTPUT_INTERNAL_LABEL (file, "L", CODE_LABEL_NUMBER (insn));
+ ASM_OUTPUT_INTERNAL_LABEL (file, "L", CODE_LABEL_NUMBER (insn));
#endif
#endif
break;
}
}
- if (LABEL_ALTERNATE_NAME (insn))
- ASM_OUTPUT_ALTERNATE_LABEL_NAME (file, insn);
+ if (LABEL_ALT_ENTRY_P (insn))
+ output_alternate_entry_point (file, insn);
else
ASM_OUTPUT_INTERNAL_LABEL (file, "L", CODE_LABEL_NUMBER (insn));
break;
===================================================================
Index: print-rtl.c
--- print-rtl.c 18 Jun 2002 20:12:13 -0000 1.84
+++ print-rtl.c 18 Jul 2002 00:38:33 -0000
@@ -526,9 +526,14 @@ print_rtx (in_rtx)
case CODE_LABEL:
fprintf (outfile, " [%d uses]", LABEL_NUSES (in_rtx));
- if (LABEL_ALTERNATE_NAME (in_rtx))
- fprintf (outfile, " [alternate name: %s]",
- LABEL_ALTERNATE_NAME (in_rtx));
+ switch (LABEL_KIND (in_rtx))
+ {
+ case LABEL_NORMAL: break;
+ case LABEL_STATIC_ENTRY: fputs (" [entry]", outfile); break;
+ case LABEL_GLOBAL_ENTRY: fputs (" [global entry]", outfile); break;
+ case LABEL_WEAK_ENTRY: fputs (" [weak entry]", outfile); break;
+ default: abort();
+ }
break;
case CALL_PLACEHOLDER:
===================================================================
Index: ra-debug.c
--- ra-debug.c 15 Jul 2002 14:07:05 -0000 1.2
+++ ra-debug.c 18 Jul 2002 00:38:33 -0000
@@ -381,8 +381,14 @@ ra_print_rtx (file, x, with_pn)
fprintf (file, "L%d:\t; ", CODE_LABEL_NUMBER (x));
if (LABEL_NAME (x))
fprintf (file, "(%s) ", LABEL_NAME (x));
- if (LABEL_ALTERNATE_NAME (x))
- fprintf (file, "(alternate: %s) ", LABEL_ALTERNATE_NAME (x));
+ switch (LABEL_KIND (x))
+ {
+ case LABEL_NORMAL: break;
+ case LABEL_STATIC_ENTRY: fputs (" (entry)", file); break;
+ case LABEL_GLOBAL_ENTRY: fputs (" (global entry)", file); break;
+ case LABEL_WEAK_ENTRY: fputs (" (weak entry)", file); break;
+ default: abort();
+ }
fprintf (file, " [%d uses] uid=(", LABEL_NUSES (x));
}
fprintf (file, "%d", INSN_UID (x));
===================================================================
Index: doc/rtl.texi
--- doc/rtl.texi 14 Jun 2002 18:58:10 -0000 1.39
+++ doc/rtl.texi 18 Jul 2002 00:45:22 -0000
@@ -2830,13 +2830,32 @@ Besides as a @code{code_label}, a label
@findex LABEL_NUSES
The field @code{LABEL_NUSES} is only defined once the jump optimization
-phase is completed and contains the number of times this label is
+phase is completed. It contains the number of times this label is
referenced in the current function.
-@findex LABEL_ALTERNATE_NAME
-The field @code{LABEL_ALTERNATE_NAME} is used to associate a name with
-a @code{code_label}. If this field is defined, the alternate name will
-be emitted instead of an internally generated label name.
+@findex LABEL_KIND
+@findex SET_LABEL_KIND
+@findex LABEL_ALT_ENTRY_P
+@cindex alternate entry points
+The field @code{LABEL_KIND} differentiates four different types of
+labels: @code{LABEL_NORMAL}, @code{LABEL_STATIC_ENTRY},
+@code{LABEL_GLOBAL_ENTRY}, and @code{LABEL_WEAK_ENTRY}. The only labels
+that do not have type @code{LABEL_NORMAL} are @dfn{alternate entry
+points} to the current function. These may be static (visible only in
+the containing translation unit), global (exposed to all translation
+units), or weak (global, but can be overriden by another symbol with the
+same name).
+
+Much of the compiler treats all four kinds of label identically. Some
+of it needs to know whether or not a label is an alternate entry point;
+for this purpose, the macro @code{LABEL_ALT_ENTRY_P} is provided. It is
+equivalent to testing whether @samp{LABEL_KIND (label) == LABEL_NORMAL}.
+The only place that cares about the distinction between static, global,
+and weak alternate entry points, besides the front-end code that creates
+them, is the function @code{output_alternate_entry_point}, in
+@file{final.c}.
+
+To set the kind of a label, use the @code{SET_LABEL_KIND} macro.
@findex barrier
@item barrier
===================================================================
Index: doc/tm.texi
--- doc/tm.texi 17 Jul 2002 21:31:42 -0000 1.146
+++ doc/tm.texi 18 Jul 2002 00:38:39 -0000
@@ -6597,17 +6597,6 @@ bundles.
If this macro is not defined, then @code{ASM_OUTPUT_INTERNAL_LABEL} will be
used.
-@findex ASM_OUTPUT_ALTERNATE_LABEL_NAME
-@item ASM_OUTPUT_ALTERNATE_LABEL_NAME (@var{stream}, @var{string})
-A C statement to output to the stdio stream @var{stream} the string
-@var{string}.
-
-The default definition of this macro is as follows:
-
-@example
-fprintf (@var{stream}, "%s:\n", LABEL_ALTERNATE_NAME (INSN))
-@end example
-
@findex ASM_GENERATE_INTERNAL_LABEL
@item ASM_GENERATE_INTERNAL_LABEL (@var{string}, @var{prefix}, @var{num})
A C statement to store into the string @var{string} a label whose name
next reply other threads:[~2002-07-18 0:47 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-07-17 17:50 Zack Weinberg [this message]
2002-07-17 18:04 ` Graham Stott
2002-07-17 18:05 ` Zack Weinberg
2002-07-17 21:29 ` Matt Kraai
2002-07-17 22:44 ` Zack Weinberg
2002-07-18 12:22 ` Mark Mitchell
2002-07-18 12:44 ` Steven Bosscher
2002-07-18 13:19 ` Zack Weinberg
2002-07-18 14:11 ` Richard Henderson
2002-07-18 14:43 ` Zack Weinberg
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20020718004720.GF8656@codesourcery.com \
--to=zack@codesourcery.com \
--cc=gcc-patches@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).