PPCHazardRecognizers.h 3.8 KB

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