Llvm 如何在模块末尾插入全局变量?

Llvm 如何在模块末尾插入全局变量?,llvm,Llvm,有一个构造函数似乎符合我的需要: 00055 /// GlobalVariable ctor - If a parent module is specified, the global is 00056 /// automatically inserted into the end of the specified modules global list. 00057 GlobalVariable(Type *Ty, bool isConstant, LinkageTypes Lin

有一个构造函数似乎符合我的需要:

00055   /// GlobalVariable ctor - If a parent module is specified, the global is
00056   /// automatically inserted into the end of the specified modules global list.
00057   GlobalVariable(Type *Ty, bool isConstant, LinkageTypes Linkage,
00058                  Constant *Initializer = nullptr, const Twine &Name = "",
00059                  ThreadLocalMode = NotThreadLocal, unsigned AddressSpace = 0,
00060                  bool isExternallyInitialized = false);

根据以下文档,如果指定了父模块,则gv将插入到其末尾。如何指定模块?

看来注释是错误的。您可以使用,它将
模块&
作为第一个参数。您可以为要插入的新全局变量指定一个
GlobalVariable
,但它是可选的,没有它,新全局变量将在末尾插入

或者(根据问题的标题),如果您已经有了一个
GlobalVariable
,您可以调用
模块
,然后
将您的全局变量推回它