Index: gcc/config/sol2.h =================================================================== RCS file: /usr/cvs/cm3/m3-sys/m3cc/gcc/gcc/config/sol2.h,v retrieving revision 1.1.1.3 diff -u -r1.1.1.3 sol2.h --- gcc/config/sol2.h 14 Apr 2008 03:10:37 -0000 1.1.1.3 +++ gcc/config/sol2.h 2 Jun 2010 14:04:59 -0000 @@ -242,3 +242,5 @@ /* Allow macro expansion in #pragma pack. */ #define HANDLE_PRAGMA_PACK_WITH_EXPANSION + +#define TARGET_SOLARIS 1 Index: gcc/config/sparc/sparc.h =================================================================== RCS file: /usr/cvs/cm3/m3-sys/m3cc/gcc/gcc/config/sparc/sparc.h,v retrieving revision 1.6 diff -u -r1.6 sparc.h --- gcc/config/sparc/sparc.h 14 Apr 2008 12:49:01 -0000 1.6 +++ gcc/config/sparc/sparc.h 2 Jun 2010 14:05:00 -0000 @@ -2483,3 +2483,5 @@ /* The number of Pmode words for the setjmp buffer. */ #define JMP_BUF_SIZE 12 + +#define TARGET_SPARC 1 Index: gcc/m3cg/m3gty43.h =================================================================== RCS file: /usr/cvs/cm3/m3-sys/m3cc/gcc/gcc/m3cg/m3gty43.h,v retrieving revision 1.4 diff -u -r1.4 m3gty43.h --- gcc/m3cg/m3gty43.h 27 May 2010 13:18:18 -0000 1.4 +++ gcc/m3cg/m3gty43.h 2 Jun 2010 14:05:00 -0000 @@ -60,5 +60,5 @@ struct language_function GTY(()) { - char junk; /* dummy field to ensure struct is not empty */ + bool volatil; /* does function call setjmp/fork/vfork */ }; Index: gcc/m3cg/m3gty45.h =================================================================== RCS file: /usr/cvs/cm3/m3-sys/m3cc/gcc/gcc/m3cg/m3gty45.h,v retrieving revision 1.4 diff -u -r1.4 m3gty45.h --- gcc/m3cg/m3gty45.h 27 May 2010 13:18:18 -0000 1.4 +++ gcc/m3cg/m3gty45.h 2 Jun 2010 14:05:00 -0000 @@ -60,5 +60,5 @@ struct GTY(()) language_function { - char junk; /* dummy field to ensure struct is not empty */ + bool volatil; /* does function call setjmp/fork/vfork */ }; Index: gcc/m3cg/parse.c =================================================================== RCS file: /usr/cvs/cm3/m3-sys/m3cc/gcc/gcc/m3cg/parse.c,v retrieving revision 1.177 diff -u -r1.177 parse.c --- gcc/m3cg/parse.c 2 Jun 2010 13:59:39 -0000 1.177 +++ gcc/m3cg/parse.c 2 Jun 2010 14:05:00 -0000 @@ -65,6 +65,18 @@ #include "debug.h" +#ifndef TARGET_SOLARIS +#define TARGET_SOLARIS 0 +#endif +#ifndef TARGET_SPARC +#define TARGET_SPARC 0 +#endif +#ifndef TARGET_ARCH32 +#define TARGET_ARCH32 0 +#endif + +#define M3_HAS_STACK_WALKER (TARGET_SPARC && TARGET_SOLARIS && TARGET_ARCH32) + #ifdef GCC45 /* error: attempt to use poisoned "USE_MAPPED_LOCATION" */ @@ -213,6 +225,10 @@ static void m3_parse_file (int); static alias_set_type m3_get_alias_set (tree); static void m3_finish (void); +static bool m3_volatize_p (void); +static void m3_volatilize_decl (tree decl); + +static bool m3_next_store_volatile; /* Functions to keep track of the current scope */ static tree pushdecl (tree decl); @@ -251,10 +267,8 @@ #define LANG_HOOKS_TYPE_FOR_SIZE m3_type_for_size #undef LANG_HOOKS_PARSE_FILE #define LANG_HOOKS_PARSE_FILE m3_parse_file -#ifndef GCC45 #undef LANG_HOOKS_GET_ALIAS_SET #define LANG_HOOKS_GET_ALIAS_SET m3_get_alias_set -#endif #undef LANG_HOOKS_WRITE_GLOBALS #define LANG_HOOKS_WRITE_GLOBALS m3_write_globals @@ -834,7 +848,7 @@ tree var = (tree)DECL_LANG_SPECIFIC(index); if (var) { gcc_assert(TREE_CODE(var) == VAR_DECL); - gcc_assert (TREE_ADDRESSABLE (var)); /* ensure optimizers play fair */ + if (TREE_ADDRESSABLE (var)) /* take apart the rtx, which is of the form (insn n m p (use (mem: (plus: (reg: r $fp) (const_int offset))) ...) @@ -853,6 +867,11 @@ } VEC_index (constructor_elt, elts, idx)->value = size_int (j); } + else + { + /*fprintf(stderr, "%s %s not addressable, should be?\n", + input_filename, IDENTIFIER_POINTER(DECL_NAME(var)));*/ + } } } } @@ -1910,6 +1929,9 @@ DECL_UNSIGNED (v) = TYPE_UNSIGNED (t); DECL_CONTEXT (v) = current_function_decl; + if (m3_volatize_p ()) + m3_volatilize_decl (v); + add_stmt (build1 (DECL_EXPR, t_void, v)); TREE_CHAIN (v) = BLOCK_VARS (current_block); BLOCK_VARS (current_block) = v; @@ -1993,6 +2015,45 @@ #else +static struct language_function* +m3_get_language_function (void) +{ + if (M3_HAS_STACK_WALKER) + return 0; + return DECL_STRUCT_FUNCTION(current_function_decl)->language; +} + +static struct language_function* +m3_set_language_function (void) +{ + struct language_function* f; + if (M3_HAS_STACK_WALKER) + return 0; + f = DECL_STRUCT_FUNCTION(current_function_decl)->language; + if (!f) + { + f = GGC_NEW (struct language_function); + DECL_STRUCT_FUNCTION(current_function_decl)->language = f; + } + return f; +} + +static bool +m3_volatize_p (void) +{ + struct language_function* f; + if (M3_HAS_STACK_WALKER) + return true; + f = m3_get_language_function(); + return (f && f->volatil); +} + +static void +m3_set_volatize (void) +{ + m3_set_language_function()->volatil = true; +} + static void m3_volatilize_decl (tree decl) { @@ -2031,6 +2092,7 @@ if (flags & ECF_RETURNS_TWICE) { tree block, decl; /* call to setjmp: make locals volatile */ + m3_set_volatize (); /* for later temporaries, locals */ for (block = current_block; block != current_function_decl; block = BLOCK_SUPERCONTEXT(block)) { @@ -2094,7 +2156,11 @@ m3_cast (build_pointer_type (src_t), v)); #endif } - TREE_THIS_VOLATILE(v) = TREE_SIDE_EFFECTS(v) = 1; /* force this to avoid aliasing problems */ + /* not good! */ + if (FLOAT_TYPE_P (src_t) || FLOAT_TYPE_P (dst_t)) + TREE_THIS_VOLATILE(v) = 1; /* force this to avoid aliasing problems */ + if (M3_HAS_STACK_WALKER) + TREE_THIS_VOLATILE(v) = TREE_SIDE_EFFECTS(v) = 1; /* force this to avoid aliasing problems */ if (src_T != dst_T) { v = m3_build1 (CONVERT_EXPR, dst_t, v); } @@ -2102,7 +2168,8 @@ } static void -m3_store (tree v, int o, tree src_t, m3_type src_T, tree dst_t, m3_type dst_T) +m3_store_1 (tree v, int o, tree src_t, m3_type src_T, tree dst_t, m3_type dst_T, + bool volatil) { tree val; if (o != 0 || TREE_TYPE (v) != dst_t) @@ -2111,14 +2178,19 @@ v = m3_build3 (BIT_FIELD_REF, dst_t, v, TYPE_SIZE (dst_t), bitsize_int (o)); #else - /* failsafe, but inefficient */ + /* failsafe, but inefficient */ v = m3_build1 (ADDR_EXPR, t_addr, v); v = m3_build2 (PLUS_EXPR, t_addr, v, size_int (o / BITS_PER_UNIT)); v = m3_build1 (INDIRECT_REF, dst_t, m3_cast (build_pointer_type (dst_t), v)); #endif } - TREE_THIS_VOLATILE(v) = TREE_SIDE_EFFECTS(v) = 1; /* force this to avoid aliasing problems */ + /* not good! */ + if (volatil || m3_next_store_volatile || FLOAT_TYPE_P (src_t) || FLOAT_TYPE_P (dst_t)) + TREE_THIS_VOLATILE(v) = 1; /* force this to avoid aliasing problems */ + if (M3_HAS_STACK_WALKER) + TREE_THIS_VOLATILE(v) = TREE_SIDE_EFFECTS(v) = 1; /* force this to avoid aliasing problems */ + m3_next_store_volatile = false; val = m3_cast (src_t, EXPR_REF (-1)); if (src_T != dst_T) { val = m3_build1 (CONVERT_EXPR, dst_t, val); @@ -2128,6 +2200,21 @@ } static void +m3_store (tree v, int o, tree src_t, m3_type src_T, tree dst_t, m3_type dst_T) +{ + bool volatil = false; + m3_store_1(v, o, src_t, src_T, dst_t, dst_T, volatil); +} + +static void +m3_store_volatile (tree v, int o, tree src_t, m3_type src_T, tree dst_t, + m3_type dst_T) +{ + bool volatil = true; + m3_store_1(v, o, src_t, src_T, dst_t, dst_T, volatil); +} + +static void setop (tree p, int n, int q) { m3_start_call (); @@ -3023,6 +3110,8 @@ if (current_block) { + if (m3_volatize_p ()) + m3_volatilize_decl(v); add_stmt (build1 (DECL_EXPR, t_void, v)); TREE_CHAIN (v) = BLOCK_VARS (current_block); BLOCK_VARS (current_block) = v; @@ -3120,13 +3209,17 @@ if (option_vars_trace) fprintf(stderr, " temp var type:%s size:0x%lx alignment:0x%lx\n", m3cg_typename(t), s, a); + + if (t == T_void) + t = T_struct; - if (t == T_void) t = T_struct; TREE_TYPE (v) = m3_build_type (t, s, a); layout_decl (v, 0); DECL_UNSIGNED (v) = TYPE_UNSIGNED (TREE_TYPE (v)); TREE_ADDRESSABLE (v) = in_memory; DECL_CONTEXT (v) = current_function_decl; + if (m3_volatize_p ()) + m3_volatilize_decl(v); TREE_CHAIN (v) = BLOCK_VARS (BLOCK_SUBBLOCKS (DECL_INITIAL (current_function_decl))); @@ -3397,9 +3490,9 @@ { DECL_VISIBILITY (p) = VISIBILITY_HIDDEN; } -#ifdef GCC45 gcc_assert((parent == 0) == (lev == 0)); if (parent) +#ifdef GCC45 DECL_STATIC_CHAIN (parent) = 1; #endif DECL_CONTEXT (p) = parent; @@ -4526,6 +4619,15 @@ gcc_assert (INTEGRAL_TYPE_P (t)); gcc_assert (m >= 0); gcc_assert (n >= 0); + + /* workaround the fact that we use + * insert_mn on uninitialized variables. + */ + m3_next_store_volatile = true; if (option_trace_all) fprintf(stderr, " insert_mn offset:%u count:%u\n", (unsigned)m, @@ -4929,7 +5032,8 @@ m3cg_pop_static_link (void) { tree v = declare_temp (t_addr); - m3_store (v, 0, t_addr, T_addr, t_addr, T_addr); + /* volatile otherwise gcc complains it is not intialized */ + m3_store_volatile (v, 0, t_addr, T_addr, t_addr, T_addr); CALL_TOP_STATIC_CHAIN () = v; } @@ -5472,22 +5575,46 @@ bool m3_post_options (const char **pfilename ATTRIBUTE_UNUSED) { - if (flag_reorder_blocks) - { - warning (OPT_freorder_blocks, - "-freorder-blocks disabled for Modula-3 ex_stack exception handling"); - flag_reorder_blocks = 0; - } - if (flag_reorder_blocks_and_partition) - { - warning (OPT_freorder_blocks_and_partition, - "-freorder-blocks-and-partition disabled for Modula-3 ex_stack exception handling"); - flag_reorder_blocks_and_partition = 0; - } + /* These optimizations break our exception handling? */ + flag_reorder_blocks = 0; + flag_reorder_blocks_and_partition = 0; + + if (M3_HAS_STACK_WALKER) + { + /* We continue to make all loads/stores volatile + * which greatly hampers optimization, but + * we don't then have to disable any particular + * optimizations below. + * TODO: Find out what optimizations break + * stack walking. + */ + } + else + { + /* Turn off some optimizations that cause problems, + * unless we make all loads/stores volatile. + */ + /* + * Undefined symbols: + * "_ZChassisVBT__NewBtn__Win32.675", referenced from: + * _L_1 in ZChassisVBT.mo + * It would be really nice to find another fix for this! + */ + flag_unit_at_a_time = 0; + + flag_tree_vrp = 0; /* value range propagation, causes problems? */ + flag_tree_pre = 0; /* partial redundancy elmination, crashes? */ + flag_tree_fre = 0; /* full redundancy elimination, causes problems? */ + + flag_tree_loop_im = 0; /* loop Invariant Motion, breaks compiling Trestle */ + flag_schedule_insns = 0; /* fails to compile, surprising */ + } + #ifdef GCC45 /* Excess precision other than "fast" requires front-end support. */ flag_excess_precision_cmdline = EXCESS_PRECISION_FAST; #endif + return false; }