Bug 177922 - Refactor the inliner to simplify block linking
Summary: Refactor the inliner to simplify block linking
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Robin Morisset
URL:
Keywords: InRadar
Depends on:
Blocks: 176601 177925 177926 177927
  Show dependency treegraph
 
Reported: 2017-10-05 01:36 PDT by Robin Morisset
Modified: 2017-10-09 16:56 PDT (History)
7 users (show)

See Also:


Attachments
Patch (76.23 KB, patch)
2017-10-05 04:40 PDT, Robin Morisset
no flags Details | Formatted Diff | Diff
Applied Saam's suggestions + s/PARSER_ASSERT/RELEASE_ASSERT/g (83.62 KB, patch)
2017-10-09 16:13 PDT, Robin Morisset
no flags Details | Formatted Diff | Diff
Patch for landing (83.62 KB, patch)
2017-10-09 16:17 PDT, Robin Morisset
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Robin Morisset 2017-10-05 01:36:46 PDT
This bug is to discuss separately the refactoring I started in https://bugs.webkit.org/show_bug.cgi?id=176601.

The key idea is to put basic blocks in m_unlinkedBlocks once we have given them a terminal (and know where their successor will be allocated) instead of as soon as possible.
Details are in the Changelog, and in the aforementioned bug.
Comment 1 Robin Morisset 2017-10-05 04:40:46 PDT
Created attachment 322824 [details]
Patch
Comment 2 Robin Morisset 2017-10-05 04:43:02 PDT
This patch is based on the one that I last submitted to https://bugs.webkit.org/show_bug.cgi?id=176601, and takes into account the comments left there by Keith and Saam.
Comment 3 Build Bot 2017-10-05 04:43:54 PDT
Attachment 322824 [details] did not pass style-queue:


ERROR: Source/JavaScriptCore/dfg/DFGByteCodeParser.cpp:4084:  WTF_CONCAT is incorrectly named. Don't use underscores in your identifier names.  [readability/naming/underscores] [4]
ERROR: Source/JavaScriptCore/dfg/DFGByteCodeParser.cpp:4086:  Should be indented on a separate line, with the colon or comma first on that line.  [whitespace/indent] [4]
ERROR: Source/JavaScriptCore/dfg/DFGByteCodeParser.cpp:4091:  Wrong number of spaces before statement. (expected: 12)  [whitespace/indent] [4]
ERROR: Source/JavaScriptCore/dfg/DFGByteCodeParser.cpp:6171:  Wrong number of spaces before statement. (expected: 8)  [whitespace/indent] [4]
Total errors found: 4 in 6 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 4 Saam Barati 2017-10-09 12:23:07 PDT
Comment on attachment 322824 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=322824&action=review

r=me with some comments.

> Source/JavaScriptCore/ChangeLog:23
> +        - I made separate allocateBlock routines because the little dance with AdoptRef(* new BasicBlock(...)) was being repeated in lots of places, and typos in that were a major source of bugs during other refactorings

typo: AdoptRef => adoptRef

> Source/JavaScriptCore/ChangeLog:26
> +        - probably some more I forgot..

no need for this. This is assumed in most changelog entries :)

> Source/JavaScriptCore/dfg/DFGByteCodeParser.cpp:82
> +#define VERBOSE_LOG(...) dataLogIf(Options::verboseDFGByteCodeParsing(), __VA_ARGS__)

Why not use the static verbose variable instead of the runtime option? I think until we prove having this runtime switch is actually useful, we should let the compiler eliminate a bunch of the dead code.

Also, FWIW, I'm not sure we'll need all the logging you added. Do you think it's all actually helpful to someone else hacking on this code in the future?

> Source/JavaScriptCore/dfg/DFGByteCodeParser.cpp:208
> +    // or they can be untargetable, with bytecodeBegin==UINT_MAX, to be managed manually and not by the linkBlock machinery.

what are the use cases for the not well defined bytecode begin?

> Source/JavaScriptCore/dfg/DFGByteCodeParser.cpp:1238
> +void ByteCodeParser::makeJumpTo(BasicBlock* block)

Style nit: I think a name more consistent with DFG bytecode parser naming would be: addJumpTo instead of makeJumpTo

> Source/JavaScriptCore/dfg/DFGByteCodeParser.cpp:1246
> +void ByteCodeParser::makeJumpTo(unsigned bytecodeIndex)

ditto

> Source/JavaScriptCore/dfg/DFGByteCodeParser.cpp:1292
> +    // We first check that we have profiling information about this call, and that it did not behave too polymorphically.

nit: I'd say: "did not behave too polymorphically" => "does not have megamorphic callees" or something similar.

> Source/JavaScriptCore/dfg/DFGByteCodeParser.cpp:2045
> +

please remove empty line

> Source/JavaScriptCore/dfg/DFGByteCodeParser.cpp:4094
> +        shouldContinueParsing
> +#define LAST_OPCODE(name) \

style nit: I'd add a newline between these two macros

> Source/JavaScriptCore/dfg/DFGByteCodeParser.cpp:4096
> +        if (m_currentBlock->terminal()) { \

nit: I'd cache the result of terminal() since I'm not 100% sure the compiler will CSE it because it loops and such.

> Source/JavaScriptCore/dfg/DFGByteCodeParser.cpp:4104
> +                case Jump: \
> +                case Branch: \
> +                case Switch: \
> +                    ASSERT(!m_currentBlock->isLinked); \
> +                    m_inlineStackTop->m_unlinkedBlocks.append(m_currentBlock); \
> +                    break;\
> +                default: break; \

style nit: Webkit style says that we don't indent between switch and case

> Source/JavaScriptCore/dfg/DFGByteCodeParser.cpp:4162
>                  addToGraph(Jump, OpInfo(m_currentIndex));

maybe use your helper function here?

> Source/JavaScriptCore/dfg/DFGByteCodeParser.cpp:6320
> +            // - we may just have returned from an inlined callee that had some early returns and so allocated a continuation block, and the instruction after the call is a jump target.

nit: I'd break this line up across 2 new lines

> Source/JavaScriptCore/dfg/DFGByteCodeParser.cpp:6344
> +                // This case only happens if the last instruction was an inlined call with early returns or polymorphic (creating an empty continuation block),

nit: I'd break this line up across 2 new lines

> JSTests/stress/arguments-elimination-varargs-too-many-args-arg-count.js:28
> -            throw "Error: bad result in loop in DFG: " + result.result;
> +            throw "Error: bad result in loop in DFG (result.ftl: " + result.ftl + "): " + result.result + " in iteration " + i;
>      } else {
>          if (result.result != 1)
> -            throw "Error: bad result in loop before DFG: " + result.result;
> +            throw "Error: bad result in loop before DFG (result.ftl: " + result.ftl + "): " + result.result + " in iteration " + i;

Please revert or add a changelog entry for JSTests. I'd vote for reverting since this was probably just used by you for some local debugging.
Comment 5 Robin Morisset 2017-10-09 16:13:15 PDT
Created attachment 323239 [details]
Applied Saam's suggestions + s/PARSER_ASSERT/RELEASE_ASSERT/g
Comment 6 Build Bot 2017-10-09 16:16:19 PDT
Attachment 323239 [details] did not pass style-queue:


ERROR: Source/JavaScriptCore/dfg/DFGByteCodeParser.cpp:4084:  WTF_CONCAT is incorrectly named. Don't use underscores in your identifier names.  [readability/naming/underscores] [4]
ERROR: Source/JavaScriptCore/dfg/DFGByteCodeParser.cpp:4086:  Should be indented on a separate line, with the colon or comma first on that line.  [whitespace/indent] [4]
ERROR: Source/JavaScriptCore/dfg/DFGByteCodeParser.cpp:4091:  Wrong number of spaces before statement. (expected: 12)  [whitespace/indent] [4]
ERROR: Source/JavaScriptCore/dfg/DFGByteCodeParser.cpp:6167:  Wrong number of spaces before statement. (expected: 8)  [whitespace/indent] [4]
Total errors found: 4 in 5 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 7 Robin Morisset 2017-10-09 16:17:43 PDT
Created attachment 323240 [details]
Patch for landing
Comment 8 WebKit Commit Bot 2017-10-09 16:55:29 PDT
Comment on attachment 323240 [details]
Patch for landing

Clearing flags on attachment: 323240

Committed r223086: <http://trac.webkit.org/changeset/223086>
Comment 9 WebKit Commit Bot 2017-10-09 16:55:31 PDT
All reviewed patches have been landed.  Closing bug.
Comment 10 Radar WebKit Bug Importer 2017-10-09 16:56:13 PDT
<rdar://problem/34898758>