LLVM API Documentation

ScheduleHazardRecognizer.h

Go to the documentation of this file.
00001 //=- llvm/CodeGen/ScheduleHazardRecognizer.h - Scheduling Support -*- C++ -*-=//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file implements the ScheduleHazardRecognizer class, which implements
00011 // hazard-avoidance heuristics for scheduling.
00012 //
00013 //===----------------------------------------------------------------------===//
00014 
00015 #ifndef LLVM_CODEGEN_SCHEDULEHAZARDRECOGNIZER_H
00016 #define LLVM_CODEGEN_SCHEDULEHAZARDRECOGNIZER_H
00017 
00018 namespace llvm {
00019 
00020 class SUnit;
00021 
00022 /// HazardRecognizer - This determines whether or not an instruction can be
00023 /// issued this cycle, and whether or not a noop needs to be inserted to handle
00024 /// the hazard.
00025 class ScheduleHazardRecognizer {
00026 public:
00027   virtual ~ScheduleHazardRecognizer();
00028 
00029   enum HazardType {
00030     NoHazard,      // This instruction can be emitted at this cycle.
00031     Hazard,        // This instruction can't be emitted at this cycle.
00032     NoopHazard     // This instruction can't be emitted, and needs noops.
00033   };
00034 
00035   /// getHazardType - Return the hazard type of emitting this node.  There are
00036   /// three possible results.  Either:
00037   ///  * NoHazard: it is legal to issue this instruction on this cycle.
00038   ///  * Hazard: issuing this instruction would stall the machine.  If some
00039   ///     other instruction is available, issue it first.
00040   ///  * NoopHazard: issuing this instruction would break the program.  If
00041   ///     some other instruction can be issued, do so, otherwise issue a noop.
00042   virtual HazardType getHazardType(SUnit *) {
00043     return NoHazard;
00044   }
00045 
00046   /// Reset - This callback is invoked when a new block of
00047   /// instructions is about to be schedule. The hazard state should be
00048   /// set to an initialized state.
00049   virtual void Reset() {}
00050 
00051   /// EmitInstruction - This callback is invoked when an instruction is
00052   /// emitted, to advance the hazard state.
00053   virtual void EmitInstruction(SUnit *) {}
00054 
00055   /// AdvanceCycle - This callback is invoked when no instructions can be
00056   /// issued on this cycle without a hazard.  This should increment the
00057   /// internal state of the hazard recognizer so that previously "Hazard"
00058   /// instructions will now not be hazards.
00059   virtual void AdvanceCycle() {}
00060 
00061   /// EmitNoop - This callback is invoked when a noop was added to the
00062   /// instruction stream.
00063   virtual void EmitNoop() {
00064     // Default implementation: count it as a cycle.
00065     AdvanceCycle();
00066   }
00067 };
00068 
00069 }
00070 
00071 #endif