1. A computer-implemented method for compiling a thread program, the method comprising: generating a control flow graph (CFG) that describes control flow dependencies among instructions within the thread program; analyzing the CFG to identify a first set of instructions that generate memory requests and a second set of instructions that consume memory requests; and placing a first texture barrier instruction in the thread program based on the control flow dependencies among the instructions within the thread program, wherein an argument associated with the first texture barrier instruction is based on the first set of instructions and the second set of instructions.