0

Is there any way to get an lli execution trace. As an example for a given program:

define dso_local i32 @main() {
  %1 = alloca i32, align 4
  store i32 1, i32* %1, align 4
  %2 = load i32, i32* %1, align 4
  ret i32 %2
}

I would like to have some runtime output like:

$ lli test.ll -trace

%1 = alloca(4)
st %1, 1       ; [%1] = 1
ld %1 -> %2    ; %2 = 1
ret %2         ; ret 1

I've found an XRay project but it seems to be complicated. Are there any llc native ways to output execution trace?

alexanius
  • 402
  • 2
  • 11

1 Answers1

1

I didn't find one, and ended up writing something that's general enough for my needs but not even nearly appropriate for general use. One big problem is that any code can call native code, and most code does that very often, so the tracer only traces a few instructions before encountering a CallInst it cannot handle.

If you're only interested in very short instruction sequences, the functions in Analysis/ConstantFolding.h may be helpful... or may not, it depends on your purpose. If you have to write a tracer yourself, you might want to look around for code that uses InstVisitor, some of that code may be usable, reusable, or a good starting point. Good luck.

arnt
  • 8,949
  • 5
  • 24
  • 32
  • Thank you, I hoped there should be an easy way to do it. I think for my purposes this way is not appropriatable (I hoped to find a ready project or an option) – alexanius Oct 28 '18 at 17:18