| 1 | //===--------------------- CustomBehaviour.cpp ------------------*- 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 | /// \file |
| 9 | /// |
| 10 | /// This file implements methods from the CustomBehaviour interface. |
| 11 | /// |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "llvm/MCA/CustomBehaviour.h" |
| 15 | #include "llvm/MCA/Instruction.h" |
| 16 | |
| 17 | namespace llvm { |
| 18 | namespace mca { |
| 19 | |
| 20 | CustomBehaviour::~CustomBehaviour() = default; |
| 21 | |
| 22 | unsigned CustomBehaviour::checkCustomHazard(ArrayRef<InstRef> IssuedInst, |
| 23 | const InstRef &IR) { |
| 24 | // 0 signifies that there are no hazards that need to be waited on |
| 25 | return 0; |
| 26 | } |
| 27 | |
| 28 | std::vector<std::unique_ptr<View>> |
| 29 | CustomBehaviour::getStartViews(llvm::MCInstPrinter &IP, |
| 30 | llvm::ArrayRef<llvm::MCInst> Insts) { |
| 31 | return std::vector<std::unique_ptr<View>>(); |
| 32 | } |
| 33 | |
| 34 | std::vector<std::unique_ptr<View>> |
| 35 | CustomBehaviour::getPostInstrInfoViews(llvm::MCInstPrinter &IP, |
| 36 | llvm::ArrayRef<llvm::MCInst> Insts) { |
| 37 | return std::vector<std::unique_ptr<View>>(); |
| 38 | } |
| 39 | |
| 40 | std::vector<std::unique_ptr<View>> |
| 41 | CustomBehaviour::getEndViews(llvm::MCInstPrinter &IP, |
| 42 | llvm::ArrayRef<llvm::MCInst> Insts) { |
| 43 | return std::vector<std::unique_ptr<View>>(); |
| 44 | } |
| 45 | |
| 46 | const llvm::StringRef LatencyInstrument::DESC_NAME = "LATENCY" ; |
| 47 | |
| 48 | bool InstrumentManager::supportsInstrumentType(StringRef Type) const { |
| 49 | return EnableInstruments && Type == LatencyInstrument::DESC_NAME; |
| 50 | } |
| 51 | |
| 52 | bool InstrumentManager::canCustomize(const ArrayRef<Instrument *> IVec) const { |
| 53 | for (const auto I : IVec) { |
| 54 | if (I->getDesc() == LatencyInstrument::DESC_NAME) { |
| 55 | auto LatInst = static_cast<LatencyInstrument *>(I); |
| 56 | return LatInst->hasValue(); |
| 57 | } |
| 58 | } |
| 59 | return false; |
| 60 | } |
| 61 | |
| 62 | void InstrumentManager::customize(const ArrayRef<Instrument *> IVec, |
| 63 | InstrDesc &ID) const { |
| 64 | for (const auto I : IVec) { |
| 65 | if (I->getDesc() == LatencyInstrument::DESC_NAME) { |
| 66 | auto LatInst = static_cast<LatencyInstrument *>(I); |
| 67 | if (LatInst->hasValue()) { |
| 68 | unsigned Latency = LatInst->getLatency(); |
| 69 | // TODO Allow to customize a subset of ID.Writes |
| 70 | for (auto &W : ID.Writes) |
| 71 | W.Latency = Latency; |
| 72 | ID.MaxLatency = Latency; |
| 73 | } |
| 74 | } |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | UniqueInstrument InstrumentManager::createInstrument(StringRef Desc, |
| 79 | StringRef Data) { |
| 80 | if (EnableInstruments) { |
| 81 | if (Desc == LatencyInstrument::DESC_NAME) |
| 82 | return std::make_unique<LatencyInstrument>(args&: Data); |
| 83 | } |
| 84 | return std::make_unique<Instrument>(args&: Desc, args&: Data); |
| 85 | } |
| 86 | |
| 87 | SmallVector<UniqueInstrument> |
| 88 | InstrumentManager::createInstruments(const MCInst &Inst) { |
| 89 | return SmallVector<UniqueInstrument>(); |
| 90 | } |
| 91 | |
| 92 | unsigned InstrumentManager::getSchedClassID( |
| 93 | const MCInstrInfo &MCII, const MCInst &MCI, |
| 94 | const llvm::SmallVector<Instrument *> &IVec) const { |
| 95 | return MCII.get(Opcode: MCI.getOpcode()).getSchedClass(); |
| 96 | } |
| 97 | |
| 98 | } // namespace mca |
| 99 | } // namespace llvm |
| 100 | |