[llvm-commits] [llvm] r105955 - /llvm/trunk/lib/CodeGen/SimpleHazardRecognizer.h
Evan Cheng
evan.cheng at apple.com
Mon Jun 14 13:18:40 PDT 2010
Author: evancheng
Date: Mon Jun 14 15:18:40 2010
New Revision: 105955
URL: http://llvm.org/viewvc/llvm-project?rev=105955&view=rev
Log:
Avoid uncessary array copying.
Modified:
llvm/trunk/lib/CodeGen/SimpleHazardRecognizer.h
Modified: llvm/trunk/lib/CodeGen/SimpleHazardRecognizer.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SimpleHazardRecognizer.h?rev=105955&r1=105954&r2=105955&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/SimpleHazardRecognizer.h (original)
+++ llvm/trunk/lib/CodeGen/SimpleHazardRecognizer.h Mon Jun 14 15:18:40 2010
@@ -35,6 +35,10 @@
/// instructions.
Class Window[8];
+ /// Pos - Current position pointing into Window.
+ ///
+ unsigned Pos;
+
/// getClass - Classify the given SUnit.
Class getClass(const SUnit *SU) {
const MachineInstr *MI = SU->getInstr();
@@ -49,8 +53,11 @@
/// Step - Rotate the existing entries in Window and insert the
/// given class value in position as the most recent.
void Step(Class C) {
- std::copy(Window+1, array_endof(Window), Window);
- Window[array_lengthof(Window)-1] = C;
+ Window[Pos] = C;
+ if (Pos == 0)
+ Pos = array_lengthof(Window)-1;
+ else
+ --Pos;
}
public:
@@ -62,18 +69,23 @@
Class C = getClass(SU);
if (C == Other)
return NoHazard;
+
unsigned Score = 0;
- for (unsigned i = 0; i != array_lengthof(Window); ++i)
- if (Window[i] == C)
- Score += i + 1;
- if (Score > array_lengthof(Window) * 2)
- return Hazard;
+ for (unsigned i = array_lengthof(Window); i != 0; --i) {
+ unsigned RealPos = (Pos + (i-1)) % array_lengthof(Window);
+ if (Window[RealPos] == C) {
+ Score += i;
+ if (Score > array_lengthof(Window) * 2)
+ return Hazard;
+ }
+ }
return NoHazard;
}
virtual void Reset() {
for (unsigned i = 0; i != array_lengthof(Window); ++i)
Window[i] = Other;
+ Pos = array_lengthof(Window)-1;
}
virtual void EmitInstruction(SUnit *SU) {
More information about the llvm-commits
mailing list