1. A computer-implemented method for compiling code, comprising: identifying critical sections in the code; minimizing the identified critical sections; constructing an instruction dependence graph of instructions in the code; generating a summarized dependence graph based on the instruction dependence graph; and merging at least two of the critical sections based on the summarized dependence graph; wherein the summarized dependence graph includes only instructions for resource accesses and instructions that start and release the critical sections; and wherein minimizing the critical sections comprises using multiple threads to hide resource access latencies and using computations out of a critical section to hide resource access latency original in the critical section.