1 #ifndef NOM_REPRESENTATIONS_CONTROLFLOW_H 2 #define NOM_REPRESENTATIONS_CONTROLFLOW_H 4 #include "nomnigraph/Graph/Graph.h" 5 #include "nomnigraph/Representations/Compiler.h" 7 #include <unordered_map> 17 using NodeRef =
typename Subgraph<T, U>::NodeRef;
20 for (
auto pair : callbacks) {
21 pair.first->deleteDestructorCallback(pair.second);
25 void trackNode(NodeRef node) {
26 callbacks[node] = node->registerDestructorCallback([&](NodeRef n){
27 assert(hasInstruction(n) &&
"Destructor callback invoked on untracked node in BasicBlock.");
33 void untrackNode(NodeRef node) {
34 callbacks.erase(node);
35 Nodes.removeNode(node);
38 void pushInstructionNode(NodeRef node) {
39 assert(isa<Instruction>(node->data()) &&
40 "Cannot push non-instruction node to basic block.");
41 Instructions.emplace_back(node);
44 const std::vector<NodeRef> &getInstructions() {
return Instructions; }
46 const bool hasInstruction(NodeRef instr)
const {
47 return Nodes.hasNode(instr);
50 void insertInstructionBefore(NodeRef newInstr, NodeRef instr) {
51 auto it = std::find(std::begin(Instructions), std::end(Instructions), instr);
52 Instructions.insert(it, newInstr);
56 void deleteInstruction(NodeRef instr) {
57 assert(hasInstruction(instr) &&
"Instruction not in basic block.");
58 Instructions.erase(std::remove(Instructions.begin(), Instructions.end(), instr),
65 std::vector<NodeRef> Instructions;
68 std::unordered_map<NodeRef, typename Notifier<Node<T, U>>::Callback *> callbacks;
76 "ControlFlowGraph<G> must be of " 104 template <
typename G>
110 static_assert(std::is_base_of<Instruction, Phi>::value,
"Phi type must be derived from Instruction.");
111 auto dfMap = dominanceFrontierMap(cfg);
112 for (
auto pair : dfMap) {
113 for (
auto n : pair.second) {
114 printf(
"%llu -> %llu\n", (
unsigned long long)pair.first, (
unsigned long long)n);
120 template <
typename G>
122 for (
auto bbNode : cfg->getMutableNodes()) {
123 auto bb = bbNode->data().get();
124 if (bb->hasInstruction(node)) {
125 bb->deleteInstruction(node);
133 #endif // NOM_REPRESENTATIONS_CONTROLFLOW_H Effectively a constant reference to a graph.
Control flow graph is a graph of basic blocks that can be used as an analysis tool.
A simple graph implementation.
A basic block holds a reference to a subgraph of the data flow graph as well as an ordering on instru...