EmbDev.net

Forum: ARM programming with GCC/GNU tools Need Help: A small problem in Clang


Author: Phong Pham (Company: HUT) (phongph)
Posted on:

Rate this post
0 useful
not useful
Hi everyone,

I am having a small problem as follows, please help me:

Implement, using LLVM/Clang, to count the number of memory operations 
executed in a given function (recording reads and writes of fields and 
arrays elements) of C programs. Here is an example:

            int* test(int* b, int* c) {
               ...
               for (int i=0; i<10; i++) {
                   a[i] =b[i] + c[i];
               }
               return a;
            }

After execution of the whole program, the output of the instrumentation 
should return something like this for each method: "function test: reads 
= 20; writes = 10".

Thank you very much!

Author: Klaus Wachtler (mfgkw)
Posted on:

Rate this post
0 useful
not useful
Are you interested in counting access to any objects or only particular 
objects?

If only particular objects: you can use C++ to create a class behaving 
like your array, but override operators to count usage.
The rest of your program could be kept in C as it is, usually without 
modifications.

Author: gjlayde (Guest)
Posted on:

Rate this post
0 useful
not useful
> you can use C++ to create a class behaving
> like your array, but override operators to count usage.

That's nothing to do with instrumentation: instrumenting code does not 
require to change the sources.

Author: Klaus Wachtler (mfgkw)
Posted on:

Rate this post
0 useful
not useful
... ok, but it would answer his question "how man reads/writes?"

Author: gjlayde (Guest)
Posted on:

Rate this post
0 useful
not useful
> ok, but it would answer his question "how man reads/writes?"

But this was not the question :-)

Apart from that the numer of reads / writes can be determined by just 
looking at the function: "function test: reads = 20; writes = 10".

The question is: How to change Clang so that Clang can determine the 
number of reads / writes for any input (program), either by statically 
analyzing the input or by instrumenting the generated code without 
changing its semantics.

In general, you don't even know the input to clang as you are writing a 
specific analysis or transformaton, the given source is just a sample 
code to explain the issue w.r.t. changing clang.

Author: beric (Guest)
Posted on:

Rate this post
0 useful
not useful
Static analysis only will not help you:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int a[5] = { 0, }; // does this count as "write" as well? :-)
int b[5] = { 1, 2, 3, 4, 5 };
int c[5] = { 6, 7, 8, 9, 0 };

int main()
{
   int i, n;
   time_t t;

   /* Initialize random number generator */
   srand((unsigned) time(&t));

   /* pick a number */
   n = rand() % 5;

   /* fill a - partially */
   for( i = 0 ; i < n ; i++ ) {
      a[i] = b[i] + c[i]; // <-- now, how many times is this executed?
   }

  return(0);
}

Reply

Entering an e-mail address is optional. If you want to receive reply notifications by e-mail, please log in.

Rules — please read before posting

  • Post long source code as attachment, not in the text
  • Posting advertisements is forbidden.

Formatting options

  • [c]C code[/c]
  • [avrasm]AVR assembler code[/avrasm]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]




Bild automatisch verkleinern, falls nötig
Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.