annotate graal/GraalCompiler/src/com/sun/c1x/lir/LIRTableSwitch.java @ 2822:530366123e46

Invoke is a block end
author Gilles Duboscq <gilles.duboscq@oracle.com>
date Fri, 27 May 2011 15:41:10 +0200
parents 5e8a69041cd7
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2507
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
1 /*
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
2 * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved.
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
4 *
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
7 * published by the Free Software Foundation.
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
8 *
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
13 * accompanied this code).
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
14 *
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
18 *
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
21 * questions.
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
22 */
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
23 package com.sun.c1x.lir;
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
24
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
25 import com.sun.cri.ci.*;
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
26
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
27 /**
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
28 * @author Doug Simon
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
29 */
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
30 public class LIRTableSwitch extends LIRInstruction {
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
31
2725
c379183d1c54 Removed target block references from LIR to BlockBegin instructions. Now there is a getLIRBlock method in the LIRGenerator.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2718
diff changeset
32 public LIRBlock defaultTarget;
2507
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
33
2725
c379183d1c54 Removed target block references from LIR to BlockBegin instructions. Now there is a getLIRBlock method in the LIRGenerator.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2718
diff changeset
34 public final LIRBlock[] targets;
2507
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
35
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
36 public final int lowKey;
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
37
2725
c379183d1c54 Removed target block references from LIR to BlockBegin instructions. Now there is a getLIRBlock method in the LIRGenerator.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2718
diff changeset
38 public LIRTableSwitch(CiValue value, int lowKey, LIRBlock defaultTarget, LIRBlock[] targets) {
2507
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
39 super(LIROpcode.TableSwitch, CiValue.IllegalValue, null, false, 1, 0, value);
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
40 this.lowKey = lowKey;
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
41 this.targets = targets;
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
42 this.defaultTarget = defaultTarget;
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
43 }
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
44
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
45 @Override
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
46 public void emitCode(LIRAssembler masm) {
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
47 masm.emitTableSwitch(this);
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
48 }
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
49
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
50 /**
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
51 * @return the input value to this switch
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
52 */
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
53 public CiValue value() {
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
54 return operand(0);
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
55 }
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
56
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
57 @Override
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
58 public String operationString(OperandFormatter operandFmt) {
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
59 StringBuilder buf = new StringBuilder(super.operationString(operandFmt));
2725
c379183d1c54 Removed target block references from LIR to BlockBegin instructions. Now there is a getLIRBlock method in the LIRGenerator.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2718
diff changeset
60 buf.append("\ndefault: [B").append(defaultTarget.blockID()).append(']');
2507
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
61 int key = lowKey;
2725
c379183d1c54 Removed target block references from LIR to BlockBegin instructions. Now there is a getLIRBlock method in the LIRGenerator.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2718
diff changeset
62 for (LIRBlock b : targets) {
c379183d1c54 Removed target block references from LIR to BlockBegin instructions. Now there is a getLIRBlock method in the LIRGenerator.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2718
diff changeset
63 buf.append("\ncase ").append(key).append(": [B").append(b.blockID()).append(']');
2507
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
64 key++;
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
65 }
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
66 return buf.toString();
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
67 }
2761
d3398b21faf9 Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2731
diff changeset
68
d3398b21faf9 Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2731
diff changeset
69
d3398b21faf9 Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2731
diff changeset
70 private LIRBlock substitute(LIRBlock block, LIRBlock oldBlock, LIRBlock newBlock) {
d3398b21faf9 Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2731
diff changeset
71 if (block == oldBlock) {
d3398b21faf9 Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2731
diff changeset
72 LIRInstruction instr = newBlock.lir().instructionsList().get(0);
d3398b21faf9 Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2731
diff changeset
73 assert instr instanceof LIRLabel : "first instruction of block must be label";
d3398b21faf9 Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2731
diff changeset
74 return newBlock;
d3398b21faf9 Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2731
diff changeset
75 }
d3398b21faf9 Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2731
diff changeset
76 return oldBlock;
d3398b21faf9 Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2731
diff changeset
77 }
d3398b21faf9 Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2731
diff changeset
78
d3398b21faf9 Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2731
diff changeset
79 public void substitute(LIRBlock oldBlock, LIRBlock newBlock) {
d3398b21faf9 Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2731
diff changeset
80 if (substitute(defaultTarget, oldBlock, newBlock) == newBlock) {
d3398b21faf9 Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2731
diff changeset
81 defaultTarget = newBlock;
d3398b21faf9 Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2731
diff changeset
82 }
d3398b21faf9 Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2731
diff changeset
83 for (int i = 0; i < targets.length; i++) {
d3398b21faf9 Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2731
diff changeset
84 if (substitute(targets[i], oldBlock, newBlock) == newBlock) {
d3398b21faf9 Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2731
diff changeset
85 targets[i] = newBlock;
d3398b21faf9 Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2731
diff changeset
86 }
d3398b21faf9 Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2731
diff changeset
87 }
d3398b21faf9 Re-enabled CFG optimization (now only on LIRBlock data structure).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2731
diff changeset
88 }
2507
9ec15d6914ca Pull over of compiler from maxine repository.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
diff changeset
89 }