Path: blob/main/contrib/llvm-project/llvm/lib/Target/SPIRV/SPIRVBuiltins.h
35269 views
//===-- SPIRVBuiltins.h - SPIR-V Built-in Functions -------------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// Lowering builtin function calls and types using their demangled names.9//10//===----------------------------------------------------------------------===//1112#ifndef LLVM_LIB_TARGET_SPIRV_SPIRVBUILTINS_H13#define LLVM_LIB_TARGET_SPIRV_SPIRVBUILTINS_H1415#include "SPIRVGlobalRegistry.h"16#include "llvm/CodeGen/GlobalISel/CallLowering.h"17#include "llvm/CodeGen/GlobalISel/MachineIRBuilder.h"1819namespace llvm {20namespace SPIRV {21/// Parses the name part of the demangled builtin call.22std::string lookupBuiltinNameHelper(StringRef DemangledCall);23/// Lowers a builtin function call using the provided \p DemangledCall skeleton24/// and external instruction \p Set.25///26/// \return the lowering success status if the called function is a recognized27/// builtin, std::nullopt otherwise.28///29/// \p DemangledCall is the skeleton of the lowered builtin function call.30/// \p Set is the external instruction set containing the given builtin.31/// \p OrigRet is the single original virtual return register if defined,32/// Register(0) otherwise.33/// \p OrigRetTy is the type of the \p OrigRet.34/// \p Args are the arguments of the lowered builtin call.35std::optional<bool> lowerBuiltin(const StringRef DemangledCall,36InstructionSet::InstructionSet Set,37MachineIRBuilder &MIRBuilder,38const Register OrigRet, const Type *OrigRetTy,39const SmallVectorImpl<Register> &Args,40SPIRVGlobalRegistry *GR);4142/// Helper function for finding a builtin function attributes43/// by a demangled function name. Defined in SPIRVBuiltins.cpp.44std::tuple<int, unsigned, unsigned>45mapBuiltinToOpcode(const StringRef DemangledCall,46SPIRV::InstructionSet::InstructionSet Set);4748/// Parses the provided \p ArgIdx argument base type in the \p DemangledCall49/// skeleton. A base type is either a basic type (e.g. i32 for int), pointer50/// element type (e.g. i8 for char*), or builtin type (TargetExtType).51///52/// \return LLVM Type or nullptr if unrecognized53///54/// \p DemangledCall is the skeleton of the lowered builtin function call.55/// \p ArgIdx is the index of the argument to parse.56Type *parseBuiltinCallArgumentBaseType(const StringRef DemangledCall,57unsigned ArgIdx, LLVMContext &Ctx);5859/// Translates a string representing a SPIR-V or OpenCL builtin type to a60/// TargetExtType that can be further lowered with lowerBuiltinType().61///62/// \return A TargetExtType representing the builtin SPIR-V type.63///64/// \p TypeName is the full string representation of the SPIR-V or OpenCL65/// builtin type.66TargetExtType *parseBuiltinTypeNameToTargetExtType(std::string TypeName,67LLVMContext &Context);6869/// Handles the translation of the provided special opaque/builtin type \p Type70/// to SPIR-V type. Generates the corresponding machine instructions for the71/// target type or gets the already existing OpType<...> register from the72/// global registry \p GR.73///74/// \return A machine instruction representing the OpType<...> SPIR-V type.75///76/// \p Type is the special opaque/builtin type to be lowered.77SPIRVType *lowerBuiltinType(const Type *Type,78AccessQualifier::AccessQualifier AccessQual,79MachineIRBuilder &MIRBuilder,80SPIRVGlobalRegistry *GR);81} // namespace SPIRV82} // namespace llvm83#endif // LLVM_LIB_TARGET_SPIRV_SPIRVBUILTINS_H848586