[LLVMdev] Counting load and stores of variables

MKT taram.mohammad at gmail.com
Tue Mar 10 02:24:41 PDT 2015


Thanks for your response,

> On Esfand 18, 1393 AP, at 16:17, mats petersson <mats at planetcatfish.com> wrote:
> 
> Further on that last comment:
> 
> If you are interested in counting accesses to `x`, and have the following code:
> 
>  a = x + x + x + x;
> 
> and the compiler translates that to:
> 
>  a= x * 4;
> 
> should that count as 1 or 4 accesses?
> 

if the compiler translated it to a= x*4  and it has actually one load it should count as 1,

> What if you have code like this:
> 
>   x = 1;
>   if (a) x = 4;
>   if (b) x = 5;
>   if (c) x = 7;
> 
> if a, b and c are true, and the compiler decided to re-arrange the
> code like this:
> 
>   reg_temp = 1;
>   if (a) reg_temp = 4;
>   if (b) reg_temp = 5;
>   if (c) reg_temp = 7;
>   x = reg_temp;
> 
> how many accesses to `x` is that? 1 or 4?  Do you care about accesses
> in the original source or accesses to the memory location where it
> stores the value?
> 
I care about memory location and not original source. thus it has actually 1 access to x.

Thanks for giving so many alternatives.

>> It gets even more interesting if we consider the actual machine
>> instructions. The `a++` above could in say x86 be implemented as `inc
>> a` or `mov a, reg; inc reg; move reg, a` - both will indeed read,
>> modify the value and write it back - but one is explicitly
>> loading/storing the value, the other is not. How do you account for
>> that? Is it one or two accesses?
>> 
As I target arm instruction set, I need only to consider load and store instructions. 
>> 
>> 
>> On 9 March 2015 at 11:24, MKT <taram.mohammad at gmail.com> wrote:
>>> Hi all,
>>> I’m working on my thesis in which I need to count the number of memory
>>> access (i.e. load and stores) of each variable of program. how can I do
>>> that? these are some approaches came to my mind :
>>> 
>>> I need to know during the execution of the program how many load and store
>>> instructions are executed on a specific variable, hence simply counting
>>> static load and store instructions doesn’t help.
>>> I also cannot write an IR pass to inject some instructions to count memory
>>> accesses of variables (instrumenting) , because in IR optimization I’m not
>>> aware of what will happen in register allocation.
>>> And if I write a machine pass to inject machine instructions, I guess maybe
>>> I loose some informations( e.g. variable names) during the optimizations.
>>> 
>>> 
>>> Thanks,
>>> MohammadKazem
>>> 
>>> 
>>> 
>>> 
>>> _______________________________________________
>>> LLVM Developers mailing list
>>> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
>>> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>>> 





More information about the llvm-dev mailing list