diff --git a/lib/StackAnalysis/InterproceduralAnalysis.cpp b/lib/StackAnalysis/InterproceduralAnalysis.cpp index 29bc2dd36..39da0d961 100644 --- a/lib/StackAnalysis/InterproceduralAnalysis.cpp +++ b/lib/StackAnalysis/InterproceduralAnalysis.cpp @@ -57,29 +57,9 @@ void InterproceduralAnalysis::run(BasicBlock *Entry, ResultsPool &Results) { Optional Cached = TheCache.get(Entry); - // Has this function been analyzed already? If so, only now we register it in - // the ResultsPool. - if (Cached) { - FunctionType::Values Type; - if (TheCache.isFakeFunction(Entry)) - Type = FunctionType::Fake; - else if (TheCache.isIndirectTailCall(Entry)) - Type = FunctionType::IndirectTailCall; - else if (TheCache.isNoReturnFunction(Entry)) - Type = FunctionType::NoReturn; - else - Type = FunctionType::Regular; - - // Regular functions need to be composed by at least a basic block - const IFS &Summary = **Cached; - if (Type == FunctionType::Regular) - revng_assert(Summary.BranchesType.size() != 0); - - Results.registerFunction(Entry, Type, Summary); - - // We're done here + // Has this function been analyzed already? If so, skip it. + if (Cached) return; - } // Setup logger: each time we start a new intraprocedural analysis we indent // the output @@ -278,7 +258,6 @@ void InterproceduralAnalysis::run(BasicBlock *Entry, ResultsPool &Results) { } while (InProgress.size() > 0); revng_assert(Type != FunctionType::Invalid); - Results.registerFunction(Entry, Type, Result.getFunctionSummary()); } void ResultsPool::mergeFunction(BasicBlock *Function, diff --git a/lib/StackAnalysis/InterproceduralAnalysis.h b/lib/StackAnalysis/InterproceduralAnalysis.h index da03ef319..3b5257138 100644 --- a/lib/StackAnalysis/InterproceduralAnalysis.h +++ b/lib/StackAnalysis/InterproceduralAnalysis.h @@ -89,13 +89,15 @@ public: void registerFunction(llvm::BasicBlock *Entry, FunctionType::Values Type, - const IntraproceduralFunctionSummary &Summary) { + const IntraproceduralFunctionSummary *Summary) { registerFunction(Entry, Type); - mergeCallSites(Entry, Summary.FrameSizeAtCallSite); - mergeBranches(Entry, Summary.BranchesType); - if (Type == FunctionType::Regular or Type == FunctionType::NoReturn - or Type == FunctionType::IndirectTailCall) - mergeFunction(Entry, Summary); + if (Summary != nullptr) { + mergeCallSites(Entry, Summary->FrameSizeAtCallSite); + mergeBranches(Entry, Summary->BranchesType); + if (Type == FunctionType::Regular or Type == FunctionType::NoReturn + or Type == FunctionType::IndirectTailCall) + mergeFunction(Entry, *Summary); + } } /// \brief Merge data about \p Function in \p Summary into the results pool diff --git a/lib/StackAnalysis/StackAnalysis.cpp b/lib/StackAnalysis/StackAnalysis.cpp index c0646fe0e..4dff8ebfd 100644 --- a/lib/StackAnalysis/StackAnalysis.cpp +++ b/lib/StackAnalysis/StackAnalysis.cpp @@ -145,6 +145,36 @@ bool StackAnalysis::runOnModule(Module &M) { } } + for (CFEP &Function : Functions) { + using IFS = IntraproceduralFunctionSummary; + BasicBlock *Entry = Function.Entry; + llvm::Optional Cached = TheCache.get(Entry); + revng_assert(Cached or TheCache.isFakeFunction(Entry)); + + // Has this function been analyzed already? If so, only now we register it + // in the ResultsPool. + FunctionType::Values Type; + if (TheCache.isFakeFunction(Entry)) + Type = FunctionType::Fake; + else if (TheCache.isIndirectTailCall(Entry)) + Type = FunctionType::IndirectTailCall; + else if (TheCache.isNoReturnFunction(Entry)) + Type = FunctionType::NoReturn; + else + Type = FunctionType::Regular; + + // Regular functions need to be composed by at least a basic block + if (Cached) { + const IFS *Summary = *Cached; + if (Type == FunctionType::Regular) + revng_assert(Summary->BranchesType.size() != 0); + + Results.registerFunction(Entry, Type, Summary); + } else { + Results.registerFunction(Entry, Type, nullptr); + } + } + std::stringstream Output; GrandResult = Results.finalize(&M); GrandResult.dump(&M, Output);