xref: /llvm-project/llvm/lib/Target/RISCV/MCA/RISCVCustomBehaviour.h (revision 3d7d463f73bac66663070f7371a1da33714b923b)
198e342dcSMichael Maitland //===-------------------- RISCVCustomBehaviour.h -----------------*-C++ -*-===//
298e342dcSMichael Maitland //
398e342dcSMichael Maitland // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
498e342dcSMichael Maitland // See https://llvm.org/LICENSE.txt for license information.
598e342dcSMichael Maitland // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
698e342dcSMichael Maitland //
798e342dcSMichael Maitland //===----------------------------------------------------------------------===//
898e342dcSMichael Maitland /// \file
998e342dcSMichael Maitland ///
1098e342dcSMichael Maitland /// This file defines the RISCVCustomBehaviour class which inherits from
1198e342dcSMichael Maitland /// CustomBehaviour. This class is used by the tool llvm-mca to enforce
1298e342dcSMichael Maitland /// target specific behaviour that is not expressed well enough in the
1398e342dcSMichael Maitland /// scheduling model for mca to enforce it automatically.
1498e342dcSMichael Maitland ///
1598e342dcSMichael Maitland //===----------------------------------------------------------------------===//
1698e342dcSMichael Maitland 
1798e342dcSMichael Maitland #ifndef LLVM_LIB_TARGET_RISCV_MCA_RISCVCUSTOMBEHAVIOUR_H
1898e342dcSMichael Maitland #define LLVM_LIB_TARGET_RISCV_MCA_RISCVCUSTOMBEHAVIOUR_H
1998e342dcSMichael Maitland 
2098e342dcSMichael Maitland #include "llvm/ADT/SmallVector.h"
2198e342dcSMichael Maitland #include "llvm/MC/MCInst.h"
2298e342dcSMichael Maitland #include "llvm/MC/MCInstrDesc.h"
2398e342dcSMichael Maitland #include "llvm/MC/MCInstrInfo.h"
2498e342dcSMichael Maitland #include "llvm/MCA/CustomBehaviour.h"
2598e342dcSMichael Maitland 
2698e342dcSMichael Maitland namespace llvm {
2798e342dcSMichael Maitland namespace mca {
2898e342dcSMichael Maitland 
2998e342dcSMichael Maitland class RISCVLMULInstrument : public Instrument {
3098e342dcSMichael Maitland public:
3198e342dcSMichael Maitland   static const StringRef DESC_NAME;
3298e342dcSMichael Maitland   static bool isDataValid(StringRef Data);
3398e342dcSMichael Maitland 
RISCVLMULInstrument(StringRef Data)34*3d7d463fSMichael Maitland   explicit RISCVLMULInstrument(StringRef Data) : Instrument(DESC_NAME, Data) {}
3598e342dcSMichael Maitland 
3698e342dcSMichael Maitland   ~RISCVLMULInstrument() = default;
3798e342dcSMichael Maitland 
3898e342dcSMichael Maitland   uint8_t getLMUL() const;
3998e342dcSMichael Maitland };
4098e342dcSMichael Maitland 
41*3d7d463fSMichael Maitland class RISCVSEWInstrument : public Instrument {
42*3d7d463fSMichael Maitland public:
43*3d7d463fSMichael Maitland   static const StringRef DESC_NAME;
44*3d7d463fSMichael Maitland   static bool isDataValid(StringRef Data);
45*3d7d463fSMichael Maitland 
RISCVSEWInstrument(StringRef Data)46*3d7d463fSMichael Maitland   explicit RISCVSEWInstrument(StringRef Data) : Instrument(DESC_NAME, Data) {}
47*3d7d463fSMichael Maitland 
48*3d7d463fSMichael Maitland   ~RISCVSEWInstrument() = default;
49*3d7d463fSMichael Maitland 
50*3d7d463fSMichael Maitland   uint8_t getSEW() const;
51*3d7d463fSMichael Maitland };
52*3d7d463fSMichael Maitland 
5398e342dcSMichael Maitland class RISCVInstrumentManager : public InstrumentManager {
5498e342dcSMichael Maitland public:
RISCVInstrumentManager(const MCSubtargetInfo & STI,const MCInstrInfo & MCII)5598e342dcSMichael Maitland   RISCVInstrumentManager(const MCSubtargetInfo &STI, const MCInstrInfo &MCII)
5698e342dcSMichael Maitland       : InstrumentManager(STI, MCII) {}
5798e342dcSMichael Maitland 
shouldIgnoreInstruments()5898e342dcSMichael Maitland   bool shouldIgnoreInstruments() const override { return false; }
5998e342dcSMichael Maitland   bool supportsInstrumentType(StringRef Type) const override;
6098e342dcSMichael Maitland 
6129463612SCraig Topper   /// Create a Instrument for RISC-V target
6256674e8eSMichael Maitland   UniqueInstrument createInstrument(StringRef Desc, StringRef Data) override;
6398e342dcSMichael Maitland 
64ecf372f9SMichael Maitland   SmallVector<UniqueInstrument> createInstruments(const MCInst &Inst) override;
65ecf372f9SMichael Maitland 
6698e342dcSMichael Maitland   /// Using the Instrument, returns a SchedClassID to use instead of
6798e342dcSMichael Maitland   /// the SchedClassID that belongs to the MCI or the original SchedClassID.
6898e342dcSMichael Maitland   unsigned
6998e342dcSMichael Maitland   getSchedClassID(const MCInstrInfo &MCII, const MCInst &MCI,
7056674e8eSMichael Maitland                   const SmallVector<Instrument *> &IVec) const override;
7198e342dcSMichael Maitland };
7298e342dcSMichael Maitland 
7398e342dcSMichael Maitland } // namespace mca
7498e342dcSMichael Maitland } // namespace llvm
7598e342dcSMichael Maitland 
7698e342dcSMichael Maitland #endif
77