|
| 1 | +//===- llvm/CodeGen/GlobalISel/BURSInstructionSelector.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 | +// |
| 9 | +/// \file This file declares the API for the BURS instruction selector. |
| 10 | +// |
| 11 | +//===----------------------------------------------------------------------===// |
| 12 | + |
| 13 | +#ifndef LLVM_CODEGEN_GLOBALISEL_BURSINSTRUCTIONSELECTOR_H |
| 14 | +#define LLVM_CODEGEN_GLOBALISEL_BURSINSTRUCTIONSELECTOR_H |
| 15 | + |
| 16 | +#include <llvm/ADT/DenseMap.h> |
| 17 | +#include <cstdint> |
| 18 | + |
| 19 | +namespace llvm { |
| 20 | +class BlockFrequencyInfo; |
| 21 | +class CodeGenCoverage; |
| 22 | +class GISelKnownBits; |
| 23 | +class MachineBasicBlock; |
| 24 | +class MachineFunction; |
| 25 | +class MachineInstr; |
| 26 | +class MachineOptimizationRemarkEmitter; |
| 27 | +class ProfileSummaryInfo; |
| 28 | +class TargetPassConfig; |
| 29 | + |
| 30 | +class BURSInstructionSelector { |
| 31 | + // The mapping of MIs to a state. |
| 32 | + DenseMap<MachineInstr *, uint32_t> States; |
| 33 | + |
| 34 | +public: |
| 35 | + virtual ~BURSInstructionSelector(); |
| 36 | + |
| 37 | + // The tablegen-erated functions. |
| 38 | + virtual void label(MachineInstr &I) = 0; |
| 39 | + virtual bool reduce(MachineInstr &I) = 0; |
| 40 | + |
| 41 | +protected: |
| 42 | + /// A lowering phase that runs before any selection attempts. |
| 43 | + /// Returns true if the instruction was modified. |
| 44 | + virtual bool preISelLower(MachineInstr &I) { return false; } |
| 45 | + |
| 46 | + /// An early selection function that runs before the reduce() call. |
| 47 | + /// Returns true if the instruction was selected. |
| 48 | + virtual bool earlySelect(MachineInstr &I) { return false; } |
| 49 | + |
| 50 | + /// Select the (possibly generic) instruction \p I to only use target-specific |
| 51 | + /// opcodes. It is OK to insert multiple instructions, but they cannot be |
| 52 | + /// generic pre-isel instructions. |
| 53 | + /// |
| 54 | + /// \returns whether selection succeeded. |
| 55 | + /// \pre I.getParent() && I.getParent()->getParent() |
| 56 | + /// \post |
| 57 | + /// if returns true: |
| 58 | + /// for I in all mutated/inserted instructions: |
| 59 | + /// !isPreISelGenericOpcode(I.getOpcode()) |
| 60 | + virtual bool select(MachineInstr &I) = 0; |
| 61 | + |
| 62 | +public: |
| 63 | + void setTargetPassConfig(const TargetPassConfig *T) { TPC = T; } |
| 64 | + |
| 65 | + void setRemarkEmitter(MachineOptimizationRemarkEmitter *M) { MORE = M; } |
| 66 | + |
| 67 | +protected: |
| 68 | + CodeGenCoverage *CoverageInfo = nullptr; |
| 69 | + GISelKnownBits *KB = nullptr; |
| 70 | + MachineFunction *MF = nullptr; |
| 71 | + ProfileSummaryInfo *PSI = nullptr; |
| 72 | + BlockFrequencyInfo *BFI = nullptr; |
| 73 | + // For some predicates, we need to track the current MBB. |
| 74 | + MachineBasicBlock *CurMBB = nullptr; |
| 75 | + |
| 76 | +public: |
| 77 | + virtual void setupGeneratedPerFunctionState(MachineFunction &MF) = 0; |
| 78 | + |
| 79 | + /// Setup per-MF executor state. |
| 80 | + virtual void setupMF(MachineFunction &MF, GISelKnownBits *KB, |
| 81 | + CodeGenCoverage *CoverageInfo = nullptr, |
| 82 | + ProfileSummaryInfo *PSI = nullptr, |
| 83 | + BlockFrequencyInfo *BFI = nullptr) { |
| 84 | + this->CoverageInfo = CoverageInfo; |
| 85 | + this->KB = KB; |
| 86 | + this->MF = &MF; |
| 87 | + this->PSI = PSI; |
| 88 | + this->BFI = BFI; |
| 89 | + this->CurMBB = nullptr; |
| 90 | + setupGeneratedPerFunctionState(MF); |
| 91 | + } |
| 92 | + |
| 93 | + void setCurMBB(MachineBasicBlock *CurMBB) { |
| 94 | + this->CurMBB = CurMBB; |
| 95 | + // Clear the recorded states for a new MBB. |
| 96 | + // Cannot give a good default, since MBB.size() is in O(N). |
| 97 | + States.clear(); |
| 98 | + } |
| 99 | + |
| 100 | +protected: |
| 101 | + const TargetPassConfig *TPC = nullptr; |
| 102 | + MachineOptimizationRemarkEmitter *MORE = nullptr; |
| 103 | +}; |
| 104 | +} // namespace llvm |
| 105 | + |
| 106 | +#endif |
0 commit comments