@@ -32,23 +32,43 @@ void DGNode::dump() const {
32
32
}
33
33
#endif // NDEBUG
34
34
35
+ MemDGNode *
36
+ MemDGNodeIntervalBuilder::getTopMemDGNode (const Interval<Instruction> &Intvl,
37
+ const DependencyGraph &DAG) {
38
+ Instruction *I = Intvl.top ();
39
+ Instruction *BeforeI = Intvl.bottom ();
40
+ // Walk down the chain looking for a mem-dep candidate instruction.
41
+ while (!DGNode::isMemDepNodeCandidate (I) && I != BeforeI)
42
+ I = I->getNextNode ();
43
+ if (!DGNode::isMemDepNodeCandidate (I))
44
+ return nullptr ;
45
+ return cast<MemDGNode>(DAG.getNode (I));
46
+ }
47
+
48
+ MemDGNode *
49
+ MemDGNodeIntervalBuilder::getBotMemDGNode (const Interval<Instruction> &Intvl,
50
+ const DependencyGraph &DAG) {
51
+ Instruction *I = Intvl.bottom ();
52
+ Instruction *AfterI = Intvl.top ();
53
+ // Walk up the chain looking for a mem-dep candidate instruction.
54
+ while (!DGNode::isMemDepNodeCandidate (I) && I != AfterI)
55
+ I = I->getPrevNode ();
56
+ if (!DGNode::isMemDepNodeCandidate (I))
57
+ return nullptr ;
58
+ return cast<MemDGNode>(DAG.getNode (I));
59
+ }
60
+
35
61
Interval<MemDGNode>
36
62
MemDGNodeIntervalBuilder::make (const Interval<Instruction> &Instrs,
37
63
DependencyGraph &DAG) {
38
- // If top or bottom instructions are not mem-dep candidate nodes we need to
39
- // walk down/up the chain and find the mem-dep ones.
40
- Instruction *MemTopI = Instrs.top ();
41
- Instruction *MemBotI = Instrs.bottom ();
42
- while (!DGNode::isMemDepNodeCandidate (MemTopI) && MemTopI != MemBotI)
43
- MemTopI = MemTopI->getNextNode ();
44
- while (!DGNode::isMemDepNodeCandidate (MemBotI) && MemBotI != MemTopI)
45
- MemBotI = MemBotI->getPrevNode ();
64
+ auto *TopMemN = getTopMemDGNode (Instrs, DAG);
46
65
// If we couldn't find a mem node in range TopN - BotN then it's empty.
47
- if (! DGNode::isMemDepNodeCandidate (MemTopI) )
66
+ if (TopMemN == nullptr )
48
67
return {};
68
+ auto *BotMemN = getBotMemDGNode (Instrs, DAG);
69
+ assert (BotMemN != nullptr && " TopMemN should be null too!" );
49
70
// Now that we have the mem-dep nodes, create and return the range.
50
- return Interval<MemDGNode>(cast<MemDGNode>(DAG.getNode (MemTopI)),
51
- cast<MemDGNode>(DAG.getNode (MemBotI)));
71
+ return Interval<MemDGNode>(TopMemN, BotMemN);
52
72
}
53
73
54
74
DependencyGraph::DependencyType
0 commit comments