Roger Federer reached the Miami Open final for the first time since 2006 with an enthralling win over Nick Kyrgios on Friday.