SortDebugInfoVisitor.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. //===--- SortDebugInfoVisitor.h - Debug instrs in Valid order ----*- C++ -*-==//
  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. #ifndef LLVM_CLANG_LIB_SPIRV_SORTDEBUGINFOVISITOR_H
  10. #define LLVM_CLANG_LIB_SPIRV_SORTDEBUGINFOVISITOR_H
  11. #include "clang/SPIRV/SpirvContext.h"
  12. #include "clang/SPIRV/SpirvInstruction.h"
  13. #include "clang/SPIRV/SpirvModule.h"
  14. #include "clang/SPIRV/SpirvVisitor.h"
  15. namespace clang {
  16. namespace spirv {
  17. class SpirvFunction;
  18. class SpirvBasicBlock;
  19. /// The class responsible to sort OpenCL.DebugInfo.100 instructions in a
  20. /// valid order without any invalid forward reference.
  21. class SortDebugInfoVisitor : public Visitor {
  22. public:
  23. SortDebugInfoVisitor(SpirvContext &spvCtx, const SpirvCodeGenOptions &opts)
  24. : Visitor(opts, spvCtx) {}
  25. // Sorts debug instructions in a post order to remove invalid forward
  26. // references. Note that the post order guarantees a successor node is not
  27. // visited before its predecessor and this property can be used to sort
  28. // instructions in a valid layout without any invalid forward reference.
  29. bool visit(SpirvModule *, Phase);
  30. // Visiting different SPIR-V constructs.
  31. bool visit(SpirvFunction *, Phase) { return true; }
  32. bool visit(SpirvBasicBlock *, Phase) { return true; }
  33. /// The "sink" visit function for all instructions.
  34. ///
  35. /// By default, all other visit instructions redirect to this visit function.
  36. /// So that you want override this visit function to handle all instructions,
  37. /// regardless of their polymorphism.
  38. bool visitInstruction(SpirvInstruction *) { return true; }
  39. private:
  40. // Invokes visitor for each operand of the debug instruction `di`. If
  41. // `visitor` returns false, it stops and returns.
  42. void whileEachOperandOfDebugInstruction(
  43. SpirvDebugInstruction *di,
  44. llvm::function_ref<bool(SpirvDebugInstruction *)> visitor);
  45. };
  46. } // end namespace spirv
  47. } // end namespace clang
  48. #endif // LLVM_CLANG_LIB_SPIRV_SORTDEBUGINFOVISITOR_H