This is an archive of the discontinued LLVM Phabricator instance.

Convert CoreInputGraph.
ClosedPublic

Authored by ruiu on Dec 14 2014, 9:13 PM.

Details

Summary

This is a part of InputGraph cleanup to represent input files as a flat list of Files (and some meta-nodes for group etc.)

We cannot achieve that goal in one gigantic patch (well, I could, but no one wants to review such patch), so I split the task into small steps as shown below.

(But before that, recap the progress I've made so far: Currently InputGraph contains a list of InputElements. Each InputElement contain one File (that used to have multiple Files, but I eliminated that use case in r223867). Files are currently instantiated in Driver::link(), but I already made a change to separate file parsing from object instantiation (r224102), so we can safely instantiate Files when we need them, instead of instantiating them through the wrapper class (FileNode subclasses). InputGraph used to have a logic to act like a generator by interpreting groups itself, but it's now just a container of a list of InputElements (r223867). The logic has moved to the resolver.)

  1. Instantiate Files in the driver and wrap them with WrapperNode. WrapperNode is a temporary class that allows us to instantiate Files in the driver while keep using the current InputGraph data structure.

This patch demonstrates how this step 1 looks like, using Core driver as an example.

  1. Do the same thing for the other drivers.

When step 2 is done, an InputGraph consists of GroupEnd objects or WrapperNodes each of which contains one File. Other types of FileNode subclasses are gone.

  1. Replace InputGraph with a list of InputElements. InputGraph is already just a container of InputElement list, so this step retires the wrapper.
  1. Replace WrapperNode with File to remove the temporary scaffolding.

We need some code cleanup between each step, because many classes do a bit odd things (e.g. InputGraph::getGroupSize()). I'll straight things up as I need to.

After step 4, we can clean things up by removing code that was written to work-around InputGraph limitation (e.g. LinkingContext::maybeSortInputFile). But that's a future plan atm.

So, that's a plan. Please review!

Diff Detail

Event Timeline

ruiu updated this revision to Diff 17265.Dec 14 2014, 9:13 PM
ruiu retitled this revision from to Convert CoreInputGraph..
ruiu updated this object.
ruiu edited the test plan for this revision. (Show Details)
ruiu added a project: lld.
ruiu added a subscriber: Unknown Object (MLST).
shankarke added inline comments.Dec 14 2014, 9:57 PM
include/lld/Core/File.h
270–299

parseFile could still return an error code. If we want to just use this class for error reporting purposes, this classes could go in the unittests for InputGraph.

include/lld/Driver/WrapperInputGraph.h
22–27

We would need to move this to CoreInputGraph.

lib/Driver/CoreDriver.cpp
154–159

couldnt the InputElement determine that a file has not been created and automatically create a File at parsing time ?

lib/Driver/Driver.cpp
10–13

sort includes.

39–50

The driver should not know about ArchiveLibraryFiles. This increases the circular dependency when building lld as a shared library.

60–61

FileNode::parse would need to check if wholeArchive is set and parse all members, why is this being done in the Driver ?

ruiu added inline comments.Dec 14 2014, 10:16 PM
include/lld/Core/File.h
270–299

It doesn't sound like a good idea. What do we get from making parseFile return an error? The behavior remains the same in practice, but it needs more code and more interface to customize the behavior.

include/lld/Driver/WrapperInputGraph.h
22–27

No it's not. As I wrote in the description, this is going to be used by all drivers.

lib/Driver/Driver.cpp
10–13

Will do.

39–50

That's not a problem. ArchiveLibraryFile is in include/lld/Core. include/lld/Driver can depends on Core. No one in Core should depends on Driver. If there's a circular dependency between Driver and Core, we need to eliminate the dependency from Core to Driver, not the opposite one.

60–61

As I wrote in the description, we are going to represent a input file list as a File list. FileNode's features are being deprecated.

atanasyan accepted this revision.Dec 17 2014, 1:34 PM
atanasyan edited edge metadata.

LGTM But please wait one more +1 at least

This revision is now accepted and ready to land.Dec 17 2014, 1:34 PM
ruiu added a comment.Dec 23 2014, 10:39 PM

Ping. (I'm sure this is not a good timing, but this is blocking many
follow-up patches...)

Bigcheese accepted this revision.Jan 6 2015, 12:33 PM
Bigcheese edited edge metadata.

lgtm

kledzik edited edge metadata.Jan 6 2015, 12:53 PM

LGTM

Two comments:

  1. This refactoring has taken so many steps, I'm beginning to think one big patch where we can see the end design might have been better...
  2. The ErrorFile concept makes me wonder if that should be the approach for all parseFile() implementations. Rather than having a result parameter is that is a vector they append to and returning an error_code, they simply return a vector of Files and any errors are encoded as ErrorFiles in that vector.
ruiu added a comment.Jan 6 2015, 1:06 PM

Thank you for reviewing!

atanasyan resigned from this revision.Feb 3 2016, 12:29 AM
atanasyan removed a reviewer: atanasyan.
Eugene.Zelenko added a subscriber: Eugene.Zelenko.

Committed in r225313.

lib/Driver/Driver.cpp