Skip to content

Commit 2be7c65

Browse files
authored
[clang][dataflow] HTML logger: Mark iterations that have converged. (#68204)
I've eliminated the `logText("Block converged")` call entirely because a) These logs are associated with an individual `CFGElement`, while convergence should be associated with a block, and b) The log message was being associated with the wrong block: `recordState()` dumps all of the pending log messages, but `blockConverged()` is called after the last `recordState()` call for a given block, so that the "Block converged" log message was being associated with the first element of the _next_ block to be processed. Example: ![image](https://github.com/llvm/llvm-project/assets/29098113/6a19095c-2dbb-4771-9485-e8e45c9d26fb)
1 parent cf80def commit 2be7c65

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

clang/lib/Analysis/FlowSensitive/HTMLLogger.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ class HTMLLogger : public Logger {
150150
const CFGBlock *Block;
151151
unsigned Iter;
152152
bool PostVisit;
153+
bool Converged;
153154
};
154155

155156
StreamFactory Streams;
@@ -159,8 +160,8 @@ class HTMLLogger : public Logger {
159160
const ControlFlowContext *CFG;
160161
// Timeline of iterations of CFG block visitation.
161162
std::vector<Iteration> Iters;
162-
// Number of times each CFG block has been seen.
163-
llvm::DenseMap<const CFGBlock *, llvm::SmallVector<Iteration>> BlockIters;
163+
// Indexes in `Iters` of the iterations for each block.
164+
llvm::DenseMap<const CFGBlock *, llvm::SmallVector<size_t>> BlockIters;
164165
// The messages logged in the current context but not yet written.
165166
std::string ContextLogs;
166167
// The number of elements we have visited within the current CFG block.
@@ -207,6 +208,7 @@ class HTMLLogger : public Logger {
207208
JOS->attribute("block", blockID(E.Block->getBlockID()));
208209
JOS->attribute("iter", E.Iter);
209210
JOS->attribute("post_visit", E.PostVisit);
211+
JOS->attribute("converged", E.Converged);
210212
});
211213
}
212214
});
@@ -222,10 +224,10 @@ class HTMLLogger : public Logger {
222224
}
223225

224226
void enterBlock(const CFGBlock &B, bool PostVisit) override {
225-
llvm::SmallVector<Iteration> &BIter = BlockIters[&B];
227+
llvm::SmallVector<size_t> &BIter = BlockIters[&B];
226228
unsigned IterNum = BIter.size() + 1;
227-
BIter.push_back({&B, IterNum, PostVisit});
228-
Iters.push_back({&B, IterNum, PostVisit});
229+
BIter.push_back(Iters.size());
230+
Iters.push_back({&B, IterNum, PostVisit, /*Converged=*/false});
229231
ElementIndex = 0;
230232
}
231233
void enterElement(const CFGElement &E) override {
@@ -290,7 +292,7 @@ class HTMLLogger : public Logger {
290292
}
291293
});
292294
}
293-
void blockConverged() override { logText("Block converged"); }
295+
void blockConverged() override { Iters.back().Converged = true; }
294296

295297
void logText(llvm::StringRef S) override {
296298
ContextLogs.append(S.begin(), S.end());
@@ -301,13 +303,15 @@ class HTMLLogger : public Logger {
301303
// Write the CFG block details.
302304
// Currently this is just the list of elements in execution order.
303305
// FIXME: an AST dump would be a useful view, too.
304-
void writeBlock(const CFGBlock &B, llvm::ArrayRef<Iteration> ItersForB) {
306+
void writeBlock(const CFGBlock &B, llvm::ArrayRef<size_t> ItersForB) {
305307
JOS->attributeObject(blockID(B.getBlockID()), [&] {
306308
JOS->attributeArray("iters", [&] {
307-
for (const auto &Iter : ItersForB) {
309+
for (size_t IterIdx : ItersForB) {
310+
const Iteration &Iter = Iters[IterIdx];
308311
JOS->object([&] {
309312
JOS->attribute("iter", Iter.Iter);
310313
JOS->attribute("post_visit", Iter.PostVisit);
314+
JOS->attribute("converged", Iter.Converged);
311315
});
312316
}
313317
});

clang/lib/Analysis/FlowSensitive/HTMLLogger.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
{{entry.block}}
4646
<template data-if="entry.post_visit">(post-visit)</template>
4747
<template data-if="!entry.post_visit">({{entry.iter}})</template>
48+
<template data-if="entry.converged"> &#x2192;&#x7c;<!--Rightwards arrow, vertical line--></template>
4849
</div>
4950
</template>
5051
</section>
@@ -62,6 +63,7 @@
6263
<a class="chooser {{selection.bb}}:{{iter.iter}}" data-iter="{{selection.bb}}:{{iter.iter}}">
6364
<template data-if="iter.post_visit">Post-visit</template>
6465
<template data-if="!iter.post_visit">Iteration {{iter.iter}}</template>
66+
<template data-if="iter.converged"> &#x2192;&#x7c;<!--Rightwards arrow, vertical line--></template>
6567
</a>
6668
</template>
6769
</div>

0 commit comments

Comments
 (0)