Skip to content

[CGQuery] Refactor & add (Post) Dominator analysis#111

Open
silas-martens wants to merge 9 commits intotudasc:develfrom
silas-martens:refactor_cgquery
Open

[CGQuery] Refactor & add (Post) Dominator analysis#111
silas-martens wants to merge 9 commits intotudasc:develfrom
silas-martens:refactor_cgquery

Conversation

@silas-martens
Copy link
Contributor

This PR introduces a refactoring of CGQuery and adds Dominator and Post-dominator analysis.
The refactoring separates each analysis into its own command which cleans up the main file and is more extensible.

@TimHeldmann
Copy link
Member

Is this still a draft, or are you looking for feedback?

@silas-martens
Copy link
Contributor Author

Is this still a draft, or are you looking for feedback?

Im looking for feedback :)

@jplehr
Copy link
Member

jplehr commented Jan 23, 2026

The analysis should have unit tests.

Copy link
Member

@sebastiankreutzer sebastiankreutzer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, but I agree with JP that there should be rudimentary unit tests.


auto& doms_node1 = doms[node1].Doms;
ASSERT_TRUE(doms_node1.size() == 2);
ASSERT_TRUE(doms_node1.count(main));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why ASSERT_TRUE on something that supposedly returns a number? Is all we care that the number is != 0?

#include <string>
#include <vector>

struct Command {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is a Command?

return !s.empty() && std::all_of(s.begin(), s.end(), [](unsigned char c) { return std::isdigit(c); });
}

inline metacg::CgNode* findNode(metacg::Callgraph* cg, const std::string& spec, const std::string& role) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we already have a graph utils header in the main lib. What is the reason this is here?

#include "commands/ReachesCommand.h"
#include "utils.h"

#include <cxxopts.hpp>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This used here?

#include <cxxopts.hpp>
#include <iostream>
#include <memory>
#include <ostream>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this when iostream is already there?

DomAnalysisResult<NodeT> computeDoms(const GraphT& graph, const NodeT& exitNode);

template <typename Container>
Container unordered_intersection(const Container& a, const Container& b) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why snack case here?

using DomAnalysisResult = std::unordered_map<const NodeT*, DomData<NodeT>>;

template <typename NodeT, typename GraphT>
DomAnalysisResult<NodeT> computeDoms(const GraphT& graph, const NodeT& exitNode);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are people opinions on renaming computeDominators? I would think we can afford the additional 6 characters.

}

template <typename NodeT, typename GraphT, TraverseDir dir>
DomAnalysisResult<NodeT> computeDoms(const GraphT& graph, const NodeT& exitNode) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also here computeDominators?

return graph.getCallees(*n);
};

using DomDataT = DomData<NodeT>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this move to beginning of scope?

typename DomDataT::NodeSet DomNew = intersection(initializedCallees, DomMap);
DomNew.insert(nodeData.node);

// LOG_STATUS("New Doms " << dumpNodeSet(nodeData.node->getName(), DomNew) << "\n");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants