The TeamPlay project developed advanced energy modelling techniques, energy models, and resource analysis techniques which statically predict the energy consumed by programs. A demo is available here.
When combined with a compiler the users may obtain energy consumption estimates as a by-product of compilation. Alternatively, they may ask your compiler to generate the most energy efficient code it can find, which is achieved through the use of powerful constraint solvers.