Files
revng-revng/include/revng/StackAnalysis/StackAnalysis.h
T
Alessandro Di Federico 2e241acae3 Introduce SA-based ABIDetection and FBD passes
This commit drops the old FunctionBoundariesDetectionPass and introduces
a new one based on the results provided by the StackAnalysis. A very
similar pass, the ABIDetectionPass, is now available to offer the
results of the ABI analysis too.

These two new passes are a thin shim depending on the appropriate
version of the StackAnalysis (with or withour ABI anlysis) and simply
call `serializeMetadata`, which decorates the LLVM IR with the requested
information.

In addition to drop the old analysis, this commit also isolates the
function boundaries detection pass from `revamb` making it available as
a library only.
2019-01-18 15:18:47 +01:00

70 lines
1.6 KiB
C++

#ifndef STACKANALYSIS_H
#define STACKANALYSIS_H
//
// This file is distributed under the MIT License. See LICENSE.md for details.
//
// Standard includes
#include <string>
// LLVM includes
#include "llvm/Pass.h"
// Local libraries includes
#include "revng/BasicAnalyses/GeneratedCodeBasicInfo.h"
#include "revng/FunctionCallIdentification/FunctionCallIdentification.h"
#include "revng/StackAnalysis/FunctionsSummary.h"
namespace StackAnalysis {
extern const std::set<llvm::GlobalVariable *> EmptyCSVSet;
template<bool AnalyzeABI>
class StackAnalysis : public llvm::ModulePass {
friend class FunctionBoundariesDetectionPass;
public:
static char ID;
public:
StackAnalysis() : llvm::ModulePass(ID) {}
void getAnalysisUsage(llvm::AnalysisUsage &AU) const override {
AU.setPreservesAll();
AU.addRequired<GeneratedCodeBasicInfo>();
}
bool runOnModule(llvm::Module &M) override;
const std::set<llvm::GlobalVariable *> &
getClobbered(llvm::BasicBlock *Function) const {
auto It = GrandResult.Functions.find(Function);
if (It == GrandResult.Functions.end())
return EmptyCSVSet;
else
return It->second.ClobberedRegisters;
}
void serialize(std::ostream &Output) { Output << TextRepresentation; }
void serializeMetadata(llvm::Function &F);
public:
FunctionsSummary GrandResult;
std::string TextRepresentation;
};
template<>
char StackAnalysis<true>::ID;
template<>
char StackAnalysis<false>::ID;
extern template void StackAnalysis<true>::serializeMetadata(llvm::Function &F);
extern template void StackAnalysis<false>::serializeMetadata(llvm::Function &F);
} // namespace StackAnalysis
#endif // STACKANALYSIS_H