Aaron via llvm-dev
2018-May-07 04:43 UTC
[llvm-dev] Global Variable Initialization via Internal Function
Hello, I'm trying to figure out how to initialize global variables via LLVM IR and I found that clang creates a internal function to initialize global variables if initialization values are not constants. *Do we really need to create an internal function for complex global variable initializations during variable declaration? Can't we create instructions in global scope?* Example Simple C++ code: int func() { return 5*2; } init globalVar = func(); int main(...) ... Thanks for helping! Aaron -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20180506/731b5be2/attachment.html>
Dean Michael Berris via llvm-dev
2018-May-07 04:57 UTC
[llvm-dev] Global Variable Initialization via Internal Function
On Mon, May 7, 2018 at 2:43 PM Aaron via llvm-dev <llvm-dev at lists.llvm.org> wrote:> Hello,> I'm trying to figure out how to initialize global variables via LLVM IRand I found that clang creates a internal function to initialize global variables if initialization values are not constants.> Do we really need to create an internal function for complex globalvariable initializations during variable declaration? Can't we create instructions in global scope? There might be other ways, but the C++ standard says something about the order of initialisation of objects, and operating systems usually do this by a convention. The convention seems to be that it will call functions that are referred to from specially-named sections in a binary. So far, the "cleanest" way of doing that is to define functions that get referred to (by address) from these special sections.> Example Simple C++ code:> int func() > { > return 5*2; > }> init globalVar = func();> int main(...) > ...> Thanks for helping!> Aaron> _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev-- Dean
Seemingly Similar Threads
- [LLVMdev] Global variable initializer type does not match global variable type
- [LLVMdev] LICM promoting memory to scalar
- [LLVMdev] LICM promoting memory to scalar
- [LLVMdev] LICM promoting memory to scalar
- [LLVMdev] Global variable initializer type does not match global variable type