blob: 32fac91eee6632ca5937a7e44dbe9e8c2e42c48e [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
Dan Gohmanfc54c552009-01-15 22:18:12 +000017#include "llvm/CodeGen/ScheduleHazardRecognizer.h"
Hal Finkelc6d08f12011-10-17 04:03:49 +000018#include "llvm/CodeGen/ScoreboardHazardRecognizer.h"
Dan Gohmanfc54c552009-01-15 22:18:12 +000019#include "llvm/CodeGen/SelectionDAGNodes.h"
Chris Lattner88d211f2006-03-12 09:13:49 +000020#include "PPCInstrInfo.h"
Chris Lattnerc6644182006-03-07 06:32:48 +000021
22namespace llvm {
Andrew Trick6e8f4c42010-12-24 04:28:06 +000023
Hal Finkelc6d08f12011-10-17 04:03:49 +000024/// PPCHazardRecognizer440 - This class implements a scoreboard-based
25/// hazard recognizer for the PPC 440 and friends.
26class PPCHazardRecognizer440 : public ScoreboardHazardRecognizer {
27 const ScheduleDAG *DAG;
28public:
29 PPCHazardRecognizer440(const InstrItineraryData *ItinData,
30 const ScheduleDAG *DAG_) :
31 ScoreboardHazardRecognizer(ItinData, DAG_), DAG(DAG_) {}
32
33 virtual void EmitInstruction(SUnit *SU);
34};
35
Chris Lattnerc6644182006-03-07 06:32:48 +000036/// PPCHazardRecognizer970 - This class defines a finite state automata that
37/// models the dispatch logic on the PowerPC 970 (aka G5) processor. This
38/// promotes good dispatch group formation and implements noop insertion to
39/// avoid structural hazards that cause significant performance penalties (e.g.
40/// setting the CTR register then branching through it within a dispatch group),
41/// or storing then loading from the same address within a dispatch group.
Dan Gohmanfc54c552009-01-15 22:18:12 +000042class PPCHazardRecognizer970 : public ScheduleHazardRecognizer {
Chris Lattner88d211f2006-03-12 09:13:49 +000043 const TargetInstrInfo &TII;
Andrew Trick6e8f4c42010-12-24 04:28:06 +000044
Chris Lattner88d211f2006-03-12 09:13:49 +000045 unsigned NumIssued; // Number of insts issued, including advanced cycles.
Andrew Trick6e8f4c42010-12-24 04:28:06 +000046
Chris Lattnerc6644182006-03-07 06:32:48 +000047 // Various things that can cause a structural hazard.
Andrew Trick6e8f4c42010-12-24 04:28:06 +000048
Chris Lattnerc6644182006-03-07 06:32:48 +000049 // HasCTRSet - If the CTR register is set in this group, disallow BCTRL.
50 bool HasCTRSet;
Andrew Trick6e8f4c42010-12-24 04:28:06 +000051
Chris Lattnerc6644182006-03-07 06:32:48 +000052 // StoredPtr - Keep track of the address of any store. If we see a load from
Chris Lattner88d211f2006-03-12 09:13:49 +000053 // the same address (or one that aliases it), disallow the store. We can have
54 // up to four stores in one dispatch group, hence we track up to 4.
Chris Lattnerc6644182006-03-07 06:32:48 +000055 //
56 // This is null if we haven't seen a store yet. We keep track of both
57 // operands of the store here, since we support [r+r] and [r+i] addressing.
Dan Gohman475871a2008-07-27 21:46:04 +000058 SDValue StorePtr1[4], StorePtr2[4];
Chris Lattner88d211f2006-03-12 09:13:49 +000059 unsigned StoreSize[4];
60 unsigned NumStores;
Andrew Trick6e8f4c42010-12-24 04:28:06 +000061
Chris Lattnerc6644182006-03-07 06:32:48 +000062public:
Chris Lattner88d211f2006-03-12 09:13:49 +000063 PPCHazardRecognizer970(const TargetInstrInfo &TII);
Andrew Trick2da8bc82010-12-24 05:03:26 +000064 virtual HazardType getHazardType(SUnit *SU, int Stalls);
Dan Gohmanfc54c552009-01-15 22:18:12 +000065 virtual void EmitInstruction(SUnit *SU);
Chris Lattnerc6644182006-03-07 06:32:48 +000066 virtual void AdvanceCycle();
Andrew Trick6e8f4c42010-12-24 04:28:06 +000067
Chris Lattnerc6644182006-03-07 06:32:48 +000068private:
69 /// EndDispatchGroup - Called when we are finishing a new dispatch group.
70 ///
71 void EndDispatchGroup();
Andrew Trick6e8f4c42010-12-24 04:28:06 +000072
Chris Lattnerc6644182006-03-07 06:32:48 +000073 /// GetInstrType - Classify the specified powerpc opcode according to its
74 /// pipeline.
Chris Lattner88d211f2006-03-12 09:13:49 +000075 PPCII::PPC970_Unit GetInstrType(unsigned Opcode,
Chris Lattner3faad492006-03-13 05:20:04 +000076 bool &isFirst, bool &isSingle,bool &isCracked,
Chris Lattner88d211f2006-03-12 09:13:49 +000077 bool &isLoad, bool &isStore);
Andrew Trick6e8f4c42010-12-24 04:28:06 +000078
Chris Lattnerc6644182006-03-07 06:32:48 +000079 bool isLoadOfStoredAddress(unsigned LoadSize,
Dan Gohman475871a2008-07-27 21:46:04 +000080 SDValue Ptr1, SDValue Ptr2) const;
Chris Lattnerc6644182006-03-07 06:32:48 +000081};
82
83} // end namespace llvm
84
Chris Lattnerab5801c2006-03-07 16:19:46 +000085#endif
86