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> 19 #include <llvm/IR/Constants.h> 21 #include <type_traits> 33 template <
typename SignatureT,
34 size_t I = FunctionTraits<SignatureT>::N_ARGS>
54 template <
typename ...Tys>
56 fold(
const std::vector<llvm::Constant*>& args,
57 const SignatureT&
function,
62 llvm::Constant* constant = args[I-1];
63 const llvm::Type* type = constant->getType();
64 if (type->isIntegerTy()) {
66 llvm::ConstantInt* cint =
67 llvm::cast<llvm::ConstantInt>(constant);
68 const uint64_t val = cint->getLimitedValue();
69 return call<uint64_t, ArgumentValueType>(args,
function, C, val, ts...);
71 else if (type->isFloatTy() || type->isDoubleTy()) {
73 llvm::ConstantFP* cfp =
74 llvm::cast<llvm::ConstantFP>(constant);
75 const llvm::APFloat& apf = cfp->getValueAPF();
76 if (type->isFloatTy()) {
77 const float val = apf.convertToFloat();
78 return call<float, ArgumentValueType>(args,
function, C, val, ts...);
80 if (type->isDoubleTy()) {
81 const double val = apf.convertToDouble();
82 return call<double, ArgumentValueType>(args,
function, C, val, ts...);
85 else if (type->isArrayTy()) {
96 template <
typename In,
typename Out,
typename ...Tys>
97 static typename std::enable_if<std::is_convertible<In, Out>::value, llvm::Value*>::type
98 call(
const std::vector<llvm::Constant*>& args,
99 const SignatureT&
function,
100 llvm::LLVMContext& C,
105 return Next::fold(args,
function, C, Out(arg), ts...);
110 template <
typename In,
typename Out,
typename ...Tys>
111 static typename std::enable_if<!std::is_convertible<In, Out>::value, llvm::Value*>::type
112 call(
const std::vector<llvm::Constant*>&,
121 template <
typename SignatureT>
126 template <
typename ...Tys>
128 fold(
const std::vector<llvm::Constant*>& args,
129 const SignatureT&
function,
130 llvm::LLVMContext& C,
134 return call<ReturnT>(args,
function, C, ts...);
141 template <
typename ReturnT,
typename ...Tys>
142 static typename std::enable_if<!std::is_pointer<ReturnT>::value &&
143 !std::is_same<ReturnT, void>::value, llvm::Value*>::type
144 call(
const std::vector<llvm::Constant*>&,
145 const SignatureT&
function,
146 llvm::LLVMContext& C,
149 const ReturnT result =
function(ts...);
155 template <
typename ReturnT,
typename ...Tys>
156 static typename std::enable_if<std::is_pointer<ReturnT>::value ||
157 std::is_same<ReturnT, void>::value, llvm::Value*>::type
158 call(
const std::vector<llvm::Constant*>&,
172 #endif // OPENVDB_AX_CODEGEN_CONSTANT_FOLDING_HAS_BEEN_INCLUDED LLVM type mapping from pod types.
Definition: Types.h:55
static llvm::Value * fold(const std::vector< llvm::Constant * > &args, const SignatureT &function, llvm::LLVMContext &C, Tys &&...ts)
Definition: ConstantFolding.h:128
typename FunctionTraits< SignatureT >::template Arg< I-1 > ArgT
Definition: ConstantFolding.h:37
Consolidated llvm types for most supported types.
static llvm::Value * fold(const std::vector< llvm::Constant * > &args, const SignatureT &function, llvm::LLVMContext &C, Tys &&...ts)
Definition: ConstantFolding.h:56
#define OPENVDB_ASSERT(X)
Definition: Assert.h:41
Constant folding support structure.
Definition: ConstantFolding.h:35
Definition: Exceptions.h:13
typename ArgT::Type ArgumentValueType
Definition: ConstantFolding.h:38
Templated function traits which provides compile-time index access to the types of the function signa...
Definition: Types.h:280
#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