A compiler is a program that translates code written in one programming language into another language. Compilation has two phases - translation and optimization. The basic compilation phases are parsing, symbol table construction, machine-independent optimizations, machine-dependent optimizations, and assembly code generation. Compiler optimizations improve performance by techniques like dead code elimination, loop transformations, register allocation, instruction scheduling, and software pipelining.