Skip to content
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

Adapt to LLVM 16 #51591

Merged
merged 2 commits into from Oct 28, 2023
Merged

Adapt to LLVM 16 #51591

merged 2 commits into from Oct 28, 2023

Conversation

vchuravy
Copy link
Sponsor Member

@vchuravy vchuravy commented Oct 4, 2023

I love C++ so much...

starts the slog towards upgrading us to LLVM 16 and C++17.

@brenhinkeller brenhinkeller added the llvm For issues that relate to LLVM label Oct 5, 2023
@giordano giordano changed the title Adopt to LLVM 16 Adapt to LLVM 16 Oct 5, 2023
Make.inc Outdated Show resolved Hide resolved
@Robert-j7
Copy link

One general question, why not just skip LLVM 16 and go straight to LLVM 17?

@giordano
Copy link
Contributor

giordano commented Oct 5, 2023

One general question, why not just skip LLVM 16 and go straight to LLVM 17?

"just" and "straight" are easier said than done: we started the effort to build llvm 16 5 months ago, and that's not even fully done yet.

@vchuravy
Copy link
Sponsor Member Author

vchuravy commented Oct 5, 2023

One general question, why not just skip LLVM 16 and go straight to LLVM 17?

Are you volunteering to do that work? LLVM updates are tedious, fraught with risk and while it might be nice to skip an entire version you end up with more work and less ability to find out when something broke, because you can't bisect the middle.

If anyone wants to get involve getting the LLVM 16 build into Yggdrasil and looking at LLVM 17 in Yggdrasil would be a major contribution.

@vchuravy
Copy link
Sponsor Member Author

vchuravy commented Oct 5, 2023

Okay two remaining source files...

make[1]: *** [/home/vchuravy/src/julia/src/Makefile:240: pipeline.dbg.obj] Error 1
make[1]: *** [/home/vchuravy/src/julia/src/Makefile:240: jitlayers.dbg.obj] Error 1

The pipeline failures are:

/home/vchuravy/src/julia/src/pipeline.cpp: In function 'void buildEarlySimplificationPipeline(llvm::ModulePassManager&, llvm::PassBuilder*, llvm::OptimizationLevel, const OptimizationOptions&)':
/home/vchuravy/src/julia/src/pipeline.cpp:345:33: error: use of deleted function 'llvm::PassManager<llvm::Module>::PassManager(const llvm::PassManager<llvm::Module>&)'
  345 |     invokePipelineStartCallbacks(MPM, PB, O);
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~

Which makes me think that we are missing one of @pchintalapudi patches from LLVM 15.

@vchuravy
Copy link
Sponsor Member Author

vchuravy commented Oct 6, 2023

Okay @pchintalapudi this is probably ready for a first review.

definitly didn't do the memory attribute transition correctly since:

Attribute 'readnone' does not apply to functions!
  %10 = call nonnull ptr @julia.pointer_from_objref(ptr addrspace(11) %9) #3
Attribute 'readnone' does not apply to functions!
  %33 = call nonnull ptr @julia.pointer_from_objref(ptr addrspace(11) %32) #3
Attribute 'readnone' does not apply to functions!

@vchuravy
Copy link
Sponsor Member Author

vchuravy commented Oct 6, 2023

cat deps/llvm.version
# -*- makefile -*-

## jll artifact
LLVM_JLL_NAME := libLLVM
LLVM_ASSERT_JLL_VER := 15.0.7+8
## source build
# Version number of LLVM
LLVM_VER := 16.0.6
# Git branch name in `LLVM_GIT_URL` repository
LLVM_BRANCH=julia-16.0.6-0
# Git ref in `LLVM_GIT_URL` repository
LLVM_SHA1=julia-16.0.6-0

## Following options are used to automatically fetch patchset from Julia's fork.  This is
## useful if you want to build an external LLVM while still applying Julia's patches.
# Set to 1 if you want to automatically apply Julia's patches to a different fork of LLVM.
LLVM_APPLY_JULIA_PATCHES := 0
# GitHub repository to use for fetching the Julia patches to apply to LLVM source code.
LLVM_JULIA_DIFF_GITHUB_REPO := https://github.com/llvm/llvm-project
# Base GitHub ref for generating the diff.
LLVM_BASE_REF := llvm:llvmorg-16.0.6
# Julia fork's GitHub ref for generating the diff.
LLVM_JULIA_REF := JuliaLang:julia-16.0.6-0

with

cat Make.user
USE_BINARYBUILDER_LLVM:=0
DEPS_GIT=1

FORCE_ASSERTIONS=1
LLVM_ASSERTIONS=1

LLVM_DEBUG=2
override JULIA_BUILD_MODE=debug

@@ -98,7 +102,9 @@ struct OptimizationOptions {

struct NewPM {
std::unique_ptr<TargetMachine> TM;
#if JL_LLVM_VERSION < 160000
StandardInstrumentations SI;
Copy link
Member

Choose a reason for hiding this comment

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

Removing all of StandardInstrumentations is not an option since we rely on print-before and print-after for testing, if upstream won't go back and remove the LLVMContext argument in the constructor then we need to create our own standardinstrumentations class that behaves the way we want it to.

Copy link
Sponsor Member

Choose a reason for hiding this comment

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

https://reviews.llvm.org/D137149 we can either try to copy the code and maintain our own copies of it, or move this state hidden behind the same ThreadSafeContext as controls the LLVMContext. I think I prefer the latter

Copy link
Sponsor Member Author

Choose a reason for hiding this comment

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

That would mean creating a pass pipeline per module, certainly doable but we should measure the cost that has.

Copy link
Sponsor Member

Choose a reason for hiding this comment

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

Just per context

src/codegen.cpp Outdated Show resolved Hide resolved
src/ccall.cpp Outdated Show resolved Hide resolved
src/codegen.cpp Outdated Show resolved Hide resolved
@vchuravy vchuravy removed the request for review from aviks October 7, 2023 17:25
@@ -351,7 +350,12 @@ static void buildEarlySimplificationPipeline(ModulePassManager &MPM, PassBuilder
FPM.addPass(DCEPass());
FPM.addPass(SimplifyCFGPass(basicSimplifyCFGOptions()));
if (O.getSpeedupLevel() >= 1) {
#if JL_LLVM_VERSION >= 160000
// TODO check the LLVM 15 default.
FPM.addPass(SROAPass(SROAOptions::PreserveCFG));
Copy link
Sponsor Member

Choose a reason for hiding this comment

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

Copy link
Sponsor Member Author

Choose a reason for hiding this comment

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

Thanks for digging that up. So we should use PreserveCFG late in the pipeline and ModifyCFG early on.

@@ -98,7 +102,9 @@ struct OptimizationOptions {

struct NewPM {
std::unique_ptr<TargetMachine> TM;
#if JL_LLVM_VERSION < 160000
StandardInstrumentations SI;
Copy link
Sponsor Member

Choose a reason for hiding this comment

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

https://reviews.llvm.org/D137149 we can either try to copy the code and maintain our own copies of it, or move this state hidden behind the same ThreadSafeContext as controls the LLVMContext. I think I prefer the latter

src/llvm-codegen-shared.h Outdated Show resolved Hide resolved
@vchuravy vchuravy marked this pull request as ready for review October 20, 2023 14:25
@vchuravy vchuravy added the merge me PR is reviewed. Merge when all tests are passing label Oct 26, 2023
@vchuravy
Copy link
Sponsor Member Author

This should be NFC for now so let's land this.

Co-authored-by: Gabriel Baraldi <baraldigabriel@gmail.com>
Co-authored-by: Prem Chintalapudi <prem.chintalapudi@gmail.com>
Co-authored-by: Jameson Nash <vtjnash@gmail.com>
@IanButterworth
Copy link
Sponsor Member

Build is failing

@IanButterworth IanButterworth removed the merge me PR is reviewed. Merge when all tests are passing label Oct 28, 2023
@vchuravy
Copy link
Sponsor Member Author

Build is failing

Stupid rebase mistakes.

@vchuravy vchuravy merged commit 81abb6d into master Oct 28, 2023
7 checks passed
@vchuravy vchuravy deleted the vc/llvm16 branch October 28, 2023 21:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
llvm For issues that relate to LLVM
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants