2
* Copyright (C) 2012 Apple Inc. All rights reserved.
4
* Redistribution and use in source and binary forms, with or without
5
* modification, are permitted provided that the following conditions
7
* 1. Redistributions of source code must retain the above copyright
8
* notice, this list of conditions and the following disclaimer.
9
* 2. Redistributions in binary form must reproduce the above copyright
10
* notice, this list of conditions and the following disclaimer in the
11
* documentation and/or other materials provided with the distribution.
13
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
#include "DFGDisassembler.h"
31
#include "CodeBlockWithJITType.h"
34
namespace JSC { namespace DFG {
36
Disassembler::Disassembler(Graph& graph)
39
m_labelForBlockIndex.resize(graph.m_blocks.size());
40
m_labelForNodeIndex.resize(graph.size());
43
void Disassembler::dump(PrintStream& out, LinkBuffer& linkBuffer)
45
m_graph.m_dominators.computeIfNecessary(m_graph);
47
out.print("Generated JIT code for ", CodeBlockWithJITType(m_graph.m_codeBlock, JITCode::DFGJIT), ", instruction count = ", m_graph.m_codeBlock->instructionCount(), ":\n");
48
out.print(" Code at [", RawPointer(linkBuffer.debugAddress()), ", ", RawPointer(static_cast<char*>(linkBuffer.debugAddress()) + linkBuffer.debugSize()), "):\n");
50
const char* prefix = " ";
51
const char* disassemblyPrefix = " ";
53
NodeIndex lastNodeIndex = NoNode;
54
MacroAssembler::Label previousLabel = m_startOfCode;
55
for (size_t blockIndex = 0; blockIndex < m_graph.m_blocks.size(); ++blockIndex) {
56
BasicBlock* block = m_graph.m_blocks[blockIndex].get();
59
dumpDisassembly(out, disassemblyPrefix, linkBuffer, previousLabel, m_labelForBlockIndex[blockIndex], lastNodeIndex);
60
m_graph.dumpBlockHeader(out, prefix, blockIndex, Graph::DumpLivePhisOnly);
61
NodeIndex lastNodeIndexForDisassembly = block->at(0);
62
for (size_t i = 0; i < block->size(); ++i) {
63
if (!m_graph[block->at(i)].willHaveCodeGenOrOSR() && !Options::showAllDFGNodes())
65
MacroAssembler::Label currentLabel;
66
if (m_labelForNodeIndex[block->at(i)].isSet())
67
currentLabel = m_labelForNodeIndex[block->at(i)];
69
// Dump the last instruction by using the first label of the next block
70
// as the end point. This case is hit either during peephole compare
71
// optimizations (the Branch won't have its own label) or if we have a
73
if (blockIndex + 1 < m_graph.m_blocks.size())
74
currentLabel = m_labelForBlockIndex[blockIndex + 1];
76
currentLabel = m_endOfMainPath;
78
dumpDisassembly(out, disassemblyPrefix, linkBuffer, previousLabel, currentLabel, lastNodeIndexForDisassembly);
79
m_graph.dumpCodeOrigin(out, prefix, lastNodeIndex, block->at(i));
80
m_graph.dump(out, prefix, block->at(i));
81
lastNodeIndex = block->at(i);
82
lastNodeIndexForDisassembly = block->at(i);
85
dumpDisassembly(out, disassemblyPrefix, linkBuffer, previousLabel, m_endOfMainPath, lastNodeIndex);
86
out.print(prefix, "(End Of Main Path)\n");
87
dumpDisassembly(out, disassemblyPrefix, linkBuffer, previousLabel, m_endOfCode, NoNode);
90
void Disassembler::dump(LinkBuffer& linkBuffer)
92
dump(WTF::dataFile(), linkBuffer);
95
void Disassembler::dumpDisassembly(PrintStream& out, const char* prefix, LinkBuffer& linkBuffer, MacroAssembler::Label& previousLabel, MacroAssembler::Label currentLabel, NodeIndex context)
97
size_t prefixLength = strlen(prefix);
98
int amountOfNodeWhiteSpace;
99
if (context == NoNode)
100
amountOfNodeWhiteSpace = 0;
102
amountOfNodeWhiteSpace = Graph::amountOfNodeWhiteSpace(m_graph[context]);
103
OwnArrayPtr<char> prefixBuffer = adoptArrayPtr(new char[prefixLength + amountOfNodeWhiteSpace + 1]);
104
strcpy(prefixBuffer.get(), prefix);
105
for (int i = 0; i < amountOfNodeWhiteSpace; ++i)
106
prefixBuffer[i + prefixLength] = ' ';
107
prefixBuffer[prefixLength + amountOfNodeWhiteSpace] = 0;
109
CodeLocationLabel start = linkBuffer.locationOf(previousLabel);
110
CodeLocationLabel end = linkBuffer.locationOf(currentLabel);
111
previousLabel = currentLabel;
112
ASSERT(bitwise_cast<uintptr_t>(end.executableAddress()) >= bitwise_cast<uintptr_t>(start.executableAddress()));
113
disassemble(start, bitwise_cast<uintptr_t>(end.executableAddress()) - bitwise_cast<uintptr_t>(start.executableAddress()), prefixBuffer.get(), out);
116
} } // namespace JSC::DFG
118
#endif // ENABLE(DFG_JIT)