Less instantiations

This commit is contained in:
Raúl Marín 2024-12-02 17:50:57 +01:00
parent e41a018a5f
commit e2b8186d4b
3 changed files with 26 additions and 7 deletions

View File

@ -326,7 +326,8 @@ public:
#if USE_EMBEDDED_COMPILER #if USE_EMBEDDED_COMPILER
void compileAdd(llvm::IRBuilderBase & builder, llvm::Value * aggregate_data_ptr, const ValuesWithType & arguments) const override void compileAddImpl(llvm::IRBuilderBase & builder, llvm::Value * aggregate_data_ptr, const ValuesWithType & arguments) const
requires(canBeNativeType<Numerator>() && canBeNativeType<Denominator>())
{ {
llvm::IRBuilder<> & b = static_cast<llvm::IRBuilder<> &>(builder); llvm::IRBuilder<> & b = static_cast<llvm::IRBuilder<> &>(builder);
@ -345,6 +346,12 @@ public:
b.CreateStore(denominator_value_updated, denominator_ptr); b.CreateStore(denominator_value_updated, denominator_ptr);
} }
void compileAdd(llvm::IRBuilderBase & builder, llvm::Value * aggregate_data_ptr, const ValuesWithType & arguments) const override
{
if constexpr(canBeNativeType<Numerator>() && canBeNativeType<Denominator>())
compileAddImpl(builder, aggregate_data_ptr, arguments);
}
#endif #endif
private: private:

View File

@ -94,6 +94,20 @@ public:
b.CreateStore(denominator_value_updated, denominator_ptr); b.CreateStore(denominator_value_updated, denominator_ptr);
} }
void
compileMerge(llvm::IRBuilderBase & builder, llvm::Value * aggregate_data_dst_ptr, llvm::Value * aggregate_data_src_ptr) const override
{
if constexpr (canBeNativeType<Weight>() && canBeNativeType<Numerator>() && canBeNativeType<Denominator>())
Base::compileMergeImpl(builder, aggregate_data_dst_ptr, aggregate_data_src_ptr);
}
llvm::Value * compileGetResult(llvm::IRBuilderBase & builder, llvm::Value * aggregate_data_ptr) const override
{
if constexpr (canBeNativeType<Weight>() && canBeNativeType<Numerator>() && canBeNativeType<Denominator>())
return Base::compileGetResultImpl(builder, aggregate_data_ptr);
return nullptr;
}
void compileAdd(llvm::IRBuilderBase & builder, llvm::Value * aggregate_data_ptr, const ValuesWithType & arguments) const override void compileAdd(llvm::IRBuilderBase & builder, llvm::Value * aggregate_data_ptr, const ValuesWithType & arguments) const override
{ {
if constexpr (canBeNativeType<Weight>() && canBeNativeType<Numerator>() && canBeNativeType<Denominator>()) if constexpr (canBeNativeType<Weight>() && canBeNativeType<Numerator>() && canBeNativeType<Denominator>())
@ -110,7 +124,7 @@ bool allowTypes(const DataTypePtr& left, const DataTypePtr& right) noexcept
constexpr auto allow = [](WhichDataType t) constexpr auto allow = [](WhichDataType t)
{ {
return t.isInt() || t.isUInt() || t.isFloat(); return t.isInt() || t.isUInt() || t.isNativeFloat();
}; };
return allow(l_dt) && allow(r_dt); return allow(l_dt) && allow(r_dt);

View File

@ -74,14 +74,12 @@ static inline llvm::Type * toNativeType(llvm::IRBuilderBase & builder)
template <typename ToType> template <typename ToType>
static inline DataTypePtr toNativeDataType() static inline DataTypePtr toNativeDataType()
{ {
if constexpr (std::is_same_v<ToType, Int8> || std::is_same_v<ToType, UInt8> || static_assert(std::is_same_v<ToType, Int8> || std::is_same_v<ToType, UInt8> ||
std::is_same_v<ToType, Int16> || std::is_same_v<ToType, UInt16> || std::is_same_v<ToType, Int16> || std::is_same_v<ToType, UInt16> ||
std::is_same_v<ToType, Int32> || std::is_same_v<ToType, UInt32> || std::is_same_v<ToType, Int32> || std::is_same_v<ToType, UInt32> ||
std::is_same_v<ToType, Int64> || std::is_same_v<ToType, UInt64> || std::is_same_v<ToType, Int64> || std::is_same_v<ToType, UInt64> ||
std::is_same_v<ToType, Float32> || std::is_same_v<ToType, Float64>) std::is_same_v<ToType, Float32> || std::is_same_v<ToType, Float64>);
return std::make_shared<DataTypeNumber<ToType>>(); return std::make_shared<DataTypeNumber<ToType>>();
throw Exception(ErrorCodes::LOGICAL_ERROR, "Invalid cast to native data type");
} }
/// Cast LLVM value with type to bool /// Cast LLVM value with type to bool