title: llvm alloca dependencies
body: <p>I am trying to determine for certain Load instructions from my pass their corresponding Alloca instructions (that can be in other previous blocks). The chain can be something like : <code>TargetLoad(var) -&gt; other stores/loads that use var (or dependencies on var) -&gt; alloca(var).</code> , linked on several basic blocks. Do you know how can I do it?</p>
  
  <p>I tried to use the methods from DependenceAnalysis and MemoryDependenceAnalysis, but the results were not correct. For instance, <code>MemoryDependenceAnalysis::getDependency</code> should be good with option "Def", but works only for stores, not for loads. Also I have a segfault when trying to use <code>MemoryDependenceAnalysis::getNonLocalPointerDependency</code> or <code>MemoryDependenceAnalysis::getPointerDependencyFrom</code> . When I try to check my result using MemDepResult::getDef(), the result for Load instructions is the same instruction ! So its depending on itself, that being weird since it is using a variable that is previously defined in the code. </p>
  
  <p>The alternative of making the intersection for identifying common parts between all the variables used by target_load_instructions and all the allocated variables is not an option. Because there might be something like : <code>alloca(a) ... c=a*b+4 .... load(c)</code>.</p>
  
  <p>It seems also that DependenceAnalysis::depends() is not ok for my pass. The next line of code is only for reference: <code>if(DA.depends(allocaInstrArray[i],loadInstrArray[j],true))</code> is always false. And it should be true in several cases. I think I am not using it correctly.</p>
  
  <p>However, I made the assumption that maybe depends() does not work for Alloca. So I checked the dependencies among all Load instructions kept in an array. Some results are not based on the loaded variable as they should. For example: <code>LOAD   %3 = load i32* %c, align 4 IS DEPENDENT ON  %1 = load i32* %j, align 4</code>. As you can see, one is loading c and one is loading j. In my Test.cpp target code there is no dependence between j and c. Maybe the dependence is not based on variables/memory locations used?</p>
  
  <p>Thank you for any suggestion !</p>