@@ -32,23 +32,43 @@ void DGNode::dump() const {
3232}
3333#endif // NDEBUG
3434
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+
3561Interval<MemDGNode>
3662MemDGNodeIntervalBuilder::make (const Interval<Instruction> &Instrs,
3763 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);
4665 // 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 )
4867 return {};
68+ auto *BotMemN = getBotMemDGNode (Instrs, DAG);
69+ assert (BotMemN != nullptr && " TopMemN should be null too!" );
4970 // 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);
5272}
5373
5474DependencyGraph::DependencyType
0 commit comments