Path: blob/main/contrib/llvm-project/llvm/lib/CodeGen/DroppedVariableStatsMIR.cpp
213765 views
///===- DroppedVariableStatsMIR.cpp ---------------------------------------===//1///2/// Part of the LLVM Project, under the Apache License v2.0 with LLVM3/// Exceptions. See https://llvm.org/LICENSE.txt for license information.4/// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5///6///===---------------------------------------------------------------------===//7/// \file8/// Dropped Variable Statistics for Debug Information. Reports any number9/// of DBG_VALUEs that get dropped due to an optimization pass.10///11///===---------------------------------------------------------------------===//1213#include "llvm/CodeGen/DroppedVariableStatsMIR.h"14#include "llvm/IR/DebugInfoMetadata.h"1516using namespace llvm;1718void DroppedVariableStatsMIR::runBeforePass(StringRef PassID,19MachineFunction *MF) {20if (PassID == "Debug Variable Analysis")21return;22setup();23return runOnMachineFunction(MF, true);24}2526void DroppedVariableStatsMIR::runAfterPass(StringRef PassID,27MachineFunction *MF) {28if (PassID == "Debug Variable Analysis")29return;30runOnMachineFunction(MF, false);31calculateDroppedVarStatsOnMachineFunction(MF, PassID, MF->getName().str());32cleanup();33}3435void DroppedVariableStatsMIR::runOnMachineFunction(const MachineFunction *MF,36bool Before) {37auto &DebugVariables = DebugVariablesStack.back()[&MF->getFunction()];38auto FuncName = MF->getName();39MFunc = MF;40run(DebugVariables, FuncName, Before);41}4243void DroppedVariableStatsMIR::calculateDroppedVarStatsOnMachineFunction(44const MachineFunction *MF, StringRef PassID, StringRef FuncOrModName) {45MFunc = MF;46StringRef FuncName = MF->getName();47const Function *Func = &MF->getFunction();48DebugVariables &DbgVariables = DebugVariablesStack.back()[Func];49calculateDroppedStatsAndPrint(DbgVariables, FuncName, PassID, FuncOrModName,50"MachineFunction", Func);51}5253void DroppedVariableStatsMIR::visitEveryInstruction(54unsigned &DroppedCount, DenseMap<VarID, DILocation *> &InlinedAtsMap,55VarID Var) {56unsigned PrevDroppedCount = DroppedCount;57const DIScope *DbgValScope = std::get<0>(Var);58for (const auto &MBB : *MFunc) {59for (const auto &MI : MBB) {60if (!MI.isDebugInstr()) {61auto *DbgLoc = MI.getDebugLoc().get();62if (!DbgLoc)63continue;6465auto *Scope = DbgLoc->getScope();66if (updateDroppedCount(DbgLoc, Scope, DbgValScope, InlinedAtsMap, Var,67DroppedCount))68break;69}70}71if (PrevDroppedCount != DroppedCount) {72PrevDroppedCount = DroppedCount;73break;74}75}76}7778void DroppedVariableStatsMIR::visitEveryDebugRecord(79DenseSet<VarID> &VarIDSet,80DenseMap<StringRef, DenseMap<VarID, DILocation *>> &InlinedAtsMap,81StringRef FuncName, bool Before) {82for (const auto &MBB : *MFunc) {83for (const auto &MI : MBB) {84if (MI.isDebugValueLike()) {85auto *DbgVar = MI.getDebugVariable();86if (!DbgVar)87continue;88auto DbgLoc = MI.getDebugLoc();89populateVarIDSetAndInlinedMap(DbgVar, DbgLoc, VarIDSet, InlinedAtsMap,90FuncName, Before);91}92}93}94}959697