Henning Thielemann via llvm-dev
2016-Aug-30 08:21 UTC
[llvm-dev] LLVMAddGlobalMapping after optimization
I use MCJIT on LLVM-3.8 and use LLVMAddGlobalMapping to register call-back functions. LLVMAddGlobalMapping needs a LLVMValueRef to a function call value. However, is this still valid after optimization? I always suspected that this is not true, but it worked in many occasions anyway. Now, I think I hit a case where it fails. I do roughly this: ... funcRef = LLVMAddFunction(module, funcName, funcType); ... LLVMRunPassManager(passes, module); ... LLVMCreateExecutionEngineForModule(&ee, module, &err); ... // Is funcRef still valid here? LLVMAddGlobalMapping(ee, funcRef, &myFunc); ... Is this admissible? If not (what I assume), how can I manage call-backs in an optimization-proof way?
Henning Thielemann via llvm-dev
2016-Sep-18 16:11 UTC
[llvm-dev] LLVMAddGlobalMapping after optimization
On Tue, 30 Aug 2016, Henning Thielemann wrote:> I use MCJIT on LLVM-3.8 and use LLVMAddGlobalMapping to register call-back > functions. LLVMAddGlobalMapping needs a LLVMValueRef to a function call > value. However, is this still valid after optimization? I always suspected > that this is not true, but it worked in many occasions anyway. Now, I think I > hit a case where it fails.Aha, it seems that optimization does not change the LLVMValueRef of a function during optimization. However, optimization may remove an unused function completely, which makes the LLVMValueRef invalid. Now I retrieve the LLVMValueRefs via LLVMGetNamedFunction and check for NULL pointers.