15 #ifndef LLVM_IR_CFGDIFF_H 16 #define LLVM_IR_CFGDIFF_H 81 template <
typename NodePtr,
bool InverseGraph = false>
class GraphDiff {
83 UpdateMapType SuccInsert;
84 UpdateMapType SuccDelete;
85 UpdateMapType PredInsert;
86 UpdateMapType PredDelete;
91 void printMap(
raw_ostream &OS,
const UpdateMapType &M)
const {
93 for (
auto Child : Pair.second) {
95 Pair.first->printAsOperand(OS,
false);
97 Child->printAsOperand(OS,
false);
107 cfg::LegalizeUpdates<NodePtr>(Updates, LegalizedUpdates, InverseGraph);
108 for (
auto U : LegalizedUpdates) {
110 SuccInsert[U.getFrom()].push_back(U.getTo());
111 PredInsert[U.getTo()].push_back(U.getFrom());
113 SuccDelete[U.getFrom()].push_back(U.getTo());
114 PredDelete[U.getTo()].push_back(U.getFrom());
120 auto &DeleteChildren =
121 (InverseEdge != InverseGraph) ? PredDelete : SuccDelete;
122 auto It = DeleteChildren.
find(BB);
123 if (It == DeleteChildren.end())
125 auto &EdgesForBB = It->second;
126 return llvm::find(EdgesForBB, EdgeEnd) != EdgesForBB.end();
131 auto &InsertChildren =
132 (InverseEdge != InverseGraph) ? PredInsert : SuccInsert;
133 auto It = InsertChildren.
find(BB);
134 if (It == InsertChildren.end())
136 return make_range(It->second.begin(), It->second.end());
140 OS <<
"===== GraphDiff: CFG edge changes to create a CFG snapshot. \n" 141 "===== (Note: notion of children/inverse_children depends on " 142 "the direction of edges and the graph.)\n";
143 OS <<
"Children to insert:\n\t";
144 printMap(OS, SuccInsert);
145 OS <<
"Children to delete:\n\t";
146 printMap(OS, SuccDelete);
147 OS <<
"Inverse_children to insert:\n\t";
148 printMap(OS, PredInsert);
149 OS <<
"Inverse_children to delete:\n\t";
150 printMap(OS, PredDelete);
154 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) 161 using NodeRef = std::pair<DataRef, BasicBlock *>;
169 return !N.first->ignoreChild(BB, N.second,
false);
183 auto InsertVec = N.first->getAddedChildren(N.second,
false);
186 make_range<ExistingChildIterator>({
succ_begin(N.second), N.first},
188 DeletedEdgesFilter(N.second));
190 auto secondit = make_range<AddNewChildrenIterator>(
191 {InsertVec.begin(), N.first}, {InsertVec.end(), N.first});
198 auto InsertVec = N.first->getAddedChildren(N.second,
false);
201 make_range<ExistingChildIterator>({
succ_end(N.second), N.first},
203 DeletedEdgesFilter(N.second));
205 auto secondit = make_range<AddNewChildrenIterator>(
206 {InsertVec.end(), N.first}, {InsertVec.end(), N.first});
215 using NodeRef = std::pair<DataRef, BasicBlock *>;
223 return !N.first->ignoreChild(BB, N.second,
true);
230 using AddNewChildrenIterator =
234 AddNewChildrenIterator>;
237 auto InsertVec = N.first->getAddedChildren(N.second,
true);
240 make_range<ExistingChildIterator>({
pred_begin(N.second), N.first},
242 DeletedEdgesFilter(N.second));
244 auto secondit = make_range<AddNewChildrenIterator>(
245 {InsertVec.begin(), N.first}, {InsertVec.end(), N.first});
248 AddNewChildrenIterator>(firstit, secondit);
252 auto InsertVec = N.first->getAddedChildren(N.second,
true);
255 make_range<ExistingChildIterator>({
pred_end(N.second), N.first},
257 DeletedEdgesFilter(N.second));
259 auto secondit = make_range<AddNewChildrenIterator>(
260 {InsertVec.end(), N.first}, {InsertVec.end(), N.first});
263 AddNewChildrenIterator>(firstit, secondit);
269 std::pair<const GraphDiff<BasicBlock *, false> *, BasicBlock *>>
273 std::pair<const GraphDiff<BasicBlock *, true> *, BasicBlock *>>
277 std::pair<const GraphDiff<BasicBlock *, false> *, Inverse<BasicBlock *>>>
281 std::pair<const GraphDiff<BasicBlock *, true> *, Inverse<BasicBlock *>>>
285 #endif // LLVM_IR_CFGDIFF_H
This class represents lattice values for constants.
This provides a very simple, boring adaptor for a begin and end iterator into a range type...
static ChildIteratorType child_begin(NodeRef N)
std::pair< DataRef, BasicBlock *> NodeRef
static ChildIteratorType child_begin(NodeRef N)
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
LLVM_DUMP_METHOD void dump() const
bool ignoreChild(const NodePtr BB, NodePtr EdgeEnd, bool InverseEdge) const
DeletedEdgesFilter(BasicBlock *BB)
Interval::succ_iterator succ_begin(Interval *I)
succ_begin/succ_end - define methods so that Intervals may be used just like BasicBlocks can with the...
std::pair< DataRef, BasicBlock *> NodeRef
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Interval::succ_iterator succ_end(Interval *I)
iterator find(const_arg_type_t< KeyT > Val)
LLVM Basic Block Representation.
std::shared_ptr< Node > NodePtr
Short-hand for a Node pointer.
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator begin()
Interval::pred_iterator pred_begin(Interval *I)
pred_begin/pred_end - define methods so that Intervals may be used just like BasicBlocks can with the...
Interval::pred_iterator pred_end(Interval *I)
void print(raw_ostream &OS) const
bool operator()(NodeRef N) const
auto find(R &&Range, const T &Val) -> decltype(adl_begin(Range))
Provide wrappers to std::find which take ranges instead of having to pass begin/end explicitly...
static ChildIteratorType child_end(NodeRef N)
static ChildIteratorType child_end(NodeRef N)
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
GraphDiff(ArrayRef< cfg::Update< NodePtr >> Updates)
DeletedEdgesFilter(BasicBlock *BB)
SmallVectorImpl< BasicBlock *>::const_iterator vec_iterator
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
A range adaptor for a pair of iterators.
This file provides various utilities for inspecting and working with the control flow graph in LLVM I...
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
iterator_range< filter_iterator< detail::IterOfRange< RangeT >, PredicateT > > make_filter_range(RangeT &&Range, PredicateT Pred)
Convenience function that takes a range of elements and a predicate, and return a new filter_iterator...
iterator_range< typename SmallVectorImpl< NodePtr >::const_iterator > getAddedChildren(const NodePtr BB, bool InverseEdge) const
SmallVectorImpl< BasicBlock *>::const_iterator vec_iterator
bool operator()(NodeRef N) const
This class implements an extremely fast bulk output stream that can only output to a stream...
Specialization of filter_iterator_base for forward iteration only.
Iterator wrapper that concatenates sequences together.