In this paper, we propose a novel method for designing all-optical logic gates based on the coherent perfect absorption principle in graphene-based metasurface in terahertz (THz) region. The proposed structure allows us to access AND, OR, and XOR logic operations by adjusting the relative phase difference of two input signals and creating destructive and/or constructive interference. We have calculated the contrast ratio to analyze the performance of these logic gates. The working frequency of the proposed logic gates can be manipulated by varying the gate-controlled Fermi energy of graphene. These structures can be used in ultrafast all-optical signal processing and ultra-compact integrated circuits.