LLVM API Documentation

PPCHazardRecognizers.h
Go to the documentation of this file.
00001 //===-- PPCHazardRecognizers.h - PowerPC Hazard Recognizers -----*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file defines hazard recognizers for scheduling on PowerPC processors.
00011 //
00012 //===----------------------------------------------------------------------===//
00013 
00014 #ifndef LLVM_LIB_TARGET_POWERPC_PPCHAZARDRECOGNIZERS_H
00015 #define LLVM_LIB_TARGET_POWERPC_PPCHAZARDRECOGNIZERS_H
00016 
00017 #include "PPCInstrInfo.h"
00018 #include "llvm/CodeGen/ScheduleHazardRecognizer.h"
00019 #include "llvm/CodeGen/ScoreboardHazardRecognizer.h"
00020 #include "llvm/CodeGen/SelectionDAGNodes.h"
00021 
00022 namespace llvm {
00023 
00024 /// PPCDispatchGroupSBHazardRecognizer - This class implements a scoreboard-based
00025 /// hazard recognizer for PPC ooo processors with dispatch-group hazards.
00026 class PPCDispatchGroupSBHazardRecognizer : public ScoreboardHazardRecognizer {
00027   const ScheduleDAG *DAG;
00028   SmallVector<SUnit *, 7> CurGroup;
00029   unsigned CurSlots, CurBranches;
00030 
00031   bool isLoadAfterStore(SUnit *SU);
00032   bool isBCTRAfterSet(SUnit *SU);
00033   bool mustComeFirst(const MCInstrDesc *MCID, unsigned &NSlots);
00034 public:
00035   PPCDispatchGroupSBHazardRecognizer(const InstrItineraryData *ItinData,
00036                          const ScheduleDAG *DAG_) :
00037     ScoreboardHazardRecognizer(ItinData, DAG_), DAG(DAG_),
00038     CurSlots(0), CurBranches(0) {}
00039 
00040   HazardType getHazardType(SUnit *SU, int Stalls) override;
00041   bool ShouldPreferAnother(SUnit* SU) override;
00042   unsigned PreEmitNoops(SUnit *SU) override;
00043   void EmitInstruction(SUnit *SU) override;
00044   void AdvanceCycle() override;
00045   void RecedeCycle() override;
00046   void Reset() override;
00047   void EmitNoop() override;
00048 };
00049 
00050 /// PPCHazardRecognizer970 - This class defines a finite state automata that
00051 /// models the dispatch logic on the PowerPC 970 (aka G5) processor.  This
00052 /// promotes good dispatch group formation and implements noop insertion to
00053 /// avoid structural hazards that cause significant performance penalties (e.g.
00054 /// setting the CTR register then branching through it within a dispatch group),
00055 /// or storing then loading from the same address within a dispatch group.
00056 class PPCHazardRecognizer970 : public ScheduleHazardRecognizer {
00057   const ScheduleDAG &DAG;
00058 
00059   unsigned NumIssued;  // Number of insts issued, including advanced cycles.
00060 
00061   // Various things that can cause a structural hazard.
00062 
00063   // HasCTRSet - If the CTR register is set in this group, disallow BCTRL.
00064   bool HasCTRSet;
00065 
00066   // StoredPtr - Keep track of the address of any store.  If we see a load from
00067   // the same address (or one that aliases it), disallow the store.  We can have
00068   // up to four stores in one dispatch group, hence we track up to 4.
00069   //
00070   // This is null if we haven't seen a store yet.  We keep track of both
00071   // operands of the store here, since we support [r+r] and [r+i] addressing.
00072   const Value *StoreValue[4];
00073   int64_t StoreOffset[4];
00074   uint64_t StoreSize[4];
00075   unsigned NumStores;
00076 
00077 public:
00078   PPCHazardRecognizer970(const ScheduleDAG &DAG);
00079   HazardType getHazardType(SUnit *SU, int Stalls) override;
00080   void EmitInstruction(SUnit *SU) override;
00081   void AdvanceCycle() override;
00082   void Reset() override;
00083 
00084 private:
00085   /// EndDispatchGroup - Called when we are finishing a new dispatch group.
00086   ///
00087   void EndDispatchGroup();
00088 
00089   /// GetInstrType - Classify the specified powerpc opcode according to its
00090   /// pipeline.
00091   PPCII::PPC970_Unit GetInstrType(unsigned Opcode,
00092                                   bool &isFirst, bool &isSingle,bool &isCracked,
00093                                   bool &isLoad, bool &isStore);
00094 
00095   bool isLoadOfStoredAddress(uint64_t LoadSize, int64_t LoadOffset,
00096                              const Value *LoadValue) const;
00097 };
00098 
00099 } // end namespace llvm
00100 
00101 #endif
00102