Currently, there is no way to extract a basic block from a function easily. This patch
extends llvm-extract to extract the specified basic block(s).
Details
Diff Detail
- Repository
- rL LLVM
Event Timeline
include/llvm/Transforms/IPO.h | ||
---|---|---|
182–188 ↗ | (On Diff #128351) | The doc comment is either confusing or wrong here, I think. Could you please update it? |
lib/Transforms/IPO/BlockExtractor.cpp | ||
76–77 ↗ | (On Diff #128351) | Should this use report_fatal_error or something instead of llvm_unreachable? |
134–135 ↗ | (On Diff #128351) | These should either be fatal errors (see above comment) or asserts. "if (x) unreachable" is a strange pattern. |
136–138 ↗ | (On Diff #128351) | llvm::find_if would save a few characters, if you prefer. |
155 ↗ | (On Diff #128351) | I guess CodeExtractor takes care of naming the extracted function, but could you double check that it does the right thing for name collisions? IE, if you extract bb1 from foo, but there's already a function called foo_bb1, what happens? |
test/tools/llvm-extract/extract-block.ll | ||
3 ↗ | (On Diff #128351) | Worth checking that it got the right block? Could check for "%tmp5 = ", etc. |
test/tools/llvm-extract/extract-invalid-block.ll | ||
3 ↗ | (On Diff #128351) | typo, s/contains/contain/ (pretty sure this test doesn't pass right now) |
tools/bugpoint/ExtractFunction.cpp | ||
410 ↗ | (On Diff #128351) | Why this change? |
tools/llvm-extract/llvm-extract.cpp | ||
241–244 ↗ | (On Diff #128351) | Not sure it's worth it, but I wonder if it would make sense to allow something like "-bb func1:bb2 -bb func2:bb3" to support extracting blocks from multiple functions. |
tools/llvm-extract/llvm-extract.cpp | ||
---|---|---|
321–322 ↗ | (On Diff #131120) | On interesting side effect of the "-bb function:block" approach is that we'll probably do something kind of strange if someone calls this like "llvm-extract -func f0 -bb f0:bb1" - will the result be functions f0 and f0_bb1, or will f0 be deleted and we only get f0_bb1? I suspect the latter. This is probably fine though - it seems unlikely that someone would really want to do that. |
tools/llvm-extract/llvm-extract.cpp | ||
---|---|---|
321–322 ↗ | (On Diff #131120) | Yes, it's going to be the latter. BlockExtractor erases the existing functions. |
Looks good. If people don't like the behaviour of mixing -func and -bb we can revisit later.