10b57cec5SDimitry Andric //===-- NVPTXUtilities - Utilities -----------------------------*- C++ -*-====// 20b57cec5SDimitry Andric // 30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 60b57cec5SDimitry Andric // 70b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 80b57cec5SDimitry Andric // 90b57cec5SDimitry Andric // This file contains the declaration of the NVVM specific utility functions. 100b57cec5SDimitry Andric // 110b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 120b57cec5SDimitry Andric 130b57cec5SDimitry Andric #ifndef LLVM_LIB_TARGET_NVPTX_NVPTXUTILITIES_H 140b57cec5SDimitry Andric #define LLVM_LIB_TARGET_NVPTX_NVPTXUTILITIES_H 150b57cec5SDimitry Andric 165f757f3fSDimitry Andric #include "llvm/CodeGen/ValueTypes.h" 170b57cec5SDimitry Andric #include "llvm/IR/Function.h" 180b57cec5SDimitry Andric #include "llvm/IR/GlobalVariable.h" 190b57cec5SDimitry Andric #include "llvm/IR/IntrinsicInst.h" 200b57cec5SDimitry Andric #include "llvm/IR/Value.h" 21*0fca6ea1SDimitry Andric #include "llvm/Support/Alignment.h" 220b57cec5SDimitry Andric #include <cstdarg> 230b57cec5SDimitry Andric #include <set> 240b57cec5SDimitry Andric #include <string> 250b57cec5SDimitry Andric #include <vector> 260b57cec5SDimitry Andric 270b57cec5SDimitry Andric namespace llvm { 280b57cec5SDimitry Andric 29bdd1243dSDimitry Andric class TargetMachine; 30bdd1243dSDimitry Andric 310b57cec5SDimitry Andric void clearAnnotationCache(const Module *); 320b57cec5SDimitry Andric 330b57cec5SDimitry Andric bool findOneNVVMAnnotation(const GlobalValue *, const std::string &, 340b57cec5SDimitry Andric unsigned &); 350b57cec5SDimitry Andric bool findAllNVVMAnnotation(const GlobalValue *, const std::string &, 360b57cec5SDimitry Andric std::vector<unsigned> &); 370b57cec5SDimitry Andric 380b57cec5SDimitry Andric bool isTexture(const Value &); 390b57cec5SDimitry Andric bool isSurface(const Value &); 400b57cec5SDimitry Andric bool isSampler(const Value &); 410b57cec5SDimitry Andric bool isImage(const Value &); 420b57cec5SDimitry Andric bool isImageReadOnly(const Value &); 430b57cec5SDimitry Andric bool isImageWriteOnly(const Value &); 440b57cec5SDimitry Andric bool isImageReadWrite(const Value &); 450b57cec5SDimitry Andric bool isManaged(const Value &); 460b57cec5SDimitry Andric 470b57cec5SDimitry Andric std::string getTextureName(const Value &); 480b57cec5SDimitry Andric std::string getSurfaceName(const Value &); 490b57cec5SDimitry Andric std::string getSamplerName(const Value &); 500b57cec5SDimitry Andric 51*0fca6ea1SDimitry Andric std::optional<unsigned> getMaxNTIDx(const Function &); 52*0fca6ea1SDimitry Andric std::optional<unsigned> getMaxNTIDy(const Function &); 53*0fca6ea1SDimitry Andric std::optional<unsigned> getMaxNTIDz(const Function &); 54*0fca6ea1SDimitry Andric std::optional<unsigned> getMaxNTID(const Function &F); 550b57cec5SDimitry Andric 56*0fca6ea1SDimitry Andric std::optional<unsigned> getReqNTIDx(const Function &); 57*0fca6ea1SDimitry Andric std::optional<unsigned> getReqNTIDy(const Function &); 58*0fca6ea1SDimitry Andric std::optional<unsigned> getReqNTIDz(const Function &); 59*0fca6ea1SDimitry Andric std::optional<unsigned> getReqNTID(const Function &); 600b57cec5SDimitry Andric 615f757f3fSDimitry Andric bool getMaxClusterRank(const Function &, unsigned &); 620b57cec5SDimitry Andric bool getMinCTASm(const Function &, unsigned &); 630b57cec5SDimitry Andric bool getMaxNReg(const Function &, unsigned &); 640b57cec5SDimitry Andric bool isKernelFunction(const Function &); 65*0fca6ea1SDimitry Andric bool isParamGridConstant(const Value &); 660b57cec5SDimitry Andric 67*0fca6ea1SDimitry Andric MaybeAlign getAlign(const Function &, unsigned); 68*0fca6ea1SDimitry Andric MaybeAlign getAlign(const CallInst &, unsigned); 69bdd1243dSDimitry Andric Function *getMaybeBitcastedCallee(const CallBase *CB); 700b57cec5SDimitry Andric 71fcaf7f86SDimitry Andric // PTX ABI requires all scalar argument/return values to have 72fcaf7f86SDimitry Andric // bit-size as a power of two of at least 32 bits. 73fcaf7f86SDimitry Andric inline unsigned promoteScalarArgumentSize(unsigned size) { 74fcaf7f86SDimitry Andric if (size <= 32) 75fcaf7f86SDimitry Andric return 32; 76fcaf7f86SDimitry Andric else if (size <= 64) 77fcaf7f86SDimitry Andric return 64; 78fcaf7f86SDimitry Andric else 79fcaf7f86SDimitry Andric return size; 80fcaf7f86SDimitry Andric } 81bdd1243dSDimitry Andric 82bdd1243dSDimitry Andric bool shouldEmitPTXNoReturn(const Value *V, const TargetMachine &TM); 835f757f3fSDimitry Andric 845f757f3fSDimitry Andric bool Isv2x16VT(EVT VT); 850b57cec5SDimitry Andric } 860b57cec5SDimitry Andric 870b57cec5SDimitry Andric #endif 88