Hi,<br><br>I am trying to create a pass that is similar to the GlobalMerge code found here:<br><a href="http://llvm.org/docs/doxygen/html/GlobalMerge_8cpp_source.html">http://llvm.org/docs/doxygen/html/GlobalMerge_8cpp_source.html</a><br>

<br>I am concerned with lines 149-163 of the above file. From the documentation at the top of the file, it will convert this:<br><br><blockquote style="margin:0 0 0 40px;border:none;padding:0px"></blockquote>static int foo[N], bar[N], baz[N];<br>

<blockquote style="margin:0 0 0 40px;border:none;padding:0px"></blockquote>for (i = 0; i < N; ++i) {<br><blockquote style="margin:0 0 0 40px;border:none;padding:0px"></blockquote>  foo[i] = bar[i] * baz[i];<br>}<div><br>

Into something like this (slightly modified):<br><br>struct mergestruct {<br>  int foo[N];<br>  int bar[N];<br>  int baz[N];<br>};<br><br>static struct mergestruct merged;<br>for (i = 0; i < N; ++i) {<br>  merged.foo[i] = merged.bar[i] * merged.baz[i];<br>

}<div><br></div><div>Great, now in addition I want to use an extra pointer to access the elements, like this:</div><div><br></div><div>struct mergestruct *merged_ptr = &merged;</div><div>for (i = 0; i < N; ++i) {<br>

  merged_ptr->foo[i] = merged_ptr->bar[i] * merged_ptr->baz[i];<br>}</div><div><br></div><div>So I add something like this after line 153:</div><div><br></div><div><div>PointerType *MergedPointerType = PointerType::get(<span style="background-color:rgb(245,245,245);font-family:Fixed,monospace;font-size:13px">MergedTy</span>, 0);</div>

<div>GlobalVariable *MergedPointer = new GlobalVariable(M, MergedPointerType, false,</div><div>  GlobalValue::ExternalLinkage, <span style="background-color:rgb(245,245,245);font-family:Fixed,monospace;font-size:13px">MergedGV</span>, "_MergedGlobalsPtr");</div>

</div><div><br></div><div>This is where I'm stuck. How can I use replaceAllUsesWith() to replace uses of each global with accesses through the new MergedPointer instead of through indices into the MergedGV struct as is currently done? Is this possible?</div>

</div><div><br></div><div>Thanks,</div><div>Rob</div>