Control speculation refers to the execution of instructions before it has been determined that they would be executed in the normal flow of execution. Data speculation refers to the execution of instructions with potentially incorrect operand values, and a typical example is to execute a load before its preceding aliasing stores. Both types of speculation are effective techniques to enrich instruction level parallelism, but the research work for these two types of speculation have remained largely independent so far and the required compiler support has not been well studied. This paper proposes a unified compiler framework to exploit both control and data speculation and provides an in-depth discussion of various compilation issues. The adopted recovery mechanism guarantees the original program semantics including exceptions fully recoverable from a mis-speculation. Cascaded speculation and predication are also addressed. We demonstrate the effectiveness of the compiler optimization techniques for control and data speculation in terms of run-time performance improvements and code size increases through experimental results.