Maria Sharapova booked her place in the last four of the Madrid Open after edging a tight quarter-final against second seed Li Na 2-6 7-6 (7-5) 6-3.