66#ifndef OPENVDB_AX_CODEGEN_FUNCTION_TYPES_HAS_BEEN_INCLUDED 
   67#define OPENVDB_AX_CODEGEN_FUNCTION_TYPES_HAS_BEEN_INCLUDED 
   73#include <openvdb/version.h> 
   76#include <llvm/IR/Constants.h> 
   77#include <llvm/IR/IRBuilder.h> 
   78#include <llvm/IR/Module.h> 
  102template <
typename T, 
size_t _SIZE = 1>
 
  105    static const size_t SIZE = _SIZE;
 
 
  110template <
typename T, 
size_t S>
 
  133template <
typename T> 
struct TypeToSymbol { 
static inline std::string 
s() { 
return "?"; } };
 
  134template <> 
struct TypeToSymbol<void> { 
static inline std::string 
s() { 
return "v"; } };
 
  135template <> 
struct TypeToSymbol<char> { 
static inline std::string 
s() { 
return "c"; } };
 
  136template <> 
struct TypeToSymbol<uint8_t>  { 
static inline std::string 
s() { 
return "u8"; } };
 
  137template <> 
struct TypeToSymbol<uint16_t> { 
static inline std::string 
s() { 
return "us"; } };
 
  138template <> 
struct TypeToSymbol<uint32_t> { 
static inline std::string 
s() { 
return "ui"; } };
 
  139template <> 
struct TypeToSymbol<uint64_t> { 
static inline std::string 
s() { 
return "ul"; } };
 
  140template <> 
struct TypeToSymbol<int8_t>  { 
static inline std::string 
s() { 
return "8"; } };
 
  141template <> 
struct TypeToSymbol<int16_t> { 
static inline std::string 
s() { 
return "s"; } };
 
  142template <> 
struct TypeToSymbol<int32_t> { 
static inline std::string 
s() { 
return "i"; } };
 
  143template <> 
struct TypeToSymbol<int64_t> { 
static inline std::string 
s() { 
return "l"; } };
 
  144template <> 
struct TypeToSymbol<float> { 
static inline std::string 
s() { 
return "f"; } };
 
  145template <> 
struct TypeToSymbol<double> { 
static inline std::string 
s() { 
return "d"; } };
 
  153template <
typename T, 
size_t S>
 
  173template <typename SignatureT, size_t I = FunctionTraits<SignatureT>::N_ARGS>
 
  179    template <
typename OpT>
 
  180    static void apply(
const OpT& op, 
const bool forwards) {
 
 
 
  192template <
typename SignatureT>
 
  195    template <
typename OpT>
 
  196    static void apply(
const OpT&, 
const bool) {}
 
 
  207template <
typename SignatureT>
 
  210                std::vector<llvm::Type*>* types = 
nullptr)
 
  213    using ArgumentIteratorT =
 
  217        types->reserve(Traits::N_ARGS);
 
  218        auto callback = [&types, &C](
auto type) {
 
  219            using Type = 
decltype(type);
 
  222        ArgumentIteratorT::apply(callback, 
true);
 
 
  231template <
typename SignatureT>
 
  232inline llvm::FunctionType*
 
  235    std::vector<llvm::Type*> types;
 
  236    llvm::Type* returnType =
 
  238    return llvm::FunctionType::get(returnType,
 
  239            llvm::ArrayRef<llvm::Type*>(types),
 
 
  256               const std::vector<llvm::Type*>& types,
 
  257               const llvm::Type* returnType,
 
  258               const char* name = 
nullptr,
 
  259               const std::vector<const char*>& names = {},
 
  260               const bool axTypes = 
false);
 
  269    using Ptr = std::shared_ptr<Function>;
 
  274        , mAttributes(nullptr)
 
 
  286    virtual llvm::Type* 
types(std::vector<llvm::Type*>&, llvm::LLVMContext&) 
const = 0;
 
  312    virtual llvm::Function*
 
  313    create(llvm::LLVMContext& C, llvm::Module* M = 
nullptr) 
const;
 
  318    llvm::Function* 
create(llvm::Module& M)
 const {
 
  319        return this->
create(M.getContext(), &M);
 
 
  326    llvm::Function* 
get(
const llvm::Module& M) 
const;
 
  352    call(
const std::vector<llvm::Value*>& args,
 
  353         llvm::IRBuilder<>& B,
 
  354         const bool cast = 
false) 
const;
 
  383    inline size_t size()
 const { 
return mSize; }
 
  387    inline const char* 
symbol()
 const { 
return mSymbol.c_str(); }
 
  394    inline const char* 
argName(
const size_t idx)
 const {
 
  395        return idx < mNames.size() ? mNames[idx] : 
"";
 
 
  409    virtual void print(llvm::LLVMContext& C,
 
  411            const char* name = 
nullptr,
 
  412            const bool axTypes = 
true) 
const;
 
  417            const llvm::Attribute::AttrKind& kind)
 const 
  419        if (!mAttributes) 
return false;
 
  420        const auto iter = mAttributes->mParamAttrs.find(i);
 
  421        if (iter == mAttributes->mParamAttrs.end()) 
return false;
 
  422        const auto& vec = iter->second;
 
  423        return std::find(vec.begin(), vec.end(), kind) != vec.end();
 
 
  433        this->attrs().mFnAttrs = in;
 
 
  437        this->attrs().mRetAttrs = in;
 
 
  440            const std::vector<llvm::Attribute::AttrKind>& in)
 
  442        this->attrs().mParamAttrs[i] = in;
 
 
  454    static void cast(std::vector<llvm::Value*>& args,
 
  455                const std::vector<llvm::Type*>& 
types,
 
  456                llvm::IRBuilder<>& B);
 
  461        std::vector<llvm::Attribute::AttrKind> mFnAttrs, mRetAttrs;
 
  462        std::map<size_t, std::vector<llvm::Attribute::AttrKind>> mParamAttrs;
 
  465    inline Attributes& attrs() {
 
  466        if (!mAttributes) mAttributes.reset(
new Attributes());
 
  470    llvm::AttributeList flattenAttrs(llvm::LLVMContext& C) 
const;
 
  473    const std::string mSymbol;
 
  474    std::unique_ptr<Attributes> mAttributes;
 
  475    std::vector<const char*> mNames;
 
  476    std::vector<const char*> mDeps;
 
 
  493template <
typename SignatureT, 
typename DerivedFunction>
 
  496    using Ptr = std::shared_ptr<SRetFunction<SignatureT, DerivedFunction>>;
 
  500    static_assert(Traits::N_ARGS > 0,
 
  501        "SRET Function object has been setup with the first argument as the return " 
  502        "value, however the provided signature is empty.");
 
  505    static_assert(std::is_same<typename Traits::ReturnType, void>::value,
 
  506        "SRET Function object has been setup with the first argument as the return " 
  507        "value and a non void return type.");
 
  511    using FirstArgument = 
typename Traits::template Arg<0>::Type;
 
  512    static_assert(std::is_pointer<FirstArgument>::value,
 
  513        "SRET Function object has been setup with the first argument as the return " 
  514        "value, but this argument it is not a pointer type.");
 
  515    using SRetType = 
typename std::remove_pointer<FirstArgument>::type;
 
  522            llvm::LLVMContext& C)
 const override 
  525        std::vector<llvm::Type*> inputs(args);
 
  527        std::rotate(inputs.rbegin(), inputs.rbegin() + 1, inputs.rend());
 
  528        return DerivedFunction::match(inputs, C);
 
 
  538    call(
const std::vector<llvm::Value*>& args,
 
  539         llvm::IRBuilder<>& B,
 
  540         const bool cast)
 const override 
  543        std::vector<llvm::Value*> inputs(args);
 
  546        std::rotate(inputs.rbegin(), inputs.rbegin() + 1, inputs.rend());
 
  547        DerivedFunction::call(inputs, B, 
cast);
 
  548        return inputs.front();
 
 
  554           const char* name = 
nullptr,
 
  555           const bool axTypes = 
true)
 const override 
  557        std::vector<llvm::Type*> current;
 
  558        llvm::Type* ret = this->types(current, C);
 
  560        std::rotate(current.begin(), current.begin() + 1, current.end());
 
  561        ret = current.back();
 
  564        std::vector<const char*> names;
 
  565        names.reserve(this->
size());
 
  566        for (
size_t i = 0; i < this->
size()-1; ++i) {
 
  567            names.emplace_back(this->
argName(i));
 
 
  574    template <
typename ...Args>
 
 
  581    using Ptr = std::shared_ptr<CFunctionBase>;
 
  592    inline virtual llvm::Value* 
fold(
const std::vector<llvm::Value*>&,
 
  593            llvm::LLVMContext&)
 const {
 
 
  599        const std::string& 
symbol)
 
  601        , mConstantFold(false) {}
 
 
 
  612template <
typename SignatureT>
 
  616    using Ptr = std::shared_ptr<CFunctionT>;
 
  622    static_assert(std::is_same<typename Traits::ReturnType, void*>::value ||
 
  623        !std::is_pointer<typename Traits::ReturnType>::value,
 
  624        "CFunction object has been setup with a pointer return argument. C bindings " 
  625        "cannot return memory locations to LLVM - Consider using a CFunctionSRet.");
 
  629        , mFunction(function) {}
 
 
  633    inline llvm::Type* 
types(std::vector<llvm::Type*>& 
types, llvm::LLVMContext& C)
 const override 
 
  638    inline uint64_t 
address() const override final {
 
  639        return reinterpret_cast<uint64_t
>(mFunction);
 
 
  643    call(
const std::vector<llvm::Value*>& args,
 
  644         llvm::IRBuilder<>& B,
 
  645         const bool cast)
 const override 
  647        llvm::Value* result = this->
fold(args, B.getContext());
 
  648        if (result) 
return result;
 
 
  652    llvm::Value* 
fold(
const std::vector<llvm::Value*>& args, llvm::LLVMContext& C) 
const override final 
  655            [](
const std::vector<llvm::Value*>& vals) -> 
bool {
 
  656            for (
auto& value : vals) {
 
  657                if (!llvm::isa<llvm::Constant>(value)) 
return false;
 
  663        if (!allconst(args))  
return nullptr;
 
  664        std::vector<llvm::Constant*> constants;
 
  665        constants.reserve(args.size());
 
  666        for (
auto& value : args) {
 
  667            constants.emplace_back(llvm::cast<llvm::Constant>(value));
 
 
  675    SignatureT* mFunction;
 
 
  681    using Ptr = std::shared_ptr<IRFunctionBase>;
 
  693        (
const std::vector<llvm::Value*>&, llvm::IRBuilder<>&)>;
 
  713    create(llvm::LLVMContext& C, llvm::Module* M) 
const override;
 
  720    call(
const std::vector<llvm::Value*>& args,
 
  721         llvm::IRBuilder<>& B,
 
  722         const bool cast) 
const override;
 
  731        if (result == expected) 
return;
 
  732        std::string source, target;
 
  736            "\" has been invoked with a mismatching return type. Expected: \"" +
 
  737            target + 
"\", got \"" + source + 
"\".");
 
 
 
  753template <
typename SignatureT>
 
  757    using Ptr = std::shared_ptr<IRFunction>;
 
  763    types(std::vector<llvm::Type*>& 
types, llvm::LLVMContext& C)
 const override 
 
 
  771template <
typename SignatureT>
 
  782template <
typename SignatureT>
 
  795    using Ptr = std::shared_ptr<FunctionGroup>;
 
  804        , mFunctionList(
list) {}
 
 
  821    match(
const std::vector<llvm::Type*>& types,
 
  822          llvm::LLVMContext& C,
 
  836    execute(
const std::vector<llvm::Value*>& args,
 
  837            llvm::IRBuilder<>& B) 
const;
 
  853    execute(
const std::vector<llvm::Value*>& args,
 
  854            llvm::IRBuilder<>& B,
 
  855            llvm::Value*& result) 
const;
 
  859    const char* 
name()
 const { 
return mName; }
 
  860    const char* 
doc()
 const { 
return mDoc; }
 
  865    const FunctionList mFunctionList;
 
 
  885        using Ptr = std::shared_ptr<Settings>;
 
  889            if (!
mDeps.empty()) 
return false;
 
  891            if (!
mFnAttrs.empty()) 
return false;
 
 
  897        std::shared_ptr<std::vector<const char*>> 
mNames = 
nullptr;
 
  898        std::vector<const char*> 
mDeps = {};
 
  901        std::vector<llvm::Attribute::AttrKind> 
mFnAttrs = {};
 
  903        std::map<size_t, std::vector<llvm::Attribute::AttrKind>> 
mParamAttrs = {};
 
 
  908        , mCurrentSettings(new 
Settings()) {}
 
 
  911    template <
typename Signature, 
bool SRet = false>
 
  914            const char* symbol = 
nullptr)
 
  916        using IRFType = 
typename std::conditional
 
  918        using IRPtr = 
typename IRFType::Ptr;
 
  921        if (!mCurrentSettings->isDefault()) {
 
  926        if (symbol) s = std::string(symbol);
 
  927        else s = this->genSymbol<Signature>();
 
  929        auto ir = IRPtr(
new IRFType(s, cb));
 
  930        mIRFunctions.emplace_back(ir);
 
  931        mSettings[ir.get()] = settings;
 
  932        mCurrentSettings = settings;
 
 
  936    template <
typename Signature, 
bool SRet = false>
 
  939            const char* symbol = 
nullptr)
 
  941        using CFType = 
typename std::conditional
 
  943        using CPtr = 
typename CFType::Ptr;
 
  946        if (!mCurrentSettings->isDefault()) {
 
  951        if (symbol) s = std::string(symbol);
 
  952        else s = this->genSymbol<Signature>();
 
  954        auto c = CPtr(
new CFType(s, ptr));
 
  955        mCFunctions.emplace_back(c);
 
  956        mSettings[c.get()] = settings;
 
  957        mCurrentSettings = settings;
 
 
  961    template <
typename Signature, 
bool SRet = false>
 
  971        mCurrentSettings->mDeps.emplace_back(name); 
return *
this;
 
 
  977        mCurrentSettings->mNames.reset(
new std::vector<const char*>(names));
 
 
 1046        mCurrentSettings->mParamAttrs[idx].emplace_back(attr);
 
 
 1052        mCurrentSettings->mRetAttrs.emplace_back(attr);
 
 
 1058        mCurrentSettings->mFnAttrs.emplace_back(attr);
 
 
 1067        for (
auto& decl : mCFunctions) {
 
 1068            const auto& s = mSettings.at(decl.get());
 
 1069            decl->setDependencies(s->mDeps);
 
 1070            decl->setConstantFold(s->mConstantFold);
 
 1071            if (!s->mFnAttrs.empty())  decl->setFnAttributes(s->mFnAttrs);
 
 1072            if (!s->mRetAttrs.empty()) decl->setRetAttributes(s->mRetAttrs);
 
 1073            if (!s->mParamAttrs.empty()) {
 
 1074                for (
auto& idxAttrs : s->mParamAttrs) {
 
 1075                    if (idxAttrs.first > decl->size()) 
continue;
 
 1076                    decl->setParamAttributes(idxAttrs.first, idxAttrs.second);
 
 1079            if (s->mNames) decl->setArgumentNames(*s->mNames);
 
 1082        for (
auto& decl : mIRFunctions) {
 
 1083            const auto& s = mSettings.at(decl.get());
 
 1084            decl->setDependencies(s->mDeps);
 
 1085            decl->setEmbedIR(s->mEmbedIR);
 
 1086            if (!s->mFnAttrs.empty())  decl->setFnAttributes(s->mFnAttrs);
 
 1087            if (!s->mRetAttrs.empty()) decl->setRetAttributes(s->mRetAttrs);
 
 1088            if (!s->mParamAttrs.empty()) {
 
 1089                for (
auto& idxAttrs : s->mParamAttrs) {
 
 1090                    if (idxAttrs.first > decl->size()) 
continue;
 
 1091                    decl->setParamAttributes(idxAttrs.first, idxAttrs.second);
 
 1094            if (s->mNames) decl->setArgumentNames(*s->mNames);
 
 1097        std::vector<Function::Ptr> functions;
 
 1100            functions.insert(functions.end(), mIRFunctions.begin(), mIRFunctions.end());
 
 1103            functions.insert(functions.end(), mCFunctions.begin(), mCFunctions.end());
 
 1105        if (functions.empty()) {
 
 1106            functions.insert(functions.end(), mIRFunctions.begin(), mIRFunctions.end());
 
 1107            functions.insert(functions.end(), mCFunctions.begin(), mCFunctions.end());
 
 
 1116    template <
typename Signature>
 
 1117    std::string genSymbol()
 const 
 1122        auto callback = [&args](
auto type) {
 
 1123            using Type = 
decltype(type);
 
 1127        ArgumentIterator<Signature>::apply(callback, 
true);
 
 1133        return "ax." + std::string(this->mName) + 
"." +
 
 1134            TypeToSymbol<typename Traits::ReturnType>::s() + args;
 
 1137    const char* mName = 
"";
 
 1138    const char* mDoc = 
"";
 
 1139    DeclPreferrence mDeclPref = IR;
 
 1140    std::vector<CFunctionBase::Ptr> mCFunctions = {};
 
 1141    std::vector<IRFunctionBase::Ptr> mIRFunctions = {};
 
 1142    std::map<const Function*, Settings::Ptr> mSettings = {};
 
 1143    Settings::Ptr mCurrentSettings = 
nullptr;
 
 
#define OPENVDB_ASSERT(X)
Definition Assert.h:41
Constant folding for C++ bindings.
Consolidated llvm types for most supported types.
Definition Exceptions.h:38
ArgType< float, 16 > M4F
Definition FunctionTypes.h:125
llvm::Type * llvmTypesFromSignature(llvm::LLVMContext &C, std::vector< llvm::Type * > *types=nullptr)
Populate a vector of llvm types from a function signature declaration.
Definition FunctionTypes.h:209
ArgType< double, 2 > V2D
Definition FunctionTypes.h:113
ArgType< int32_t, 4 > V4I
Definition FunctionTypes.h:121
ArgType< float, 3 > V3F
Definition FunctionTypes.h:117
llvm::Value * insertStaticAlloca(llvm::IRBuilder<> &B, llvm::Type *type, llvm::Value *size=nullptr)
Insert a stack allocation at the beginning of the current function of the provided type and size....
Definition Utils.h:187
void llvmTypeToString(const llvm::Type *const type, std::string &str)
Prints an llvm type to a std string.
Definition Utils.h:134
ArgType< double, 9 > M3D
Definition FunctionTypes.h:122
OPENVDB_AX_API void printSignature(std::ostream &os, const std::vector< llvm::Type * > &types, const llvm::Type *returnType, const char *name=nullptr, const std::vector< const char * > &names={}, const bool axTypes=false)
Print a function signature to the provided ostream.
ArgType< double, 16 > M4D
Definition FunctionTypes.h:124
ArgType< float, 4 > V4F
Definition FunctionTypes.h:120
ArgType< int32_t, 3 > V3I
Definition FunctionTypes.h:118
llvm::FunctionType * llvmFunctionTypeFromSignature(llvm::LLVMContext &C)
Generate an LLVM FunctionType from a function signature.
Definition FunctionTypes.h:233
ArgType< double, 4 > V4D
Definition FunctionTypes.h:119
ArgType< float, 9 > M3F
Definition FunctionTypes.h:123
ArgType< int32_t, 2 > V2I
Definition FunctionTypes.h:115
ArgType< float, 2 > V2F
Definition FunctionTypes.h:114
ArgType< double, 3 > V3D
Definition FunctionTypes.h:116
Definition OpenSimplexNoise.h:31
Definition Exceptions.h:13
#define OPENVDB_THROW(exception, message)
Definition Exceptions.h:74
Utility code generation methods for performing various llvm operations.
Alias mapping between two types, a frontend type T1 and a backend type T2. This class is the intended...
Definition Types.h:240
Object to array conversion methods to allow functions to return vector types. These containers provid...
Definition FunctionTypes.h:103
T Type
Definition FunctionTypes.h:104
static const size_t SIZE
Definition FunctionTypes.h:105
ArrayType mData
Definition FunctionTypes.h:107
Type[SIZE] ArrayType
Definition FunctionTypes.h:106
static void apply(const OpT &, const bool)
Definition FunctionTypes.h:196
Templated argument iterator which implements various small functions per argument type,...
Definition FunctionTypes.h:175
static void apply(const OpT &op, const bool forwards)
Definition FunctionTypes.h:180
typename FunctionTraits< SignatureT >::template Arg< I-1 > ArgT
Definition FunctionTypes.h:176
typename ArgT::Type ArgumentValueType
Definition FunctionTypes.h:177
bool hasConstantFold() const
Definition FunctionTypes.h:590
void setConstantFold(bool on)
Definition FunctionTypes.h:589
virtual llvm::Value * fold(const std::vector< llvm::Value * > &, llvm::LLVMContext &) const
Definition FunctionTypes.h:592
virtual uint64_t address() const =0
Returns the global address of this function.
CFunctionBase(const size_t size, const std::string &symbol)
Definition FunctionTypes.h:598
~CFunctionBase() override=default
std::shared_ptr< CFunctionBase > Ptr
Definition FunctionTypes.h:581
Represents a concrete C function binding with the first argument as its return type.
Definition FunctionTypes.h:773
CFunctionSRet(const std::string &symbol, const SignatureT function)
Definition FunctionTypes.h:775
SRetFunction< SignatureT, CFunction< SignatureT > > BaseT
Definition FunctionTypes.h:774
~CFunctionSRet() override=default
Represents a concrete C function binding.
Definition FunctionTypes.h:614
std::shared_ptr< CFunctionT > Ptr
Definition FunctionTypes.h:616
uint64_t address() const override final
Returns the global address of this function.
Definition FunctionTypes.h:638
FunctionTraits< SignatureT > Traits
Definition FunctionTypes.h:617
llvm::Value * call(const std::vector< llvm::Value * > &args, llvm::IRBuilder<> &B, const bool cast) const override
Uses the IRBuilder to create a call to this function with the given arguments, creating the function ...
Definition FunctionTypes.h:643
llvm::Type * types(std::vector< llvm::Type * > &types, llvm::LLVMContext &C) const override
Populate a vector of llvm::Types which describe this function signature. This method is used by Funct...
Definition FunctionTypes.h:633
~CFunction() override=default
llvm::Value * fold(const std::vector< llvm::Value * > &args, llvm::LLVMContext &C) const override final
Definition FunctionTypes.h:652
CFunction(const std::string &symbol, SignatureT *function)
Definition FunctionTypes.h:627
CFunction< SignatureT > CFunctionT
Definition FunctionTypes.h:615
static llvm::Value * fold(const std::vector< llvm::Constant * > &args, const SignatureT &function, llvm::LLVMContext &C, Tys &&... ts)
Definition ConstantFolding.h:56
Definition FunctionTypes.h:884
std::shared_ptr< std::vector< const char * > > mNames
Definition FunctionTypes.h:897
std::shared_ptr< Settings > Ptr
Definition FunctionTypes.h:885
bool isDefault() const
Definition FunctionTypes.h:887
std::vector< llvm::Attribute::AttrKind > mFnAttrs
Definition FunctionTypes.h:901
std::map< size_t, std::vector< llvm::Attribute::AttrKind > > mParamAttrs
Definition FunctionTypes.h:903
std::vector< llvm::Attribute::AttrKind > mRetAttrs
Definition FunctionTypes.h:902
bool mEmbedIR
Definition FunctionTypes.h:900
bool mConstantFold
Definition FunctionTypes.h:899
std::vector< const char * > mDeps
Definition FunctionTypes.h:898
The FunctionBuilder class provides a builder pattern framework to allow easy and valid construction o...
Definition FunctionTypes.h:878
FunctionGroup::UniquePtr get() const
Definition FunctionTypes.h:1065
FunctionBuilder & addFunctionAttribute(const llvm::Attribute::AttrKind attr)
Definition FunctionTypes.h:1057
FunctionBuilder & addSignature(const IRFunctionBase::GeneratorCb &cb, const Signature *ptr, const char *symbol=nullptr)
Definition FunctionTypes.h:963
FunctionBuilder & addSignature(const IRFunctionBase::GeneratorCb &cb, const char *symbol=nullptr)
Definition FunctionTypes.h:913
FunctionBuilder & addParameterAttribute(const size_t idx, const llvm::Attribute::AttrKind attr)
Definition FunctionTypes.h:1045
FunctionBuilder & setPreferredImpl(DeclPreferrence pref)
Definition FunctionTypes.h:1063
DeclPreferrence
Definition FunctionTypes.h:879
@ IR
Definition FunctionTypes.h:880
@ C
Definition FunctionTypes.h:880
@ Any
Definition FunctionTypes.h:880
FunctionBuilder & addDependency(const char *name)
Definition FunctionTypes.h:970
FunctionBuilder & setConstantFold(bool on)
Definition FunctionTypes.h:975
FunctionBuilder & addSignature(const Signature *ptr, const char *symbol=nullptr)
Definition FunctionTypes.h:938
FunctionBuilder(const char *name)
Definition FunctionTypes.h:906
FunctionBuilder & addReturnAttribute(const llvm::Attribute::AttrKind attr)
Definition FunctionTypes.h:1051
FunctionBuilder & setArgumentNames(const std::vector< const char * > &names)
Definition FunctionTypes.h:976
FunctionBuilder & setDocumentation(const char *doc)
Definition FunctionTypes.h:1062
FunctionBuilder & setEmbedIR(bool on)
Definition FunctionTypes.h:974
todo
Definition FunctionTypes.h:794
std::vector< Function::Ptr > FunctionList
Definition FunctionTypes.h:797
std::shared_ptr< FunctionGroup > Ptr
Definition FunctionTypes.h:795
std::unique_ptr< FunctionGroup > UniquePtr
Definition FunctionTypes.h:796
const Function * match(const std::vector< llvm::Type * > &types, llvm::LLVMContext &C, Function::SignatureMatch *type=nullptr) const
Given a vector of llvm types, automatically returns the best possible function declaration from the s...
const char * name() const
Definition FunctionTypes.h:859
llvm::Value * execute(const std::vector< llvm::Value * > &args, llvm::IRBuilder<> &B) const
Given a vector of llvm values, find the best possible function signature, generate and execute the fu...
const char * doc() const
Definition FunctionTypes.h:860
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 fu...
const FunctionList & list() const
Accessor to the underlying function signature list.
Definition FunctionTypes.h:858
FunctionGroup(const char *name, const char *doc, const FunctionList &list)
Definition FunctionTypes.h:799
Templated function traits which provides compile-time index access to the types of the function signa...
Definition Types.h:280
The base/abstract representation of an AX function. Derived classes must implement the Function::type...
Definition FunctionTypes.h:268
const std::vector< const char * > & dependencies() const
Definition FunctionTypes.h:428
const char * argName(const size_t idx) const
Returns the descriptive name of the given argument index.
Definition FunctionTypes.h:394
virtual void print(llvm::LLVMContext &C, std::ostream &os, const char *name=nullptr, const bool axTypes=true) const
Print this function's signature to the provided ostream.
void setDependencies(std::vector< const char * > deps)
Definition FunctionTypes.h:429
size_t size() const
The number of arguments that this function has.
Definition FunctionTypes.h:383
virtual llvm::Function * create(llvm::LLVMContext &C, llvm::Module *M=nullptr) const
Converts and creates this AX function into a llvm Function.
void setParamAttributes(const size_t i, const std::vector< llvm::Attribute::AttrKind > &in)
Definition FunctionTypes.h:439
static void cast(std::vector< llvm::Value * > &args, const std::vector< llvm::Type * > &types, llvm::IRBuilder<> &B)
Cast the provided arguments to the given type as supported by implicit casting of function types....
Function(const size_t size, const std::string &symbol)
Definition FunctionTypes.h:271
void setRetAttributes(const std::vector< llvm::Attribute::AttrKind > &in)
Definition FunctionTypes.h:435
llvm::Function * create(llvm::Module &M) const
Convenience method which always uses the provided module to find the function or insert it if necessa...
Definition FunctionTypes.h:318
void setFnAttributes(const std::vector< llvm::Attribute::AttrKind > &in)
Definition FunctionTypes.h:431
std::shared_ptr< Function > Ptr
Definition FunctionTypes.h:269
virtual llvm::Value * call(const std::vector< llvm::Value * > &args, llvm::IRBuilder<> &B, const bool cast=false) const
Uses the IRBuilder to create a call to this function with the given arguments, creating the function ...
bool hasParamAttribute(const size_t i, const llvm::Attribute::AttrKind &kind) const
Builder methods.
Definition FunctionTypes.h:416
virtual SignatureMatch match(const std::vector< llvm::Type * > &inputs, llvm::LLVMContext &C) const
The base implementation for determining how a vector of llvm arguments translates to this functions s...
const char * symbol() const
The function symbol name.
Definition FunctionTypes.h:387
virtual ~Function()=default
virtual llvm::Type * types(std::vector< llvm::Type * > &, llvm::LLVMContext &) const =0
Populate a vector of llvm::Types which describe this function signature. This method is used by Funct...
llvm::Function * get(const llvm::Module &M) const
Convenience method for calling M.getFunction(symbol). Returns a nullptr if the function has not yet b...
SignatureMatch
The result type from calls to Function::match.
Definition FunctionTypes.h:357
@ Implicit
Definition FunctionTypes.h:357
@ None
Definition FunctionTypes.h:357
@ Explicit
Definition FunctionTypes.h:357
@ Size
Definition FunctionTypes.h:357
void setArgumentNames(std::vector< const char * > names)
Definition FunctionTypes.h:426
std::function< llvm::Value *(const std::vector< llvm::Value * > &, llvm::IRBuilder<> &)> GeneratorCb
The IR callback function which will write the LLVM IR for this function's body.
Definition FunctionTypes.h:692
bool hasEmbedIR() const
Definition FunctionTypes.h:698
void setEmbedIR(bool on)
Enable or disable the embedding of IR. Embedded IR is currently required for function which use paren...
Definition FunctionTypes.h:697
llvm::Value * call(const std::vector< llvm::Value * > &args, llvm::IRBuilder<> &B, const bool cast) const override
Override for call, which is only necessary if mEmbedIR is true, as the IR generation for embedded fun...
std::shared_ptr< IRFunctionBase > Ptr
Definition FunctionTypes.h:681
llvm::Function * create(llvm::LLVMContext &C, llvm::Module *M) const override
Override for the creation of an IR function. This ensures that the body and prototype of the function...
const GeneratorCb mGen
Definition FunctionTypes.h:748
bool mEmbedIR
Definition FunctionTypes.h:749
IRFunctionBase(const std::string &symbol, const GeneratorCb &gen, const size_t size)
Definition FunctionTypes.h:740
void verifyResultType(const llvm::Type *result, const llvm::Type *expected) const
Definition FunctionTypes.h:729
~IRFunctionBase() override=default
Represents a concrete IR function with the first argument as its return type.
Definition FunctionTypes.h:784
IRFunctionSRet(const std::string &symbol, const IRFunctionBase::GeneratorCb &gen)
Definition FunctionTypes.h:786
SRetFunction< SignatureT, IRFunction< SignatureT > > BaseT
Definition FunctionTypes.h:785
~IRFunctionSRet() override=default
Represents a concrete IR function.
Definition FunctionTypes.h:755
FunctionTraits< SignatureT > Traits
Definition FunctionTypes.h:756
llvm::Type * types(std::vector< llvm::Type * > &types, llvm::LLVMContext &C) const override
Populate a vector of llvm::Types which describe this function signature. This method is used by Funct...
Definition FunctionTypes.h:763
IRFunction(const std::string &symbol, const GeneratorCb &gen)
Definition FunctionTypes.h:759
std::shared_ptr< IRFunction > Ptr
Definition FunctionTypes.h:757
LLVM type mapping from pod types.
Definition Types.h:56
static llvm::Type * get(llvm::LLVMContext &C)
Return an LLVM type which represents T.
Definition Types.h:67
void print(llvm::LLVMContext &C, std::ostream &os, const char *name=nullptr, const bool axTypes=true) const override
Override of print to avoid printing out the SRET type.
Definition FunctionTypes.h:552
std::shared_ptr< SRetFunction< SignatureT, DerivedFunction > > Ptr
Definition FunctionTypes.h:496
FunctionTraits< SignatureT > Traits
Definition FunctionTypes.h:497
llvm::Value * call(const std::vector< llvm::Value * > &args, llvm::IRBuilder<> &B, const bool cast) const override
Override of call which allocates the required SRET llvm::Value for this function.
Definition FunctionTypes.h:538
SRetFunction(Args &&... ts)
Forward all arguments to the derived class.
Definition FunctionTypes.h:575
Function::SignatureMatch match(const std::vector< llvm::Type * > &args, llvm::LLVMContext &C) const override
Override of match which inserts the SRET type such that the base class methods ignore it.
Definition FunctionTypes.h:521
An extremely basic but native representation of a string class with SSO support. This exists to provi...
Definition String.h:34
static std::string s()
Definition FunctionTypes.h:150
static std::string s()
Definition FunctionTypes.h:155
static std::string s()
Definition FunctionTypes.h:135
static std::string s()
Definition FunctionTypes.h:146
static std::string s()
Definition FunctionTypes.h:145
static std::string s()
Definition FunctionTypes.h:144
static std::string s()
Definition FunctionTypes.h:141
static std::string s()
Definition FunctionTypes.h:142
static std::string s()
Definition FunctionTypes.h:143
static std::string s()
Definition FunctionTypes.h:140
static std::string s()
Definition FunctionTypes.h:137
static std::string s()
Definition FunctionTypes.h:138
static std::string s()
Definition FunctionTypes.h:139
static std::string s()
Definition FunctionTypes.h:136
static std::string s()
Definition FunctionTypes.h:134
Type to symbol conversions - these characters are used to build each functions unique signature....
Definition FunctionTypes.h:133
static std::string s()
Definition FunctionTypes.h:133
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition version.h.in:121
#define OPENVDB_USE_VERSION_NAMESPACE
Definition version.h.in:218