1 //===-- SPIRVISelLowering.h - SPIR-V DAG Lowering Interface -----*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 // This file defines the interfaces that SPIR-V uses to lower LLVM code into a
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_LIB_TARGET_SPIRV_SPIRVISELLOWERING_H
15 #define LLVM_LIB_TARGET_SPIRV_SPIRVISELLOWERING_H
17 #include "SPIRVGlobalRegistry.h"
18 #include "llvm/CodeGen/TargetLowering.h"
24 class SPIRVTargetLowering
: public TargetLowering
{
25 const SPIRVSubtarget
&STI
;
27 // Record of already processed machine functions
28 mutable std::set
<const MachineFunction
*> ProcessedMF
;
31 explicit SPIRVTargetLowering(const TargetMachine
&TM
,
32 const SPIRVSubtarget
&ST
)
33 : TargetLowering(TM
), STI(ST
) {}
35 // Stop IRTranslator breaking up FMA instrs to preserve types information.
36 bool isFMAFasterThanFMulAndFAdd(const MachineFunction
&MF
,
41 // prevent creation of jump tables
42 bool areJTsAllowed(const Function
*) const override
{ return false; }
44 // This is to prevent sexts of non-i64 vector indices which are generated
45 // within general IRTranslator hence type generation for it is omitted.
46 MVT
getVectorIdxTy(const DataLayout
&DL
) const override
{
47 return MVT::getIntegerVT(32);
49 unsigned getNumRegistersForCallingConv(LLVMContext
&Context
,
51 EVT VT
) const override
;
52 MVT
getRegisterTypeForCallingConv(LLVMContext
&Context
, CallingConv::ID CC
,
53 EVT VT
) const override
;
54 bool getTgtMemIntrinsic(IntrinsicInfo
&Info
, const CallInst
&I
,
56 unsigned Intrinsic
) const override
;
58 std::pair
<unsigned, const TargetRegisterClass
*>
59 getRegForInlineAsmConstraint(const TargetRegisterInfo
*TRI
,
60 StringRef Constraint
, MVT VT
) const override
;
62 getNumRegisters(LLVMContext
&Context
, EVT VT
,
63 std::optional
<MVT
> RegisterVT
= std::nullopt
) const override
{
67 // Call the default implementation and finalize target lowering by inserting
68 // extra instructions required to preserve validity of SPIR-V code imposed by
70 void finalizeLowering(MachineFunction
&MF
) const override
;
72 MVT
getPreferredSwitchConditionType(LLVMContext
&Context
,
73 EVT ConditionVT
) const override
{
74 return ConditionVT
.getSimpleVT();
79 #endif // LLVM_LIB_TARGET_SPIRV_SPIRVISELLOWERING_H