Mode directed tabling combined with subgoal sharing