On 16 February 2010 20:49, Trevor Harmon <Trevor.W.Harmon at nasa.gov>
wrote:> We were discussing that a few days ago:
>
> http://lists.cs.uiuc.edu/pipermail/llvmdev/2010-February/029245.html
Hi Trevor,
On a similar question, I'd want to see what line is being compiled to
which instructions. Is it possible to print the before the
instructions as comment?
For example:
array.c:
------------------------------
int array[5] = { 1, 2, 3, 4, 5 };
int main () {
array[1] = 5;
array[4] = array[1] + array[3];
array[0] = array[4] * array[1];
array[2] = array[0] + 1;
return array[2];
}
------------------------------
$ clang -emit-llvm -O1 -c array.c -o - | llvm-dis -
; array.c:1: int array[5] = { 1, 2, 3, 4, 5 };
@array = global [5 x i32] [i32 1, i32 2, i32 3, i32 4, i32 5], align 4
; <[5 x i32]*> [#uses=5]
; array.c:2: int main () {
define i32 @main() nounwind {
entry:
; array.c:3: array[1] = 5;
store i32 5, i32* getelementptr inbounds ([5 x i32]* @array, i64 0, i64 1)
; array.c:4: array[4] = array[1] + array[3];
%tmp1 = load i32* getelementptr inbounds ([5 x i32]* @array, i64 0,
i64 3) ; <i32> [#uses=1]
%add = add nsw i32 %tmp1, 5 ; <i32> [#uses=2]
; array.c:5: array[0] = array[4] * array[1];
store i32 %add, i32* getelementptr inbounds ([5 x i32]* @array, i64 0, i64 4)
%tmp3 = load i32* getelementptr inbounds ([5 x i32]* @array, i64 0,
i64 1) ; <i32> [#uses=1]
%mul = mul i32 %add, %tmp3 ; <i32> [#uses=2]
store i32 %mul, i32* getelementptr inbounds ([5 x i32]* @array, i64 0, i64 0)
; array.c:6: array[2] = array[0] + 1;
%add5 = add nsw i32 %mul, 1 ; <i32> [#uses=2]
store i32 %add5, i32* getelementptr inbounds ([5 x i32]* @array, i64 0, i64 2)
; array.c:7: return array[2];
ret i32 %add5
}
When lines get re-arranged with basic optimizations, the output could
be messy, but at least on -O0, the majority of lines can still be
quite readable, especially when you're testing very simple test cases
to assure correct instruction generation.
If there isn't such thing, is it easy to add as an extra option (only
when -O0 is selected)? I'm willing to implement that, in case it's
possible.
--
cheers,
--renato
http://systemcall.org/
Reclaim your digital rights, eliminate DRM, learn more at
http://www.defectivebydesign.org/what_is_drm