6 Jan 2011 redi   » (Master)

Adventures in C++ compiler land

I've ventured into the g++ front end a couple of times recently (I usually only touch libstdc++ code) trying to fix some bugs. I haven't managed to get my patches reviewed, but as stage 3 has ended I'll have to wait until 4.6 is branched and then try to get them into 4.7

More clang bangin'

One of the goals/features of Clang/LLVM is faster compile times than GCC, so I think something's very wrong with my build (which I configured as a "Release+Asserts build"):


$ wc -l src/Order.cc
4107 src/Order.cc
$ time make CXX=g++ objs/Order.o
...
real    0m8.993s
user    0m8.483s
sys     0m0.339s
$ time make CXX=g++ CXXFLAGS="-O2 -DNDEBUG" objs/Order.o
...
real    0m12.111s
user    0m11.999s
sys     0m0.309s
$ time make CXX=clang++ objs/Order.o
...
real    2m11.608s
user    2m7.475s
sys     0m0.260s
$ time make CXX=clang++ CXXFLAGS="-O2 -DNDEBUG" objs/Order.o
...
real    17m22.577s
user    17m21.589s
sys     0m0.377s

Yes, that really did take 17 minutes at 100% CPU (on a 2.93GHz Xeon X5570) compared to 12 seconds for GCC.

One of the things I really like is that most of GCC's command-line options are supported. so I used -ftime-report to see where all that time is spent, but all the detailed stats are for the code generation stages, which is the only bit that isn't slow!

---User Time--- --System Time-- --User+System-- ---Wall Time--- --- Name ---
137.5871 ( 50.6%) 0.2380 ( 67.8%) 137.8250 ( 50.6%) 138.0570 ( 50.6%) Clang front-end timer
131.2420 ( 48.2%) 0.0610 ( 17.4%) 131.3030 ( 48.2%) 131.3707 ( 48.2%) LLVM IR Generation Time
3.1755 ( 1.2%) 0.0520 ( 14.8%) 3.2275 ( 1.2%) 3.2308 ( 1.2%) Code Generation Time
272.0046 (100.0%) 0.3509 (100.0%) 272.3556 (100.0%) 272.6585 (100.0%) Total

That was with a build from subversion a few weeks ago (trunk 121966) so I updated and got sensible times, although the optimised build is still slower than I expected:


$ time make CXX=clang++ objs/Order.o
...
real    0m7.380s
user    0m6.674s
sys     0m0.471s
$ time make CXX=clang++ CXXFLAGS="-O2 -DNDEBUG" objs/Order.o
...
real    0m17.667s
user    0m17.131s
sys     0m0.309s

I don't remember the earlier build being so slow a few weeks ago, so maybe some gremlins came and moved the files to a really slow bit of the filesystem over Christmas.

Using Clang on a large codebase did find a few bugs which GCC and Sun CC didn't object to (one notable feature is that clang++ found errors in templates which were never instantiated, which even EDG didn't find) and I also found a bug in clang, but one of the main reasons I wanted to try it was the static analyzer. Unfortunately it only works for C and Obj-C and trying to analyze C++ fails miserably. I guess I'll wait and try it again at a later date.

Latest blog entries     Older blog entries

New Advogato Features

New HTML Parser: The long-awaited libxml2 based HTML parser code is live. It needs further work but already handles most markup better than the original parser.

Keep up with the latest Advogato features by reading the Advogato status blog.

If you're a C programmer with some spare time, take a look at the mod_virgule project page and help us with one of the tasks on the ToDo list!