xref: /freebsd/contrib/llvm-project/llvm/lib/Target/RISCV/MCA/RISCVCustomBehaviour.h (revision 8c2f6c3be0125142d3c1782e4b0ee0634c584b9e)
1 //===-------------------- RISCVCustomBehaviour.h -----------------*-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 defines the RISCVCustomBehaviour class which inherits from
11 /// CustomBehaviour. This class is used by the tool llvm-mca to enforce
12 /// target specific behaviour that is not expressed well enough in the
13 /// scheduling model for mca to enforce it automatically.
14 ///
15 //===----------------------------------------------------------------------===//
16 
17 #ifndef LLVM_LIB_TARGET_RISCV_MCA_RISCVCUSTOMBEHAVIOUR_H
18 #define LLVM_LIB_TARGET_RISCV_MCA_RISCVCUSTOMBEHAVIOUR_H
19 
20 #include "llvm/ADT/SmallVector.h"
21 #include "llvm/MC/MCInst.h"
22 #include "llvm/MC/MCInstrDesc.h"
23 #include "llvm/MC/MCInstrInfo.h"
24 #include "llvm/MCA/CustomBehaviour.h"
25 
26 namespace llvm {
27 namespace mca {
28 
29 class RISCVLMULInstrument : public Instrument {
30 public:
31   static const StringRef DESC_NAME;
32   static bool isDataValid(StringRef Data);
33 
34   explicit RISCVLMULInstrument(StringRef Data) : Instrument(DESC_NAME, Data) {}
35 
36   ~RISCVLMULInstrument() = default;
37 
38   uint8_t getLMUL() const;
39 };
40 
41 class RISCVSEWInstrument : public Instrument {
42 public:
43   static const StringRef DESC_NAME;
44   static bool isDataValid(StringRef Data);
45 
46   explicit RISCVSEWInstrument(StringRef Data) : Instrument(DESC_NAME, Data) {}
47 
48   ~RISCVSEWInstrument() = default;
49 
50   uint8_t getSEW() const;
51 };
52 
53 class RISCVInstrumentManager : public InstrumentManager {
54 public:
55   RISCVInstrumentManager(const MCSubtargetInfo &STI, const MCInstrInfo &MCII)
56       : InstrumentManager(STI, MCII) {}
57 
58   bool shouldIgnoreInstruments() const override { return false; }
59   bool supportsInstrumentType(StringRef Type) const override;
60 
61   /// Create a Instrument for RISC-V target
62   UniqueInstrument createInstrument(StringRef Desc, StringRef Data) override;
63 
64   SmallVector<UniqueInstrument> createInstruments(const MCInst &Inst) override;
65 
66   /// Using the Instrument, returns a SchedClassID to use instead of
67   /// the SchedClassID that belongs to the MCI or the original SchedClassID.
68   unsigned
69   getSchedClassID(const MCInstrInfo &MCII, const MCInst &MCI,
70                   const SmallVector<Instrument *> &IVec) const override;
71 };
72 
73 } // namespace mca
74 } // namespace llvm
75 
76 #endif
77