BlockReadableOrder.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. //===--- BlockReadableOrder.cpp - BlockReadableOrderVisitor impl ----------===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. #include "BlockReadableOrder.h"
  10. namespace clang {
  11. namespace spirv {
  12. void BlockReadableOrderVisitor::visit(BasicBlock *block) {
  13. if (doneBlocks.count(block) || todoBlocks.count(block))
  14. return;
  15. callback(block);
  16. doneBlocks.insert(block);
  17. // Check the continue and merge targets. If any one of them exists, we need
  18. // to make sure visiting it is delayed until we've done the rest.
  19. BasicBlock *continueBlock = block->getContinueTarget();
  20. BasicBlock *mergeBlock = block->getMergeTarget();
  21. if (continueBlock)
  22. todoBlocks.insert(continueBlock);
  23. if (mergeBlock)
  24. todoBlocks.insert(mergeBlock);
  25. for (BasicBlock *successor : block->getSuccessors())
  26. visit(successor);
  27. // Handle continue and merge targets now.
  28. if (continueBlock) {
  29. todoBlocks.erase(continueBlock);
  30. visit(continueBlock);
  31. }
  32. if (mergeBlock) {
  33. todoBlocks.erase(mergeBlock);
  34. visit(mergeBlock);
  35. }
  36. }
  37. } // end namespace spirv
  38. } // end namespace clang