LLVM 19.0.0git
Go to the documentation of this file.
1//===-- SPIRVBuiltins.h - SPIR-V Built-in Functions -------------*- C++ -*-===//
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
9// Lowering builtin function calls and types using their demangled names.
16#include "SPIRVGlobalRegistry.h"
20namespace llvm {
21namespace SPIRV {
22/// Parses the name part of the demangled builtin call.
23std::string lookupBuiltinNameHelper(StringRef DemangledCall);
24/// Lowers a builtin function call using the provided \p DemangledCall skeleton
25/// and external instruction \p Set.
27/// \return the lowering success status if the called function is a recognized
28/// builtin, std::nullopt otherwise.
30/// \p DemangledCall is the skeleton of the lowered builtin function call.
31/// \p Set is the external instruction set containing the given builtin.
32/// \p OrigRet is the single original virtual return register if defined,
33/// Register(0) otherwise.
34/// \p OrigRetTy is the type of the \p OrigRet.
35/// \p Args are the arguments of the lowered builtin call.
36std::optional<bool> lowerBuiltin(const StringRef DemangledCall,
37 InstructionSet::InstructionSet Set,
38 MachineIRBuilder &MIRBuilder,
39 const Register OrigRet, const Type *OrigRetTy,
40 const SmallVectorImpl<Register> &Args,
43/// Helper function for finding a builtin function attributes
44/// by a demangled function name. Defined in SPIRVBuiltins.cpp.
45std::tuple<int, unsigned, unsigned>
46mapBuiltinToOpcode(const StringRef DemangledCall,
47 SPIRV::InstructionSet::InstructionSet Set);
49/// Parses the provided \p ArgIdx argument base type in the \p DemangledCall
50/// skeleton. A base type is either a basic type (e.g. i32 for int), pointer
51/// element type (e.g. i8 for char*), or builtin type (TargetExtType).
53/// \return LLVM Type or nullptr if unrecognized
55/// \p DemangledCall is the skeleton of the lowered builtin function call.
56/// \p ArgIdx is the index of the argument to parse.
58 unsigned ArgIdx, LLVMContext &Ctx);
60/// Translates a string representing a SPIR-V or OpenCL builtin type to a
61/// TargetExtType that can be further lowered with lowerBuiltinType().
63/// \return A TargetExtType representing the builtin SPIR-V type.
65/// \p TypeName is the full string representation of the SPIR-V or OpenCL
66/// builtin type.
68 LLVMContext &Context);
70/// Handles the translation of the provided special opaque/builtin type \p Type
71/// to SPIR-V type. Generates the corresponding machine instructions for the
72/// target type or gets the already existing OpType<...> register from the
73/// global registry \p GR.
75/// \return A machine instruction representing the OpType<...> SPIR-V type.
77/// \p Type is the special opaque/builtin type to be lowered.
79 AccessQualifier::AccessQualifier AccessQual,
80 MachineIRBuilder &MIRBuilder,
82} // namespace SPIRV
83} // namespace llvm
This file describes how to lower LLVM calls to machine code calls.
This file declares the MachineIRBuilder class.
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:67
Helper class to build MachineInstr.
Representation of each machine instruction.
Definition: MachineInstr.h:69
Wrapper class representing virtual and physical registers.
Definition: Register.h:19
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:586
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
Class to represent target extensions types, which are generally unintrospectable from target-independ...
Definition: DerivedTypes.h:720
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
std::tuple< int, unsigned, unsigned > mapBuiltinToOpcode(const StringRef DemangledCall, SPIRV::InstructionSet::InstructionSet Set)
Helper function for finding a builtin function attributes by a demangled function name.
Type * parseBuiltinCallArgumentBaseType(const StringRef DemangledCall, unsigned ArgIdx, LLVMContext &Ctx)
Parses the provided ArgIdx argument base type in the DemangledCall skeleton.
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...
std::optional< bool > lowerBuiltin(const StringRef DemangledCall, SPIRV::InstructionSet::InstructionSet Set, MachineIRBuilder &MIRBuilder, const Register OrigRet, const Type *OrigRetTy, const SmallVectorImpl< Register > &Args, SPIRVGlobalRegistry *GR)
SPIRVType * lowerBuiltinType(const Type *OpaqueType, SPIRV::AccessQualifier::AccessQualifier AccessQual, MachineIRBuilder &MIRBuilder, SPIRVGlobalRegistry *GR)
std::string lookupBuiltinNameHelper(StringRef DemangledCall)
Parses the name part of the demangled builtin call.
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18