blob: 4b502147ca63851a19a5dbe448f8116c2794370d [file] [log] [blame]
Chris Lattner2cab1352006-03-07 06:32:48 +00001//===-- PPCHazardRecognizers.h - PowerPC Hazard Recognizers -----*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattnerf3ebc3f2007-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 Lattner2cab1352006-03-07 06:32:48 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file defines hazard recognizers for scheduling on PowerPC processors.
11//
12//===----------------------------------------------------------------------===//
13
Benjamin Kramera7c40ef2014-08-13 16:26:38 +000014#ifndef LLVM_LIB_TARGET_POWERPC_PPCHAZARDRECOGNIZERS_H
15#define LLVM_LIB_TARGET_POWERPC_PPCHAZARDRECOGNIZERS_H
Chris Lattner2cab1352006-03-07 06:32:48 +000016
Craig Topperb25fda92012-03-17 18:46:09 +000017#include "PPCInstrInfo.h"
Dan Gohman7e105f02009-01-15 22:18:12 +000018#include "llvm/CodeGen/ScheduleHazardRecognizer.h"
Hal Finkel6fa56972011-10-17 04:03:49 +000019#include "llvm/CodeGen/ScoreboardHazardRecognizer.h"
Dan Gohman7e105f02009-01-15 22:18:12 +000020#include "llvm/CodeGen/SelectionDAGNodes.h"
Chris Lattner2cab1352006-03-07 06:32:48 +000021
22namespace llvm {
Andrew Trickc416ba62010-12-24 04:28:06 +000023
Hal Finkelceb1f122013-12-12 00:19:11 +000024/// PPCDispatchGroupSBHazardRecognizer - This class implements a scoreboard-based
25/// hazard recognizer for PPC ooo processors with dispatch-group hazards.
26class PPCDispatchGroupSBHazardRecognizer : public ScoreboardHazardRecognizer {
27 const ScheduleDAG *DAG;
28 SmallVector<SUnit *, 7> CurGroup;
29 unsigned CurSlots, CurBranches;
30
31 bool isLoadAfterStore(SUnit *SU);
32 bool isBCTRAfterSet(SUnit *SU);
33 bool mustComeFirst(const MCInstrDesc *MCID, unsigned &NSlots);
34public:
35 PPCDispatchGroupSBHazardRecognizer(const InstrItineraryData *ItinData,
36 const ScheduleDAG *DAG_) :
37 ScoreboardHazardRecognizer(ItinData, DAG_), DAG(DAG_),
38 CurSlots(0), CurBranches(0) {}
39
Craig Topper0d3fa922014-04-29 07:57:37 +000040 HazardType getHazardType(SUnit *SU, int Stalls) override;
41 bool ShouldPreferAnother(SUnit* SU) override;
42 unsigned PreEmitNoops(SUnit *SU) override;
43 void EmitInstruction(SUnit *SU) override;
44 void AdvanceCycle() override;
45 void RecedeCycle() override;
46 void Reset() override;
47 void EmitNoop() override;
Hal Finkelceb1f122013-12-12 00:19:11 +000048};
49
Chris Lattner2cab1352006-03-07 06:32:48 +000050/// PPCHazardRecognizer970 - This class defines a finite state automata that
51/// models the dispatch logic on the PowerPC 970 (aka G5) processor. This
52/// promotes good dispatch group formation and implements noop insertion to
53/// avoid structural hazards that cause significant performance penalties (e.g.
54/// setting the CTR register then branching through it within a dispatch group),
55/// or storing then loading from the same address within a dispatch group.
Dan Gohman7e105f02009-01-15 22:18:12 +000056class PPCHazardRecognizer970 : public ScheduleHazardRecognizer {
Eric Christopher1dcea732014-06-12 21:48:52 +000057 const ScheduleDAG &DAG;
Andrew Trickc416ba62010-12-24 04:28:06 +000058
Chris Lattner51348c52006-03-12 09:13:49 +000059 unsigned NumIssued; // Number of insts issued, including advanced cycles.
Andrew Trickc416ba62010-12-24 04:28:06 +000060
Chris Lattner2cab1352006-03-07 06:32:48 +000061 // Various things that can cause a structural hazard.
Andrew Trickc416ba62010-12-24 04:28:06 +000062
Chris Lattner2cab1352006-03-07 06:32:48 +000063 // HasCTRSet - If the CTR register is set in this group, disallow BCTRL.
64 bool HasCTRSet;
Andrew Trickc416ba62010-12-24 04:28:06 +000065
Chris Lattner2cab1352006-03-07 06:32:48 +000066 // StoredPtr - Keep track of the address of any store. If we see a load from
Chris Lattner51348c52006-03-12 09:13:49 +000067 // the same address (or one that aliases it), disallow the store. We can have
68 // up to four stores in one dispatch group, hence we track up to 4.
Chris Lattner2cab1352006-03-07 06:32:48 +000069 //
70 // This is null if we haven't seen a store yet. We keep track of both
71 // operands of the store here, since we support [r+r] and [r+i] addressing.
Hal Finkel58ca3602011-12-02 04:58:02 +000072 const Value *StoreValue[4];
73 int64_t StoreOffset[4];
74 uint64_t StoreSize[4];
Chris Lattner51348c52006-03-12 09:13:49 +000075 unsigned NumStores;
Andrew Trickc416ba62010-12-24 04:28:06 +000076
Chris Lattner2cab1352006-03-07 06:32:48 +000077public:
Eric Christopher1dcea732014-06-12 21:48:52 +000078 PPCHazardRecognizer970(const ScheduleDAG &DAG);
Craig Topperfd38cbe2014-08-30 16:48:34 +000079 HazardType getHazardType(SUnit *SU, int Stalls) override;
80 void EmitInstruction(SUnit *SU) override;
81 void AdvanceCycle() override;
82 void Reset() override;
Andrew Trickc416ba62010-12-24 04:28:06 +000083
Chris Lattner2cab1352006-03-07 06:32:48 +000084private:
85 /// EndDispatchGroup - Called when we are finishing a new dispatch group.
86 ///
87 void EndDispatchGroup();
Andrew Trickc416ba62010-12-24 04:28:06 +000088
Chris Lattner2cab1352006-03-07 06:32:48 +000089 /// GetInstrType - Classify the specified powerpc opcode according to its
90 /// pipeline.
Chris Lattner51348c52006-03-12 09:13:49 +000091 PPCII::PPC970_Unit GetInstrType(unsigned Opcode,
Chris Lattner4fbb6122006-03-13 05:20:04 +000092 bool &isFirst, bool &isSingle,bool &isCracked,
Chris Lattner51348c52006-03-12 09:13:49 +000093 bool &isLoad, bool &isStore);
Andrew Trickc416ba62010-12-24 04:28:06 +000094
Hal Finkel58ca3602011-12-02 04:58:02 +000095 bool isLoadOfStoredAddress(uint64_t LoadSize, int64_t LoadOffset,
96 const Value *LoadValue) const;
Chris Lattner2cab1352006-03-07 06:32:48 +000097};
98
99} // end namespace llvm
100
Chris Lattner8c73d802006-03-07 16:19:46 +0000101#endif
102