mirror of
https://github.com/revng/revng
synced 2026-06-21 14:07:57 +00:00
47db3fdb11
While doing thie, also drop `printAccessNode()` from DLA DebugPrinter. The information about which LLVM instruction originated a given access node is already available in the csv generated by the `dla-accesses-log` logger.
81 lines
2.0 KiB
C++
81 lines
2.0 KiB
C++
//
|
|
// Copyright (c) rev.ng Srls. See LICENSE.md for details.
|
|
//
|
|
|
|
#include <algorithm>
|
|
#include <set>
|
|
|
|
#include "llvm/ADT/PostOrderIterator.h"
|
|
|
|
#include "revng/ADT/FilteredGraphTraits.h"
|
|
#include "revng/Support/Debug.h"
|
|
|
|
#include "revng-c/DataLayoutAnalysis/DLATypeSystem.h"
|
|
|
|
#include "DLAStep.h"
|
|
|
|
using namespace llvm;
|
|
|
|
static Logger<> Log("dla-prune");
|
|
|
|
namespace dla {
|
|
|
|
bool PruneLayoutNodesWithoutLayout::runOnTypeSystem(LayoutTypeSystem &TS) {
|
|
bool Changed = false;
|
|
using LTSN = LayoutTypeSystemNode;
|
|
if (Log.isEnabled())
|
|
TS.dumpDotOnFile("before-prune.dot");
|
|
if (VerifyLog.isEnabled())
|
|
revng_assert(TS.verifyDAG() and TS.verifyInheritanceTree());
|
|
|
|
std::set<const LTSN *> Visited;
|
|
std::set<LTSN *> ToRemove;
|
|
|
|
for (LTSN *Root : llvm::nodes(&TS)) {
|
|
revng_assert(Root != nullptr);
|
|
if (not isRoot(Root))
|
|
continue;
|
|
|
|
revng_log(Log, "# Starting from Root: " << Root->ID);
|
|
for (LTSN *N : post_order_ext(Root, Visited)) {
|
|
revng_log(Log, "## Visiting N: " << N->ID);
|
|
revng_log(Log, "## Is Leaf: " << isLeaf(N));
|
|
|
|
if (N->Size > 0) {
|
|
revng_log(Log, "### has size " << N->Size << " !");
|
|
continue;
|
|
}
|
|
|
|
using GT = GraphTraits<LTSN *>;
|
|
if (std::any_of(GT::child_begin(N),
|
|
GT::child_end(N),
|
|
[&ToRemove](LTSN *Chld) {
|
|
return ToRemove.count(Chld) == 0;
|
|
})) {
|
|
revng_log(Log, "### ChildHasLayout(N)!");
|
|
continue;
|
|
}
|
|
|
|
// Here N does not have valid layout, nor any of its child has.
|
|
revng_log(Log, "#### Queuing for removal: " << N->ID);
|
|
ToRemove.insert(N);
|
|
}
|
|
}
|
|
|
|
Changed = not ToRemove.empty();
|
|
|
|
for (LTSN *N : ToRemove) {
|
|
revng_log(Log, "# Removing: " << N->ID);
|
|
TS.removeNode(N);
|
|
}
|
|
|
|
if (VerifyLog.isEnabled())
|
|
revng_assert(TS.verifyDAG() and TS.verifyInheritanceTree()
|
|
and TS.verifyLeafs());
|
|
if (Log.isEnabled())
|
|
TS.dumpDotOnFile("after-prune.dot");
|
|
return Changed;
|
|
}
|
|
|
|
} // end namespace dla
|