Lang Hames | 0000afd | 2015-06-26 23:56:53 +0000 | [diff] [blame] | 1 | //===-------- StackMapPrinter.h - Pretty-print stackmaps --------*- C++ -*-===// |
| 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 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 |
Lang Hames | 0000afd | 2015-06-26 23:56:53 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #ifndef LLVM_TOOLS_LLVM_READOBJ_STACKMAPPRINTER_H |
| 10 | #define LLVM_TOOLS_LLVM_READOBJ_STACKMAPPRINTER_H |
| 11 | |
| 12 | #include "llvm/Object/StackMapParser.h" |
Sam Clegg | 88e9a15 | 2018-01-10 00:14:19 +0000 | [diff] [blame] | 13 | #include "llvm/Support/ScopedPrinter.h" |
Lang Hames | 0000afd | 2015-06-26 23:56:53 +0000 | [diff] [blame] | 14 | |
| 15 | namespace llvm { |
| 16 | |
| 17 | // Pretty print a stackmap to the given ostream. |
Sam Clegg | 88e9a15 | 2018-01-10 00:14:19 +0000 | [diff] [blame] | 18 | template <typename StackMapParserT> |
| 19 | void prettyPrintStackMap(ScopedPrinter &W, const StackMapParserT &SMP) { |
Lang Hames | 0000afd | 2015-06-26 23:56:53 +0000 | [diff] [blame] | 20 | |
Sam Clegg | 88e9a15 | 2018-01-10 00:14:19 +0000 | [diff] [blame] | 21 | W.printNumber("LLVM StackMap Version", SMP.getVersion()); |
| 22 | W.printNumber("Num Functions", SMP.getNumFunctions()); |
Lang Hames | 0000afd | 2015-06-26 23:56:53 +0000 | [diff] [blame] | 23 | |
| 24 | // Functions: |
| 25 | for (const auto &F : SMP.functions()) |
Sam Clegg | 88e9a15 | 2018-01-10 00:14:19 +0000 | [diff] [blame] | 26 | W.startLine() << " Function address: " << F.getFunctionAddress() |
Sanjoy Das | 23f06e5 | 2016-09-14 20:22:03 +0000 | [diff] [blame] | 27 | << ", stack size: " << F.getStackSize() |
Sam Clegg | 88e9a15 | 2018-01-10 00:14:19 +0000 | [diff] [blame] | 28 | << ", callsite record count: " << F.getRecordCount() << "\n"; |
Lang Hames | 0000afd | 2015-06-26 23:56:53 +0000 | [diff] [blame] | 29 | |
| 30 | // Constants: |
Sam Clegg | 88e9a15 | 2018-01-10 00:14:19 +0000 | [diff] [blame] | 31 | W.printNumber("Num Constants", SMP.getNumConstants()); |
Lang Hames | 0000afd | 2015-06-26 23:56:53 +0000 | [diff] [blame] | 32 | unsigned ConstantIndex = 0; |
| 33 | for (const auto &C : SMP.constants()) |
Sam Clegg | 88e9a15 | 2018-01-10 00:14:19 +0000 | [diff] [blame] | 34 | W.startLine() << " #" << ++ConstantIndex << ": " << C.getValue() << "\n"; |
Lang Hames | 0000afd | 2015-06-26 23:56:53 +0000 | [diff] [blame] | 35 | |
| 36 | // Records: |
Sam Clegg | 88e9a15 | 2018-01-10 00:14:19 +0000 | [diff] [blame] | 37 | W.printNumber("Num Records", SMP.getNumRecords()); |
Lang Hames | 0000afd | 2015-06-26 23:56:53 +0000 | [diff] [blame] | 38 | for (const auto &R : SMP.records()) { |
Sam Clegg | 88e9a15 | 2018-01-10 00:14:19 +0000 | [diff] [blame] | 39 | W.startLine() << " Record ID: " << R.getID() |
| 40 | << ", instruction offset: " << R.getInstructionOffset() |
| 41 | << "\n"; |
| 42 | W.startLine() << " " << R.getNumLocations() << " locations:\n"; |
Lang Hames | 0000afd | 2015-06-26 23:56:53 +0000 | [diff] [blame] | 43 | |
| 44 | unsigned LocationIndex = 0; |
| 45 | for (const auto &Loc : R.locations()) { |
Sam Clegg | 88e9a15 | 2018-01-10 00:14:19 +0000 | [diff] [blame] | 46 | raw_ostream &OS = W.startLine(); |
| 47 | OS << " #" << ++LocationIndex << ": "; |
Lang Hames | 0000afd | 2015-06-26 23:56:53 +0000 | [diff] [blame] | 48 | switch (Loc.getKind()) { |
| 49 | case StackMapParserT::LocationKind::Register: |
Philip Reames | eea989a | 2019-04-13 03:08:45 +0000 | [diff] [blame] | 50 | OS << "Register R#" << Loc.getDwarfRegNum(); |
Lang Hames | 0000afd | 2015-06-26 23:56:53 +0000 | [diff] [blame] | 51 | break; |
| 52 | case StackMapParserT::LocationKind::Direct: |
Philip Reames | eea989a | 2019-04-13 03:08:45 +0000 | [diff] [blame] | 53 | OS << "Direct R#" << Loc.getDwarfRegNum() << " + " << Loc.getOffset(); |
Lang Hames | 0000afd | 2015-06-26 23:56:53 +0000 | [diff] [blame] | 54 | break; |
| 55 | case StackMapParserT::LocationKind::Indirect: |
Sam Clegg | 88e9a15 | 2018-01-10 00:14:19 +0000 | [diff] [blame] | 56 | OS << "Indirect [R#" << Loc.getDwarfRegNum() << " + " << Loc.getOffset() |
Philip Reames | eea989a | 2019-04-13 03:08:45 +0000 | [diff] [blame] | 57 | << "]"; |
Lang Hames | 0000afd | 2015-06-26 23:56:53 +0000 | [diff] [blame] | 58 | break; |
| 59 | case StackMapParserT::LocationKind::Constant: |
Philip Reames | eea989a | 2019-04-13 03:08:45 +0000 | [diff] [blame] | 60 | OS << "Constant " << Loc.getSmallConstant(); |
Lang Hames | 0000afd | 2015-06-26 23:56:53 +0000 | [diff] [blame] | 61 | break; |
| 62 | case StackMapParserT::LocationKind::ConstantIndex: |
| 63 | OS << "ConstantIndex #" << Loc.getConstantIndex() << " (" |
Philip Reames | eea989a | 2019-04-13 03:08:45 +0000 | [diff] [blame] | 64 | << SMP.getConstant(Loc.getConstantIndex()).getValue() << ")"; |
Lang Hames | 0000afd | 2015-06-26 23:56:53 +0000 | [diff] [blame] | 65 | break; |
| 66 | } |
Philip Reames | eea989a | 2019-04-13 03:08:45 +0000 | [diff] [blame] | 67 | OS << ", size: " << Loc.getSizeInBytes() << "\n"; |
Lang Hames | 0000afd | 2015-06-26 23:56:53 +0000 | [diff] [blame] | 68 | } |
| 69 | |
Sam Clegg | 88e9a15 | 2018-01-10 00:14:19 +0000 | [diff] [blame] | 70 | raw_ostream &OS = W.startLine(); |
| 71 | OS << " " << R.getNumLiveOuts() << " live-outs: [ "; |
Lang Hames | 0000afd | 2015-06-26 23:56:53 +0000 | [diff] [blame] | 72 | for (const auto &LO : R.liveouts()) |
| 73 | OS << "R#" << LO.getDwarfRegNum() << " (" |
| 74 | << LO.getSizeInBytes() << "-bytes) "; |
| 75 | OS << "]\n"; |
| 76 | } |
Lang Hames | 0000afd | 2015-06-26 23:56:53 +0000 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | } |
| 80 | |
| 81 | #endif |