blob: 900a890e93abc981b1dfbf707d1610f4f60b68d8 [file] [log] [blame]
Owen Anderson0bda0e82007-10-31 03:37:57 +00001//===- StrongPhiElimination.cpp - Eliminate PHI nodes by inserting copies -===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file was developed by Owen Anderson and is distributed under
6// the University of Illinois Open Source License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This pass eliminates machine instruction PHI nodes by inserting copy
11// instructions, using an intelligent copy-folding technique based on
12// dominator information. This is technique is derived from:
13//
14// Budimlic, et al. Fast copy coalescing and live-range identification.
15// In Proceedings of the ACM SIGPLAN 2002 Conference on Programming Language
16// Design and Implementation (Berlin, Germany, June 17 - 19, 2002).
17// PLDI '02. ACM, New York, NY, 25-32.
18// DOI= http://doi.acm.org/10.1145/512529.512534
19//
20//===----------------------------------------------------------------------===//
21
22#define DEBUG_TYPE "strongphielim"
23#include "llvm/CodeGen/Passes.h"
Owen Anderson83430bc2007-11-04 22:33:26 +000024#include "llvm/CodeGen/LiveVariables.h"
Owen Anderson0bda0e82007-10-31 03:37:57 +000025#include "llvm/CodeGen/MachineDominators.h"
26#include "llvm/CodeGen/MachineFunctionPass.h"
27#include "llvm/CodeGen/MachineInstr.h"
Owen Anderson17b14182007-11-13 20:04:45 +000028#include "llvm/CodeGen/SSARegMap.h"
Owen Anderson0bda0e82007-10-31 03:37:57 +000029#include "llvm/Target/TargetInstrInfo.h"
30#include "llvm/Target/TargetMachine.h"
31#include "llvm/ADT/Statistic.h"
32#include "llvm/Support/Compiler.h"
33using namespace llvm;
34
35
36namespace {
37 struct VISIBILITY_HIDDEN StrongPHIElimination : public MachineFunctionPass {
38 static char ID; // Pass identification, replacement for typeid
39 StrongPHIElimination() : MachineFunctionPass((intptr_t)&ID) {}
40
Owen Andersonafc6de02007-12-10 08:07:09 +000041 DenseMap<MachineBasicBlock*,
42 SmallVector<std::pair<unsigned, unsigned>, 2> > Waiting;
43
Owen Andersona4ad2e72007-11-06 04:49:43 +000044 bool runOnMachineFunction(MachineFunction &Fn);
45
Owen Anderson0bda0e82007-10-31 03:37:57 +000046 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
Owen Anderson83430bc2007-11-04 22:33:26 +000047 AU.addPreserved<LiveVariables>();
48 AU.addPreservedID(PHIEliminationID);
Owen Anderson0bda0e82007-10-31 03:37:57 +000049 AU.addRequired<MachineDominatorTree>();
Owen Andersona4ad2e72007-11-06 04:49:43 +000050 AU.addRequired<LiveVariables>();
51 AU.setPreservesAll();
Owen Anderson0bda0e82007-10-31 03:37:57 +000052 MachineFunctionPass::getAnalysisUsage(AU);
53 }
54
55 virtual void releaseMemory() {
56 preorder.clear();
57 maxpreorder.clear();
Owen Andersona4ad2e72007-11-06 04:49:43 +000058
59 waiting.clear();
Owen Anderson0bda0e82007-10-31 03:37:57 +000060 }
61
62 private:
Owen Anderson83430bc2007-11-04 22:33:26 +000063 struct DomForestNode {
64 private:
65 std::vector<DomForestNode*> children;
Owen Andersonee49b532007-11-06 05:22:43 +000066 unsigned reg;
Owen Anderson83430bc2007-11-04 22:33:26 +000067
68 void addChild(DomForestNode* DFN) { children.push_back(DFN); }
69
70 public:
71 typedef std::vector<DomForestNode*>::iterator iterator;
72
Owen Andersonee49b532007-11-06 05:22:43 +000073 DomForestNode(unsigned r, DomForestNode* parent) : reg(r) {
Owen Anderson83430bc2007-11-04 22:33:26 +000074 if (parent)
75 parent->addChild(this);
76 }
77
Owen Andersona4ad2e72007-11-06 04:49:43 +000078 ~DomForestNode() {
79 for (iterator I = begin(), E = end(); I != E; ++I)
80 delete *I;
81 }
Owen Anderson83430bc2007-11-04 22:33:26 +000082
Owen Andersonee49b532007-11-06 05:22:43 +000083 inline unsigned getReg() { return reg; }
Owen Andersona4ad2e72007-11-06 04:49:43 +000084
85 inline DomForestNode::iterator begin() { return children.begin(); }
86 inline DomForestNode::iterator end() { return children.end(); }
Owen Anderson83430bc2007-11-04 22:33:26 +000087 };
88
Owen Anderson0bda0e82007-10-31 03:37:57 +000089 DenseMap<MachineBasicBlock*, unsigned> preorder;
90 DenseMap<MachineBasicBlock*, unsigned> maxpreorder;
91
Owen Andersona4ad2e72007-11-06 04:49:43 +000092 DenseMap<MachineBasicBlock*, std::vector<MachineInstr*> > waiting;
93
94
Owen Anderson0bda0e82007-10-31 03:37:57 +000095 void computeDFS(MachineFunction& MF);
Owen Anderson60a877d2007-11-07 05:17:15 +000096 void processBlock(MachineBasicBlock* MBB);
Owen Anderson83430bc2007-11-04 22:33:26 +000097
Owen Andersonee49b532007-11-06 05:22:43 +000098 std::vector<DomForestNode*> computeDomForest(std::set<unsigned>& instrs);
Owen Andersond525f662007-12-11 20:12:11 +000099 void processPHIUnion(MachineInstr* Inst,
100 std::set<unsigned>& PHIUnion,
Owen Anderson62d67dd2007-12-13 05:53:03 +0000101 std::vector<StrongPHIElimination::DomForestNode*>& DF,
102 std::vector<std::pair<unsigned, unsigned> >& locals);
Owen Anderson83430bc2007-11-04 22:33:26 +0000103
Owen Anderson0bda0e82007-10-31 03:37:57 +0000104 };
105
106 char StrongPHIElimination::ID = 0;
107 RegisterPass<StrongPHIElimination> X("strong-phi-node-elimination",
108 "Eliminate PHI nodes for register allocation, intelligently");
109}
110
111const PassInfo *llvm::StrongPHIEliminationID = X.getPassInfo();
112
113/// computeDFS - Computes the DFS-in and DFS-out numbers of the dominator tree
114/// of the given MachineFunction. These numbers are then used in other parts
115/// of the PHI elimination process.
116void StrongPHIElimination::computeDFS(MachineFunction& MF) {
117 SmallPtrSet<MachineDomTreeNode*, 8> frontier;
118 SmallPtrSet<MachineDomTreeNode*, 8> visited;
119
120 unsigned time = 0;
121
122 MachineDominatorTree& DT = getAnalysis<MachineDominatorTree>();
123
124 MachineDomTreeNode* node = DT.getRootNode();
125
126 std::vector<MachineDomTreeNode*> worklist;
127 worklist.push_back(node);
128
129 while (!worklist.empty()) {
130 MachineDomTreeNode* currNode = worklist.back();
131
132 if (!frontier.count(currNode)) {
133 frontier.insert(currNode);
134 ++time;
135 preorder.insert(std::make_pair(currNode->getBlock(), time));
136 }
137
138 bool inserted = false;
139 for (MachineDomTreeNode::iterator I = node->begin(), E = node->end();
140 I != E; ++I)
141 if (!frontier.count(*I) && !visited.count(*I)) {
142 worklist.push_back(*I);
143 inserted = true;
144 break;
145 }
146
147 if (!inserted) {
148 frontier.erase(currNode);
149 visited.insert(currNode);
150 maxpreorder.insert(std::make_pair(currNode->getBlock(), time));
151
152 worklist.pop_back();
153 }
154 }
Duncan Sands1bd32712007-10-31 08:49:24 +0000155}
Owen Anderson83430bc2007-11-04 22:33:26 +0000156
Owen Anderson8b96b9f2007-11-06 05:26:02 +0000157/// PreorderSorter - a helper class that is used to sort registers
158/// according to the preorder number of their defining blocks
Owen Anderson83430bc2007-11-04 22:33:26 +0000159class PreorderSorter {
160private:
161 DenseMap<MachineBasicBlock*, unsigned>& preorder;
Owen Andersonee49b532007-11-06 05:22:43 +0000162 LiveVariables& LV;
Owen Anderson83430bc2007-11-04 22:33:26 +0000163
164public:
Owen Andersonee49b532007-11-06 05:22:43 +0000165 PreorderSorter(DenseMap<MachineBasicBlock*, unsigned>& p,
166 LiveVariables& L) : preorder(p), LV(L) { }
Owen Anderson83430bc2007-11-04 22:33:26 +0000167
Owen Andersonee49b532007-11-06 05:22:43 +0000168 bool operator()(unsigned A, unsigned B) {
Owen Anderson83430bc2007-11-04 22:33:26 +0000169 if (A == B)
170 return false;
171
Owen Andersonee49b532007-11-06 05:22:43 +0000172 MachineBasicBlock* ABlock = LV.getVarInfo(A).DefInst->getParent();
173 MachineBasicBlock* BBlock = LV.getVarInfo(A).DefInst->getParent();
174
175 if (preorder[ABlock] < preorder[BBlock])
Owen Anderson83430bc2007-11-04 22:33:26 +0000176 return true;
Owen Andersonee49b532007-11-06 05:22:43 +0000177 else if (preorder[ABlock] > preorder[BBlock])
Owen Anderson83430bc2007-11-04 22:33:26 +0000178 return false;
179
Owen Andersonee49b532007-11-06 05:22:43 +0000180 assert(0 && "Error sorting by dominance!");
181 return false;
Owen Anderson83430bc2007-11-04 22:33:26 +0000182 }
183};
184
Owen Anderson8b96b9f2007-11-06 05:26:02 +0000185/// computeDomForest - compute the subforest of the DomTree corresponding
186/// to the defining blocks of the registers in question
Owen Anderson83430bc2007-11-04 22:33:26 +0000187std::vector<StrongPHIElimination::DomForestNode*>
Owen Andersonee49b532007-11-06 05:22:43 +0000188StrongPHIElimination::computeDomForest(std::set<unsigned>& regs) {
189 LiveVariables& LV = getAnalysis<LiveVariables>();
190
Owen Anderson83430bc2007-11-04 22:33:26 +0000191 DomForestNode* VirtualRoot = new DomForestNode(0, 0);
192 maxpreorder.insert(std::make_pair((MachineBasicBlock*)0, ~0UL));
193
Owen Andersonee49b532007-11-06 05:22:43 +0000194 std::vector<unsigned> worklist;
195 worklist.reserve(regs.size());
196 for (std::set<unsigned>::iterator I = regs.begin(), E = regs.end();
197 I != E; ++I)
Owen Anderson83430bc2007-11-04 22:33:26 +0000198 worklist.push_back(*I);
Owen Andersonee49b532007-11-06 05:22:43 +0000199
200 PreorderSorter PS(preorder, LV);
Owen Anderson83430bc2007-11-04 22:33:26 +0000201 std::sort(worklist.begin(), worklist.end(), PS);
202
203 DomForestNode* CurrentParent = VirtualRoot;
204 std::vector<DomForestNode*> stack;
205 stack.push_back(VirtualRoot);
206
Owen Andersonee49b532007-11-06 05:22:43 +0000207 for (std::vector<unsigned>::iterator I = worklist.begin(), E = worklist.end();
208 I != E; ++I) {
209 unsigned pre = preorder[LV.getVarInfo(*I).DefInst->getParent()];
210 MachineBasicBlock* parentBlock =
211 LV.getVarInfo(CurrentParent->getReg()).DefInst->getParent();
212
213 while (pre > maxpreorder[parentBlock]) {
Owen Anderson83430bc2007-11-04 22:33:26 +0000214 stack.pop_back();
215 CurrentParent = stack.back();
Owen Andersonee49b532007-11-06 05:22:43 +0000216
217 parentBlock = LV.getVarInfo(CurrentParent->getReg()).DefInst->getParent();
Owen Anderson83430bc2007-11-04 22:33:26 +0000218 }
219
220 DomForestNode* child = new DomForestNode(*I, CurrentParent);
221 stack.push_back(child);
222 CurrentParent = child;
223 }
224
225 std::vector<DomForestNode*> ret;
226 ret.insert(ret.end(), VirtualRoot->begin(), VirtualRoot->end());
227 return ret;
228}
Owen Andersona4ad2e72007-11-06 04:49:43 +0000229
Owen Anderson60a877d2007-11-07 05:17:15 +0000230/// isLiveIn - helper method that determines, from a VarInfo, if a register
231/// is live into a block
232bool isLiveIn(LiveVariables::VarInfo& V, MachineBasicBlock* MBB) {
233 if (V.AliveBlocks.test(MBB->getNumber()))
234 return true;
Owen Andersonee49b532007-11-06 05:22:43 +0000235
Owen Anderson14b3fb72007-11-08 01:32:45 +0000236 if (V.DefInst->getParent() != MBB &&
237 V.UsedBlocks.test(MBB->getNumber()))
238 return true;
Owen Anderson60a877d2007-11-07 05:17:15 +0000239
240 return false;
241}
242
243/// isLiveOut - help method that determines, from a VarInfo, if a register is
244/// live out of a block.
245bool isLiveOut(LiveVariables::VarInfo& V, MachineBasicBlock* MBB) {
Owen Anderson14b3fb72007-11-08 01:32:45 +0000246 if (MBB == V.DefInst->getParent() ||
247 V.UsedBlocks.test(MBB->getNumber())) {
248 for (std::vector<MachineInstr*>::iterator I = V.Kills.begin(),
249 E = V.Kills.end(); I != E; ++I)
250 if ((*I)->getParent() == MBB)
251 return false;
252
Owen Anderson60a877d2007-11-07 05:17:15 +0000253 return true;
Owen Anderson14b3fb72007-11-08 01:32:45 +0000254 }
Owen Anderson60a877d2007-11-07 05:17:15 +0000255
256 return false;
257}
258
Owen Anderson87a702b2007-12-16 05:44:27 +0000259/// isKillInst - helper method that determines, from a VarInfo, if an
260/// instruction kills a given register
261bool isKillInst(LiveVariables::VarInfo& V, MachineInstr* MI) {
262 return std::find(V.Kills.begin(), V.Kills.end(), MI) != V.Kills.end();
263}
264
265/// interferes - checks for local interferences by scanning a block. The only
266/// trick parameter is 'mode' which tells it the relationship of the two
267/// registers. 0 - defined in the same block, 1 - first properly dominates
268/// second, 2 - second properly dominates first
269bool interferes(LiveVariables::VarInfo& First, LiveVariables::VarInfo& Second,
270 MachineBasicBlock* scan, unsigned mode) {
271 MachineInstr* def = 0;
272 MachineInstr* kill = 0;
273
274 bool interference = false;
275
276 // Wallk the block, checking for interferences
277 for (MachineBasicBlock::iterator MBI = scan->begin(), MBE = scan->end();
278 MBI != MBE; ++MBI) {
279 MachineInstr* curr = MBI;
280
281 // Same defining block...
282 if (mode == 0) {
283 if (curr == First.DefInst) {
284 // If we find our first DefInst, save it
285 if (!def) {
286 def = curr;
287 // If there's already an unkilled DefInst, then
288 // this is an interference
289 } else if (!kill) {
290 interference = true;
291 break;
292 // If there's a DefInst followed by a KillInst, then
293 // they can't interfere
294 } else {
295 interference = false;
296 break;
297 }
298 // Symmetric with the above
299 } else if (curr == Second.DefInst ) {
300 if (!def) {
301 def = curr;
302 } else if (!kill) {
303 interference = true;
304 break;
305 } else {
306 interference = false;
307 break;
308 }
309 // Store KillInsts if they match up with the DefInst
310 } else if (isKillInst(First, curr)) {
311 if (def == First.DefInst) {
312 kill = curr;
313 } else if (isKillInst(Second, curr)) {
314 if (def == Second.DefInst) {
315 kill = curr;
316 }
317 }
318 }
319 // First properly dominates second...
320 } else if (mode == 1) {
321 if (curr == Second.DefInst) {
322 // DefInst of second without kill of first is an interference
323 if (!kill) {
324 interference = true;
325 break;
326 // DefInst after a kill is a non-interference
327 } else {
328 interference = false;
329 break;
330 }
331 // Save KillInsts of First
332 } else if (isKillInst(First, curr)) {
333 kill = curr;
334 }
335 // Symmetric with the above
336 } else if (mode == 2) {
337 if (curr == First.DefInst) {
338 if (!kill) {
339 interference = true;
340 break;
341 } else {
342 interference = false;
343 break;
344 }
345 } else if (isKillInst(Second, curr)) {
346 kill = curr;
347 }
348 }
349 }
350
351 return interference;
352}
353
Owen Anderson60a877d2007-11-07 05:17:15 +0000354/// processBlock - Eliminate PHIs in the given block
355void StrongPHIElimination::processBlock(MachineBasicBlock* MBB) {
356 LiveVariables& LV = getAnalysis<LiveVariables>();
357
358 // Holds names that have been added to a set in any PHI within this block
359 // before the current one.
360 std::set<unsigned> ProcessedNames;
361
362 MachineBasicBlock::iterator P = MBB->begin();
363 while (P->getOpcode() == TargetInstrInfo::PHI) {
364 LiveVariables::VarInfo& PHIInfo = LV.getVarInfo(P->getOperand(0).getReg());
365
Owen Andersonafc6de02007-12-10 08:07:09 +0000366 unsigned DestReg = P->getOperand(0).getReg();
367
Owen Anderson60a877d2007-11-07 05:17:15 +0000368 // Hold the names that are currently in the candidate set.
369 std::set<unsigned> PHIUnion;
370 std::set<MachineBasicBlock*> UnionedBlocks;
371
372 for (int i = P->getNumOperands() - 1; i >= 2; i-=2) {
373 unsigned SrcReg = P->getOperand(i-1).getReg();
374 LiveVariables::VarInfo& SrcInfo = LV.getVarInfo(SrcReg);
375
Owen Andersonafc6de02007-12-10 08:07:09 +0000376 // Check for trivial interferences
377 if (isLiveIn(SrcInfo, P->getParent()) ||
378 isLiveOut(PHIInfo, SrcInfo.DefInst->getParent()) ||
379 ( PHIInfo.DefInst->getOpcode() == TargetInstrInfo::PHI &&
380 isLiveIn(PHIInfo, SrcInfo.DefInst->getParent()) ) ||
381 ProcessedNames.count(SrcReg) ||
382 UnionedBlocks.count(SrcInfo.DefInst->getParent())) {
383
Owen Anderson60a877d2007-11-07 05:17:15 +0000384 // add a copy from a_i to p in Waiting[From[a_i]]
Owen Andersonafc6de02007-12-10 08:07:09 +0000385 MachineBasicBlock* From = P->getOperand(i).getMachineBasicBlock();
386 Waiting[From].push_back(std::make_pair(SrcReg, DestReg));
Owen Anderson60a877d2007-11-07 05:17:15 +0000387 } else {
388 PHIUnion.insert(SrcReg);
389 UnionedBlocks.insert(SrcInfo.DefInst->getParent());
Owen Anderson60a877d2007-11-07 05:17:15 +0000390 }
Owen Anderson60a877d2007-11-07 05:17:15 +0000391 }
392
Owen Anderson42f9e962007-11-13 20:13:24 +0000393 std::vector<StrongPHIElimination::DomForestNode*> DF =
394 computeDomForest(PHIUnion);
395
Owen Andersonafc6de02007-12-10 08:07:09 +0000396 // Walk DomForest to resolve interferences
Owen Anderson62d67dd2007-12-13 05:53:03 +0000397 std::vector<std::pair<unsigned, unsigned> > localInterferences;
398 processPHIUnion(P, PHIUnion, DF, localInterferences);
399
400 // FIXME: Check for local interferences
Owen Anderson87a702b2007-12-16 05:44:27 +0000401 for (std::vector<std::pair<unsigned, unsigned> >::iterator I =
402 localInterferences.begin(), E = localInterferences.end(); I != E; ++I) {
403 std::pair<unsigned, unsigned> p = *I;
404
405 LiveVariables::VarInfo& FirstInfo = LV.getVarInfo(p.first);
406 LiveVariables::VarInfo& SecondInfo = LV.getVarInfo(p.second);
407
408 MachineDominatorTree& MDT = getAnalysis<MachineDominatorTree>();
409
410 // Determine the block we need to scan and the relationship between
411 // the two registers
412 MachineBasicBlock* scan = 0;
413 unsigned mode = 0;
414 if (FirstInfo.DefInst->getParent() == SecondInfo.DefInst->getParent()) {
415 scan = FirstInfo.DefInst->getParent();
416 mode = 0; // Same block
417 } else if (MDT.dominates(FirstInfo.DefInst->getParent(),
418 SecondInfo.DefInst->getParent())) {
419 scan = SecondInfo.DefInst->getParent();
420 mode = 1; // First dominates second
421 } else {
422 scan = FirstInfo.DefInst->getParent();
423 mode = 2; // Second dominates first
424 }
425
426 // If there's an interference, we need to insert copies
427 if (interferes(FirstInfo, SecondInfo, scan, mode)) {
428 // Insert copies for First
429 for (int i = P->getNumOperands() - 1; i >= 2; i-=2) {
430 if (P->getOperand(i-1).getReg() == p.first) {
431 unsigned SrcReg = p.first;
432 MachineBasicBlock* From = P->getOperand(i).getMBB();
433
434 Waiting[From].push_back(std::make_pair(SrcReg,
435 P->getOperand(0).getReg()));
436 PHIUnion.erase(SrcReg);
437 }
438 }
439 }
440 }
Owen Anderson42f9e962007-11-13 20:13:24 +0000441
442 ProcessedNames.insert(PHIUnion.begin(), PHIUnion.end());
Owen Anderson60a877d2007-11-07 05:17:15 +0000443 ++P;
444 }
Owen Andersonee49b532007-11-06 05:22:43 +0000445}
446
Owen Anderson965b4672007-12-16 04:07:23 +0000447/// processPHIUnion - Take a set of candidate registers to be coallesced when
448/// decomposing the PHI instruction. Use the DominanceForest to remove the ones
449/// that are known to interfere, and flag others that need to be checked for
450/// local interferences.
Owen Andersond525f662007-12-11 20:12:11 +0000451void StrongPHIElimination::processPHIUnion(MachineInstr* Inst,
452 std::set<unsigned>& PHIUnion,
Owen Anderson62d67dd2007-12-13 05:53:03 +0000453 std::vector<StrongPHIElimination::DomForestNode*>& DF,
454 std::vector<std::pair<unsigned, unsigned> >& locals) {
Owen Andersond525f662007-12-11 20:12:11 +0000455
456 std::vector<DomForestNode*> worklist(DF.begin(), DF.end());
457 SmallPtrSet<DomForestNode*, 4> visited;
458
459 LiveVariables& LV = getAnalysis<LiveVariables>();
460 unsigned DestReg = Inst->getOperand(0).getReg();
461
Owen Anderson965b4672007-12-16 04:07:23 +0000462 // DF walk on the DomForest
Owen Andersond525f662007-12-11 20:12:11 +0000463 while (!worklist.empty()) {
464 DomForestNode* DFNode = worklist.back();
465
466 LiveVariables::VarInfo& Info = LV.getVarInfo(DFNode->getReg());
467 visited.insert(DFNode);
468
469 bool inserted = false;
Owen Andersond525f662007-12-11 20:12:11 +0000470 for (DomForestNode::iterator CI = DFNode->begin(), CE = DFNode->end();
471 CI != CE; ++CI) {
472 DomForestNode* child = *CI;
473 LiveVariables::VarInfo& CInfo = LV.getVarInfo(child->getReg());
474
475 if (isLiveOut(Info, CInfo.DefInst->getParent())) {
Owen Andersond525f662007-12-11 20:12:11 +0000476 // Insert copies for parent
477 for (int i = Inst->getNumOperands() - 1; i >= 2; i-=2) {
478 if (Inst->getOperand(i-1).getReg() == DFNode->getReg()) {
Owen Andersoned2ffa22007-12-12 01:25:08 +0000479 unsigned SrcReg = DFNode->getReg();
Owen Andersond525f662007-12-11 20:12:11 +0000480 MachineBasicBlock* From = Inst->getOperand(i).getMBB();
481
482 Waiting[From].push_back(std::make_pair(SrcReg, DestReg));
Owen Andersoned2ffa22007-12-12 01:25:08 +0000483 PHIUnion.erase(SrcReg);
Owen Andersond525f662007-12-11 20:12:11 +0000484 }
485 }
Owen Anderson4ba08ec2007-12-13 05:43:37 +0000486 } else if (isLiveIn(Info, CInfo.DefInst->getParent()) ||
487 Info.DefInst->getParent() == CInfo.DefInst->getParent()) {
Owen Anderson62d67dd2007-12-13 05:53:03 +0000488 // Add (p, c) to possible local interferences
489 locals.push_back(std::make_pair(DFNode->getReg(), child->getReg()));
Owen Andersond525f662007-12-11 20:12:11 +0000490 }
Owen Anderson965b4672007-12-16 04:07:23 +0000491
Owen Anderson4ba08ec2007-12-13 05:43:37 +0000492 if (!visited.count(child)) {
493 worklist.push_back(child);
494 inserted = true;
Owen Andersond525f662007-12-11 20:12:11 +0000495 }
496 }
497
498 if (!inserted) worklist.pop_back();
499 }
500}
501
Owen Andersona4ad2e72007-11-06 04:49:43 +0000502bool StrongPHIElimination::runOnMachineFunction(MachineFunction &Fn) {
503 computeDFS(Fn);
504
Owen Anderson60a877d2007-11-07 05:17:15 +0000505 for (MachineFunction::iterator I = Fn.begin(), E = Fn.end(); I != E; ++I)
506 if (!I->empty() &&
507 I->begin()->getOpcode() == TargetInstrInfo::PHI)
508 processBlock(I);
Owen Andersona4ad2e72007-11-06 04:49:43 +0000509
510 return false;
511}