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> 84 #include <type_traits> 102 template <
typename T,
size_t _SIZE = 1>
105 static const size_t SIZE = _SIZE;
110 template <
typename T,
size_t S>
133 template <
typename T>
struct TypeToSymbol {
static inline std::string
s() {
return "?"; } };
134 template <>
struct TypeToSymbol<void> {
static inline std::string
s() {
return "v"; } };
135 template <>
struct TypeToSymbol<char> {
static inline std::string
s() {
return "c"; } };
136 template <>
struct TypeToSymbol<uint8_t> {
static inline std::string
s() {
return "u8"; } };
137 template <>
struct TypeToSymbol<uint16_t> {
static inline std::string
s() {
return "us"; } };
138 template <>
struct TypeToSymbol<uint32_t> {
static inline std::string
s() {
return "ui"; } };
139 template <>
struct TypeToSymbol<uint64_t> {
static inline std::string
s() {
return "ul"; } };
140 template <>
struct TypeToSymbol<int8_t> {
static inline std::string
s() {
return "8"; } };
141 template <>
struct TypeToSymbol<int16_t> {
static inline std::string
s() {
return "s"; } };
142 template <>
struct TypeToSymbol<int32_t> {
static inline std::string
s() {
return "i"; } };
143 template <>
struct TypeToSymbol<int64_t> {
static inline std::string
s() {
return "l"; } };
144 template <>
struct TypeToSymbol<float> {
static inline std::string
s() {
return "f"; } };
145 template <>
struct TypeToSymbol<double> {
static inline std::string
s() {
return "d"; } };
148 template <
typename T>
153 template <
typename T,
size_t S>
173 template <typename SignatureT, size_t I = FunctionTraits<SignatureT>::N_ARGS>
179 template <
typename OpT>
180 static void apply(
const OpT&
op,
const bool forwards) {
192 template <
typename SignatureT>
195 template <
typename OpT>
196 static void apply(
const OpT&,
const bool) {}
207 template <
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);
231 template <
typename SignatureT>
232 inline llvm::FunctionType*
235 std::vector<llvm::Type*> types;
236 llvm::Type* returnType =
237 llvmTypesFromSignature<SignatureT>(C, &types);
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>;
271 Function(
const size_t size,
const std::string& symbol)
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;
380 virtual SignatureMatch match(
const std::vector<llvm::Type*>& inputs, llvm::LLVMContext& C)
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;
493 template <
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>;
587 virtual uint64_t address()
const = 0;
592 inline virtual llvm::Value*
fold(
const std::vector<llvm::Value*>&,
593 llvm::LLVMContext&)
const {
599 const std::string& symbol)
601 , mConstantFold(false) {}
612 template <
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.");
627 CFunction(
const std::string& symbol, SignatureT*
function)
629 , mFunction(function) {}
633 inline llvm::Type*
types(std::vector<llvm::Type*>& types, llvm::LLVMContext& C)
const override 635 return llvmTypesFromSignature<SignatureT>(C, &types);
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;
649 return Function::call(args, B, cast);
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;
662 if (!this->hasConstantFold())
return nullptr;
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 +
"\".");
753 template <
typename SignatureT>
757 using Ptr = std::shared_ptr<IRFunction>;
763 types(std::vector<llvm::Type*>& types, llvm::LLVMContext& C)
const override 765 return llvmTypesFromSignature<SignatureT>(C, &types);
771 template <
typename SignatureT>
776 :
BaseT(symbol, function) {}
782 template <
typename SignatureT>
788 :
BaseT(symbol, gen) {}
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; }
885 using Ptr = std::shared_ptr<Settings>;
888 if (mNames)
return false;
889 if (!mDeps.empty())
return false;
890 if (mConstantFold || mEmbedIR)
return false;
891 if (!mFnAttrs.empty())
return false;
892 if (!mRetAttrs.empty())
return false;
893 if (!mParamAttrs.empty())
return false;
897 std::shared_ptr<std::vector<const char*>> mNames =
nullptr;
898 std::vector<const char*> mDeps = {};
899 bool mConstantFold =
false;
900 bool mEmbedIR =
false;
901 std::vector<llvm::Attribute::AttrKind> mFnAttrs = {};
902 std::vector<llvm::Attribute::AttrKind> mRetAttrs = {};
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>
965 this->addSignature<Signature, SRet>(cb, symbol);
966 this->addSignature<Signature, SRet>(ptr, symbol);
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);
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);
1082 for (
auto& decl : mIRFunctions) {
1083 const auto& s = mSettings.at(decl.get());
1084 decl->setDependencies(s->mDeps);
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);
1097 std::vector<Function::Ptr> functions;
1099 if (mDeclPref == DeclPreferrence::IR) {
1100 functions.insert(functions.end(), mIRFunctions.begin(), mIRFunctions.end());
1102 if (mDeclPref == DeclPreferrence::C) {
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);
1133 return "ax." + std::string(this->mName) +
"." +
1137 const char* mName =
"";
1138 const char* mDoc =
"";
1140 std::vector<CFunctionBase::Ptr> mCFunctions = {};
1141 std::vector<IRFunctionBase::Ptr> mIRFunctions = {};
1142 std::map<const Function*, Settings::Ptr> mSettings = {};
1151 #endif // OPENVDB_AX_CODEGEN_FUNCTION_TYPES_HAS_BEEN_INCLUDED const GeneratorCb mGen
Definition: FunctionTypes.h:748
LLVM type mapping from pod types.
Definition: Types.h:55
uint64_t address() const override final
Returns the global address of this function.
Definition: FunctionTypes.h:638
static std::string s()
Definition: FunctionTypes.h:138
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
Definition: FunctionTypes.h:883
Object to array conversion methods to allow functions to return vector types. These containers provid...
Definition: FunctionTypes.h:103
Represents a concrete IR function.
Definition: FunctionTypes.h:754
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
ArrayType mData
Definition: FunctionTypes.h:107
const std::vector< const char * > & dependencies() const
Definition: FunctionTypes.h:428
Definition: FunctionTypes.h:149
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:74
Templated interface class for SRET functions. This struct provides the interface for functions that w...
Definition: FunctionTypes.h:494
const char * argName(const size_t idx) const
Returns the descriptive name of the given argument index.
Definition: FunctionTypes.h:394
FunctionBuilder & addSignature(const IRFunctionBase::GeneratorCb &cb, const char *symbol=nullptr)
Definition: FunctionTypes.h:913
typename FunctionTraits< SignatureT >::template Arg< I-1 > ArgT
Definition: FunctionTypes.h:176
The base/abstract definition for an IR function.
Definition: FunctionTypes.h:679
Function(const size_t size, const std::string &symbol)
Definition: FunctionTypes.h:271
CFunctionSRet(const std::string &symbol, const SignatureT function)
Definition: FunctionTypes.h:775
FunctionBuilder & setArgumentNames(const std::vector< const char * > &names)
Definition: FunctionTypes.h:976
The base class for all C bindings.
Definition: FunctionTypes.h:579
const char * name() const
Definition: FunctionTypes.h:859
T Type
Definition: FunctionTypes.h:104
const char * symbol() const
The function symbol name.
Definition: FunctionTypes.h:387
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
Alias mapping between two types, a frontend type T1 and a backend type T2. This class is the intended...
Definition: Types.h:239
static std::string s()
Definition: FunctionTypes.h:134
static std::string s()
Definition: FunctionTypes.h:145
Templated argument iterator which implements various small functions per argument type...
Definition: FunctionTypes.h:174
llvm::FunctionType * llvmFunctionTypeFromSignature(llvm::LLVMContext &C)
Generate an LLVM FunctionType from a function signature.
Definition: FunctionTypes.h:233
Definition: FunctionTypes.h:880
Type[SIZE] ArrayType
Definition: FunctionTypes.h:106
std::vector< Function::Ptr > FunctionList
Definition: FunctionTypes.h:797
std::unique_ptr< FunctionGroup > UniquePtr
Definition: FunctionTypes.h:796
Consolidated llvm types for most supported types.
OPENVDB_AX_API void print(const ast::Node &node, const bool numberStatements=true, std::ostream &os=std::cout, const char *indent=" ")
Writes a descriptive printout of a Node hierarchy into a target stream.
static std::string s()
Definition: FunctionTypes.h:142
static std::string s()
Definition: FunctionTypes.h:150
static std::string s()
Definition: FunctionTypes.h:144
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
static std::string s()
Definition: FunctionTypes.h:133
FunctionBuilder & setConstantFold(bool on)
Definition: FunctionTypes.h:975
Represents a concrete IR function with the first argument as its return type.
Definition: FunctionTypes.h:783
void setDependencies(std::vector< const char * > deps)
Definition: FunctionTypes.h:429
FunctionBuilder & setDocumentation(const char *doc)
Definition: FunctionTypes.h:1062
bool hasParamAttribute(const size_t i, const llvm::Attribute::AttrKind &kind) const
Builder methods.
Definition: FunctionTypes.h:416
FunctionBuilder & setEmbedIR(bool on)
Definition: FunctionTypes.h:974
const FunctionList & list() const
Accessor to the underlying function signature list.
Definition: FunctionTypes.h:858
FunctionBuilder & addDependency(const char *name)
Definition: FunctionTypes.h:970
std::shared_ptr< Settings > Ptr
Definition: FunctionTypes.h:885
bool mEmbedIR
Definition: FunctionTypes.h:749
static std::string s()
Definition: FunctionTypes.h:140
FunctionBuilder & addSignature(const Signature *ptr, const char *symbol=nullptr)
Definition: FunctionTypes.h:938
FunctionGroup(const char *name, const char *doc, const FunctionList &list)
Definition: FunctionTypes.h:799
static std::string s()
Definition: FunctionTypes.h:155
std::shared_ptr< FunctionGroup > Ptr
Definition: FunctionTypes.h:795
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
CFunctionBase(const size_t size, const std::string &symbol)
Definition: FunctionTypes.h:598
The FunctionBuilder class provides a builder pattern framework to allow easy and valid construction o...
Definition: FunctionTypes.h:877
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
Represents a concrete C function binding.
Definition: FunctionTypes.h:613
static std::string s()
Definition: FunctionTypes.h:139
#define OPENVDB_ASSERT(X)
Definition: Assert.h:41
Constant folding support structure.
Definition: ConstantFolding.h:35
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:693
typename ArgT::Type ArgumentValueType
Definition: FunctionTypes.h:177
FunctionBuilder & addFunctionAttribute(const llvm::Attribute::AttrKind attr)
Definition: FunctionTypes.h:1057
llvm::Value * fold(const std::vector< llvm::Value * > &args, llvm::LLVMContext &C) const override final
Definition: FunctionTypes.h:652
IRFunction(const std::string &symbol, const GeneratorCb &gen)
Definition: FunctionTypes.h:759
IRFunctionSRet(const std::string &symbol, const IRFunctionBase::GeneratorCb &gen)
Definition: FunctionTypes.h:786
FunctionBuilder(const char *name)
Definition: FunctionTypes.h:906
DeclPreferrence
Definition: FunctionTypes.h:879
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
Definition: FunctionTypes.h:357
void verifyResultType(const llvm::Type *result, const llvm::Type *expected) const
Definition: FunctionTypes.h:729
static std::string s()
Definition: FunctionTypes.h:146
Definition: Exceptions.h:13
void setRetAttributes(const std::vector< llvm::Attribute::AttrKind > &in)
Definition: FunctionTypes.h:435
FunctionBuilder & setPreferredImpl(DeclPreferrence pref)
Definition: FunctionTypes.h:1063
void setArgumentNames(std::vector< const char * > names)
Definition: FunctionTypes.h:426
todo
Definition: FunctionTypes.h:793
bool hasConstantFold() const
Definition: FunctionTypes.h:590
static void apply(const OpT &, const bool)
Definition: FunctionTypes.h:196
static std::string s()
Definition: FunctionTypes.h:135
void setFnAttributes(const std::vector< llvm::Attribute::AttrKind > &in)
Definition: FunctionTypes.h:431
FunctionBuilder & addSignature(const IRFunctionBase::GeneratorCb &cb, const Signature *ptr, const char *symbol=nullptr)
Definition: FunctionTypes.h:963
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:143
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
bool hasEmbedIR() const
Definition: FunctionTypes.h:698
FunctionBuilder & addParameterAttribute(const size_t idx, const llvm::Attribute::AttrKind attr)
Definition: FunctionTypes.h:1045
size_t size() const
The number of arguments that this function has.
Definition: FunctionTypes.h:383
static std::string s()
Definition: FunctionTypes.h:137
CFunction(const std::string &symbol, SignatureT *function)
Definition: FunctionTypes.h:627
Constant folding for C++ bindings.
Templated function traits which provides compile-time index access to the types of the function signa...
Definition: Types.h:280
static std::string s()
Definition: FunctionTypes.h:136
The base/abstract representation of an AX function. Derived classes must implement the Function::type...
Definition: FunctionTypes.h:267
const char * doc() const
Definition: FunctionTypes.h:860
Represents a concrete C function binding with the first argument as its return type.
Definition: FunctionTypes.h:772
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.
An extremely basic but native representation of a string class with SSO support. This exists to provi...
Definition: String.h:33
Utility code generation methods for performing various llvm operations.
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
SRetFunction(Args &&...ts)
Forward all arguments to the derived class.
Definition: FunctionTypes.h:575
bool isDefault() const
Definition: FunctionTypes.h:887
void llvmTypeToString(const llvm::Type *const type, std::string &str)
Prints an llvm type to a std string.
Definition: Utils.h:134
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h.in:121
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
void setParamAttributes(const size_t i, const std::vector< llvm::Attribute::AttrKind > &in)
Definition: FunctionTypes.h:439
SignatureMatch
The result type from calls to Function::match.
Definition: FunctionTypes.h:357
virtual llvm::Value * fold(const std::vector< llvm::Value * > &, llvm::LLVMContext &) const
Definition: FunctionTypes.h:592
std::shared_ptr< Function > Ptr
Definition: FunctionTypes.h:269
static void apply(const OpT &op, const bool forwards)
Definition: FunctionTypes.h:180
static std::string s()
Definition: FunctionTypes.h:141
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h.in:218
IRFunctionBase(const std::string &symbol, const GeneratorCb &gen, const size_t size)
Definition: FunctionTypes.h:740
void setConstantFold(bool on)
Definition: FunctionTypes.h:589
FunctionBuilder & addReturnAttribute(const llvm::Attribute::AttrKind attr)
Definition: FunctionTypes.h:1051
Definition: Exceptions.h:38