diff options
author | Jan Hubicka <jh@suse.cz> | 2000-04-13 13:59:00 +0000 |
---|---|---|
committer | Jan Hubicka <hubicka@gcc.gnu.org> | 2000-04-13 13:59:00 +0000 |
commit | 2a8f6b90c17bc2eb63bb218e7b11b6c6178c9d70 (patch) | |
tree | d0cc1485f0444d16267f642aaa62f86e34308a1e /gcc/extend.texi | |
parent | c966901c242442c6ca4d34c8cdc85f5dfd3dbdd3 (diff) | |
download | gcc-2a8f6b90c17bc2eb63bb218e7b11b6c6178c9d70.zip gcc-2a8f6b90c17bc2eb63bb218e7b11b6c6178c9d70.tar.gz gcc-2a8f6b90c17bc2eb63bb218e7b11b6c6178c9d70.tar.bz2 |
alias.c (nonlocal_reference_p): Take a care for CALL_INSNS's fusage field.
* alias.c (nonlocal_reference_p): Take a care for
CALL_INSNS's fusage field.
* calls.c (ECF_PURE): New flag.
(emit_call_1): Handle ECF_PURE calls.
(initialize_argument_information): Unset ECF_PURE flag too.
(precompute_arguments): Precompute for ECF_PURE too.
(expand_call): Handle ECF_PURE calls too.
(emit_library_call_value_1): Rename no_queue argument to
fn_type, accept value of 2 as pure function.
(emit_library_call_value, emit_library_call): Rename no_queue argument
to fn_type.
* optabs.c (prepare_cmp_insn): Pass fn_type 2 to memcmp call.
* tree.h (DECL_IS_PURE): New macro.
(struct tree_decl): Add pure_flag.
* c-common.c (enum attrs): Add attribute "pure".
(init_attributes): Initialize attribute "pure"
(decl_attributes): Handle attribute "pure".
* extend.texi (Attribute "pure"): Document.
* calls.c (expand_call): Add (mem:BLK (scratch)) to "equal from"
in pure function.
(flags_from_decl_or_type): Support attribute "pure".
From-SVN: r33138
Diffstat (limited to 'gcc/extend.texi')
-rw-r--r-- | gcc/extend.texi | 40 |
1 files changed, 28 insertions, 12 deletions
diff --git a/gcc/extend.texi b/gcc/extend.texi index 4cce201..22fe741 100644 --- a/gcc/extend.texi +++ b/gcc/extend.texi @@ -1379,22 +1379,44 @@ typedef void voidfn (); volatile voidfn fatal; @end smallexample -@cindex @code{const} function attribute -@item const -Many functions do not examine any values except their arguments, and -have no effects except the return value. Such a function can be subject +@cindex @code{pure} function attribute +@item pure +Many functions have no effects except the return value and their +return value and depends only on the parameters and/or global variables. +Such a function can be subject to common subexpression elimination and loop optimization just as an arithmetic operator would be. These functions should be declared -with the attribute @code{const}. For example, +with the attribute @code{pure}. For example, @smallexample -int square (int) __attribute__ ((const)); +int square (int) __attribute__ ((pure)); @end smallexample @noindent says that the hypothetical function @code{square} is safe to call fewer times than the program says. +Some of common examples of pure functions are @code{strlen} or @code{memcmp}. +Interesting non-pure functions are functions with infinite loops or those +depending on volatile memory or other system resource, that may change between +two consetuctive calls (such as @code{feof} in multithreding environment). + +The attribute @code{pure} is not implemented in GNU C versions earlier +than 2.96. +@cindex @code{const} function attribute +@item const +Many functions do not examine any values except their arguments, and +have no effects except the return value. Basically this is just slightly +more strict class than the "pure" attribute above, since function is not +alloved to read global memory. + +@cindex pointer arguments +Note that a function that has pointer arguments and examines the data +pointed to must @emph{not} be declared @code{const}. Likewise, a +function that calls a non-@code{const} function usually must not be +@code{const}. It does not make sense for a @code{const} function to +return @code{void}. + The attribute @code{const} is not implemented in GNU C versions earlier than 2.5. An alternative way to declare that a function has no side effects, which works in the current version and in some older versions, @@ -1409,12 +1431,6 @@ extern const intfn square; This approach does not work in GNU C++ from 2.6.0 on, since the language specifies that the @samp{const} must be attached to the return value. -@cindex pointer arguments -Note that a function that has pointer arguments and examines the data -pointed to must @emph{not} be declared @code{const}. Likewise, a -function that calls a non-@code{const} function usually must not be -@code{const}. It does not make sense for a @code{const} function to -return @code{void}. @item format (@var{archetype}, @var{string-index}, @var{first-to-check}) @cindex @code{format} function attribute |