Stream: general

Topic: detect codegen backend


gnzlbg (Nov 20 2018 at 19:55, on Zulip):

Is there a way to detect the codegen backend being used (e.g. llvm vs cranelift) ?

gnzlbg (Nov 20 2018 at 19:55, on Zulip):

Ideally a cfg() macro ?

Jake Goulding (Nov 20 2018 at 20:22, on Zulip):

That seems like a bad thing to check. From the user's perspective there shouldn't be a difference.

gnzlbg (Nov 20 2018 at 21:12, on Zulip):

yeah, but the std library needs to be able to tell, when using backend-specific intrinsics for example

rkruppe (Nov 20 2018 at 21:13, on Zulip):

@eddyb ^

RalfJ (Nov 20 2018 at 21:42, on Zulip):

yeah, but the std library needs to be able to tell, when using backend-specific intrinsics for example

shouldnt instead the intrinsics have the same name and type and just their implementration differ?

rkruppe (Nov 20 2018 at 21:43, on Zulip):

for rustc intrinsincs yes, but i am skeptical about cranelift's ability to provide all the numerous llvm intrinsics that e.g. correspond to sse instructions

RalfJ (Nov 20 2018 at 21:44, on Zulip):

wouldn't that be more of a "does platform support feature X" flag though?

Dan Gohman (Nov 20 2018 at 21:56, on Zulip):

One of the ideas with the Cranelift backend is that we can make it automatically fall back to the LLVM backend if it encounters something it doesn't support.

Dan Gohman (Nov 20 2018 at 21:58, on Zulip):

That would be the quickest path to providing users with a working system without having to implement the entire long tail of LLVM's feature set first.

eddyb (Nov 20 2018 at 22:01, on Zulip):

also IMO using LLVM intrinsics from libraries is a complete hack that needs to be replaced at some point

eddyb (Nov 20 2018 at 22:02, on Zulip):

too bad platform-intrinsics wasn't used more

Dan Gohman (Nov 20 2018 at 22:04, on Zulip):

So to answer the original question: no, there isn't a way to detect the backend, and it's too early at this point to even predict if we'll want to add one.

gnzlbg (Nov 26 2018 at 16:36, on Zulip):

thanks @Dan Gohman that makes sense. Do you think that if Cretonne can fall back to LLVM it would make sense for stdsimd to use "platform-intrinsics" instead of link_llvm_intrinsics ? Or it would not matter ?

Dan Gohman (Nov 26 2018 at 16:40, on Zulip):

I don't know the specifics of the "platform-intrinsics" vs link_llvm_intrinsics mechanisms.

Dan Gohman (Nov 26 2018 at 16:42, on Zulip):

The basic plan is that Cranelift will implement most of the functionality of the LLVM intrinsics, though they look a little different in Cranelift's IR and builder APIs than in LLVM's.

gnzlbg (Nov 26 2018 at 16:42, on Zulip):

IIUC link_llvm_intrinsics allows using extern { fn llvm.foo.bar(...) -> .. } to call llvm intrinsics directly from Rust as if one was calling C.
"platform-intinriscs" allows importing functions that are provided by Rust, e.g., extern "platform-intrinsics" { fn foo_bar(...) -> ... }

gnzlbg (Nov 26 2018 at 16:43, on Zulip):

the difference is that Rust can change what platform intrinsics do, and provide different implementations for the different backends, while link_llvm_intrinsics cannot do that

Dan Gohman (Nov 26 2018 at 16:43, on Zulip):

Ah, ok. So yeah, Cranelift won't be providing magical functions named like "llvm.foo.bar".

gnzlbg (Nov 26 2018 at 17:17, on Zulip):

@Dan Gohman but could cranelift identify these functions and fall back to LLVM in this case ?

Dan Gohman (Nov 26 2018 at 17:21, on Zulip):

We could make that work, though in most cases, what we really want to do is implement the feature in Cranelift too :-).

gnzlbg (Nov 26 2018 at 17:22, on Zulip):

for x86, we would only need to implement ~2000 SIMD intrinsics, looks like a lot, but is a process that might be automated, the problem is how do we hook them up in stdsimd

gnzlbg (Nov 26 2018 at 17:24, on Zulip):

the logic to choose which intrinsic to emit has to be somewhere, and currently stdsimd uses link_llvm_intrinsic. @eddyb suggested moving that into rustc so that stdsimd just calls platform-intrinsics, and rustc chooses between llvm or cranelift intrinsics

gnzlbg (Nov 26 2018 at 17:24, on Zulip):

we could do that, but to me this looks like moving the problem from stdsimd into rustc, and i'm not so sure that rustc can solve it better than stdsimd does

Dan Gohman (Nov 26 2018 at 17:26, on Zulip):

In Cranelift, these things aren't calls to intrinsics. They're just instructions. Rustc seems like it's able to emit those instructions directly, while stdsimd isn't.

Last update: Nov 22 2019 at 00:05UTC