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"
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
;
43 mir(static_cast<CompileRealm
*>(nullptr), options
, &alloc
, &graph
, &info
,
44 static_cast<const OptimizationInfo
*>(nullptr)),
47 MBasicBlock
* createEntryBlock() {
49 MBasicBlock::New(graph
, info
, nullptr, MBasicBlock::NORMAL
);
50 graph
.addBlock(block
);
54 MBasicBlock
* createOsrEntryBlock() {
56 MBasicBlock::New(graph
, info
, nullptr, MBasicBlock::NORMAL
);
57 graph
.addBlock(block
);
58 graph
.setOsrBlock(block
);
62 MBasicBlock
* createBlock(MBasicBlock
* pred
) {
64 MBasicBlock::New(graph
, info
, pred
, MBasicBlock::NORMAL
);
65 graph
.addBlock(block
);
69 MParameter
* createParameter() {
70 MParameter
* p
= MParameter::New(alloc
, numParams
++);
75 if (!SplitCriticalEdges(graph
)) {
78 RenumberBlocks(graph
);
79 if (!BuildDominatorTree(graph
)) {
82 if (!BuildPhiReverseMapping(graph
)) {
85 ValueNumberer
gvn(&mir
, graph
);
86 if (!gvn
.run(ValueNumberer::DontUpdateAliasAnalysis
)) {
92 bool runRangeAnalysis() {
93 if (!SplitCriticalEdges(graph
)) {
96 RenumberBlocks(graph
);
97 if (!BuildDominatorTree(graph
)) {
100 if (!BuildPhiReverseMapping(graph
)) {
103 RangeAnalysis
rangeAnalysis(&mir
, graph
);
104 if (!rangeAnalysis
.addBetaNodes()) {
107 if (!rangeAnalysis
.analyze()) {
110 if (!rangeAnalysis
.addRangeAssertions()) {
113 if (!rangeAnalysis
.removeBetaNodes()) {