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

Add LLVM 14 support #830

Merged
merged 6 commits into from
Mar 9, 2023
Merged

Add LLVM 14 support #830

merged 6 commits into from
Mar 9, 2023

Conversation

apmasell
Copy link
Contributor

@apmasell apmasell commented Apr 5, 2022

No description provided.

@stuartarchibald
Copy link
Contributor

Thanks for starting work on LLVM 14 support. In thinking about how to make it easier to review the changes needed, perhaps the following approach might work:

  • Creating a separate patch for the C++ code formatting changes, this gets merged first so as to minimise future diffs and to make it easy to spot code changes that are real vs. formatting.
  • Subsequently adding support for LLVM 14 including build and patch updates as a separate PR, then merging this next.
  • Finally adding support for the addition LLVM pass bindings/wrappers and merging this last.

What do you think?

@apmasell
Copy link
Contributor Author

apmasell commented Apr 6, 2022

Sure. I've created #831 for the code formatting changes. I'm going to leave this PR open so I can use it for the build farm.

@stuartarchibald
Copy link
Contributor

Sure. I've created #831 for the code formatting changes. I'm going to leave this PR open so I can use it for the build farm.

Thanks, keeping this open for testing purposes sounds like a good plan.

@stuartarchibald stuartarchibald added this to the 0.39.0 RC milestone Apr 8, 2022
@sklam sklam modified the milestones: 0.39.0 RC, PR Backlog Jun 1, 2022
@Hardcode84
Copy link

Hi,

Here is svml patch for llvm 14 Hardcode84/llvm-project@bc2dcd1

littlewu2508 added a commit to littlewu2508/sci that referenced this pull request Aug 4, 2022
The newset version can depend on llvm:13 which is still in ::gentoo

And there is ongoing efforts of migrating to llvm:14
See numba/llvmlite#830

Signed-off-by: Yiyang Wu <xgreenlandforwyy@gmail.com>
littlewu2508 added a commit to littlewu2508/sci that referenced this pull request Aug 4, 2022
The newset version can depend on llvm:13 which is still in ::gentoo

And there is ongoing efforts of migrating to llvm:14
See numba/llvmlite#830

Signed-off-by: Yiyang Wu <xgreenlandforwyy@gmail.com>
gentoo-bot pushed a commit to gentoo/sci that referenced this pull request Aug 7, 2022
The newset version can depend on llvm:13 which is still in ::gentoo

And there is ongoing efforts of migrating to llvm:14
See numba/llvmlite#830

Signed-off-by: Yiyang Wu <xgreenlandforwyy@gmail.com>
Closes: #1164
Signed-off-by: Andrew Ammerlaan <andrewammerlaan@gentoo.org>
{% set sha256_lld = "017a788cbe1ecc4a949abf10755870519086d058a2e99f438829aef24f0c66ce" %}
{% set shortversion = "14.0" %}
{% set version = "14.0.1" %}
{% set sha256_llvm = "1a3c2e57916c5a70153aaf0a0e6f1230d6368b9e0f4d04dcb9e039a31b1cd4e6" %}
{% set build_number = "5" %}
Copy link
Member

Choose a reason for hiding this comment

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

rmbr to reset this before merge

Comment on lines 33 to 35
- llvmdev 14.0.1 *5 # [(osx and arm64)]
- llvmdev 14.0.1 *4 # [not ((osx and arm64) or win)]
- llvmdev 14.0.1 4 # [win]
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
- llvmdev 14.0.1 *5 # [(osx and arm64)]
- llvmdev 14.0.1 *4 # [not ((osx and arm64) or win)]
- llvmdev 14.0.1 4 # [win]
- llvmdev 14.0.1

@apmasell apmasell mentioned this pull request Oct 24, 2022
@detrout
Copy link

detrout commented Oct 25, 2022

Thanks for pointing me here from the llvmlite patch.

How important are the patches to llvm itself? There seems to be a bunch of changes in the conda recipes, are those needed outside of a conda environment?

@apmasell
Copy link
Contributor Author

The patches to LLVM 14 that are included with the recipe are pretty important. Numba uses SVML and that is not in LLVM mainline and needs to be patched in. Some of the other changes are for building on different environments (MacOS and Windows can be uncooperative).

@apmasell
Copy link
Contributor Author

apmasell commented Nov 7, 2022

That's not on our roadmap yet. LLVM 15 has a number of breaking changes in the way it handles pointers, and we aren't prepared to handle those yet.

Copy link
Member

@sklam sklam left a comment

Choose a reason for hiding this comment

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

@apmasell, try vs2019 and pinning to 14.2 toolset:

conda-recipes/llvmdev/bld.bat Outdated Show resolved Hide resolved
conda-recipes/llvmdev/bld.bat Outdated Show resolved Hide resolved
@gmarkall
Copy link
Member

/azp run

@azure-pipelines
Copy link
Contributor

Azure Pipelines successfully started running 1 pipeline(s).

Copy link
Member

@sklam sklam left a comment

Choose a reason for hiding this comment

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

Before proceeding, we should get more cases. Particular, we can to see if there are other patterns if multiple exceptions of different exception type are raised.

e.g.

if cond_a:
    raise ValueError
elif cond_b:
    raise TypeError
else:
    return ok

auto operand = first->getOperand(0);
// If the operand is a constant, check if it indicates an exception
auto int_operand = dyn_cast<ConstantInt>(operand);
if (int_operand && !int_operand->isZeroValue()) {
Copy link
Member

Choose a reason for hiding this comment

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

Seems like it will always be one according to the old code.

            // and then cast the const as Metadata (Numba sets this as literal
            // 1)
            auto data = dyn_cast<ConstantAsMetadata>(operand.get());

But other negative non-zero value can indicate other non-raising condition.

Copy link
Member

Choose a reason for hiding this comment

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

See https://github.com/numba/numba/blob/9d4f82df7f0426d89b189eafc7acdc6bf719c716/numba/core/callconv.py#L473-L479. It's Numba handling the return code. For this refprune case, we used to only care about user exception. The existing Numba code seems to only ever emit 1. Numba callconv may need to clean up.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The case that is failing in the Numba repository emits a 1, so I'm not sure what's going on with the calling convetions.

if (phi_operand) {
auto arg_value = dyn_cast<ConstantInt>(
phi_operand->getIncomingValueForBlock(bb));
return arg_value && !arg_value->isZeroValue();
Copy link
Member

Choose a reason for hiding this comment

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

same as earlier, not all non-zero value means exception

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The way the LLVM constants are set up, I can only check for 0, 1, and -1. https://llvm.org/doxygen/classllvm_1_1Constant.html

Comment on lines 970 to 976
auto phi_operand = dyn_cast<PHINode>(operand);
if (phi_operand) {
auto arg_value = dyn_cast<ConstantInt>(
phi_operand->getIncomingValueForBlock(bb));
Copy link
Member

Choose a reason for hiding this comment

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

Look at PHI value for the return code is clever. That may save us needing the metadata all together.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is restricted to the cases where the PHI values contain constants. It would be a lot more effort to untangle if they were other results.

@MehdiChinoune MehdiChinoune mentioned this pull request Dec 22, 2022
@gmarkall
Copy link
Member

/azp run

@azure-pipelines
Copy link
Contributor

Azure Pipelines successfully started running 1 pipeline(s).

@gmarkall
Copy link
Member

CI was messed up because of the recent issue with it, so I'm just running the pipelines because I'm curious what the tests look like right now.

Copy link
Member

@sklam sklam left a comment

Choose a reason for hiding this comment

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

Changes needed:

@@ -371,7 +371,7 @@ def test_fanout_1(self):
self.assertEqual(stats.fanout, 3)

fanout_2 = r"""
define void @main(i8* %ptr, i1 %cond) {
define void @main(i8* %ptr, i1 %cond, i8** %excinfo) {
Copy link
Member

Choose a reason for hiding this comment

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

Is this needed? Fanout test shouldn't depend on excinfo.

llvmlite/tests/test_refprune.py Outdated Show resolved Hide resolved
Comment on lines +489 to +491
ret i32 1 ; BAD; all tails are raising without decref
bb_C:
ret i32 1, !ret_is_raise !0 ; BAD; all tails are raising without decref
ret i32 1 ; BAD; all tails are raising without decref
Copy link
Member

Choose a reason for hiding this comment

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

The original intention of the test is to verify that no pruning is done when all branches are raising. I'd suggest adding the store to excinfo for these branches so isRaising will return True.

{% set sha256_llvm = "ce8508e318a01a63d4e8b3090ab2ded3c598a50258cc49e2625b9120d4c03ea5" %}
{% set sha256_lld = "017a788cbe1ecc4a949abf10755870519086d058a2e99f438829aef24f0c66ce" %}
{% set build_number = "5" %}
{% set shortversion = "14.0" %}
Copy link
Member

Choose a reason for hiding this comment

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

We'll need split build for linux-aarch64 to use llvm11 as discussed in numba/numba#8756.

See
https://github.com/numba/llvmlite/pull/599/files#diff-a97126465bc884942a676793bbd8f9443dc410f5aa05c57d9bbf1d0ce5a6c437R2-R18 for reference.

@stuartarchibald stuartarchibald modified the milestones: PR Backlog, v0.40.0 Feb 23, 2023
@stuartarchibald
Copy link
Contributor

NOTE: need to check if any documentation needs updating.

Comment on lines -96 to -102
# run the tests, skip some on linux-32
cd ../test
if [[ $ARCH == 'i686' ]]; then
../build/bin/llvm-lit -vv Transforms Analysis CodeGen/X86
else
../build/bin/llvm-lit -vv Transforms ExecutionEngine Analysis CodeGen/X86
fi
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the reason for removing these tests? If it's because they are in build.sh perhaps they should be moved to run_test.sh?

Copy link
Member

Choose a reason for hiding this comment

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

We are having trouble getting any test to work. Deferring adding the test back to another PR given that this PR has passed buildfarm multiple times.

Copy link
Contributor

Choose a reason for hiding this comment

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

Please could a new issue be opened to track this so it's visible as to what is failing/has been tried already. I also think it is ok on this occasion to defer this work to another patch given how many runs through the build farm this has had. Many thanks.

CC @apmasell.

llvmlite/tests/test_refprune.py Outdated Show resolved Hide resolved
Comment on lines 460 to 461
# Change in behaviour: ignore bad metadata
self.assertEqual(stats.fanout_raise, 2)
Copy link
Member

Choose a reason for hiding this comment

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

The original intention is to check that pruning does not occur when there's a bad metadata; e.g. misspelled metadata name. See suggestion above.

llvmlite/tests/test_refprune.py Outdated Show resolved Hide resolved
apmasell and others added 2 commits March 7, 2023 15:02
Co-authored-by: Siu Kwan Lam <1929845+sklam@users.noreply.github.com>
Co-authored-by: Siu Kwan Lam <1929845+sklam@users.noreply.github.com>
Co-authored-by: Siu Kwan Lam <1929845+sklam@users.noreply.github.com>
@sklam sklam added Pending BuildFarm For PRs that have been reviewed but pending a push through our buildfarm and removed 4 - Waiting on reviewer labels Mar 7, 2023
@stuartarchibald
Copy link
Contributor

The installation instructions need updating from here onward:


suggest deferring this to a subsequent PR?

CXX = clang++ -std=c++11 -stdlib=libc++
CXXFLAGS = $(LLVM_CXXFLAGS)
CXX = clang++
CXXFLAGS = $(LLVM_CXXFLAGS) -O3
Copy link
Member

Choose a reason for hiding this comment

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

@apmasell, is the -O3 needed?

Copy link
Member

Choose a reason for hiding this comment

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

i am removing it in my PR

Copy link
Member

@sklam sklam left a comment

Choose a reason for hiding this comment

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

Approving for merge.
Installation docs defer to separate PR

@sklam sklam added BuildFarm Passed For PRs that have been through the buildfarm and passed 5 - Ready to merge and removed Pending BuildFarm For PRs that have been reviewed but pending a push through our buildfarm labels Mar 9, 2023
@sklam sklam merged commit a78869d into numba:main Mar 9, 2023
@apmasell apmasell deleted the llvm_14_support branch March 29, 2023 18:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
5 - Ready to merge BuildFarm Passed For PRs that have been through the buildfarm and passed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants