mirror of
https://github.com/revng/revng
synced 2026-06-21 14:07:57 +00:00
ab125b35b0
Change company name to "rev.ng Labs Srl" in all license headers to reflect changed company name and legal status Add missing license headers to files that didn't have one
88 lines
3.2 KiB
C++
88 lines
3.2 KiB
C++
//
|
|
// Copyright (c) rev.ng Labs Srl. See LICENSE.md for details.
|
|
//
|
|
|
|
#include "revng/Model/LoadModelPass.h"
|
|
|
|
#include "revng-c/DataLayoutAnalysis/DLALayouts.h"
|
|
#include "revng-c/DataLayoutAnalysis/DLAPass.h"
|
|
|
|
#include "Backend/DLAMakeLayouts.h"
|
|
#include "Backend/DLAMakeModelTypes.h"
|
|
#include "Frontend/DLATypeSystemBuilder.h"
|
|
#include "Middleend/DLAStep.h"
|
|
|
|
namespace {
|
|
|
|
llvm::cl::opt<std::string> DLADir("dla-flatc-dir",
|
|
llvm::cl::desc("Path to serialize flatc"),
|
|
llvm::cl::value_desc("Path"),
|
|
llvm::cl::cat(MainCategory),
|
|
llvm::cl::NumOccurrencesFlag::Optional);
|
|
} // end of unnamed namespace
|
|
|
|
char DLAPass::ID = 0;
|
|
|
|
static Logger<> BuilderLog("dla-builder-log");
|
|
|
|
using Register = llvm::RegisterPass<DLAPass>;
|
|
static ::Register X("dla", "Data Layout Analysis Pass", false, false);
|
|
|
|
void DLAPass::getAnalysisUsage(llvm::AnalysisUsage &AU) const {
|
|
AU.addRequired<LoadModelWrapperPass>();
|
|
AU.addRequired<llvm::LoopInfoWrapperPass>();
|
|
AU.addRequired<llvm::ScalarEvolutionWrapperPass>();
|
|
|
|
AU.setPreservesAll();
|
|
}
|
|
|
|
bool DLAPass::runOnModule(llvm::Module &M) {
|
|
auto &ModelWrapper = getAnalysis<LoadModelWrapperPass>().get();
|
|
|
|
// Front-end: Create the LayoutTypeSystem graph from an LLVM module
|
|
dla::LayoutTypeSystem TS;
|
|
dla::DLATypeSystemLLVMBuilder Builder{ TS };
|
|
const model::Binary &Model = *ModelWrapper.getReadOnlyModel();
|
|
Builder.buildFromLLVMModule(M, this, Model);
|
|
|
|
if (BuilderLog.isEnabled())
|
|
Builder.dumpValuesMapping("DLA-values-initial.csv");
|
|
|
|
// Middle-end Steps: manipulate nodes and edges of the DLATypeSystem graph
|
|
dla::StepManager SM;
|
|
size_t PtrSize = getPointerSize(Model.Architecture);
|
|
revng_check(SM.addStep<dla::RemoveInvalidPointers>(PtrSize));
|
|
revng_check(SM.addStep<dla::CollapseEqualitySCC>());
|
|
revng_check(SM.addStep<dla::CollapseInstanceAtOffset0SCC>());
|
|
revng_check(SM.addStep<dla::SimplifyInstanceAtOffset0>());
|
|
revng_check(SM.addStep<dla::PruneLayoutNodesWithoutLayout>());
|
|
revng_check(SM.addStep<dla::ComputeUpperMemberAccesses>());
|
|
revng_check(SM.addStep<dla::CollapseCompatibleArrays>());
|
|
revng_check(SM.addStep<dla::RemoveInvalidStrideEdges>());
|
|
revng_check(SM.addStep<dla::PruneLayoutNodesWithoutLayout>());
|
|
revng_check(SM.addStep<dla::ComputeUpperMemberAccesses>());
|
|
revng_check(SM.addStep<dla::ComputeNonInterferingComponents>());
|
|
revng_check(SM.addStep<dla::DeduplicateUnionFields>());
|
|
revng_check(SM.addStep<dla::ComputeNonInterferingComponents>());
|
|
SM.run(TS);
|
|
|
|
// Compress the equivalence classes obtained after graph manipulation
|
|
dla::VectEqClasses &EqClasses = TS.getEqClasses();
|
|
EqClasses.compress();
|
|
dla::LayoutTypePtrVect Values = Builder.getValues();
|
|
|
|
if (BuilderLog.isEnabled())
|
|
Builder.dumpValuesMapping("DLA-values-after-ME.csv");
|
|
|
|
// Generate model types
|
|
auto &WritableModel = ModelWrapper.getWriteableModel();
|
|
auto ValueToTypeMap = dla::makeModelTypes(TS, Values, WritableModel);
|
|
bool Changed = dla::updateFuncSignatures(M, WritableModel, ValueToTypeMap);
|
|
|
|
// Generate Layouts
|
|
dla::LayoutPtrVector OrderedLayouts = makeLayouts(TS, this->Layouts);
|
|
this->ValueLayoutsMap = makeLayoutMap(Values, OrderedLayouts, EqClasses);
|
|
|
|
return Changed;
|
|
}
|