Mercurial > hg > Members > anatofuz > slides
diff slides/2018/06/05/zip.txt @ 52:73b27e5c1d79 default tip
auto-Update generated slides by script
author | Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 16 Apr 2019 18:58:24 +0900 |
parents | 32e35be2ce71 |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/slides/2018/06/05/zip.txt Tue Apr 16 18:58:24 2019 +0900 @@ -0,0 +1,187 @@ +2018-05-29---- + ❯ lldb -- /Users/anatofuz/workspace/cr/Basic/build_perl6/bin/moar nqp.moarvm examples/hello_world.nqp [13:52:54] +(lldb) target create "/Users/anatofuz/workspace/cr/Basic/build_perl6/bin/moar" +Current executable set to '/Users/anatofuz/workspace/cr/Basic/build_perl6/bin/moar' (x86_64). +(lldb) settings set -- target.run-args "nqp.moarvm" "examples/hello_world.nqp" +(lldb) b add_bb_facts +Breakpoint 1: where = libmoar.dylib`add_bb_facts + 32 at facts.c:362, address = 0x0000000000118540 +(lldb) c +error: invalid process +(lldb) run +Process 8479 launched: '/Users/anatofuz/workspace/cr/Basic/build_perl6/bin/moar' (x86_64) +Process 8479 stopped +* thread #2, stop reason = breakpoint 1.1 + frame #0: 0x00000001001bb540 libmoar.dylib`add_bb_facts(tc=0x0000000100802e30, g=0x0000000100f4efe0, bb=0x0000000102115e00, p=0x0000000100f514d0, cur_deopt_idx=-1) at facts.c:362 + 359 MVMint32 i, is_phi; + 360 + 361 /* Look for instructions that provide or propagate facts. */ +-> 362 MVMSpeshIns *ins = bb->first_ins; + 363 while (ins) { + 364 /* See if there's deopt and logged annotations. Sync cur_deopt_idx + 365 * and, for logged+deopt-one, add logged facts and guards. */ +Target 0: (moar) stopped. +(lldb) bt +* thread #2, stop reason = breakpoint 1.1 + * frame #0: 0x00000001001bb540 libmoar.dylib`add_bb_facts(tc=0x0000000100802e30, g=0x0000000100f4efe0, bb=0x0000000102115e00, p=0x0000000100f514d0, cur_deopt_idx=-1) at facts.c:362 + frame #1: 0x00000001001bb503 libmoar.dylib`MVM_spesh_facts_discover(tc=0x0000000100802e30, g=0x0000000100f4efe0, p=0x0000000100f514d0) at facts.c:659 + frame #2: 0x00000001001b4eb7 libmoar.dylib`MVM_spesh_candidate_add(tc=0x0000000100802e30, p=0x0000000100f514d0) at candidate.c:61 + frame #3: 0x00000001001cf991 libmoar.dylib`worker(tc=0x0000000100802e30, callsite=0x00000001006c9150, args=0x0000000000000000) at worker.c:16 + frame #4: 0x000000010014e8e2 libmoar.dylib`invoke_handler(tc=0x0000000100802e30, invokee=0x0000000102014840, callsite=0x00000001006c9150, args=0x0000000000000000) at MVMCFunction.c:9 + frame #5: 0x00000001000e8494 libmoar.dylib`thread_initial_invoke(tc=0x0000000100802e30, data=0x0000000100802050) at threads.c:59 + frame #6: 0x00000001000aefee libmoar.dylib`MVM_interp_run(tc=0x0000000100802e30, initial_invoke=(libmoar.dylib`thread_initial_invoke at threads.c:50), invoke_data=0x0000000100802050) at interp.c:93 + frame #7: 0x00000001000e7a35 libmoar.dylib`start_thread(data=0x0000000100802050) at threads.c:87 + frame #8: 0x00007fff7b9fe661 libsystem_pthread.dylib`_pthread_body + 340 + frame #9: 0x00007fff7b9fe50d libsystem_pthread.dylib`_pthread_start + 377 + frame #10: 0x00007fff7b9fdbf9 libsystem_pthread.dylib`thread_start + 13 + +(lldb) n +Process 8479 stopped +* thread #2, stop reason = step over + frame #0: 0x00000001001bb579 libmoar.dylib`add_bb_facts(tc=0x0000000100802e30, g=0x0000000100f4efe0, bb=0x0000000102115e00, p=0x0000000100f514d0, cur_deopt_idx=-1) at facts.c:370 + 367 MVMSpeshAnn *ann_deopt_one = NULL; + 368 MVMSpeshAnn *ann_logged = NULL; + 369 MVMint32 is_deopt_ins = 0; +-> 370 while (ann) { + 371 switch (ann->type) { + 372 case MVM_SPESH_ANN_DEOPT_ONE_INS: + 373 ann_deopt_one = ann; +Target 0: (moar) stopped. +(lldb) +Process 8479 stopped +* thread #2, stop reason = step over + frame #0: 0x00000001001bb620 libmoar.dylib`add_bb_facts(tc=0x0000000100802e30, g=0x0000000100f4efe0, bb=0x0000000102115e00, p=0x0000000100f514d0, cur_deopt_idx=-1) at facts.c:385 + 382 } + 383 ann = ann->next; + 384 } +-> 385 if (ann_deopt_one && ann_logged) + 386 log_facts(tc, g, bb, ins, p, ann_deopt_one, ann_logged); + 387 + 388 /* Look through operands for reads and writes. */ +Target 0: (moar) stopped. +(lldb) l + 389 is_phi = ins->info->opcode == MVM_SSA_PHI; + 390 for (i = 0; i < ins->info->num_operands; i++) { + 391 /* Reads need usage tracking; if the read is after a deopt point + 392 * relative to the write then give it an extra usage bump. */ + 393 if ((is_phi && i > 0) + 394 || (!is_phi && (ins->info->operands[i] & MVM_operand_rw_mask) == MVM_operand_read_reg)) { + 395 MVMSpeshFacts *facts = &(g->facts[ins->operands[i].reg.orig][ins->operands[i].reg.i]); +(lldb) l + 396 facts->usages += facts->deopt_idx == cur_deopt_idx ? 1 : 2; + 397 } + 398 + 399 /* Writes need the current deopt index and the writing instruction + 400 * to be specified. A write that's on a deopt instruction bumps + 401 * the usage too. */ + 402 if ((is_phi && i == 0) +(lldb) n +Process 8479 stopped +* thread #2, stop reason = step over + frame #0: 0x00000001001bb65b libmoar.dylib`add_bb_facts(tc=0x0000000100802e30, g=0x0000000100f4efe0, bb=0x0000000102115e00, p=0x0000000100f514d0, cur_deopt_idx=-1) at facts.c:389 + 386 log_facts(tc, g, bb, ins, p, ann_deopt_one, ann_logged); + 387 + 388 /* Look through operands for reads and writes. */ +-> 389 is_phi = ins->info->opcode == MVM_SSA_PHI; + 390 for (i = 0; i < ins->info->num_operands; i++) { + 391 /* Reads need usage tracking; if the read is after a deopt point + 392 * relative to the write then give it an extra usage bump. */ +Target 0: (moar) stopped. +(lldb) p MVM_SSA_PHI +error: use of undeclared identifier 'MVM_SSA_PHI' +(lldb) nexr +error: 'nexr' is not a valid command. +error: Unrecognized command 'nexr'. +(lldb) n +Process 8479 stopped +* thread #2, stop reason = step over + frame #0: 0x00000001001bb677 libmoar.dylib`add_bb_facts(tc=0x0000000100802e30, g=0x0000000100f4efe0, bb=0x0000000102115e00, p=0x0000000100f514d0, cur_deopt_idx=-1) at facts.c:390 + 387 + 388 /* Look through operands for reads and writes. */ + 389 is_phi = ins->info->opcode == MVM_SSA_PHI; +-> 390 for (i = 0; i < ins->info->num_operands; i++) { + 391 /* Reads need usage tracking; if the read is after a deopt point + 392 * relative to the write then give it an extra usage bump. */ + 393 if ((is_phi && i > 0) +Target 0: (moar) stopped. +(lldb) p is_phi +(MVMint32) $14 = 0 +(lldb) p ins +(MVMSpeshIns *) $15 = 0x0000000102115e60 +(lldb) p *ins +(MVMSpeshIns) $16 = { + info = 0x00000001005757c0 + operands = 0x0000000000000000 + prev = 0x0000000000000000 + next = 0x0000000000000000 + annotations = 0x0000000000000000 +} +(lldb) p *ins->info +(MVMOpInfo) $17 = { + opcode = 0 + name = 0x00000001002def92 "no_op" + mark = { + [0] = ' ' + [1] = ' ' + } + num_operands = 0 + pure = '\0' + deopt_point = '\0' + logged = '\0' + no_inline = '\0' + jittivity = '\0' + uses_hll = '\0' + operands = ([0] = '\0', [1] = '\0', [2] = '\0', [3] = '\0', [4] = '\0', [5] = '\0', [6] = '\0', [7] = '\0') +} + + +* profilingの箇所を見ていく + +* perlスクリプトをperl6に移植する +* markdownのparserみたいなのを書き換えてみるなど +* タイトループを早くするのか,ここのハッシュを早くするのか,オブジェクトのオペレーションを早くするのか… +* 手近な場所をとにかく見ていきたい + +* native codeをやるのかvmをやるのか + +* bytecode interpureter, gc関連を書き直すという手もある + +* gcc vs clang + +* llvm側でtail coll呼び出す時はフラグを見ている + * code grarであるというフラグを渡している感じ + +* script言語--> 上手く並列化出来ない + +* targetとしてCbCのコードを吐く + * 継続コード(meta level) + * 継続コードを見て計算結果を見て変えていく + * MoarVMのJIT,nqpのコンパイラにcbcを生成する部分を入れる + * perlccみたいなものをいれる + * targetのアプリケーション...whileでstring matchをする部分を最適化する + +* 正規表現の箇所をターゲットとして書くのも手…!? + * fileをmmapを使うかどうかなど +* 並列のgrep + * 早くなるには早くなる + * cache prefetchの処理でも高速化出来る + + +---------- +2018-06-05---- +MoarVMが実際にインタプリタとして走っているのはMVM_interp_runという関数らしい. +これはスレッド毎に用意されるらしい + +定義自体は `src/core/interp.c`に書かれている + + MVMInstancとかいう構造体に全ての情報が入っている + + MVM_cu_map_from_fileでスレッド情報とファイルから生成した結果をMVMCompUnit構造体として生成している + + DISPATCHでNEXT_OPを判断している,これはオペランドリストとswitch文が同じオーダーで書かれているので + 最適化しやすいらしい + + MVM_interp_runの後DISPATCHというマクロでNEXT_OPというマクロに応じて処理を行っているが + これがMoarVMのバイトコードを一対一対応しているので5000行のcase文が生成されている + + +----------