Skip to content

Update ref-op pruning pass to use remarks API for stats tracking #855

Open
@stuartarchibald

Description

@stuartarchibald

Following on from #837, which adds support for obtaining remarks from LLVM passes. It should now be possible to update the RefPrunePass, which does Numba specific ref-op pruning, to emit remarks and for them to be consumed by this API. This would effectively replace this:

static size_t stats_per_bb;
static size_t stats_diamond;
static size_t stats_fanout;
static size_t stats_fanout_raise;

and this:

llvmlite/ffi/custom_passes.cpp

Lines 1178 to 1210 in dfca79f

/**
* Struct for holding statistics about the amount of pruning performed by
* each type of pruning algorithm.
*/
typedef struct PruneStats {
size_t basicblock;
size_t diamond;
size_t fanout;
size_t fanout_raise;
} PRUNESTATS;
API_EXPORT(void)
LLVMPY_DumpRefPruneStats(PRUNESTATS *buf, bool do_print) {
/* PRUNESTATS is updated with the statistics about what has been pruned from
* the RefPrunePass static state vars. This isn't threadsafe but neither is
* the LLVM pass infrastructure so it's all done under a python thread lock.
*
* do_print if set will print the stats to stderr.
*/
if (do_print) {
errs() << "refprune stats "
<< "per-BB " << RefPrunePass::stats_per_bb << " "
<< "diamond " << RefPrunePass::stats_diamond << " "
<< "fanout " << RefPrunePass::stats_fanout << " "
<< "fanout+raise " << RefPrunePass::stats_fanout_raise << " "
<< "\n";
};
buf->basicblock = RefPrunePass::stats_per_bb;
buf->diamond = RefPrunePass::stats_diamond;
buf->fanout = RefPrunePass::stats_fanout;
buf->fanout_raise = RefPrunePass::stats_fanout_raise;
}

and also allowing tracking of the source line origin of the pruned ref-ops (which is interesting in itself).

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions