Dong Chen
2012-Dec-05 13:37 UTC
[LLVMdev] how to get and modify a global variable inside a module
hi Eduardo, thanks for your attention, i checked the iterator, but i didn't see any fucntion can return or modify the main memory address of a global variable inside the module. can you provide some reference code or program can achieve this? thank you very much -- View this message in context: http://llvm.1065342.n5.nabble.com/how-to-get-and-modify-a-global-variable-inside-a-module-tp52289p52294.html Sent from the LLVM - Dev mailing list archive at Nabble.com.
Eduardo
2012-Dec-05 13:58 UTC
[LLVMdev] how to get and modify a global variable inside a module
Hi Dong Chen, I realized you are actually executing the IR, right? I am not sure if the things I mentioned apply in that case. Actually, I wrote a optimization pass that modify the IR. It modifies global variables and the final IR is intended to be compiled. A snippet of what I do looks like this: class TestClass : public llvm::ModulePass { public: TestClass() : llvm::ModulePass(TestClass::ID) { } virtual bool runOnModule(llvm::Module &m) { for (llvm::Module::global_iterator ii = m.global_begin(); ii != m.global_end(); ++ii) { GlobalVariable* gv = ii; // here you can modify the gv variable (actually I am creating new globals and deleting the old ones) for (llvm::Value::use_iterator jj = gv->use_begin(); jj != gv->use_end(); ++jj) { // jj is a reference for the user of the global variable } } } } On Wed, Dec 5, 2012 at 11:37 AM, Dong Chen <jameschennerd at gmail.com> wrote:> hi Eduardo, > thanks for your attention, i checked the iterator, but i didn't see any > fucntion can return or modify the main memory address of a global variable > inside the module. > can you provide some reference code or program can achieve this? > thank you very much > > > > -- > View this message in context: http://llvm.1065342.n5.nabble.com/how-to-get-and-modify-a-global-variable-inside-a-module-tp52289p52294.html > Sent from the LLVM - Dev mailing list archive at Nabble.com. > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Dong Chen
2012-Dec-05 14:56 UTC
[LLVMdev] how to get and modify a global variable inside a module
hi Eduardo, i got what you did, but it seemed that you modified the Global Variable list, deleted Global Variable and created new one and added it to the list. I don't know whether i got it right and for more details, can you get the main memory address of the Global Variable? or did the iterator provide method to get this? thank you very much -- View this message in context: http://llvm.1065342.n5.nabble.com/how-to-get-and-modify-a-global-variable-inside-a-module-tp52289p52299.html Sent from the LLVM - Dev mailing list archive at Nabble.com.
Reasonably Related Threads
- [LLVMdev] how to get and modify a global variable inside a module
- [LLVMdev] how to get and modify a global variable inside a module
- [LLVMdev] how to get and modify a global variable inside a module
- [LLVMdev] how to get and modify a global variable inside a module
- [LLVMdev] how to get and modify a global variable inside a module