tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

testJitMinimalFunc.h (3093B)


      1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
      2 * vim: set ts=8 sts=2 et sw=2 tw=80:
      3 * This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this
      5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #ifndef jsapi_tests_jitTestGVN_h
      8 #define jsapi_tests_jitTestGVN_h
      9 
     10 #include "jit/DominatorTree.h"
     11 #include "jit/IonAnalysis.h"
     12 #include "jit/MIRGenerator.h"
     13 #include "jit/MIRGraph.h"
     14 #include "jit/RangeAnalysis.h"
     15 #include "jit/ValueNumbering.h"
     16 
     17 namespace js {
     18 namespace jit {
     19 
     20 struct MinimalAlloc {
     21  LifoAlloc lifo;
     22  TempAllocator alloc;
     23 
     24  // We are not testing the fallible allocator in these test cases, thus make
     25  // the lifo alloc chunk extremely large for our test cases.
     26  MinimalAlloc() : lifo(128 * 1024, js::MallocArena), alloc(&lifo) {
     27    if (!alloc.ensureBallast()) {
     28      MOZ_CRASH("[OOM] Not enough RAM for the test.");
     29    }
     30  }
     31 };
     32 
     33 struct MinimalFunc : MinimalAlloc {
     34  JitCompileOptions options;
     35  CompileInfo info;
     36  MIRGraph graph;
     37  MIRGenerator mir;
     38  uint32_t numParams;
     39 
     40  MinimalFunc()
     41      : options(),
     42        info(0),
     43        graph(&alloc),
     44        mir(static_cast<CompileRealm*>(nullptr), options, &alloc, &graph, &info,
     45            static_cast<const OptimizationInfo*>(nullptr)),
     46        numParams(0) {}
     47 
     48  MBasicBlock* createEntryBlock() {
     49    MBasicBlock* block =
     50        MBasicBlock::New(graph, info, nullptr, MBasicBlock::NORMAL);
     51    graph.addBlock(block);
     52    return block;
     53  }
     54 
     55  MBasicBlock* createOsrEntryBlock() {
     56    MBasicBlock* block =
     57        MBasicBlock::New(graph, info, nullptr, MBasicBlock::NORMAL);
     58    graph.addBlock(block);
     59    graph.setOsrBlock(block);
     60    return block;
     61  }
     62 
     63  MBasicBlock* createBlock(MBasicBlock* pred) {
     64    MBasicBlock* block =
     65        MBasicBlock::New(graph, info, pred, MBasicBlock::NORMAL);
     66    graph.addBlock(block);
     67    return block;
     68  }
     69 
     70  MParameter* createParameter() {
     71    MParameter* p = MParameter::New(alloc, numParams++);
     72    return p;
     73  }
     74 
     75  bool runGVN() {
     76    if (!SplitCriticalEdges(graph)) {
     77      return false;
     78    }
     79    RenumberBlocks(graph);
     80    if (!BuildDominatorTree(&mir, graph)) {
     81      return false;
     82    }
     83    if (!BuildPhiReverseMapping(graph)) {
     84      return false;
     85    }
     86    ValueNumberer gvn(&mir, graph);
     87    if (!gvn.run(ValueNumberer::DontUpdateAliasAnalysis)) {
     88      return false;
     89    }
     90    return true;
     91  }
     92 
     93  bool runRangeAnalysis() {
     94    if (!SplitCriticalEdges(graph)) {
     95      return false;
     96    }
     97    RenumberBlocks(graph);
     98    if (!BuildDominatorTree(&mir, graph)) {
     99      return false;
    100    }
    101    if (!BuildPhiReverseMapping(graph)) {
    102      return false;
    103    }
    104    RangeAnalysis rangeAnalysis(&mir, graph);
    105    if (!rangeAnalysis.addBetaNodes()) {
    106      return false;
    107    }
    108    if (!rangeAnalysis.analyze()) {
    109      return false;
    110    }
    111    if (!rangeAnalysis.addRangeAssertions()) {
    112      return false;
    113    }
    114    if (!rangeAnalysis.removeBetaNodes()) {
    115      return false;
    116    }
    117    return true;
    118  }
    119 };
    120 
    121 }  // namespace jit
    122 }  // namespace js
    123 
    124 #endif