LLVM  14.0.0git
CustomBehaviour.h
Go to the documentation of this file.
1 //===---------------------- CustomBehaviour.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 base class CustomBehaviour which can be inherited from
11 /// by specific targets (ex. llvm/tools/llvm-mca/lib/X86CustomBehaviour.h).
12 /// CustomBehaviour is designed to enforce custom behaviour and dependencies
13 /// within the llvm-mca pipeline simulation that llvm-mca isn't already capable
14 /// of extracting from the Scheduling Models.
15 ///
16 //===----------------------------------------------------------------------===//
17 
18 #ifndef LLVM_MCA_CUSTOMBEHAVIOUR_H
19 #define LLVM_MCA_CUSTOMBEHAVIOUR_H
20 
21 #include "llvm/MC/MCInst.h"
22 #include "llvm/MC/MCInstrInfo.h"
24 #include "llvm/MCA/SourceMgr.h"
25 #include "llvm/MCA/View.h"
26 
27 namespace llvm {
28 namespace mca {
29 
30 /// Class which can be overriden by targets to modify the
31 /// mca::Instruction objects before the pipeline starts.
32 /// A common usage of this class is to add immediate operands to certain
33 /// instructions or to remove Defs/Uses from an instruction where the
34 /// schedulinng model is incorrect.
36 protected:
38  const MCInstrInfo &MCII;
39 
40 public:
42  : STI(STI), MCII(MCII) {}
43 
44  virtual ~InstrPostProcess() {}
45 
46  virtual void postProcessInstruction(std::unique_ptr<Instruction> &Inst,
47  const MCInst &MCI) {}
48 };
49 
50 /// Class which can be overriden by targets to enforce instruction
51 /// dependencies and behaviours that aren't expressed well enough
52 /// within the scheduling model for mca to automatically simulate
53 /// them properly.
54 /// If you implement this class for your target, make sure to also implement
55 /// a target specific InstrPostProcess class as well.
57 protected:
60  const MCInstrInfo &MCII;
61 
62 public:
64  const MCInstrInfo &MCII)
65  : STI(STI), SrcMgr(SrcMgr), MCII(MCII) {}
66 
67  virtual ~CustomBehaviour();
68 
69  /// Before the llvm-mca pipeline dispatches an instruction, it first checks
70  /// for any register or resource dependencies / hazards. If it doesn't find
71  /// any, this method will be invoked to determine if there are any custom
72  /// hazards that the instruction needs to wait for.
73  /// The return value of this method is the number of cycles that the
74  /// instruction needs to wait for.
75  /// It's safe to underestimate the number of cycles to wait for since these
76  /// checks will be invoked again before the intruction gets dispatched.
77  /// However, it's not safe (accurate) to overestimate the number of cycles
78  /// to wait for since the instruction will wait for AT LEAST that number of
79  /// cycles before attempting to be dispatched again.
80  virtual unsigned checkCustomHazard(ArrayRef<InstRef> IssuedInst,
81  const InstRef &IR);
82 
83  // Functions that target CBs can override to return a list of
84  // target specific Views that need to live within /lib/Target/ so that
85  // they can benefit from the target CB or from backend functionality that is
86  // not already exposed through MC-layer classes. Keep in mind that how this
87  // function is used is that the function is called within llvm-mca.cpp and
88  // then each unique_ptr<View> is passed into the PipelinePrinter::addView()
89  // function. This function will then std::move the View into its own vector of
90  // Views. So any CB that overrides this function needs to make sure that they
91  // are not relying on the current address or reference of the View
92  // unique_ptrs. If you do need the CB and View to be able to communicate with
93  // each other, consider giving the View a reference or pointer to the CB when
94  // the View is constructed. Then the View can query the CB for information
95  // when it needs it.
96  /// Return a vector of Views that will be added before all other Views.
97  virtual std::vector<std::unique_ptr<View>>
99  /// Return a vector of Views that will be added after the InstructionInfoView.
100  virtual std::vector<std::unique_ptr<View>>
103  /// Return a vector of Views that will be added after all other Views.
104  virtual std::vector<std::unique_ptr<View>>
106 };
107 
108 } // namespace mca
109 } // namespace llvm
110 
111 #endif /* LLVM_MCA_CUSTOMBEHAVIOUR_H */
llvm
This file implements support for optimizing divisions by a constant.
Definition: AllocatorList.h:23
llvm::mca::InstrPostProcess::~InstrPostProcess
virtual ~InstrPostProcess()
Definition: CustomBehaviour.h:44
llvm::MCInst
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:184
llvm::mca::CustomBehaviour::~CustomBehaviour
virtual ~CustomBehaviour()
Definition: CustomBehaviour.cpp:19
SourceMgr.h
MCInstrInfo.h
IP
Definition: NVPTXLowerArgs.cpp:166
llvm::mca::CustomBehaviour::SrcMgr
const mca::SourceMgr & SrcMgr
Definition: CustomBehaviour.h:59
MCInst.h
llvm::mca::CustomBehaviour::MCII
const MCInstrInfo & MCII
Definition: CustomBehaviour.h:60
MCSubtargetInfo.h
llvm::mca::InstrPostProcess::STI
const MCSubtargetInfo & STI
Definition: CustomBehaviour.h:37
IR
Statically lint checks LLVM IR
Definition: Lint.cpp:744
llvm::mca::CustomBehaviour::STI
const MCSubtargetInfo & STI
Definition: CustomBehaviour.h:58
llvm::mca::InstrPostProcess::postProcessInstruction
virtual void postProcessInstruction(std::unique_ptr< Instruction > &Inst, const MCInst &MCI)
Definition: CustomBehaviour.h:46
llvm::MCInstPrinter
This is an instance of a target assembly language printer that converts an MCInst to valid target ass...
Definition: MCInstPrinter.h:43
llvm::mca::CustomBehaviour
Class which can be overriden by targets to enforce instruction dependencies and behaviours that aren'...
Definition: CustomBehaviour.h:56
llvm::mca::InstRef
An InstRef contains both a SourceMgr index and Instruction pair.
Definition: Instruction.h:686
llvm::mca::InstrPostProcess::MCII
const MCInstrInfo & MCII
Definition: CustomBehaviour.h:38
llvm::mca::CustomBehaviour::getStartViews
virtual std::vector< std::unique_ptr< View > > getStartViews(llvm::MCInstPrinter &IP, llvm::ArrayRef< llvm::MCInst > Insts)
Return a vector of Views that will be added before all other Views.
Definition: CustomBehaviour.cpp:28
llvm::ArrayRef
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: APInt.h:32
llvm::mca::CustomBehaviour::checkCustomHazard
virtual unsigned checkCustomHazard(ArrayRef< InstRef > IssuedInst, const InstRef &IR)
Before the llvm-mca pipeline dispatches an instruction, it first checks for any register or resource ...
Definition: CustomBehaviour.cpp:21
llvm::mca::InstrPostProcess
Class which can be overriden by targets to modify the mca::Instruction objects before the pipeline st...
Definition: CustomBehaviour.h:35
llvm::mca::CustomBehaviour::CustomBehaviour
CustomBehaviour(const MCSubtargetInfo &STI, const mca::SourceMgr &SrcMgr, const MCInstrInfo &MCII)
Definition: CustomBehaviour.h:63
llvm::mca::SourceMgr
Definition: SourceMgr.h:28
llvm::MCInstrInfo
Interface to description of machine instruction set.
Definition: MCInstrInfo.h:25
llvm::mca::InstrPostProcess::InstrPostProcess
InstrPostProcess(const MCSubtargetInfo &STI, const MCInstrInfo &MCII)
Definition: CustomBehaviour.h:41
llvm::mca::CustomBehaviour::getEndViews
virtual std::vector< std::unique_ptr< View > > getEndViews(llvm::MCInstPrinter &IP, llvm::ArrayRef< llvm::MCInst > Insts)
Return a vector of Views that will be added after all other Views.
Definition: CustomBehaviour.cpp:40
View.h
llvm::MCSubtargetInfo
Generic base class for all target subtargets.
Definition: MCSubtargetInfo.h:75
llvm::mca::CustomBehaviour::getPostInstrInfoViews
virtual std::vector< std::unique_ptr< View > > getPostInstrInfoViews(llvm::MCInstPrinter &IP, llvm::ArrayRef< llvm::MCInst > Insts)
Return a vector of Views that will be added after the InstructionInfoView.
Definition: CustomBehaviour.cpp:34