Hi all, is there an easy way to get a 'copy' of a type living in another context into the local context? Background: when calling a function residing in a different module (context2) from a module (context1), we first need to introduce a function declaration of the function with empty body. However, in order to do so, we need the function type. pFuncInContext2->getType gives us the type in context2. The returnType or argument type might refer to some types yet only defined in context2 (e.g. special structs). In order to get the functin declaration right, I would need to find out if we have in context 1every necessary type referred to by the function (in context2) and introduce it if not. Is there an elegant way wrapping all this? E.G. getTypeinLocalcontext(context1, pFuncTypeInContext2)? Thx Alex
Friedman, Eli via llvm-dev
2017-Aug-15 18:05 UTC
[llvm-dev] transfer type to 'local' context
On 8/15/2017 5:48 AM, alex via llvm-dev wrote:> Hi all, > > is there an easy way to get a 'copy' of a type living in another context > into the local context?No, as far as I know. (Probably not hard to write, if you really need it, though; the LLVM type system is pretty simple.)> Background: > when calling a function residing in a different module (context2) from a > module (context1), we first need to introduce a function declaration of > the function with empty body. > > However, in order to do so, we need the function type. > pFuncInContext2->getType gives us the type in context2. > The returnType or argument type might refer to some types yet only > defined in context2 (e.g. special structs). > > In order to get the functin declaration right, I would need to find out > if we have in context 1every necessary type referred to by the function > (in context2) and introduce it if not. > > Is there an elegant way wrapping all this? > E.G. getTypeinLocalcontext(context1, pFuncTypeInContext2)?Why are your modules in different contexts? IR linking normally involves loading all of the relevant modules into the same context. -Eli -- Employee of Qualcomm Innovation Center, Inc. Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project
Hi Eli, indeed, there is no need to use separate contexts for different modules, my mistake. That solved it for me. Thanks!> On 8/15/2017 5:48 AM, alex via llvm-dev wrote: >> Hi all, >> >> is there an easy way to get a 'copy' of a type living in another context >> into the local context? > > No, as far as I know. (Probably not hard to write, if you really need > it, though; the LLVM type system is pretty simple.) > >> Background: >> when calling a function residing in a different module (context2) from a >> module (context1), we first need to introduce a function declaration of >> the function with empty body. >> >> However, in order to do so, we need the function type. >> pFuncInContext2->getType gives us the type in context2. >> The returnType or argument type might refer to some types yet only >> defined in context2 (e.g. special structs). >> >> In order to get the functin declaration right, I would need to find out >> if we have in context 1every necessary type referred to by the function >> (in context2) and introduce it if not. >> >> Is there an elegant way wrapping all this? >> E.G. getTypeinLocalcontext(context1, pFuncTypeInContext2)? > > Why are your modules in different contexts? IR linking normally > involves loading all of the relevant modules into the same context. > > -Eli >