blob: 77a054b178a523dca428885bcf68ded05f3d7258 [file] [log] [blame]
Lang Hames63f40542015-06-26 23:56:53 +00001//===-------- StackMapPrinter.h - Pretty-print stackmaps --------*- 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
10#ifndef LLVM_TOOLS_LLVM_READOBJ_STACKMAPPRINTER_H
11#define LLVM_TOOLS_LLVM_READOBJ_STACKMAPPRINTER_H
12
13#include "llvm/Object/StackMapParser.h"
Sam Clegg52483262018-01-10 00:14:19 +000014#include "llvm/Support/ScopedPrinter.h"
Lang Hames63f40542015-06-26 23:56:53 +000015
16namespace llvm {
17
18// Pretty print a stackmap to the given ostream.
Sam Clegg52483262018-01-10 00:14:19 +000019template <typename StackMapParserT>
20void prettyPrintStackMap(ScopedPrinter &W, const StackMapParserT &SMP) {
Lang Hames63f40542015-06-26 23:56:53 +000021
Sam Clegg52483262018-01-10 00:14:19 +000022 W.printNumber("LLVM StackMap Version", SMP.getVersion());
23 W.printNumber("Num Functions", SMP.getNumFunctions());
Lang Hames63f40542015-06-26 23:56:53 +000024
25 // Functions:
26 for (const auto &F : SMP.functions())
Sam Clegg52483262018-01-10 00:14:19 +000027 W.startLine() << " Function address: " << F.getFunctionAddress()
Sanjoy Das9becdee2016-09-14 20:22:03 +000028 << ", stack size: " << F.getStackSize()
Sam Clegg52483262018-01-10 00:14:19 +000029 << ", callsite record count: " << F.getRecordCount() << "\n";
Lang Hames63f40542015-06-26 23:56:53 +000030
31 // Constants:
Sam Clegg52483262018-01-10 00:14:19 +000032 W.printNumber("Num Constants", SMP.getNumConstants());
Lang Hames63f40542015-06-26 23:56:53 +000033 unsigned ConstantIndex = 0;
34 for (const auto &C : SMP.constants())
Sam Clegg52483262018-01-10 00:14:19 +000035 W.startLine() << " #" << ++ConstantIndex << ": " << C.getValue() << "\n";
Lang Hames63f40542015-06-26 23:56:53 +000036
37 // Records:
Sam Clegg52483262018-01-10 00:14:19 +000038 W.printNumber("Num Records", SMP.getNumRecords());
Lang Hames63f40542015-06-26 23:56:53 +000039 for (const auto &R : SMP.records()) {
Sam Clegg52483262018-01-10 00:14:19 +000040 W.startLine() << " Record ID: " << R.getID()
41 << ", instruction offset: " << R.getInstructionOffset()
42 << "\n";
43 W.startLine() << " " << R.getNumLocations() << " locations:\n";
Lang Hames63f40542015-06-26 23:56:53 +000044
45 unsigned LocationIndex = 0;
46 for (const auto &Loc : R.locations()) {
Sam Clegg52483262018-01-10 00:14:19 +000047 raw_ostream &OS = W.startLine();
48 OS << " #" << ++LocationIndex << ": ";
Lang Hames63f40542015-06-26 23:56:53 +000049 switch (Loc.getKind()) {
50 case StackMapParserT::LocationKind::Register:
Sam Clegg52483262018-01-10 00:14:19 +000051 OS << "Register R#" << Loc.getDwarfRegNum() << "\n";
Lang Hames63f40542015-06-26 23:56:53 +000052 break;
53 case StackMapParserT::LocationKind::Direct:
Sam Clegg52483262018-01-10 00:14:19 +000054 OS << "Direct R#" << Loc.getDwarfRegNum() << " + " << Loc.getOffset()
55 << "\n";
Lang Hames63f40542015-06-26 23:56:53 +000056 break;
57 case StackMapParserT::LocationKind::Indirect:
Sam Clegg52483262018-01-10 00:14:19 +000058 OS << "Indirect [R#" << Loc.getDwarfRegNum() << " + " << Loc.getOffset()
59 << "]\n";
Lang Hames63f40542015-06-26 23:56:53 +000060 break;
61 case StackMapParserT::LocationKind::Constant:
Sam Clegg52483262018-01-10 00:14:19 +000062 OS << "Constant " << Loc.getSmallConstant() << "\n";
Lang Hames63f40542015-06-26 23:56:53 +000063 break;
64 case StackMapParserT::LocationKind::ConstantIndex:
65 OS << "ConstantIndex #" << Loc.getConstantIndex() << " ("
Sam Clegg52483262018-01-10 00:14:19 +000066 << SMP.getConstant(Loc.getConstantIndex()).getValue() << ")\n";
Lang Hames63f40542015-06-26 23:56:53 +000067 break;
68 }
69 }
70
Sam Clegg52483262018-01-10 00:14:19 +000071 raw_ostream &OS = W.startLine();
72 OS << " " << R.getNumLiveOuts() << " live-outs: [ ";
Lang Hames63f40542015-06-26 23:56:53 +000073 for (const auto &LO : R.liveouts())
74 OS << "R#" << LO.getDwarfRegNum() << " ("
75 << LO.getSizeInBytes() << "-bytes) ";
76 OS << "]\n";
77 }
Lang Hames63f40542015-06-26 23:56:53 +000078}
79
80}
81
82#endif