-
-
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
Add an LLVM pass to remove Julia-specific address space information. #35645
Conversation
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 like how short this is! Would be good if we can run @code_llvm
with AS and without so that in the case one needs to debug AS information it is still easily accessible.
66b3c35
to
1a9408d
Compare
I'm not sure it's worth a dedicated option, like we don't have one for e.g. not lowering GC intrinsics (which are similarly internal to Julia's IR). |
1a9408d
to
87e7a33
Compare
Should be good to go, so if people want to review. I'd like this to be part of 1.5 as it is necessary for the SPIR-V compiler (and I'd rather not patch yet another back-end). Related to that, this PR should make it possible to remove those address space-related LLVM patches we've been carrying. |
This is probably fine, but I do have to say I'm not a fan of all the extra memory traffic and latency this introduces. |
If we switch to GlobalISel we might have to do this (https://www.youtube.com/watch?v=Oj1BNoL1jpM&t=143s) or backends need to generally start documenting which AddressSpaces are okay to be used by frontends. We can turn this off by default, but on the other hand it makes the IR much nicer to read ;) |
Yeah, the pass is not cheap:, around 2% of total LLVM pass time:
We could whitelist it for targets that are known not to care about random address spaces (like X86). But I'd definitely enable it for reflection. I'll have a look, maybe I can optimize the implementation a little. |
I removed the pass from the default pipeline, it's now only called during reflection. We can always add it back when its needed, or if specific targets require it. I also removed the NVPTX and WASM address space patches, since these aren't host targets and we can just run the address space removal pass from the respective compilers (cc @tshort, see JuliaGPU/GPUCompiler.jl#22). |
I do still think we should start a discussion with upstream about reserving some AS numbers for frontend usage and requiring the backends to ignore them. Any amount of overhead seems sad for something that could be easily fixed by an if/else in the backend. The reflection use case is legitimate and not performance sensitive of course. |
{ | ||
} | ||
|
||
Type *remapType(Type *SrcTy) |
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 algorithm here doesn't appear to have a guaranteed fixed point (it doesn't deal with the fact that PointerType->getElementType
can form cycles in the type tree). We avoid emitting any code like that, so it's probably okay for us, but probably not for upstream.
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 does LLVM typically deal with that? A Seen
set?
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.
Type *SrcTy = remapType( | ||
cast<PointerType>(Src->getType()->getScalarType()) | ||
->getElementType()); |
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.
Type *SrcTy = remapType( | |
cast<PointerType>(Src->getType()->getScalarType()) | |
->getElementType()); | |
Type *SrcTy = remapType(cast<GetElementPtrConstantExpr>(CE) | |
->getSourceElementType()); |
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 don't think we can use GetElementPtrConstantExpr, it looks like a private class?
Fixes #22414:
becomes
Maintains target-specific address spaces:
becomes: