Mercurial > hg > graal-jvmci-8
comparison graal/Compiler/src/com/sun/c1x/alloc/LIRInsertionBuffer.java @ 2507:9ec15d6914ca
Pull over of compiler from maxine repository.
author | Thomas Wuerthinger <thomas@wuerthinger.net> |
---|---|
date | Wed, 27 Apr 2011 11:43:22 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
2506:4a3bf8a5bf41 | 2507:9ec15d6914ca |
---|---|
1 /* | |
2 * Copyright (c) 2009, 2010, 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.alloc; | |
24 | |
25 import java.util.*; | |
26 | |
27 import com.sun.c1x.lir.*; | |
28 import com.sun.c1x.util.*; | |
29 import com.sun.cri.ci.*; | |
30 | |
31 /** | |
32 * | |
33 * @author Thomas Wuerthinger | |
34 */ | |
35 public final class LIRInsertionBuffer { | |
36 | |
37 private LIRList lir; // the lir list where ops of this buffer should be inserted later (null when uninitialized) | |
38 | |
39 // list of insertion points. index and count are stored alternately: | |
40 // indexAndCount[i * 2]: the index into lir list where "count" ops should be inserted | |
41 // indexAndCount[i * 2 + 1]: the number of ops to be inserted at index | |
42 private final IntList indexAndCount; | |
43 | |
44 // the LIROps to be inserted | |
45 private final List<LIRInstruction> ops; | |
46 | |
47 private void appendNew(int index, int count) { | |
48 indexAndCount.add(index); | |
49 indexAndCount.add(count); | |
50 } | |
51 | |
52 private void setCountAt(int i, int value) { | |
53 indexAndCount.set((i << 1) + 1, value); | |
54 } | |
55 | |
56 LIRInsertionBuffer() { | |
57 ops = new ArrayList<LIRInstruction>(8); | |
58 indexAndCount = new IntList(8); | |
59 } | |
60 | |
61 // must be called before using the insertion buffer | |
62 void init(LIRList lir) { | |
63 assert !initialized() : "already initialized"; | |
64 this.lir = lir; | |
65 indexAndCount.clear(); | |
66 ops.clear(); | |
67 } | |
68 | |
69 boolean initialized() { | |
70 return lir != null; | |
71 } | |
72 | |
73 // called automatically when the buffer is appended to the LIRList | |
74 public void finish() { | |
75 lir = null; | |
76 } | |
77 | |
78 // accessors | |
79 public LIRList lirList() { | |
80 return lir; | |
81 } | |
82 | |
83 public int numberOfInsertionPoints() { | |
84 return indexAndCount.size() >> 1; | |
85 } | |
86 | |
87 public int indexAt(int i) { | |
88 return indexAndCount.get((i << 1)); | |
89 } | |
90 | |
91 public int countAt(int i) { | |
92 return indexAndCount.get((i << 1) + 1); | |
93 } | |
94 | |
95 public int numberOfOps() { | |
96 return ops.size(); | |
97 } | |
98 | |
99 public LIRInstruction opAt(int i) { | |
100 return ops.get(i); | |
101 } | |
102 | |
103 void move(int index, CiValue src, CiValue dst, LIRDebugInfo info) { | |
104 append(index, new LIROp1(LIROpcode.Move, src, dst, dst.kind, info)); | |
105 } | |
106 | |
107 // Implementation of LIRInsertionBuffer | |
108 | |
109 private void append(int index, LIRInstruction op) { | |
110 assert indexAndCount.size() % 2 == 0 : "must have a count for each index"; | |
111 | |
112 int i = numberOfInsertionPoints() - 1; | |
113 if (i < 0 || indexAt(i) < index) { | |
114 appendNew(index, 1); | |
115 } else { | |
116 assert indexAt(i) == index : "can append LIROps in ascending order only"; | |
117 assert countAt(i) > 0 : "check"; | |
118 setCountAt(i, countAt(i) + 1); | |
119 } | |
120 ops.add(op); | |
121 | |
122 assert verify(); | |
123 } | |
124 | |
125 private boolean verify() { | |
126 int sum = 0; | |
127 int prevIdx = -1; | |
128 | |
129 for (int i = 0; i < numberOfInsertionPoints(); i++) { | |
130 assert prevIdx < indexAt(i) : "index must be ordered ascending"; | |
131 sum += countAt(i); | |
132 } | |
133 assert sum == numberOfOps() : "wrong total sum"; | |
134 return true; | |
135 } | |
136 } |