Revert "[LiveDebugValues] Emit the debug entry values"

Appears that the 'test/DebugInfo/MIR/X86/dbginfo-entryvals.mir'
does not pass on Windows.

This reverts commit rL364553.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@364571 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Djordje Todorovic
2019-06-27 18:12:04 +00:00
parent c1056cbe8b
commit 6998f5cb03
3 changed files with 20 additions and 301 deletions
+20 -139
View File
@@ -39,7 +39,6 @@
#include "llvm/CodeGen/TargetFrameLowering.h"
#include "llvm/CodeGen/TargetInstrInfo.h"
#include "llvm/CodeGen/TargetLowering.h"
#include "llvm/CodeGen/TargetPassConfig.h"
#include "llvm/CodeGen/TargetRegisterInfo.h"
#include "llvm/CodeGen/TargetSubtargetInfo.h"
#include "llvm/Config/llvm-config.h"
@@ -186,8 +185,7 @@ private:
InvalidKind = 0,
RegisterKind,
SpillLocKind,
ImmediateKind,
EntryValueKind
ImmediateKind
} Kind = InvalidKind;
/// The value location. Stored separately to avoid repeatedly
@@ -201,18 +199,14 @@ private:
const ConstantInt *CImm;
} Loc;
VarLoc(const MachineInstr &MI, LexicalScopes &LS,
VarLocKind K = InvalidKind)
: Var(MI), MI(MI), UVS(MI.getDebugLoc(), LS), Kind(K) {
VarLoc(const MachineInstr &MI, LexicalScopes &LS)
: Var(MI), MI(MI), UVS(MI.getDebugLoc(), LS) {
static_assert((sizeof(Loc) == sizeof(uint64_t)),
"hash does not cover all members of Loc");
assert(MI.isDebugValue() && "not a DBG_VALUE");
assert(MI.getNumOperands() == 4 && "malformed DBG_VALUE");
if (int RegNo = isDbgValueDescribedByReg(MI)) {
assert((!EntryValueKind || RegNo) &&
"entry values must be register locations");
if (Kind != EntryValueKind)
Kind = RegisterKind;
Kind = RegisterKind;
Loc.RegNo = RegNo;
} else if (MI.getOperand(0).isImm()) {
Kind = ImmediateKind;
@@ -247,10 +241,6 @@ private:
return 0;
}
bool isEntryValueKind() const {
return Kind == EntryValueKind;
}
/// Determine whether the lexical scope of this value's debug location
/// dominates MBB.
bool dominates(MachineBasicBlock &MBB) const { return UVS.dominates(&MBB); }
@@ -266,12 +256,12 @@ private:
/// This operator guarantees that VarLocs are sorted by Variable first.
bool operator<(const VarLoc &Other) const {
return std::tie(Var, Kind, Loc.Hash) <
std::tie(Other.Var, Other.Kind, Other.Loc.Hash);
if (Var == Other.Var)
return Loc.Hash < Other.Loc.Hash;
return Var < Other.Var;
}
};
using DebugParamMap = SmallDenseMap<const DILocalVariable *, MachineInstr *>;
using VarLocMap = UniqueVector<VarLoc>;
using VarLocSet = SparseBitVector<>;
using VarLocInMBB = SmallDenseMap<const MachineBasicBlock *, VarLocSet>;
@@ -357,23 +347,17 @@ private:
VarLocMap &VarLocIDs);
void transferSpillOrRestoreInst(MachineInstr &MI, OpenRangesSet &OpenRanges,
VarLocMap &VarLocIDs, TransferMap &Transfers);
void emitEntryValues(MachineInstr &MI, OpenRangesSet &OpenRanges,
VarLocMap &VarLocIDs, TransferMap &Transfers,
DebugParamMap &DebugEntryVals,
SparseBitVector<> &KillSet);
void transferRegisterCopy(MachineInstr &MI, OpenRangesSet &OpenRanges,
VarLocMap &VarLocIDs, TransferMap &Transfers);
void transferRegisterDef(MachineInstr &MI, OpenRangesSet &OpenRanges,
VarLocMap &VarLocIDs, TransferMap &Transfers,
DebugParamMap &DebugEntryVals);
const VarLocMap &VarLocIDs);
bool transferTerminatorInst(MachineInstr &MI, OpenRangesSet &OpenRanges,
VarLocInMBB &OutLocs, const VarLocMap &VarLocIDs);
bool process(MachineInstr &MI, OpenRangesSet &OpenRanges,
VarLocInMBB &OutLocs, VarLocMap &VarLocIDs,
TransferMap &Transfers, DebugParamMap &DebugEntryVals,
bool transferChanges, OverlapMap &OverlapFragments,
VarToFragments &SeenFragments);
TransferMap &Transfers, bool transferChanges,
OverlapMap &OverlapFragments, VarToFragments &SeenFragments);
void accumulateFragmentMap(MachineInstr &MI, VarToFragments &SeenFragments,
OverlapMap &OLapMap);
@@ -564,26 +548,13 @@ void LiveDebugValues::transferDebugValue(const MachineInstr &MI,
OpenRanges.erase(V);
// Add the VarLoc to OpenRanges from this DBG_VALUE.
VarLoc::VarLocKind Kind = VarLoc::InvalidKind;
unsigned ID;
auto FinishVarLoc = [&] (const MachineInstr &MI, VarLoc::VarLocKind &Kind) {
if (isDbgValueDescribedByReg(MI) || MI.getOperand(0).isImm() ||
MI.getOperand(0).isFPImm() || MI.getOperand(0).isCImm()) {
// Use normal VarLoc constructor for registers and immediates.
VarLoc VL(MI, LS, Kind);
VarLoc VL(MI, LS);
ID = VarLocIDs.insert(VL);
OpenRanges.insert(ID, VL.Var);
};
if (isDbgValueDescribedByReg(MI)) {
Kind = VarLoc::RegisterKind;
const DIExpression *Expr = MI.getDebugExpression();
if (Expr->isEntryValue())
Kind = VarLoc::EntryValueKind;
FinishVarLoc(MI, Kind);
} else if (MI.getOperand(0).isImm() ||
MI.getOperand(0).isFPImm() || MI.getOperand(0).isCImm()) {
Kind = VarLoc::ImmediateKind;
FinishVarLoc(MI, Kind);
} else if (MI.hasOneMemOperand()) {
// It's a stack spill -- fetch spill base and offset.
VarLoc::SpillLoc SpillLocation = extractSpillBaseRegAndOffset(MI);
@@ -597,44 +568,6 @@ void LiveDebugValues::transferDebugValue(const MachineInstr &MI,
}
}
void LiveDebugValues::emitEntryValues(MachineInstr &MI,
OpenRangesSet &OpenRanges,
VarLocMap &VarLocIDs,
TransferMap &Transfers,
DebugParamMap &DebugEntryVals,
SparseBitVector<> &KillSet) {
MachineFunction *MF = MI.getParent()->getParent();
for (unsigned ID : KillSet) {
if (!VarLocIDs[ID].Var.getVar()->isParameter())
continue;
const MachineInstr *CurrDebugInstr = &VarLocIDs[ID].MI;
// If parameter's DBG_VALUE is not in the map that means we can't
// generate parameter's entry value.
if (!DebugEntryVals.count(CurrDebugInstr->getDebugVariable()))
continue;
auto ParamDebugInstr = DebugEntryVals[CurrDebugInstr->getDebugVariable()];
DIExpression *NewExpr = DIExpression::prepend(
ParamDebugInstr->getDebugExpression(), DIExpression::EntryValue);
MachineInstr *EntryValDbgMI =
BuildMI(*MF, ParamDebugInstr->getDebugLoc(), ParamDebugInstr->getDesc(),
ParamDebugInstr->isIndirectDebugValue(),
ParamDebugInstr->getOperand(0).getReg(),
ParamDebugInstr->getDebugVariable(), NewExpr);
if (ParamDebugInstr->isIndirectDebugValue())
EntryValDbgMI->getOperand(1).setImm(
ParamDebugInstr->getOperand(1).getImm());
Transfers.push_back({&MI, EntryValDbgMI});
VarLoc VL(*EntryValDbgMI, LS, VarLoc::EntryValueKind);
unsigned EntryValLocID = VarLocIDs.insert(VL);
OpenRanges.insert(EntryValLocID, VL.Var);
}
}
/// Create new TransferDebugPair and insert it in \p Transfers. The VarLoc
/// with \p OldVarID should be deleted form \p OpenRanges and replaced with
/// new VarLoc. If \p NewReg is different than default zero value then the
@@ -725,9 +658,9 @@ void LiveDebugValues::insertTransferDebugPair(
}
/// A definition of a register may mark the end of a range.
void LiveDebugValues::transferRegisterDef(
MachineInstr &MI, OpenRangesSet &OpenRanges, VarLocMap &VarLocIDs,
TransferMap &Transfers, DebugParamMap &DebugEntryVals) {
void LiveDebugValues::transferRegisterDef(MachineInstr &MI,
OpenRangesSet &OpenRanges,
const VarLocMap &VarLocIDs) {
MachineFunction *MF = MI.getMF();
const TargetLowering *TLI = MF->getSubtarget().getTargetLowering();
unsigned SP = TLI->getStackPointerRegisterToSaveRestore();
@@ -757,13 +690,6 @@ void LiveDebugValues::transferRegisterDef(
}
}
OpenRanges.erase(KillSet, VarLocIDs);
if (auto *TPC = getAnalysisIfAvailable<TargetPassConfig>()) {
auto &TM = TPC->getTM<TargetMachine>();
if (TM.Options.EnableDebugEntryValues)
emitEntryValues(MI, OpenRanges, VarLocIDs, Transfers, DebugEntryVals,
KillSet);
}
}
/// Decide if @MI is a spill instruction and return true if it is. We use 2
@@ -1015,14 +941,12 @@ void LiveDebugValues::accumulateFragmentMap(MachineInstr &MI,
/// This routine creates OpenRanges and OutLocs.
bool LiveDebugValues::process(MachineInstr &MI, OpenRangesSet &OpenRanges,
VarLocInMBB &OutLocs, VarLocMap &VarLocIDs,
TransferMap &Transfers, DebugParamMap &DebugEntryVals,
bool transferChanges,
TransferMap &Transfers, bool transferChanges,
OverlapMap &OverlapFragments,
VarToFragments &SeenFragments) {
bool Changed = false;
transferDebugValue(MI, OpenRanges, VarLocIDs);
transferRegisterDef(MI, OpenRanges, VarLocIDs, Transfers,
DebugEntryVals);
transferRegisterDef(MI, OpenRanges, VarLocIDs);
if (transferChanges) {
transferRegisterCopy(MI, OpenRanges, VarLocIDs, Transfers);
transferSpillOrRestoreInst(MI, OpenRanges, VarLocIDs, Transfers);
@@ -1176,41 +1100,6 @@ bool LiveDebugValues::ExtendRanges(MachineFunction &MF) {
enum : bool { dontTransferChanges = false, transferChanges = true };
// Besides parameter's modification, check whether a DBG_VALUE is inlined
// in order to deduce whether the variable that it tracks comes from
// a different function. If that is the case we can't track its entry value.
auto IsUnmodifiedFuncParam = [&](const MachineInstr &MI) {
auto *DIVar = MI.getDebugVariable();
return DIVar->isParameter() && DIVar->isNotModified() &&
!MI.getDebugLoc()->getInlinedAt();
};
const TargetLowering *TLI = MF.getSubtarget().getTargetLowering();
unsigned SP = TLI->getStackPointerRegisterToSaveRestore();
unsigned FP = TRI->getFrameRegister(MF);
auto IsRegOtherThanSPAndFP = [&](const MachineOperand &Op) -> bool {
return Op.isReg() && Op.getReg() != SP && Op.getReg() != FP;
};
// Working set of currently collected debug variables mapped to DBG_VALUEs
// representing candidates for production of debug entry values.
DebugParamMap DebugEntryVals;
MachineBasicBlock &First_MBB = *(MF.begin());
// Only in the case of entry MBB collect DBG_VALUEs representing
// function parameters in order to generate debug entry values for them.
// Currently, we generate debug entry values only for parameters that are
// unmodified throughout the function and located in a register.
// TODO: Add support for parameters that are described as fragments.
// TODO: Add support for modified arguments that can be expreseed
// by using its entry value.
for (auto &MI : First_MBB)
if (MI.isDebugValue() && IsUnmodifiedFuncParam(MI) &&
!MI.isIndirectDebugValue() && IsRegOtherThanSPAndFP(MI.getOperand(0)) &&
!DebugEntryVals.count(MI.getDebugVariable()) &&
!MI.getDebugExpression()->isFragment())
DebugEntryVals[MI.getDebugVariable()] = &MI;
// Initialize every mbb with OutLocs.
// We are not looking at any spill instructions during the initial pass
// over the BBs. The LiveDebugVariables pass has already created DBG_VALUE
@@ -1218,16 +1107,9 @@ bool LiveDebugValues::ExtendRanges(MachineFunction &MF) {
// within the BB in which the spill occurs.
for (auto &MBB : MF) {
for (auto &MI : MBB) {
process(MI, OpenRanges, OutLocs, VarLocIDs, Transfers, DebugEntryVals,
process(MI, OpenRanges, OutLocs, VarLocIDs, Transfers,
dontTransferChanges, OverlapFragments, SeenFragments);
}
// Add any entry DBG_VALUE instructions necessitated by parameter
// clobbering.
for (auto &TR : Transfers) {
MBB.insertAfter(MachineBasicBlock::iterator(*TR.TransferInst),
TR.DebugInst);
}
Transfers.clear();
}
auto hasNonArtificialLocation = [](const MachineInstr &MI) -> bool {
@@ -1276,8 +1158,7 @@ bool LiveDebugValues::ExtendRanges(MachineFunction &MF) {
for (auto &MI : *MBB)
OLChanged |=
process(MI, OpenRanges, OutLocs, VarLocIDs, Transfers,
DebugEntryVals, transferChanges, OverlapFragments,
SeenFragments);
transferChanges, OverlapFragments, SeenFragments);
// Add any DBG_VALUE instructions necessitated by spills.
for (auto &TR : Transfers)