@@ -8925,6 +8925,8 @@ handle_optimize_attribute (tree *node, tree name, tree args,
DECL_FUNCTION_SPECIFIC_OPTIMIZATION (*node)
= build_optimization_node ();
+ save_optabs_if_changed (DECL_FUNCTION_SPECIFIC_OPTIMIZATION (*node));
+
/* Restore current options. */
cl_optimization_restore (&global_options, &cur_opts);
}
@@ -4397,6 +4397,13 @@ invoke_set_current_function_hook (tree fndecl)
{
optimization_current_node = opts;
cl_optimization_restore (&global_options, TREE_OPTIMIZATION (opts));
+
+ /* Change optabs if needed. */
+ if (TREE_OPTIMIZATION_OPTABS (opts))
+ this_target_optabs
+ = (struct target_optabs *) TREE_OPTIMIZATION_OPTABS (opts);
+ else
+ this_target_optabs = &default_target_optabs;
}
targetm.set_current_function (fndecl);
@@ -44,8 +44,8 @@ along with GCC; see the file COPYING3. If not see
struct target_optabs default_target_optabs;
struct target_libfuncs default_target_libfuncs;
-#if SWITCHABLE_TARGET
struct target_optabs *this_target_optabs = &default_target_optabs;
+#if SWITCHABLE_TARGET
struct target_libfuncs *this_target_libfuncs = &default_target_libfuncs;
#endif
@@ -6207,6 +6207,40 @@ init_optabs (void)
targetm.init_libfuncs ();
}
+/* Recompute the optabs. If they have changed, save the new set of
+ optabs in the optimization node OPTNODE. */
+
+void
+save_optabs_if_changed (tree optnode)
+{
+ struct target_optabs *save_target_optabs = this_target_optabs;
+ struct target_optabs *tmp_target_optabs = XCNEW (struct target_optabs);
+
+ /* Generate a new set of optabs into tmp_target_optabs. */
+ this_target_optabs = tmp_target_optabs;
+ init_all_optabs ();
+ this_target_optabs = save_target_optabs;
+
+ /* If the optabs changed, record it in the node. */
+ if (memcmp (tmp_target_optabs, &default_target_optabs,
+ sizeof (struct target_optabs)))
+ {
+ /* ?? An existing entry in TREE_OPTIMIZATION_OPTABS indicates
+ multiple ((optimize)) attributes for the same function. Is
+ this even valid? For now, just clobber the existing entry
+ with the new optabs. */
+ if (TREE_OPTIMIZATION_OPTABS (optnode))
+ XDELETE (TREE_OPTIMIZATION_OPTABS (optnode));
+
+ TREE_OPTIMIZATION_OPTABS (optnode) = tmp_target_optabs;
+ }
+ else
+ {
+ TREE_OPTIMIZATION_OPTABS (optnode) = NULL;
+ XDELETE (tmp_target_optabs);
+ }
+}
+
/* A helper function for init_sync_libfuncs. Using the basename BASE,
install libfuncs into TAB for BASE_N for 1 <= N <= MAX. */
@@ -76,11 +76,7 @@ struct target_optabs {
};
extern struct target_optabs default_target_optabs;
-#if SWITCHABLE_TARGET
extern struct target_optabs *this_target_optabs;
-#else
-#define this_target_optabs (&default_target_optabs)
-#endif
/* Define functions given in optabs.c. */
new file mode 100644
@@ -0,0 +1,10 @@
+/* { dg-options "-ffast-math" } */
+
+float farg;
+unsigned val;
+
+void __attribute__((optimize("O")))
+test()
+{
+ val = __builtin_ceilf(farg);
+}
@@ -3586,14 +3586,25 @@ struct GTY(()) tree_optimization_option {
/* The optimization options used by the user. */
struct cl_optimization opts;
+
+ /* Target optabs for this set of optimization options. This is of
+ type `struct target_optabs *'. */
+ void *GTY ((skip)) target_optabs;
};
#define TREE_OPTIMIZATION(NODE) \
(&OPTIMIZATION_NODE_CHECK (NODE)->optimization.opts)
+#define TREE_OPTIMIZATION_OPTABS(NODE) \
+ (OPTIMIZATION_NODE_CHECK (NODE)->optimization.target_optabs)
+
/* Return a tree node that encapsulates the current optimization options. */
extern tree build_optimization_node (void);
+/* Save a new set of target_optabs in a TREE_OPTIMIZATION node if the
+ current set of optabs has changed. */
+extern void save_optabs_if_changed (tree);
+
/* Target options used by a function. */
struct GTY(()) tree_target_option {