Build LLVM wrap getDeclaration by version

This commit is contained in:
Niram7777 2025-12-02 20:05:33 +00:00
parent 7ca184a3a8
commit 18963da9a5

View file

@ -1149,7 +1149,11 @@ struct llvm_fshl
static llvm::Function* get_fshl(llvm::IRBuilder<>* ir) static llvm::Function* get_fshl(llvm::IRBuilder<>* ir)
{ {
const auto _module = ir->GetInsertBlock()->getParent()->getParent(); const auto _module = ir->GetInsertBlock()->getParent()->getParent();
#if LLVM_VERSION_MAJOR >= 21 || (LLVM_VERSION_MAJOR == 20 && LLVM_VERSION_MINOR >= 1)
return llvm::Intrinsic::getOrInsertDeclaration(_module, llvm::Intrinsic::fshl, {llvm_value_t<T>::get_type(ir->getContext())}); return llvm::Intrinsic::getOrInsertDeclaration(_module, llvm::Intrinsic::fshl, {llvm_value_t<T>::get_type(ir->getContext())});
#else
return llvm::Intrinsic::getDeclaration(_module, llvm::Intrinsic::fshl, {llvm_value_t<T>::get_type(ir->getContext())});
#endif
} }
static llvm::Value* fold(llvm::IRBuilder<>* ir, llvm::Value* v1, llvm::Value* v2, llvm::Value* v3) static llvm::Value* fold(llvm::IRBuilder<>* ir, llvm::Value* v1, llvm::Value* v2, llvm::Value* v3)
@ -1221,7 +1225,11 @@ struct llvm_fshr
static llvm::Function* get_fshr(llvm::IRBuilder<>* ir) static llvm::Function* get_fshr(llvm::IRBuilder<>* ir)
{ {
const auto _module = ir->GetInsertBlock()->getParent()->getParent(); const auto _module = ir->GetInsertBlock()->getParent()->getParent();
#if LLVM_VERSION_MAJOR >= 21 || (LLVM_VERSION_MAJOR == 20 && LLVM_VERSION_MINOR >= 1)
return llvm::Intrinsic::getOrInsertDeclaration(_module, llvm::Intrinsic::fshr, {llvm_value_t<T>::get_type(ir->getContext())}); return llvm::Intrinsic::getOrInsertDeclaration(_module, llvm::Intrinsic::fshr, {llvm_value_t<T>::get_type(ir->getContext())});
#else
return llvm::Intrinsic::getDeclaration(_module, llvm::Intrinsic::fshr, {llvm_value_t<T>::get_type(ir->getContext())});
#endif
} }
static llvm::Value* fold(llvm::IRBuilder<>* ir, llvm::Value* v1, llvm::Value* v2, llvm::Value* v3) static llvm::Value* fold(llvm::IRBuilder<>* ir, llvm::Value* v1, llvm::Value* v2, llvm::Value* v3)
@ -2220,7 +2228,11 @@ struct llvm_add_sat
static llvm::Function* get_add_sat(llvm::IRBuilder<>* ir) static llvm::Function* get_add_sat(llvm::IRBuilder<>* ir)
{ {
const auto _module = ir->GetInsertBlock()->getParent()->getParent(); const auto _module = ir->GetInsertBlock()->getParent()->getParent();
#if LLVM_VERSION_MAJOR >= 21 || (LLVM_VERSION_MAJOR == 20 && LLVM_VERSION_MINOR >= 1)
return llvm::Intrinsic::getOrInsertDeclaration(_module, intr, {llvm_value_t<T>::get_type(ir->getContext())}); return llvm::Intrinsic::getOrInsertDeclaration(_module, intr, {llvm_value_t<T>::get_type(ir->getContext())});
#else
return llvm::Intrinsic::getDeclaration(_module, intr, {llvm_value_t<T>::get_type(ir->getContext())});
#endif
} }
llvm::Value* eval(llvm::IRBuilder<>* ir) const llvm::Value* eval(llvm::IRBuilder<>* ir) const
@ -2303,7 +2315,11 @@ struct llvm_sub_sat
static llvm::Function* get_sub_sat(llvm::IRBuilder<>* ir) static llvm::Function* get_sub_sat(llvm::IRBuilder<>* ir)
{ {
const auto _module = ir->GetInsertBlock()->getParent()->getParent(); const auto _module = ir->GetInsertBlock()->getParent()->getParent();
#if LLVM_VERSION_MAJOR >= 21 || (LLVM_VERSION_MAJOR == 20 && LLVM_VERSION_MINOR >= 1)
return llvm::Intrinsic::getOrInsertDeclaration(_module, intr, {llvm_value_t<T>::get_type(ir->getContext())}); return llvm::Intrinsic::getOrInsertDeclaration(_module, intr, {llvm_value_t<T>::get_type(ir->getContext())});
#else
return llvm::Intrinsic::getDeclaration(_module, intr, {llvm_value_t<T>::get_type(ir->getContext())});
#endif
} }
llvm::Value* eval(llvm::IRBuilder<>* ir) const llvm::Value* eval(llvm::IRBuilder<>* ir) const
@ -3592,7 +3608,11 @@ public:
llvm::Function* get_intrinsic(llvm::Intrinsic::ID id) llvm::Function* get_intrinsic(llvm::Intrinsic::ID id)
{ {
const auto _module = m_ir->GetInsertBlock()->getParent()->getParent(); const auto _module = m_ir->GetInsertBlock()->getParent()->getParent();
#if LLVM_VERSION_MAJOR >= 21 || (LLVM_VERSION_MAJOR == 20 && LLVM_VERSION_MINOR >= 1)
return llvm::Intrinsic::getOrInsertDeclaration(_module, id, {get_type<Types>()...}); return llvm::Intrinsic::getOrInsertDeclaration(_module, id, {get_type<Types>()...});
#else
return llvm::Intrinsic::getDeclaration(_module, id, {get_type<Types>()...});
#endif
} }
template <typename T1, typename T2> template <typename T1, typename T2>