LLVM: lib/Target/WebAssembly/WebAssemblyDebugFixup.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

28using namespace llvm;

29

30#define DEBUG_TYPE "wasm-debug-fixup"

31

32namespace {

34 StringRef getPassName() const override { return "WebAssembly Debug Fixup"; }

35

36 void getAnalysisUsage(AnalysisUsage &AU) const override {

39 }

40

42

43public:

44 static char ID;

46};

47}

48

49char WebAssemblyDebugFixup::ID = 0;

52 "Ensures debug_value's that have been stackified become stack relative",

53 false, false)

54

56 return new WebAssemblyDebugFixup();

57}

58

59

60

61

62

63

64

68 if (MI.isDebugValue() && MI.getDebugOperand(0).isReg() &&

69 MI.isUndefDebugValue()) {

70 LLVM_DEBUG(dbgs() << "Warning: dangling DBG_VALUE set to undef: " << MI

71 << "\n");

72 MI.setDebugValueUndef();

73 }

74 }

75}

76

77bool WebAssemblyDebugFixup::runOnMachineFunction(MachineFunction &MF) {

78 LLVM_DEBUG(dbgs() << "********** Debug Fixup **********\n"

79 "********** Function: "

81

82 WebAssemblyFunctionInfo &MFI = *MF.getInfo();

83 const auto *TII = MF.getSubtarget().getInstrInfo();

84

85 struct StackElem {

86 unsigned Reg;

87 MachineInstr *DebugValue;

88 };

89 std::vector Stack;

90 for (MachineBasicBlock &MBB : MF) {

91

92 for (auto MII = MBB.begin(); MII != MBB.end(); ++MII) {

93 MachineInstr &MI = *MII;

94 if (MI.isDebugValue()) {

95 auto &MO = MI.getOperand(0);

96

97 if (MO.isReg() && MO.getReg().isValid() &&

99

100

101

102

103

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");

110

111

112

113 Elem.DebugValue = &MI;

114 break;

115 }

116 }

117

118

119

120 }

121 } else {

122

123 for (MachineOperand &MO : reverse(MI.explicit_uses())) {

125 auto Prev = Stack.back();

126 Stack.pop_back();

127 assert(Prev.Reg == MO.getReg() &&

128 "WebAssemblyDebugFixup: Pop: Register not matched!");

129

130

131 if (Prev.DebugValue && MI.isTerminator()) {

132

133

134

135

136 BuildMI(*Prev.DebugValue->getParent(), std::next(MII),

137 Prev.DebugValue->getDebugLoc(),

139 Prev.DebugValue->getOperand(2).getMetadata(),

140 Prev.DebugValue->getOperand(3).getMetadata());

141 }

142 }

143 }

144 for (MachineOperand &MO : MI.defs()) {

146 Stack.push_back({MO.getReg(), nullptr});

147 }

148 }

149 }

150 }

152 "WebAssemblyDebugFixup: Stack not empty at end of basic block!");

153

155 }

156

157 return true;

158}

assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")

const TargetInstrInfo & TII

Promote Memory to Register

#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)

static void setDanglingDebugValuesUndef(MachineBasicBlock &MBB, const TargetInstrInfo *TII)

Definition WebAssemblyDebugFixup.cpp:65

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.

const MCInstrDesc & get(unsigned Opcode) const

Return the machine instruction descriptor that corresponds to the specified instruction opcode.

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.