llvm memset memcpy 处理流程
- code 框架:
code 框架:
ProcessMemIntrinsic(Module *m) {
//遍历module的function,寻找name为memset、memcpy的function。
ProcessMemset(memset_func);
ProcessMemcpy(memcpy_func);
}ProcessMemset(memset_func) {
//遍历memset_func的user,对每条memset instruction进行replace
ReplaceMemsetInst(inst);
}//; Function Attrs: argmemonly nounwind
//declare void @llvm.memset.p0i8.i64(i8* nocapture writeonly, i8, i64, i32, i1)
//call void @llvm.memset.p0i8.i64(i8* nonnull %4, i8 0, i64 256, i32 16, i1 false)
ReplaceMemsetInst(Instruction *inst) {}
Memset 处理:A为array : [num x iN]
数据A初始化:memset(A,value,length,alignment)
label 0: A
br label meminst
meminst:
%phi_inst = phi i32 [0, %0], [%add_inst, %meminst]
%add_inst = add i32 %phi_inst , 1
%sext_inst = sext i32 phi_inst to i64
%A.addr = getelementptr [num x iN], [num x iN]* A, i64 0, i64 %sext_inst
Store iN value, iN* A.addr
%icmp_inst = icmp eq i32 %phi_inst, num
br i1 %icmp_inst, label %2, label %meminst