[PATCH] Support LTO when built-in functions are used
Howard Su <[email protected]>
| Newsgroups | gmane.comp.hardware.texas-instruments.msp430.gcc.user |
|---|---|
| Message-ID | <CAAvnz_rs9m38LiuAhWawKEokNDavHhhB9+uK4tesxrP2KhX7vw@mail.gmail.com> |
I am working on a projec which is using MSP430F5438a. I have to use gcc 4.7 so that I can leverae 256KB ROM. I tried the LTO compile which generate so impressived result: Normal compile: text data bss dec hex filename 87254 376 7674 95304 17448 iwatch.elf LTO: (except main.c) text data bss dec hex filename 80133 376 7660 88169 15869 iwatch.elf The same project compiled under IAR is like 67 856 bytes of CODE memory 8 430 bytes of DATA memory (+ 197 absolute ) 41 640 bytes of CONST memory The attached patch is enable the support for built-in function like __delay_cycles. I don't really understand the gcc code base. I use the same way of AVR backend does for the same purpose. I also tried build the same project under mingw with gcc 4.7 and LTO. Surprizing, it generates much bigger hex file. (i have another dirty patch to get gcc 4.7 lto works under mingw. the main problem is mingw gcc has a broken __attribute((weak)) support.) (mingw gcc-msp430 4.7.0, with LTO) text data bss dec hex filename 87220 372 7672 95264 17420 iwatch.elf -- -Howard ------------------------------------------------------------------------------ Learn Graph Databases - Download FREE O'Reilly Book "Graph Databases" is the definitive new guide to graph databases and their applications. This 200-page book is written by three acclaimed leaders in the field. The early access version is available now. Download your free book today! http://p.sf.net/sfu/neotech_d2d_may _______________________________________________ Mspgcc-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/mspgcc-users
LTO_builtin.diff
(text/plain, 7.1 KB)
diff -du ../../../../gcc-4.7.0/gcc/config/msp430/msp430-builtins.c ./msp430-builtins.c
--- ../../../../gcc-4.7.0/gcc/config/msp430/msp430-builtins.c 2013-05-09 12:58:08.791355400 +0000
+++ ./msp430-builtins.c 2013-05-06 05:50:50.679355402 +0000
@@ -38,6 +38,7 @@
/* The following functions are defined in this file and used by msp430.c */
void msp430_init_builtins (void);
rtx msp430_expand_builtin (tree, rtx, rtx, enum machine_mode, int);
+tree msp430_builtin_decl (unsigned, bool);
enum msp430_builtins
{
@@ -63,6 +64,8 @@
MSP430_BUILTIN_last_enum
};
+tree fndecl[MSP430_BUILTIN_last_enum];
+
void
msp430_init_builtins (void)
{
@@ -72,98 +75,117 @@
gcc_assert (PSImode == TYPE_MODE (msp430_a20_unsigned_type_node));
(*lang_hooks.types.register_builtin_type) (msp430_a20_unsigned_type_node,
"__uint20");
- add_builtin_function ("__nop",
+ fndecl[MSP430_BUILTIN_NOP] =
+ add_builtin_function ("__nop",
build_function_type_list (void_type_node, NULL_TREE),
MSP430_BUILTIN_NOP, BUILT_IN_MD, NULL, NULL_TREE);
- add_builtin_function ("__dint",
+ fndecl[MSP430_BUILTIN_DINT] =
+ add_builtin_function ("__dint",
build_function_type_list (void_type_node, NULL_TREE),
MSP430_BUILTIN_DINT, BUILT_IN_MD, NULL, NULL_TREE);
- add_builtin_function ("__eint",
+ fndecl[MSP430_BUILTIN_EINT] =
+ add_builtin_function ("__eint",
build_function_type_list (void_type_node, NULL_TREE),
MSP430_BUILTIN_EINT, BUILT_IN_MD, NULL, NULL_TREE);
- add_builtin_function ("__read_status_register",
+ fndecl[MSP430_BUILTIN_READ_STATUS_REGISTER] =
+ add_builtin_function ("__read_status_register",
build_function_type_list (unsigned_type_node,
NULL_TREE),
MSP430_BUILTIN_READ_STATUS_REGISTER, BUILT_IN_MD,
NULL, NULL_TREE);
- add_builtin_function ("__get_interrupt_state",
+ fndecl[MSP430_BUILTIN_GET_INTERRUPT_STATE] =
+ add_builtin_function ("__get_interrupt_state",
build_function_type_list (unsigned_type_node,
NULL_TREE),
MSP430_BUILTIN_GET_INTERRUPT_STATE, BUILT_IN_MD, NULL,
NULL_TREE);
- add_builtin_function ("__write_status_register",
+ fndecl[MSP430_BUILTIN_WRITE_STATUS_REGISTER] =
+ add_builtin_function ("__write_status_register",
build_function_type_list (void_type_node,
unsigned_type_node,
NULL_TREE),
MSP430_BUILTIN_WRITE_STATUS_REGISTER, BUILT_IN_MD,
NULL, NULL_TREE);
- add_builtin_function ("__bic_status_register",
+ fndecl[MSP430_BUILTIN_BIC_STATUS_REGISTER] =
+ add_builtin_function ("__bic_status_register",
build_function_type_list (void_type_node,
unsigned_type_node,
NULL_TREE),
MSP430_BUILTIN_BIC_STATUS_REGISTER, BUILT_IN_MD, NULL,
NULL_TREE);
- add_builtin_function ("__bis_status_register",
+ fndecl[MSP430_BUILTIN_BIS_STATUS_REGISTER] =
+ add_builtin_function ("__bis_status_register",
build_function_type_list (void_type_node,
unsigned_type_node,
NULL_TREE),
MSP430_BUILTIN_BIS_STATUS_REGISTER, BUILT_IN_MD, NULL,
NULL_TREE);
- add_builtin_function ("__set_interrupt_state",
+ fndecl[MSP430_BUILTIN_SET_INTERRUPT_STATE] =
+ add_builtin_function ("__set_interrupt_state",
build_function_type_list (void_type_node,
unsigned_type_node,
NULL_TREE),
MSP430_BUILTIN_SET_INTERRUPT_STATE, BUILT_IN_MD, NULL,
NULL_TREE);
- add_builtin_function ("__bic_status_register_on_exit",
+ fndecl[MSP430_BUILTIN_BIC_SR_IRQ] =
+ add_builtin_function ("__bic_status_register_on_exit",
build_function_type_list (void_type_node,
unsigned_type_node,
NULL_TREE),
MSP430_BUILTIN_BIC_SR_IRQ, BUILT_IN_MD, NULL,
NULL_TREE);
- add_builtin_function ("__bis_status_register_on_exit",
+ fndecl[MSP430_BUILTIN_BIS_SR_IRQ] =
+ add_builtin_function ("__bis_status_register_on_exit",
build_function_type_list (void_type_node,
unsigned_type_node,
NULL_TREE),
MSP430_BUILTIN_BIS_SR_IRQ, BUILT_IN_MD, NULL,
NULL_TREE);
- add_builtin_function ("__read_stack_pointer",
+ fndecl[MSP430_BUILTIN_READ_STACK_POINTER] =
+ add_builtin_function ("__read_stack_pointer",
build_function_type_list (ptr_type_node, NULL_TREE),
MSP430_BUILTIN_READ_STACK_POINTER, BUILT_IN_MD, NULL,
NULL_TREE);
- add_builtin_function ("__write_stack_pointer",
+ fndecl[MSP430_BUILTIN_WRITE_STACK_POINTER] =
+ add_builtin_function ("__write_stack_pointer",
build_function_type_list (void_type_node,
ptr_type_node, NULL_TREE),
MSP430_BUILTIN_WRITE_STACK_POINTER, BUILT_IN_MD, NULL,
NULL_TREE);
- add_builtin_function ("__delay_cycles",
+ fndecl[MSP430_BUILTIN_DELAY_CYCLES] =
+ add_builtin_function ("__delay_cycles",
build_function_type_list (void_type_node,
long_unsigned_type_node,
NULL_TREE),
MSP430_BUILTIN_DELAY_CYCLES, BUILT_IN_MD, NULL,
NULL_TREE);
- add_builtin_function ("__swap_bytes",
+ fndecl[MSP430_BUILTIN_SWAP_BYTES] =
+ add_builtin_function ("__swap_bytes",
build_function_type_list (unsigned_type_node,
unsigned_type_node,
NULL_TREE),
MSP430_BUILTIN_SWAP_BYTES, BUILT_IN_MD, NULL,
NULL_TREE);
- add_builtin_function ("__get_watchdog_clear_value",
+ fndecl[MSP430_BUILTIN_GET_WATCHDOG_CLEAR_VALUE] =
+ add_builtin_function ("__get_watchdog_clear_value",
build_function_type_list (unsigned_type_node,
NULL_TREE),
MSP430_BUILTIN_GET_WATCHDOG_CLEAR_VALUE, BUILT_IN_MD,
NULL, NULL_TREE);
- add_builtin_function ("__set_watchdog_clear_value",
+ fndecl[MSP430_BUILTIN_SET_WATCHDOG_CLEAR_VALUE] =
+ add_builtin_function ("__set_watchdog_clear_value",
build_function_type_list (void_type_node,
unsigned_type_node,
NULL_TREE),
MSP430_BUILTIN_SET_WATCHDOG_CLEAR_VALUE, BUILT_IN_MD,
NULL, NULL_TREE);
- add_builtin_function ("__watchdog_clear",
+ fndecl[MSP430_BUILTIN_WATCHDOG_CLEAR] =
+ add_builtin_function ("__watchdog_clear",
build_function_type_list (void_type_node, NULL_TREE),
MSP430_BUILTIN_WATCHDOG_CLEAR, BUILT_IN_MD, NULL,
NULL_TREE);
- add_builtin_function ("__even_in_range",
+ fndecl[MSP430_BUILTIN_EVEN_IN_RANGE] =
+ add_builtin_function ("__even_in_range",
build_function_type_list (unsigned_type_node,
unsigned_type_node,
unsigned_type_node,
@@ -481,3 +503,12 @@
return retval;
}
+
+tree
+msp430_builtin_decl (unsigned id, bool initialize_p ATTRIBUTE_UNUSED)
+{
+ if (id < MSP430_BUILTIN_last_enum)
+ return fndecl[id];
+
+ return error_mark_node;
+}
diff -du ../../../../gcc-4.7.0/gcc/config/msp430/msp430.c ./msp430.c
--- ../../../../gcc-4.7.0/gcc/config/msp430/msp430.c 2013-05-09 12:58:08.799355400 +0000
+++ ./msp430.c 2013-05-06 05:46:44.955355401 +0000
@@ -4149,9 +4149,13 @@
/* Defined in msp430-builtins.c */
rtx msp430_expand_builtin (tree, rtx, rtx, enum machine_mode, int);
+tree msp430_builtin_decl (unsigned, bool);
#undef TARGET_EXPAND_BUILTIN
#define TARGET_EXPAND_BUILTIN msp430_expand_builtin
+#undef TARGET_BUILTIN_DECL
+#define TARGET_BUILTIN_DECL msp430_builtin_decl
+
/* Defined in msp430-function.c */
#undef TARGET_SET_CURRENT_FUNCTION
#define TARGET_SET_CURRENT_FUNCTION msp430_set_current_function