TargetSchedModel API. Implement latency lookup, disabled.
[oota-llvm.git] / include / llvm / CodeGen / TargetSchedule.h
1 //===-- llvm/CodeGen/TargetSchedule.h - Sched Machine Model -----*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines a wrapper around MCSchedModel that allows the interface to
11 // benefit from information currently only available in TargetInstrInfo.
12 // Ideally, the scheduling interface would be fully defined in the MC layer.
13 //
14 //===----------------------------------------------------------------------===//
15
16 #ifndef LLVM_TARGET_TARGETSCHEDMODEL_H
17 #define LLVM_TARGET_TARGETSCHEDMODEL_H
18
19 #include "llvm/MC/MCSchedule.h"
20 #include "llvm/MC/MCInstrItineraries.h"
21
22 namespace llvm {
23
24 class TargetRegisterInfo;
25 class TargetSubtargetInfo;
26 class TargetInstrInfo;
27 class MachineInstr;
28
29 /// Provide an instruction scheduling machine model to CodeGen passes.
30 class TargetSchedModel {
31   // For efficiency, hold a copy of the statically defined MCSchedModel for this
32   // processor.
33   MCSchedModel SchedModel;
34   InstrItineraryData InstrItins;
35   const TargetSubtargetInfo *STI;
36   const TargetInstrInfo *TII;
37 public:
38   TargetSchedModel(): STI(0), TII(0) {}
39
40   void init(const MCSchedModel &sm, const TargetSubtargetInfo *sti,
41             const TargetInstrInfo *tii);
42
43   const TargetInstrInfo *getInstrInfo() const { return TII; }
44
45   /// Return true if this machine model includes an instruction-level scheduling
46   /// model. This is more detailed than the course grain IssueWidth and default
47   /// latency properties, but separate from the per-cycle itinerary data.
48   bool hasInstrSchedModel() const { return SchedModel.hasInstrSchedModel(); }
49
50   /// Return true if this machine model includes cycle-to-cycle itinerary
51   /// data. This models scheduling at each stage in the processor pipeline.
52   bool hasInstrItineraries() const { return !InstrItins.isEmpty(); }
53
54   /// computeOperandLatency - Compute and return the latency of the given data
55   /// dependent def and use when the operand indices are already known. UseMI
56   /// may be NULL for an unknown user.
57   ///
58   /// FindMin may be set to get the minimum vs. expected latency. Minimum
59   /// latency is used for scheduling groups, while expected latency is for
60   /// instruction cost and critical path.
61   unsigned computeOperandLatency(const MachineInstr *DefMI, unsigned DefOperIdx,
62                                  const MachineInstr *UseMI, unsigned UseOperIdx,
63                                  bool FindMin) const;
64
65   unsigned getProcessorID() const { return SchedModel.getProcessorID(); }
66
67 private:
68   /// getDefLatency is a helper for computeOperandLatency. Return the
69   /// instruction's latency if operand lookup is not required.
70   /// Otherwise return -1.
71   int getDefLatency(const MachineInstr *DefMI, bool FindMin) const;
72
73   /// Return the MCSchedClassDesc for this instruction.
74   const MCSchedClassDesc *resolveSchedClass(const MachineInstr *MI) const;
75 };
76
77 } // namespace llvm
78
79 #endif