Modern hardware features can boost the performance of an application, but software vendors are often limited to the lowest common denominator to maintain compatibility with the spectrum of processors used by their clients. Given more detailed information about the hardware features, a compiler can generate more efficient code, but even if the exact CPU model is known, manufacturer confidentiality policies leave substantial uncertainty about precise performance characteristics. In addition, the effectiveness of many optimization techniques can vary depending on the inputs to the program. This thesis introduces two tools, FITTCHOOSER and OFSPER, to do function-level optimizations most suitable for the current runtime environment and data. FI...