OpenVDB 14.0.0
Loading...
Searching...
No Matches
FunctionGroup Struct Reference

A group of functions which all have the same name but different signatures. For example: float abs(float) double abs(double) As well as serving as a way of grouping common functions, this class provides an API for selecting the best possible function signature, should a match exist, against a provided set of argument types. More...

#include <openvdb_ax/codegen/FunctionTypes.h>

Public Types

using Ptr = std::shared_ptr<FunctionGroup>
using UniquePtr = std::unique_ptr<FunctionGroup>
using FunctionList = std::vector<Function::Ptr>

Public Member Functions

 FunctionGroup (const char *name, const char *doc, const FunctionList &list)
 ~FunctionGroup ()=default
bool HasUniqueFunctionSymbols () const
 Verify the function symbol names in this group (must be unique).
bool HasUniqueTypeSignatures (llvm::LLVMContext &C) const
 Verify the function signatures in this group (must be unique).
std::pair< const Function *, Function::SignatureMatch > match (const ArgInfoVector &args, llvm::LLVMContext &C) const
 Given a vector of args, automatically returns the best possible function declaration from the stored function list. The 'best' declaration is determined by the provided types compatibility to each functions signature.
Value execute (const Arguments &args, llvm::IRBuilder<> &B) const
 Given a set of Arguments, find an EXPLICIT signature match, generate and execute the function body. If no explicit match exists, Value::Invalid() is returned.
Value execute (const NativeArguments &args, llvm::IRBuilder<> &B) const
 Given a set of NativeArguments, find the best possible function signature, generate and execute the function body. Returns the return value of the function or Value::Invalid() if no Explicit or Implicit match is found.
const FunctionList & list () const
 Accessor to the underlying function signature list.
const char * name () const
const char * doc () const

Detailed Description

A group of functions which all have the same name but different signatures. For example: float abs(float) double abs(double) As well as serving as a way of grouping common functions, this class provides an API for selecting the best possible function signature, should a match exist, against a provided set of argument types.

Member Typedef Documentation

◆ FunctionList

using FunctionList = std::vector<Function::Ptr>

◆ Ptr

using Ptr = std::shared_ptr<FunctionGroup>

◆ UniquePtr

using UniquePtr = std::unique_ptr<FunctionGroup>

Constructor & Destructor Documentation

◆ FunctionGroup()

FunctionGroup ( const char * name,
const char * doc,
const FunctionList & list )
inline

◆ ~FunctionGroup()

~FunctionGroup ( )
default

Member Function Documentation

◆ doc()

const char * doc ( ) const
inline

◆ execute() [1/2]

Value execute ( const Arguments & args,
llvm::IRBuilder<> & B ) const

Given a set of Arguments, find an EXPLICIT signature match, generate and execute the function body. If no explicit match exists, Value::Invalid() is returned.

Note
To ensure something is matched/executed, consider calling match() and Function::call instead. This method should only be used by internal methods that can assert an explicit match exists.
Parameters
argsFunction arguments
BThe current llvm IRBuilder

◆ execute() [2/2]

Value execute ( const NativeArguments & args,
llvm::IRBuilder<> & B ) const

Given a set of NativeArguments, find the best possible function signature, generate and execute the function body. Returns the return value of the function or Value::Invalid() if no Explicit or Implicit match is found.

Note
This function will throw if no valid return is provided by the matched declaration implementation.
Parameters
argsNatively supported function arguments
BThe current llvm IRBuilder

◆ HasUniqueFunctionSymbols()

bool HasUniqueFunctionSymbols ( ) const

Verify the function symbol names in this group (must be unique).

◆ HasUniqueTypeSignatures()

bool HasUniqueTypeSignatures ( llvm::LLVMContext & C) const

Verify the function signatures in this group (must be unique).

◆ list()

const FunctionList & list ( ) const
inline

Accessor to the underlying function signature list.

◆ match()

std::pair< const Function *, Function::SignatureMatch > match ( const ArgInfoVector & args,
llvm::LLVMContext & C ) const

Given a vector of args, automatically returns the best possible function declaration from the stored function list. The 'best' declaration is determined by the provided types compatibility to each functions signature.

Note
Returns a nullptr if no compatible match was found or if the function list is empty. A compatible match is defined as an Explicit, Implicit or Ambiguous match (where the latter returns the first matched implicit function where other implicit matches exist).
If multiple implicit matches are found, the first match is returned and 'type' is set to Ambiguous (if provided).
Warning
All funcions in this group must implement the types(ArgInfo) virtual function, which is optional in LLVM 15 but required from LLVM 16.
Parameters
argsArgs representing the function argument types
CThe llvm context

◆ name()

const char * name ( ) const
inline