⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 286790 in webkit


Ignore:
Timestamp:
Dec 9, 2021, 11:07:58 AM (5 years ago)
Author:
sbarati@apple.com
Message:

Add an option to dump the B3 IR for an allowlist of Wasm function indices
https://bugs.webkit.org/show_bug.cgi?id=234028

Reviewed by Tadeu Zagallo.

  • b3/B3Common.cpp:

(JSC::B3::shouldDumpIR):

  • b3/B3Common.h:
  • b3/B3Generate.cpp:

(JSC::B3::generateToAir):

  • b3/B3Procedure.cpp:

(JSC::B3::Procedure::dump const):
(JSC::B3::Procedure::setShouldDumpIR):

  • b3/B3Procedure.h:

(JSC::B3::Procedure::shouldDumpIR const):

  • b3/air/AirGenerate.cpp:

(JSC::B3::Air::prepareForGeneration):

  • b3/testb3.h:

(shouldBeVerbose):
(lowerToAirForTesting):

  • b3/testb3_6.cpp:

(testInterpreter):
(testMoveConstants):

  • b3/testb3_7.cpp:

(testReduceStrengthReassociation):

  • runtime/OptionsList.h:
  • tools/FunctionAllowlist.cpp:

(JSC::FunctionAllowlist::shouldDumpWasmFunction const):

  • tools/FunctionAllowlist.h:
  • wasm/WasmB3IRGenerator.cpp:

(JSC::Wasm::shouldDumpIRFor):
(JSC::Wasm::parseAndCompile):

  • wasm/WasmOMGForOSREntryPlan.cpp:

(JSC::Wasm::OMGForOSREntryPlan::work):

  • wasm/WasmOMGPlan.cpp:

(JSC::Wasm::OMGPlan::work):

Location:
trunk/Source/JavaScriptCore
Files:
16 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r286769 r286790  
     12021-12-09  Saam Barati  <sbarati@apple.com>
     2
     3        Add an option to dump the B3 IR for an allowlist of Wasm function indices
     4        https://bugs.webkit.org/show_bug.cgi?id=234028
     5
     6        Reviewed by Tadeu Zagallo.
     7
     8        * b3/B3Common.cpp:
     9        (JSC::B3::shouldDumpIR):
     10        * b3/B3Common.h:
     11        * b3/B3Generate.cpp:
     12        (JSC::B3::generateToAir):
     13        * b3/B3Procedure.cpp:
     14        (JSC::B3::Procedure::dump const):
     15        (JSC::B3::Procedure::setShouldDumpIR):
     16        * b3/B3Procedure.h:
     17        (JSC::B3::Procedure::shouldDumpIR const):
     18        * b3/air/AirGenerate.cpp:
     19        (JSC::B3::Air::prepareForGeneration):
     20        * b3/testb3.h:
     21        (shouldBeVerbose):
     22        (lowerToAirForTesting):
     23        * b3/testb3_6.cpp:
     24        (testInterpreter):
     25        (testMoveConstants):
     26        * b3/testb3_7.cpp:
     27        (testReduceStrengthReassociation):
     28        * runtime/OptionsList.h:
     29        * tools/FunctionAllowlist.cpp:
     30        (JSC::FunctionAllowlist::shouldDumpWasmFunction const):
     31        * tools/FunctionAllowlist.h:
     32        * wasm/WasmB3IRGenerator.cpp:
     33        (JSC::Wasm::shouldDumpIRFor):
     34        (JSC::Wasm::parseAndCompile):
     35        * wasm/WasmOMGForOSREntryPlan.cpp:
     36        (JSC::Wasm::OMGForOSREntryPlan::work):
     37        * wasm/WasmOMGPlan.cpp:
     38        (JSC::Wasm::OMGPlan::work):
     39
    1402021-12-09  Yusuke Suzuki  <ysuzuki@apple.com>
    241
  • trunk/Source/JavaScriptCore/b3/B3Common.cpp

    r280650 r286790  
    3737const char* const tierName = "b3  ";
    3838
    39 bool shouldDumpIR(B3CompilationMode mode)
     39bool shouldDumpIR(Procedure& procedure, B3CompilationMode mode)
    4040{
     41    if (procedure.shouldDumpIR())
     42        return true;
     43
    4144#if ENABLE(FTL_JIT)
    4245    return FTL::verboseCompilationEnabled() || FTL::shouldDumpDisassembly() || shouldDumpIRAtEachPhase(mode);
  • trunk/Source/JavaScriptCore/b3/B3Common.h

    r280650 r286790  
    3535namespace JSC { namespace B3 {
    3636
     37class Procedure;
     38
    3739extern const char* const tierName;
    3840
     
    4244};
    4345
    44 JS_EXPORT_PRIVATE bool shouldDumpIR(B3CompilationMode);
     46JS_EXPORT_PRIVATE bool shouldDumpIR(Procedure&, B3CompilationMode);
    4547bool shouldDumpIRAtEachPhase(B3CompilationMode);
    4648bool shouldValidateIR();
  • trunk/Source/JavaScriptCore/b3/B3Generate.cpp

    r281693 r286790  
    7171    TimingScope timingScope("generateToAir");
    7272   
    73     if (shouldDumpIR(B3Mode) && !shouldDumpIRAtEachPhase(B3Mode)) {
     73    if (shouldDumpIR(procedure, B3Mode) && !shouldDumpIRAtEachPhase(B3Mode)) {
    7474        dataLog(tierName, "Initial B3:\n");
    7575        dataLog(procedure);
     
    131131    // If we're doing super verbose dumping, the phase scope of any phase will already do a dump.
    132132    // Note that lowerToAir() acts like a phase in this regard.
    133     if (shouldDumpIR(B3Mode) && !shouldDumpIRAtEachPhase(B3Mode)) {
     133    if (shouldDumpIR(procedure, B3Mode) && !shouldDumpIRAtEachPhase(B3Mode)) {
    134134        dataLog("B3 after ", procedure.lastPhaseName(), ", before generation:\n");
    135135        dataLog(procedure);
  • trunk/Source/JavaScriptCore/b3/B3Procedure.cpp

    r280198 r286790  
    229229void Procedure::dump(PrintStream& out) const
    230230{
     231    out.print("Opt Level: ", optLevel(), "\n");
    231232    IndexSet<Value*> valuesInBlocks;
    232233    for (BasicBlock* block : *this) {
     
    480481}
    481482
     483void Procedure::setShouldDumpIR()
     484{
     485    m_shouldDumpIR = true;
     486    m_code->forcePreservationOfB3Origins();
     487}
     488
    482489} } // namespace JSC::B3
    483490
  • trunk/Source/JavaScriptCore/b3/B3Procedure.h

    r280198 r286790  
    281281    JS_EXPORT_PRIVATE void freeUnneededB3ValuesAfterLowering();
    282282
     283    bool shouldDumpIR() const { return m_shouldDumpIR; }
     284    void setShouldDumpIR();
     285
    283286private:
    284287    friend class BlockInsertionSet;
     
    308311    bool m_hasQuirks { false };
    309312    bool m_needsPCToOriginMap { false };
     313    bool m_shouldDumpIR { false };
    310314};
    311315   
  • trunk/Source/JavaScriptCore/b3/air/AirGenerate.cpp

    r278810 r286790  
    6262   
    6363    // If we're doing super verbose dumping, the phase scope of any phase will already do a dump.
    64     if (shouldDumpIR(AirMode) && !shouldDumpIRAtEachPhase(AirMode)) {
     64    if (shouldDumpIR(code.proc(), AirMode) && !shouldDumpIRAtEachPhase(AirMode)) {
    6565        dataLog(tierName, "Initial air:\n");
    6666        dataLog(code);
     
    9090            validate(code);
    9191
    92         if (shouldDumpIR(AirMode)) {
     92        if (shouldDumpIR(code.proc(), AirMode)) {
    9393            dataLog("Air after ", code.lastPhaseName(), ", before generation:\n");
    9494            dataLog(code);
     
    184184    // Do a final dump of Air. Note that we have to do this even if we are doing per-phase dumping,
    185185    // since the final generation is not a phase.
    186     if (shouldDumpIR(AirMode)) {
     186    if (shouldDumpIR(code.proc(), AirMode)) {
    187187        dataLog("Air after ", code.lastPhaseName(), ", before generation:\n");
    188188        dataLog(code);
  • trunk/Source/JavaScriptCore/b3/testb3.h

    r281910 r286790  
    9898using namespace JSC::B3;
    9999
    100 inline bool shouldBeVerbose()
    101 {
    102     return shouldDumpIR(B3Mode);
     100inline bool shouldBeVerbose(Procedure& procedure)
     101{
     102    return shouldDumpIR(procedure, B3Mode);
    103103}
    104104
     
    221221    proc.resetReachability();
    222222   
    223     if (shouldBeVerbose())
     223    if (shouldBeVerbose(proc))
    224224        dataLog("B3 before lowering:\n", proc);
    225225   
     
    227227    lowerToAir(proc);
    228228   
    229     if (shouldBeVerbose())
     229    if (shouldBeVerbose(proc))
    230230        dataLog("Air after lowering:\n", proc.code());
    231231   
  • trunk/Source/JavaScriptCore/b3/testb3_6.cpp

    r281534 r286790  
    17971797    data.append(0);
    17981798
    1799     if (shouldBeVerbose())
     1799    if (shouldBeVerbose(proc))
    18001800        dataLog("data = ", listDump(data), "\n");
    18011801
     
    18331833    code.append(Stop);
    18341834
    1835     if (shouldBeVerbose())
     1835    if (shouldBeVerbose(proc))
    18361836        dataLog("code = ", listDump(code), "\n");
    18371837
     
    18421842        CHECK(stream[i] == i + 1);
    18431843
    1844     if (shouldBeVerbose())
     1844    if (shouldBeVerbose(proc))
    18451845        dataLog("stream = ", listDump(stream), "\n");
    18461846}
     
    27842784        proc.resetReachability();
    27852785   
    2786         if (shouldBeVerbose()) {
     2786        if (shouldBeVerbose(proc)) {
    27872787            dataLog("IR before:\n");
    27882788            dataLog(proc);
     
    27912791        moveConstants(proc);
    27922792   
    2793         if (shouldBeVerbose()) {
     2793        if (shouldBeVerbose(proc)) {
    27942794            dataLog("IR after:\n");
    27952795            dataLog(proc);
  • trunk/Source/JavaScriptCore/b3/testb3_7.cpp

    r281910 r286790  
    360360    proc.resetReachability();
    361361
    362     if (shouldBeVerbose()) {
     362    if (shouldBeVerbose(proc)) {
    363363        dataLog("IR before reduceStrength:\n");
    364364        dataLog(proc);
     
    367367    reduceStrength(proc);
    368368
    369     if (shouldBeVerbose()) {
     369    if (shouldBeVerbose(proc)) {
    370370        dataLog("IR after reduceStrength:\n");
    371371        dataLog(proc);
  • trunk/Source/JavaScriptCore/runtime/OptionsList.h

    r286111 r286790  
    134134    v(Bool, dumpRegExpDisassembly, false, Normal, "dumps disassembly of RegExp upon compilation") \
    135135    v(Bool, dumpWasmDisassembly, false, Normal, "dumps disassembly of all Wasm code upon compilation") \
     136    v(OptionString, wasmB3FunctionsToDump, nullptr, Normal, "file with newline separated list of function indices to dump IR/disassembly for, if no such file exists, the function index itself") \
    136137    v(Bool, dumpBBQDisassembly, false, Normal, "dumps disassembly of BBQ Wasm code upon compilation") \
    137138    v(Bool, dumpOMGDisassembly, false, Normal, "dumps disassembly of OMG Wasm code upon compilation") \
  • trunk/Source/JavaScriptCore/tools/FunctionAllowlist.cpp

    r284533 r286790  
    9797}
    9898
     99bool FunctionAllowlist::shouldDumpWasmFunction(uint32_t index) const
     100{
     101    if (!m_hasActiveAllowlist)
     102        return false;
     103    if (m_entries.isEmpty())
     104        return false;
     105    return m_entries.contains(String::number(index));
     106}
     107
    99108} // namespace JSC
    100109
  • trunk/Source/JavaScriptCore/tools/FunctionAllowlist.h

    r262928 r286790  
    3838
    3939    bool contains(CodeBlock*) const;
     40    bool shouldDumpWasmFunction(uint32_t) const;
    4041
    4142private:
  • trunk/Source/JavaScriptCore/wasm/WasmB3IRGenerator.cpp

    r286092 r286790  
    4747#include "B3WasmAddressValue.h"
    4848#include "B3WasmBoundsCheckValue.h"
     49#include "FunctionAllowlist.h"
    4950#include "JSCJSValueInlines.h"
    5051#include "JSWebAssemblyInstance.h"
     
    32293230}
    32303231
     3232static bool shouldDumpIRFor(uint32_t functionIndex)
     3233{
     3234    static LazyNeverDestroyed<FunctionAllowlist> dumpAllowlist;
     3235    static std::once_flag initializeAllowlistFlag;
     3236    std::call_once(initializeAllowlistFlag, [] {
     3237        const char* functionAllowlistFile = Options::wasmB3FunctionsToDump();
     3238        dumpAllowlist.construct(functionAllowlistFile);
     3239    });
     3240    return dumpAllowlist->shouldDumpWasmFunction(functionIndex);
     3241}
     3242
    32313243Expected<std::unique_ptr<InternalFunction>, String> parseAndCompile(CompilationContext& compilationContext, const FunctionData& function, const Signature& signature, Vector<UnlinkedWasmToWasmCall>& unlinkedWasmToWasmCalls, unsigned& osrEntryScratchBufferSize, const ModuleInformation& info, MemoryMode mode, CompilationMode compilationMode, uint32_t functionIndex, uint32_t loopIndexForOSREntry, TierUpCount* tierUp)
    32323244{
     
    32383250
    32393251    Procedure& procedure = *compilationContext.procedure;
     3252    if (shouldDumpIRFor(functionIndex + info.importFunctionCount()))
     3253        procedure.setShouldDumpIR();
    32403254
    32413255    compilationContext.wasmEntrypointJIT = makeUnique<CCallHelpers>();
  • trunk/Source/JavaScriptCore/wasm/WasmOMGForOSREntryPlan.cpp

    r285149 r286790  
    9797
    9898    omgEntrypoint.compilation = makeUnique<Compilation>(
    99         FINALIZE_WASM_CODE_FOR_MODE(CompilationMode::OMGForOSREntryMode, linkBuffer, JITCompilationPtrTag, "WebAssembly OMGForOSREntry function[%i] %s name %s", m_functionIndex, signature.toString().ascii().data(), makeString(IndexOrName(functionIndexSpace, m_moduleInformation->nameSection->get(functionIndexSpace))).ascii().data()),
     99        FINALIZE_CODE_IF(context.procedure->shouldDumpIR() || shouldDumpDisassemblyFor(CompilationMode::OMGForOSREntryMode), linkBuffer, JITCompilationPtrTag, "WebAssembly OMGForOSREntry function[%i] %s name %s", m_functionIndex, signature.toString().ascii().data(), makeString(IndexOrName(functionIndexSpace, m_moduleInformation->nameSection->get(functionIndexSpace))).ascii().data()),
    100100        WTFMove(context.wasmEntrypointByproducts));
    101101
  • trunk/Source/JavaScriptCore/wasm/WasmOMGPlan.cpp

    r285149 r286790  
    9494
    9595    omgEntrypoint.compilation = makeUnique<Compilation>(
    96         FINALIZE_WASM_CODE_FOR_MODE(CompilationMode::OMGMode, linkBuffer, JITCompilationPtrTag, "WebAssembly OMG function[%i] %s name %s", m_functionIndex, signature.toString().ascii().data(), makeString(IndexOrName(functionIndexSpace, m_moduleInformation->nameSection->get(functionIndexSpace))).ascii().data()),
     96        FINALIZE_CODE_IF(context.procedure->shouldDumpIR() || shouldDumpDisassemblyFor(CompilationMode::OMGMode), linkBuffer, JITCompilationPtrTag, "WebAssembly OMG function[%i] %s name %s", m_functionIndex, signature.toString().ascii().data(), makeString(IndexOrName(functionIndexSpace, m_moduleInformation->nameSection->get(functionIndexSpace))).ascii().data()),
    9797        WTFMove(context.wasmEntrypointByproducts));
    9898
Note: See TracChangeset for help on using the changeset viewer.