28 if (!Def->getMF()->getFunction().getSubprogram())
34 if (!Def->getOperand(0).isReg())
36 CurrentReg = Def->getOperand(0).getReg();
41 unsigned RemainingUses = 0;
43 if (
MI.isDebugValue() &&
MI.getParent() ==
MBB)
45 if (RemainingUses == 0)
53 DownEnd =
MBB->end(), Up = Def->getIterator(),
54 UpBegin =
MBB->begin();
55 while (RemainingUses > 0 && Down != DownEnd) {
56 if (Down->isDebugValue()) {
57 if (Down->hasDebugOperandForReg(CurrentReg)) {
58 DbgValues.push_back(&*Down);
61 }
else if (Down->definesRegister(CurrentReg,
nullptr)) {
67 if (Up->isDebugValue() && Up->hasDebugOperandForReg(CurrentReg))
76 if (
A->getOpcode() !=
B->getOpcode() ||
81 if ((OpA.
isImm() && OpB.isImm() && OpA.
getImm() == OpB.getImm()) ||
89WebAssemblyDebugValueManager::getSinkableDebugValues(
91 if (DbgValues.empty())
96 if (Def->getParent() !=
Insert->getParent() &&
97 !Def->getParent()->isSuccessor(
Insert->getParent()))
100 SmallDenseSet<DebugVariable, 4> OurVars;
101 for (MachineInstr *DV : DbgValues)
102 OurVars.
insert(DebugVariable(DV->getDebugVariable(),
103 DV->getDebugExpression(),
104 DV->getDebugLoc()->getInlinedAt()));
106 SmallDenseMap<DebugVariable, SmallVector<MachineInstr *, 2>>
107 SeenDbgVarToDbgValues;
108 auto RecordDbgValue = [&](MachineInstr &
MI) {
109 if (!
MI.isDebugValue())
111 DebugVariable Var(
MI.getDebugVariable(),
MI.getDebugExpression(),
112 MI.getDebugLoc()->getInlinedAt());
114 SeenDbgVarToDbgValues[Var].push_back(&
MI);
117 if (Def->getParent() ==
Insert->getParent()) {
121 DownEnd = Def->getParent()->end(),
122 Up = Def->getIterator(),
123 UpBegin = Def->getParent()->begin();
124 bool DefFirst =
false;
125 while (Down != DownEnd || Up != UpBegin) {
126 if (Down != DownEnd) {
127 if (&*Down == Insert) {
131 RecordDbgValue(*Down);
147 ME = Def->getParent()->end();
151 ME =
Insert->getIterator();
166 MachineRegisterInfo &MRI = Def->getParent()->getParent()->getRegInfo();
167 for (
auto *DV : DbgValues) {
168 DebugVariable Var(DV->getDebugVariable(), DV->getDebugExpression(),
169 DV->getDebugLoc()->getInlinedAt());
170 auto It = SeenDbgVarToDbgValues.
find(Var);
171 if (It == SeenDbgVarToDbgValues.
end()) {
177 auto &OverlappingDbgValues = It->second;
178 bool Sinkable =
true;
179 for (
auto *OverlappingDV : OverlappingDbgValues) {
180 MachineOperand &DbgOp = OverlappingDV->getDebugOperand(0);
181 if (!DbgOp.
isReg()) {
250 return SinkableDbgValues;
255bool WebAssemblyDebugValueManager::isInsertSamePlace(
257 if (Def->getParent() !=
Insert->getParent())
272 for (
const auto &
MI : *
MBB)
273 if (
MI.getDebugLoc() ==
DL)
303 if (isInsertSamePlace(Insert))
312 getSinkableDebugValues(Insert);
321 MBB->splice(Insert, Def->getParent(), Def);
323 if (DbgValues.empty())
330 MBB->insert(Insert, Clone);
374 DV->setDebugValueUndef();
376 DbgValues.
swap(NewDbgValues);
391 bool CloneDef)
const {
396 getSinkableDebugValues(Insert);
406 if (NewReg != CurrentReg && NewReg.
isValid())
408 MBB->insert(Insert, Clone);
411 if (DbgValues.empty())
418 MBB->insert(Insert, Clone);
422 if (NewReg != CurrentReg && NewReg.
isValid())
423 for (
auto *DBI : NewDbgValues)
424 for (
auto &MO : DBI->getDebugOperandsForReg(CurrentReg))
430 if (Reg != CurrentReg && Reg.isValid()) {
431 for (
auto *DBI : DbgValues)
432 for (
auto &MO : DBI->getDebugOperandsForReg(CurrentReg))
435 Def->getOperand(0).setReg(Reg);
440 for (
auto *DBI : DbgValues) {
441 auto IndexType = DBI->isIndirectDebugValue()
444 for (
auto &MO : DBI->getDebugOperandsForReg(CurrentReg))
445 MO.ChangeToTargetIndex(IndexType, LocalId);
451 Def->removeFromParent();
453 DV->setDebugValueUndef();
for(const MachineOperand &MO :llvm::drop_begin(OldMI.operands(), Desc.getNumOperands()))
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
This file defines the DenseSet and SmallDenseSet classes.
Promote Memory to Register
static bool isSameScalarConst(const MachineInstr *A, const MachineInstr *B)
static bool hasSameDebugLoc(const MachineBasicBlock *MBB, DebugLoc DL)
This file contains the declaration of the WebAssembly-specific manager for DebugValues associated wit...
This file provides WebAssembly-specific target descriptions.
This file declares WebAssembly-specific per-machine-function information.
This file contains the entry points for global functions defined in the LLVM WebAssembly back-end.
iterator find(const_arg_type_t< KeyT > Val)
MachineInstrBundleIterator< MachineInstr > iterator
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
Representation of each machine instruction.
const MachineOperand & getOperand(unsigned i) const
void setDebugLoc(DebugLoc DL)
Replace current source information with new such.
MachineOperand class - Representation of each machine instruction operand.
const GlobalValue * getGlobal() const
bool isReg() const
isReg - Tests if this is a MO_Register operand.
LLVM_ABI void setReg(Register Reg)
Change the register this operand corresponds to.
bool isImm() const
isImm - Tests if this is a MO_Immediate operand.
bool isGlobal() const
isGlobal - Tests if this is a MO_GlobalAddress operand.
Register getReg() const
getReg - Returns the register number.
const ConstantFP * getFPImm() const
bool isFPImm() const
isFPImm - Tests if this is a MO_FPImmediate operand.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
const MachineFunction & getMF() const
LLVM_ABI LLVM_READONLY MachineInstr * getUniqueVRegDef(Register Reg) const
getUniqueVRegDef - Return the unique machine instr that defines the specified virtual register or nul...
Wrapper class representing virtual and physical registers.
constexpr bool isValid() const
void swap(SmallVectorImpl &RHS)
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
WebAssemblyDebugValueManager(MachineInstr *Def)
void updateReg(Register Reg)
void cloneSink(MachineInstr *Insert, Register NewReg=Register(), bool CloneDef=true) const
void replaceWithLocal(unsigned LocalId)
void sink(MachineInstr *Insert)
std::pair< iterator, bool > insert(const ValueT &V)
bool contains(const_arg_type_t< ValueT > V) const
Check if the set contains the given element.
bool isScalarConst(unsigned Opc)
This is an optimization pass for GlobalISel generic memory operations.
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.