[llvm-commits] [llvm] r169319 - in /llvm/trunk/lib/CodeGen: AllocationOrder.cpp AllocationOrder.h RegAllocGreedy.cpp
Jakob Stoklund Olesen
stoklund at 2pi.dk
Tue Dec 4 14:25:16 PST 2012
Author: stoklund
Date: Tue Dec 4 16:25:16 2012
New Revision: 169319
URL: http://llvm.org/viewvc/llvm-project?rev=169319&view=rev
Log:
Speed up the AllocationOrder class a bit.
Allow the central functions to be inlined, and use the argumentless
isHint() function when possible.
Modified:
llvm/trunk/lib/CodeGen/AllocationOrder.cpp
llvm/trunk/lib/CodeGen/AllocationOrder.h
llvm/trunk/lib/CodeGen/RegAllocGreedy.cpp
Modified: llvm/trunk/lib/CodeGen/AllocationOrder.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AllocationOrder.cpp?rev=169319&r1=169318&r2=169319&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AllocationOrder.cpp (original)
+++ llvm/trunk/lib/CodeGen/AllocationOrder.cpp Tue Dec 4 16:25:16 2012
@@ -35,6 +35,7 @@
const TargetRegisterInfo *TRI = &VRM.getTargetRegInfo();
Order = RegClassInfo.getOrder(MF.getRegInfo().getRegClass(VirtReg));
TRI->getRegAllocationHints(VirtReg, Order, Hints, MF, &VRM);
+ rewind();
DEBUG({
if (!Hints.empty()) {
@@ -45,21 +46,3 @@
}
});
}
-
-bool AllocationOrder::isHint(unsigned PhysReg) const {
- return std::find(Hints.begin(), Hints.end(), PhysReg) != Hints.end();
-}
-
-unsigned AllocationOrder::next() {
- if (Pos < Hints.size())
- return Hints[Pos++];
- ArrayRef<MCPhysReg>::iterator I = Order.begin() + (Pos - Hints.size());
- ArrayRef<MCPhysReg>::iterator E = Order.end();
- while (I != E) {
- unsigned Reg = *I++;
- ++Pos;
- if (!isHint(Reg))
- return Reg;
- }
- return 0;
-}
Modified: llvm/trunk/lib/CodeGen/AllocationOrder.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AllocationOrder.h?rev=169319&r1=169318&r2=169319&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AllocationOrder.h (original)
+++ llvm/trunk/lib/CodeGen/AllocationOrder.h Tue Dec 4 16:25:16 2012
@@ -28,7 +28,7 @@
class AllocationOrder {
SmallVector<MCPhysReg, 16> Hints;
ArrayRef<MCPhysReg> Order;
- unsigned Pos;
+ int Pos;
public:
/// Create a new AllocationOrder for VirtReg.
@@ -42,16 +42,27 @@
/// Return the next physical register in the allocation order, or 0.
/// It is safe to call next() again after it returned 0, it will keep
/// returning 0 until rewind() is called.
- unsigned next();
+ unsigned next() {
+ if (Pos < 0)
+ return Hints.end()[Pos++];
+ while (Pos < int(Order.size())) {
+ unsigned Reg = Order[Pos++];
+ if (!isHint(Reg))
+ return Reg;
+ }
+ return 0;
+ }
/// Start over from the beginning.
- void rewind() { Pos = 0; }
+ void rewind() { Pos = -int(Hints.size()); }
/// Return true if the last register returned from next() was a preferred register.
- bool isHint() const { return Pos <= Hints.size(); }
+ bool isHint() const { return Pos <= 0; }
/// Return true if PhysReg is a preferred register.
- bool isHint(unsigned PhysReg) const;
+ bool isHint(unsigned PhysReg) const {
+ return std::find(Hints.begin(), Hints.end(), PhysReg) != Hints.end();
+ }
};
} // end namespace llvm
Modified: llvm/trunk/lib/CodeGen/RegAllocGreedy.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/RegAllocGreedy.cpp?rev=169319&r1=169318&r2=169319&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/RegAllocGreedy.cpp (original)
+++ llvm/trunk/lib/CodeGen/RegAllocGreedy.cpp Tue Dec 4 16:25:16 2012
@@ -442,7 +442,7 @@
while ((PhysReg = Order.next()))
if (!Matrix->checkInterference(VirtReg, PhysReg))
break;
- if (!PhysReg || Order.isHint(PhysReg))
+ if (!PhysReg || Order.isHint())
return PhysReg;
// PhysReg is available, but there may be a better choice.
@@ -661,7 +661,7 @@
BestPhys = PhysReg;
// Stop if the hint can be used.
- if (Order.isHint(PhysReg))
+ if (Order.isHint())
break;
}
More information about the llvm-commits
mailing list