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