编译llvm.org/demo上的代码会产生以下结果:
define i32 @main(i32 %argc, i8** nocapture %argv) nounwind uwtable {
%1 = getelementptr inbounds i8** %argv, i64 1
%2 = load i8** %1, align 8, !tbaa !0
%3 = tail call i64 @strtol(i8* nocapture %2, i8** null, i32 10) nounwind
%4 = trunc i64 %3 to i32
%5 = icmp eq i32 %4, 0
br i1 %5, label %factorial.exit, label %tailrecurse.i
tailrecurse.i: ; preds = %tailrecurse.i, %0
%X.tr2.i = phi i32 [ %6, %tailrecurse.i ], [ %4, %0 ]
%accumulator.tr1.i = phi i32 [ %7, %tailrecurse.i ], [ 1, %0 ]
%6 = add nsw i32 %X.tr2.i, -1
%7 = mul nsw i32 %accumulator.tr1.i, %X.tr2.i
%8 = icmp eq i32 %6, 0
br i1 %8, label %factorial.exit, label %tailrecurse.i
factorial.exit: ; preds = %tailrecurse.i, %0
%accumulator.tr.lcssa.i = phi i32 [ 1, %0 ], [ %7, %tailrecurse.i ]
%9 = tail call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([4 x i8]* @.str, i64 0, i64 0), i32 %accumulator.tr.lcssa.i) nounwind
ret i32 0
}
特别是您应该查看%1
(ie argv+1
) 和%2
(ie *(argv+1)
):当您调用 时lli factorial.bc 5
,%2
将包含指向字符串 5
的指针。