blob: 2f81f0f7c7f1b0e42f6abb3b2c37392cf16a02ec [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"
18#include "llvm/CodeGen/SelectionDAGNodes.h"
Chris Lattner88d211f2006-03-12 09:13:49 +000019#include "PPCInstrInfo.h"
Chris Lattnerc6644182006-03-07 06:32:48 +000020
21namespace llvm {
Andrew Trick6e8f4c42010-12-24 04:28:06 +000022
Chris Lattnerc6644182006-03-07 06:32:48 +000023/// PPCHazardRecognizer970 - This class defines a finite state automata that
24/// models the dispatch logic on the PowerPC 970 (aka G5) processor. This
25/// promotes good dispatch group formation and implements noop insertion to
26/// avoid structural hazards that cause significant performance penalties (e.g.
27/// setting the CTR register then branching through it within a dispatch group),
28/// or storing then loading from the same address within a dispatch group.
Dan Gohmanfc54c552009-01-15 22:18:12 +000029class PPCHazardRecognizer970 : public ScheduleHazardRecognizer {
Chris Lattner88d211f2006-03-12 09:13:49 +000030 const TargetInstrInfo &TII;
Andrew Trick6e8f4c42010-12-24 04:28:06 +000031
Chris Lattner88d211f2006-03-12 09:13:49 +000032 unsigned NumIssued; // Number of insts issued, including advanced cycles.
Andrew Trick6e8f4c42010-12-24 04:28:06 +000033
Chris Lattnerc6644182006-03-07 06:32:48 +000034 // Various things that can cause a structural hazard.
Andrew Trick6e8f4c42010-12-24 04:28:06 +000035
Chris Lattnerc6644182006-03-07 06:32:48 +000036 // HasCTRSet - If the CTR register is set in this group, disallow BCTRL.
37 bool HasCTRSet;
Andrew Trick6e8f4c42010-12-24 04:28:06 +000038
Chris Lattnerc6644182006-03-07 06:32:48 +000039 // StoredPtr - Keep track of the address of any store. If we see a load from
Chris Lattner88d211f2006-03-12 09:13:49 +000040 // the same address (or one that aliases it), disallow the store. We can have
41 // up to four stores in one dispatch group, hence we track up to 4.
Chris Lattnerc6644182006-03-07 06:32:48 +000042 //
43 // This is null if we haven't seen a store yet. We keep track of both
44 // operands of the store here, since we support [r+r] and [r+i] addressing.
Dan Gohman475871a2008-07-27 21:46:04 +000045 SDValue StorePtr1[4], StorePtr2[4];
Chris Lattner88d211f2006-03-12 09:13:49 +000046 unsigned StoreSize[4];
47 unsigned NumStores;
Andrew Trick6e8f4c42010-12-24 04:28:06 +000048
Chris Lattnerc6644182006-03-07 06:32:48 +000049public:
Chris Lattner88d211f2006-03-12 09:13:49 +000050 PPCHazardRecognizer970(const TargetInstrInfo &TII);
Andrew Trick2da8bc82010-12-24 05:03:26 +000051 virtual HazardType getHazardType(SUnit *SU, int Stalls);
Dan Gohmanfc54c552009-01-15 22:18:12 +000052 virtual void EmitInstruction(SUnit *SU);
Chris Lattnerc6644182006-03-07 06:32:48 +000053 virtual void AdvanceCycle();
Andrew Trick6e8f4c42010-12-24 04:28:06 +000054
Chris Lattnerc6644182006-03-07 06:32:48 +000055private:
56 /// EndDispatchGroup - Called when we are finishing a new dispatch group.
57 ///
58 void EndDispatchGroup();
Andrew Trick6e8f4c42010-12-24 04:28:06 +000059
Chris Lattnerc6644182006-03-07 06:32:48 +000060 /// GetInstrType - Classify the specified powerpc opcode according to its
61 /// pipeline.
Chris Lattner88d211f2006-03-12 09:13:49 +000062 PPCII::PPC970_Unit GetInstrType(unsigned Opcode,
Chris Lattner3faad492006-03-13 05:20:04 +000063 bool &isFirst, bool &isSingle,bool &isCracked,
Chris Lattner88d211f2006-03-12 09:13:49 +000064 bool &isLoad, bool &isStore);
Andrew Trick6e8f4c42010-12-24 04:28:06 +000065
Chris Lattnerc6644182006-03-07 06:32:48 +000066 bool isLoadOfStoredAddress(unsigned LoadSize,
Dan Gohman475871a2008-07-27 21:46:04 +000067 SDValue Ptr1, SDValue Ptr2) const;
Chris Lattnerc6644182006-03-07 06:32:48 +000068};
69
70} // end namespace llvm
71
Chris Lattnerab5801c2006-03-07 16:19:46 +000072#endif
73