StackMapPrinter.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. //===-------- StackMapPrinter.h - Pretty-print stackmaps --------*- C++ -*-===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. #ifndef LLVM_TOOLS_LLVM_READOBJ_STACKMAPPRINTER_H
  9. #define LLVM_TOOLS_LLVM_READOBJ_STACKMAPPRINTER_H
  10. #include "llvm/Object/StackMapParser.h"
  11. #include "llvm/Support/ScopedPrinter.h"
  12. namespace llvm {
  13. // Pretty print a stackmap to the given ostream.
  14. template <typename StackMapParserT>
  15. void prettyPrintStackMap(ScopedPrinter &W, const StackMapParserT &SMP) {
  16. W.printNumber("LLVM StackMap Version", SMP.getVersion());
  17. W.printNumber("Num Functions", SMP.getNumFunctions());
  18. // Functions:
  19. for (const auto &F : SMP.functions())
  20. W.startLine() << " Function address: " << F.getFunctionAddress()
  21. << ", stack size: " << F.getStackSize()
  22. << ", callsite record count: " << F.getRecordCount() << "\n";
  23. // Constants:
  24. W.printNumber("Num Constants", SMP.getNumConstants());
  25. unsigned ConstantIndex = 0;
  26. for (const auto &C : SMP.constants())
  27. W.startLine() << " #" << ++ConstantIndex << ": " << C.getValue() << "\n";
  28. // Records:
  29. W.printNumber("Num Records", SMP.getNumRecords());
  30. for (const auto &R : SMP.records()) {
  31. W.startLine() << " Record ID: " << R.getID()
  32. << ", instruction offset: " << R.getInstructionOffset()
  33. << "\n";
  34. W.startLine() << " " << R.getNumLocations() << " locations:\n";
  35. unsigned LocationIndex = 0;
  36. for (const auto &Loc : R.locations()) {
  37. raw_ostream &OS = W.startLine();
  38. OS << " #" << ++LocationIndex << ": ";
  39. switch (Loc.getKind()) {
  40. case StackMapParserT::LocationKind::Register:
  41. OS << "Register R#" << Loc.getDwarfRegNum();
  42. break;
  43. case StackMapParserT::LocationKind::Direct:
  44. OS << "Direct R#" << Loc.getDwarfRegNum() << " + " << Loc.getOffset();
  45. break;
  46. case StackMapParserT::LocationKind::Indirect:
  47. OS << "Indirect [R#" << Loc.getDwarfRegNum() << " + " << Loc.getOffset()
  48. << "]";
  49. break;
  50. case StackMapParserT::LocationKind::Constant:
  51. OS << "Constant " << Loc.getSmallConstant();
  52. break;
  53. case StackMapParserT::LocationKind::ConstantIndex:
  54. OS << "ConstantIndex #" << Loc.getConstantIndex() << " ("
  55. << SMP.getConstant(Loc.getConstantIndex()).getValue() << ")";
  56. break;
  57. }
  58. OS << ", size: " << Loc.getSizeInBytes() << "\n";
  59. }
  60. raw_ostream &OS = W.startLine();
  61. OS << " " << R.getNumLiveOuts() << " live-outs: [ ";
  62. for (const auto &LO : R.liveouts())
  63. OS << "R#" << LO.getDwarfRegNum() << " ("
  64. << LO.getSizeInBytes() << "-bytes) ";
  65. OS << "]\n";
  66. }
  67. }
  68. }
  69. #endif