LLVM: lib/Target/Hexagon/RDFDeadCode.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

12

20

21#include

22

23using namespace llvm;

24using namespace rdf;

25

26

27

30

32 return Queue.empty();

33 }

35 T V = Queue.front();

36 Queue.pop();

37 Set.erase(V);

38 return V;

39 }

41 if (Set.count(V))

42 return;

43 Queue.push(V);

44 Set.insert(V);

45 }

46

47private:

49 std::queue Queue;

50};

51

52

53

54

55

56

57

60 if (MI->mayStore() || MI->isBranch() || MI->isCall() || MI->isReturn())

61 return true;

62 if (MI->hasOrderedMemoryRef() || MI->hasUnmodeledSideEffects() ||

63 MI->isPosition())

64 return true;

65 if (MI->isPHI())

66 return false;

67 for (auto &Op : MI->operands()) {

68 if (Op.isReg() && MRI.isReserved(Op.getReg()))

69 return true;

70 if (Op.isRegMask()) {

72 for (unsigned R = 0, RN = DFG.getTRI().getNumRegs(); R != RN; ++R) {

73 if (BM[R/32] & (1u << (R%32)))

74 continue;

75 if (MRI.isReserved(R))

76 return true;

77 }

78 }

79 }

80 return false;

81}

82

83void DeadCodeElimination::scanInstr(NodeAddr<InstrNode*> IA,

84 SetQueue &WorkQ) {

86 return;

87 if (!isLiveInstr(IA))

88 return;

89 for (NodeAddr<RefNode*> RA : IA.Addr->members(DFG)) {

90 if (!LiveNodes.count(RA.Id))

91 WorkQ.push_back(RA.Id);

92 }

93}

94

95void DeadCodeElimination::processDef(NodeAddr<DefNode*> DA,

96 SetQueue &WorkQ) {

97 NodeAddr<InstrNode*> IA = DA.Addr->getOwner(DFG);

98 for (NodeAddr<UseNode*> UA : IA.Addr->members_if(DFG.IsUse, DFG)) {

99 if (!LiveNodes.count(UA.Id))

100 WorkQ.push_back(UA.Id);

101 }

102 for (NodeAddr<DefNode*> TA : DFG.getRelatedRefs(IA, DA))

103 LiveNodes.insert(TA.Id);

104}

105

106void DeadCodeElimination::processUse(NodeAddr<UseNode*> UA,

107 SetQueue &WorkQ) {

108 for (NodeAddr<DefNode*> DA : LV.getAllReachingDefs(UA)) {

109 if (!LiveNodes.count(DA.Id))

110 WorkQ.push_back(DA.Id);

111 }

112}

113

114

115

116

118

119

120

121

122

123

124

125

126

127 LiveNodes.clear();

128 SetQueue WorkQ;

131 scanInstr(IA, WorkQ);

132

133 while (!WorkQ.empty()) {

134 NodeId N = WorkQ.pop_front();

135 LiveNodes.insert(N);

137 if (DFG.IsDef(RA))

138 processDef(RA, WorkQ);

139 else

141 }

142

144 dbgs() << "Live nodes:\n";

145 for (NodeId N : LiveNodes) {

148 }

149 }

150

153 if (LiveNodes.count(DA.Id))

154 return false;

155 return true;

156 };

157

161 if (!LiveNodes.count(RA.Id))

162 DeadNodes.insert(RA.Id);

164 if (isLiveInstr(IA) || DFG.hasUntrackedRef(IA))

165 continue;

167 DeadInstrs.insert(IA.Id);

170 }

171 }

172 }

173

174 return !DeadNodes.empty();

175}

176

177

178

179

181 if (Nodes.empty())

182 return false;

183

184

185

186

188 for (auto I : Nodes) {

189 auto BA = DFG.addr<NodeBase*>(I);

193 continue;

194 }

195

196

197 uint16_t Kind = BA.Addr->getKind();

201 } else {

203 return false;

204 }

205 }

206

207

208

210 uint16_t KindA = A.Addr->getKind(), KindB = B.Addr->getKind();

212 return true;

214 return false;

215 return A.Id < B.Id;

216 };

218

220 dbgs() << "Removing dead ref nodes:\n";

224 if (DFG.IsUse(RA))

225 DFG.unlinkUse(RA, true);

226 else if (DFG.IsDef(RA))

227 DFG.unlinkDef(RA, true);

228 }

229

230

233 BA.Addr->removeMember(IA, DFG);

235 continue;

236

239 dbgs() << "erasing: " << *MI;

240 MI->eraseFromParent();

241 }

242 return true;

243}

unsigned const MachineRegisterInfo * MRI

static bool processUse(CallInst *CI, bool IsV5OrAbove)

static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")

static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")

SI optimize exec mask operations pre RA

This file implements a set that has insertion order iteration characteristics.

Implements a dense probed hash-table based set.

Representation of each machine instruction.

A vector that has set insertion semantics.

bool empty() const

Determine if the SetVector is empty or not.

void push_back(const T &Elt)

The instances of the Type class are immutable: once they are created, they are never changed.

#define llvm_unreachable(msg)

Marks that the current location is not supposed to be reachable.

SmallVector< Node, 4 > NodeList

This is an optimization pass for GlobalISel generic memory operations.

void append_range(Container &C, Range &&R)

Wrapper function to append range R to container C.

void sort(IteratorTy Start, IteratorTy End)

LLVM_ABI raw_ostream & dbgs()

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

DWARFExpression::Operation Op

Definition RDFDeadCode.cpp:28

SetQueue()

Definition RDFDeadCode.cpp:29

void push_back(T V)

Definition RDFDeadCode.cpp:40

bool empty() const

Definition RDFDeadCode.cpp:31

T pop_front()

Definition RDFDeadCode.cpp:34

bool collect()

Definition RDFDeadCode.cpp:117

bool erase(const SetVector< NodeId > &Nodes)

Definition RDFDeadCode.cpp:180