comparison graal/GraalCompiler/src/com/sun/c1x/ir/AccessIndexed.java @ 2509:16b9a8b5ad39

Renamings Runtime=>GraalRuntime and Compiler=>GraalCompiler
author Thomas Wuerthinger <thomas@wuerthinger.net>
date Wed, 27 Apr 2011 11:50:44 +0200
parents graal/Compiler/src/com/sun/c1x/ir/AccessIndexed.java@9ec15d6914ca
children 0f9eeb15e636
comparison
equal deleted inserted replaced
2508:fea94949e0a2 2509:16b9a8b5ad39
1 /*
2 * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
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 com.sun.c1x.ir;
24
25 import static com.sun.c1x.ir.Value.Flag.*;
26
27 import com.sun.c1x.value.*;
28 import com.sun.cri.ci.*;
29
30 /**
31 * The {@code AccessIndexed} class is the base class of instructions that read or write
32 * elements of an array.
33 *
34 * @author Ben L. Titzer
35 */
36 public abstract class AccessIndexed extends AccessArray {
37
38 private Value index;
39 private Value length;
40 private final CiKind elementType;
41
42 /**
43 * Create an new AccessIndexed instruction.
44 * @param kind the result kind of the access
45 * @param array the instruction producing the array
46 * @param index the instruction producing the index
47 * @param length the instruction producing the length (used in bounds check elimination?)
48 * @param elementType the type of the elements of the array
49 * @param stateBefore the state before executing this instruction
50 */
51 AccessIndexed(CiKind kind, Value array, Value index, Value length, CiKind elementType, FrameState stateBefore) {
52 super(kind, array, stateBefore);
53 this.index = index;
54 this.length = length;
55 this.elementType = elementType;
56 }
57
58 /**
59 * Gets the instruction producing the index into the array.
60 * @return the index
61 */
62 public Value index() {
63 return index;
64 }
65
66 /**
67 * Gets the instruction that produces the length of the array.
68 * @return the length
69 */
70 public Value length() {
71 return length;
72 }
73
74 /**
75 * Gets the element type of the array.
76 * @return the element type
77 */
78 public CiKind elementKind() {
79 return elementType;
80 }
81
82 /**
83 * Checks whether this instruction needs a bounds check.
84 * @return {@code true} if a bounds check is needed
85 */
86 public boolean needsBoundsCheck() {
87 return !checkFlag(NoBoundsCheck);
88 }
89
90 public void eliminateBoundsCheck() {
91 clearRuntimeCheck(NoBoundsCheck);
92 }
93
94 /**
95 * Checks whether this instruction can cause a trap.
96 * @return {@code true} if this instruction can cause a trap
97 */
98 @Override
99 public boolean canTrap() {
100 return needsNullCheck() || needsBoundsCheck();
101 }
102
103 @Override
104 public void inputValuesDo(ValueClosure closure) {
105 super.inputValuesDo(closure);
106 index = closure.apply(index);
107 if (length != null) {
108 length = closure.apply(length);
109 }
110 }
111 }