[PATCH - h8300] function_vector attribute in H8300 targets
Asgari J. Jinia
AsgariJ@KPITCummins.com
Mon Sep 20 14:06:00 GMT 2004
Hi,
As per the document at
http://gcc.gnu.org/onlinedocs/gcc-3.4.1/gcc/Function-Attributes.html#Function%20Attributes
calling a function with function_vector attribute for H8300H,
H8S targets should use lesser number of bytes than normal call. That means it
should be using memory indirect call using jsr @@aa:8 instruction. But following test
case doesn't generate such instruction.
Command line: h8300-elf-gcc test.c -mh -S
/* test.c */
void foo (void) __attribute__ ((function_vector));
void foo (void)
{
}
void bar (void)
{
foo();
}
Following is assembly listing.
.h8300h
.section .text
.align 1
.global _foo
_foo:
mov.l er6,@-er7
mov.l er7,er6
mov.l @er7+,er6
rts
.size _foo, .-_foo
.align 1
.global _bar
_bar:
mov.l er6,@-er7
mov.l er7,er6
jsr @_foo ----> should be jsr @@aa:8
mov.l @er7+,er6
rts
.size _bar, .-_bar
.end
Following patch adds integer argument to function_vector attribute and generates
jsr @@aa:8 instruction where "aa" is value supplied as argument. I have done
regression on gcc 3.4.2
------------------------------------------------
ChangeLog:
2004-09-15 Asgari Jinia <ajinia@kpitcummins.com>
* config/h8300/h8300.c (h8300_handle_function_vector_attribute): New function.
(print_operand): New switch case added to check jsr operands.
(h8300_attrib): Changed for argument and new function.
* config/h8300/h8300.md (call): Changed assembly output to get processed by
print_operand function.
(call_value): Likewise.
--- gcc-3.4.2/gcc/config/h8300/h8300.c 2004-02-09 22:55:35.000000000 +0530
+++ gcc-3.4.2/gcc/config/h8300/h8300.c.new 2004-09-15 12:32:39.000000000 +0530
@@ -61,6 +61,7 @@ static const char *cond_string (enum rtx
static unsigned int h8300_asm_insn_count (const char *);
static tree h8300_handle_fndecl_attribute (tree *, tree, tree, int, bool *);
static tree h8300_handle_eightbit_data_attribute (tree *, tree, tree, int, bool *);
+static tree h8300_handle_function_vector_attribute (tree *, tree, tree, int, bool *);
static tree h8300_handle_tiny_data_attribute (tree *, tree, tree, int, bool *);
#ifndef OBJECT_FORMAT_ELF
static void h8300_asm_named_section (const char *, unsigned int);
@@ -1198,6 +1199,34 @@ print_operand (FILE *file, rtx x, int co
switch (code)
{
+ case 'C':
+ switch (GET_CODE (x))
+ {
+ case MEM:
+ {
+ rtx inside = XEXP (x, 0);
+ if (GET_CODE (inside) == SYMBOL_REF
+ && (SYMBOL_REF_FLAGS (inside) & SYMBOL_FLAG_FUNCVEC_FUNCTION))
+ {
+ int func_vect_num;
+ tree t;
+ t = SYMBOL_REF_DECL (inside);
+
+ func_vect_num = TREE_INT_CST_LOW (TREE_VALUE (TREE_VALUE (lookup_attribute ("function_vector",
+ DECL_ATTRIBUTES (t)))));
+ fprintf (file,"@@%d:8",(func_vect_num & 0xff));
+ }
+ else
+ {
+ fprintf (file,"@");
+ assemble_name (file,XSTR (inside,0));
+ }
+ }
+ break;
+ default:
+ abort ();
+ }
+ break;
case 'E':
switch (GET_CODE (x))
{
@@ -4240,7 +4269,7 @@ const struct attribute_spec h8300_attrib
{ "saveall", 0, 0, true, false, false, h8300_handle_fndecl_attribute },
{ "OS_Task", 0, 0, true, false, false, h8300_handle_fndecl_attribute },
{ "monitor", 0, 0, true, false, false, h8300_handle_fndecl_attribute },
- { "function_vector", 0, 0, true, false, false, h8300_handle_fndecl_attribute },
+ { "function_vector", 1, 1, true, false, false, h8300_handle_function_vector_attribute },
{ "eightbit_data", 0, 0, true, false, false, h8300_handle_eightbit_data_attribute },
{ "tiny_data", 0, 0, true, false, false, h8300_handle_tiny_data_attribute },
{ NULL, 0, 0, false, false, false, NULL }
@@ -4264,6 +4293,31 @@ h8300_handle_fndecl_attribute (tree *nod
return NULL_TREE;
}
+/* Handle a "function_vector" attribute; arguments as in
+ struct attribute_spec.handler. */
+
+static tree
+h8300_handle_function_vector_attribute (tree *node, tree name,
+ tree args ATTRIBUTE_UNUSED,
+ int flags ATTRIBUTE_UNUSED,
+ bool *no_add_attrs)
+{
+ if (TREE_CODE (*node) != FUNCTION_DECL)
+ {
+ warning ("`%s' attribute only applies to functions",
+ IDENTIFIER_POINTER (name));
+ *no_add_attrs = true;
+ }
+ else if (TREE_CODE (TREE_VALUE (args)) != INTEGER_CST)
+ {
+ /* The argument must be a constant integer. */
+ warning ("`%s' attribute argument not an integer constant",
+ IDENTIFIER_POINTER (name));
+ *no_add_attrs = true;
+ }
+ return NULL_TREE;
+}
+
/* Handle an "eightbit_data" attribute; arguments as in
struct attribute_spec.handler. */
--- gcc-3.4.2/gcc/config/h8300/h8300.md 2004-01-25 08:09:22.000000000 +0530
+++ gcc-3.4.2/gcc/config/h8300/h8300.md.new 2004-09-15 12:32:48.000000000 +0530
@@ -1816,14 +1816,8 @@
[(call (match_operand:QI 0 "call_insn_operand" "or")
(match_operand:HI 1 "general_operand" "g"))]
""
- "*
-{
- if (GET_CODE (XEXP (operands[0], 0)) == SYMBOL_REF
- && SYMBOL_REF_FLAG (XEXP (operands[0], 0)))
- return \"jsr\\t@%0:8\";
- else
- return \"jsr\\t%0\";
-}"
+ "@
+ jsr %C0"
[(set_attr "cc" "clobber")
(set (attr "length")
(if_then_else (match_operand:QI 0 "small_call_insn_operand" "")
@@ -1840,14 +1834,8 @@
(call (match_operand:QI 1 "call_insn_operand" "or")
(match_operand:HI 2 "general_operand" "g")))]
""
- "*
-{
- if (GET_CODE (XEXP (operands[1], 0)) == SYMBOL_REF
- && SYMBOL_REF_FLAG (XEXP (operands[1], 0)))
- return \"jsr\\t@%1:8\";
- else
- return \"jsr\\t%1\";
-}"
+ "@
+ jsr %C1"
[(set_attr "cc" "clobber")
(set (attr "length")
(if_then_else (match_operand:QI 0 "small_call_insn_operand" "")
------------------------------------------------------------------
Regards,
Asgari Jinia
KPIT Cummins InfoSystems Ltd.
Pune, India
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Free download of GNU based tool-chains for Renesas' SH and H8 Series.
The following site also offers free technical support to its users.
Visit http://www.kpitgnutools.com for details.
Latest versions of KPIT GNU tools are released on June 1, 2004.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
More information about the Gcc-patches
mailing list