File tree Expand file tree Collapse file tree 2 files changed +41
-0
lines changed
Expand file tree Collapse file tree 2 files changed +41
-0
lines changed Original file line number Diff line number Diff line change @@ -742,6 +742,29 @@ inline SILFunction *SILInstruction::getFunction() const {
742742 return getParent ()->getParent ();
743743}
744744
745+ inline bool SILInstruction::visitPriorInstructions (
746+ llvm::function_ref<bool (SILInstruction *)> visitor) {
747+ if (auto *previous = getPreviousInstruction ()) {
748+ return visitor (previous);
749+ }
750+ for (auto *predecessor : getParent ()->getPredecessorBlocks ()) {
751+ if (!visitor (&predecessor->back ()))
752+ return false ;
753+ }
754+ return true ;
755+ }
756+ inline bool SILInstruction::visitSubsequentInstructions (
757+ llvm::function_ref<bool (SILInstruction *)> visitor) {
758+ if (auto *next = getNextInstruction ()) {
759+ return visitor (next);
760+ }
761+ for (auto *successor : getParent ()->getSuccessorBlocks ()) {
762+ if (!visitor (&successor->front ()))
763+ return false ;
764+ }
765+ return true ;
766+ }
767+
745768inline SILInstruction *SILInstruction::getPreviousInstruction () {
746769 auto pos = getIterator ();
747770 return pos == getParent ()->begin () ? nullptr : &*std::prev (pos);
Original file line number Diff line number Diff line change @@ -517,6 +517,24 @@ class SILInstruction : public llvm::ilist_node<SILInstruction> {
517517 // / instruction in its block.
518518 SILInstruction *getNextInstruction ();
519519
520+ // / Calls \p visitor with each instruction that is immediately prior. Returns
521+ // / false and stops visiting if \p visitor returns false.
522+ // /
523+ // / If \p this is is the first instruction in a block, then \p visitor is
524+ // / called with the back of each predecessor. In particular if \p this is
525+ // / the first instruction of the entry block, \p visitor is never called.
526+ bool
527+ visitPriorInstructions (llvm::function_ref<bool (SILInstruction *)> visitor);
528+
529+ // / Calls \p visitor with each instruction that is immediately subsequent.
530+ // / Returns false and stops visiting if \p visitor returns false.
531+ // /
532+ // / If \p this is the last instruction in a block, then \p visitor is called
533+ // / with the front of each successor. In particular if \p this is the last
534+ // / instruction of a block without successors, \p visitor is never called.
535+ bool visitSubsequentInstructions (
536+ llvm::function_ref<bool (SILInstruction *)> visitor);
537+
520538 // / This method unlinks 'self' from the containing basic block and deletes it.
521539 void eraseFromParent ();
522540
You can’t perform that action at this time.
0 commit comments