#include "llvm/CodeGen/DbgEntityHistoryCalculator.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallSet.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/CodeGen/LexicalScopes.h"
#include "llvm/CodeGen/MachineBasicBlock.h"
#include "llvm/CodeGen/MachineFunction.h"
#include "llvm/CodeGen/MachineInstr.h"
#include "llvm/CodeGen/MachineOperand.h"
#include "llvm/CodeGen/TargetLowering.h"
#include "llvm/CodeGen/TargetRegisterInfo.h"
#include "llvm/CodeGen/TargetSubtargetInfo.h"
#include "llvm/IR/DebugInfoMetadata.h"
#include "llvm/IR/DebugLoc.h"
#include "llvm/MC/MCRegisterInfo.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
#include <cassert>
#include <map>
#include <optional>
#include <utility>
usingnamespacellvm;
#define DEBUG_TYPE …
namespace {
EntryIndex;
}
void InstructionOrdering::initialize(const MachineFunction &MF) { … }
bool InstructionOrdering::isBefore(const MachineInstr *A,
const MachineInstr *B) const { … }
bool DbgValueHistoryMap::startDbgValue(InlinedEntity Var,
const MachineInstr &MI,
EntryIndex &NewIndex) { … }
EntryIndex DbgValueHistoryMap::startClobber(InlinedEntity Var,
const MachineInstr &MI) { … }
void DbgValueHistoryMap::Entry::endEntry(EntryIndex Index) { … }
static std::optional<ArrayRef<InsnRange>::iterator>
intersects(const MachineInstr *StartMI, const MachineInstr *EndMI,
const ArrayRef<InsnRange> &Ranges,
const InstructionOrdering &Ordering) { … }
void DbgValueHistoryMap::trimLocationRanges(
const MachineFunction &MF, LexicalScopes &LScopes,
const InstructionOrdering &Ordering) { … }
bool DbgValueHistoryMap::hasNonEmptyLocation(const Entries &Entries) const { … }
void DbgLabelInstrMap::addInstr(InlinedEntity Label, const MachineInstr &MI) { … }
namespace {
InlinedEntity;
RegDescribedVarsMap;
DbgValueEntriesMap;
}
static void dropRegDescribedVar(RegDescribedVarsMap &RegVars, unsigned RegNo,
InlinedEntity Var) { … }
static void addRegDescribedVar(RegDescribedVarsMap &RegVars, unsigned RegNo,
InlinedEntity Var) { … }
static void clobberRegEntries(InlinedEntity Var, unsigned RegNo,
const MachineInstr &ClobberingInstr,
DbgValueEntriesMap &LiveEntries,
DbgValueHistoryMap &HistMap,
SmallVectorImpl<Register> &FellowRegisters) { … }
static void handleNewDebugValue(InlinedEntity Var, const MachineInstr &DV,
RegDescribedVarsMap &RegVars,
DbgValueEntriesMap &LiveEntries,
DbgValueHistoryMap &HistMap) { … }
static void clobberRegisterUses(RegDescribedVarsMap &RegVars,
RegDescribedVarsMap::iterator I,
DbgValueHistoryMap &HistMap,
DbgValueEntriesMap &LiveEntries,
const MachineInstr &ClobberingInstr) { … }
static void clobberRegisterUses(RegDescribedVarsMap &RegVars, unsigned RegNo,
DbgValueHistoryMap &HistMap,
DbgValueEntriesMap &LiveEntries,
const MachineInstr &ClobberingInstr) { … }
void llvm::calculateDbgEntityHistory(const MachineFunction *MF,
const TargetRegisterInfo *TRI,
DbgValueHistoryMap &DbgValues,
DbgLabelInstrMap &DbgLabels) { … }
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
LLVM_DUMP_METHOD void DbgValueHistoryMap::dump(StringRef FuncName) const {
dbgs() << "DbgValueHistoryMap('" << FuncName << "'):\n";
for (const auto &VarRangePair : *this) {
const InlinedEntity &Var = VarRangePair.first;
const Entries &Entries = VarRangePair.second;
const DILocalVariable *LocalVar = cast<DILocalVariable>(Var.first);
const DILocation *Location = Var.second;
dbgs() << " - " << LocalVar->getName() << " at ";
if (Location)
dbgs() << Location->getFilename() << ":" << Location->getLine() << ":"
<< Location->getColumn();
else
dbgs() << "<unknown location>";
dbgs() << " --\n";
for (const auto &E : enumerate(Entries)) {
const auto &Entry = E.value();
dbgs() << " Entry[" << E.index() << "]: ";
if (Entry.isDbgValue())
dbgs() << "Debug value\n";
else
dbgs() << "Clobber\n";
dbgs() << " Instr: " << *Entry.getInstr();
if (Entry.isDbgValue()) {
if (Entry.getEndIndex() == NoEntry)
dbgs() << " - Valid until end of function\n";
else
dbgs() << " - Closed by Entry[" << Entry.getEndIndex() << "]\n";
}
dbgs() << "\n";
}
}
}
#endif