Path: blob/main/contrib/llvm-project/llvm/lib/Target/PowerPC/PPCHazardRecognizers.h
35267 views
//===-- PPCHazardRecognizers.h - PowerPC Hazard Recognizers -----*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// This file defines hazard recognizers for scheduling on PowerPC processors.9//10//===----------------------------------------------------------------------===//1112#ifndef LLVM_LIB_TARGET_POWERPC_PPCHAZARDRECOGNIZERS_H13#define LLVM_LIB_TARGET_POWERPC_PPCHAZARDRECOGNIZERS_H1415#include "PPCInstrInfo.h"16#include "llvm/CodeGen/ScheduleHazardRecognizer.h"17#include "llvm/CodeGen/ScoreboardHazardRecognizer.h"18#include "llvm/CodeGen/SelectionDAGNodes.h"1920namespace llvm {2122/// PPCDispatchGroupSBHazardRecognizer - This class implements a scoreboard-based23/// hazard recognizer for PPC ooo processors with dispatch-group hazards.24class PPCDispatchGroupSBHazardRecognizer : public ScoreboardHazardRecognizer {25const ScheduleDAG *DAG;26SmallVector<SUnit *, 7> CurGroup;27unsigned CurSlots, CurBranches;2829bool isLoadAfterStore(SUnit *SU);30bool isBCTRAfterSet(SUnit *SU);31bool mustComeFirst(const MCInstrDesc *MCID, unsigned &NSlots);32public:33PPCDispatchGroupSBHazardRecognizer(const InstrItineraryData *ItinData,34const ScheduleDAG *DAG_) :35ScoreboardHazardRecognizer(ItinData, DAG_), DAG(DAG_),36CurSlots(0), CurBranches(0) {}3738HazardType getHazardType(SUnit *SU, int Stalls) override;39bool ShouldPreferAnother(SUnit* SU) override;40unsigned PreEmitNoops(SUnit *SU) override;41void EmitInstruction(SUnit *SU) override;42void AdvanceCycle() override;43void RecedeCycle() override;44void Reset() override;45void EmitNoop() override;46};4748/// PPCHazardRecognizer970 - This class defines a finite state automata that49/// models the dispatch logic on the PowerPC 970 (aka G5) processor. This50/// promotes good dispatch group formation and implements noop insertion to51/// avoid structural hazards that cause significant performance penalties (e.g.52/// setting the CTR register then branching through it within a dispatch group),53/// or storing then loading from the same address within a dispatch group.54class PPCHazardRecognizer970 : public ScheduleHazardRecognizer {55const ScheduleDAG &DAG;5657unsigned NumIssued; // Number of insts issued, including advanced cycles.5859// Various things that can cause a structural hazard.6061// HasCTRSet - If the CTR register is set in this group, disallow BCTRL.62bool HasCTRSet;6364// StoredPtr - Keep track of the address of any store. If we see a load from65// the same address (or one that aliases it), disallow the store. We can have66// up to four stores in one dispatch group, hence we track up to 4.67//68// This is null if we haven't seen a store yet. We keep track of both69// operands of the store here, since we support [r+r] and [r+i] addressing.70const Value *StoreValue[4];71int64_t StoreOffset[4];72uint64_t StoreSize[4];73unsigned NumStores;7475public:76PPCHazardRecognizer970(const ScheduleDAG &DAG);77HazardType getHazardType(SUnit *SU, int Stalls) override;78void EmitInstruction(SUnit *SU) override;79void AdvanceCycle() override;80void Reset() override;8182private:83/// EndDispatchGroup - Called when we are finishing a new dispatch group.84///85void EndDispatchGroup();8687/// GetInstrType - Classify the specified powerpc opcode according to its88/// pipeline.89PPCII::PPC970_Unit GetInstrType(unsigned Opcode,90bool &isFirst, bool &isSingle,bool &isCracked,91bool &isLoad, bool &isStore);9293bool isLoadOfStoredAddress(uint64_t LoadSize, int64_t LoadOffset,94const Value *LoadValue) const;95};9697} // end namespace llvm9899#endif100101102103