1 //=- llvm/CodeGen/SimpleHazardRecognizer.h - Scheduling Support -*- C++ -*-=//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements the SimpleHazardRecognizer class, which
11 // implements hazard-avoidance heuristics for scheduling, based on the
12 // scheduling itineraries specified for the target.
14 //===----------------------------------------------------------------------===//
16 #ifndef LLVM_CODEGEN_SIMPLEHAZARDRECOGNIZER_H
17 #define LLVM_CODEGEN_SIMPLEHAZARDRECOGNIZER_H
19 #include "llvm/CodeGen/ScheduleHazardRecognizer.h"
20 #include "llvm/CodeGen/ScheduleDAG.h"
21 #include "llvm/Target/TargetMachine.h"
22 #include "llvm/Target/TargetInstrInfo.h"
25 /// SimpleHazardRecognizer - A *very* simple hazard recognizer. It uses
26 /// a coarse classification and attempts to avoid that instructions of
27 /// a given class aren't grouped too densely together.
28 class SimpleHazardRecognizer
: public ScheduleHazardRecognizer
{
29 /// Class - A simple classification for SUnits.
34 /// Window - The Class values of the most recently issued
38 /// getClass - Classify the given SUnit.
39 Class
getClass(const SUnit
*SU
) {
40 const MachineInstr
*MI
= SU
->getInstr();
41 const TargetInstrDesc
&TID
= MI
->getDesc();
49 /// Step - Rotate the existing entries in Window and insert the
50 /// given class value in position as the most recent.
52 std::copy(Window
+1, array_endof(Window
), Window
);
53 Window
[array_lengthof(Window
)-1] = C
;
57 SimpleHazardRecognizer() : Window() {
61 virtual HazardType
getHazardType(SUnit
*SU
) {
62 Class C
= getClass(SU
);
66 for (unsigned i
= 0; i
!= array_lengthof(Window
); ++i
)
69 if (Score
> array_lengthof(Window
) * 2)
74 virtual void Reset() {
75 for (unsigned i
= 0; i
!= array_lengthof(Window
); ++i
)
79 virtual void EmitInstruction(SUnit
*SU
) {
83 virtual void AdvanceCycle() {