1/*
2 * Copyright (C) 2016-2017 Apple Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
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.
12 *
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.
24 */
25
26#include "config.h"
27#include "AirLogRegisterPressure.h"
28
29#if ENABLE(B3_JIT)
30
31#include "AirArgInlines.h"
32#include "AirCode.h"
33#include "AirInstInlines.h"
34#include "AirRegLiveness.h"
35
36namespace JSC { namespace B3 { namespace Air {
37
38void logRegisterPressure(Code& code)
39{
40 const unsigned totalColumns = 200;
41 const unsigned registerColumns = 100;
42
43 RegLiveness liveness(code);
44
45 for (BasicBlock* block : code) {
46 RegLiveness::LocalCalc localCalc(liveness, block);
47
48 block->dumpHeader(WTF::dataFile());
49
50 Vector<CString> instDumps;
51 for (unsigned instIndex = block->size(); instIndex--;) {
52 Inst& inst = block->at(instIndex);
53 Inst* prevInst = block->get(instIndex - 1);
54
55 localCalc.execute(instIndex);
56
57 RegisterSet set;
58 set.setAll(localCalc.live());
59 Inst::forEachDefWithExtraClobberedRegs<Reg>(
60 prevInst, &inst,
61 [&] (Reg reg, Arg::Role, Bank, Width) {
62 set.set(reg);
63 });
64
65 StringPrintStream instOut;
66 StringPrintStream lineOut;
67 lineOut.print(" ");
68 if (set.numberOfSetRegisters()) {
69 set.forEach(
70 [&] (Reg reg) {
71 CString text = toCString(" ", reg);
72 if (text.length() + lineOut.length() > totalColumns) {
73 instOut.print(lineOut.toCString(), "\n");
74 lineOut.reset();
75 lineOut.print(" ");
76 }
77 lineOut.print(text);
78 });
79 lineOut.print(":");
80 }
81 if (lineOut.length() > registerColumns) {
82 instOut.print(lineOut.toCString(), "\n");
83 lineOut.reset();
84 }
85 while (lineOut.length() < registerColumns)
86 lineOut.print(" ");
87 lineOut.print(" ");
88 lineOut.print(inst);
89 instOut.print(lineOut.toCString(), "\n");
90 instDumps.append(instOut.toCString());
91 }
92
93 for (unsigned i = instDumps.size(); i--;)
94 dataLog(instDumps[i]);
95
96 block->dumpFooter(WTF::dataFile());
97 }
98}
99
100} } } // namespace JSC::B3::Air
101
102#endif // ENABLE(B3_JIT)
103
104