-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
RFC: Use JL_LLVM_VERSION instead of LLVMxx #17826
Conversation
There was some discussion of whether there should be a 3.10 version. Just to be safe, I think we can use something like |
#elif LLVM_VERSION_MINOR == 3 | ||
#define LLVM_VERSION 33 | ||
#endif | ||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Constructing LLVM_VERSION
can be done more succinctly as
#define CONCAT(a, b) a ## b
#define GETVERS(maj, min) CONCAT(maj, min)
#define LLVM_VERSION GETVERS(LLVM_VERSION_MAJOR, LLVM_VERSION_MINOR)
But as @yuyichao noted, this is the kind of thing that one gets stabbed for if put into production.
You mean check for LLVM 3.10 by doing |
No, I mean |
|
Anyther way is to use something like the glibc trick Line 153 in 3e00217
|
So something like #if _LLVM_VERSION_GE(3, 10)
where |
I get segfaults when I do |
Yes.... Maybe use |
Full patch?? |
What do you mean full patch? This is what I was doing to test: #define LLVM_VERSION_MAJOR 3
#define LLVM_VERSION_MINOR 10
#define LLVM_VERSION_PATCH 1
#define JL_LLVM_VERSION (LLVM_VERSION_MAJOR * 0x10000 + LLVM_VERSION_MINOR * 0x100 + LLVM_VERSION_PATCH)
int main() {
int x = JL_LLVM_VERSION;
printf("%s", x);
return 0;
} |
int x = JL_LLVM_VERSION;
printf("%s", x);
return 0; Why should this work at all? |
¯_(ツ)_/¯ Because I'm not good at C |
A good advice for C is to turn on |
Oh, heh, whoops. Format string... So for major version 3, minor 10, patch 1, I get 199169. How would you check the version based on that number? |
|
Do patches ever have more than two digits? |
The nope is that neither patch and minor do. Actually |
Okay, changed to use the |
I actually mean the |
|
||
#endif | ||
#if LLVM_VERSION < 0x33000 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think thse bounds are wrong. E.g. after switching to 100
, this should be 30300
LGTM other than the missing |
Okay, added the |
@@ -1,6 +1,6 @@ | |||
// This file is a part of Julia. License is MIT: http:https://julialang.org/license | |||
|
|||
#if defined(LLVM38) && !defined(LLVM37) | |||
#if defined(JL_LLVM_VERSION) && JL_LLVM_VERSION >= 30800 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the defined(JL_LLVM_VERSION)
needed here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, that's not needed. I'll take it out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMHO, we shouldn't check if JL_LLVM_VERSION
is defined. This can catch errors of missing include earlier rather than silently ignoring the error.
I looked through the diff and I think the translation is correct. Since the diff is so long, it would be better if someone else could have a look too to make sure we aren't silently disabling features on newer version of llvm. |
@@ -103,7 +103,7 @@ void addOptimizationPasses(PassManager *PM) | |||
#endif | |||
|
|||
#if defined(JL_ASAN_ENABLED) | |||
# if defined(LLVM37) && !defined(LLVM38) | |||
# if JL_LLVM_VERSION == 30700 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#if JL_LLVM_VERSION >= 30700 && JL_LLVM_VERSION < 30800
@@ -1,6 +1,6 @@ | |||
// This file is a part of Julia. License is MIT: http:https://julialang.org/license | |||
|
|||
#if defined(LLVM38) && !defined(LLVM37) | |||
#if JL_LLVM_VERSION >= 30800 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how would the old version of this ever happen?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function is also declared in jitlayers.cpp
. Doing it here might have some issue due to missing type declaration/missing headers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tkelman If 3.8 is the lowest version. So it's at least 3.8 and not 3.7 or lower.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yuyichao Should the function declaration here be removed then?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The condition is actually USE_ORCJIT && JL_LLVM_VERSION <= 30800
(roughly 3.7 <= llvm_ver < 3.8). It is better to remove the declaration in jitlayers.cpp
instead and keep this one with the condition fixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The condition there before was false
, the current condition is wrong. The correct one is in jitlayers.cpp
and is the same with the one I gave above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like it fails if I remove the part in jitlayers.cpp.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move to jitlayers.h
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
defined(LLVM38) && !defined(LLVM37)
would never happen since LLVM37
meant "3.7 or newer"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which is why I said,
The condition there before was false
This was added before the JIT and codegen are split and therefore before jitlayers.h
exists. This is needed only by jitlayers.cpp
, which doesn't include codegen_internal.h
, for LLVM 3.7.x which is why it should be moved to jitlayers.h
.
a6d63b6
to
bca6f94
Compare
cef63d2
to
0158e6c
Compare
@@ -1,6 +1,6 @@ | |||
// This file is a part of Julia. License is MIT: http:https://julialang.org/license | |||
|
|||
#if defined(LLVM38) && !defined(LLVM37) | |||
#if defined(USE_ORCJIT) && JL_LLVM_VERSION <= 30800 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since the old version of this could never be true, probably best to just delete these few lines
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think @yuyichao specifically requested this change: #17826 (comment)
(I found this a little easier to review locally after curl -L https://github.com/JuliaLang/julia/pull/17826.patch | git apply
for i in $(seq 3 9); do
sed -i -e "s/JL_LLVM_VERSION >= 30${i}00/defined(LLVM3$i)/g" \
-e "s/JL_LLVM_VERSION < 30${i}00/\!defined(LLVM3$i)/g" \
-e "s/#if defined(LLVM3$i)/#ifdef LLVM3$i/g" \
-e "s/#if \!defined(LLVM3$i)/#ifndef LLVM3$i/g" src/*.cpp src/*.h
done which gives a shorter diff) |
dd37fe8
to
8cc0383
Compare
8cc0383
to
b83e1bd
Compare
Is there anything else this needs before it's good to go? |
@@ -59,7 +59,7 @@ using namespace llvm; | |||
#include <cstdio> | |||
#include <cassert> | |||
|
|||
#if defined(LLVM35) && !defined(LLVM36) | |||
#if JL_LLVM_VERSION == 30500 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should in principle still be a range since LLVM 3.5.1 does exist. Not sure if it actually matters though since we might not compile there anyway....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed, thanks!
LGTM other than the very minor comment above. I think we should merge this now. It's unlikely that we can trivially backport all codegen changes anymore and the conflict introduced by this change should be easy to resolve. If everyone is fine with this I'd like to merge this tomorrow (with the comment above fixed or not) and rebase #18519 on top of this. |
b83e1bd
to
d9e07b5
Compare
I think there was a conflict before #18519 was merged........ So I guess this needs to be rebased again (hopefully the last time). |
d9e07b5
to
038abd2
Compare
Rebased and conflicts resolved. Thanks for the heads up! |
Reviewers should probably pay extra careful attention to future PRs that modify or introduce LLVM version conditioning in the C preprocessor, since |
should we make those defines result in compile-time errors now? maybe just for a little while? |
That seems like a good idea to me. How would you propose we go about that? I can submit a PR. |
I don't think there's a way to do it in C++ code (a grep on CI could do that though). It shouldn't be a huge issue since hopefully PR's that uses those are already tested on newer LLVM versions. |
Fixes #9860.
As noted in the linked issue, the names
LLVM37
,LLVM34
, etc. aren't immediately descriptive because they don't refer to specific versions but rather to ranges of versions. This implements the proposed fix of having a singleLLVM_VERSION
macro that holds the LLVM version as a two-digit number and instead of checking whetherLLVMxx
is defined, we check whetherLLVM_VERSION >= xx
. Similarly, checking whetherLLVMxx
is not defined equates toLLVM_VERSION < xx
.This works locally, so fingers crossed that it works everywhere else...