LLVM: lib/CodeGen/RemoveRedundantDebugValues.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

22

23

24

25

26

27

28#define DEBUG_TYPE "removeredundantdebugvalues"

29

30using namespace llvm;

31

32STATISTIC(NumRemovedBackward, "Number of DBG_VALUEs removed (backward scan)");

33STATISTIC(NumRemovedForward, "Number of DBG_VALUEs removed (forward scan)");

34

35namespace {

36

37struct RemoveRedundantDebugValuesImpl {

39};

40

42public:

43 static char ID;

44

45 RemoveRedundantDebugValuesLegacy();

46

47 bool runOnMachineFunction(MachineFunction &MF) override;

48

49 void getAnalysisUsage(AnalysisUsage &AU) const override {

52 }

53};

54

55}

56

57

58

59

60

61char RemoveRedundantDebugValuesLegacy::ID = 0;

62

64

66 "Remove Redundant DEBUG_VALUE analysis", false, false)

67

68

69RemoveRedundantDebugValuesLegacy::RemoveRedundantDebugValuesLegacy()

73}

74

75

76

77

78

79

80

81

82

83

84

87

90 VariableMap;

91 const auto *TRI = MBB.getParent()->getSubtarget().getRegisterInfo();

92

93 for (auto &MI : MBB) {

94 if (MI.isDebugValue()) {

96 MI.getDebugLoc()->getInlinedAt());

97 auto VMI = VariableMap.find(Var);

98

99

100

101

102

103

104 if (MI.isDebugValueList() && VMI != VariableMap.end()) {

105 VariableMap.erase(VMI);

106 continue;

107 }

108

110 if (Loc.isReg()) {

111

112 if (VMI != VariableMap.end())

113 VariableMap.erase(VMI);

114 continue;

115 }

116

117

118 if (VMI == VariableMap.end() ||

119 VMI->second.first->getReg() != Loc.getReg() ||

120 VMI->second.second != MI.getDebugExpression()) {

121 VariableMap[Var] = {&Loc, MI.getDebugExpression()};

122 continue;

123 }

124

125

126

128 }

129

130 if (MI.isMetaInstruction())

131 continue;

132

133

134 for (auto &Var : VariableMap) {

135 auto &LocOp = Var.second.first;

136 if (MI.modifiesRegister(LocOp->getReg(), TRI))

137 VariableMap.erase(Var.first);

138 }

139 }

140

141 for (auto &Instr : DbgValsToBeRemoved) {

143 Instr->eraseFromParent();

144 ++NumRemovedForward;

145 }

146

147 return !DbgValsToBeRemoved.empty();

148}

149

150

151

152

153

154

155

156

157

158

163

165 if (MI.isDebugValue()) {

166 DebugVariable Var(MI.getDebugVariable(), MI.getDebugExpression(),

167 MI.getDebugLoc()->getInlinedAt());

168 auto R = VariableSet.insert(Var);

169

170

171

172

173 if (MI.isNonListDebugValue()) {

175 if (Loc.isReg()) {

176

177

178 if (!R.second)

179 VariableSet.erase(Var);

180 continue;

181 }

182 }

183

184

185

186 if (!R.second)

188 continue;

189 }

190

191

192

193 VariableSet.clear();

194 }

195

196 for (auto &Instr : DbgValsToBeRemoved) {

198 Instr->eraseFromParent();

199 ++NumRemovedBackward;

200 }

201

202 return !DbgValsToBeRemoved.empty();

203}

204

205bool RemoveRedundantDebugValuesImpl::reduceDbgValues(MachineFunction &MF) {

207

209

210 for (auto &MBB : MF) {

213 }

214

216}

217

218bool RemoveRedundantDebugValuesLegacy::runOnMachineFunction(

219 MachineFunction &MF) {

220

221

225 return false;

226

227 return RemoveRedundantDebugValuesImpl().reduceDbgValues(MF);

228}

229

230PreservedAnalyses

233

234

239

240 if (!RemoveRedundantDebugValuesImpl().reduceDbgValues(MF))

242

245 return PA;

246}

This file defines the DenseMap class.

This file defines the DenseSet and SmallDenseSet classes.

Register const TargetRegisterInfo * TRI

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

static bool reduceDbgValsForwardScan(MachineBasicBlock &MBB)

Definition RemoveRedundantDebugValues.cpp:85

static bool reduceDbgValsBackwardScan(MachineBasicBlock &MBB)

Definition RemoveRedundantDebugValues.cpp:159

This file defines the SmallVector class.

This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...

#define STATISTIC(VARNAME, DESC)

LLVM_ABI void setPreservesCFG()

This function should be called by the pass, iff they do not:

Represents analyses that only rely on functions' control flow.

Identifies a unique instance of a variable.

iterator find(const_arg_type_t< KeyT > Val)

bool erase(const KeyT &Val)

DISubprogram * getSubprogram() const

Get the attached subprogram.

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.

Function & getFunction()

Return the LLVM function that this machine code represents.

Representation of each machine instruction.

MachineOperand class - Representation of each machine instruction operand.

static LLVM_ABI PassRegistry * getPassRegistry()

getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...

static PreservedAnalyses all()

Construct a special preserved set that preserves all passes.

PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)

Definition RemoveRedundantDebugValues.cpp:231

Implements a dense probed hash-table based set with some number of buckets stored inline.

void push_back(const T &Elt)

This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.

std::pair< iterator, bool > insert(const ValueT &V)

bool erase(const ValueT &V)

unsigned ID

LLVM IR allows to use arbitrary numbers as calling convention identifiers.

This is an optimization pass for GlobalISel generic memory operations.

AnalysisManager< MachineFunction > MachineFunctionAnalysisManager

LLVM_ABI void initializeRemoveRedundantDebugValuesLegacyPass(PassRegistry &)

LLVM_ABI PreservedAnalyses getMachineFunctionPassPreservedAnalyses()

Returns the minimum set of Analyses that all machine function passes must preserve.

auto reverse(ContainerTy &&C)

LLVM_ABI raw_ostream & dbgs()

dbgs() - This returns a reference to a raw_ostream for debugging messages.

LLVM_ABI char & RemoveRedundantDebugValuesID

RemoveRedundantDebugValues pass.

Definition RemoveRedundantDebugValues.cpp:63