@@ -78,23 +78,43 @@ void MemDGNode::print(raw_ostream &OS, bool PrintDeps) const {
78
78
}
79
79
#endif // NDEBUG
80
80
81
+ MemDGNode *
82
+ MemDGNodeIntervalBuilder::getTopMemDGNode (const Interval<Instruction> &Intvl,
83
+ const DependencyGraph &DAG) {
84
+ Instruction *I = Intvl.top ();
85
+ Instruction *BeforeI = Intvl.bottom ();
86
+ // Walk down the chain looking for a mem-dep candidate instruction.
87
+ while (!DGNode::isMemDepNodeCandidate (I) && I != BeforeI)
88
+ I = I->getNextNode ();
89
+ if (!DGNode::isMemDepNodeCandidate (I))
90
+ return nullptr ;
91
+ return cast<MemDGNode>(DAG.getNode (I));
92
+ }
93
+
94
+ MemDGNode *
95
+ MemDGNodeIntervalBuilder::getBotMemDGNode (const Interval<Instruction> &Intvl,
96
+ const DependencyGraph &DAG) {
97
+ Instruction *I = Intvl.bottom ();
98
+ Instruction *AfterI = Intvl.top ();
99
+ // Walk up the chain looking for a mem-dep candidate instruction.
100
+ while (!DGNode::isMemDepNodeCandidate (I) && I != AfterI)
101
+ I = I->getPrevNode ();
102
+ if (!DGNode::isMemDepNodeCandidate (I))
103
+ return nullptr ;
104
+ return cast<MemDGNode>(DAG.getNode (I));
105
+ }
106
+
81
107
Interval<MemDGNode>
82
108
MemDGNodeIntervalBuilder::make (const Interval<Instruction> &Instrs,
83
109
DependencyGraph &DAG) {
84
- // If top or bottom instructions are not mem-dep candidate nodes we need to
85
- // walk down/up the chain and find the mem-dep ones.
86
- Instruction *MemTopI = Instrs.top ();
87
- Instruction *MemBotI = Instrs.bottom ();
88
- while (!DGNode::isMemDepNodeCandidate (MemTopI) && MemTopI != MemBotI)
89
- MemTopI = MemTopI->getNextNode ();
90
- while (!DGNode::isMemDepNodeCandidate (MemBotI) && MemBotI != MemTopI)
91
- MemBotI = MemBotI->getPrevNode ();
110
+ auto *TopMemN = getTopMemDGNode (Instrs, DAG);
92
111
// If we couldn't find a mem node in range TopN - BotN then it's empty.
93
- if (! DGNode::isMemDepNodeCandidate (MemTopI) )
112
+ if (TopMemN == nullptr )
94
113
return {};
114
+ auto *BotMemN = getBotMemDGNode (Instrs, DAG);
115
+ assert (BotMemN != nullptr && " TopMemN should be null too!" );
95
116
// Now that we have the mem-dep nodes, create and return the range.
96
- return Interval<MemDGNode>(cast<MemDGNode>(DAG.getNode (MemTopI)),
97
- cast<MemDGNode>(DAG.getNode (MemBotI)));
117
+ return Interval<MemDGNode>(TopMemN, BotMemN);
98
118
}
99
119
100
120
DependencyGraph::DependencyType
0 commit comments