mirror of
https://github.com/revng/revng
synced 2026-06-21 14:07:57 +00:00
c70b6f1097
Now, during the simplification of short-circuits the so called `de-optimization` is also applied to the corresponding `RegionCFGTree`. This allows us to avoid loss of information during the iterative refinement phase, which basically divides for ever the existencies of two nodes that have been cloned starting from a single original one.
81 lines
2.3 KiB
C++
81 lines
2.3 KiB
C++
/// \file BasicBlockNode.cpp
|
|
/// \brief
|
|
|
|
//
|
|
// This file is distributed under the MIT License. See LICENSE.md for details.
|
|
//
|
|
|
|
// Standard includes
|
|
#include <cstdlib>
|
|
#include <map>
|
|
#include <set>
|
|
|
|
// Local libraries includes
|
|
#include "revng-c/RestructureCFGPass/BasicBlockNode.h"
|
|
#include "revng-c/RestructureCFGPass/RegionCFGTree.h"
|
|
#include "revng-c/RestructureCFGPass/Utils.h"
|
|
|
|
using namespace llvm;
|
|
|
|
BasicBlockNode::BasicBlockNode(RegionCFG *Parent,
|
|
llvm::BasicBlock * BB,
|
|
RegionCFG *Collapsed,
|
|
ExitTypeT E,
|
|
const std::string &Name) :
|
|
ID(Parent->getNewID()),
|
|
Parent(Parent),
|
|
BB(BB),
|
|
CollapsedRegion(Collapsed),
|
|
ExitType(E),
|
|
Name(Name) {
|
|
}
|
|
|
|
void BasicBlockNode::removeNode() {
|
|
Parent->removeNode(this);
|
|
}
|
|
|
|
// TODO: Check why this implementation is really necessary.
|
|
void BasicBlockNode::printAsOperand(raw_ostream &O, bool PrintType) {
|
|
O << Name;
|
|
}
|
|
|
|
void BasicBlockNode::removeSuccessor(BasicBlockNode *Successor) {
|
|
for (auto It = Successors.begin(); It != Successors.end(); It++) {
|
|
if (*It == Successor) {
|
|
Successors.erase(It);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
void BasicBlockNode::removePredecessor(BasicBlockNode *Predecessor) {
|
|
for (auto It = Predecessors.begin(); It != Predecessors.end(); It++) {
|
|
if (*It == Predecessor) {
|
|
Predecessors.erase(It);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
using BBNodeMap = std::map<BasicBlockNode *, BasicBlockNode *>;
|
|
|
|
static void handleNeighbors(const BBNodeMap &SubstitutionMap,
|
|
BasicBlockNode::links_container & Neighbors) {
|
|
Neighbors.erase(std::remove_if(Neighbors.begin(),
|
|
Neighbors.end(),
|
|
[&SubstitutionMap](BasicBlockNode *N) {
|
|
return SubstitutionMap.count(N) == 0;
|
|
}),
|
|
Neighbors.end());
|
|
for (BasicBlockNode *&Neighbor : Neighbors) {
|
|
revng_assert(SubstitutionMap.count(Neighbor) != 0);
|
|
Neighbor = SubstitutionMap.at(Neighbor);
|
|
}
|
|
}
|
|
|
|
void BasicBlockNode::updatePointers(const BBNodeMap &SubstitutionMap) {
|
|
handleNeighbors(SubstitutionMap, Predecessors);
|
|
handleNeighbors(SubstitutionMap, Successors);
|
|
}
|