30#define DEBUG_TYPE "wasm-debug-fixup"
34 StringRef getPassName()
const override {
return "WebAssembly Debug Fixup"; }
49char WebAssemblyDebugFixup::ID = 0;
52 "Ensures debug_value's that have been stackified become stack relative",
56 return new WebAssemblyDebugFixup();
68 if (
MI.isDebugValue() &&
MI.getDebugOperand(0).isReg() &&
69 !
MI.isUndefDebugValue()) {
72 MI.setDebugValueUndef();
79 "********** Function: "
82 WebAssemblyFunctionInfo &MFI = *MF.
getInfo<WebAssemblyFunctionInfo>();
83 const auto *
TII = MF.
getSubtarget<WebAssemblySubtarget>().getInstrInfo();
87 MachineInstr *DebugValue;
89 std::vector<StackElem>
Stack;
90 for (MachineBasicBlock &
MBB : MF) {
93 MachineInstr &
MI = *MII;
94 if (
MI.isDebugValue()) {
95 auto &MO =
MI.getOperand(0);
97 if (MO.isReg() && MO.getReg().isValid() &&
104 for (
auto &Elem :
reverse(Stack)) {
105 if (MO.getReg() == Elem.Reg) {
106 auto Depth =
static_cast<unsigned>(&Elem - &
Stack[0]);
108 <<
" -> Stack Relative " <<
Depth <<
"\n");
113 Elem.DebugValue = &
MI;
123 for (MachineOperand &MO :
reverse(
MI.explicit_uses())) {
125 auto Prev =
Stack.back();
127 assert(Prev.Reg == MO.getReg() &&
128 "WebAssemblyDebugFixup: Pop: Register not matched!");
131 if (Prev.DebugValue && !
MI.isTerminator()) {
136 BuildMI(*Prev.DebugValue->getParent(), std::next(MII),
137 Prev.DebugValue->getDebugLoc(),
138 TII->get(WebAssembly::DBG_VALUE),
false,
Register(),
139 Prev.DebugValue->getOperand(2).getMetadata(),
140 Prev.DebugValue->getOperand(3).getMetadata());
144 for (MachineOperand &MO :
MI.defs()) {
146 Stack.push_back({MO.getReg(),
nullptr});
152 "WebAssemblyDebugFixup: Stack not empty at end of basic block!");
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
const HexagonInstrInfo * TII
Promote Memory to Register
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
static void setDanglingDebugValuesUndef(MachineBasicBlock &MBB, const TargetInstrInfo *TII)
This file provides WebAssembly-specific target descriptions.
This file declares WebAssembly-specific per-machine-function information.
This file declares the WebAssembly-specific subclass of TargetSubtarget.
This file contains the declaration of the WebAssembly-specific utility functions.
This file contains the entry points for global functions defined in the LLVM WebAssembly back-end.
Represent the analysis usage information of a pass.
LLVM_ABI void setPreservesCFG()
This function should be called by the pass, iff they do not:
FunctionPass class - This class is used to implement most global optimizations.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
StringRef - Represent a constant reference to a string, i.e.
TargetInstrInfo - Interface to description of machine instruction set.
bool isVRegStackified(Register VReg) const
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
This is an optimization pass for GlobalISel generic memory operations.
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
iterator_range< early_inc_iterator_impl< detail::IterOfRange< RangeT > > > make_early_inc_range(RangeT &&Range)
Make a range that does early increment to allow mutation of the underlying range without disrupting i...
auto reverse(ContainerTy &&C)
FunctionPass * createWebAssemblyDebugFixup()
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
LLVM_ABI Printable printReg(Register Reg, const TargetRegisterInfo *TRI=nullptr, unsigned SubIdx=0, const MachineRegisterInfo *MRI=nullptr)
Prints virtual and physical registers with or without a TRI instance.