1f4a2713aSLionel Sambuc //===-- PPCHazardRecognizers.h - PowerPC Hazard Recognizers -----*- C++ -*-===// 2f4a2713aSLionel Sambuc // 3f4a2713aSLionel Sambuc // The LLVM Compiler Infrastructure 4f4a2713aSLionel Sambuc // 5f4a2713aSLionel Sambuc // This file is distributed under the University of Illinois Open Source 6f4a2713aSLionel Sambuc // License. See LICENSE.TXT for details. 7f4a2713aSLionel Sambuc // 8f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===// 9f4a2713aSLionel Sambuc // 10f4a2713aSLionel Sambuc // This file defines hazard recognizers for scheduling on PowerPC processors. 11f4a2713aSLionel Sambuc // 12f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===// 13f4a2713aSLionel Sambuc 14*0a6a1f1dSLionel Sambuc #ifndef LLVM_LIB_TARGET_POWERPC_PPCHAZARDRECOGNIZERS_H 15*0a6a1f1dSLionel Sambuc #define LLVM_LIB_TARGET_POWERPC_PPCHAZARDRECOGNIZERS_H 16f4a2713aSLionel Sambuc 17f4a2713aSLionel Sambuc #include "PPCInstrInfo.h" 18f4a2713aSLionel Sambuc #include "llvm/CodeGen/ScheduleHazardRecognizer.h" 19f4a2713aSLionel Sambuc #include "llvm/CodeGen/ScoreboardHazardRecognizer.h" 20f4a2713aSLionel Sambuc #include "llvm/CodeGen/SelectionDAGNodes.h" 21f4a2713aSLionel Sambuc 22f4a2713aSLionel Sambuc namespace llvm { 23f4a2713aSLionel Sambuc 24*0a6a1f1dSLionel Sambuc /// PPCDispatchGroupSBHazardRecognizer - This class implements a scoreboard-based 25*0a6a1f1dSLionel Sambuc /// hazard recognizer for PPC ooo processors with dispatch-group hazards. 26*0a6a1f1dSLionel Sambuc class PPCDispatchGroupSBHazardRecognizer : public ScoreboardHazardRecognizer { 27f4a2713aSLionel Sambuc const ScheduleDAG *DAG; 28*0a6a1f1dSLionel Sambuc SmallVector<SUnit *, 7> CurGroup; 29*0a6a1f1dSLionel Sambuc unsigned CurSlots, CurBranches; 30f4a2713aSLionel Sambuc 31*0a6a1f1dSLionel Sambuc bool isLoadAfterStore(SUnit *SU); 32*0a6a1f1dSLionel Sambuc bool isBCTRAfterSet(SUnit *SU); 33*0a6a1f1dSLionel Sambuc bool mustComeFirst(const MCInstrDesc *MCID, unsigned &NSlots); 34*0a6a1f1dSLionel Sambuc public: PPCDispatchGroupSBHazardRecognizer(const InstrItineraryData * ItinData,const ScheduleDAG * DAG_)35*0a6a1f1dSLionel Sambuc PPCDispatchGroupSBHazardRecognizer(const InstrItineraryData *ItinData, 36*0a6a1f1dSLionel Sambuc const ScheduleDAG *DAG_) : 37*0a6a1f1dSLionel Sambuc ScoreboardHazardRecognizer(ItinData, DAG_), DAG(DAG_), 38*0a6a1f1dSLionel Sambuc CurSlots(0), CurBranches(0) {} 39*0a6a1f1dSLionel Sambuc 40*0a6a1f1dSLionel Sambuc HazardType getHazardType(SUnit *SU, int Stalls) override; 41*0a6a1f1dSLionel Sambuc bool ShouldPreferAnother(SUnit* SU) override; 42*0a6a1f1dSLionel Sambuc unsigned PreEmitNoops(SUnit *SU) override; 43*0a6a1f1dSLionel Sambuc void EmitInstruction(SUnit *SU) override; 44*0a6a1f1dSLionel Sambuc void AdvanceCycle() override; 45*0a6a1f1dSLionel Sambuc void RecedeCycle() override; 46*0a6a1f1dSLionel Sambuc void Reset() override; 47*0a6a1f1dSLionel Sambuc void EmitNoop() override; 48f4a2713aSLionel Sambuc }; 49f4a2713aSLionel Sambuc 50f4a2713aSLionel Sambuc /// PPCHazardRecognizer970 - This class defines a finite state automata that 51f4a2713aSLionel Sambuc /// models the dispatch logic on the PowerPC 970 (aka G5) processor. This 52f4a2713aSLionel Sambuc /// promotes good dispatch group formation and implements noop insertion to 53f4a2713aSLionel Sambuc /// avoid structural hazards that cause significant performance penalties (e.g. 54f4a2713aSLionel Sambuc /// setting the CTR register then branching through it within a dispatch group), 55f4a2713aSLionel Sambuc /// or storing then loading from the same address within a dispatch group. 56f4a2713aSLionel Sambuc class PPCHazardRecognizer970 : public ScheduleHazardRecognizer { 57*0a6a1f1dSLionel Sambuc const ScheduleDAG &DAG; 58f4a2713aSLionel Sambuc 59f4a2713aSLionel Sambuc unsigned NumIssued; // Number of insts issued, including advanced cycles. 60f4a2713aSLionel Sambuc 61f4a2713aSLionel Sambuc // Various things that can cause a structural hazard. 62f4a2713aSLionel Sambuc 63f4a2713aSLionel Sambuc // HasCTRSet - If the CTR register is set in this group, disallow BCTRL. 64f4a2713aSLionel Sambuc bool HasCTRSet; 65f4a2713aSLionel Sambuc 66f4a2713aSLionel Sambuc // StoredPtr - Keep track of the address of any store. If we see a load from 67f4a2713aSLionel Sambuc // the same address (or one that aliases it), disallow the store. We can have 68f4a2713aSLionel Sambuc // up to four stores in one dispatch group, hence we track up to 4. 69f4a2713aSLionel Sambuc // 70f4a2713aSLionel Sambuc // This is null if we haven't seen a store yet. We keep track of both 71f4a2713aSLionel Sambuc // operands of the store here, since we support [r+r] and [r+i] addressing. 72f4a2713aSLionel Sambuc const Value *StoreValue[4]; 73f4a2713aSLionel Sambuc int64_t StoreOffset[4]; 74f4a2713aSLionel Sambuc uint64_t StoreSize[4]; 75f4a2713aSLionel Sambuc unsigned NumStores; 76f4a2713aSLionel Sambuc 77f4a2713aSLionel Sambuc public: 78*0a6a1f1dSLionel Sambuc PPCHazardRecognizer970(const ScheduleDAG &DAG); 79*0a6a1f1dSLionel Sambuc HazardType getHazardType(SUnit *SU, int Stalls) override; 80*0a6a1f1dSLionel Sambuc void EmitInstruction(SUnit *SU) override; 81*0a6a1f1dSLionel Sambuc void AdvanceCycle() override; 82*0a6a1f1dSLionel Sambuc void Reset() override; 83f4a2713aSLionel Sambuc 84f4a2713aSLionel Sambuc private: 85f4a2713aSLionel Sambuc /// EndDispatchGroup - Called when we are finishing a new dispatch group. 86f4a2713aSLionel Sambuc /// 87f4a2713aSLionel Sambuc void EndDispatchGroup(); 88f4a2713aSLionel Sambuc 89f4a2713aSLionel Sambuc /// GetInstrType - Classify the specified powerpc opcode according to its 90f4a2713aSLionel Sambuc /// pipeline. 91f4a2713aSLionel Sambuc PPCII::PPC970_Unit GetInstrType(unsigned Opcode, 92f4a2713aSLionel Sambuc bool &isFirst, bool &isSingle,bool &isCracked, 93f4a2713aSLionel Sambuc bool &isLoad, bool &isStore); 94f4a2713aSLionel Sambuc 95f4a2713aSLionel Sambuc bool isLoadOfStoredAddress(uint64_t LoadSize, int64_t LoadOffset, 96f4a2713aSLionel Sambuc const Value *LoadValue) const; 97f4a2713aSLionel Sambuc }; 98f4a2713aSLionel Sambuc 99f4a2713aSLionel Sambuc } // end namespace llvm 100f4a2713aSLionel Sambuc 101f4a2713aSLionel Sambuc #endif 102f4a2713aSLionel Sambuc 103