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