Improve debug printing of MIR
Categories
(Core :: JavaScript Engine: JIT, enhancement, P1)
Tracking
()
Tracking | Status | |
---|---|---|
firefox109 | --- | fixed |
People
(Reporter: jseward, Assigned: jseward)
References
(Blocks 1 open bug)
Details
Attachments
(1 file)
(deleted),
text/x-phabricator-request
|
Details |
Debug printing of MIR is poor, which makes it difficult to debug the more
complex Wasm->MIR translations, mostly because so much information is missing.
This patch improves the basic printed structure and adds a framework by which
we can incrementally add printing of MIR-node-specific fields in future. The
following changes are made:
-
Printing of MIR expressions in nested style is removed. This is confusing
in that casual reading of the output suggests that expressions are sometimes
evaluated twice. This is removed and replaced with standard non-nested
printing of (SSA) operands. -
The result type of each MIR node is now printed before its name. This helps
in debugging wasm 32-vs-64 bit code, for example. -
Block IDs are now printed, so they can be referred to by branch insns.
-
A generic mechanism for printing extra, node-specific, fields has been
introduced: overrideable methodMDefinition::getExtras
. By default this
does nothing, but individual MIR classes can override it to provide any
extra info they want. -
For a few classes,
MDefinition::getExtras
has been filled in: for
constants, comparisons, branch instructions, and fixed offsets in some wasm
memory access insns.
Here's a before and after example showing all the above improvements:
Before:
--
36:abs (18:sub (12:phi) (17:add))
37:wasmfloatconstant
38:compare (36:abs (18:sub)) (37:wasmfloatconstant)
39:test (38:compare (36:abs) (37:wasmfloatconstant))
--
40:wasmtruncatetoint32 (18:sub (12:phi) (17:add))
41:goto
--
42:constant 0x80000000
43:goto
--
45:wasmbinarybitwise (44:phi (40:wasmtruncatetoint32) (42:constant 0x80000000)) (31:constant 0x1)
46:wasmreturn (45:wasmbinarybitwise (44:phi) (31:constant 0x1)) (2:wasmparameter)
After:
Block4:
36 = Float32.abs 18
37 = Float32.wasmfloatconstant 2.147484e+09:f32
38 = Int32.compare ty=Float32 jsop=Lt 36 37
39 = None.test true->Block5 false->Block6 38
Block5:
40 = Int32.wasmtruncatetoint32 18
41 = None.goto Block7
Block6:
42 = Int32.constant 0x80000000
43 = None.goto Block7
Block7:
44 = Int32.phi 40 42
45 = Int32.wasmbinarybitwise And 44 31
46 = None.wasmreturn 45 2
Assignee | ||
Comment 1•2 years ago
|
||
Debug printing of MIR is poor, which makes it difficult to debug the more
complex Wasm->MIR translations, mostly because so much information is missing.
This patch improves the basic printed structure and adds a framework by which
we can incrementally add printing of MIR-node-specific fields in future. The
following changes are made:
-
Printing of MIR expressions in nested style is removed. This is confusing
in that casual reading of the output suggests that expressions are sometimes
evaluated more than once. This is removed and replaced with standard
non-nested printing of (SSA) operands. -
The result type of each MIR node is now printed before its name. This helps
in debugging wasm 32-vs-64 bit code, for example. -
Block IDs are now printed, so they can be referred to by branch insns.
-
A generic mechanism for printing extra, node-specific, fields has been
introduced: overrideable methodMDefinition::getExtras
. By default this
does nothing, but individual MIR classes can override it to provide any
extra info they want. -
For a few classes,
MDefinition::getExtras
has been filled in: for
constants, comparisons, branch instructions, and fixed offsets in some wasm
memory access insns.
The only tricky bit is the ExtrasCollector
class that is used to collect up
the (C) strings created by the ::getExtras
method. This needs to
(1) ensure that those methods can safely pass on stack-allocated strings, and
(2) ensure that none of those methods calls the system malloc/free directly --
this would be an embedding bug.
ExtrasCollector
solves these by respectively (1) copying any strings it is
given and (2) using js::SystemAllocPolicy
as the allocator both for the
string copies and the vector that holds them.
Updated•2 years ago
|
Comment 3•2 years ago
|
||
bugherder |
Description
•