#What is the zig compiler doing when we give him a .bc file (LLVM bitcode)?

1 messages ยท Page 1 of 1 (latest)

austere furnace
#

I tried compiling some random webassembly module and using -femit-llvm-bc but if I compile this emitted bitcode it just produce an unoptimized version of the previous module

subtle brook
#

What are you seeking to accomplish?
Only I think that's what I'd expect, assuming that you asked Zig to build in debubg mode. (Or didn't specify.)

austere furnace
# subtle brook What are you seeking to accomplish? Only I think that's what I'd expect, assumin...

I'm currently learning to write LLVM passes and thought it would be fun to run it on those emitted bitcode, here are the 2 commands I used to compile
zig build-lib src/main.zig -target wasm32-freestanding -dynamic -rdynamic -O ReleaseSafe -femit-llvm-bc=module.bc
zig build-lib module.bc -target wasm32-freestanding -dynamic -rdynamic -O ReleaseSafe
So I was wondering what is the zig compiler exactly doing? I can't remember where I saw this but iirc zig doesn't use LLVM as a backend for wasm so it might be why

subtle brook
#

Hmmm. I'm not sure. That might be a bug. I'm not sure that Zig supports compiling LLVM bitcode using zig build-lib like that. ๐Ÿค”

#

I suppose it might if LLVM is enabled in Zig, but I'm just guessing there.

austere furnace
#

That would make sense

subtle brook
#

But I would expect that the bitcode produced by the first invocation would be built in releasesmall mode, for the record.

#

Though, that's probably not used very much (-femit-llvm-bc) - so might have bitrotted or otherwise be bugged.

austere furnace
#

What I noticed is that the llvm IR produced is super close to the actual wasm output

subtle brook
#

You could try running LLVM's WASM optimizer on it and see how much changes. ๐Ÿค”

#

LLVM, if you acquire it separately, comes with something like llvm-opt (I forget what its called)

#

But it's for optimizing WASM IIRC.

austere furnace
#

Yup

#

Thanks for the hindsight I'll do some more digging ๐Ÿ˜‚

subtle brook
#

๐Ÿ‘ ๐Ÿ˜„ o7