[PATCH for 3.2] PR opt/6627: Backport force_align_functions_log
Roger Sayle
roger@eyesopen.com
Sat Oct 5 20:27:00 GMT 2002
The following patch is a backport to 3.2.1 of the recent patch to
mainline to fix PR optimization/6627. The original has been in
mainline CVS for a few days, and hasn't been causing any problems :).
http://gcc.gnu.org/ml/gcc-patches/2002-10/msg00092.html
There has been some discussion on the gcc list recently that some
distributions would appreciate this problem fixed on the 3.2 branch.
Whilst customary to wait a few more days, I believe this patch is
safe to backport at this time.
Tested against the gcc-3_2-branch CVS, with a complete "make bootstrap"
and "make -k check", all languages except Ada and treelang, on
i686-pc-linux-gnu with no new regressions. The patch itself is
identical to the one applied to mainline (modulo line numbering).
Ok for the gcc-3_2-branch? Many thanks in advance.
2002-10-05 Roger Sayle <roger@eyesopen.com>
PR optimization/6627
* toplev.c (force_align_functions_log): New global variable.
* flags.h (force_align_functions_log): Add extern prototype.
* varasm.c (assemble_start_function): Use it to force minimum
function alignment.
* config/i386/i386.h (FUNCTION_BOUNDARY): Set the correct
minimum function alignment to one byte.
(TARGET_PTRMEMFUNC_VBIT_LOCATION): Store the virtual bit in
the least significant bit of vtable member function pointers.
* tree.h (enum ptrmemfunc_vbit_where_t): Move definition to
here from cp/cp-tree.h.
* cp/cp-tree.h (enum ptrmemfunc_vbit_where_t): Delete definition
from here, and move it to tree.h.
* cp/decl.c (cxx_init_decl_processing): If storing the vbit
in function pointers, ensure that force_align_functions_log
is atleast one.
* java/lang.c (java_init): If storing the vbit in function
pointers, ensure that force_align_functions_log is atleast
one to aid compatability with g++ vtables.
Index: toplev.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/toplev.c,v
retrieving revision 1.574.2.16.2.1
diff -c -3 -p -r1.574.2.16.2.1 toplev.c
*** toplev.c 3 Oct 2002 19:40:43 -0000 1.574.2.16.2.1
--- toplev.c 5 Oct 2002 18:58:47 -0000
*************** int align_labels_max_skip;
*** 879,884 ****
--- 879,888 ----
int align_functions;
int align_functions_log;
+ /* Like align_functions_log above, but used by front-ends to force the
+ minimum function alignment. Zero means no alignment is forced. */
+ int force_align_functions_log;
+
/* Table of supported debugging formats. */
static const struct
{
Index: flags.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/flags.h,v
retrieving revision 1.76.4.1
diff -c -3 -p -r1.76.4.1 flags.h
*** flags.h 21 Mar 2002 23:12:21 -0000 1.76.4.1
--- flags.h 5 Oct 2002 18:58:47 -0000
*************** extern int align_labels_max_skip;
*** 604,609 ****
--- 604,613 ----
extern int align_functions;
extern int align_functions_log;
+ /* Like align_functions_log above, but used by front-ends to force the
+ minimum function alignment. Zero means no alignment is forced. */
+ extern int force_align_functions_log;
+
/* Nonzero if we dump in VCG format, not plain text. */
extern int dump_for_graph;
Index: varasm.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/varasm.c,v
retrieving revision 1.250.2.14
diff -c -3 -p -r1.250.2.14 varasm.c
*** varasm.c 10 Jun 2002 21:44:41 -0000 1.250.2.14
--- varasm.c 5 Oct 2002 18:58:48 -0000
*************** assemble_start_function (decl, fnname)
*** 1194,1199 ****
--- 1194,1201 ----
/* Tell assembler to move to target machine's alignment for functions. */
align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT);
+ if (align < force_align_functions_log)
+ align = force_align_functions_log;
if (align > 0)
{
ASM_OUTPUT_ALIGN (asm_out_file, align);
Index: tree.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree.h,v
retrieving revision 1.308.2.2
diff -c -3 -p -r1.308.2.2 tree.h
*** tree.h 17 Apr 2002 01:43:57 -0000 1.308.2.2
--- tree.h 5 Oct 2002 18:58:48 -0000
*************** extern tree integer_types[itk_none];
*** 2052,2057 ****
--- 2052,2084 ----
#define long_long_unsigned_type_node integer_types[itk_unsigned_long_long]
+ /* A pointer-to-function member type looks like:
+
+ struct {
+ __P __pfn;
+ ptrdiff_t __delta;
+ };
+
+ If __pfn is NULL, it is a NULL pointer-to-member-function.
+
+ (Because the vtable is always the first thing in the object, we
+ don't need its offset.) If the function is virtual, then PFN is
+ one plus twice the index into the vtable; otherwise, it is just a
+ pointer to the function.
+
+ Unfortunately, using the lowest bit of PFN doesn't work in
+ architectures that don't impose alignment requirements on function
+ addresses, or that use the lowest bit to tell one ISA from another,
+ for example. For such architectures, we use the lowest bit of
+ DELTA instead of the lowest bit of the PFN, and DELTA will be
+ multiplied by 2. */
+
+ enum ptrmemfunc_vbit_where_t
+ {
+ ptrmemfunc_vbit_in_pfn,
+ ptrmemfunc_vbit_in_delta
+ };
+
#define NULL_TREE (tree) NULL
/* Approximate positive square root of a host double. This is for
Index: config/i386/i386.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/i386/i386.h,v
retrieving revision 1.243.2.8.2.1
diff -c -3 -p -r1.243.2.8.2.1 i386.h
*** config/i386/i386.h 3 Oct 2002 21:16:11 -0000 1.243.2.8.2.1
--- config/i386/i386.h 5 Oct 2002 18:58:50 -0000
*************** extern int ix86_arch;
*** 760,767 ****
#define FORCE_PREFERRED_STACK_BOUNDARY_IN_MAIN \
(ix86_preferred_stack_boundary > STACK_BOUNDARY && !TARGET_64BIT)
! /* Allocation boundary for the code of a function. */
! #define FUNCTION_BOUNDARY 16
/* Alignment of field after `int : 0' in a structure. */
--- 760,770 ----
#define FORCE_PREFERRED_STACK_BOUNDARY_IN_MAIN \
(ix86_preferred_stack_boundary > STACK_BOUNDARY && !TARGET_64BIT)
! /* Minimum allocation boundary for the code of a function. */
! #define FUNCTION_BOUNDARY 8
!
! /* C++ stores the virtual bit in the lowest bit of function pointers. */
! #define TARGET_PTRMEMFUNC_VBIT_LOCATION ptrmemfunc_vbit_in_pfn
/* Alignment of field after `int : 0' in a structure. */
Index: cp/cp-tree.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/cp-tree.h,v
retrieving revision 1.681.2.12.2.3
diff -c -3 -p -r1.681.2.12.2.3 cp-tree.h
*** cp/cp-tree.h 27 Aug 2002 22:49:46 -0000 1.681.2.12.2.3
--- cp/cp-tree.h 5 Oct 2002 18:58:51 -0000
*************** extern int flag_new_for_scope;
*** 2557,2588 ****
member function. [expr.unary.op]/3 */
#define PTRMEM_OK_P(NODE) TREE_LANG_FLAG_0 (NODE)
- /* A pointer-to-function member type looks like:
-
- struct {
- __P __pfn;
- ptrdiff_t __delta;
- };
-
- If __pfn is NULL, it is a NULL pointer-to-member-function.
-
- (Because the vtable is always the first thing in the object, we
- don't need its offset.) If the function is virtual, then PFN is
- one plus twice the index into the vtable; otherwise, it is just a
- pointer to the function.
-
- Unfortunately, using the lowest bit of PFN doesn't work in
- architectures that don't impose alignment requirements on function
- addresses, or that use the lowest bit to tell one ISA from another,
- for example. For such architectures, we use the lowest bit of
- DELTA instead of the lowest bit of the PFN, and DELTA will be
- multiplied by 2. */
- enum ptrmemfunc_vbit_where_t
- {
- ptrmemfunc_vbit_in_pfn,
- ptrmemfunc_vbit_in_delta
- };
-
/* Get the POINTER_TYPE to the METHOD_TYPE associated with this
pointer to member function. TYPE_PTRMEMFUNC_P _must_ be true,
before using this macro. */
--- 2557,2562 ----
Index: cp/decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/decl.c,v
retrieving revision 1.866.2.36.2.1
diff -c -3 -p -r1.866.2.36.2.1 decl.c
*** cp/decl.c 4 Sep 2002 08:25:50 -0000 1.866.2.36.2.1
--- cp/decl.c 5 Oct 2002 18:58:54 -0000
*************** cxx_init_decl_processing ()
*** 6517,6522 ****
--- 6517,6528 ----
flag_inline_functions = 0;
}
+ /* Force minimum function alignment if using the least significant
+ bit of function pointers to store the virtual bit. */
+ if (TARGET_PTRMEMFUNC_VBIT_LOCATION == ptrmemfunc_vbit_in_pfn
+ && force_align_functions_log < 1)
+ force_align_functions_log = 1;
+
/* Initially, C. */
current_lang_name = lang_name_c;
Index: java/lang.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/lang.c,v
retrieving revision 1.85.2.4
diff -c -3 -p -r1.85.2.4 lang.c
*** java/lang.c 11 Jun 2002 06:20:12 -0000 1.85.2.4
--- java/lang.c 5 Oct 2002 18:58:54 -0000
*************** java_init (filename)
*** 458,463 ****
--- 458,470 ----
flag_minimal_debug = 0;
#endif
+ /* Force minimum function alignment if g++ uses the least significant
+ bit of function pointers to store the virtual bit. This is required
+ to keep vtables compatible. */
+ if (TARGET_PTRMEMFUNC_VBIT_LOCATION == ptrmemfunc_vbit_in_pfn
+ && force_align_functions_log < 1)
+ force_align_functions_log = 1;
+
/* Open input file. */
if (filename == 0 || !strcmp (filename, "-"))
Roger
--
Roger Sayle, E-mail: roger@eyesopen.com
OpenEye Scientific Software, WWW: http://www.eyesopen.com/
Suite 1107, 3600 Cerrillos Road, Tel: (+1) 505-473-7385
Santa Fe, New Mexico, 87507. Fax: (+1) 505-473-0833
More information about the Gcc-patches
mailing list