Bug 1852740: add tests for the `fetchpriority` attribute in Link headers. r=necko...
[gecko.git] / js / src / jsapi-tests / testJitMinimalFunc.h
blob3a7dbd318317a3e5c340468643543d3eaa117ad1
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/. */
7 #ifndef jsapi_tests_jitTestGVN_h
8 #define jsapi_tests_jitTestGVN_h
10 #include "jit/IonAnalysis.h"
11 #include "jit/MIRGenerator.h"
12 #include "jit/MIRGraph.h"
13 #include "jit/RangeAnalysis.h"
14 #include "jit/ValueNumbering.h"
16 namespace js {
17 namespace jit {
19 struct MinimalAlloc {
20 LifoAlloc lifo;
21 TempAllocator alloc;
23 // We are not testing the fallible allocator in these test cases, thus make
24 // the lifo alloc chunk extremely large for our test cases.
25 MinimalAlloc() : lifo(128 * 1024), alloc(&lifo) {
26 if (!alloc.ensureBallast()) {
27 MOZ_CRASH("[OOM] Not enough RAM for the test.");
32 struct MinimalFunc : MinimalAlloc {
33 JitCompileOptions options;
34 CompileInfo info;
35 MIRGraph graph;
36 MIRGenerator mir;
37 uint32_t numParams;
39 MinimalFunc()
40 : options(),
41 info(0),
42 graph(&alloc),
43 mir(static_cast<CompileRealm*>(nullptr), options, &alloc, &graph, &info,
44 static_cast<const OptimizationInfo*>(nullptr)),
45 numParams(0) {}
47 MBasicBlock* createEntryBlock() {
48 MBasicBlock* block =
49 MBasicBlock::New(graph, info, nullptr, MBasicBlock::NORMAL);
50 graph.addBlock(block);
51 return block;
54 MBasicBlock* createOsrEntryBlock() {
55 MBasicBlock* block =
56 MBasicBlock::New(graph, info, nullptr, MBasicBlock::NORMAL);
57 graph.addBlock(block);
58 graph.setOsrBlock(block);
59 return block;
62 MBasicBlock* createBlock(MBasicBlock* pred) {
63 MBasicBlock* block =
64 MBasicBlock::New(graph, info, pred, MBasicBlock::NORMAL);
65 graph.addBlock(block);
66 return block;
69 MParameter* createParameter() {
70 MParameter* p = MParameter::New(alloc, numParams++);
71 return p;
74 bool runGVN() {
75 if (!SplitCriticalEdges(graph)) {
76 return false;
78 RenumberBlocks(graph);
79 if (!BuildDominatorTree(graph)) {
80 return false;
82 if (!BuildPhiReverseMapping(graph)) {
83 return false;
85 ValueNumberer gvn(&mir, graph);
86 if (!gvn.run(ValueNumberer::DontUpdateAliasAnalysis)) {
87 return false;
89 return true;
92 bool runRangeAnalysis() {
93 if (!SplitCriticalEdges(graph)) {
94 return false;
96 RenumberBlocks(graph);
97 if (!BuildDominatorTree(graph)) {
98 return false;
100 if (!BuildPhiReverseMapping(graph)) {
101 return false;
103 RangeAnalysis rangeAnalysis(&mir, graph);
104 if (!rangeAnalysis.addBetaNodes()) {
105 return false;
107 if (!rangeAnalysis.analyze()) {
108 return false;
110 if (!rangeAnalysis.addRangeAssertions()) {
111 return false;
113 if (!rangeAnalysis.removeBetaNodes()) {
114 return false;
116 return true;
120 } // namespace jit
121 } // namespace js
123 #endif