I see, thanks. Yeah, you can write your own LLVM IR passes and run them on
the combined bc, that should be safe to do.

I'm not sure about where it would be easiest to do function removal, though:

 * To do it in LLVM IR, the pass itself would be pretty easy, but you'd
need to maintain a fork of LLVM (unless you get them to accept it upstream).
 * Doing it on asm.js should be easy,  we can add a js optimizer pass for
that.
 * Doing it on wasm should also be easy, we can add a binaryen pass for
that. See https://github.com/kripken/emscripten/issues/6379 , this was
recently discussed there.

On Tue, Mar 27, 2018 at 7:57 PM, Александр Гурьянов <[email protected]>
wrote:

> "Safe" - means that I do not plan to run any built in optimizations of
> clang, only one that I write by my self. Actually I want to delete
> some functions. I have list of functions to delete, and I want to do
> it on (2) step by fixing bc. I think it is much easier then doing this
> after js generation.
>
> How do you think is it actually possible?
>
>
> 2018-03-27 10:27 GMT+07:00 Alon Zakai <[email protected]>:
> > Yeah, sounds like you're hitting an LLVM optimizer bug, then.
> >
> > What do you mean by "safe" here? The issue is, I think, that if you do
> the
> > "normal" thing, which is to optimize each source file as you convert it
> to
> > an object file, things will work, while if you link those object files
> and
> > then optimize that then the LLVM optimizer can do a lot more and your
> chance
> > of running into bugs is higher. In principle, all optimizations should be
> > safe to do on the combined bitcode, but in practice there are bugs.
> >
> > Concretely, if you do emcc -O3 a.cpp -o a.bc then it runs the LLVM
> > optimizer. When you do  emcc -O3 all.bc -o all.js then we do not run the
> > LLVM optimizer, unless you specify LTO, but the -O3 is used to determine
> how
> > much to optimize in other things than LLVM (asm.js/wasm optimizations).
> >
> >
> > On Mon, Mar 26, 2018 at 6:44 PM, Александр Гурьянов <[email protected]
> >
> > wrote:
> >>
> >> Hmm, looks link time optimizations id broken --llvm-lto 2 produce not
> >> worked js, but game stuck forever on loading. If I found little test
> >> case then I post it.
> >>
> >> Anyway, is it correct that I can run my "SAFE" optimization on step
> >> (2) and as result get correct js with no performance lost against
> >> default build? In other words doing single bc and then using emcc to
> >> produce js, is same that doing just emcc?
> >>
> >> 2018-03-26 23:33 GMT+07:00 Alon Zakai <[email protected]>:
> >> > Hmm, the --llvm-lto 2 option should do basically what you describe
> here
> >> > -
> >> > run LLVM opts on the combined bitcode. Does that also cause this
> >> > problem?
> >> >
> >> > My guess is you're hitting an LLVM optimizer bug or undefined behavior
> >> > of
> >> > some sort, when it has all the bitcode to optimize it is capable of
> >> > doing a
> >> > lot more and that has uncovered LLVM bugs in the past. If you can
> reduce
> >> > this to a testcase you can file I can take a look at that.
> >> >
> >> > On Mon, Mar 26, 2018 at 1:49 AM, caiiiycuk <[email protected]>
> wrote:
> >> >>
> >> >> Good day! I am playing with llvm optimizer and I trying to setup
> build
> >> >> process that allows me to run custom optimizations over bc. I want
> to:
> >> >> 1. Build resulting .bc of game (using llvm-link)
> >> >> 2. Transform this .bc with custom optimizations
> >> >> 3. Produce .js with emcc
> >> >>
> >> >> For (1) I compile all source files into shared library (instead of
> js):
> >> >>  add_library(bin-lib SHARED ${SOURCES})
> >> >>  set_target_properties(bin-lib PROPERTIES SUFFIX .bc)
> >> >>
> >> >> As I understand this step works perfect, because as a result I have
> one
> >> >> libbin-lib.bc file.
> >> >>
> >> >> For (2) I use this command:
> >> >> ~/emscripten/sdk/emscripten-fastcomp/bin/opt -O3 libbin-lib.bc -o
> >> >> libbin-lib-opt.bc
> >> >>
> >> >>
> >> >> For (3) I use this command:
> >> >> ~/emscripten/sdk/emscripten/emcc -O3 \
> >> >>     -s USE_ZLIB=1 -s USE_LIBPNG=1 -s USE_FREETYPE=1 -s USE_GLFW=3 -s
> >> >> FULL_ES2=1 \
> >> >>     --emit-symbol-map \
> >> >>     -s ASSERTIONS=0 \
> >> >>     -s SAFE_HEAP=0 \
> >> >>     -s TOTAL_MEMORY=134217728 \
> >> >>     -s INVOKE_RUN=0 \
> >> >>     -s EXTRA_EXPORTED_RUNTIME_METHODS="['getMemory',
> >> >> 'addRunDependency',
> >> >> 'removeRunDependency', 'FS_createPath', 'FS_createPreloadedFile', \
> >> >>           'FS_createDataFile', 'lengthBytesUTF8', 'stringToUTF8']" \
> >> >>     -s NO_EXIT_RUNTIME=1 \
> >> >>     libbin-lib-opt.bc -o bin.js
> >> >>
> >> >> If I build my game with this steps:
> >> >> (1) -> (3) (skip 2)
> >> >>
> >> >> Then I have working bin.js. I can play game exactly the same as when
> I
> >> >> compile just .js file with emcc.
> >> >>
> >> >> BUT, if I build my game with this steps:
> >> >> (1) -> (2) -> (3)
> >> >>
> >> >> Then I have bin.js that produce errors in browser:
> >> >>
> >> >> Invalid function pointer called with signature 'vi'. Perhaps this is
> an
> >> >> invalid value (e.g. caused by calling a virtual method on a NULL
> >> >> pointer)?
> >> >> Or calling a function with an incorrect type, which will fail? (it is
> >> >> worth
> >> >> building your source files with -Werror (warnings are errors), as
> >> >> warnings
> >> >> can indicate undefined behavior which can cause this)
> >> >>
> >> >> This pointer might make sense in another type signature: v: 0 vid: 0
> >> >> vii:
> >> >> 0 vidd: 0 vidi: 0 viid: 0 viii: 0 viddi: 0 viidi: 0 viiii: 0 vidddd:
> 0
> >> >> viiiii: 0 viddddd: 0 viiiiii: 0 vidddddi: 0 viiiiiii: 0 vidddddii: 0
> >> >> viiddiidii: 0 viiiiiiiii: 0 i: 0 di: 0 ii: 0 dii: 0 iid: 0 iii: 0
> diid:
> >> >> 0
> >> >> iidi: 0 iiii: 0 iiiid: 0 iiiii: 0 iiiiid: 0 iiiiii: 0 iiiiddd: 0
> >> >> iiiiiid: 0
> >> >> iiiiiii: 0 iiiiiiii: 0 iiiiiiiii: 0 iiiiiiiiii: 0
> >> >>
> >> >> uncaught exception: abort(20) at
> >> >> jsStackTrace@http://localhost/gamepix-loader.js line 168 >
> >> >> Function:3:40923
> >> >> stackTrace@http://localhost/gamepix-loader.js line 168 >
> >> >> Function:3:41094
> >> >> abort@http://localhost/gamepix-loader.js line 168 >
> Function:26:243921
> >> >> nullFunc_vi@http://localhost/gamepix-loader.js line 168 >
> >> >> Function:3:326758
> >> >> b20@http://localhost/gamepix-loader.js line 168 > Function:19:112979
> >> >>
> >> >>
> >> >> __ZNSt3__214__shared_count16__release_sharedEv@http://
> localhost/gamepix-loader.js
> >> >> line 168 > Function:19:45045
> >> >> __ZNSt3__26localeD2Ev@http://localhost/gamepix-loader.js line 168 >
> >> >> Function:16:660576
> >> >>
> >> >>
> >> >> __ZNSt3__210__stdinbufIcEC2EP8_IO_FILEP11__mbstate_t@
> http://localhost/gamepix-loader.js
> >> >> line 168 > Function:16:635917
> >> >> __ZNSt3__28ios_base4InitC2Ev@http://localhost/gamepix-loader.js line
> >> >> 168 >
> >> >> Function:16:633585
> >> >> ___cxx_global_var_init@http://localhost/gamepix-loader.js line 168 >
> >> >> Function:16:633478
> >> >> __GLOBAL__I_000101@http://localhost/gamepix-loader.js line 168 >
> >> >> Function:16:633365
> >> >>
> >> >> Error exists if i use any level of optimizations on opt step (O1, O2,
> >> >> O3)
> >> >> If I set --llvm-opts 0, on emcc step error still exists
> >> >>
> >> >> Can you help me?
> >> >> Thank you
> >> >>
> >> >> --
> >> >> You received this message because you are subscribed to the Google
> >> >> Groups
> >> >> "emscripten-discuss" group.
> >> >> To unsubscribe from this group and stop receiving emails from it,
> send
> >> >> an
> >> >> email to [email protected].
> >> >> For more options, visit https://groups.google.com/d/optout.
> >> >
> >> >
> >> > --
> >> > You received this message because you are subscribed to the Google
> >> > Groups
> >> > "emscripten-discuss" group.
> >> > To unsubscribe from this group and stop receiving emails from it, send
> >> > an
> >> > email to [email protected].
> >> > For more options, visit https://groups.google.com/d/optout.
> >>
> >> --
> >> You received this message because you are subscribed to the Google
> Groups
> >> "emscripten-discuss" group.
> >> To unsubscribe from this group and stop receiving emails from it, send
> an
> >> email to [email protected].
> >> For more options, visit https://groups.google.com/d/optout.
> >
> >
> > --
> > You received this message because you are subscribed to the Google Groups
> > "emscripten-discuss" group.
> > To unsubscribe from this group and stop receiving emails from it, send an
> > email to [email protected].
> > For more options, visit https://groups.google.com/d/optout.
>
> --
> You received this message because you are subscribed to the Google Groups
> "emscripten-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to