Joint optimization of phase diversity and adaptive optics