OpenVDB  12.1.0
Classes | Public Types | Public Member Functions | List of all members
FunctionBuilder Struct Reference

The FunctionBuilder class provides a builder pattern framework to allow easy and valid construction of AX functions. There are a number of complex tasks which may need to be performed during construction of C or IR function which are delegated to this builder, whilst ensuring that the constructed functions are guaranteed to be valid. More...

#include <openvdb_ax/codegen/FunctionTypes.h>

Classes

struct  Settings
 

Public Types

enum  DeclPreferrence { C, IR, Any }
 

Public Member Functions

 FunctionBuilder (const char *name)
 
template<typename Signature , bool SRet = false>
FunctionBuilderaddSignature (const Signature *ptr, const char *symbol=nullptr)
 
template<typename Signature , bool SRet = false>
FunctionBuilderaddSignature (const IRFunctionBase::GeneratorCb &cb, const char *symbol=nullptr)
 
template<typename Signature , bool SRet = false>
FunctionBuilderaddSignature (const IRFunctionBase::GeneratorCb &cb, const Signature *ptr, const char *symbol=nullptr)
 
template<typename Signature , bool SRet = false>
FunctionBuilderaddSignature (const IRFunctionBase::GeneratorNativeCb &cb, const char *symbol=nullptr)
 
template<typename Signature , bool SRet = false>
FunctionBuilderaddSignature (const IRFunctionBase::GeneratorNativeCb &cb, const Signature *ptr, const char *symbol=nullptr)
 
template<typename Signature , bool SRet = false>
FunctionBuilderaddSignature (const IRFunctionBase::GeneratorArgumentsCb &cb, const char *symbol=nullptr)
 
template<typename Signature , bool SRet = false>
FunctionBuilderaddSignature (const IRFunctionBase::GeneratorArgumentsCb &cb, const Signature *ptr, const char *symbol=nullptr)
 
FunctionBuilderaddDependency (const char *name)
 
FunctionBuildersetEmbedIR (bool on)
 
FunctionBuildersetConstantFold (bool on)
 
FunctionBuildersetArgumentNames (const std::vector< const char * > &names)
 
FunctionBuilderaddParameterAttribute (const size_t idx, const llvm::Attribute::AttrKind attr)
 Parameter and Function Attributes. When designing a C binding, llvm will be unable to assign parameter markings to the return type, function body or parameter attributes due to there not being any visibility on the function itself during codegen. The best way to ensure performant C bindings is to ensure that the function is marked with the required llvm parameters. More...
 
FunctionBuilderaddReturnAttribute (const llvm::Attribute::AttrKind attr)
 
FunctionBuilderaddFunctionAttribute (const llvm::Attribute::AttrKind attr)
 
FunctionBuildersetReadOnly (const bool on)
 Mark functions currently sharing settings with as "readonly". This enables the strictest possible memory effects for this function in llvm and implies that the function does not write to any memory (i.e. CreateStore) and only reads memory directly from its function arguments (i.e. nothing external to the function). Functions marked as "readonly" but do not adhere to the above will cause UB. More...
 
FunctionBuildersetBuiltin (const bool on)
 Mark functions currently sharing settings as builtin AX methods. At compile time, this causes the IR function body, arguments and return value to be marked with a set of default attributes that apply to all builtin methods, as they are expected to only be called by AX programs. Currently this results in: More...
 
FunctionBuildersetDocumentation (const char *doc)
 
FunctionBuildersetPreferredImpl (DeclPreferrence pref)
 
FunctionGroup::UniquePtr get () const
 

Detailed Description

The FunctionBuilder class provides a builder pattern framework to allow easy and valid construction of AX functions. There are a number of complex tasks which may need to be performed during construction of C or IR function which are delegated to this builder, whilst ensuring that the constructed functions are guaranteed to be valid.

Use the FunctionBuilder::addSignature methods to append function signatures. Finalize the group of functions with FunctionBuilder::get.

Member Enumeration Documentation

Enumerator
IR 
Any 

Constructor & Destructor Documentation

FunctionBuilder ( const char *  name)
inline

Member Function Documentation

FunctionBuilder& addDependency ( const char *  name)
inline
FunctionBuilder& addFunctionAttribute ( const llvm::Attribute::AttrKind  attr)
inline
FunctionBuilder& addParameterAttribute ( const size_t  idx,
const llvm::Attribute::AttrKind  attr 
)
inline

Parameter and Function Attributes. When designing a C binding, llvm will be unable to assign parameter markings to the return type, function body or parameter attributes due to there not being any visibility on the function itself during codegen. The best way to ensure performant C bindings is to ensure that the function is marked with the required llvm parameters.

Note
Some of the most common are shown in FunctionBuilder::setBuiltin, but also consider FunctionBuilder::setReadOnly
FunctionBuilder& addReturnAttribute ( const llvm::Attribute::AttrKind  attr)
inline
FunctionBuilder& addSignature ( const Signature *  ptr,
const char *  symbol = nullptr 
)
inline
FunctionBuilder& addSignature ( const IRFunctionBase::GeneratorCb cb,
const char *  symbol = nullptr 
)
inline
FunctionBuilder& addSignature ( const IRFunctionBase::GeneratorCb cb,
const Signature *  ptr,
const char *  symbol = nullptr 
)
inline
FunctionBuilder& addSignature ( const IRFunctionBase::GeneratorNativeCb cb,
const char *  symbol = nullptr 
)
inline
FunctionBuilder& addSignature ( const IRFunctionBase::GeneratorNativeCb cb,
const Signature *  ptr,
const char *  symbol = nullptr 
)
inline
FunctionBuilder& addSignature ( const IRFunctionBase::GeneratorArgumentsCb cb,
const char *  symbol = nullptr 
)
inline
FunctionBuilder& addSignature ( const IRFunctionBase::GeneratorArgumentsCb cb,
const Signature *  ptr,
const char *  symbol = nullptr 
)
inline
FunctionGroup::UniquePtr get ( ) const
inline
FunctionBuilder& setArgumentNames ( const std::vector< const char * > &  names)
inline
FunctionBuilder& setBuiltin ( const bool  on)
inline

Mark functions currently sharing settings as builtin AX methods. At compile time, this causes the IR function body, arguments and return value to be marked with a set of default attributes that apply to all builtin methods, as they are expected to only be called by AX programs. Currently this results in:

Function Attributes: llvm::Attribute::NoFree llvm::Attribute::WillReturn llvm::Attribute::NoRecurse llvm::Attribute::NoUnwind llvm::Attribute::AlwaysInline Return Attributes: - Parameter Attributes (Ptrs): llvm::Attribute::NonNull llvm::Attribute::NoUndef llvm::Attribute::NoFree

Warning
Attributes in this method may be extended - as such, you should mark external function with individual attributes instead of calling this.
FunctionBuilder& setConstantFold ( bool  on)
inline
FunctionBuilder& setDocumentation ( const char *  doc)
inline
FunctionBuilder& setEmbedIR ( bool  on)
inline
FunctionBuilder& setPreferredImpl ( DeclPreferrence  pref)
inline
FunctionBuilder& setReadOnly ( const bool  on)
inline

Mark functions currently sharing settings with as "readonly". This enables the strictest possible memory effects for this function in llvm and implies that the function does not write to any memory (i.e. CreateStore) and only reads memory directly from its function arguments (i.e. nothing external to the function). Functions marked as "readonly" but do not adhere to the above will cause UB.

Note
Obviously invalid for SRET functions!