This is an archive of the discontinued LLVM Phabricator instance.

[llvm-extract] Add option for recursive extraction
ClosedPublic

Authored by loladiro on Apr 5 2017, 1:22 PM.

Details

Summary

Particularly, with --delete, this can be very useful for testing
new optimizations on some hotspots, without having to run it on the whole
application. E.g. as such:

llvm-extract app.bc --recursive --rfunc .*hotspot.* > hotspot.bc
llvm-extract app.bc --recursive --delete --rfunc .*hotspot.* > residual.bc
llc -filetype=obj residual.bc > residual.o
# Play with hotspot.bc here
llc -filetype=obj hotspot.bc > hotspot.o
cc -o app residual.o hotspot.o

Event Timeline

loladiro created this revision.Apr 5 2017, 1:22 PM
davide requested changes to this revision.Apr 6 2017, 11:18 AM
davide added a subscriber: davide.

Please add a basic test and a test with mutually recursive calls. The basic logic seems fine to me, some nits (sorry for being pedantic).

tools/llvm-extract/llvm-extract.cpp
236

explicit type when non-obvious.

244

Can we have a slightly better diagnostic here? Something like Cannot materialize function F + F->getName().

245

I generally prefer early continue to avoid many levels of nesting (there are a few in this case), so I'd rewrite the loop as:

for (...) {
  auto *CI = dyn_cast<>();
  if (!CI)
    continue;
  [...]
}

but I don't feel strong about it, so, up to you.

247

and probably auto when the type is obvious`.

This revision now requires changes to proceed.Apr 6 2017, 11:18 AM
davide added inline comments.Apr 6 2017, 11:19 AM
tools/llvm-extract/llvm-extract.cpp
21–23

Also this reordering seems unrelated? I think it's a good cleanup but can be committed separately (without pre-commit code review).

loladiro updated this revision to Diff 94427.Apr 6 2017, 1:00 PM
loladiro edited edge metadata.

Address review comments

loladiro added inline comments.Apr 6 2017, 1:02 PM
tools/llvm-extract/llvm-extract.cpp
21–23

I run git clang-format as a commit hook and it reorders the include list. Happy to commit separately, but I though the general policy on that was just to put formatting changes into the commit where you're editing the code.

244

IIRC, ExitOnError will add diagnostics if the Error object provides them.

davide accepted this revision.Apr 6 2017, 1:13 PM

LGTM

This revision is now accepted and ready to land.Apr 6 2017, 1:13 PM
This revision was automatically updated to reflect the committed changes.