<div dir="ltr">Load it, add it, store it, and then for good measure, plug it, play it, burn it, and rip it. :)<div><br></div><div>You just need to add a store to your IR:</div><div><span style="font-size:12.8000001907349px">%cell_index = load i32* %cell_index_ptr</span><br style="font-size:12.8000001907349px"><span style="font-size:12.8000001907349px">%new_cell_index = add i32 1, %cell_index</span><br></div><div><span style="font-size:12.8000001907349px">store i32 %new_cell_index, i32* %cell_index_ptr</span></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, May 13, 2015 at 9:23 PM, Kolmogorov <span dir="ltr"><<a href="mailto:e-link@msn.com" target="_blank">e-link@msn.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I want to add an instruction at the end of a basic block to increment a<br>
GlobalVariable (using the LLVM C++ library). I am pretty new to to the LLVM,<br>
can I do this directly or does this require loading the global variable,<br>
incrementing it by the desired value and writing back to the global variable<br>
?<br>
<br>
Even if I load the variable (with LoadInst constructor), How will the "Add"<br>
instruction know where is the variable ?<br>
<br>
For example, look at this IR ocde : %cell_index = load i32* %cell_index_ptr<br>
%new_cell_index = add i32 1, %cell_index<br>
<br>
the add instruction knows on which variable to operate (cell_index). But<br>
since I will create the load instruction from the C++ I don't know where the<br>
variable will be created. (I do not operate the IR code directly but using<br>
the C++ it was just for the example<br>
<br>
<br>
<br>
--<br>
View this message in context: <a href="http://clang-developers.42468.n3.nabble.com/How-to-increment-a-Global-Variable-in-a-LLVM-module-tp4045533.html" target="_blank">http://clang-developers.42468.n3.nabble.com/How-to-increment-a-Global-Variable-in-a-LLVM-module-tp4045533.html</a><br>
Sent from the Clang Developers mailing list archive at Nabble.com.<br>
_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@cs.uiuc.edu">cfe-dev@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br>
</blockquote></div><br></div>