2018-08-17 23:22:04 +08:00
|
|
|
//===- llvm/CodeGen/AsmPrinter/DbgEntityHistoryCalculator.cpp -------------===//
|
2014-05-01 05:34:11 +08:00
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2014-05-01 05:34:11 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2018-12-19 07:10:17 +08:00
|
|
|
#include "llvm/CodeGen/DbgEntityHistoryCalculator.h"
|
2014-10-06 23:31:04 +08:00
|
|
|
#include "llvm/ADT/BitVector.h"
|
2017-08-18 05:26:39 +08:00
|
|
|
#include "llvm/ADT/STLExtras.h"
|
2014-05-21 02:34:54 +08:00
|
|
|
#include "llvm/ADT/SmallVector.h"
|
2014-05-01 05:34:11 +08:00
|
|
|
#include "llvm/CodeGen/MachineBasicBlock.h"
|
|
|
|
#include "llvm/CodeGen/MachineFunction.h"
|
2017-08-18 05:26:39 +08:00
|
|
|
#include "llvm/CodeGen/MachineInstr.h"
|
|
|
|
#include "llvm/CodeGen/MachineOperand.h"
|
2017-11-17 09:07:10 +08:00
|
|
|
#include "llvm/CodeGen/TargetLowering.h"
|
|
|
|
#include "llvm/CodeGen/TargetRegisterInfo.h"
|
|
|
|
#include "llvm/CodeGen/TargetSubtargetInfo.h"
|
2017-08-18 05:26:39 +08:00
|
|
|
#include "llvm/IR/DebugInfoMetadata.h"
|
|
|
|
#include "llvm/IR/DebugLoc.h"
|
|
|
|
#include "llvm/MC/MCRegisterInfo.h"
|
2014-05-01 05:34:11 +08:00
|
|
|
#include "llvm/Support/Debug.h"
|
2015-03-24 02:07:13 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2017-08-18 05:26:39 +08:00
|
|
|
#include <cassert>
|
2014-05-21 02:34:54 +08:00
|
|
|
#include <map>
|
2017-08-18 05:26:39 +08:00
|
|
|
#include <utility>
|
|
|
|
|
2014-10-06 23:31:04 +08:00
|
|
|
using namespace llvm;
|
2014-05-01 05:34:11 +08:00
|
|
|
|
|
|
|
#define DEBUG_TYPE "dwarfdebug"
|
|
|
|
|
2018-05-01 23:54:18 +08:00
|
|
|
// If @MI is a DBG_VALUE with debug value described by a
|
2014-05-21 02:34:54 +08:00
|
|
|
// defined register, returns the number of this register.
|
|
|
|
// In the other case, returns 0.
|
|
|
|
static unsigned isDescribedByReg(const MachineInstr &MI) {
|
|
|
|
assert(MI.isDebugValue());
|
Move the complex address expression out of DIVariable and into an extra
argument of the llvm.dbg.declare/llvm.dbg.value intrinsics.
Previously, DIVariable was a variable-length field that has an optional
reference to a Metadata array consisting of a variable number of
complex address expressions. In the case of OpPiece expressions this is
wasting a lot of storage in IR, because when an aggregate type is, e.g.,
SROA'd into all of its n individual members, the IR will contain n copies
of the DIVariable, all alike, only differing in the complex address
reference at the end.
By making the complex address into an extra argument of the
dbg.value/dbg.declare intrinsics, all of the pieces can reference the
same variable and the complex address expressions can be uniqued across
the CU, too.
Down the road, this will allow us to move other flags, such as
"indirection" out of the DIVariable, too.
The new intrinsics look like this:
declare void @llvm.dbg.declare(metadata %storage, metadata %var, metadata %expr)
declare void @llvm.dbg.value(metadata %storage, i64 %offset, metadata %var, metadata %expr)
This patch adds a new LLVM-local tag to DIExpressions, so we can detect
and pretty-print DIExpression metadata nodes.
What this patch doesn't do:
This patch does not touch the "Indirect" field in DIVariable; but moving
that into the expression would be a natural next step.
http://reviews.llvm.org/D4919
rdar://problem/17994491
Thanks to dblaikie and dexonsmith for reviewing this patch!
Note: I accidentally committed a bogus older version of this patch previously.
llvm-svn: 218787
2014-10-02 02:55:02 +08:00
|
|
|
assert(MI.getNumOperands() == 4);
|
2014-05-21 02:34:54 +08:00
|
|
|
// If location of variable is described using a register (directly or
|
Improve virtual register handling when computing debug information
Summary: Some backends, like WebAssembly, use virtual registers instead of physical registers. This crashes the DbgValueHistoryCalculator pass, which assumes that all registers are physical. Instead, skip virtual registers when iterating aliases, and assume that they are clobbered.
Reviewers: dexonsmith, dschuff, aprantl
Subscribers: yurydelendik, llvm-commits, jfb, sunfish
Differential Revision: https://reviews.llvm.org/D22590
llvm-svn: 278371
2016-08-12 01:52:40 +08:00
|
|
|
// indirectly), this register is always a first operand.
|
2014-05-21 02:34:54 +08:00
|
|
|
return MI.getOperand(0).isReg() ? MI.getOperand(0).getReg() : 0;
|
|
|
|
}
|
|
|
|
|
2019-04-10 17:07:43 +08:00
|
|
|
void DbgValueHistoryMap::startEntry(InlinedEntity Var, const MachineInstr &MI) {
|
2014-05-28 07:09:50 +08:00
|
|
|
// Instruction range should start with a DBG_VALUE instruction for the
|
|
|
|
// variable.
|
Move the complex address expression out of DIVariable and into an extra
argument of the llvm.dbg.declare/llvm.dbg.value intrinsics.
Previously, DIVariable was a variable-length field that has an optional
reference to a Metadata array consisting of a variable number of
complex address expressions. In the case of OpPiece expressions this is
wasting a lot of storage in IR, because when an aggregate type is, e.g.,
SROA'd into all of its n individual members, the IR will contain n copies
of the DIVariable, all alike, only differing in the complex address
reference at the end.
By making the complex address into an extra argument of the
dbg.value/dbg.declare intrinsics, all of the pieces can reference the
same variable and the complex address expressions can be uniqued across
the CU, too.
Down the road, this will allow us to move other flags, such as
"indirection" out of the DIVariable, too.
The new intrinsics look like this:
declare void @llvm.dbg.declare(metadata %storage, metadata %var, metadata %expr)
declare void @llvm.dbg.value(metadata %storage, i64 %offset, metadata %var, metadata %expr)
This patch adds a new LLVM-local tag to DIExpressions, so we can detect
and pretty-print DIExpression metadata nodes.
What this patch doesn't do:
This patch does not touch the "Indirect" field in DIVariable; but moving
that into the expression would be a natural next step.
http://reviews.llvm.org/D4919
rdar://problem/17994491
Thanks to dblaikie and dexonsmith for reviewing this patch!
Note: I accidentally committed a bogus older version of this patch previously.
llvm-svn: 218787
2014-10-02 02:55:02 +08:00
|
|
|
assert(MI.isDebugValue() && "not a DBG_VALUE");
|
2019-04-10 17:07:43 +08:00
|
|
|
auto &Entries = VarEntries[Var];
|
|
|
|
if (!Entries.empty() && !Entries.back().isClosed() &&
|
|
|
|
Entries.back().getBegin()->isIdenticalTo(MI)) {
|
2018-05-14 20:53:11 +08:00
|
|
|
LLVM_DEBUG(dbgs() << "Coalescing identical DBG_VALUE entries:\n"
|
2019-04-10 17:07:43 +08:00
|
|
|
<< "\t" << Entries.back().getBegin() << "\t" << MI
|
2019-04-10 17:07:32 +08:00
|
|
|
<< "\n");
|
2014-05-28 07:09:50 +08:00
|
|
|
return;
|
|
|
|
}
|
2019-04-10 17:07:43 +08:00
|
|
|
Entries.emplace_back(&MI);
|
2014-05-28 07:09:50 +08:00
|
|
|
}
|
|
|
|
|
2019-04-10 17:07:43 +08:00
|
|
|
void DbgValueHistoryMap::endEntry(InlinedEntity Var, const MachineInstr &MI) {
|
|
|
|
auto &Entries = VarEntries[Var];
|
|
|
|
assert(!Entries.empty() && "No range exists for variable!");
|
|
|
|
Entries.back().endEntry(MI);
|
2019-04-10 17:07:32 +08:00
|
|
|
}
|
|
|
|
|
2019-04-10 17:07:43 +08:00
|
|
|
void DbgValueHistoryMap::Entry::endEntry(const MachineInstr &MI) {
|
2014-05-28 07:09:50 +08:00
|
|
|
// For now, instruction ranges are not allowed to cross basic block
|
|
|
|
// boundaries.
|
2019-04-10 17:07:32 +08:00
|
|
|
assert(Begin->getParent() == MI.getParent());
|
|
|
|
assert(!isClosed() && "Range is already closed!");
|
|
|
|
End = &MI;
|
2014-05-28 07:09:50 +08:00
|
|
|
}
|
|
|
|
|
2018-09-06 10:22:06 +08:00
|
|
|
unsigned DbgValueHistoryMap::getRegisterForVar(InlinedEntity Var) const {
|
2019-04-10 17:07:43 +08:00
|
|
|
const auto &I = VarEntries.find(Var);
|
|
|
|
if (I == VarEntries.end())
|
2014-05-28 07:09:50 +08:00
|
|
|
return 0;
|
2019-04-10 17:07:43 +08:00
|
|
|
const auto &Entries = I->second;
|
|
|
|
if (Entries.empty() || Entries.back().isClosed())
|
2014-05-28 07:09:50 +08:00
|
|
|
return 0;
|
2019-04-10 17:07:43 +08:00
|
|
|
return isDescribedByReg(*Entries.back().getBegin());
|
2014-05-28 07:09:50 +08:00
|
|
|
}
|
|
|
|
|
2018-09-06 10:22:06 +08:00
|
|
|
void DbgLabelInstrMap::addInstr(InlinedEntity Label, const MachineInstr &MI) {
|
2018-08-17 23:22:04 +08:00
|
|
|
assert(MI.isDebugLabel() && "not a DBG_LABEL");
|
|
|
|
LabelInstr[Label] = &MI;
|
|
|
|
}
|
|
|
|
|
2014-05-28 07:09:50 +08:00
|
|
|
namespace {
|
2017-08-18 05:26:39 +08:00
|
|
|
|
2014-05-28 07:09:50 +08:00
|
|
|
// Maps physreg numbers to the variables they describe.
|
2018-09-06 10:22:06 +08:00
|
|
|
using InlinedEntity = DbgValueHistoryMap::InlinedEntity;
|
|
|
|
using RegDescribedVarsMap = std::map<unsigned, SmallVector<InlinedEntity, 1>>;
|
2017-08-18 05:26:39 +08:00
|
|
|
|
|
|
|
} // end anonymous namespace
|
2014-05-28 07:09:50 +08:00
|
|
|
|
2018-05-01 23:54:18 +08:00
|
|
|
// Claim that @Var is not described by @RegNo anymore.
|
2015-04-16 06:29:27 +08:00
|
|
|
static void dropRegDescribedVar(RegDescribedVarsMap &RegVars, unsigned RegNo,
|
2018-09-06 10:22:06 +08:00
|
|
|
InlinedEntity Var) {
|
2014-05-21 02:34:54 +08:00
|
|
|
const auto &I = RegVars.find(RegNo);
|
|
|
|
assert(RegNo != 0U && I != RegVars.end());
|
|
|
|
auto &VarSet = I->second;
|
2017-08-18 05:26:39 +08:00
|
|
|
const auto &VarPos = llvm::find(VarSet, Var);
|
2014-05-21 02:34:54 +08:00
|
|
|
assert(VarPos != VarSet.end());
|
|
|
|
VarSet.erase(VarPos);
|
|
|
|
// Don't keep empty sets in a map to keep it as small as possible.
|
|
|
|
if (VarSet.empty())
|
|
|
|
RegVars.erase(I);
|
|
|
|
}
|
|
|
|
|
2018-05-01 23:54:18 +08:00
|
|
|
// Claim that @Var is now described by @RegNo.
|
2015-04-16 06:29:27 +08:00
|
|
|
static void addRegDescribedVar(RegDescribedVarsMap &RegVars, unsigned RegNo,
|
2018-09-06 10:22:06 +08:00
|
|
|
InlinedEntity Var) {
|
2014-05-21 02:34:54 +08:00
|
|
|
assert(RegNo != 0U);
|
2014-05-28 07:09:50 +08:00
|
|
|
auto &VarSet = RegVars[RegNo];
|
2016-08-12 06:21:41 +08:00
|
|
|
assert(!is_contained(VarSet, Var));
|
2014-05-28 07:09:50 +08:00
|
|
|
VarSet.push_back(Var);
|
2014-05-21 02:34:54 +08:00
|
|
|
}
|
|
|
|
|
2018-05-01 23:54:18 +08:00
|
|
|
// Terminate the location range for variables described by register at
|
2014-10-06 23:31:04 +08:00
|
|
|
// @I by inserting @ClobberingInstr to their history.
|
|
|
|
static void clobberRegisterUses(RegDescribedVarsMap &RegVars,
|
|
|
|
RegDescribedVarsMap::iterator I,
|
|
|
|
DbgValueHistoryMap &HistMap,
|
|
|
|
const MachineInstr &ClobberingInstr) {
|
|
|
|
// Iterate over all variables described by this register and add this
|
|
|
|
// instruction to their history, clobbering it.
|
|
|
|
for (const auto &Var : I->second)
|
2019-04-10 17:07:43 +08:00
|
|
|
HistMap.endEntry(Var, ClobberingInstr);
|
2014-10-06 23:31:04 +08:00
|
|
|
RegVars.erase(I);
|
|
|
|
}
|
|
|
|
|
2018-05-01 23:54:18 +08:00
|
|
|
// Terminate the location range for variables described by register
|
2014-05-21 02:34:54 +08:00
|
|
|
// @RegNo by inserting @ClobberingInstr to their history.
|
|
|
|
static void clobberRegisterUses(RegDescribedVarsMap &RegVars, unsigned RegNo,
|
|
|
|
DbgValueHistoryMap &HistMap,
|
|
|
|
const MachineInstr &ClobberingInstr) {
|
|
|
|
const auto &I = RegVars.find(RegNo);
|
|
|
|
if (I == RegVars.end())
|
|
|
|
return;
|
2014-10-06 23:31:04 +08:00
|
|
|
clobberRegisterUses(RegVars, I, HistMap, ClobberingInstr);
|
2014-05-21 02:34:54 +08:00
|
|
|
}
|
|
|
|
|
2018-05-01 23:54:18 +08:00
|
|
|
// Returns the first instruction in @MBB which corresponds to
|
2014-06-10 05:53:47 +08:00
|
|
|
// the function epilogue, or nullptr if @MBB doesn't contain an epilogue.
|
|
|
|
static const MachineInstr *getFirstEpilogueInst(const MachineBasicBlock &MBB) {
|
|
|
|
auto LastMI = MBB.getLastNonDebugInstr();
|
|
|
|
if (LastMI == MBB.end() || !LastMI->isReturn())
|
|
|
|
return nullptr;
|
|
|
|
// Assume that epilogue starts with instruction having the same debug location
|
|
|
|
// as the return instruction.
|
|
|
|
DebugLoc LastLoc = LastMI->getDebugLoc();
|
|
|
|
auto Res = LastMI;
|
2016-09-12 02:51:28 +08:00
|
|
|
for (MachineBasicBlock::const_reverse_iterator I = LastMI.getReverse(),
|
|
|
|
E = MBB.rend();
|
2014-10-06 23:31:04 +08:00
|
|
|
I != E; ++I) {
|
2014-06-10 05:53:47 +08:00
|
|
|
if (I->getDebugLoc() != LastLoc)
|
2016-07-09 03:31:47 +08:00
|
|
|
return &*Res;
|
2014-10-06 23:31:04 +08:00
|
|
|
Res = &*I;
|
2014-06-10 05:53:47 +08:00
|
|
|
}
|
|
|
|
// If all instructions have the same debug location, assume whole MBB is
|
|
|
|
// an epilogue.
|
2016-07-09 03:31:47 +08:00
|
|
|
return &*MBB.begin();
|
2014-06-10 05:53:47 +08:00
|
|
|
}
|
|
|
|
|
2018-05-01 23:54:18 +08:00
|
|
|
// Collect registers that are modified in the function body (their
|
2014-08-07 02:41:24 +08:00
|
|
|
// contents is changed outside of the prologue and epilogue).
|
2014-06-10 05:53:47 +08:00
|
|
|
static void collectChangingRegs(const MachineFunction *MF,
|
|
|
|
const TargetRegisterInfo *TRI,
|
2014-10-06 23:31:04 +08:00
|
|
|
BitVector &Regs) {
|
2014-06-10 05:53:47 +08:00
|
|
|
for (const auto &MBB : *MF) {
|
|
|
|
auto FirstEpilogueInst = getFirstEpilogueInst(MBB);
|
2014-08-07 02:41:19 +08:00
|
|
|
|
2014-06-10 05:53:47 +08:00
|
|
|
for (const auto &MI : MBB) {
|
2016-03-26 01:54:46 +08:00
|
|
|
// Avoid looking at prologue or epilogue instructions.
|
2014-08-07 02:41:19 +08:00
|
|
|
if (&MI == FirstEpilogueInst)
|
|
|
|
break;
|
2016-03-26 01:54:46 +08:00
|
|
|
if (MI.getFlag(MachineInstr::FrameSetup))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Look for register defs and register masks. Register masks are
|
|
|
|
// typically on calls and they clobber everything not in the mask.
|
|
|
|
for (const MachineOperand &MO : MI.operands()) {
|
Improve virtual register handling when computing debug information
Summary: Some backends, like WebAssembly, use virtual registers instead of physical registers. This crashes the DbgValueHistoryCalculator pass, which assumes that all registers are physical. Instead, skip virtual registers when iterating aliases, and assume that they are clobbered.
Reviewers: dexonsmith, dschuff, aprantl
Subscribers: yurydelendik, llvm-commits, jfb, sunfish
Differential Revision: https://reviews.llvm.org/D22590
llvm-svn: 278371
2016-08-12 01:52:40 +08:00
|
|
|
// Skip virtual registers since they are handled by the parent.
|
|
|
|
if (MO.isReg() && MO.isDef() && MO.getReg() &&
|
|
|
|
!TRI->isVirtualRegister(MO.getReg())) {
|
2016-03-26 01:54:46 +08:00
|
|
|
for (MCRegAliasIterator AI(MO.getReg(), TRI, true); AI.isValid();
|
|
|
|
++AI)
|
|
|
|
Regs.set(*AI);
|
|
|
|
} else if (MO.isRegMask()) {
|
|
|
|
Regs.setBitsNotInMask(MO.getRegMask());
|
|
|
|
}
|
|
|
|
}
|
2014-06-10 05:53:47 +08:00
|
|
|
}
|
|
|
|
}
|
2014-05-21 02:34:54 +08:00
|
|
|
}
|
|
|
|
|
2018-08-17 23:22:04 +08:00
|
|
|
void llvm::calculateDbgEntityHistory(const MachineFunction *MF,
|
|
|
|
const TargetRegisterInfo *TRI,
|
|
|
|
DbgValueHistoryMap &DbgValues,
|
|
|
|
DbgLabelInstrMap &DbgLabels) {
|
2014-10-06 23:31:04 +08:00
|
|
|
BitVector ChangingRegs(TRI->getNumRegs());
|
2014-06-10 05:53:47 +08:00
|
|
|
collectChangingRegs(MF, TRI, ChangingRegs);
|
2014-05-21 02:34:54 +08:00
|
|
|
|
2016-03-26 01:54:46 +08:00
|
|
|
const TargetLowering *TLI = MF->getSubtarget().getTargetLowering();
|
|
|
|
unsigned SP = TLI->getStackPointerRegisterToSaveRestore();
|
2014-06-10 05:53:47 +08:00
|
|
|
RegDescribedVarsMap RegVars;
|
2014-05-21 02:34:54 +08:00
|
|
|
for (const auto &MBB : *MF) {
|
|
|
|
for (const auto &MI : MBB) {
|
2018-05-09 10:42:00 +08:00
|
|
|
if (!MI.isDebugInstr()) {
|
2014-05-21 02:34:54 +08:00
|
|
|
// Not a DBG_VALUE instruction. It may clobber registers which describe
|
|
|
|
// some variables.
|
2016-03-26 01:54:46 +08:00
|
|
|
for (const MachineOperand &MO : MI.operands()) {
|
|
|
|
if (MO.isReg() && MO.isDef() && MO.getReg()) {
|
2017-06-02 05:14:58 +08:00
|
|
|
// Ignore call instructions that claim to clobber SP. The AArch64
|
|
|
|
// backend does this for aggregate function arguments.
|
|
|
|
if (MI.isCall() && MO.getReg() == SP)
|
|
|
|
continue;
|
Improve virtual register handling when computing debug information
Summary: Some backends, like WebAssembly, use virtual registers instead of physical registers. This crashes the DbgValueHistoryCalculator pass, which assumes that all registers are physical. Instead, skip virtual registers when iterating aliases, and assume that they are clobbered.
Reviewers: dexonsmith, dschuff, aprantl
Subscribers: yurydelendik, llvm-commits, jfb, sunfish
Differential Revision: https://reviews.llvm.org/D22590
llvm-svn: 278371
2016-08-12 01:52:40 +08:00
|
|
|
// If this is a virtual register, only clobber it since it doesn't
|
|
|
|
// have aliases.
|
|
|
|
if (TRI->isVirtualRegister(MO.getReg()))
|
2018-08-17 23:22:04 +08:00
|
|
|
clobberRegisterUses(RegVars, MO.getReg(), DbgValues, MI);
|
2016-03-26 01:54:46 +08:00
|
|
|
// If this is a register def operand, it may end a debug value
|
|
|
|
// range.
|
Improve virtual register handling when computing debug information
Summary: Some backends, like WebAssembly, use virtual registers instead of physical registers. This crashes the DbgValueHistoryCalculator pass, which assumes that all registers are physical. Instead, skip virtual registers when iterating aliases, and assume that they are clobbered.
Reviewers: dexonsmith, dschuff, aprantl
Subscribers: yurydelendik, llvm-commits, jfb, sunfish
Differential Revision: https://reviews.llvm.org/D22590
llvm-svn: 278371
2016-08-12 01:52:40 +08:00
|
|
|
else {
|
|
|
|
for (MCRegAliasIterator AI(MO.getReg(), TRI, true); AI.isValid();
|
|
|
|
++AI)
|
|
|
|
if (ChangingRegs.test(*AI))
|
2018-08-17 23:22:04 +08:00
|
|
|
clobberRegisterUses(RegVars, *AI, DbgValues, MI);
|
Improve virtual register handling when computing debug information
Summary: Some backends, like WebAssembly, use virtual registers instead of physical registers. This crashes the DbgValueHistoryCalculator pass, which assumes that all registers are physical. Instead, skip virtual registers when iterating aliases, and assume that they are clobbered.
Reviewers: dexonsmith, dschuff, aprantl
Subscribers: yurydelendik, llvm-commits, jfb, sunfish
Differential Revision: https://reviews.llvm.org/D22590
llvm-svn: 278371
2016-08-12 01:52:40 +08:00
|
|
|
}
|
2016-03-26 01:54:46 +08:00
|
|
|
} else if (MO.isRegMask()) {
|
|
|
|
// If this is a register mask operand, clobber all debug values in
|
|
|
|
// non-CSRs.
|
2017-05-17 09:07:53 +08:00
|
|
|
for (unsigned I : ChangingRegs.set_bits()) {
|
2016-03-26 01:54:46 +08:00
|
|
|
// Don't consider SP to be clobbered by register masks.
|
|
|
|
if (unsigned(I) != SP && TRI->isPhysicalRegister(I) &&
|
|
|
|
MO.clobbersPhysReg(I)) {
|
2018-08-17 23:22:04 +08:00
|
|
|
clobberRegisterUses(RegVars, I, DbgValues, MI);
|
2016-03-26 01:54:46 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-05-21 02:34:54 +08:00
|
|
|
continue;
|
2014-05-01 05:34:11 +08:00
|
|
|
}
|
|
|
|
|
2018-08-17 23:22:04 +08:00
|
|
|
if (MI.isDebugValue()) {
|
|
|
|
assert(MI.getNumOperands() > 1 && "Invalid DBG_VALUE instruction!");
|
|
|
|
// Use the base variable (without any DW_OP_piece expressions)
|
|
|
|
// as index into History. The full variables including the
|
|
|
|
// piece expressions are attached to the MI.
|
|
|
|
const DILocalVariable *RawVar = MI.getDebugVariable();
|
|
|
|
assert(RawVar->isValidLocationForIntrinsic(MI.getDebugLoc()) &&
|
|
|
|
"Expected inlined-at fields to agree");
|
2018-09-06 10:22:06 +08:00
|
|
|
InlinedEntity Var(RawVar, MI.getDebugLoc()->getInlinedAt());
|
2018-08-17 23:22:04 +08:00
|
|
|
|
|
|
|
if (unsigned PrevReg = DbgValues.getRegisterForVar(Var))
|
|
|
|
dropRegDescribedVar(RegVars, PrevReg, Var);
|
|
|
|
|
2019-04-10 17:07:43 +08:00
|
|
|
DbgValues.startEntry(Var, MI);
|
2018-08-17 23:22:04 +08:00
|
|
|
|
|
|
|
if (unsigned NewReg = isDescribedByReg(MI))
|
|
|
|
addRegDescribedVar(RegVars, NewReg, Var);
|
|
|
|
} else if (MI.isDebugLabel()) {
|
|
|
|
assert(MI.getNumOperands() == 1 && "Invalid DBG_LABEL instruction!");
|
|
|
|
const DILabel *RawLabel = MI.getDebugLabel();
|
|
|
|
assert(RawLabel->isValidLocationForIntrinsic(MI.getDebugLoc()) &&
|
|
|
|
"Expected inlined-at fields to agree");
|
|
|
|
// When collecting debug information for labels, there is no MCSymbol
|
|
|
|
// generated for it. So, we keep MachineInstr in DbgLabels in order
|
|
|
|
// to query MCSymbol afterward.
|
2018-09-06 10:22:06 +08:00
|
|
|
InlinedEntity L(RawLabel, MI.getDebugLoc()->getInlinedAt());
|
2018-08-17 23:22:04 +08:00
|
|
|
DbgLabels.addInstr(L, MI);
|
|
|
|
}
|
2014-05-01 05:34:11 +08:00
|
|
|
}
|
2014-05-21 02:34:54 +08:00
|
|
|
|
|
|
|
// Make sure locations for register-described variables are valid only
|
|
|
|
// until the end of the basic block (unless it's the last basic block, in
|
|
|
|
// which case let their liveness run off to the end of the function).
|
2014-10-06 23:31:04 +08:00
|
|
|
if (!MBB.empty() && &MBB != &MF->back()) {
|
|
|
|
for (auto I = RegVars.begin(), E = RegVars.end(); I != E;) {
|
|
|
|
auto CurElem = I++; // CurElem can be erased below.
|
Improve virtual register handling when computing debug information
Summary: Some backends, like WebAssembly, use virtual registers instead of physical registers. This crashes the DbgValueHistoryCalculator pass, which assumes that all registers are physical. Instead, skip virtual registers when iterating aliases, and assume that they are clobbered.
Reviewers: dexonsmith, dschuff, aprantl
Subscribers: yurydelendik, llvm-commits, jfb, sunfish
Differential Revision: https://reviews.llvm.org/D22590
llvm-svn: 278371
2016-08-12 01:52:40 +08:00
|
|
|
if (TRI->isVirtualRegister(CurElem->first) ||
|
|
|
|
ChangingRegs.test(CurElem->first))
|
2018-08-17 23:22:04 +08:00
|
|
|
clobberRegisterUses(RegVars, CurElem, DbgValues, MBB.back());
|
2014-10-06 23:31:04 +08:00
|
|
|
}
|
2014-06-10 05:53:47 +08:00
|
|
|
}
|
2014-05-01 05:34:11 +08:00
|
|
|
}
|
|
|
|
}
|
2018-06-02 06:33:15 +08:00
|
|
|
|
|
|
|
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
|
|
|
|
LLVM_DUMP_METHOD void DbgValueHistoryMap::dump() const {
|
|
|
|
dbgs() << "DbgValueHistoryMap:\n";
|
|
|
|
for (const auto &VarRangePair : *this) {
|
2018-09-06 10:22:06 +08:00
|
|
|
const InlinedEntity &Var = VarRangePair.first;
|
2019-04-10 17:07:43 +08:00
|
|
|
const Entries &Entries = VarRangePair.second;
|
2018-06-02 06:33:15 +08:00
|
|
|
|
2018-09-06 10:22:06 +08:00
|
|
|
const DILocalVariable *LocalVar = cast<DILocalVariable>(Var.first);
|
2018-06-02 06:33:15 +08:00
|
|
|
const DILocation *Location = Var.second;
|
|
|
|
|
|
|
|
dbgs() << " - " << LocalVar->getName() << " at ";
|
|
|
|
|
|
|
|
if (Location)
|
|
|
|
dbgs() << Location->getFilename() << ":" << Location->getLine() << ":"
|
|
|
|
<< Location->getColumn();
|
|
|
|
else
|
|
|
|
dbgs() << "<unknown location>";
|
|
|
|
|
|
|
|
dbgs() << " --\n";
|
|
|
|
|
2019-04-10 17:07:43 +08:00
|
|
|
for (const auto &Entry : Entries) {
|
|
|
|
dbgs() << " Begin: " << *Entry.getBegin();
|
|
|
|
if (Entry.getEnd())
|
|
|
|
dbgs() << " End : " << *Entry.getEnd();
|
2018-06-02 06:33:15 +08:00
|
|
|
dbgs() << "\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|