1//===-- SPIRVCombinerHelper.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/// This contains common combine transformations that may be used in a combine
10/// pass.
11///
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_LIB_TARGET_SPIRV_SPIRVCOMBINERHELPER_H
15#define LLVM_LIB_TARGET_SPIRV_SPIRVCOMBINERHELPER_H
16
17#include "SPIRVSubtarget.h"
18#include "llvm/CodeGen/GlobalISel/CombinerHelper.h"
19
20namespace llvm {
21class SPIRVCombinerHelper : public CombinerHelper {
22protected:
23 const SPIRVSubtarget &STI;
24
25public:
26 using CombinerHelper::CombinerHelper;
27 SPIRVCombinerHelper(GISelChangeObserver &Observer, MachineIRBuilder &B,
28 bool IsPreLegalize, GISelValueTracking *VT,
29 MachineDominatorTree *MDT, const LegalizerInfo *LI,
30 const SPIRVSubtarget &STI);
31
32 bool matchFDivToNormalize(MachineInstr &MI) const;
33 void applySPIRVNormalize(MachineInstr &MI) const;
34 bool matchSelectToFaceForward(MachineInstr &MI) const;
35 void applySPIRVFaceForward(MachineInstr &MI) const;
36 void applyMatrixTranspose(MachineInstr &MI) const;
37 void applyMatrixMultiply(MachineInstr &MI) const;
38
39private:
40 SPIRVTypeInst getDotProductVectorType(Register ResReg, uint32_t K,
41 SPIRVGlobalRegistry *GR) const;
42 SmallVector<Register, 4> extractColumns(Register BReg, uint32_t N,
43 SPIRVTypeInst SpvVecType,
44 SPIRVGlobalRegistry *GR) const;
45 SmallVector<Register, 4> extractRows(Register AReg, uint32_t NumRows,
46 uint32_t NumCols,
47 SPIRVTypeInst SpvRowType,
48 SPIRVGlobalRegistry *GR) const;
49 SmallVector<Register, 16> computeDotProducts(ArrayRef<Register> RowsA,
50 ArrayRef<Register> ColsB,
51 SPIRVTypeInst SpvVecType,
52 SPIRVGlobalRegistry *GR) const;
53 Register computeDotProduct(Register RowA, Register ColB,
54 SPIRVTypeInst SpvVecType,
55 SPIRVGlobalRegistry *GR) const;
56};
57
58} // end namespace llvm
59
60#endif // LLVM_LIB_TARGET_SPIRV_SPIRVCOMBINERHELPER_H
61