+2015-11-17 Richard Sandiford <richard.sandiford@arm.com>
+
+ * tree-core.h (internal_fn): Move immediately after the definition
+ of built_in_function.
+ (combined_fn): New enum.
+ * tree.h (as_combined_fn, builtin_fn_p, as_builtin_fn)
+ (internal_fn_p, as_internal_fn): New functions.
+ (get_call_combined_fn, combined_fn_name): Declare.
+ * tree.c (get_call_combined_fn): New function.
+ (combined_fn_name): Likewise.
+ * gimple.h (gimple_call_combined_fn): Declare.
+ * gimple.c (gimple_call_combined_fn): New function.
+
2015-11-17 Martin Sebor <msebor@redhat.com>
PR c++/68308
return false;
}
+/* If CALL is a call to a combined_fn (i.e. an internal function or
+ a normal built-in function), return its code, otherwise return
+ CFN_LAST. */
+
+combined_fn
+gimple_call_combined_fn (const gimple *stmt)
+{
+ if (const gcall *call = dyn_cast <const gcall *> (stmt))
+ {
+ if (gimple_call_internal_p (call))
+ return as_combined_fn (gimple_call_internal_fn (call));
+
+ tree fndecl = gimple_call_fndecl (stmt);
+ if (fndecl
+ && DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL
+ && gimple_builtin_call_types_compatible_p (stmt, fndecl))
+ return as_combined_fn (DECL_FUNCTION_CODE (fndecl));
+ }
+ return CFN_LAST;
+}
+
/* Return true if STMT clobbers memory. STMT is required to be a
GIMPLE_ASM. */
extern alias_set_type gimple_get_alias_set (tree);
extern bool gimple_ior_addresses_taken (bitmap, gimple *);
extern bool gimple_builtin_call_types_compatible_p (const gimple *, tree);
+extern combined_fn gimple_call_combined_fn (const gimple *);
extern bool gimple_call_builtin_p (const gimple *);
extern bool gimple_call_builtin_p (const gimple *, enum built_in_class);
extern bool gimple_call_builtin_p (const gimple *, enum built_in_function);
END_BUILTINS
};
+/* Internal functions. */
+enum internal_fn {
+#define DEF_INTERNAL_FN(CODE, FLAGS, FNSPEC) IFN_##CODE,
+#include "internal-fn.def"
+ IFN_LAST
+};
+
+/* An enum that combines target-independent built-in functions with
+ internal functions, so that they can be treated in a similar way.
+ The numbers for built-in functions are the same as for the
+ built_in_function enum. The numbers for internal functions
+ start at END_BUITLINS. */
+enum combined_fn {
+#define DEF_BUILTIN(ENUM, N, C, T, LT, B, F, NA, AT, IM, COND) \
+ CFN_##ENUM = int (ENUM),
+#include "builtins.def"
+
+#define DEF_BUILTIN(ENUM, N, C, T, LT, B, F, NA, AT, IM, COND)
+#define DEF_BUILTIN_CHKP(ENUM, N, C, T, LT, B, F, NA, AT, IM, COND) \
+ CFN_##ENUM##_CHKP = int (ENUM##_CHKP),
+#include "builtins.def"
+
+#define DEF_INTERNAL_FN(CODE, FLAGS, FNSPEC) \
+ CFN_##CODE = int (END_BUILTINS) + int (IFN_##CODE),
+#include "internal-fn.def"
+
+ CFN_LAST
+};
+
/* Tree code classes. Each tree_code has an associated code class
represented by a TREE_CODE_CLASS. */
enum tree_code_class {
annot_expr_kind_last
};
-/* Internal functions. */
-enum internal_fn {
-#define DEF_INTERNAL_FN(CODE, FLAGS, FNSPEC) IFN_##CODE,
-#include "internal-fn.def"
- IFN_LAST
-};
-
/*---------------------------------------------------------------------------
Type definitions
---------------------------------------------------------------------------*/
return NULL_TREE;
}
+/* If CALL_EXPR CALL calls a normal built-in function or an internal function,
+ return the associated function code, otherwise return CFN_LAST. */
+
+combined_fn
+get_call_combined_fn (const_tree call)
+{
+ /* It's invalid to call this function with anything but a CALL_EXPR. */
+ gcc_assert (TREE_CODE (call) == CALL_EXPR);
+
+ if (!CALL_EXPR_FN (call))
+ return as_combined_fn (CALL_EXPR_IFN (call));
+
+ tree fndecl = get_callee_fndecl (call);
+ if (fndecl && DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL)
+ return as_combined_fn (DECL_FUNCTION_CODE (fndecl));
+
+ return CFN_LAST;
+}
+
#define TREE_MEM_USAGE_SPACES 40
/* Print debugging information about tree nodes generated during the compile,
SET_EXPR_LOCATION (expr, adhoc);
}
+/* Return the name of combined function FN, for debugging purposes. */
+
+const char *
+combined_fn_name (combined_fn fn)
+{
+ if (builtin_fn_p (fn))
+ {
+ tree fndecl = builtin_decl_explicit (as_builtin_fn (fn));
+ return IDENTIFIER_POINTER (DECL_NAME (fndecl));
+ }
+ else
+ return internal_fn_name (as_internal_fn (fn));
+}
+
#include "gt-tree.h"
#include "tree-core.h"
+/* Convert a target-independent built-in function code to a combined_fn. */
+
+inline combined_fn
+as_combined_fn (built_in_function fn)
+{
+ return combined_fn (int (fn));
+}
+
+/* Convert an internal function code to a combined_fn. */
+
+inline combined_fn
+as_combined_fn (internal_fn fn)
+{
+ return combined_fn (int (fn) + int (END_BUILTINS));
+}
+
+/* Return true if CODE is a target-independent built-in function. */
+
+inline bool
+builtin_fn_p (combined_fn code)
+{
+ return int (code) < int (END_BUILTINS);
+}
+
+/* Return the target-independent built-in function represented by CODE.
+ Only valid if builtin_fn_p (CODE). */
+
+inline built_in_function
+as_builtin_fn (combined_fn code)
+{
+ gcc_checking_assert (builtin_fn_p (code));
+ return built_in_function (int (code));
+}
+
+/* Return true if CODE is an internal function. */
+
+inline bool
+internal_fn_p (combined_fn code)
+{
+ return int (code) >= int (END_BUILTINS);
+}
+
+/* Return the internal function represented by CODE. Only valid if
+ internal_fn_p (CODE). */
+
+inline internal_fn
+as_internal_fn (combined_fn code)
+{
+ gcc_checking_assert (internal_fn_p (code));
+ return internal_fn (int (code) - int (END_BUILTINS));
+}
+
/* Macros for initializing `tree_contains_struct'. */
#define MARK_TS_BASE(C) \
do { \
extern void clean_symbol_name (char *);
extern tree get_file_function_name (const char *);
extern tree get_callee_fndecl (const_tree);
+extern combined_fn get_call_combined_fn (const_tree);
extern int type_num_arguments (const_tree);
extern bool associative_tree_code (enum tree_code);
extern bool commutative_tree_code (enum tree_code);
extern void assign_assembler_name_if_neeeded (tree);
extern void warn_deprecated_use (tree, tree);
extern void cache_integer_cst (tree);
+extern const char *combined_fn_name (combined_fn);
/* Return the memory model from a host integer. */
static inline enum memmodel