private List < Instruction > reduceInstructionsInternal ( final List < Instruction > instructions ) { final List < Instruction > visitedInstructions = new LinkedList <> ( ) ; final Set < Integer > visitedInstructionPositions = new HashSet <> ( ) ; final Set < Integer > handledLoadIndexes = new HashSet <> ( ) ; final Set < Integer > backtrackPositions = new LinkedHashSet <> ( findSortedBacktrackPositions ( ) ) ; while ( ! visitedInstructionPositions . containsAll ( backtrackPositions ) ) { // unvisited backtrack position final int backtrackPosition = backtrackPositions . stream ( ) . filter ( pos -> ! visitedInstructionPositions . contains ( pos ) ) . findFirst ( ) . orElseThrow ( IllegalStateException :: new ) ; final List < Integer > lastVisitedPositions = stackSizeSimulator . simulateStatementBackwards ( backtrackPosition ) ; final List < Instruction > lastVisitedInstructions = lastVisitedPositions . stream ( ) . map ( instructions :: get ) . collect ( Collectors . toList ( ) ) ; visitedInstructionPositions . addAll ( lastVisitedPositions ) ; visitedInstructions . addAll ( lastVisitedInstructions ) ; // unhandled load indexes final Set < Integer > unhandledLoadIndexes = findUnhandledLoadIndexes ( handledLoadIndexes , lastVisitedInstructions ) ; // for each load occurrence index -> find load/store backtrack positions (reverse order matters here) final SortedSet < Integer > loadStoreBacktrackPositions = findLoadStoreBacktrackPositions ( unhandledLoadIndexes ) ; handledLoadIndexes . addAll ( unhandledLoadIndexes ) ; loadStoreBacktrackPositions . stream ( ) . forEach ( backtrackPositions :: add ) ; } // sort in method natural order Collections . reverse ( visitedInstructions ) ; return visitedInstructions ; }
Returns all reduced instructions .