Path: blob/main/contrib/llvm-project/llvm/tools/llvm-readobj/StackMapPrinter.h
35231 views
//===-------- StackMapPrinter.h - Pretty-print stackmaps --------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#ifndef LLVM_TOOLS_LLVM_READOBJ_STACKMAPPRINTER_H9#define LLVM_TOOLS_LLVM_READOBJ_STACKMAPPRINTER_H1011#include "llvm/Object/StackMapParser.h"12#include "llvm/Support/ScopedPrinter.h"1314namespace llvm {1516// Pretty print a stackmap to the given ostream.17template <typename StackMapParserT>18void prettyPrintStackMap(ScopedPrinter &W, const StackMapParserT &SMP) {1920W.printNumber("LLVM StackMap Version", SMP.getVersion());21W.printNumber("Num Functions", SMP.getNumFunctions());2223// Functions:24for (const auto &F : SMP.functions())25W.startLine() << " Function address: " << F.getFunctionAddress()26<< ", stack size: " << F.getStackSize()27<< ", callsite record count: " << F.getRecordCount() << "\n";2829// Constants:30W.printNumber("Num Constants", SMP.getNumConstants());31unsigned ConstantIndex = 0;32for (const auto &C : SMP.constants())33W.startLine() << " #" << ++ConstantIndex << ": " << C.getValue() << "\n";3435// Records:36W.printNumber("Num Records", SMP.getNumRecords());37for (const auto &R : SMP.records()) {38W.startLine() << " Record ID: " << R.getID()39<< ", instruction offset: " << R.getInstructionOffset()40<< "\n";41W.startLine() << " " << R.getNumLocations() << " locations:\n";4243unsigned LocationIndex = 0;44for (const auto &Loc : R.locations()) {45raw_ostream &OS = W.startLine();46OS << " #" << ++LocationIndex << ": ";47switch (Loc.getKind()) {48case StackMapParserT::LocationKind::Register:49OS << "Register R#" << Loc.getDwarfRegNum();50break;51case StackMapParserT::LocationKind::Direct:52OS << "Direct R#" << Loc.getDwarfRegNum() << " + " << Loc.getOffset();53break;54case StackMapParserT::LocationKind::Indirect:55OS << "Indirect [R#" << Loc.getDwarfRegNum() << " + " << Loc.getOffset()56<< "]";57break;58case StackMapParserT::LocationKind::Constant:59OS << "Constant " << Loc.getSmallConstant();60break;61case StackMapParserT::LocationKind::ConstantIndex:62OS << "ConstantIndex #" << Loc.getConstantIndex() << " ("63<< SMP.getConstant(Loc.getConstantIndex()).getValue() << ")";64break;65}66OS << ", size: " << Loc.getSizeInBytes() << "\n";67}6869raw_ostream &OS = W.startLine();70OS << " " << R.getNumLiveOuts() << " live-outs: [ ";71for (const auto &LO : R.liveouts())72OS << "R#" << LO.getDwarfRegNum() << " ("73<< LO.getSizeInBytes() << "-bytes) ";74OS << "]\n";75}76}7778}7980#endif818283