Hi Guys,
I am an absolute newbie to the compiler community. I am experimenting a little bit with llvm.
I have a few small questions, i would be really great if someone could help me.
1. Can i find out (is there something already built), if the previous instruction / or some instruction was a cache miss. Basically i want to detect cache misses and instructions that are causing this
2. Can i find if there was a branch misprediction?
3. Can i find if a branch was taken or not taken?
It would be really great if someone could answer this for me.
Thank you
Ketan
Georgia Institue of Technology
Ketan Pundlik Umare wrote:
Hi Guys,
I am an absolute newbie to the compiler community. I am experimenting a little bit with llvm.
I have a few small questions, i would be really great if someone could help me.
It sounds like what you want is valgrind --tool=cachegrind (or --tool=callgrind). See http://valgrind.org/
1. Can i find out (is there something already built), if the previous instruction / or some instruction was a cache miss. Basically i want to detect cache misses and instructions that are causing this
2. Can i find if there was a branch misprediction?
3. Can i find if a branch was taken or not taken?
It would be really great if someone could answer this for me.
I suppose you could instrument the existing LLVM JIT to collect this sort of information.
Realize that much of LLVM works in the LLVM IR language, and we just 'lower' to assembly. LLVM 'passes' which modify code work by editing the IR, not the assembly, so things like 'branch prediction' and whatnot don't exist at that level. If you want to do it with LLVM, you'll likely need to build most of the infrastructure yourself.
If you're interested in what we do have, see llvm/tools/llvm-prof.cpp, llvm/runtime/libprofile and llvm/utils/profile.pl . I have no idea what state this stuff is in, quite possibly bitrotted.
Nick Lewycky
Thanx a lot Nick!!!
I will try to look at it and let you know.
Thank you
Ketan
I am an absolute newbie to the compiler community. I am experimenting a little bit with llvm.
I have a few small questions, i would be really great if someone could help me.
1. Can i find out (is there something already built), if the previous instruction / or some instruction was a cache miss. Basically i want to detect cache misses and instructions that are causing this
Well, you could time it, though, doing that alters the code of course. Small time, in cache, bigger time, in farther away cache, bigger time, in dram, bigger time, page fault. No one in the real world does this. Instead the use tools like Shark or vtune. You can say, show me all the instructions that missed cache and how often they missed.
2. Can i find if there was a branch misprediction?
Likewise. Though, I'm trying to recall if mispredictions where one of the things one could watch for on x86. google around for performance counters on x86.
3. Can i find if a branch was taken or not taken?
gcov will tell you this today.
AMD's CodeAnalyst is free and quite wonderful at this job. Shows
details about just about anything the CPU reports (and on newer AMD
CPU's there is an even more ridiculous amount of information) about
every little function call, time they took, multiple profiling modes,
etc...
Thanx a lot Guys!!
But i have to do this online and and use it to do some kind code transformation. Its for a different project.
But all this has given me a quite a bit of knowledge.Wow!!!
Thank you
Best
Ketan
Ketan Pundlik Umare wrote:
Thanx a lot Guys!!
But i have to do this online and and use it to do some kind code transformation. Its for a different project.
Another possibility is to write an LLVM transform that inserts code into a program to do this profiling for you.
For example, consider cache misses. You could write a function that reads the processor's performance counter registers for cache misses in native code. You could then write an LLVM transform that instruments a program to call this function to calculate cache misses in various parts of the program. A run-time transform used in a JIT built using LLVM could then use this information to transform various parts of the program at run-time.
If you want to do fine grained profiling (for example, instrumenting individual LLVM load/store instructions), there may be more efficient ways to read the performance counters. You may be able to, for example, write an inline asm statement to read the performance counter registers directly (LLVM supports inline assembly).
If you want to instrument code that is not visible at the LLVM IR level (e.g., cache misses due to register spills), then you'd need to modify the code generator, I believe.
You may want to check this resource (Measuring and Improving Application Performance with PerfSuite) for information on software you can use to read performance counters on Linux.
-- John T.