LLVM 18.0.0git
SPIRVISelLowering.cpp
Go to the documentation of this file.
1//===- SPIRVISelLowering.cpp - SPIR-V DAG Lowering Impl ---------*- 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 file implements the SPIRVTargetLowering class.
10//
11//===----------------------------------------------------------------------===//
12
13#include "SPIRVISelLowering.h"
14#include "SPIRV.h"
15#include "llvm/IR/IntrinsicsSPIRV.h"
16
17#define DEBUG_TYPE "spirv-lower"
18
19using namespace llvm;
20
22 LLVMContext &Context, CallingConv::ID CC, EVT VT) const {
23 // This code avoids CallLowering fail inside getVectorTypeBreakdown
24 // on v3i1 arguments. Maybe we need to return 1 for all types.
25 // TODO: remove it once this case is supported by the default implementation.
26 if (VT.isVector() && VT.getVectorNumElements() == 3 &&
27 (VT.getVectorElementType() == MVT::i1 ||
28 VT.getVectorElementType() == MVT::i8))
29 return 1;
30 if (!VT.isVector() && VT.isInteger() && VT.getSizeInBits() <= 64)
31 return 1;
32 return getNumRegisters(Context, VT);
33}
34
37 EVT VT) const {
38 // This code avoids CallLowering fail inside getVectorTypeBreakdown
39 // on v3i1 arguments. Maybe we need to return i32 for all types.
40 // TODO: remove it once this case is supported by the default implementation.
41 if (VT.isVector() && VT.getVectorNumElements() == 3) {
42 if (VT.getVectorElementType() == MVT::i1)
43 return MVT::v4i1;
44 else if (VT.getVectorElementType() == MVT::i8)
45 return MVT::v4i8;
46 }
47 return getRegisterType(Context, VT);
48}
49
51 const CallInst &I,
53 unsigned Intrinsic) const {
54 unsigned AlignIdx = 3;
55 switch (Intrinsic) {
56 case Intrinsic::spv_load:
57 AlignIdx = 2;
58 [[fallthrough]];
59 case Intrinsic::spv_store: {
60 if (I.getNumOperands() >= AlignIdx + 1) {
61 auto *AlignOp = cast<ConstantInt>(I.getOperand(AlignIdx));
62 Info.align = Align(AlignOp->getZExtValue());
63 }
64 Info.flags = static_cast<MachineMemOperand::Flags>(
65 cast<ConstantInt>(I.getOperand(AlignIdx - 1))->getZExtValue());
66 Info.memVT = MVT::i64;
67 // TODO: take into account opaque pointers (don't use getElementType).
68 // MVT::getVT(PtrTy->getElementType());
69 return true;
70 break;
71 }
72 default:
73 break;
74 }
75 return false;
76}
Analysis containing CSE Info
Definition: CSEInfo.cpp:27
#define I(x, y, z)
Definition: MD5.cpp:58
LLVMContext & Context
This class represents a function call, abstracting a target machine's calling convention.
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:67
Machine Value Type.
Flags
Flags values. These may be or'd together.
unsigned getNumRegistersForCallingConv(LLVMContext &Context, CallingConv::ID CC, EVT VT) const override
Certain targets require unusual breakdowns of certain types.
MVT getRegisterTypeForCallingConv(LLVMContext &Context, CallingConv::ID CC, EVT VT) const override
Certain combinations of ABIs, Targets and features require that types are legal for some operations a...
bool getTgtMemIntrinsic(IntrinsicInfo &Info, const CallInst &I, MachineFunction &MF, unsigned Intrinsic) const override
Given an intrinsic, checks if on the target the intrinsic will need to map to a MemIntrinsicNode (tou...
virtual unsigned getNumRegisters(LLVMContext &Context, EVT VT, std::optional< MVT > RegisterVT=std::nullopt) const
Return the number of registers that this ValueType will eventually require.
MVT getRegisterType(MVT VT) const
Return the type of registers that this ValueType will eventually require.
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39
Extended Value Type.
Definition: ValueTypes.h:34
TypeSize getSizeInBits() const
Return the size of the specified value type in bits.
Definition: ValueTypes.h:351
bool isVector() const
Return true if this is a vector value type.
Definition: ValueTypes.h:160
EVT getVectorElementType() const
Given a vector type, return the type of each element.
Definition: ValueTypes.h:311
unsigned getVectorNumElements() const
Given a vector type, return the number of elements it contains.
Definition: ValueTypes.h:319
bool isInteger() const
Return true if this is an integer or a vector integer type.
Definition: ValueTypes.h:144