summaryrefslogtreecommitdiffstats
path: root/llvm/lib/CodeGen/SimpleHazardRecognizer.h
diff options
context:
space:
mode:
authorEvan Cheng <evan.cheng@apple.com>2010-06-14 20:18:40 +0000
committerEvan Cheng <evan.cheng@apple.com>2010-06-14 20:18:40 +0000
commita397ada0784a18e6724ada0a6484843323c75baf (patch)
treee44a1976932d1e41539934eb1f5c881208499915 /llvm/lib/CodeGen/SimpleHazardRecognizer.h
parentfaa7bdccbfad3ca4d40039f229832f86de6aae93 (diff)
downloadbcm5719-llvm-a397ada0784a18e6724ada0a6484843323c75baf.tar.gz
bcm5719-llvm-a397ada0784a18e6724ada0a6484843323c75baf.zip
Avoid uncessary array copying.
llvm-svn: 105955
Diffstat (limited to 'llvm/lib/CodeGen/SimpleHazardRecognizer.h')
-rw-r--r--llvm/lib/CodeGen/SimpleHazardRecognizer.h26
1 files changed, 19 insertions, 7 deletions
diff --git a/llvm/lib/CodeGen/SimpleHazardRecognizer.h b/llvm/lib/CodeGen/SimpleHazardRecognizer.h
index f69feaf9e57..b9038e073e4 100644
--- a/llvm/lib/CodeGen/SimpleHazardRecognizer.h
+++ b/llvm/lib/CodeGen/SimpleHazardRecognizer.h
@@ -35,6 +35,10 @@ namespace llvm {
/// 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 @@ namespace llvm {
/// 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 @@ namespace llvm {
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) {
OpenPOWER on IntegriCloud