OpenVDB  12.1.0
Public Types | Public Member Functions | List of all members
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 HasUniqueTypeSignatures (llvm::LLVMContext &C) const
 Verify the function signatures in this group. More...
 
std::pair< const Function *, Function::SignatureMatchmatch (const ArgInfoVector &args, llvm::LLVMContext &C) const
 Given a vector of llvm types, 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. More...
 
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. More...
 
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. More...
 
const FunctionListlist () const
 Accessor to the underlying function signature list. More...
 
const char * name () const
 
const char * doc () const
 
const Functionmatch (const std::vector< llvm::Type * > &types, llvm::LLVMContext &C, Function::SignatureMatch *type=nullptr) const
 
llvm::Value * execute (const std::vector< llvm::Value * > &args, llvm::IRBuilder<> &B) const
 
const Functionexecute (const std::vector< llvm::Value * > &args, llvm::IRBuilder<> &B, llvm::Value *&result) const
 Given a vector of llvm values, find the best possible function signature, generate and execute the function body. Returns the Function that was selected and executed or a nullptr if no valid match was found. Sets the result variable to the return value of the function (nullptr if void). If no match is found, the result variable if left unset. More...
 

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

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

Constructor & Destructor Documentation

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

Member Function Documentation

const char* doc ( ) const
inline
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
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
llvm::Value* execute ( const std::vector< llvm::Value * > &  args,
llvm::IRBuilder<> &  B 
) const
Deprecated:
"FunctionGroup::execute which takes llvm::Value's and " "supports argument matching/casting is incompatible with LLVM 16+ and will be " "removed."
const Function* execute ( const std::vector< llvm::Value * > &  args,
llvm::IRBuilder<> &  B,
llvm::Value *&  result 
) const

Given a vector of llvm values, find the best possible function signature, generate and execute the function body. Returns the Function that was selected and executed or a nullptr if no valid match was found. Sets the result variable to the return value of the function (nullptr if void). If no match is found, the result variable if left unset.

Note
This function will throw if no valid return is provided by the matched declaration implementation.
Parameters
argsA vector of values representing the function arguments
BThe current llvm IRBuilder
resultThe result to set. nullptr on void return.
Returns
The matched function. nullptr if no match was found
Deprecated:
"FunctionGroup::execute which takes llvm::Value's and " "supports argument matching/casting is incompatible with LLVM 16+ and will be " "removed."
bool HasUniqueTypeSignatures ( llvm::LLVMContext &  C) const

Verify the function signatures in this group.

const FunctionList& list ( ) const
inline

Accessor to the underlying function signature list.

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

Given a vector of llvm types, 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
typesA vector of types representing the function argument types
CThe llvm context
typeIf provided, type is set to the type of match that occurred
const Function* match ( const std::vector< llvm::Type * > &  types,
llvm::LLVMContext &  C,
Function::SignatureMatch type = nullptr 
) const
Warning
Does not support detecting Ambiguous functions (returns Implicit in these cases).
Deprecated:
"Switch to AX's internal ArgInfo types for LLVM 16 onwards"
const char* name ( ) const
inline