<div>Hi,</div><div><br></div><div>I have a question with respect to relating the alloca's of local variables in the LLVM bit-</div><div>code to their actual declarations in the source code. Consider for instance the following</div>
<div>declaration of a variable called 'digest' within a loop (iteration local variable):</div><div><br></div><div>int main()</div><div>{</div><div> ...</div><div> for (i=0; i < n; i++)</div><div> {</div><div>
unsigned char digest[16];</div><div> ...</div><div> }</div><div>}</div><div><br></div><div>The LLVM bit-code looks as follows:</div><div><br></div><div><br></div><div>define i32 @main(i32 %argc, i8** %argv) noreturn nounwind {</div>
<div>entry:</div><div> ...</div><div> %digest = alloca [16 x i8], align 1 ; <[16 x i8]*> [#uses=2]</div><div> ...</div><div><br></div><div>for.cond:</div><div> ...</div><div>}</div><div><br></div><div>
What I would like to is to transform the code above, for certain selective loops,</div><div>to pre-allocate n copies of digest, using alloca's or malloc/free before the loop.</div><div><br></div><div>I would like modify clang to detect and annotate variables like digest as being local</div>
<div>to a loop/compound statement, which can then be used by some pass in LLVM's opt to</div><div>find the corresponding alloca and apply the transformation above. Right now, one crude</div><div>way of doing this would be to add calls to annotation functions at places where the</div>
<div>variables are declared, by detecting VarDecl instances in clang. The later pass in opt can then</div><div>parse the annotation function and figure out the nearest enclosing loop to do the pre-allocation</div><div> transformation. Is there is better/easier way to do this ?</div>
<div><br></div><div>thanks,</div><div>Prakash</div>