Skip to content

[StandardInstrumentations]Add support for numeric label #148844

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions llvm/lib/Passes/StandardInstrumentations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -727,8 +727,13 @@ template <typename T>
template <typename FunctionT>
bool IRComparer<T>::generateFunctionData(IRDataT<T> &Data, const FunctionT &F) {
if (shouldGenerateData(F)) {
FuncDataT<T> FD(F.front().getName().str());
int I = 0;
// Basic block with numberic label will be empty here.
std::string FDEntryBlockName = F.front().getName().str();
if (FDEntryBlockName.empty())
FDEntryBlockName = formatv("{0}", I);

FuncDataT<T> FD(FDEntryBlockName);
for (const auto &B : F) {
std::string BBName = B.getName().str();
if (BBName.empty()) {
Expand Down Expand Up @@ -1787,10 +1792,10 @@ class DotCfgDiffNode {
// Create a node in Dot difference graph \p G representing the basic block
// represented by \p BD with colour \p Colour (where it exists).
DotCfgDiffNode(DotCfgDiff &G, unsigned N, const BlockDataT<DCData> &BD,
StringRef Colour)
: Graph(G), N(N), Data{&BD, nullptr}, Colour(Colour) {}
StringRef Label, StringRef Colour)
: Graph(G), N(N), Data{&BD, nullptr}, Label(Label), Colour(Colour) {}
DotCfgDiffNode(const DotCfgDiffNode &DN)
: Graph(DN.Graph), N(DN.N), Data{DN.Data[0], DN.Data[1]},
: Graph(DN.Graph), N(DN.N), Data{DN.Data[0], DN.Data[1]}, Label(DN.Label),
Colour(DN.Colour), EdgesMap(DN.EdgesMap), Children(DN.Children),
Edges(DN.Edges) {}

Expand All @@ -1799,6 +1804,8 @@ class DotCfgDiffNode {
// The label of the basic block
StringRef getLabel() const {
assert(Data[0] && "Expected Data[0] to be set.");
assert((Data[0]->getLabel().empty() || Data[0]->getLabel() == Label) &&
"Unexpected label");
return Data[0]->getLabel();
}
// Return the colour for this block
Expand Down Expand Up @@ -1836,6 +1843,7 @@ class DotCfgDiffNode {
DotCfgDiff &Graph;
const unsigned N;
const BlockDataT<DCData> *Data[2];
StringRef Label;
StringRef Colour;
std::map<const unsigned, std::pair<std::string, StringRef>> EdgesMap;
std::vector<unsigned> Children;
Expand Down Expand Up @@ -1884,7 +1892,7 @@ class DotCfgDiff {

void createNode(StringRef Label, const BlockDataT<DCData> &BD, StringRef C) {
unsigned Pos = Nodes.size();
Nodes.emplace_back(*this, Pos, BD, C);
Nodes.emplace_back(*this, Pos, BD, Label, C);
NodePosition.insert({Label, Pos});
}

Expand Down Expand Up @@ -1946,10 +1954,9 @@ std::string DotCfgDiffNode::getBodyContent() const {
// Drop leading newline, if present.
if (BS.front() == '\n')
BS1 = BS1.drop_front(1);
// Get label.
StringRef Label = BS1.take_until([](char C) { return C == ':'; });
// drop predecessors as they can be big and are redundant
BS1 = BS1.drop_until([](char C) { return C == '\n'; }).drop_front();
if (BS1.str().find(Label) != std::string::npos)
BS1 = BS1.drop_until([](char C) { return C == '\n'; }).drop_front();

std::string S = "<FONT COLOR=\"" + Colour.str() + "\">" + Label.str() + ":";

Expand Down Expand Up @@ -1991,6 +1998,11 @@ DotCfgDiff::DotCfgDiff(StringRef Title, const FuncDataT<DCData> &Before,
EdgesMap.insert({Key, BeforeColour});
}
}
if (Before == After) {
for (auto &I : Nodes)
I.finalize(*this);
return;
}

// Handle each basic block in the after IR
for (auto &A : After.getData()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
; RUN: FileCheck %s -input-file=%t/passes.html --check-prefix=CHECK-DOT-CFG-QUIET-MULT-PASSES-FILTER-FUNC

define i32 @g() {
entry:
1:
%a = add i32 2, 3
ret i32 %a
}
Expand Down
Loading