Get instruction as a string and SSA form

1. I am trying to get the instruction of LLVM intermediate code as a
string. How can this be done?

2. Also in the SSA version of the code, how can we come to know which %N
(N is any integer) is a version of some variable 'a' and which is just a
temporary?

Regards,
Ashutosh Shukla,
10305052
M. Tech 1
Dept of Computer Science and Engg.

1. I am trying to get the instruction of LLVM intermediate code as a
string. How can this be done?

Have you looked for a method of llvm::Value that does this? I know there's a method to print an llvm::Value to a C++ stream, so if there's no direct method, you can always output it to a string stream.

2. Also in the SSA version of the code, how can we come to know which %N
(N is any integer) is a version of some variable 'a' and which is just a
temporary?

I think you're asking how to determine whether an SSA variable maps back to a source code variable or was a temporary added by the compiler. I think you'd have to use the debug metadata to do such a mapping. I'm not sure how accurate the results would be.

Depending on what you're doing, it may be better to do your analysis or transform in Clang. Clang works on source-level ASTs and (I would think) be able to tell you what is a source code variable and what is not.

-- John T.