* [patch] Tidy up global_bindings_p langhook
@ 2011-05-07 13:47 Eric Botcazou
2011-05-07 18:02 ` Richard Guenther
0 siblings, 1 reply; 2+ messages in thread
From: Eric Botcazou @ 2011-05-07 13:47 UTC (permalink / raw)
To: gcc-patches
[-- Attachment #1: Type: text/plain, Size: 1415 bytes --]
Hi,
following the removal of pending sizes and the simplification of variable_size
this patch changes the return type of the global_bindings_p langhook to bool
and eliminates 3 calls (out of 4) present in fold-const.c; removing the 4th
will require further investigation.
Bootstrapped/regtested (all languages) on x86_64-suse-linux, OK for mainline?
2011-05-07 Eric Botcazou <ebotcazou@adacore.com>
* langhooks.h (lang_hooks_for_types): Change global_bindings_p's return
type to bool and adjust comment.
* fold-const.c (fold_range_test): Adjust call to global_bindings_p.
(fold_mathfn_compare): Remove calls to global_bindings_p.
(fold_inf_compare): Likewise.
* stor-layout.c (variable_size): Adjust call to global_bindings_p.
* c-tree.h (global_bindings_p): Adjust prototype.
* c-decl.c (global_bindings_p): Return bool and simplify.
ada/
* gcc-interface/gigi.h (global_bindings_p): Adjust prototype.
* gcc-interface/utils.c (global_bindings_p): Return bool and simplify.
cp/
* name-lookup.h (global_bindings_p): Adjust prototype.
* name-lookup.c (global_bindings_p): Return bool.
fortran/
* f95-lang.c (global_bindings_p): Return bool and simplify.
go/
* go-lang.c (global_bindings_p): Return bool and simplify.
java/
* java-tree.h (global_bindings_p): Adjust prototype.
* decl.c (global_bindings_p): Return bool.
lto/
* lto-lang.c (global_bindings_p): Return bool.
--
Eric Botcazou
[-- Attachment #2: p.diff --]
[-- Type: text/x-diff, Size: 9991 bytes --]
Index: java/decl.c
===================================================================
--- java/decl.c (revision 173422)
+++ java/decl.c (working copy)
@@ -1302,9 +1302,9 @@ pushdecl_function_level (tree x)
return t;
}
-/* Nonzero if we are currently in the global binding level. */
+/* Return true if we are in the global binding level. */
-int
+bool
global_bindings_p (void)
{
return current_binding_level == global_binding_level;
Index: java/java-tree.h
===================================================================
--- java/java-tree.h (revision 173422)
+++ java/java-tree.h (working copy)
@@ -983,7 +983,7 @@ extern tree ident_subst (const char *, i
const char *);
extern tree identifier_subst (const tree, const char *, int, int,
const char *);
-extern int global_bindings_p (void);
+extern bool global_bindings_p (void);
extern tree getdecls (void);
extern void pushlevel (int);
extern tree poplevel (int,int, int);
Index: fold-const.c
===================================================================
--- fold-const.c (revision 173422)
+++ fold-const.c (working copy)
@@ -4849,8 +4849,8 @@ fold_range_test (location_t loc, enum tr
? TRUTH_AND_EXPR : TRUTH_OR_EXPR,
type, op0, op1);
- else if (lang_hooks.decls.global_bindings_p () == 0
- && ! CONTAINS_PLACEHOLDER_P (lhs))
+ else if (!lang_hooks.decls.global_bindings_p ()
+ && !CONTAINS_PLACEHOLDER_P (lhs))
{
tree common = save_expr (lhs);
@@ -6148,10 +6148,6 @@ fold_mathfn_compare (location_t loc,
build_real (TREE_TYPE (arg), dconst0));
/* sqrt(x) < y is x >= 0 && x != +Inf, when y is large. */
- if (lang_hooks.decls.global_bindings_p () != 0
- || CONTAINS_PLACEHOLDER_P (arg))
- return NULL_TREE;
-
arg = save_expr (arg);
return fold_build2_loc (loc, TRUTH_ANDIF_EXPR, type,
fold_build2_loc (loc, GE_EXPR, type, arg,
@@ -6168,18 +6164,14 @@ fold_mathfn_compare (location_t loc,
build_real (TREE_TYPE (arg), c2));
/* sqrt(x) < c is the same as x >= 0 && x < c*c. */
- if (lang_hooks.decls.global_bindings_p () == 0
- && ! CONTAINS_PLACEHOLDER_P (arg))
- {
- arg = save_expr (arg);
- return fold_build2_loc (loc, TRUTH_ANDIF_EXPR, type,
+ arg = save_expr (arg);
+ return fold_build2_loc (loc, TRUTH_ANDIF_EXPR, type,
fold_build2_loc (loc, GE_EXPR, type, arg,
build_real (TREE_TYPE (arg),
dconst0)),
fold_build2_loc (loc, code, type, arg,
build_real (TREE_TYPE (arg),
c2)));
- }
}
}
@@ -6226,13 +6218,8 @@ fold_inf_compare (location_t loc, enum t
return omit_one_operand_loc (loc, type, integer_one_node, arg0);
/* x <= +Inf is the same as x == x, i.e. isfinite(x). */
- if (lang_hooks.decls.global_bindings_p () == 0
- && ! CONTAINS_PLACEHOLDER_P (arg0))
- {
- arg0 = save_expr (arg0);
- return fold_build2_loc (loc, EQ_EXPR, type, arg0, arg0);
- }
- break;
+ arg0 = save_expr (arg0);
+ return fold_build2_loc (loc, EQ_EXPR, type, arg0, arg0);
case EQ_EXPR:
case GE_EXPR:
Index: cp/name-lookup.c
===================================================================
--- cp/name-lookup.c (revision 173422)
+++ cp/name-lookup.c (working copy)
@@ -1576,9 +1576,9 @@ maybe_push_cleanup_level (tree type)
}
}
-/* Nonzero if we are currently in the global binding level. */
+/* Return true if we are in the global binding level. */
-int
+bool
global_bindings_p (void)
{
return global_scope_p (current_binding_level);
Index: cp/name-lookup.h
===================================================================
--- cp/name-lookup.h (revision 173422)
+++ cp/name-lookup.h (working copy)
@@ -290,7 +290,7 @@ extern GTY(()) tree global_type_node;
extern cxx_scope *leave_scope (void);
extern bool kept_level_p (void);
-extern int global_bindings_p (void);
+extern bool global_bindings_p (void);
extern bool toplevel_bindings_p (void);
extern bool namespace_bindings_p (void);
extern bool template_parm_scope_p (void);
Index: c-tree.h
===================================================================
--- c-tree.h (revision 173422)
+++ c-tree.h (working copy)
@@ -413,7 +413,7 @@ extern struct obstack parser_obstack;
extern tree c_break_label;
extern tree c_cont_label;
-extern int global_bindings_p (void);
+extern bool global_bindings_p (void);
extern void push_scope (void);
extern tree pop_scope (void);
extern void c_bindings_start_stmt_expr (struct c_spot_bindings *);
Index: go/go-lang.c
===================================================================
--- go/go-lang.c (revision 173422)
+++ go/go-lang.c (working copy)
@@ -308,10 +308,12 @@ go_langhook_builtin_function (tree decl)
return decl;
}
-static int
+/* Return true if we are in the global binding level. */
+
+static bool
go_langhook_global_bindings_p (void)
{
- return current_function_decl == NULL ? 1 : 0;
+ return current_function_decl == NULL;
}
/* Push a declaration into the current binding level. We can't
Index: ada/gcc-interface/utils.c
===================================================================
--- ada/gcc-interface/utils.c (revision 173424)
+++ ada/gcc-interface/utils.c (working copy)
@@ -365,12 +365,12 @@ build_dummy_unc_pointer_types (Entity_Id
TYPE_OBJECT_RECORD_TYPE (gnu_desig_type) = gnu_object_type;
}
\f
-/* Return nonzero if we are currently in the global binding level. */
+/* Return true if we are in the global binding level. */
-int
+bool
global_bindings_p (void)
{
- return ((force_global || !current_function_decl) ? -1 : 0);
+ return force_global || current_function_decl == NULL;
}
/* Enter a new binding level. */
Index: ada/gcc-interface/gigi.h
===================================================================
--- ada/gcc-interface/gigi.h (revision 173442)
+++ ada/gcc-interface/gigi.h (working copy)
@@ -422,8 +422,8 @@ extern GTY(()) tree gnat_raise_decls_ext
/* Routines expected by the gcc back-end. They must have exactly the same
prototype and names as below. */
-/* Returns nonzero if we are currently in the global binding level. */
-extern int global_bindings_p (void);
+/* Return true if we are in the global binding level. */
+extern bool global_bindings_p (void);
/* Enter and exit a new binding level. */
extern void gnat_pushlevel (void);
Index: c-decl.c
===================================================================
--- c-decl.c (revision 173424)
+++ c-decl.c (working copy)
@@ -845,14 +845,12 @@ objc_mark_locals_volatile (void *enclosi
}
}
-/* Nonzero if we are currently in file scope. */
+/* Return true if we are in the global binding level. */
-int
+bool
global_bindings_p (void)
{
- return (current_scope == file_scope && !c_override_global_bindings_to_false
- ? -1
- : 0);
+ return current_scope == file_scope && !c_override_global_bindings_to_false;
}
void
Index: fortran/f95-lang.c
===================================================================
--- fortran/f95-lang.c (revision 173422)
+++ fortran/f95-lang.c (working copy)
@@ -91,7 +91,7 @@ static void gfc_finish (void);
static void gfc_write_global_declarations (void);
static void gfc_print_identifier (FILE *, tree, int);
void do_function_end (void);
-int global_bindings_p (void);
+bool global_bindings_p (void);
static void clear_binding_stack (void);
static void gfc_be_parse_file (void);
static alias_set_type gfc_get_alias_set (tree);
@@ -373,12 +373,12 @@ static GTY(()) struct binding_level *glo
static struct binding_level clear_binding_level = { NULL, NULL, NULL };
-/* Return nonzero if we are currently in the global binding level. */
+/* Return true if we are in the global binding level. */
-int
+bool
global_bindings_p (void)
{
- return current_binding_level == global_binding_level ? -1 : 0;
+ return current_binding_level == global_binding_level;
}
tree
Index: langhooks.h
===================================================================
--- langhooks.h (revision 173422)
+++ langhooks.h (working copy)
@@ -148,9 +148,10 @@ struct lang_hooks_for_types
struct lang_hooks_for_decls
{
- /* Returns nonzero if we are in the global binding level. Ada
- returns -1 for an undocumented reason used in stor-layout.c. */
- int (*global_bindings_p) (void);
+ /* Return true if we are in the global binding level. This hook is really
+ needed only if the language supports variable-sized types at the global
+ level, i.e. declared outside subprograms. */
+ bool (*global_bindings_p) (void);
/* Function to add a decl to the current scope level. Takes one
argument, a decl to add. Returns that decl, or, if the same
Index: stor-layout.c
===================================================================
--- stor-layout.c (revision 173424)
+++ stor-layout.c (working copy)
@@ -89,10 +89,10 @@ variable_size (tree size)
if (CONTAINS_PLACEHOLDER_P (size))
return self_referential_size (size);
- /* If the language-processor is to take responsibility for variable-sized
- items (e.g., languages which have elaboration procedures like Ada),
- just return SIZE unchanged. */
- if (lang_hooks.decls.global_bindings_p () < 0)
+ /* If we are in the global binding level, we can't make a SAVE_EXPR
+ since it may end up being shared across functions, so it is up
+ to the front-end to deal with this case. */
+ if (lang_hooks.decls.global_bindings_p ())
return size;
return save_expr (size);
Index: lto/lto-lang.c
===================================================================
--- lto/lto-lang.c (revision 173422)
+++ lto/lto-lang.c (working copy)
@@ -938,8 +938,10 @@ lto_type_for_mode (enum machine_mode mod
return NULL_TREE;
}
-static int
-lto_global_bindings_p (void)
+/* Return true if we are in the global binding level. */
+
+static bool
+lto_global_bindings_p (void)
{
return cfun == NULL;
}
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [patch] Tidy up global_bindings_p langhook
2011-05-07 13:47 [patch] Tidy up global_bindings_p langhook Eric Botcazou
@ 2011-05-07 18:02 ` Richard Guenther
0 siblings, 0 replies; 2+ messages in thread
From: Richard Guenther @ 2011-05-07 18:02 UTC (permalink / raw)
To: Eric Botcazou; +Cc: gcc-patches
On Sat, May 7, 2011 at 3:30 PM, Eric Botcazou <ebotcazou@adacore.com> wrote:
> Hi,
>
> following the removal of pending sizes and the simplification of variable_size
> this patch changes the return type of the global_bindings_p langhook to bool
> and eliminates 3 calls (out of 4) present in fold-const.c; removing the 4th
> will require further investigation.
>
> Bootstrapped/regtested (all languages) on x86_64-suse-linux, OK for mainline?
The middle-end changes are ok. I suppose the frontend changes are obvious.
Thanks,
Richard.
>
> 2011-05-07 Eric Botcazou <ebotcazou@adacore.com>
>
> * langhooks.h (lang_hooks_for_types): Change global_bindings_p's return
> type to bool and adjust comment.
> * fold-const.c (fold_range_test): Adjust call to global_bindings_p.
> (fold_mathfn_compare): Remove calls to global_bindings_p.
> (fold_inf_compare): Likewise.
> * stor-layout.c (variable_size): Adjust call to global_bindings_p.
> * c-tree.h (global_bindings_p): Adjust prototype.
> * c-decl.c (global_bindings_p): Return bool and simplify.
> ada/
> * gcc-interface/gigi.h (global_bindings_p): Adjust prototype.
> * gcc-interface/utils.c (global_bindings_p): Return bool and simplify.
> cp/
> * name-lookup.h (global_bindings_p): Adjust prototype.
> * name-lookup.c (global_bindings_p): Return bool.
> fortran/
> * f95-lang.c (global_bindings_p): Return bool and simplify.
> go/
> * go-lang.c (global_bindings_p): Return bool and simplify.
> java/
> * java-tree.h (global_bindings_p): Adjust prototype.
> * decl.c (global_bindings_p): Return bool.
> lto/
> * lto-lang.c (global_bindings_p): Return bool.
>
>
> --
> Eric Botcazou
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2011-05-07 18:00 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-05-07 13:47 [patch] Tidy up global_bindings_p langhook Eric Botcazou
2011-05-07 18:02 ` Richard Guenther
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).