Files
Alessandro Di Federico 1429b526ab Introduce libtcg
This commit drops libptc in favor of its new form libtcg.

It brings several improvements, among which:

* The QEMU version we work on has been upgraded.
* CPUStateAccessAnalysis has been reimplemented in a way that makes it
  easier to debug and solves some limitations (e.g., tracking leaking
  pointers).
* Identification of pieces of the CPU state that are read by each helper
  and fixing access to the CPU state is now performed at build-time.
* We no longer mmap the code we need to translate, dropping all the
  issues related to code that needed to be mapped where something is
  already present.
* We now have two distinct flavors of helper modules: the full one and
  the "slim" one. The latter contains the definition only of functions
  we intend to inline. It is used in most of the pipeline, a good thing
  since we spend less time optimizing code we don't really care about.
  The full module is only used on the re-compilation branch of the
  pipeline.
* We no longer split the `cpu_loop` function.
* We change MetaAddress to rely on architectures from `model::` as
  opposed to the LLVM ones.
* We no longer attach debug info to LLVM IR containing the original
  assembly.
* We now verify that the lifted code only contains code we expect.
2025-10-31 17:25:03 +01:00

116 lines
3.0 KiB
C++

#pragma once
//
// This file is distributed under the MIT License. See LICENSE.md for details.
//
#include <map>
#include "llvm/Analysis/LazyValueInfo.h"
#include "llvm/Support/GenericDomTree.h"
#include "revng/ADT/ConstantRangeSet.h"
#include "revng/MFP/MFP.h"
#include "revng/Support/Statistics.h"
#include "revng/ValueMaterializer/AdvancedValueInfo.h"
#include "revng/ValueMaterializer/ControlFlowEdgesGraph.h"
#include "revng/ValueMaterializer/DataFlowGraph.h"
#include "revng/ValueMaterializer/MemoryOracle.h"
namespace llvm {
class LazyValueInfo;
class DominatorTree;
} // namespace llvm
class DataFlowRangeAnalysis;
namespace Oracle {
enum Values {
None,
LazyValueInfo,
AdvancedValueInfo,
Count
};
} // namespace Oracle
inline RunningStatistics DFGSizeStatitistics("vm-dfg-size");
class ValueMaterializer {
private:
using ConstraintsMap = std::map<llvm::Instruction *, ConstantRangeSet>;
private:
//
// Inputs
//
llvm::Instruction *Context;
llvm::Value *V;
MemoryOracle &MO;
llvm::LazyValueInfo &LVI;
DataFlowRangeAnalysis &DFRA;
const llvm::DominatorTree &DT;
DataFlowGraph::Limits TheLimits;
Oracle::Values Oracle;
//
// Outputs
//
DataFlowGraph DataFlowGraph;
ConstraintsMap OracleConstraints;
map<const ForwardNode<ControlFlowEdgesNode> *,
MFP::MFPResult<map<llvm::Instruction *, ConstantRangeSet>>>
MFIResults;
std::optional<MaterializedValues> Values;
ControlFlowEdgesGraph CFEG;
private:
ValueMaterializer(llvm::Instruction *Context,
llvm::Value *V,
MemoryOracle &MO,
llvm::LazyValueInfo &LVI,
DataFlowRangeAnalysis &DFRA,
const llvm::DominatorTree &DT,
DataFlowGraph::Limits TheLimits,
Oracle::Values Oracle) :
Context(Context),
V(V),
MO(MO),
LVI(LVI),
DFRA(DFRA),
DT(DT),
TheLimits(TheLimits),
Oracle(Oracle) {}
public:
static ValueMaterializer getValuesFor(llvm::Instruction *Context,
llvm::Value *V,
MemoryOracle &MO,
llvm::LazyValueInfo &LVI,
DataFlowRangeAnalysis &DFRA,
const llvm::DominatorTree &DT,
DataFlowGraph::Limits TheLimits,
Oracle::Values Oracle) {
ValueMaterializer Result(Context, V, MO, LVI, DFRA, DT, TheLimits, Oracle);
Result.run();
return Result;
}
public:
const auto &dataFlowGraph() const { return DataFlowGraph; }
const auto &oracleConstraints() const { return OracleConstraints; }
const auto &mfiResult() const { return MFIResults; }
const auto &values() const { return Values; }
const auto &cfeg() const { return CFEG; }
private:
void run();
void computeOracleConstraints();
void applyOracleResultsToDataFlowGraph();
void computeSizeLowerBound();
void electMaterializationStartingPoints();
};