1#ifndef COMMON_COMPILER_REACHABILITY_H_
2#define COMMON_COMPILER_REACHABILITY_H_
7#include <unordered_map>
8#include <unordered_set>
11#include "frontends/common/resolveReferences/resolveReferences.h"
12#include "frontends/p4/callGraph.h"
16#include "ir/visitor.h"
17#include "lib/cstring.h"
22using DCGVertexType =
const IR::Node *;
23using DCGVertexTypeSet = std::unordered_set<DCGVertexType>;
24using ReachabilityHashType = std::unordered_map<cstring, DCGVertexTypeSet>;
29 ReachabilityHashType hash;
33 const ReachabilityHashType &getHash()
const {
return hash; }
38 if (name.name.size() == 0) {
41 auto i = hash.find(name.name);
42 if (i == hash.end()) {
43 std::unordered_set<DCGVertexType> s;
45 hash.emplace(name.name, s);
47 i->second.insert(vertex);
49 const auto *prev = name.name.findlast(
'.');
50 if (prev !=
nullptr) {
51 cstring newName = name.name.before(prev);
52 i = hash.find(newName);
53 if (i == hash.end()) {
59 bool isReachable(T start, T element)
const {
65 while (!work.empty()) {
66 auto *node = *work.begin();
67 if (node->equiv(*element)) {
71 if (visited.find(node) != visited.end()) {
74 visited.emplace(node);
75 auto edges = this->out_edges.find(node);
76 if (edges == this->out_edges.end()) {
79 for (
auto c : *(edges->second)) {
87using NodesCallGraph = ExtendedCallGraph<DCGVertexType>;
92 DCGVertexTypeSet prev;
93 std::unordered_set<DCGVertexType> visited;
94 const IR::P4Program *p4program;
99 bool preorder(
const IR::Annotation *annotation)
override;
100 bool preorder(
const IR::ConstructorCallExpression *callExpr)
override;
101 bool preorder(
const IR::MethodCallExpression *call)
override;
102 bool preorder(
const IR::MethodCallStatement *method)
override;
103 bool preorder(
const IR::P4Action *action)
override;
104 bool preorder(
const IR::P4Parser *parser)
override;
105 bool preorder(
const IR::P4Table *table)
override;
106 bool preorder(
const IR::ParserState *parserState)
override;
107 bool preorder(
const IR::P4Control *control)
override;
108 bool preorder(
const IR::P4Program *program)
override;
109 bool preorder(
const IR::P4ValueSet *valueSet)
override;
110 bool preorder(
const IR::SelectExpression *selectExpression)
override;
111 bool preorder(
const IR::IfStatement *ifStatement)
override;
112 bool preorder(
const IR::SwitchStatement *switchStatement)
override;
113 bool preorder(
const IR::StatOrDecl *statOrDecl)
override;
124 std::list<DCGVertexType> state;
132 std::list<DCGVertexType>
getState();
134 void setState(
const std::list<DCGVertexType> &);
145using ReachabilityResult = std::pair<bool, const IR::Expression *>;
161 const ReachabilityHashType &hash;
162 std::unordered_map<DCGVertexType, std::list<DCGVertexType>> userTransitions;
163 std::unordered_map<DCGVertexType, const IR::Expression *> conditions;
164 std::unordered_set<DCGVertexType> forbiddenVertexes;
172 bool eliminateAnnotations =
false);
188 std::unordered_set<DCGVertexType>
getName(std::string name);
195 static const IR::Expression *
stringToNode(std::string name);
Definition callGraph.h:41
Visitor mixin for looking up names in enclosing scopes from the Visitor::Context.
Definition resolveReferences.h:35