Files
revng-revng/lib/EarlyFunctionAnalysis/ABIAnalyses/DeadReturnValuesOfFunctionCall.cpp
T
Alessandro Di Federico 7ba01f513b ABIAnalyses: fix collection points
The collection points of several ABI analyses where incorrect. Several
analyses that should have collected data only from entry points were
collecting data from any node in the graph.
2023-10-04 17:47:50 +02:00

60 lines
1.9 KiB
C++

//
// This file is distributed under the MIT License. See LICENSE.md for details.
//
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/GraphTraits.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/iterator_range.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/GlobalVariable.h"
#include "llvm/IR/Instruction.h"
#include "llvm/IR/Instructions.h"
#include "llvm/Support/Casting.h"
#include "revng/MFP/MFP.h"
#include "revng/Model/Binary.h"
#include "Analyses.h"
namespace ABIAnalyses::DeadReturnValuesOfFunctionCall {
using namespace llvm;
using namespace ABIAnalyses;
std::map<const GlobalVariable *, State>
analyze(const BasicBlock *CallSiteBlock, const GeneratedCodeBasicInfo &GCBI) {
using MFI = MFIAnalysis<true, CoreLattice>;
std::map<const GlobalVariable *, State> RegNoOrDead{};
MFI Instance{ { getPreCallHook(CallSiteBlock), GCBI } };
MFI::LatticeElement InitialValue;
MFI::LatticeElement ExtremalValue(CoreLattice::ExtremalLatticeElement);
auto *Start = CallSiteBlock->getUniqueSuccessor();
if (!Start)
return RegNoOrDead;
auto
Results = MFP::getMaximalFixedPoint<MFI, MFI::GT, MFI::LGT>(Instance,
Start,
InitialValue,
ExtremalValue,
{ Start },
{ Start });
const BasicBlock *Entrypoint = &CallSiteBlock->getParent()->getEntryBlock();
auto It = Results.find(Entrypoint);
if (It != Results.end()) {
for (auto &[GV, RegState] : It->second.OutValue) {
if (RegState == CoreLattice::NoOrDead) {
RegNoOrDead[GV] = State::NoOrDead;
}
}
}
return RegNoOrDead;
}
} // namespace ABIAnalyses::DeadReturnValuesOfFunctionCall