Chris Lattner | c664418 | 2006-03-07 06:32:48 +0000 | [diff] [blame] | 1 | //===-- PPCHazardRecognizers.h - PowerPC Hazard Recognizers -----*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 4ee451d | 2007-12-29 20:36:04 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Chris Lattner | c664418 | 2006-03-07 06:32:48 +0000 | [diff] [blame] | 7 | // |
| 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 | |
Craig Topper | 79aa341 | 2012-03-17 18:46:09 +0000 | [diff] [blame] | 17 | #include "PPCInstrInfo.h" |
Dan Gohman | fc54c55 | 2009-01-15 22:18:12 +0000 | [diff] [blame] | 18 | #include "llvm/CodeGen/ScheduleHazardRecognizer.h" |
Hal Finkel | c6d08f1 | 2011-10-17 04:03:49 +0000 | [diff] [blame] | 19 | #include "llvm/CodeGen/ScoreboardHazardRecognizer.h" |
Dan Gohman | fc54c55 | 2009-01-15 22:18:12 +0000 | [diff] [blame] | 20 | #include "llvm/CodeGen/SelectionDAGNodes.h" |
Chris Lattner | c664418 | 2006-03-07 06:32:48 +0000 | [diff] [blame] | 21 | |
| 22 | namespace llvm { |
Andrew Trick | 6e8f4c4 | 2010-12-24 04:28:06 +0000 | [diff] [blame] | 23 | |
Hal Finkel | 5b00cea | 2012-03-31 14:45:15 +0000 | [diff] [blame] | 24 | /// PPCScoreboardHazardRecognizer - This class implements a scoreboard-based |
| 25 | /// hazard recognizer for generic PPC processors. |
| 26 | class PPCScoreboardHazardRecognizer : public ScoreboardHazardRecognizer { |
Hal Finkel | c6d08f1 | 2011-10-17 04:03:49 +0000 | [diff] [blame] | 27 | const ScheduleDAG *DAG; |
| 28 | public: |
Hal Finkel | 5b00cea | 2012-03-31 14:45:15 +0000 | [diff] [blame] | 29 | PPCScoreboardHazardRecognizer(const InstrItineraryData *ItinData, |
Hal Finkel | c6d08f1 | 2011-10-17 04:03:49 +0000 | [diff] [blame] | 30 | const ScheduleDAG *DAG_) : |
| 31 | ScoreboardHazardRecognizer(ItinData, DAG_), DAG(DAG_) {} |
| 32 | |
Hal Finkel | 5b00cea | 2012-03-31 14:45:15 +0000 | [diff] [blame] | 33 | virtual HazardType getHazardType(SUnit *SU, int Stalls); |
Hal Finkel | c6d08f1 | 2011-10-17 04:03:49 +0000 | [diff] [blame] | 34 | virtual void EmitInstruction(SUnit *SU); |
Hal Finkel | 5b00cea | 2012-03-31 14:45:15 +0000 | [diff] [blame] | 35 | virtual void AdvanceCycle(); |
| 36 | virtual void Reset(); |
Hal Finkel | c6d08f1 | 2011-10-17 04:03:49 +0000 | [diff] [blame] | 37 | }; |
| 38 | |
Chris Lattner | c664418 | 2006-03-07 06:32:48 +0000 | [diff] [blame] | 39 | /// PPCHazardRecognizer970 - This class defines a finite state automata that |
| 40 | /// models the dispatch logic on the PowerPC 970 (aka G5) processor. This |
| 41 | /// promotes good dispatch group formation and implements noop insertion to |
| 42 | /// avoid structural hazards that cause significant performance penalties (e.g. |
| 43 | /// setting the CTR register then branching through it within a dispatch group), |
| 44 | /// or storing then loading from the same address within a dispatch group. |
Dan Gohman | fc54c55 | 2009-01-15 22:18:12 +0000 | [diff] [blame] | 45 | class PPCHazardRecognizer970 : public ScheduleHazardRecognizer { |
Chris Lattner | 88d211f | 2006-03-12 09:13:49 +0000 | [diff] [blame] | 46 | const TargetInstrInfo &TII; |
Andrew Trick | 6e8f4c4 | 2010-12-24 04:28:06 +0000 | [diff] [blame] | 47 | |
Chris Lattner | 88d211f | 2006-03-12 09:13:49 +0000 | [diff] [blame] | 48 | unsigned NumIssued; // Number of insts issued, including advanced cycles. |
Andrew Trick | 6e8f4c4 | 2010-12-24 04:28:06 +0000 | [diff] [blame] | 49 | |
Chris Lattner | c664418 | 2006-03-07 06:32:48 +0000 | [diff] [blame] | 50 | // Various things that can cause a structural hazard. |
Andrew Trick | 6e8f4c4 | 2010-12-24 04:28:06 +0000 | [diff] [blame] | 51 | |
Chris Lattner | c664418 | 2006-03-07 06:32:48 +0000 | [diff] [blame] | 52 | // HasCTRSet - If the CTR register is set in this group, disallow BCTRL. |
| 53 | bool HasCTRSet; |
Andrew Trick | 6e8f4c4 | 2010-12-24 04:28:06 +0000 | [diff] [blame] | 54 | |
Chris Lattner | c664418 | 2006-03-07 06:32:48 +0000 | [diff] [blame] | 55 | // StoredPtr - Keep track of the address of any store. If we see a load from |
Chris Lattner | 88d211f | 2006-03-12 09:13:49 +0000 | [diff] [blame] | 56 | // the same address (or one that aliases it), disallow the store. We can have |
| 57 | // up to four stores in one dispatch group, hence we track up to 4. |
Chris Lattner | c664418 | 2006-03-07 06:32:48 +0000 | [diff] [blame] | 58 | // |
| 59 | // This is null if we haven't seen a store yet. We keep track of both |
| 60 | // operands of the store here, since we support [r+r] and [r+i] addressing. |
Hal Finkel | 64c34e2 | 2011-12-02 04:58:02 +0000 | [diff] [blame] | 61 | const Value *StoreValue[4]; |
| 62 | int64_t StoreOffset[4]; |
| 63 | uint64_t StoreSize[4]; |
Chris Lattner | 88d211f | 2006-03-12 09:13:49 +0000 | [diff] [blame] | 64 | unsigned NumStores; |
Andrew Trick | 6e8f4c4 | 2010-12-24 04:28:06 +0000 | [diff] [blame] | 65 | |
Chris Lattner | c664418 | 2006-03-07 06:32:48 +0000 | [diff] [blame] | 66 | public: |
Chris Lattner | 88d211f | 2006-03-12 09:13:49 +0000 | [diff] [blame] | 67 | PPCHazardRecognizer970(const TargetInstrInfo &TII); |
Andrew Trick | 2da8bc8 | 2010-12-24 05:03:26 +0000 | [diff] [blame] | 68 | virtual HazardType getHazardType(SUnit *SU, int Stalls); |
Dan Gohman | fc54c55 | 2009-01-15 22:18:12 +0000 | [diff] [blame] | 69 | virtual void EmitInstruction(SUnit *SU); |
Chris Lattner | c664418 | 2006-03-07 06:32:48 +0000 | [diff] [blame] | 70 | virtual void AdvanceCycle(); |
Hal Finkel | 64c34e2 | 2011-12-02 04:58:02 +0000 | [diff] [blame] | 71 | virtual void Reset(); |
Andrew Trick | 6e8f4c4 | 2010-12-24 04:28:06 +0000 | [diff] [blame] | 72 | |
Chris Lattner | c664418 | 2006-03-07 06:32:48 +0000 | [diff] [blame] | 73 | private: |
| 74 | /// EndDispatchGroup - Called when we are finishing a new dispatch group. |
| 75 | /// |
| 76 | void EndDispatchGroup(); |
Andrew Trick | 6e8f4c4 | 2010-12-24 04:28:06 +0000 | [diff] [blame] | 77 | |
Chris Lattner | c664418 | 2006-03-07 06:32:48 +0000 | [diff] [blame] | 78 | /// GetInstrType - Classify the specified powerpc opcode according to its |
| 79 | /// pipeline. |
Chris Lattner | 88d211f | 2006-03-12 09:13:49 +0000 | [diff] [blame] | 80 | PPCII::PPC970_Unit GetInstrType(unsigned Opcode, |
Chris Lattner | 3faad49 | 2006-03-13 05:20:04 +0000 | [diff] [blame] | 81 | bool &isFirst, bool &isSingle,bool &isCracked, |
Chris Lattner | 88d211f | 2006-03-12 09:13:49 +0000 | [diff] [blame] | 82 | bool &isLoad, bool &isStore); |
Andrew Trick | 6e8f4c4 | 2010-12-24 04:28:06 +0000 | [diff] [blame] | 83 | |
Hal Finkel | 64c34e2 | 2011-12-02 04:58:02 +0000 | [diff] [blame] | 84 | bool isLoadOfStoredAddress(uint64_t LoadSize, int64_t LoadOffset, |
| 85 | const Value *LoadValue) const; |
Chris Lattner | c664418 | 2006-03-07 06:32:48 +0000 | [diff] [blame] | 86 | }; |
| 87 | |
| 88 | } // end namespace llvm |
| 89 | |
Chris Lattner | ab5801c | 2006-03-07 16:19:46 +0000 | [diff] [blame] | 90 | #endif |
| 91 | |