This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Example program takes 2000 times as long to compile under C++ as C
- To: <gcc-bugs at gcc dot gnu dot org>
- Subject: Example program takes 2000 times as long to compile under C++ as C
- From: "Kelley Cook" <kelleycook at attglobal dot net>
- Date: Wed, 30 Aug 2000 17:56:05 -0400
As originally brought up in message
http://gcc.gnu.org/ml/gcc-bugs/2000-06/msg00385.html, Mr. Robert Melcher
<robert.melchers@drives.eurotherm.co.uk> discovered that the following
program compiles nearly instantly in C, but takes 5 minutes with C++.
Mike Stump suggested to profile the compiler, unfortunately this appeared
hard to do, so I didn't bother.
However, the new -ftime-report & -fmem-report functions make this somewhat
easier, so I am resubmitting a more detail synopsis as a bug report doesn't
seem to be listed in GNATs and still exists with the current snapshot.
I have supplied the following data garnered from CodeSourcery's wonderful
on-line compiler at http://www.codesourcery.com/gcc-compile.shtml
As you can see, the compile takes 0.09 seconds with C front end and 209.43
seconds with the C++ front end. Virtually all of the time is spent in
either the parser (73%) and integration (27%) portions of the compiler.
Memory usage appears doesn't appear to be outrageous in either case -- 96K
vs 128K.
As Robert mentioned, this extra-long behavior is not present in GCC 2.95.x
FWIW, compiling the same file in C++ without -O2 results in the
approximately the same parser time, but cuts the integration portion to
zero.
Cheers,
Kelley Cook
---- Begin mux.cc ----
#ifndef __cplusplus
typedef char bool; /* needed for 'c' build */
#endif /* !__cplusplus */
bool in0 ;
bool in1 ;
bool in2 ;
bool in3 ;
bool in4 ;
bool in5 ;
bool in6 ;
bool in7 ;
bool in8 ;
bool in9 ;
bool in10;
bool in11;
bool in12;
bool in13;
bool in14;
bool in15;
unsigned int output;
void mux(void)
{
output =
(in0 ? 0x0001 : 0) |
(in1 ? 0x0002 : 0) |
(in2 ? 0x0004 : 0) |
(in3 ? 0x0008 : 0) |
(in4 ? 0x0010 : 0) |
(in5 ? 0x0020 : 0) |
(in6 ? 0x0040 : 0) |
(in7 ? 0x0080 : 0) |
(in8 ? 0x0100 : 0) |
(in9 ? 0x0200 : 0) |
(in10 ? 0x0400 : 0) |
(in11 ? 0x0800 : 0) |
(in12 ? 0x1000 : 0) |
(in13 ? 0x2000 : 0) |
(in14 ? 0x4000 : 0) |
(in15 ? 0x8000 : 0) ;
}
--- End mux.cc ---
---- Output from snapshot gcc 2.96 20000830 C -----
gcc -x c -ftime-report -fmem-report -O2 -fomit-frame-pointer [input]
Exit code: 256
Messages:
Tree Number Bytes % Total
error_mark 1 16 0.031
identifier_node 212 13k 26.658
tree_list 41 1312 2.578
void_type 2 256 0.503
integer_type 37 4736 9.305
real_type 3 384 0.754
complex_type 4 512 1.006
vector_type 5 640 1.257
pointer_type 11 1408 2.766
reference_type 1 128 0.251
array_type 11 1408 2.766
record_type 5 640 1.257
function_type 31 3968 7.796
integer_cst 99 3168 6.224
string_cst 2 64 0.126
function_decl 84 10k 21.125
type_decl 37 4736 9.305
var_decl 19 2432 4.778
result_decl 1 128 0.251
field_decl 5 640 1.257
Total 611 49k
RTX Number Bytes % Total
code_label 1 64 0.860
const_int 157 1256 16.882
const_double 21 672 9.032
pc 1 4 0.054
reg 11 176 2.366
mem 158 2528 33.978
symbol_ref 340 2720 36.559
cc0 1 4 0.054
eq 1 16 0.215
Total 691 7440
Log Allocated Used Overhead
2 4096 140 156
3 8192 4840 184
4 16k 6976 240
5 12k 7008 132
6 16k 13k 144
7 36k 32k 288
Total 96k 63k 1144
Execution times (seconds)
garbage collection : 0.00 ( 0%) usr 0.00 ( 0%) sys 0.00 ( 0%) wall
parser : 0.00 ( 0%) usr 0.00 ( 0%) sys 0.00 ( 0%) wall
varconst : 0.00 ( 0%) usr 0.00 ( 0%) sys 0.00 ( 0%) wall
jump : 0.00 ( 0%) usr 0.00 ( 0%) sys 0.00 ( 0%) wall
CSE : 0.03 (33%) usr 0.00 ( 0%) sys 0.03 (33%) wall
global CSE : 0.00 ( 0%) usr 0.00 ( 0%) sys 0.00 ( 0%) wall
loop analysis : 0.00 ( 0%) usr 0.00 ( 0%) sys 0.00 ( 0%) wall
CSE 2 : 0.03 (33%) usr 0.00 ( 0%) sys 0.03 (33%) wall
flow analysis : 0.00 ( 0%) usr 0.00 ( 0%) sys 0.00 ( 0%) wall
combiner : 0.00 ( 0%) usr 0.00 ( 0%) sys 0.00 ( 0%) wall
if-conversion : 0.01 (11%) usr 0.00 ( 0%) sys 0.01 (11%) wall
regmove : 0.00 ( 0%) usr 0.00 ( 0%) sys 0.00 ( 0%) wall
local alloc : 0.00 ( 0%) usr 0.00 ( 0%) sys 0.00 ( 0%) wall
global alloc : 0.00 ( 0%) usr 0.00 ( 0%) sys 0.00 ( 0%) wall
reload CSE regs : 0.00 ( 0%) usr 0.00 ( 0%) sys 0.00 ( 0%) wall
flow 2 : 0.00 ( 0%) usr 0.00 ( 0%) sys 0.00 ( 0%) wall
if-conversion 2 : 0.00 ( 0%) usr 0.00 ( 0%) sys 0.00 ( 0%) wall
peephole 2 : 0.00 ( 0%) usr 0.00 ( 0%) sys 0.00 ( 0%) wall
scheduling 2 : 0.01 (11%) usr 0.00 ( 0%) sys 0.01 (11%) wall
reorder blocks : 0.00 ( 0%) usr 0.00 ( 0%) sys 0.00 ( 0%) wall
shorten branches : 0.00 ( 0%) usr 0.00 ( 0%) sys 0.00 ( 0%) wall
reg stack : 0.00 ( 0%) usr 0.00 ( 0%) sys 0.00 ( 0%) wall
final : 0.00 ( 0%) usr 0.00 ( 0%) sys 0.00 ( 0%) wall
symout : 0.00 ( 0%) usr 0.00 ( 0%) sys 0.00 ( 0%) wall
rest of compilation : 0.00 ( 0%) usr 0.00 ( 0%) sys 0.00 ( 0%) wall
TOTAL : 0.09 0.00 0.09
/usr/lib/crt1.o(.text+0x18): undefined reference to `main'
collect2: ld returned 1 exit status
-------------------------
---- Output from snapshot gcc 2.96 20000830 C++ -----
GCC Output
These are the results of processing your source code with the following
command:
c++ -x c++ -ftime-report -fmem-report -O2 -fomit-frame-pointer [input]
Exit code: 256
Messages:
Tree Number Bytes % Total
error_mark 1 16 0.024
identifier_node 310 19k 29.489
tree_list 44 1408 2.093
tree_vec 3 192 0.285
void_type 3 384 0.571
integer_type 45 5760 8.561
real_type 5 640 0.951
complex_type 4 512 0.761
vector_type 5 640 0.951
boolean_type 1 128 0.190
pointer_type 18 2304 3.424
reference_type 2 256 0.380
array_type 18 2304 3.424
record_type 9 1152 1.712
function_type 31 3968 5.898
lang_type 2 256 0.380
integer_cst 143 4576 6.801
string_cst 2 64 0.095
function_decl 82 10k 15.600
type_decl 53 6784 10.083
var_decl 19 2432 3.615
result_decl 1 128 0.190
field_decl 6 768 1.141
namespace_decl 2 256 0.380
binding 63 2016 2.996
Total 872 65k
RTX Number Bytes % Total
code_label 1 64 0.866
const_int 157 1256 16.991
const_double 21 672 9.091
pc 1 4 0.054
reg 11 176 2.381
mem 156 2496 33.766
symbol_ref 338 2704 36.580
cc0 1 4 0.054
eq 1 16 0.216
Total 687 7392
Log Allocated Used Overhead
2 4096 144 156
3 12k 4944 276
4 16k 8224 240
5 20k 10k 220
6 28k 25k 252
7 44k 38k 352
Total 128k 86k 1496
Execution times (seconds)
garbage collection : 0.00 ( 0%) usr 0.00 ( 0%) sys 0.00 ( 0%) wall
parser : 153.10 (73%) usr 0.06 (86%) sys 157.06 (73%) wall
expand : 0.00 ( 0%) usr 0.00 ( 0%) sys 0.00 ( 0%) wall
varconst : 0.01 ( 0%) usr 0.00 ( 0%) sys 0.01 ( 0%) wall
integration : 56.25 (27%) usr 0.00 ( 0%) sys 56.74 (27%) wall
jump : 0.00 ( 0%) usr 0.00 ( 0%) sys 0.00 ( 0%) wall
CSE : 0.02 ( 0%) usr 0.01 (14%) sys 0.03 ( 0%) wall
global CSE : 0.01 ( 0%) usr 0.00 ( 0%) sys 0.01 ( 0%) wall
loop analysis : 0.00 ( 0%) usr 0.00 ( 0%) sys 0.00 ( 0%) wall
CSE 2 : 0.02 ( 0%) usr 0.00 ( 0%) sys 0.02 ( 0%) wall
flow analysis : 0.01 ( 0%) usr 0.00 ( 0%) sys 0.01 ( 0%) wall
combiner : 0.00 ( 0%) usr 0.00 ( 0%) sys 0.00 ( 0%) wall
if-conversion : 0.00 ( 0%) usr 0.00 ( 0%) sys 0.00 ( 0%) wall
regmove : 0.00 ( 0%) usr 0.00 ( 0%) sys 0.00 ( 0%) wall
local alloc : 0.00 ( 0%) usr 0.00 ( 0%) sys 0.00 ( 0%) wall
global alloc : 0.00 ( 0%) usr 0.00 ( 0%) sys 0.00 ( 0%) wall
reload CSE regs : 0.00 ( 0%) usr 0.00 ( 0%) sys 0.00 ( 0%) wall
flow 2 : 0.01 ( 0%) usr 0.00 ( 0%) sys 0.01 ( 0%) wall
if-conversion 2 : 0.00 ( 0%) usr 0.00 ( 0%) sys 0.00 ( 0%) wall
peephole 2 : 0.00 ( 0%) usr 0.00 ( 0%) sys 0.00 ( 0%) wall
scheduling 2 : 0.00 ( 0%) usr 0.00 ( 0%) sys 0.00 ( 0%) wall
reorder blocks : 0.00 ( 0%) usr 0.00 ( 0%) sys 0.00 ( 0%) wall
shorten branches : 0.00 ( 0%) usr 0.00 ( 0%) sys 0.00 ( 0%) wall
reg stack : 0.00 ( 0%) usr 0.00 ( 0%) sys 0.00 ( 0%) wall
final : 0.00 ( 0%) usr 0.00 ( 0%) sys 0.00 ( 0%) wall
symout : 0.00 ( 0%) usr 0.00 ( 0%) sys 0.00 ( 0%) wall
rest of compilation : 0.00 ( 0%) usr 0.00 ( 0%) sys 0.00 ( 0%) wall
TOTAL : 209.43 0.07 213.89
/usr/lib/crt1.o(.text+0x18): undefined reference to `main'
collect2: ld returned 1 exit status