return BA->getNumber() > BB->getNumber();
}
- MachineBasicBlock::const_iterator ItA = InstA->getIterator();
- MachineBasicBlock::const_iterator ItB = InstB->getIterator();
- MachineBasicBlock::const_iterator End = BA->end();
- while (ItA != End) {
- if (ItA == ItB)
- return false; // ItA was before ItB.
- ++ItA;
- }
- return true;
+ auto getDist = [this] (const MachineInstr *MI) {
+ auto F = Dist.find(MI);
+ if (F != Dist.end())
+ return F->second;
+ MachineBasicBlock::const_iterator I = MI->getParent()->begin();
+ MachineBasicBlock::const_iterator E = MI->getIterator();
+ unsigned D = std::distance(I, E);
+ Dist.insert(std::make_pair(MI, D));
+ return D;
+ };
+
+ return getDist(InstA) > getDist(InstB);
}
// Main W-Z implementation.
runEdgeQueue(BlockScanned);
runUseQueue();
}
+ UseQ.reset();
if (Trace)
print_cells(dbgs() << "Cells after propagation:\n");
// Priority queue of instructions using modified registers, ordered by
// their relative position in a basic block.
struct UseQueueType {
+ UseQueueType() : Uses(Dist) {}
+
unsigned size() const {
return Uses.size();
}
Set.erase(front());
Uses.pop();
}
+ void reset() {
+ Dist.clear();
+ }
private:
struct Cmp {
+ Cmp(DenseMap<const MachineInstr*,unsigned> &Map) : Dist(Map) {}
bool operator()(const MachineInstr *MI, const MachineInstr *MJ) const;
+ DenseMap<const MachineInstr*,unsigned> &Dist;
};
std::priority_queue<MachineInstr*, std::vector<MachineInstr*>, Cmp> Uses;
- DenseSet<MachineInstr*> Set; // Set to avoid adding duplicate entries.
+ DenseSet<const MachineInstr*> Set; // Set to avoid adding duplicate entries.
+ DenseMap<const MachineInstr*,unsigned> Dist;
};
void reset();