Skip to content

[LTO] Setup LTO pipeline and swift-lto tool #32233

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

kateinoigakukun
Copy link
Member

@kateinoigakukun kateinoigakukun commented Jun 7, 2020

Start to implement the LTO library and set up a basis of incremental testing tool named swift-lto. The swiftLTO library accepts SIB files for multi-modules, optimizes them at SIL level and emit LLVM bitcode. It will be dynamically loaded into linker to support language specific LTO.

CC: @compnerd

using RuntimeResourcePathLayout = BCRecordLayout<
RUNTIME_RESOURCE_PATH,
BCBlob
>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why serialize these? Why is it not sufficient to pass them along from the driver?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. it seems sufficient for this use.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with compnerd here.

@kateinoigakukun
Copy link
Member Author

kateinoigakukun commented Jun 9, 2020

@compnerd I want to confirm which commit style is easier to review.

  1. Always squash commits even while under reviewing
  2. Commit for each addressing change while under reviewing and squash them before merge.

@compnerd
Copy link
Member

compnerd commented Jun 9, 2020

Its definitely easier to review (at least for me) when the change is squashed into a single change. However, any change that is not directly related (e.g. refactoring or renaming) can be pulled into a separate change that can be merged prior to the change itself being in review is helpful in keeping the size of the change low.

Copy link
Contributor

@gottesmm gottesmm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Meta comment. Do we really need an extra tool here? This is going to increase link times. Can you try and fit this into another tool? Maybe we can combine this with swift-llvm-gen? That is supposed to be a tool that maps *.sil files -> llvm-ir.

using RuntimeResourcePathLayout = BCRecordLayout<
RUNTIME_RESOURCE_PATH,
BCBlob
>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with compnerd here.

@kateinoigakukun kateinoigakukun force-pushed the katei/swift-lto-tools branch 4 times, most recently from 2a2a112 to 65aa63a Compare June 9, 2020 16:57
@kateinoigakukun
Copy link
Member Author

@gottesmm Thanks for your comment. The dependent libraries are pretty much the same as sil-llvm-gen 👀 I'll combine them and make a symlink like swift-autolink-extract to separate the exec file.

@kateinoigakukun
Copy link
Member Author

@gottesmm I updated to combine the tool with sil-llvm-gen 👍

@kateinoigakukun kateinoigakukun force-pushed the katei/swift-lto-tools branch 7 times, most recently from f285e10 to c71fb6a Compare June 11, 2020 08:15

// Examine loading order
// RUN: cd %t && %swift-lto main.sib lib.sib
// RUN: cd %t && %swift-lto lib.sib main.sib
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test doesn't actually check anything ... what is the purpose of the test?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test checks that modules can be deserialized using the pipeline and ensure that the pipeline can resolve dependent modules regardless of input order.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think Im not understanding something then. The test doesn't verify that the module are deserialized and the dependency modules are resolved. It just assumes that if the process exited everything is correct.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. added more checks

if (EC)
return std::unique_ptr<llvm::raw_ostream>(nullptr);
return RawOS;
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you clarify why exact this tool is needed? This really feels like its executing sil-opt + swift-llvm-gen. Is there a reason that you cannot just pipe the tools in the test?

Copy link
Member Author

@kateinoigakukun kateinoigakukun Jun 12, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tool accepts SIB files for multiple modules and optimizes them at once. This is something swift-llvm-gen does not do. If piping sil-opt and swift-llvm-gen, it's impossible to optimize across modules.

And the main purpose of this tool is simulating linker integration without linker. So it doesn't match sil-opt and swift-llvm-gen's purposes.

Copy link
Member

@compnerd compnerd Jun 14, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But you can load the SIB file in sil-opt, run it through the pipeline and write that out, then use swift-llvm-gen to generate IR from the SIB.

If piping sil-opt and swift-llvm-gen, it's impossible to optimize across modules.

I think Im not understanding the missing piece in the tools. Can you explain that and write that up in the commit message as well? I think its critical to explain the deficiency.

And the main purpose of this tool is simulating linker integration without linker. So it doesn't match sil-opt and swift-llvm-gen's purposes.

I disagree on this. Its not simulating linker integration - its running the SIL pipeline on a set of SIB files. That is not related to linking. Running the SIL pipeline is precisely what sil-opt does. You seem to generate LLVM IR from the binary at the end, and thats precisely what swift-llvm-gen does - generates LLVM IR from SIL/SIB. That is where the disconnect is, and what Im trying to understand.

Copy link
Member Author

@kateinoigakukun kateinoigakukun Jun 14, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As you say, this swift-lto and sil-opt have the same part of roles in optimizing SIBs. But the sil-opt also accept SIL as input, whereas the LTO pipeline only accepts SIBs. The LTO pipeline accepts inputs only from linkers, so SILs will never be inputted. If LTO pipeline accepts SILs as input, the LTO pipeline becomes more complex only for testing.

For example, SIL doesn't serialize SDKPath, etc., so we have to assemble those missing pieces of information before passing input them into the pipeline.

So creating new tool that only accepts only SIBs helps keep the tool simple.

And sil-opt really depends on Frontend module that assumes that input module is always one. But LTO pipeline is independent from the module because LTO pipeline needs to be acceptable for multi-modules. This difference makes it difficult to merge these tools.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, sil-opt accepts SIL and SIB, but that makes it more flexible and keeps everything in one place :).

The flags are precisely what all the LTO work is about - its how to thread all the appropriate flags through the driver into the frontend and the linker. I think that is expected. That will also be needed for this tool.

So given that the tools can accomplish what is needed, the question is why is the new tool better than building on the existing tools? Is it going to be far more code to just add support for multiple files to sil-opt than writing a new tool?

Copy link
Member Author

@kateinoigakukun kateinoigakukun Jun 15, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps I've made a big misunderstanding. Do you mean that the linker will run sil-opt directly?

I was thinking that LTOPipeline class will be linked to the linker. And swift-lto tool was only going to be used for testing.

@kateinoigakukun kateinoigakukun force-pushed the katei/swift-lto-tools branch 4 times, most recently from 12ea471 to 459638f Compare June 14, 2020 05:17
Start to implement the LTO library and set up a basis of incremental
testing tool named `swift-lto`. The swiftLTO library  accepts SIB
files for multi-modules, optimizes them at SIL level and emit LLVM
bitcode. It will be dynamically loaded into linker to support language
specific LTO.
@kateinoigakukun kateinoigakukun force-pushed the katei/swift-lto-tools branch from 459638f to 7acfb5a Compare June 14, 2020 05:18
@@ -1384,6 +1384,7 @@ static bool serializeSIB(SILModule *SM, const PrimarySpecificPaths &PSPs,
serializationOpts.OutputPath = moduleOutputPath.c_str();
serializationOpts.SerializeAllSIL = true;
serializationOpts.IsSIB = true;
serializationOpts.SerializeOptionsForDebugging = true;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll refine after #32237 merged. I'll serialize options only when -lto=swift is given.

@MaxDesiatov MaxDesiatov changed the base branch from master to main September 24, 2020 08:45
@kateinoigakukun
Copy link
Member Author

Close as it's too stale for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants