This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[tuples] Inline get_gimple_rhs_class
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Diego Novillo <dnovillo at google dot com>, Aldy Hernandez <aldyh at redhat dot com>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Wed, 9 Jul 2008 06:08:26 -0400
- Subject: [tuples] Inline get_gimple_rhs_class
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
Hi!
This patch precomputes get_gimple_rhs_class into a table
and inlines it. It makes cc1 smaller (both .text and .rodata
sections, in case of .rodata we trade a switch table with
104 * host_word_size bytes for 280 bytes long array) and tiny bit
faster on insn-attrtab.i. The drawback is that the
macro is tiny bit harder to adjust than the function, but
as get_gimple_rhs_class is very common operation, I think it
is worth it. The non-inline get_gimple_rhs_class needed
always at least one memory read (TREE_CODE_CLASS), some arithmetics
and conditional jumps and if it wasn't one of the 6 classes,
another memory read and unpredictable switch table jump.
Ok for tuples?
2008-07-09 Jakub Jelinek <jakub@redhat.com>
* gimple.h (gimple_rhs_class_table): New extern decl.
(get_gimple_rhs_class): Change into inline.
* gimple.c (get_gimple_rhs_class): Removed.
(gimple_rhs_class_table): New variable.
--- gcc/gimple.h.jj 2008-07-09 09:02:10.000000000 +0200
+++ gcc/gimple.h 2008-07-09 09:43:23.000000000 +0200
@@ -47,6 +47,7 @@ enum gimple_code {
};
extern const char *const gimple_code_name[];
+extern const unsigned char gimple_rhs_class_table[];
/* Error out if a gimple tuple is addressed incorrectly. */
#if defined ENABLE_GIMPLE_CHECKING
@@ -842,7 +843,6 @@ bool gimple_could_trap_p (gimple);
bool gimple_assign_rhs_could_trap_p (gimple);
void gimple_regimplify_operands (gimple, gimple_stmt_iterator *);
bool empty_body_p (gimple_seq);
-enum gimple_rhs_class get_gimple_rhs_class (enum tree_code);
unsigned get_gimple_rhs_num_ops (enum tree_code);
/* FIXME tuples.
@@ -1499,6 +1499,15 @@ is_gimple_assign (const_gimple gs)
return gimple_code (gs) == GIMPLE_ASSIGN;
}
+/* Determine if expression CODE is one of the valid expressions that can
+ be used on the RHS of GIMPLE assignments. */
+
+static inline enum gimple_rhs_class
+get_gimple_rhs_class (enum tree_code code)
+{
+ return (enum gimple_rhs_class) gimple_rhs_class_table[(int) code];
+}
+
/* Return the LHS of assignment statement GS. */
static inline tree
--- gcc/gimple.c.jj 2008-07-09 09:30:40.000000000 +0200
+++ gcc/gimple.c 2008-07-09 09:41:42.000000000 +0200
@@ -2525,59 +2525,6 @@ gimple_set_loaded_syms (gimple stmt, bit
}
}
-/* Determine if expression T is one of the valid expressions that can
- be used on the RHS of GIMPLE assignments. */
-
-enum gimple_rhs_class
-get_gimple_rhs_class (enum tree_code code)
-{
- switch (TREE_CODE_CLASS (code))
- {
- case tcc_unary:
- return GIMPLE_UNARY_RHS;
-
- case tcc_binary:
- case tcc_comparison:
- return GIMPLE_BINARY_RHS;
-
- case tcc_constant:
- case tcc_declaration:
- case tcc_reference:
- return GIMPLE_SINGLE_RHS;
-
- default:
- break;
- }
-
- switch (code)
- {
- case TRUTH_AND_EXPR:
- case TRUTH_OR_EXPR:
- case TRUTH_XOR_EXPR:
- return GIMPLE_BINARY_RHS;
-
- case TRUTH_NOT_EXPR:
- return GIMPLE_UNARY_RHS;
-
- case COND_EXPR:
- case CONSTRUCTOR:
- case OBJ_TYPE_REF:
- case ASSERT_EXPR:
- case ADDR_EXPR:
- case WITH_SIZE_EXPR:
- case EXC_PTR_EXPR:
- case SSA_NAME:
- case FILTER_EXPR:
- case POLYNOMIAL_CHREC:
- return GIMPLE_SINGLE_RHS;
-
- default:
- break;
- }
-
- return GIMPLE_INVALID_RHS;
-}
-
/* Return the number of operands needed on the RHS of a GIMPLE
assignment for an expression with tree code CODE. */
@@ -2595,4 +2542,36 @@ get_gimple_rhs_num_ops (enum tree_code c
gcc_unreachable ();
}
+#define DEFTREECODE(SYM, STRING, TYPE, NARGS) \
+ (unsigned char) \
+ ((TYPE) == tcc_unary ? GIMPLE_UNARY_RHS \
+ : ((TYPE) == tcc_binary \
+ || (TYPE) == tcc_comparison) ? GIMPLE_BINARY_RHS \
+ : ((TYPE) == tcc_constant \
+ || (TYPE) == tcc_declaration \
+ || (TYPE) == tcc_reference) ? GIMPLE_SINGLE_RHS \
+ : ((SYM) == TRUTH_AND_EXPR \
+ || (SYM) == TRUTH_OR_EXPR \
+ || (SYM) == TRUTH_XOR_EXPR) ? GIMPLE_BINARY_RHS \
+ : (SYM) == TRUTH_NOT_EXPR ? GIMPLE_UNARY_RHS \
+ : ((SYM) == COND_EXPR \
+ || (SYM) == CONSTRUCTOR \
+ || (SYM) == OBJ_TYPE_REF \
+ || (SYM) == ASSERT_EXPR \
+ || (SYM) == ADDR_EXPR \
+ || (SYM) == WITH_SIZE_EXPR \
+ || (SYM) == EXC_PTR_EXPR \
+ || (SYM) == SSA_NAME \
+ || (SYM) == FILTER_EXPR \
+ || (SYM) == POLYNOMIAL_CHREC) ? GIMPLE_SINGLE_RHS \
+ : GIMPLE_INVALID_RHS),
+#define END_OF_BASE_TREE_CODES (unsigned char) GIMPLE_INVALID_RHS,
+
+const unsigned char gimple_rhs_class_table[] = {
+#include "all-tree.def"
+};
+
+#undef DEFTREECODE
+#undef END_OF_BASE_TREE_CODES
+
#include "gt-gimple.h"
Jakub