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>
75#include <llvm/IR/Constants.h>
76#include <llvm/IR/IRBuilder.h>
77#include <llvm/IR/Module.h>
84#include <unordered_map>
101template <
typename T,
size_t _SIZE = 1>
104 static const size_t SIZE = _SIZE;
109template <
typename T,
size_t S>
132template <
typename T>
struct TypeToSymbol {
static inline std::string
s() {
return "?"; } };
133template <>
struct TypeToSymbol<void> {
static inline std::string
s() {
return "v"; } };
134template <>
struct TypeToSymbol<char> {
static inline std::string
s() {
return "c"; } };
135template <>
struct TypeToSymbol<int16_t> {
static inline std::string
s() {
return "s"; } };
136template <>
struct TypeToSymbol<int32_t> {
static inline std::string
s() {
return "i"; } };
137template <>
struct TypeToSymbol<int64_t> {
static inline std::string
s() {
return "l"; } };
138template <>
struct TypeToSymbol<float> {
static inline std::string
s() {
return "f"; } };
139template <>
struct TypeToSymbol<double> {
static inline std::string
s() {
return "d"; } };
147template <
typename T,
size_t S>
167template <typename SignatureT, size_t I = FunctionTraits<SignatureT>::N_ARGS>
173 template <
typename OpT>
174 static void apply(
const OpT& op,
const bool forwards) {
186template <
typename SignatureT>
189 template <
typename OpT>
190 static void apply(
const OpT&,
const bool) {}
201template <
typename SignatureT>
204 std::vector<llvm::Type*>* types =
nullptr)
207 using ArgumentIteratorT =
211 types->reserve(Traits::N_ARGS);
212 auto callback = [&types, &C](
auto type) {
213 using Type =
decltype(type);
216 ArgumentIteratorT::apply(callback,
true);
225template <
typename SignatureT>
226inline llvm::FunctionType*
229 std::vector<llvm::Type*> types;
230 llvm::Type* returnType =
231 llvmTypesFromSignature<SignatureT>(C, &types);
232 return llvm::FunctionType::get(returnType,
233 llvm::ArrayRef<llvm::Type*>(types),
250 const std::vector<llvm::Type*>& types,
251 const llvm::Type* returnType,
252 const char* name =
nullptr,
253 const std::vector<const char*>& names = {},
254 const bool axTypes =
false);
263 using Ptr = std::shared_ptr<Function>;
265 Function(
const size_t size,
const std::string& symbol)
268 , mAttributes(nullptr)
272 assert(!symbol.empty());
280 virtual llvm::Type*
types(std::vector<llvm::Type*>&, llvm::LLVMContext&)
const = 0;
306 virtual llvm::Function*
307 create(llvm::LLVMContext& C, llvm::Module* M =
nullptr)
const;
312 llvm::Function*
create(llvm::Module& M)
const {
313 return this->create(M.getContext(), &M);
320 llvm::Function*
get(
const llvm::Module& M)
const;
346 call(
const std::vector<llvm::Value*>& args,
347 llvm::IRBuilder<>& B,
348 const bool cast =
false)
const;
377 inline size_t size()
const {
return mSize; }
381 inline const char*
symbol()
const {
return mSymbol.c_str(); }
388 inline const char*
argName(
const size_t idx)
const {
389 return idx < mNames.size() ? mNames[idx] :
"";
403 virtual void print(llvm::LLVMContext& C,
405 const char* name =
nullptr,
406 const bool axTypes =
true)
const;
411 const llvm::Attribute::AttrKind& kind)
const
413 if (!mAttributes)
return false;
414 const auto iter = mAttributes->mParamAttrs.find(i);
415 if (iter == mAttributes->mParamAttrs.end())
return false;
416 const auto& vec = iter->second;
417 return std::find(vec.begin(), vec.end(), kind) != vec.end();
427 this->attrs().mFnAttrs = in;
431 this->attrs().mRetAttrs = in;
434 const std::vector<llvm::Attribute::AttrKind>& in)
436 this->attrs().mParamAttrs[i] = in;
448 static void cast(std::vector<llvm::Value*>& args,
449 const std::vector<llvm::Type*>& types,
450 llvm::IRBuilder<>& B);
455 std::vector<llvm::Attribute::AttrKind> mFnAttrs, mRetAttrs;
456 std::map<size_t, std::vector<llvm::Attribute::AttrKind>> mParamAttrs;
459 inline Attributes& attrs() {
460 if (!mAttributes) mAttributes.reset(
new Attributes());
464 llvm::AttributeList flattenAttrs(llvm::LLVMContext& C)
const;
467 const std::string mSymbol;
468 std::unique_ptr<Attributes> mAttributes;
469 std::vector<const char*> mNames;
470 std::vector<const char*> mDeps;
487template <
typename SignatureT,
typename DerivedFunction>
490 using Ptr = std::shared_ptr<SRetFunction<SignatureT, DerivedFunction>>;
494 static_assert(Traits::N_ARGS > 0,
495 "SRET Function object has been setup with the first argument as the return "
496 "value, however the provided signature is empty.");
500 "SRET Function object has been setup with the first argument as the return "
501 "value and a non void return type.");
505 using FirstArgument =
typename Traits::template Arg<0>::Type;
507 "SRET Function object has been setup with the first argument as the return "
508 "value, but this argument it is not a pointer type.");
509 using SRetType =
typename std::remove_pointer<FirstArgument>::type;
516 llvm::LLVMContext& C)
const override
519 std::vector<llvm::Type*> inputs(args);
521 std::rotate(inputs.rbegin(), inputs.rbegin() + 1, inputs.rend());
522 return DerivedFunction::match(inputs, C);
532 call(
const std::vector<llvm::Value*>& args,
533 llvm::IRBuilder<>& B,
534 const bool cast)
const override
537 std::vector<llvm::Value*> inputs(args);
540 std::rotate(inputs.rbegin(), inputs.rbegin() + 1, inputs.rend());
541 DerivedFunction::call(inputs, B, cast);
542 return inputs.front();
548 const char* name =
nullptr,
549 const bool axTypes =
true)
const override
551 std::vector<llvm::Type*> current;
552 llvm::Type* ret = this->types(current, C);
554 std::rotate(current.begin(), current.begin() + 1, current.end());
555 ret = current.back();
558 std::vector<const char*> names;
559 names.reserve(this->size());
560 for (
size_t i = 0; i < this->size()-1; ++i) {
561 names.emplace_back(this->argName(i));
568 template <
typename ...Args>
575 using Ptr = std::shared_ptr<CFunctionBase>;
586 inline virtual llvm::Value*
fold(
const std::vector<llvm::Value*>&,
587 llvm::LLVMContext&)
const {
593 const std::string& symbol)
595 , mConstantFold(false) {}
606template <
typename SignatureT>
610 using Ptr = std::shared_ptr<CFunctionT>;
618 "CFunction object has been setup with a pointer return argument. C bindings "
619 "cannot return memory locations to LLVM - Consider using a CFunctionSRet.");
621 CFunction(
const std::string& symbol,
const SignatureT
function)
623 , mFunction(function) {}
627 inline llvm::Type*
types(std::vector<llvm::Type*>& types, llvm::LLVMContext& C)
const override
629 return llvmTypesFromSignature<SignatureT>(C, &types);
632 inline uint64_t
address() const override final {
633 return reinterpret_cast<uint64_t
>(mFunction);
637 call(
const std::vector<llvm::Value*>& args,
638 llvm::IRBuilder<>& B,
639 const bool cast)
const override
641 llvm::Value* result = this->fold(args, B.getContext());
642 if (result)
return result;
643 return Function::call(args, B, cast);
646 llvm::Value*
fold(
const std::vector<llvm::Value*>& args, llvm::LLVMContext& C)
const override final
649 [](
const std::vector<llvm::Value*>& vals) ->
bool {
650 for (
auto&
value : vals) {
651 if (!llvm::isa<llvm::Constant>(
value))
return false;
656 if (!this->hasConstantFold())
return nullptr;
657 if (!allconst(args))
return nullptr;
658 std::vector<llvm::Constant*> constants;
659 constants.reserve(args.size());
660 for (
auto&
value : args) {
661 constants.emplace_back(llvm::cast<llvm::Constant>(
value));
669 const SignatureT* mFunction;
675 using Ptr = std::shared_ptr<IRFunctionBase>;
687 (
const std::vector<llvm::Value*>&, llvm::IRBuilder<>&)>;
689 llvm::Type*
types(std::vector<llvm::Type*>& types,
690 llvm::LLVMContext& C)
const override = 0;
710 create(llvm::LLVMContext& C, llvm::Module* M)
const override;
717 call(
const std::vector<llvm::Value*>& args,
718 llvm::IRBuilder<>& B,
719 const bool cast)
const override;
728 if (result == expected)
return;
729 std::string source, target;
733 "\" has been invoked with a mismatching return type. Expected: \"" +
734 target +
"\", got \"" + source +
"\".");
750template <
typename SignatureT>
754 using Ptr = std::shared_ptr<IRFunction>;
760 types(std::vector<llvm::Type*>& types, llvm::LLVMContext& C)
const override
762 return llvmTypesFromSignature<SignatureT>(C, &types);
768template <
typename SignatureT>
773 :
BaseT(symbol, function) {}
779template <
typename SignatureT>
785 :
BaseT(symbol, gen) {}
792 using Ptr = std::shared_ptr<FunctionGroup>;
801 , mFunctionList(list) {}
818 match(
const std::vector<llvm::Type*>& types,
819 llvm::LLVMContext& C,
833 execute(
const std::vector<llvm::Value*>& args,
834 llvm::IRBuilder<>& B)
const;
850 execute(
const std::vector<llvm::Value*>& args,
851 llvm::IRBuilder<>& B,
852 llvm::Value*& result)
const;
856 const char*
name()
const {
return mName; }
857 const char*
doc()
const {
return mDoc; }
862 const FunctionList mFunctionList;
882 using Ptr = std::shared_ptr<Settings>;
885 if (mNames)
return false;
886 if (!mDeps.empty())
return false;
887 if (mConstantFold || mEmbedIR)
return false;
888 if (!mFnAttrs.empty())
return false;
889 if (!mRetAttrs.empty())
return false;
890 if (!mParamAttrs.empty())
return false;
894 std::shared_ptr<std::vector<const char*>> mNames =
nullptr;
895 std::vector<const char*> mDeps = {};
896 bool mConstantFold =
false;
897 bool mEmbedIR =
false;
898 std::vector<llvm::Attribute::AttrKind> mFnAttrs = {};
899 std::vector<llvm::Attribute::AttrKind> mRetAttrs = {};
900 std::map<size_t, std::vector<llvm::Attribute::AttrKind>> mParamAttrs = {};
905 , mCurrentSettings(new
Settings()) {}
908 template <
typename Signature,
bool SRet = false>
911 const char* symbol =
nullptr)
913 using IRFType =
typename std::conditional
915 using IRPtr =
typename IRFType::Ptr;
918 if (!mCurrentSettings->isDefault()) {
923 if (symbol) s = std::string(symbol);
924 else s = this->genSymbol<Signature>();
926 auto ir = IRPtr(
new IRFType(s, cb));
927 mIRFunctions.emplace_back(ir);
928 mSettings[ir.get()] = settings;
929 mCurrentSettings = settings;
933 template <
typename Signature,
bool SRet = false>
936 const char* symbol =
nullptr)
938 using CFType =
typename std::conditional
940 using CPtr =
typename CFType::Ptr;
943 if (!mCurrentSettings->isDefault()) {
948 if (symbol) s = std::string(symbol);
949 else s = this->genSymbol<Signature>();
951 auto c = CPtr(
new CFType(s, ptr));
952 mCFunctions.emplace_back(c);
953 mSettings[c.get()] = settings;
954 mCurrentSettings = settings;
958 template <
typename Signature,
bool SRet = false>
962 this->addSignature<Signature, SRet>(cb, symbol);
963 this->addSignature<Signature, SRet>(ptr, symbol);
968 mCurrentSettings->mDeps.emplace_back(name);
return *
this;
974 mCurrentSettings->mNames.reset(
new std::vector<const char*>(names));
1043 mCurrentSettings->mParamAttrs[idx].emplace_back(attr);
1049 mCurrentSettings->mRetAttrs.emplace_back(attr);
1055 mCurrentSettings->mFnAttrs.emplace_back(attr);
1064 for (
auto& decl : mCFunctions) {
1065 const auto& s = mSettings.at(decl.get());
1066 decl->setDependencies(s->mDeps);
1067 decl->setConstantFold(s->mConstantFold);
1068 if (!s->mFnAttrs.empty()) decl->setFnAttributes(s->mFnAttrs);
1069 if (!s->mRetAttrs.empty()) decl->setRetAttributes(s->mRetAttrs);
1070 if (!s->mParamAttrs.empty()) {
1071 for (
auto& idxAttrs : s->mParamAttrs) {
1072 if (idxAttrs.first > decl->size())
continue;
1073 decl->setParamAttributes(idxAttrs.first, idxAttrs.second);
1076 if (s->mNames) decl->setArgumentNames(*s->mNames);
1079 for (
auto& decl : mIRFunctions) {
1080 const auto& s = mSettings.at(decl.get());
1081 decl->setDependencies(s->mDeps);
1082 decl->setEmbedIR(s->mEmbedIR);
1083 if (!s->mFnAttrs.empty()) decl->setFnAttributes(s->mFnAttrs);
1084 if (!s->mRetAttrs.empty()) decl->setRetAttributes(s->mRetAttrs);
1085 if (!s->mParamAttrs.empty()) {
1086 for (
auto& idxAttrs : s->mParamAttrs) {
1087 if (idxAttrs.first > decl->size())
continue;
1088 decl->setParamAttributes(idxAttrs.first, idxAttrs.second);
1091 if (s->mNames) decl->setArgumentNames(*s->mNames);
1094 std::vector<Function::Ptr> functions;
1096 if (mDeclPref == DeclPreferrence::IR) {
1097 functions.insert(functions.end(), mIRFunctions.begin(), mIRFunctions.end());
1099 if (mDeclPref == DeclPreferrence::C) {
1100 functions.insert(functions.end(), mCFunctions.begin(), mCFunctions.end());
1102 if (functions.empty()) {
1103 functions.insert(functions.end(), mIRFunctions.begin(), mIRFunctions.end());
1104 functions.insert(functions.end(), mCFunctions.begin(), mCFunctions.end());
1113 template <
typename Signature>
1114 std::string genSymbol()
const
1119 auto callback = [&args](
auto type) {
1120 using Type =
decltype(type);
1124 ArgumentIterator<Signature>::apply(callback,
true);
1130 return "ax." + std::string(this->mName) +
"." +
1131 TypeToSymbol<typename Traits::ReturnType>::s() + args;
1134 const char* mName =
"";
1135 const char* mDoc =
"";
1136 DeclPreferrence mDeclPref = IR;
1137 std::vector<CFunctionBase::Ptr> mCFunctions = {};
1138 std::vector<IRFunctionBase::Ptr> mIRFunctions = {};
1139 std::map<const Function*, Settings::Ptr> mSettings = {};
1140 Settings::Ptr mCurrentSettings =
nullptr;
Constant folding for C++ bindings.
ValueT value
Definition: GridBuilder.h:1287
Consolidated llvm types for most supported types.
Definition: Exceptions.h:36
3x3 matrix class.
Definition: Mat3.h:29
4x4 -matrix class.
Definition: Mat4.h:24
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:123
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.
llvm::FunctionType * llvmFunctionTypeFromSignature(llvm::LLVMContext &C)
Generate an LLVM FunctionType from a function signature.
Definition: FunctionTypes.h:227
void llvmTypeToString(const llvm::Type *const type, std::string &str)
Prints an llvm type to a std string.
Definition: Utils.h:70
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:203
Definition: Exceptions.h:13
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:74
Utility classes and functions for OpenVDB plugins.
Alias mapping between two types, a frontend type T1 and a backend type T2. This class is the intended...
Definition: Types.h:219
Object to array conversion methods to allow functions to return vector types. These containers provid...
Definition: FunctionTypes.h:102
T Type
Definition: FunctionTypes.h:103
ArrayType mData
Definition: FunctionTypes.h:106
Type[SIZE] ArrayType
Definition: FunctionTypes.h:105
static void apply(const OpT &, const bool)
Definition: FunctionTypes.h:190
Templated argument iterator which implements various small functions per argument type,...
Definition: FunctionTypes.h:169
static void apply(const OpT &op, const bool forwards)
Definition: FunctionTypes.h:174
typename FunctionTraits< SignatureT >::template Arg< I-1 > ArgT
Definition: FunctionTypes.h:170
typename ArgT::Type ArgumentValueType
Definition: FunctionTypes.h:171
The base class for all C bindings.
Definition: FunctionTypes.h:574
bool hasConstantFold() const
Definition: FunctionTypes.h:584
void setConstantFold(bool on)
Definition: FunctionTypes.h:583
virtual llvm::Value * fold(const std::vector< llvm::Value * > &, llvm::LLVMContext &) const
Definition: FunctionTypes.h:586
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:592
~CFunctionBase() override=default
Represents a concrete C function binding with the first argument as its return type.
Definition: FunctionTypes.h:770
CFunctionSRet(const std::string &symbol, const SignatureT function)
Definition: FunctionTypes.h:772
~CFunctionSRet() override=default
Represents a concrete C function binding.
Definition: FunctionTypes.h:608
uint64_t address() const override final
Returns the global address of this function.
Definition: FunctionTypes.h:632
CFunction(const std::string &symbol, const SignatureT function)
Definition: FunctionTypes.h:621
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:637
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:627
~CFunction() override=default
llvm::Value * fold(const std::vector< llvm::Value * > &args, llvm::LLVMContext &C) const override final
Definition: FunctionTypes.h:646
Constant folding support structure.
Definition: ConstantFolding.h:35
Definition: FunctionTypes.h:881
std::shared_ptr< Settings > Ptr
Definition: FunctionTypes.h:882
bool isDefault() const
Definition: FunctionTypes.h:884
The FunctionBuilder class provides a builder pattern framework to allow easy and valid construction o...
Definition: FunctionTypes.h:875
FunctionGroup::UniquePtr get() const
Definition: FunctionTypes.h:1062
FunctionBuilder & addFunctionAttribute(const llvm::Attribute::AttrKind attr)
Definition: FunctionTypes.h:1054
FunctionBuilder & addSignature(const IRFunctionBase::GeneratorCb &cb, const Signature *ptr, const char *symbol=nullptr)
Definition: FunctionTypes.h:960
FunctionBuilder & addSignature(const IRFunctionBase::GeneratorCb &cb, const char *symbol=nullptr)
Definition: FunctionTypes.h:910
FunctionBuilder & addParameterAttribute(const size_t idx, const llvm::Attribute::AttrKind attr)
Definition: FunctionTypes.h:1042
FunctionBuilder & setPreferredImpl(DeclPreferrence pref)
Definition: FunctionTypes.h:1060
DeclPreferrence
Definition: FunctionTypes.h:876
@ C
Definition: FunctionTypes.h:877
FunctionBuilder & addDependency(const char *name)
Definition: FunctionTypes.h:967
FunctionBuilder & setConstantFold(bool on)
Definition: FunctionTypes.h:972
FunctionBuilder & addSignature(const Signature *ptr, const char *symbol=nullptr)
Definition: FunctionTypes.h:935
FunctionBuilder(const char *name)
Definition: FunctionTypes.h:903
FunctionBuilder & addReturnAttribute(const llvm::Attribute::AttrKind attr)
Definition: FunctionTypes.h:1048
FunctionBuilder & setArgumentNames(const std::vector< const char * > &names)
Definition: FunctionTypes.h:973
FunctionBuilder & setDocumentation(const char *doc)
Definition: FunctionTypes.h:1059
FunctionBuilder & setEmbedIR(bool on)
Definition: FunctionTypes.h:971
todo
Definition: FunctionTypes.h:791
std::vector< Function::Ptr > FunctionList
Definition: FunctionTypes.h:794
std::shared_ptr< FunctionGroup > Ptr
Definition: FunctionTypes.h:792
std::unique_ptr< FunctionGroup > UniquePtr
Definition: FunctionTypes.h:793
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:856
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:857
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:855
FunctionGroup(const char *name, const char *doc, const FunctionList &list)
Definition: FunctionTypes.h:796
Templated function traits which provides compile-time index access to the types of the function signa...
Definition: Types.h:259
The base/abstract representation of an AX function. Derived classes must implement the Function::type...
Definition: FunctionTypes.h:262
const std::vector< const char * > & dependencies() const
Definition: FunctionTypes.h:422
const char * argName(const size_t idx) const
Returns the descriptive name of the given argument index.
Definition: FunctionTypes.h:388
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:423
size_t size() const
The number of arguments that this function has.
Definition: FunctionTypes.h:377
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:433
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:265
void setRetAttributes(const std::vector< llvm::Attribute::AttrKind > &in)
Definition: FunctionTypes.h:429
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:312
void setFnAttributes(const std::vector< llvm::Attribute::AttrKind > &in)
Definition: FunctionTypes.h:425
std::shared_ptr< Function > Ptr
Definition: FunctionTypes.h:263
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:410
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:381
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:351
void setArgumentNames(std::vector< const char * > names)
Definition: FunctionTypes.h:420
The base/abstract definition for an IR function.
Definition: FunctionTypes.h:674
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:687
bool hasEmbedIR() const
Definition: FunctionTypes.h:695
void setEmbedIR(bool on)
Enable or disable the embedding of IR. Embedded IR is currently required for function which use paren...
Definition: FunctionTypes.h:694
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...
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:745
llvm::Type * types(std::vector< llvm::Type * > &types, llvm::LLVMContext &C) const override=0
Populate a vector of llvm::Types which describe this function signature. This method is used by Funct...
bool mEmbedIR
Definition: FunctionTypes.h:746
IRFunctionBase(const std::string &symbol, const GeneratorCb &gen, const size_t size)
Definition: FunctionTypes.h:737
void verifyResultType(const llvm::Type *result, const llvm::Type *expected) const
Definition: FunctionTypes.h:726
~IRFunctionBase() override=default
Represents a concrete IR function with the first argument as its return type.
Definition: FunctionTypes.h:781
IRFunctionSRet(const std::string &symbol, const IRFunctionBase::GeneratorCb &gen)
Definition: FunctionTypes.h:783
~IRFunctionSRet() override=default
Represents a concrete IR function.
Definition: FunctionTypes.h:752
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:760
IRFunction(const std::string &symbol, const GeneratorCb &gen)
Definition: FunctionTypes.h:756
LLVM type mapping from pod types.
Definition: Types.h:55
Templated interface class for SRET functions. This struct provides the interface for functions that w...
Definition: FunctionTypes.h:489
std::shared_ptr< SRetFunction< SignatureT, DerivedFunction > > Ptr
Definition: FunctionTypes.h:490
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:546
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:532
SRetFunction(Args &&... ts)
Forward all arguments to the derived class.
Definition: FunctionTypes.h:569
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:515
An extremely basic but native representation of a string class with SSO support. This exists to provi...
Definition: String.h:34
Definition: FunctionTypes.h:143
static std::string s()
Definition: FunctionTypes.h:144
static std::string s()
Definition: FunctionTypes.h:149
static std::string s()
Definition: FunctionTypes.h:134
static std::string s()
Definition: FunctionTypes.h:140
static std::string s()
Definition: FunctionTypes.h:139
static std::string s()
Definition: FunctionTypes.h:138
static std::string s()
Definition: FunctionTypes.h:135
static std::string s()
Definition: FunctionTypes.h:136
static std::string s()
Definition: FunctionTypes.h:137
static std::string s()
Definition: FunctionTypes.h:133
Type to symbol conversions - these characters are used to build each functions unique signature....
Definition: FunctionTypes.h:132
static std::string s()
Definition: FunctionTypes.h:132
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h.in:116
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h.in:202