blob: 55b45d01b20ee4addec80592335bb77e6ffb8ec7 [file] [log] [blame]
Chris Lattnerc6644182006-03-07 06:32:48 +00001//===-- PPCHazardRecognizers.h - PowerPC Hazard Recognizers -----*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Chris Lattnerc6644182006-03-07 06:32:48 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file defines hazard recognizers for scheduling on PowerPC processors.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef PPCHAZRECS_H
15#define PPCHAZRECS_H
16
Craig Topper79aa3412012-03-17 18:46:09 +000017#include "PPCInstrInfo.h"
Dan Gohmanfc54c552009-01-15 22:18:12 +000018#include "llvm/CodeGen/ScheduleHazardRecognizer.h"
Hal Finkelc6d08f12011-10-17 04:03:49 +000019#include "llvm/CodeGen/ScoreboardHazardRecognizer.h"
Dan Gohmanfc54c552009-01-15 22:18:12 +000020#include "llvm/CodeGen/SelectionDAGNodes.h"
Chris Lattnerc6644182006-03-07 06:32:48 +000021
22namespace llvm {
Andrew Trick6e8f4c42010-12-24 04:28:06 +000023
Hal Finkel5b00cea2012-03-31 14:45:15 +000024/// PPCScoreboardHazardRecognizer - This class implements a scoreboard-based
25/// hazard recognizer for generic PPC processors.
26class PPCScoreboardHazardRecognizer : public ScoreboardHazardRecognizer {
Hal Finkelc6d08f12011-10-17 04:03:49 +000027 const ScheduleDAG *DAG;
28public:
Hal Finkel5b00cea2012-03-31 14:45:15 +000029 PPCScoreboardHazardRecognizer(const InstrItineraryData *ItinData,
Hal Finkelc6d08f12011-10-17 04:03:49 +000030 const ScheduleDAG *DAG_) :
31 ScoreboardHazardRecognizer(ItinData, DAG_), DAG(DAG_) {}
32
Hal Finkel5b00cea2012-03-31 14:45:15 +000033 virtual HazardType getHazardType(SUnit *SU, int Stalls);
Hal Finkelc6d08f12011-10-17 04:03:49 +000034 virtual void EmitInstruction(SUnit *SU);
Hal Finkel5b00cea2012-03-31 14:45:15 +000035 virtual void AdvanceCycle();
36 virtual void Reset();
Hal Finkelc6d08f12011-10-17 04:03:49 +000037};
38
Chris Lattnerc6644182006-03-07 06:32:48 +000039/// PPCHazardRecognizer970 - This class defines a finite state automata that
40/// models the dispatch logic on the PowerPC 970 (aka G5) processor. This
41/// promotes good dispatch group formation and implements noop insertion to
42/// avoid structural hazards that cause significant performance penalties (e.g.
43/// setting the CTR register then branching through it within a dispatch group),
44/// or storing then loading from the same address within a dispatch group.
Dan Gohmanfc54c552009-01-15 22:18:12 +000045class PPCHazardRecognizer970 : public ScheduleHazardRecognizer {
Chris Lattner88d211f2006-03-12 09:13:49 +000046 const TargetInstrInfo &TII;
Andrew Trick6e8f4c42010-12-24 04:28:06 +000047
Chris Lattner88d211f2006-03-12 09:13:49 +000048 unsigned NumIssued; // Number of insts issued, including advanced cycles.
Andrew Trick6e8f4c42010-12-24 04:28:06 +000049
Chris Lattnerc6644182006-03-07 06:32:48 +000050 // Various things that can cause a structural hazard.
Andrew Trick6e8f4c42010-12-24 04:28:06 +000051
Chris Lattnerc6644182006-03-07 06:32:48 +000052 // HasCTRSet - If the CTR register is set in this group, disallow BCTRL.
53 bool HasCTRSet;
Andrew Trick6e8f4c42010-12-24 04:28:06 +000054
Chris Lattnerc6644182006-03-07 06:32:48 +000055 // StoredPtr - Keep track of the address of any store. If we see a load from
Chris Lattner88d211f2006-03-12 09:13:49 +000056 // the same address (or one that aliases it), disallow the store. We can have
57 // up to four stores in one dispatch group, hence we track up to 4.
Chris Lattnerc6644182006-03-07 06:32:48 +000058 //
59 // This is null if we haven't seen a store yet. We keep track of both
60 // operands of the store here, since we support [r+r] and [r+i] addressing.
Hal Finkel64c34e22011-12-02 04:58:02 +000061 const Value *StoreValue[4];
62 int64_t StoreOffset[4];
63 uint64_t StoreSize[4];
Chris Lattner88d211f2006-03-12 09:13:49 +000064 unsigned NumStores;
Andrew Trick6e8f4c42010-12-24 04:28:06 +000065
Chris Lattnerc6644182006-03-07 06:32:48 +000066public:
Chris Lattner88d211f2006-03-12 09:13:49 +000067 PPCHazardRecognizer970(const TargetInstrInfo &TII);
Andrew Trick2da8bc82010-12-24 05:03:26 +000068 virtual HazardType getHazardType(SUnit *SU, int Stalls);
Dan Gohmanfc54c552009-01-15 22:18:12 +000069 virtual void EmitInstruction(SUnit *SU);
Chris Lattnerc6644182006-03-07 06:32:48 +000070 virtual void AdvanceCycle();
Hal Finkel64c34e22011-12-02 04:58:02 +000071 virtual void Reset();
Andrew Trick6e8f4c42010-12-24 04:28:06 +000072
Chris Lattnerc6644182006-03-07 06:32:48 +000073private:
74 /// EndDispatchGroup - Called when we are finishing a new dispatch group.
75 ///
76 void EndDispatchGroup();
Andrew Trick6e8f4c42010-12-24 04:28:06 +000077
Chris Lattnerc6644182006-03-07 06:32:48 +000078 /// GetInstrType - Classify the specified powerpc opcode according to its
79 /// pipeline.
Chris Lattner88d211f2006-03-12 09:13:49 +000080 PPCII::PPC970_Unit GetInstrType(unsigned Opcode,
Chris Lattner3faad492006-03-13 05:20:04 +000081 bool &isFirst, bool &isSingle,bool &isCracked,
Chris Lattner88d211f2006-03-12 09:13:49 +000082 bool &isLoad, bool &isStore);
Andrew Trick6e8f4c42010-12-24 04:28:06 +000083
Hal Finkel64c34e22011-12-02 04:58:02 +000084 bool isLoadOfStoredAddress(uint64_t LoadSize, int64_t LoadOffset,
85 const Value *LoadValue) const;
Chris Lattnerc6644182006-03-07 06:32:48 +000086};
87
88} // end namespace llvm
89
Chris Lattnerab5801c2006-03-07 16:19:46 +000090#endif
91