Gnanambikai Krishnakumar via llvm-dev
2017-Sep-17 14:24 UTC
[llvm-dev] Usage of base register other than ebp for array accesses
Hello All, We want to write a transformation pass such that the array accesses use a base register other than ebp (assuming that the code is compiled for x86 architecture). For example, The below C code ->int a[5]; ->a[2] = 2 by default, gets compiled to something like this: ->mov dword ptr [ebp - 28], eax However, we want our pass to emit the something similar to the following instead: ->mov ecx, "base of array" ->mov dword ptr [ecx - "index from base of array a"], eax Is there any way we could modify the llvm code so as to achieve the required instruction format? Please let us know if there is some code that already does this or if it is documented elsewhere. Regards, Gnanambikai -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170917/73ae2a1e/attachment.html>
John Criswell via llvm-dev
2017-Sep-18 13:38 UTC
[llvm-dev] Usage of base register other than ebp for array accesses
On 9/17/17 10:24 AM, Gnanambikai Krishnakumar via llvm-dev wrote:> Hello All, > > We want to write a transformation pass such that the array > accesses use a base register other than ebp (assuming that the code is > compiled for x86 architecture). For example, > > The below C code > ->int a[5]; > ->a[2] = 2 > > by default, gets compiled to something like this: > ->mov dword ptr [ebp - 28], eax > > However, we want our pass to emit the something similar to the > following instead: > ->mov ecx, "base of array" > ->mov dword ptr [ecx - "index from base of array a"], eax > > Is there any way we could modify the llvm code so as to achieve the > required instruction format? Please let us know if there is some code > that already does this or if it is documented elsewhere.There are two ways that I can see to do this: * Modify the register allocator so that stack offsets are referenced using another register * Write a separate MachineFunctionPass that scans over the code and changes the register used to index into the array. The SVA project has some code which searches for free registers. If you need it, let me know, and I can point you to the relevant code on Github. I think the more interesting question is why you want to do this. What is your end goal? Regards, John Criswell> > Regards, > Gnanambikai > > > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev-- John Criswell Assistant Professor Department of Computer Science, University of Rochester http://www.cs.rochester.edu/u/criswell -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170918/d81d23a4/attachment.html>