How to determine what a compiler does with a metaprogram? (for boost.proto)

How to determine what my compiler (g ++) does with template code?

I use boost.proto (expression template library) to evaluate some math expressions at compile time. The code correctly evaluates expressions, but I would like to know if the compiler has expanded the expression to the equivalent of hand-written c-code (i.e., removed all temporary ones) or there are some additional compile-time optimizations to do.

Is there any way to see what the compiler did with the templates?

thanks

+4
source share
2 answers

There are several ways to see C ++ code after passing through the template instance:

  • Use gcc -fdump-tree-original (or even -fdump-tree-all to see more passes)
  • Use Elsa C ++ parser: http://scottmcpeak.com/elkhound/sources/elsa/
  • Use Clang and LLVM C backend - the latter will give the most unreadable code, but in some cases it is still useful. Clang should also have some AST reset functions.
+2
source
 g++ -S 

is documented as "Only compilation, don’t compile or link." Basically you get the assembly.

+2
source

All Articles