Ab initio study of phase stability in doped TiO2