Maria Sharapova overcame Ana Ivanovic in three sets to reach the semi-finals of the WTA Porsche Grand Prix in Stuttgart.