How long should a compile of a single C file with a vast number of macros take?

A colleague of mine wrote some test cases in a single huge C file with a
lot of macros.

GCC takes a few seconds to compile the file, but Clang takes apparently
more than 10 minutes - I canceled it at that point.

How can I track down the problem? I guess C-Reduce won't cut it this
time, because it's a performance problem.


// Oliver

Hi Oliver,

There are several things you can do to at least isolate which part of the compiler is at “fault”.

  1. Try to compile with -E to produce the preprocess file.
  2. Try to compile the preprocess file with -O0 -emit-llvm -S -o file.ll to produce the llvm-ir.
  3. Try to compile the llvm-ir file with opt with your optimization level to see if it is the high level optimizations passes. (e.g., opt -O3 file.ll -S -o after_opt.ll).
  4. Try to compile the produced after_opt.ll with llc to see if it is a low-level optimization problem, e.g. llc after_opt.ll -o out.s -O3.

Hopefully, one of this step will take a lot of time and will be the faulty part.
When you have that, filing a bug would be the right thing to do.



Assuming the program does actually terminate, you could probably remove some amount of stuff from the macro or some number of macro calls to reduce the severity but still demonstrate the contrast (5 sec to 5min, etc or whatever).

once you’ve got something that finishes, assuming it still demonstrates a substantial performance difference, you could look into profiling, etc - and/or simplifying the code to provide a clear reduced example for other people to investigate