1*81ad6265SDimitry Andric //===- SPIRVISelLowering.cpp - SPIR-V DAG Lowering Impl ---------*- C++ -*-===// 2*81ad6265SDimitry Andric // 3*81ad6265SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4*81ad6265SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 5*81ad6265SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6*81ad6265SDimitry Andric // 7*81ad6265SDimitry Andric //===----------------------------------------------------------------------===// 8*81ad6265SDimitry Andric // 9*81ad6265SDimitry Andric // This file implements the SPIRVTargetLowering class. 10*81ad6265SDimitry Andric // 11*81ad6265SDimitry Andric //===----------------------------------------------------------------------===// 12*81ad6265SDimitry Andric 13*81ad6265SDimitry Andric #include "SPIRVISelLowering.h" 14*81ad6265SDimitry Andric #include "SPIRV.h" 15*81ad6265SDimitry Andric 16*81ad6265SDimitry Andric #define DEBUG_TYPE "spirv-lower" 17*81ad6265SDimitry Andric 18*81ad6265SDimitry Andric using namespace llvm; 19*81ad6265SDimitry Andric 20*81ad6265SDimitry Andric unsigned SPIRVTargetLowering::getNumRegistersForCallingConv( 21*81ad6265SDimitry Andric LLVMContext &Context, CallingConv::ID CC, EVT VT) const { 22*81ad6265SDimitry Andric // This code avoids CallLowering fail inside getVectorTypeBreakdown 23*81ad6265SDimitry Andric // on v3i1 arguments. Maybe we need to return 1 for all types. 24*81ad6265SDimitry Andric // TODO: remove it once this case is supported by the default implementation. 25*81ad6265SDimitry Andric if (VT.isVector() && VT.getVectorNumElements() == 3 && 26*81ad6265SDimitry Andric (VT.getVectorElementType() == MVT::i1 || 27*81ad6265SDimitry Andric VT.getVectorElementType() == MVT::i8)) 28*81ad6265SDimitry Andric return 1; 29*81ad6265SDimitry Andric return getNumRegisters(Context, VT); 30*81ad6265SDimitry Andric } 31*81ad6265SDimitry Andric 32*81ad6265SDimitry Andric MVT SPIRVTargetLowering::getRegisterTypeForCallingConv(LLVMContext &Context, 33*81ad6265SDimitry Andric CallingConv::ID CC, 34*81ad6265SDimitry Andric EVT VT) const { 35*81ad6265SDimitry Andric // This code avoids CallLowering fail inside getVectorTypeBreakdown 36*81ad6265SDimitry Andric // on v3i1 arguments. Maybe we need to return i32 for all types. 37*81ad6265SDimitry Andric // TODO: remove it once this case is supported by the default implementation. 38*81ad6265SDimitry Andric if (VT.isVector() && VT.getVectorNumElements() == 3) { 39*81ad6265SDimitry Andric if (VT.getVectorElementType() == MVT::i1) 40*81ad6265SDimitry Andric return MVT::v4i1; 41*81ad6265SDimitry Andric else if (VT.getVectorElementType() == MVT::i8) 42*81ad6265SDimitry Andric return MVT::v4i8; 43*81ad6265SDimitry Andric } 44*81ad6265SDimitry Andric return getRegisterType(Context, VT); 45*81ad6265SDimitry Andric } 46