brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.2 KiB · 51b85bf Raw
100 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8/// \file9///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 17namespace llvm {18namespace mca {19 20CustomBehaviour::~CustomBehaviour() = default;21 22unsigned CustomBehaviour::checkCustomHazard(ArrayRef<InstRef> IssuedInst,23                                            const InstRef &IR) {24  // 0 signifies that there are no hazards that need to be waited on25  return 0;26}27 28std::vector<std::unique_ptr<View>>29CustomBehaviour::getStartViews(llvm::MCInstPrinter &IP,30                               llvm::ArrayRef<llvm::MCInst> Insts) {31  return std::vector<std::unique_ptr<View>>();32}33 34std::vector<std::unique_ptr<View>>35CustomBehaviour::getPostInstrInfoViews(llvm::MCInstPrinter &IP,36                                       llvm::ArrayRef<llvm::MCInst> Insts) {37  return std::vector<std::unique_ptr<View>>();38}39 40std::vector<std::unique_ptr<View>>41CustomBehaviour::getEndViews(llvm::MCInstPrinter &IP,42                             llvm::ArrayRef<llvm::MCInst> Insts) {43  return std::vector<std::unique_ptr<View>>();44}45 46const llvm::StringRef LatencyInstrument::DESC_NAME = "LATENCY";47 48bool InstrumentManager::supportsInstrumentType(StringRef Type) const {49  return EnableInstruments && Type == LatencyInstrument::DESC_NAME;50}51 52bool 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 62void 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.Writes70        for (auto &W : ID.Writes)71          W.Latency = Latency;72        ID.MaxLatency = Latency;73      }74    }75  }76}77 78UniqueInstrument InstrumentManager::createInstrument(StringRef Desc,79                                                     StringRef Data) {80  if (EnableInstruments) {81    if (Desc == LatencyInstrument::DESC_NAME)82      return std::make_unique<LatencyInstrument>(Data);83  }84  return std::make_unique<Instrument>(Desc, Data);85}86 87SmallVector<UniqueInstrument>88InstrumentManager::createInstruments(const MCInst &Inst) {89  return SmallVector<UniqueInstrument>();90}91 92unsigned InstrumentManager::getSchedClassID(93    const MCInstrInfo &MCII, const MCInst &MCI,94    const llvm::SmallVector<Instrument *> &IVec) const {95  return MCII.get(MCI.getOpcode()).getSchedClass();96}97 98} // namespace mca99} // namespace llvm100