LLVM 24.0.0git
SPIRVBuiltins.h
Go to the documentation of this file.
1//===-- SPIRVBuiltins.h - SPIR-V Built-in Functions -------------*- 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// Lowering builtin function calls and types using their demangled names.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_LIB_TARGET_SPIRV_SPIRVBUILTINS_H
14#define LLVM_LIB_TARGET_SPIRV_SPIRVBUILTINS_H
15
16#include "SPIRVGlobalRegistry.h"
19
20namespace llvm {
21namespace SPIRV {
22/// Parses the name part of the demangled builtin call.
23std::string lookupBuiltinNameHelper(StringRef DemangledCall,
24 FPDecorationId *DecorationId = nullptr);
25/// Lowers a builtin function call using the provided \p DemangledCall skeleton
26/// and external instruction \p Set.
27///
28/// \return the lowering success status if the called function is a recognized
29/// builtin, std::nullopt otherwise.
30///
31/// \p DemangledCall is the skeleton of the lowered builtin function call.
32/// \p Set is the external instruction set containing the given builtin.
33/// \p OrigRet is the single original virtual return register if defined,
34/// Register(0) otherwise.
35/// \p OrigRetTy is the type of the \p OrigRet.
36/// \p Args are the arguments of the lowered builtin call.
37std::optional<bool> lowerBuiltin(StringRef DemangledCall,
38 InstructionSet::InstructionSet Set,
39 MachineIRBuilder &MIRBuilder,
40 const Register OrigRet, const Type *OrigRetTy,
41 const SmallVectorImpl<Register> &Args,
42 SPIRVGlobalRegistry *GR, const CallBase &CB);
43
44/// Helper function for finding a builtin function attributes
45/// by a demangled function name. Defined in SPIRVBuiltins.cpp.
46std::tuple<int, unsigned, unsigned>
47mapBuiltinToOpcode(StringRef DemangledCall,
48 SPIRV::InstructionSet::InstructionSet Set);
49
50/// Whether lowerBuiltin() recognizes \p DemangledCall in \p Set.
51bool isBuiltin(StringRef DemangledCall,
52 SPIRV::InstructionSet::InstructionSet Set);
53
54/// Parses the provided \p ArgIdx argument base type in the \p DemangledCall
55/// skeleton. A base type is either a basic type (e.g. i32 for int), pointer
56/// element type (e.g. i8 for char*), or builtin type (TargetExtType).
57///
58/// \return LLVM Type or nullptr if unrecognized
59///
60/// \p DemangledCall is the skeleton of the lowered builtin function call.
61/// \p ArgIdx is the index of the argument to parse.
62Type *parseBuiltinCallArgumentBaseType(StringRef DemangledCall, unsigned ArgIdx,
63 LLVMContext &Ctx);
64bool parseBuiltinTypeStr(SmallVector<StringRef, 10> &BuiltinArgsTypeStrs,
65 StringRef DemangledCall, LLVMContext &Ctx);
67
68/// Translates a string representing a SPIR-V or OpenCL builtin type to a
69/// TargetExtType that can be further lowered with lowerBuiltinType().
70///
71/// \return A TargetExtType representing the builtin SPIR-V type.
72///
73/// \p TypeName is the full string representation of the SPIR-V or OpenCL
74/// builtin type.
76 LLVMContext &Context);
77
78/// Handles the translation of the provided special opaque/builtin type \p Type
79/// to SPIR-V type. Generates the corresponding machine instructions for the
80/// target type or gets the already existing OpType<...> register from the
81/// global registry \p GR.
82///
83/// \return A machine instruction representing the OpType<...> SPIR-V type.
84///
85/// \p Type is the special opaque/builtin type to be lowered.
87 AccessQualifier::AccessQualifier AccessQual,
88 MachineIRBuilder &MIRBuilder,
90
91/// Returns true if \p Name is a pipe or address-space-cast OpenCL builtin.
93} // namespace SPIRV
94} // namespace llvm
95#endif // LLVM_LIB_TARGET_SPIRV_SPIRVBUILTINS_H
This file describes how to lower LLVM calls to machine code calls.
This file declares the MachineIRBuilder class.
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
This is an important class for using LLVM in a threaded context.
Definition LLVMContext.h:68
Helper class to build MachineInstr.
Wrapper class representing virtual and physical registers.
Definition Register.h:20
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
Class to represent target extensions types, which are generally unintrospectable from target-independ...
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
bool parseBuiltinTypeStr(SmallVector< StringRef, 10 > &BuiltinArgsTypeStrs, StringRef DemangledCall, LLVMContext &Ctx)
std::string lookupBuiltinNameHelper(StringRef DemangledCall, FPDecorationId *DecorationId)
Parses the name part of the demangled builtin call.
Type * parseBuiltinCallArgumentType(StringRef TypeStr, LLVMContext &Ctx)
bool isPipeOrAddressSpaceCastBuiltin(StringRef Name)
Returns true if Name is a pipe or address-space-cast OpenCL builtin.
std::optional< bool > lowerBuiltin(StringRef DemangledCall, SPIRV::InstructionSet::InstructionSet Set, MachineIRBuilder &MIRBuilder, const Register OrigRet, const Type *OrigRetTy, const SmallVectorImpl< Register > &Args, SPIRVGlobalRegistry *GR, const CallBase &CB)
Type * parseBuiltinCallArgumentBaseType(StringRef DemangledCall, unsigned ArgIdx, LLVMContext &Ctx)
Parses the provided ArgIdx argument base type in the DemangledCall skeleton.
bool isBuiltin(StringRef DemangledCall, SPIRV::InstructionSet::InstructionSet Set)
Whether lowerBuiltin() recognizes DemangledCall in Set.
std::tuple< int, unsigned, unsigned > mapBuiltinToOpcode(StringRef DemangledCall, SPIRV::InstructionSet::InstructionSet Set)
Helper function for finding a builtin function attributes by a demangled function name.
TargetExtType * parseBuiltinTypeNameToTargetExtType(std::string TypeName, LLVMContext &Context)
Translates a string representing a SPIR-V or OpenCL builtin type to a TargetExtType that can be furth...
SPIRVTypeInst lowerBuiltinType(const Type *OpaqueType, SPIRV::AccessQualifier::AccessQualifier AccessQual, MachineIRBuilder &MIRBuilder, SPIRVGlobalRegistry *GR)
This is an optimization pass for GlobalISel generic memory operations.
FPDecorationId
Definition SPIRVUtils.h:587