js/src/jit/C1Spewer.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
michael@0 2 * vim: set ts=8 sts=4 et sw=4 tw=99:
michael@0 3 * This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 6
michael@0 7 #ifdef DEBUG
michael@0 8
michael@0 9 #include "jit/C1Spewer.h"
michael@0 10
michael@0 11 #include <time.h>
michael@0 12
michael@0 13 #include "jit/LinearScan.h"
michael@0 14 #include "jit/LIR.h"
michael@0 15 #include "jit/MIRGraph.h"
michael@0 16
michael@0 17 using namespace js;
michael@0 18 using namespace js::jit;
michael@0 19
michael@0 20 bool
michael@0 21 C1Spewer::init(const char *path)
michael@0 22 {
michael@0 23 spewout_ = fopen(path, "w");
michael@0 24 return spewout_ != nullptr;
michael@0 25 }
michael@0 26
michael@0 27 void
michael@0 28 C1Spewer::beginFunction(MIRGraph *graph, HandleScript script)
michael@0 29 {
michael@0 30 if (!spewout_)
michael@0 31 return;
michael@0 32
michael@0 33 this->graph = graph;
michael@0 34 this->script.repoint(script);
michael@0 35
michael@0 36 fprintf(spewout_, "begin_compilation\n");
michael@0 37 if (script) {
michael@0 38 fprintf(spewout_, " name \"%s:%d\"\n", script->filename(), (int)script->lineno());
michael@0 39 fprintf(spewout_, " method \"%s:%d\"\n", script->filename(), (int)script->lineno());
michael@0 40 } else {
michael@0 41 fprintf(spewout_, " name \"asm.js compilation\"\n");
michael@0 42 fprintf(spewout_, " method \"asm.js compilation\"\n");
michael@0 43 }
michael@0 44 fprintf(spewout_, " date %d\n", (int)time(nullptr));
michael@0 45 fprintf(spewout_, "end_compilation\n");
michael@0 46 }
michael@0 47
michael@0 48 void
michael@0 49 C1Spewer::spewPass(const char *pass)
michael@0 50 {
michael@0 51 if (!spewout_)
michael@0 52 return;
michael@0 53
michael@0 54 fprintf(spewout_, "begin_cfg\n");
michael@0 55 fprintf(spewout_, " name \"%s\"\n", pass);
michael@0 56
michael@0 57 for (MBasicBlockIterator block(graph->begin()); block != graph->end(); block++)
michael@0 58 spewPass(spewout_, *block);
michael@0 59
michael@0 60 fprintf(spewout_, "end_cfg\n");
michael@0 61 fflush(spewout_);
michael@0 62 }
michael@0 63
michael@0 64 void
michael@0 65 C1Spewer::spewIntervals(const char *pass, LinearScanAllocator *regalloc)
michael@0 66 {
michael@0 67 if (!spewout_)
michael@0 68 return;
michael@0 69
michael@0 70 fprintf(spewout_, "begin_intervals\n");
michael@0 71 fprintf(spewout_, " name \"%s\"\n", pass);
michael@0 72
michael@0 73 size_t nextId = 0x4000;
michael@0 74 for (MBasicBlockIterator block(graph->begin()); block != graph->end(); block++)
michael@0 75 spewIntervals(spewout_, *block, regalloc, nextId);
michael@0 76
michael@0 77 fprintf(spewout_, "end_intervals\n");
michael@0 78 fflush(spewout_);
michael@0 79 }
michael@0 80
michael@0 81 void
michael@0 82 C1Spewer::endFunction()
michael@0 83 {
michael@0 84 }
michael@0 85
michael@0 86 void
michael@0 87 C1Spewer::finish()
michael@0 88 {
michael@0 89 if (spewout_)
michael@0 90 fclose(spewout_);
michael@0 91 }
michael@0 92
michael@0 93 static void
michael@0 94 DumpDefinition(FILE *fp, MDefinition *def)
michael@0 95 {
michael@0 96 fprintf(fp, " ");
michael@0 97 fprintf(fp, "%u %u ", def->id(), unsigned(def->useCount()));
michael@0 98 def->printName(fp);
michael@0 99 fprintf(fp, " ");
michael@0 100 def->printOpcode(fp);
michael@0 101 fprintf(fp, " <|@\n");
michael@0 102 }
michael@0 103
michael@0 104 static void
michael@0 105 DumpLIR(FILE *fp, LInstruction *ins)
michael@0 106 {
michael@0 107 fprintf(fp, " ");
michael@0 108 fprintf(fp, "%d ", ins->id());
michael@0 109 ins->dump(fp);
michael@0 110 fprintf(fp, " <|@\n");
michael@0 111 }
michael@0 112
michael@0 113 void
michael@0 114 C1Spewer::spewIntervals(FILE *fp, LinearScanAllocator *regalloc, LInstruction *ins, size_t &nextId)
michael@0 115 {
michael@0 116 for (size_t k = 0; k < ins->numDefs(); k++) {
michael@0 117 uint32_t id = ins->getDef(k)->virtualRegister();
michael@0 118 VirtualRegister *vreg = &regalloc->vregs[id];
michael@0 119
michael@0 120 for (size_t i = 0; i < vreg->numIntervals(); i++) {
michael@0 121 LiveInterval *live = vreg->getInterval(i);
michael@0 122 if (live->numRanges()) {
michael@0 123 fprintf(fp, "%d object \"", (i == 0) ? id : int32_t(nextId++));
michael@0 124 fprintf(fp, "%s", live->getAllocation()->toString());
michael@0 125 fprintf(fp, "\" %d -1", id);
michael@0 126 for (size_t j = 0; j < live->numRanges(); j++) {
michael@0 127 fprintf(fp, " [%d, %d[", live->getRange(j)->from.pos(),
michael@0 128 live->getRange(j)->to.pos());
michael@0 129 }
michael@0 130 for (UsePositionIterator usePos(live->usesBegin()); usePos != live->usesEnd(); usePos++)
michael@0 131 fprintf(fp, " %d M", usePos->pos.pos());
michael@0 132 fprintf(fp, " \"\"\n");
michael@0 133 }
michael@0 134 }
michael@0 135 }
michael@0 136 }
michael@0 137
michael@0 138 void
michael@0 139 C1Spewer::spewIntervals(FILE *fp, MBasicBlock *block, LinearScanAllocator *regalloc, size_t &nextId)
michael@0 140 {
michael@0 141 LBlock *lir = block->lir();
michael@0 142 if (!lir)
michael@0 143 return;
michael@0 144
michael@0 145 for (size_t i = 0; i < lir->numPhis(); i++)
michael@0 146 spewIntervals(fp, regalloc, lir->getPhi(i), nextId);
michael@0 147
michael@0 148 for (LInstructionIterator ins = lir->begin(); ins != lir->end(); ins++)
michael@0 149 spewIntervals(fp, regalloc, *ins, nextId);
michael@0 150 }
michael@0 151
michael@0 152 void
michael@0 153 C1Spewer::spewPass(FILE *fp, MBasicBlock *block)
michael@0 154 {
michael@0 155 fprintf(fp, " begin_block\n");
michael@0 156 fprintf(fp, " name \"B%d\"\n", block->id());
michael@0 157 fprintf(fp, " from_bci -1\n");
michael@0 158 fprintf(fp, " to_bci -1\n");
michael@0 159
michael@0 160 fprintf(fp, " predecessors");
michael@0 161 for (uint32_t i = 0; i < block->numPredecessors(); i++) {
michael@0 162 MBasicBlock *pred = block->getPredecessor(i);
michael@0 163 fprintf(fp, " \"B%d\"", pred->id());
michael@0 164 }
michael@0 165 fprintf(fp, "\n");
michael@0 166
michael@0 167 fprintf(fp, " successors");
michael@0 168 for (uint32_t i = 0; i < block->numSuccessors(); i++) {
michael@0 169 MBasicBlock *successor = block->getSuccessor(i);
michael@0 170 fprintf(fp, " \"B%d\"", successor->id());
michael@0 171 }
michael@0 172 fprintf(fp, "\n");
michael@0 173
michael@0 174 fprintf(fp, " xhandlers\n");
michael@0 175 fprintf(fp, " flags\n");
michael@0 176
michael@0 177 if (block->lir() && block->lir()->begin() != block->lir()->end()) {
michael@0 178 fprintf(fp, " first_lir_id %d\n", block->lir()->firstId());
michael@0 179 fprintf(fp, " last_lir_id %d\n", block->lir()->lastId());
michael@0 180 }
michael@0 181
michael@0 182 fprintf(fp, " begin_states\n");
michael@0 183
michael@0 184 if (block->entryResumePoint()) {
michael@0 185 fprintf(fp, " begin_locals\n");
michael@0 186 fprintf(fp, " size %d\n", (int)block->numEntrySlots());
michael@0 187 fprintf(fp, " method \"None\"\n");
michael@0 188 for (uint32_t i = 0; i < block->numEntrySlots(); i++) {
michael@0 189 MDefinition *ins = block->getEntrySlot(i);
michael@0 190 fprintf(fp, " ");
michael@0 191 fprintf(fp, "%d ", i);
michael@0 192 if (ins->isUnused())
michael@0 193 fprintf(fp, "unused");
michael@0 194 else
michael@0 195 ins->printName(fp);
michael@0 196 fprintf(fp, "\n");
michael@0 197 }
michael@0 198 fprintf(fp, " end_locals\n");
michael@0 199 }
michael@0 200 fprintf(fp, " end_states\n");
michael@0 201
michael@0 202 fprintf(fp, " begin_HIR\n");
michael@0 203 for (MPhiIterator phi(block->phisBegin()); phi != block->phisEnd(); phi++)
michael@0 204 DumpDefinition(fp, *phi);
michael@0 205 for (MInstructionIterator i(block->begin()); i != block->end(); i++)
michael@0 206 DumpDefinition(fp, *i);
michael@0 207 fprintf(fp, " end_HIR\n");
michael@0 208
michael@0 209 if (block->lir()) {
michael@0 210 fprintf(fp, " begin_LIR\n");
michael@0 211 for (size_t i = 0; i < block->lir()->numPhis(); i++)
michael@0 212 DumpLIR(fp, block->lir()->getPhi(i));
michael@0 213 for (LInstructionIterator i(block->lir()->begin()); i != block->lir()->end(); i++)
michael@0 214 DumpLIR(fp, *i);
michael@0 215 fprintf(fp, " end_LIR\n");
michael@0 216 }
michael@0 217
michael@0 218 fprintf(fp, " end_block\n");
michael@0 219 }
michael@0 220
michael@0 221 #endif /* DEBUG */
michael@0 222

mercurial