Avoid uncessary array copying.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@105955 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Evan Cheng 2010-06-14 20:18:40 +00:00
parent 6b601536ff
commit 538ccb0d99

View File

@ -35,6 +35,10 @@ namespace llvm {
/// instructions. /// instructions.
Class Window[8]; Class Window[8];
/// Pos - Current position pointing into Window.
///
unsigned Pos;
/// getClass - Classify the given SUnit. /// getClass - Classify the given SUnit.
Class getClass(const SUnit *SU) { Class getClass(const SUnit *SU) {
const MachineInstr *MI = SU->getInstr(); const MachineInstr *MI = SU->getInstr();
@ -49,8 +53,11 @@ namespace llvm {
/// Step - Rotate the existing entries in Window and insert the /// Step - Rotate the existing entries in Window and insert the
/// given class value in position as the most recent. /// given class value in position as the most recent.
void Step(Class C) { void Step(Class C) {
std::copy(Window+1, array_endof(Window), Window); Window[Pos] = C;
Window[array_lengthof(Window)-1] = C; if (Pos == 0)
Pos = array_lengthof(Window)-1;
else
--Pos;
} }
public: public:
@ -62,18 +69,23 @@ namespace llvm {
Class C = getClass(SU); Class C = getClass(SU);
if (C == Other) if (C == Other)
return NoHazard; return NoHazard;
unsigned Score = 0; unsigned Score = 0;
for (unsigned i = 0; i != array_lengthof(Window); ++i) for (unsigned i = array_lengthof(Window); i != 0; --i) {
if (Window[i] == C) unsigned RealPos = (Pos + (i-1)) % array_lengthof(Window);
Score += i + 1; if (Window[RealPos] == C) {
if (Score > array_lengthof(Window) * 2) Score += i;
return Hazard; if (Score > array_lengthof(Window) * 2)
return Hazard;
}
}
return NoHazard; return NoHazard;
} }
virtual void Reset() { virtual void Reset() {
for (unsigned i = 0; i != array_lengthof(Window); ++i) for (unsigned i = 0; i != array_lengthof(Window); ++i)
Window[i] = Other; Window[i] = Other;
Pos = array_lengthof(Window)-1;
} }
virtual void EmitInstruction(SUnit *SU) { virtual void EmitInstruction(SUnit *SU) {