Page MenuHomePhabricator

Add llvm-modextract tool.
ClosedPublic

Authored by pcc on Nov 16 2016, 5:11 PM.

Details

Summary

This program is for testing features that rely on multi-module bitcode files.
It takes a multi-module bitcode file, extracts one of the modules and writes
it to the output file.

Diff Detail

Repository
rL LLVM

Event Timeline

pcc updated this revision to Diff 78292.Nov 16 2016, 5:11 PM
pcc retitled this revision from to Add llvm-modextract tool..
pcc updated this object.
pcc added a reviewer: mehdi_amini.
pcc added a subscriber: llvm-commits.
mehdi_amini edited edge metadata.Nov 23 2016, 8:08 PM

Could we have a cheap way to extract modules without parsing the IR?

(I assume we need D26179 to get in before we can have a test with multiple modules)

pcc added a comment.Nov 23 2016, 8:10 PM

Could we have a cheap way to extract modules without parsing the IR?

Most likely, but it would probably require a change to the bitcode format because we represent the VST offset as an offset from the start of the file rather than the start of the module.

(I assume we need D26179 to get in before we can have a test with multiple modules)

Right.

mehdi_amini accepted this revision.Nov 23 2016, 8:11 PM
mehdi_amini edited edge metadata.

LGTM.

In D26778#605102, @pcc wrote:

Could we have a cheap way to extract modules without parsing the IR?

Most likely, but it would probably require a change to the bitcode format because we represent the VST offset as an offset from the start of the file rather than the start of the module.

Right I think any relative offset should begin with the module block! I'm fine keeping this as future work.

This revision is now accepted and ready to land.Nov 23 2016, 8:11 PM
silvas added a subscriber: silvas.Nov 23 2016, 8:20 PM

This is just a drive-by comment, but you might be able to get away with less boilerplate by just teaching llvm-extract to do this. I don't feels strongly about this suggestion so do whatever you find best.

I agree with Sean! Reusing llvm-extract seems appropriate to me here.

Having a llvm-bcutils tool is a good idea, but that a larger refactoring. We should think about it, but not block committing this patch either.

LGTM.

In D26778#605102, @pcc wrote:

Could we have a cheap way to extract modules without parsing the IR?

Most likely, but it would probably require a change to the bitcode format because we represent the VST offset as an offset from the start of the file rather than the start of the module.

Right I think any relative offset should begin with the module block! I'm fine keeping this as future work.

Actually this is a problem and I think we should address it now.

The issue is that if we go with the current solution, we'll have to support "forever" the fact that a bitcode file with multiple module can have offset from the beginning of the file.
It seems to me that we have to first update the bitcode to make sure each offset start from the beginning of the module.

mehdi_amini added inline comments.Nov 28 2016, 10:58 PM
llvm/tools/llvm-modextract/llvm-modextract.cpp
53 ↗(On Diff #78292)

For symmetry with llvm-cat, can we have the same -b option:

std::error_code EC;
std::unique_ptr<tool_output_file> Out(
    new tool_output_file(OutputFilename, EC, sys::fs::F_None));
ExitOnErr(errorCodeToError(EC));
 
if (BinaryExtract) {
   // Write header
   ...
   //Dump Ms[ModuleIndex].getBuffer() in Out->os()
   ...
   return 0;
}

std::unique_ptr<Module> M = ExitOnErr(Ms[ModuleIndex].parseModule(Context));
WriteBitcodeToFile(M.get(), Out->os());
pcc updated this revision to Diff 79630.Nov 29 2016, 1:34 PM
pcc marked an inline comment as done.
pcc edited edge metadata.
  • add -b flag

Great! Thanks. LGTM.

This revision was automatically updated to reflect the committed changes.