14#ifndef LLVM_SUPPORT_CFGDIFF_H
15#define LLVM_SUPPORT_CFGDIFF_H
36template <
typename Range>
38 return std::forward<Range>(R);
41template <
typename Range>
56template <
typename NodePtr,
bool InverseGraph = false>
class GraphDiff {
57 struct DeletesInserts {
68 bool UpdatedAreReverseApplied;
75 void printMap(
raw_ostream &OS,
const UpdateMapType &M)
const {
76 StringRef DIText[2] = {
"Delete",
"Insert"};
78 for (
unsigned IsInsert = 0; IsInsert <= 1; ++IsInsert) {
79 OS << DIText[IsInsert] <<
" edges: \n";
80 for (
auto Child : Pair.second.DI[IsInsert]) {
82 Pair.first->printAsOperand(OS,
false);
84 Child->printAsOperand(OS,
false);
95 bool ReverseApplyUpdates =
false) {
97 for (
auto U : LegalizedUpdates) {
100 Succ[U.getFrom()].DI[IsInsert].push_back(U.getTo());
101 Pred[U.getTo()].DI[IsInsert].push_back(U.getFrom());
103 UpdatedAreReverseApplied = ReverseApplyUpdates;
107 return make_range(LegalizedUpdates.begin(), LegalizedUpdates.end());
113 assert(!LegalizedUpdates.empty() &&
"No updates to apply!");
114 auto U = LegalizedUpdates.pop_back_val();
117 auto &SuccDIList = Succ[U.getFrom()];
118 auto &SuccList = SuccDIList.DI[IsInsert];
119 assert(SuccList.back() == U.getTo());
121 if (SuccList.empty() && SuccDIList.DI[!IsInsert].empty())
122 Succ.erase(U.getFrom());
124 auto &PredDIList = Pred[U.getTo()];
125 auto &PredList = PredDIList.DI[IsInsert];
126 assert(PredList.back() == U.getFrom());
128 if (PredList.empty() && PredDIList.DI[!IsInsert].empty())
129 Pred.erase(U.getTo());
135 using DirectedNodeT =
136 std::conditional_t<InverseEdge, Inverse<NodePtr>, NodePtr>;
143 auto &Children = (InverseEdge != InverseGraph) ? Pred : Succ;
144 auto It = Children.find(
N);
145 if (It == Children.end())
149 for (
auto *Child : It->second.DI[0])
153 auto &AddedChildren = It->second.DI[1];
160 OS <<
"===== GraphDiff: CFG edge changes to create a CFG snapshot. \n"
161 "===== (Note: notion of children/inverse_children depends on "
162 "the direction of edges and the graph.)\n";
163 OS <<
"Children to delete/insert:\n\t";
165 OS <<
"Inverse_children to delete/insert:\n\t";
170#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
This file defines the little GraphTraits<X> template class that should be specialized by classes that...
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
auto getLegalizedUpdates() const
SmallVector< MachineBasicBlock *, 8 > VectRet
void print(raw_ostream &OS) const
LLVM_DUMP_METHOD void dump() const
VectRet getChildren(NodePtr N) const
GraphDiff(ArrayRef< cfg::Update< NodePtr > > Updates, bool ReverseApplyUpdates=false)
cfg::Update< NodePtr > popUpdateForIncrementalUpdates()
unsigned getNumLegalizedUpdates() const
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
This class implements an extremely fast bulk output stream that can only output to a stream.
This provides a very simple, boring adaptor for a begin and end iterator into a range type.
void LegalizeUpdates(ArrayRef< Update< NodePtr > > AllUpdates, SmallVectorImpl< Update< NodePtr > > &Result, bool InverseGraph, bool ReverseResultOrder=false)
These are wrappers over isa* function that allow them to be used in generic algorithms such as llvm:a...
auto reverse_if(Range &&R)
auto reverse_if_helper(Range &&R, std::bool_constant< false >)
This is an optimization pass for GlobalISel generic memory operations.
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
void append_range(Container &C, Range &&R)
Wrapper function to append range R to container C.
void erase(Container &C, ValueType V)
Wrapper function to remove a value from a container:
auto reverse(ContainerTy &&C)
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
iterator_range< typename GraphTraits< GraphType >::ChildIteratorType > children(const typename GraphTraits< GraphType >::NodeRef &G)