1*700637cbSDimitry Andric //===- SPIRVTargetTransformInfo.cpp - SPIR-V specific TTI -------*- C++ -*-===// 2*700637cbSDimitry Andric // 3*700637cbSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4*700637cbSDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 5*700637cbSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6*700637cbSDimitry Andric // 7*700637cbSDimitry Andric //===----------------------------------------------------------------------===// 8*700637cbSDimitry Andric 9*700637cbSDimitry Andric #include "SPIRVTargetTransformInfo.h" 10*700637cbSDimitry Andric #include "llvm/IR/IntrinsicsSPIRV.h" 11*700637cbSDimitry Andric 12*700637cbSDimitry Andric using namespace llvm; 13*700637cbSDimitry Andric collectFlatAddressOperands(SmallVectorImpl<int> & OpIndexes,Intrinsic::ID IID) const14*700637cbSDimitry Andricbool llvm::SPIRVTTIImpl::collectFlatAddressOperands( 15*700637cbSDimitry Andric SmallVectorImpl<int> &OpIndexes, Intrinsic::ID IID) const { 16*700637cbSDimitry Andric switch (IID) { 17*700637cbSDimitry Andric case Intrinsic::spv_generic_cast_to_ptr_explicit: 18*700637cbSDimitry Andric OpIndexes.push_back(0); 19*700637cbSDimitry Andric return true; 20*700637cbSDimitry Andric default: 21*700637cbSDimitry Andric return false; 22*700637cbSDimitry Andric } 23*700637cbSDimitry Andric } 24*700637cbSDimitry Andric rewriteIntrinsicWithAddressSpace(IntrinsicInst * II,Value * OldV,Value * NewV) const25*700637cbSDimitry AndricValue *llvm::SPIRVTTIImpl::rewriteIntrinsicWithAddressSpace(IntrinsicInst *II, 26*700637cbSDimitry Andric Value *OldV, 27*700637cbSDimitry Andric Value *NewV) const { 28*700637cbSDimitry Andric auto IntrID = II->getIntrinsicID(); 29*700637cbSDimitry Andric switch (IntrID) { 30*700637cbSDimitry Andric case Intrinsic::spv_generic_cast_to_ptr_explicit: { 31*700637cbSDimitry Andric unsigned NewAS = NewV->getType()->getPointerAddressSpace(); 32*700637cbSDimitry Andric unsigned DstAS = II->getType()->getPointerAddressSpace(); 33*700637cbSDimitry Andric return NewAS == DstAS ? NewV 34*700637cbSDimitry Andric : ConstantPointerNull::get( 35*700637cbSDimitry Andric PointerType::get(NewV->getContext(), DstAS)); 36*700637cbSDimitry Andric } 37*700637cbSDimitry Andric default: 38*700637cbSDimitry Andric return nullptr; 39*700637cbSDimitry Andric } 40*700637cbSDimitry Andric } 41