@@ -146,15 +146,21 @@ class ModelDumper {
146
146
};
147
147
148
148
class HTMLLogger : public Logger {
149
+ struct Iteration {
150
+ const CFGBlock *Block;
151
+ unsigned Iter;
152
+ bool PostVisit;
153
+ };
154
+
149
155
StreamFactory Streams;
150
156
std::unique_ptr<llvm::raw_ostream> OS;
151
157
std::optional<llvm::json::OStream> JOS;
152
158
153
159
const ControlFlowContext *CFG;
154
160
// Timeline of iterations of CFG block visitation.
155
- std::vector<std::pair< const CFGBlock *, unsigned > > Iters;
161
+ std::vector<Iteration > Iters;
156
162
// Number of times each CFG block has been seen.
157
- llvm::DenseMap<const CFGBlock *, unsigned > BlockIters;
163
+ llvm::DenseMap<const CFGBlock *, llvm::SmallVector<Iteration> > BlockIters;
158
164
// The messages logged in the current context but not yet written.
159
165
std::string ContextLogs;
160
166
// The number of elements we have visited within the current CFG block.
@@ -198,8 +204,9 @@ class HTMLLogger : public Logger {
198
204
JOS->attributeArray (" timeline" , [&] {
199
205
for (const auto &E : Iters) {
200
206
JOS->object ([&] {
201
- JOS->attribute (" block" , blockID (E.first ->getBlockID ()));
202
- JOS->attribute (" iter" , E.second );
207
+ JOS->attribute (" block" , blockID (E.Block ->getBlockID ()));
208
+ JOS->attribute (" iter" , E.Iter );
209
+ JOS->attribute (" post_visit" , E.PostVisit );
203
210
});
204
211
}
205
212
});
@@ -214,8 +221,11 @@ class HTMLLogger : public Logger {
214
221
*OS << llvm::StringRef (HTMLLogger_html).split (" <?INJECT?>" ).second ;
215
222
}
216
223
217
- void enterBlock (const CFGBlock &B) override {
218
- Iters.emplace_back (&B, ++BlockIters[&B]);
224
+ void enterBlock (const CFGBlock &B, bool PostVisit) override {
225
+ llvm::SmallVector<Iteration> &BIter = BlockIters[&B];
226
+ unsigned IterNum = BIter.size () + 1 ;
227
+ BIter.push_back ({&B, IterNum, PostVisit});
228
+ Iters.push_back ({&B, IterNum, PostVisit});
219
229
ElementIndex = 0 ;
220
230
}
221
231
void enterElement (const CFGElement &E) override {
@@ -243,17 +253,19 @@ class HTMLLogger : public Logger {
243
253
// - meaningful names for values
244
254
// - which boolean values are implied true/false by the flow condition
245
255
void recordState (TypeErasedDataflowAnalysisState &State) override {
246
- unsigned Block = Iters.back ().first ->getBlockID ();
247
- unsigned Iter = Iters.back ().second ;
256
+ unsigned Block = Iters.back ().Block ->getBlockID ();
257
+ unsigned Iter = Iters.back ().Iter ;
258
+ bool PostVisit = Iters.back ().PostVisit ;
248
259
JOS->attributeObject (elementIterID (Block, Iter, ElementIndex), [&] {
249
260
JOS->attribute (" block" , blockID (Block));
250
261
JOS->attribute (" iter" , Iter);
262
+ JOS->attribute (" post_visit" , PostVisit);
251
263
JOS->attribute (" element" , ElementIndex);
252
264
253
265
// If this state immediately follows an Expr, show its built-in model.
254
266
if (ElementIndex > 0 ) {
255
267
auto S =
256
- Iters.back ().first ->Elements [ElementIndex - 1 ].getAs <CFGStmt>();
268
+ Iters.back ().Block ->Elements [ElementIndex - 1 ].getAs <CFGStmt>();
257
269
if (const Expr *E = S ? llvm::dyn_cast<Expr>(S->getStmt ()) : nullptr ) {
258
270
if (E->isPRValue ()) {
259
271
if (auto *V = State.Env .getValue (*E))
@@ -289,9 +301,16 @@ class HTMLLogger : public Logger {
289
301
// Write the CFG block details.
290
302
// Currently this is just the list of elements in execution order.
291
303
// FIXME: an AST dump would be a useful view, too.
292
- void writeBlock (const CFGBlock &B, unsigned Iters ) {
304
+ void writeBlock (const CFGBlock &B, llvm::ArrayRef<Iteration> ItersForB ) {
293
305
JOS->attributeObject (blockID (B.getBlockID ()), [&] {
294
- JOS->attribute (" iters" , Iters);
306
+ JOS->attributeArray (" iters" , [&] {
307
+ for (const auto &Iter : ItersForB) {
308
+ JOS->object ([&] {
309
+ JOS->attribute (" iter" , Iter.Iter );
310
+ JOS->attribute (" post_visit" , Iter.PostVisit );
311
+ });
312
+ }
313
+ });
295
314
JOS->attributeArray (" elements" , [&] {
296
315
for (const auto &Elt : B.Elements ) {
297
316
std::string Dump;
0 commit comments