llvm:逐步构建JIT内容的策略 [英] llvm: strategies to build JIT content incrementally

查看:188
本文介绍了llvm:逐步构建JIT内容的策略的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望我的语言后端逐步构建函数和类型,但是当函数和类型无法成功构建时(由于用户输入问题),不要污染主模块和上下文.

I want my language backend to build functions and types incrementally but don't pollute the main module and context when functions and types fail to build successfully (due to problems with the user input).

我问一个较早的问题. 我可以看到的一种策略是在temp模块和LLVMContext中构建所有内容,仅在成功之后才迁移到主上下文,但是我不确定当前的API是否可行.例如,我不知道该在不同上下文之间迁移该内容,因为它们应该表示LLVM功能的孤立孤岛,但是也许总会有其他选择将所有内容保存到.bc并在其他地方加载吗?

I ask an earlier question regarding this. One strategy i can see for this would be building everything in temp module and LLVMContext, migrating to main context only after success, but i am not sure if that is possible with the current API. For instance, i wouldn't know know to migrate that content between different contexts, as they are supposed to represent isolated islands of LLVM functionality, but maybe there is always the alternative to save everything to .bc and load somewhere else?

您会建议采用什么其他策略来实现这一目标?

what other strategies would you suggest for achieving this?

推荐答案

假设您有两个模块-源和目标,则可以将函数从源复制到目标.可以用作示例的LLVM中的代码是LLVM链接器的主体,位于lib/linker/LinkModules.cpp.

Assuming you have two modules - source and destination, it's possible to copy a function from source to destination. The code in LLVM you can use as an example is the body of the LLVM linker, in lib/linker/LinkModules.cpp.

尤其要查看该文件中的linkFunctionProtolinkFunctionBody方法. linkFunctionBody复制函数定义,并使用llvm::CloneFunctionInto实用程序进行繁琐的操作.

In particular, look at the linkFunctionProto and linkFunctionBody methods in that file. linkFunctionBody copies the function definition, and uses the llvm::CloneFunctionInto utility for the heavy lifting.

对于LLVMContext,除非您特别需要在不同的线程中同时运行多个LLVM实例,否则不必太担心,只要在需要上下文的地方使用getGlobalContext().阅读此文档页面以获取更多信息.

As for LLVMContext, unless you specifically need to run several LLVM instances simultaneously in different threads, don't worry about it too much and just use getGlobalContext() everywhere a context is required. Read this doc page for more information.

这篇关于llvm:逐步构建JIT内容的策略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆