aboutsummaryrefslogtreecommitdiff
path: root/src/share/vm/shark/sharkValue.cpp
blob: 0c4ef006a61829dd295d595261b29a6ed0089024 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
/*
 * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
 * Copyright 2008, 2009 Red Hat, Inc.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 * or visit www.oracle.com if you need additional information or have any
 * questions.
 *
 */

#include "precompiled.hpp"
#include "ci/ciType.hpp"
#include "shark/llvmHeaders.hpp"
#include "shark/llvmValue.hpp"
#include "shark/sharkBuilder.hpp"
#include "shark/sharkValue.hpp"

using namespace llvm;

// Cloning

SharkValue* SharkNormalValue::clone() const {
  return SharkValue::create_generic(type(), generic_value(), zero_checked());
}
SharkValue* SharkPHIValue::clone() const {
  return SharkValue::create_phi(type(), (PHINode *) generic_value(), this);
}
SharkValue* SharkAddressValue::clone() const {
  return SharkValue::address_constant(address_value());
}

// Casting

bool SharkValue::is_phi() const {
  return false;
}
bool SharkPHIValue::is_phi() const {
  return true;
}
SharkPHIValue* SharkValue::as_phi() {
  ShouldNotCallThis();
}
SharkPHIValue* SharkPHIValue::as_phi() {
  return this;
}

// Comparison

bool SharkNormalValue::equal_to(SharkValue *other) const {
  return (this->type()          == other->type() &&
          this->generic_value() == other->generic_value() &&
          this->zero_checked()  == other->zero_checked());
}
bool SharkAddressValue::equal_to(SharkValue *other) const {
  return (this->address_value() == other->address_value());
}

// Type access

ciType* SharkValue::type() const {
  ShouldNotCallThis();
}
ciType* SharkNormalValue::type() const {
  return _type;
}

BasicType SharkNormalValue::basic_type() const {
  return type()->basic_type();
}
BasicType SharkAddressValue::basic_type() const {
  return T_ADDRESS;
}

int SharkNormalValue::size() const {
  return type()->size();
}
int SharkAddressValue::size() const {
  return 1;
}

bool SharkValue::is_jint() const {
  return false;
}
bool SharkValue::is_jlong() const {
  return false;
}
bool SharkValue::is_jfloat() const {
  return false;
}
bool SharkValue::is_jdouble() const {
  return false;
}
bool SharkValue::is_jobject() const {
  return false;
}
bool SharkValue::is_jarray() const {
  return false;
}
bool SharkValue::is_address() const {
  return false;
}

bool SharkNormalValue::is_jint() const {
  return llvm_value()->getType() == SharkType::jint_type();
}
bool SharkNormalValue::is_jlong() const {
  return llvm_value()->getType() == SharkType::jlong_type();
}
bool SharkNormalValue::is_jfloat() const {
  return llvm_value()->getType() == SharkType::jfloat_type();
}
bool SharkNormalValue::is_jdouble() const {
  return llvm_value()->getType() == SharkType::jdouble_type();
}
bool SharkNormalValue::is_jobject() const {
  return llvm_value()->getType() == SharkType::oop_type();
}
bool SharkNormalValue::is_jarray() const {
  return basic_type() == T_ARRAY;
}
bool SharkAddressValue::is_address() const {
  return true;
}

// Typed conversions from SharkValues

Value* SharkValue::jint_value() const {
  ShouldNotCallThis();
}
Value* SharkValue::jlong_value() const {
  ShouldNotCallThis();
}
Value* SharkValue::jfloat_value() const {
  ShouldNotCallThis();
}
Value* SharkValue::jdouble_value() const {
  ShouldNotCallThis();
}
Value* SharkValue::jobject_value() const {
  ShouldNotCallThis();
}
Value* SharkValue::jarray_value() const {
  ShouldNotCallThis();
}
int SharkValue::address_value() const {
  ShouldNotCallThis();
}

Value* SharkNormalValue::jint_value() const {
  assert(is_jint(), "should be");
  return llvm_value();
}
Value* SharkNormalValue::jlong_value() const {
  assert(is_jlong(), "should be");
  return llvm_value();
}
Value* SharkNormalValue::jfloat_value() const {
  assert(is_jfloat(), "should be");
  return llvm_value();
}
Value* SharkNormalValue::jdouble_value() const {
  assert(is_jdouble(), "should be");
  return llvm_value();
}
Value* SharkNormalValue::jobject_value() const {
  assert(is_jobject(), "should be");
  return llvm_value();
}
Value* SharkNormalValue::jarray_value() const {
  // XXX assert(is_jarray(), "should be");
  // XXX http://icedtea.classpath.org/bugzilla/show_bug.cgi?id=324
  assert(is_jobject(), "should be");
  return llvm_value();
}
int SharkAddressValue::address_value() const {
  return _bci;
}

// Type-losing conversions -- use with care!

Value* SharkNormalValue::generic_value() const {
  return llvm_value();
}
Value* SharkAddressValue::generic_value() const {
  return LLVMValue::intptr_constant(address_value());
}

Value* SharkValue::intptr_value(SharkBuilder* builder) const {
  ShouldNotCallThis();
}
Value* SharkNormalValue::intptr_value(SharkBuilder* builder) const {
  return builder->CreatePtrToInt(jobject_value(), SharkType::intptr_type());
}

// Phi-style stuff for SharkPHIState::add_incoming

void SharkValue::addIncoming(SharkValue *value, BasicBlock* block) {
  ShouldNotCallThis();
}
void SharkPHIValue::addIncoming(SharkValue *value, BasicBlock* block) {
  assert(!is_clone(), "shouldn't be");
  ((llvm::PHINode *) generic_value())->addIncoming(
      value->generic_value(), block);
  if (!value->zero_checked())
    _all_incomers_zero_checked = false;
}
void SharkAddressValue::addIncoming(SharkValue *value, BasicBlock* block) {
  assert(this->equal_to(value), "should be");
}

// Phi-style stuff for SharkState::merge

SharkValue* SharkNormalValue::merge(SharkBuilder* builder,
                                    SharkValue*   other,
                                    BasicBlock*   other_block,
                                    BasicBlock*   this_block,
                                    const char*   name) {
  assert(type() == other->type(), "should be");
  assert(zero_checked() == other->zero_checked(), "should be");

  PHINode *phi = builder->CreatePHI(SharkType::to_stackType(type()), 0, name);
  phi->addIncoming(this->generic_value(), this_block);
  phi->addIncoming(other->generic_value(), other_block);
  return SharkValue::create_generic(type(), phi, zero_checked());
}
SharkValue* SharkAddressValue::merge(SharkBuilder* builder,
                                     SharkValue*   other,
                                     BasicBlock*   other_block,
                                     BasicBlock*   this_block,
                                     const char*   name) {
  assert(this->equal_to(other), "should be");
  return this;
}

// Repeated null and divide-by-zero check removal

bool SharkValue::zero_checked() const {
  ShouldNotCallThis();
}
void SharkValue::set_zero_checked(bool zero_checked) {
  ShouldNotCallThis();
}

bool SharkNormalValue::zero_checked() const {
  return _zero_checked;
}
void SharkNormalValue::set_zero_checked(bool zero_checked) {
  _zero_checked = zero_checked;
}