Morse theory for the Allen-Cahn functional