今天在进行 LLVM 插桩时,遇到一个神奇的报错
PHI nodes not grouped at top of basic block!
%12 = phi i32 [ %.pre, %if.then15 ], [ %argc, %maybe_close_fd_mask.exit ], !dbg !381
label %if.end19
PHI nodes not grouped at top of basic block!
%18 = phi i32 [ %.pr, %if.else49thread-pre-split ], [ %12, %if.end19 ], !dbg !422
label %if.else49
PHI nodes not grouped at top of basic block!
%N.1 = phi i32 [ %conv.i, %if.then34 ], [ %N.0, %if.else49 ], !dbg !431
label %if.end57
PHI nodes not grouped at top of basic block!
%indvars.iv = phi i64 [ 1, %for.body.preheader ], [ %indvars.iv.next, %cleanup ]
label %for.body
PHI nodes not grouped at top of basic block!
%fd.039 = phi i32 [ %call5, %if.end ], [ 0, %for.body ]
label %if.end8
LLVM ERROR: Broken module found, compilation aborted!
经过 STFW,找到如下网址 https://stackoverflow.com/questions/16754324/input-in-llvm-i-think-i-do-not-understand-dominance-and-the-location-of-phi-nod
意思很明显,如果一个基本块里有 phi 指令,那么从基本块的开头到 phi 指令之间必须全都是 phi 指令。也就是说,phi 指令必须堆在 basic block 的开头
所以,插桩的时候要注意,不要违背了这个原则。