blob: ef757564026880338383b40009835888a6b6968f [file] [log] [blame]
Lang Hames0000afd2015-06-26 23:56:53 +00001//===-------- StackMapPrinter.h - Pretty-print stackmaps --------*- C++ -*-===//
2//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// 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 Hames0000afd2015-06-26 23:56:53 +00006//
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 Clegg88e9a152018-01-10 00:14:19 +000013#include "llvm/Support/ScopedPrinter.h"
Lang Hames0000afd2015-06-26 23:56:53 +000014
15namespace llvm {
16
17// Pretty print a stackmap to the given ostream.
Sam Clegg88e9a152018-01-10 00:14:19 +000018template <typename StackMapParserT>
19void prettyPrintStackMap(ScopedPrinter &W, const StackMapParserT &SMP) {
Lang Hames0000afd2015-06-26 23:56:53 +000020
Sam Clegg88e9a152018-01-10 00:14:19 +000021 W.printNumber("LLVM StackMap Version", SMP.getVersion());
22 W.printNumber("Num Functions", SMP.getNumFunctions());
Lang Hames0000afd2015-06-26 23:56:53 +000023
24 // Functions:
25 for (const auto &F : SMP.functions())
Sam Clegg88e9a152018-01-10 00:14:19 +000026 W.startLine() << " Function address: " << F.getFunctionAddress()
Sanjoy Das23f06e52016-09-14 20:22:03 +000027 << ", stack size: " << F.getStackSize()
Sam Clegg88e9a152018-01-10 00:14:19 +000028 << ", callsite record count: " << F.getRecordCount() << "\n";
Lang Hames0000afd2015-06-26 23:56:53 +000029
30 // Constants:
Sam Clegg88e9a152018-01-10 00:14:19 +000031 W.printNumber("Num Constants", SMP.getNumConstants());
Lang Hames0000afd2015-06-26 23:56:53 +000032 unsigned ConstantIndex = 0;
33 for (const auto &C : SMP.constants())
Sam Clegg88e9a152018-01-10 00:14:19 +000034 W.startLine() << " #" << ++ConstantIndex << ": " << C.getValue() << "\n";
Lang Hames0000afd2015-06-26 23:56:53 +000035
36 // Records:
Sam Clegg88e9a152018-01-10 00:14:19 +000037 W.printNumber("Num Records", SMP.getNumRecords());
Lang Hames0000afd2015-06-26 23:56:53 +000038 for (const auto &R : SMP.records()) {
Sam Clegg88e9a152018-01-10 00:14:19 +000039 W.startLine() << " Record ID: " << R.getID()
40 << ", instruction offset: " << R.getInstructionOffset()
41 << "\n";
42 W.startLine() << " " << R.getNumLocations() << " locations:\n";
Lang Hames0000afd2015-06-26 23:56:53 +000043
44 unsigned LocationIndex = 0;
45 for (const auto &Loc : R.locations()) {
Sam Clegg88e9a152018-01-10 00:14:19 +000046 raw_ostream &OS = W.startLine();
47 OS << " #" << ++LocationIndex << ": ";
Lang Hames0000afd2015-06-26 23:56:53 +000048 switch (Loc.getKind()) {
49 case StackMapParserT::LocationKind::Register:
Philip Reameseea989a2019-04-13 03:08:45 +000050 OS << "Register R#" << Loc.getDwarfRegNum();
Lang Hames0000afd2015-06-26 23:56:53 +000051 break;
52 case StackMapParserT::LocationKind::Direct:
Philip Reameseea989a2019-04-13 03:08:45 +000053 OS << "Direct R#" << Loc.getDwarfRegNum() << " + " << Loc.getOffset();
Lang Hames0000afd2015-06-26 23:56:53 +000054 break;
55 case StackMapParserT::LocationKind::Indirect:
Sam Clegg88e9a152018-01-10 00:14:19 +000056 OS << "Indirect [R#" << Loc.getDwarfRegNum() << " + " << Loc.getOffset()
Philip Reameseea989a2019-04-13 03:08:45 +000057 << "]";
Lang Hames0000afd2015-06-26 23:56:53 +000058 break;
59 case StackMapParserT::LocationKind::Constant:
Philip Reameseea989a2019-04-13 03:08:45 +000060 OS << "Constant " << Loc.getSmallConstant();
Lang Hames0000afd2015-06-26 23:56:53 +000061 break;
62 case StackMapParserT::LocationKind::ConstantIndex:
63 OS << "ConstantIndex #" << Loc.getConstantIndex() << " ("
Philip Reameseea989a2019-04-13 03:08:45 +000064 << SMP.getConstant(Loc.getConstantIndex()).getValue() << ")";
Lang Hames0000afd2015-06-26 23:56:53 +000065 break;
66 }
Philip Reameseea989a2019-04-13 03:08:45 +000067 OS << ", size: " << Loc.getSizeInBytes() << "\n";
Lang Hames0000afd2015-06-26 23:56:53 +000068 }
69
Sam Clegg88e9a152018-01-10 00:14:19 +000070 raw_ostream &OS = W.startLine();
71 OS << " " << R.getNumLiveOuts() << " live-outs: [ ";
Lang Hames0000afd2015-06-26 23:56:53 +000072 for (const auto &LO : R.liveouts())
73 OS << "R#" << LO.getDwarfRegNum() << " ("
74 << LO.getSizeInBytes() << "-bytes) ";
75 OS << "]\n";
76 }
Lang Hames0000afd2015-06-26 23:56:53 +000077}
78
79}
80
81#endif