10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23 package org.graalvm.compiler.hotspot.lir;
24
25 import static jdk.vm.ci.code.ValueUtil.isStackSlot;
26
27 import java.util.ArrayList;
28
29 import org.graalvm.compiler.core.common.cfg.AbstractBlockBase;
30 import org.graalvm.compiler.debug.Debug;
31 import org.graalvm.compiler.debug.Indent;
32 import org.graalvm.compiler.hotspot.HotSpotLIRGenerationResult;
33 import org.graalvm.compiler.hotspot.stubs.Stub;
34 import org.graalvm.compiler.lir.LIR;
35 import org.graalvm.compiler.lir.LIRFrameState;
36 import org.graalvm.compiler.lir.LIRInsertionBuffer;
37 import org.graalvm.compiler.lir.LIRInstruction;
38 import org.graalvm.compiler.lir.StandardOp.SaveRegistersOp;
39 import org.graalvm.compiler.lir.gen.DiagnosticLIRGeneratorTool;
40 import org.graalvm.compiler.lir.gen.DiagnosticLIRGeneratorTool.ZapRegistersAfterInstruction;
41 import org.graalvm.compiler.lir.gen.DiagnosticLIRGeneratorTool.ZapStackArgumentSpaceBeforeInstruction;
42 import org.graalvm.compiler.lir.gen.LIRGenerationResult;
43 import org.graalvm.compiler.lir.phases.PostAllocationOptimizationPhase;
44
45 import jdk.vm.ci.code.TargetDescription;
46 import jdk.vm.ci.meta.AllocatableValue;
47
48 /**
49 * Inserts a {@link DiagnosticLIRGeneratorTool#createZapRegisters ZapRegistersOp} after
50 * {@link ZapRegistersAfterInstruction} for stubs and
65 }
66 }
67 if (zapRegisters || zapStack) {
68 LIR lir = lirGenRes.getLIR();
69 processLIR(context.diagnosticLirGenTool, (HotSpotLIRGenerationResult) lirGenRes, lir, zapRegisters, zapStack);
70 }
71 }
72
73 private static void processLIR(DiagnosticLIRGeneratorTool diagnosticLirGenTool, HotSpotLIRGenerationResult res, LIR lir, boolean zapRegisters, boolean zapStack) {
74 LIRInsertionBuffer buffer = new LIRInsertionBuffer();
75 for (AbstractBlockBase<?> block : lir.codeEmittingOrder()) {
76 if (block != null) {
77 processBlock(diagnosticLirGenTool, res, lir, buffer, block, zapRegisters, zapStack);
78 }
79 }
80 }
81
82 @SuppressWarnings("try")
83 private static void processBlock(DiagnosticLIRGeneratorTool diagnosticLirGenTool, HotSpotLIRGenerationResult res, LIR lir, LIRInsertionBuffer buffer, AbstractBlockBase<?> block,
84 boolean zapRegisters, boolean zapStack) {
85 try (Indent indent = Debug.logAndIndent("Process block %s", block)) {
86 ArrayList<LIRInstruction> instructions = lir.getLIRforBlock(block);
87 buffer.init(instructions);
88 for (int index = 0; index < instructions.size(); index++) {
89 LIRInstruction inst = instructions.get(index);
90 if (zapStack && inst instanceof ZapStackArgumentSpaceBeforeInstruction) {
91 LIRInstruction zap = diagnosticLirGenTool.zapArgumentSpace();
92 if (zap != null) {
93 buffer.append(index, zap);
94 }
95 }
96 if (zapRegisters && inst instanceof ZapRegistersAfterInstruction) {
97 LIRFrameState state = getLIRState(inst);
98 if (state != null) {
99 SaveRegistersOp zap = diagnosticLirGenTool.createZapRegisters();
100 SaveRegistersOp old = res.getCalleeSaveInfo().put(state, zap);
101 assert old == null : "Already another SaveRegisterOp registered! " + old;
102 buffer.append(index + 1, (LIRInstruction) zap);
103 Debug.log("Insert ZapRegister after %s", inst);
104 }
105 }
106 }
107 buffer.finish();
108 }
109 }
110
111 /**
112 * Returns the {@link LIRFrameState} of an instruction.
113 */
114 private static LIRFrameState getLIRState(LIRInstruction inst) {
115 final LIRFrameState[] lirState = {null};
116 inst.forEachState(state -> {
117 assert lirState[0] == null : "Multiple states: " + inst;
118 lirState[0] = state;
119 });
120 assert lirState[0] != null : "No state: " + inst;
121 return lirState[0];
122 }
123
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23 package org.graalvm.compiler.hotspot.lir;
24
25 import static jdk.vm.ci.code.ValueUtil.isStackSlot;
26
27 import java.util.ArrayList;
28
29 import org.graalvm.compiler.core.common.cfg.AbstractBlockBase;
30 import org.graalvm.compiler.debug.DebugContext;
31 import org.graalvm.compiler.debug.Indent;
32 import org.graalvm.compiler.hotspot.HotSpotLIRGenerationResult;
33 import org.graalvm.compiler.hotspot.stubs.Stub;
34 import org.graalvm.compiler.lir.LIR;
35 import org.graalvm.compiler.lir.LIRFrameState;
36 import org.graalvm.compiler.lir.LIRInsertionBuffer;
37 import org.graalvm.compiler.lir.LIRInstruction;
38 import org.graalvm.compiler.lir.StandardOp.SaveRegistersOp;
39 import org.graalvm.compiler.lir.gen.DiagnosticLIRGeneratorTool;
40 import org.graalvm.compiler.lir.gen.DiagnosticLIRGeneratorTool.ZapRegistersAfterInstruction;
41 import org.graalvm.compiler.lir.gen.DiagnosticLIRGeneratorTool.ZapStackArgumentSpaceBeforeInstruction;
42 import org.graalvm.compiler.lir.gen.LIRGenerationResult;
43 import org.graalvm.compiler.lir.phases.PostAllocationOptimizationPhase;
44
45 import jdk.vm.ci.code.TargetDescription;
46 import jdk.vm.ci.meta.AllocatableValue;
47
48 /**
49 * Inserts a {@link DiagnosticLIRGeneratorTool#createZapRegisters ZapRegistersOp} after
50 * {@link ZapRegistersAfterInstruction} for stubs and
65 }
66 }
67 if (zapRegisters || zapStack) {
68 LIR lir = lirGenRes.getLIR();
69 processLIR(context.diagnosticLirGenTool, (HotSpotLIRGenerationResult) lirGenRes, lir, zapRegisters, zapStack);
70 }
71 }
72
73 private static void processLIR(DiagnosticLIRGeneratorTool diagnosticLirGenTool, HotSpotLIRGenerationResult res, LIR lir, boolean zapRegisters, boolean zapStack) {
74 LIRInsertionBuffer buffer = new LIRInsertionBuffer();
75 for (AbstractBlockBase<?> block : lir.codeEmittingOrder()) {
76 if (block != null) {
77 processBlock(diagnosticLirGenTool, res, lir, buffer, block, zapRegisters, zapStack);
78 }
79 }
80 }
81
82 @SuppressWarnings("try")
83 private static void processBlock(DiagnosticLIRGeneratorTool diagnosticLirGenTool, HotSpotLIRGenerationResult res, LIR lir, LIRInsertionBuffer buffer, AbstractBlockBase<?> block,
84 boolean zapRegisters, boolean zapStack) {
85 DebugContext debug = lir.getDebug();
86 try (Indent indent = debug.logAndIndent("Process block %s", block)) {
87 ArrayList<LIRInstruction> instructions = lir.getLIRforBlock(block);
88 buffer.init(instructions);
89 for (int index = 0; index < instructions.size(); index++) {
90 LIRInstruction inst = instructions.get(index);
91 if (zapStack && inst instanceof ZapStackArgumentSpaceBeforeInstruction) {
92 LIRInstruction zap = diagnosticLirGenTool.zapArgumentSpace();
93 if (zap != null) {
94 buffer.append(index, zap);
95 }
96 }
97 if (zapRegisters && inst instanceof ZapRegistersAfterInstruction) {
98 LIRFrameState state = getLIRState(inst);
99 if (state != null) {
100 SaveRegistersOp zap = diagnosticLirGenTool.createZapRegisters();
101 SaveRegistersOp old = res.getCalleeSaveInfo().put(state, zap);
102 assert old == null : "Already another SaveRegisterOp registered! " + old;
103 buffer.append(index + 1, (LIRInstruction) zap);
104 debug.log("Insert ZapRegister after %s", inst);
105 }
106 }
107 }
108 buffer.finish();
109 }
110 }
111
112 /**
113 * Returns the {@link LIRFrameState} of an instruction.
114 */
115 private static LIRFrameState getLIRState(LIRInstruction inst) {
116 final LIRFrameState[] lirState = {null};
117 inst.forEachState(state -> {
118 assert lirState[0] == null : "Multiple states: " + inst;
119 lirState[0] = state;
120 });
121 assert lirState[0] != null : "No state: " + inst;
122 return lirState[0];
123 }
124
|