11 #ifndef OPENVDB_AX_CODEGEN_CONSTANT_FOLDING_HAS_BEEN_INCLUDED 12 #define OPENVDB_AX_CODEGEN_CONSTANT_FOLDING_HAS_BEEN_INCLUDED 16 #include <openvdb/version.h> 18 #include <llvm/IR/Constants.h> 20 #include <type_traits> 32 template <
typename SignatureT,
33 size_t I = FunctionTraits<SignatureT>::N_ARGS>
53 template <
typename ...Tys>
55 fold(
const std::vector<llvm::Constant*>& args,
56 const SignatureT&
function,
60 assert(I-1 < args.size());
61 llvm::Constant* constant = args[I-1];
62 const llvm::Type* type = constant->getType();
63 if (type->isIntegerTy()) {
64 assert(llvm::isa<llvm::ConstantInt>(constant));
65 llvm::ConstantInt* cint =
66 llvm::cast<llvm::ConstantInt>(constant);
67 const uint64_t val = cint->getLimitedValue();
68 return call<uint64_t, ArgumentValueType>(args,
function, C, val, ts...);
70 else if (type->isFloatTy() || type->isDoubleTy()) {
71 assert(llvm::isa<llvm::ConstantFP>(constant));
72 llvm::ConstantFP* cfp =
73 llvm::cast<llvm::ConstantFP>(constant);
74 const llvm::APFloat& apf = cfp->getValueAPF();
75 if (type->isFloatTy()) {
76 const float val = apf.convertToFloat();
77 return call<float, ArgumentValueType>(args,
function, C, val, ts...);
79 if (type->isDoubleTy()) {
80 const double val = apf.convertToDouble();
81 return call<double, ArgumentValueType>(args,
function, C, val, ts...);
84 else if (type->isArrayTy()) {
95 template <
typename In,
typename Out,
typename ...Tys>
97 call(
const std::vector<llvm::Constant*>& args,
98 const SignatureT&
function,
104 return Next::fold(args,
function, C, Out(arg), ts...);
109 template <
typename In,
typename Out,
typename ...Tys>
111 call(
const std::vector<llvm::Constant*>&,
120 template <
typename SignatureT>
125 template <
typename ...Tys>
127 fold(
const std::vector<llvm::Constant*>& args,
128 const SignatureT&
function,
129 llvm::LLVMContext& C,
133 return call<ReturnT>(args,
function, C, ts...);
140 template <
typename ReturnT,
typename ...Tys>
143 call(
const std::vector<llvm::Constant*>&,
144 const SignatureT&
function,
145 llvm::LLVMContext& C,
148 const ReturnT result =
function(ts...);
154 template <
typename ReturnT,
typename ...Tys>
157 call(
const std::vector<llvm::Constant*>&,
171 #endif // OPENVDB_AX_CODEGEN_CONSTANT_FOLDING_HAS_BEEN_INCLUDED typename ArgT::Type ArgumentValueType
Definition: ConstantFolding.h:37
static llvm::Value * fold(const std::vector< llvm::Constant * > &args, const SignatureT &function, llvm::LLVMContext &C, Tys &&...ts)
Definition: ConstantFolding.h:127
Consolidated llvm types for most supported types.
Constant folding support structure.
Definition: ConstantFolding.h:34
Templated function traits which provides compile-time index access to the types of the function signa...
Definition: Types.h:259
Definition: Exceptions.h:13
ValueT value
Definition: GridBuilder.h:1287
LLVM type mapping from pod types.
Definition: Types.h:54
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h.in:116
static llvm::Value * fold(const std::vector< llvm::Constant * > &args, const SignatureT &function, llvm::LLVMContext &C, Tys &&...ts)
Definition: ConstantFolding.h:55
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h.in:202
typename FunctionTraits< SignatureT >::template Arg< I-1 > ArgT
Definition: ConstantFolding.h:36