From 72bb799584f08d0a622c0cdac35ab03705cdc8cd Mon Sep 17 00:00:00 2001 From: Shu-Mei Tseng Date: Wed, 16 May 2018 13:51:53 -0700 Subject: [PATCH] During profiling, LLFI tries to inject endProfiling callback functions at the end of the main function. In the original codes, LLFI obtains the last instruction in the last basic block and injects endProfiling before the last instruction. It's generally true in most cases but in some cases the return/unreachable instruction is not always in the last instruction in the last basic block. In my case, the return instruction is in the BB that is before the last BB in the main function. Therefore, to handle this problem, we'll check if the instruction obtained is return or unreachable instruction. If it's not, then iterate all the functions in main() to find the real return/unreachable instruction. There are stll some problems about this modification. For example, when we turn on the "tracingPropagation" option in input.yaml and run the instrumentation, there will be error regarding to the violation of SSA form in LLVM. --- llvm_passes/core/Utils.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/llvm_passes/core/Utils.cpp b/llvm_passes/core/Utils.cpp index f518a246..4e28240d 100644 --- a/llvm_passes/core/Utils.cpp +++ b/llvm_passes/core/Utils.cpp @@ -51,6 +51,17 @@ Instruction *getTermInstofFunction(Function *func) { BasicBlock &termbb = func->back(); Instruction *ret = termbb.getTerminator(); + // if the instruction in the last BB is not return/unreachable instruction, + // iterate through the main function to find the return/unreachable instruction + if( isa(ret) || isa(ret) ){} + else{ + for( inst_iterator f_it = inst_begin(func); f_it != inst_end(func); ++f_it ){ + if( isa(&(*f_it))){ + ret = &(*f_it); + } + } + } + assert(isa(ret) || isa(ret) && "Last instruction is not return or exit() instruction"); return ret;