src/share/vm/shark/sharkValue.cpp

Wed, 11 Aug 2010 05:51:21 -0700

author
twisti
date
Wed, 11 Aug 2010 05:51:21 -0700
changeset 2047
d2ede61b7a12
child 2314
f95d63e2154a
permissions
-rw-r--r--

6976186: integrate Shark HotSpot changes
Summary: Shark is a JIT compiler for Zero that uses the LLVM compiler infrastructure.
Reviewed-by: kvn, twisti
Contributed-by: Gary Benson <gbenson@redhat.com>

twisti@2047 1 /*
twisti@2047 2 * Copyright (c) 1999, 2007, Oracle and/or its affiliates. All rights reserved.
twisti@2047 3 * Copyright 2008, 2009 Red Hat, Inc.
twisti@2047 4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
twisti@2047 5 *
twisti@2047 6 * This code is free software; you can redistribute it and/or modify it
twisti@2047 7 * under the terms of the GNU General Public License version 2 only, as
twisti@2047 8 * published by the Free Software Foundation.
twisti@2047 9 *
twisti@2047 10 * This code is distributed in the hope that it will be useful, but WITHOUT
twisti@2047 11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
twisti@2047 12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
twisti@2047 13 * version 2 for more details (a copy is included in the LICENSE file that
twisti@2047 14 * accompanied this code).
twisti@2047 15 *
twisti@2047 16 * You should have received a copy of the GNU General Public License version
twisti@2047 17 * 2 along with this work; if not, write to the Free Software Foundation,
twisti@2047 18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
twisti@2047 19 *
twisti@2047 20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
twisti@2047 21 * or visit www.oracle.com if you need additional information or have any
twisti@2047 22 * questions.
twisti@2047 23 *
twisti@2047 24 */
twisti@2047 25
twisti@2047 26 #include "incls/_precompiled.incl"
twisti@2047 27 #include "incls/_sharkValue.cpp.incl"
twisti@2047 28
twisti@2047 29 using namespace llvm;
twisti@2047 30
twisti@2047 31 // Cloning
twisti@2047 32
twisti@2047 33 SharkValue* SharkNormalValue::clone() const {
twisti@2047 34 return SharkValue::create_generic(type(), generic_value(), zero_checked());
twisti@2047 35 }
twisti@2047 36 SharkValue* SharkPHIValue::clone() const {
twisti@2047 37 return SharkValue::create_phi(type(), (PHINode *) generic_value(), this);
twisti@2047 38 }
twisti@2047 39 SharkValue* SharkAddressValue::clone() const {
twisti@2047 40 return SharkValue::address_constant(address_value());
twisti@2047 41 }
twisti@2047 42
twisti@2047 43 // Casting
twisti@2047 44
twisti@2047 45 bool SharkValue::is_phi() const {
twisti@2047 46 return false;
twisti@2047 47 }
twisti@2047 48 bool SharkPHIValue::is_phi() const {
twisti@2047 49 return true;
twisti@2047 50 }
twisti@2047 51 SharkPHIValue* SharkValue::as_phi() {
twisti@2047 52 ShouldNotCallThis();
twisti@2047 53 }
twisti@2047 54 SharkPHIValue* SharkPHIValue::as_phi() {
twisti@2047 55 return this;
twisti@2047 56 }
twisti@2047 57
twisti@2047 58 // Comparison
twisti@2047 59
twisti@2047 60 bool SharkNormalValue::equal_to(SharkValue *other) const {
twisti@2047 61 return (this->type() == other->type() &&
twisti@2047 62 this->generic_value() == other->generic_value() &&
twisti@2047 63 this->zero_checked() == other->zero_checked());
twisti@2047 64 }
twisti@2047 65 bool SharkAddressValue::equal_to(SharkValue *other) const {
twisti@2047 66 return (this->address_value() == other->address_value());
twisti@2047 67 }
twisti@2047 68
twisti@2047 69 // Type access
twisti@2047 70
twisti@2047 71 ciType* SharkValue::type() const {
twisti@2047 72 ShouldNotCallThis();
twisti@2047 73 }
twisti@2047 74 ciType* SharkNormalValue::type() const {
twisti@2047 75 return _type;
twisti@2047 76 }
twisti@2047 77
twisti@2047 78 BasicType SharkNormalValue::basic_type() const {
twisti@2047 79 return type()->basic_type();
twisti@2047 80 }
twisti@2047 81 BasicType SharkAddressValue::basic_type() const {
twisti@2047 82 return T_ADDRESS;
twisti@2047 83 }
twisti@2047 84
twisti@2047 85 int SharkNormalValue::size() const {
twisti@2047 86 return type()->size();
twisti@2047 87 }
twisti@2047 88 int SharkAddressValue::size() const {
twisti@2047 89 return 1;
twisti@2047 90 }
twisti@2047 91
twisti@2047 92 bool SharkValue::is_jint() const {
twisti@2047 93 return false;
twisti@2047 94 }
twisti@2047 95 bool SharkValue::is_jlong() const {
twisti@2047 96 return false;
twisti@2047 97 }
twisti@2047 98 bool SharkValue::is_jfloat() const {
twisti@2047 99 return false;
twisti@2047 100 }
twisti@2047 101 bool SharkValue::is_jdouble() const {
twisti@2047 102 return false;
twisti@2047 103 }
twisti@2047 104 bool SharkValue::is_jobject() const {
twisti@2047 105 return false;
twisti@2047 106 }
twisti@2047 107 bool SharkValue::is_jarray() const {
twisti@2047 108 return false;
twisti@2047 109 }
twisti@2047 110 bool SharkValue::is_address() const {
twisti@2047 111 return false;
twisti@2047 112 }
twisti@2047 113
twisti@2047 114 bool SharkNormalValue::is_jint() const {
twisti@2047 115 return llvm_value()->getType() == SharkType::jint_type();
twisti@2047 116 }
twisti@2047 117 bool SharkNormalValue::is_jlong() const {
twisti@2047 118 return llvm_value()->getType() == SharkType::jlong_type();
twisti@2047 119 }
twisti@2047 120 bool SharkNormalValue::is_jfloat() const {
twisti@2047 121 return llvm_value()->getType() == SharkType::jfloat_type();
twisti@2047 122 }
twisti@2047 123 bool SharkNormalValue::is_jdouble() const {
twisti@2047 124 return llvm_value()->getType() == SharkType::jdouble_type();
twisti@2047 125 }
twisti@2047 126 bool SharkNormalValue::is_jobject() const {
twisti@2047 127 return llvm_value()->getType() == SharkType::oop_type();
twisti@2047 128 }
twisti@2047 129 bool SharkNormalValue::is_jarray() const {
twisti@2047 130 return basic_type() == T_ARRAY;
twisti@2047 131 }
twisti@2047 132 bool SharkAddressValue::is_address() const {
twisti@2047 133 return true;
twisti@2047 134 }
twisti@2047 135
twisti@2047 136 // Typed conversions from SharkValues
twisti@2047 137
twisti@2047 138 Value* SharkValue::jint_value() const {
twisti@2047 139 ShouldNotCallThis();
twisti@2047 140 }
twisti@2047 141 Value* SharkValue::jlong_value() const {
twisti@2047 142 ShouldNotCallThis();
twisti@2047 143 }
twisti@2047 144 Value* SharkValue::jfloat_value() const {
twisti@2047 145 ShouldNotCallThis();
twisti@2047 146 }
twisti@2047 147 Value* SharkValue::jdouble_value() const {
twisti@2047 148 ShouldNotCallThis();
twisti@2047 149 }
twisti@2047 150 Value* SharkValue::jobject_value() const {
twisti@2047 151 ShouldNotCallThis();
twisti@2047 152 }
twisti@2047 153 Value* SharkValue::jarray_value() const {
twisti@2047 154 ShouldNotCallThis();
twisti@2047 155 }
twisti@2047 156 int SharkValue::address_value() const {
twisti@2047 157 ShouldNotCallThis();
twisti@2047 158 }
twisti@2047 159
twisti@2047 160 Value* SharkNormalValue::jint_value() const {
twisti@2047 161 assert(is_jint(), "should be");
twisti@2047 162 return llvm_value();
twisti@2047 163 }
twisti@2047 164 Value* SharkNormalValue::jlong_value() const {
twisti@2047 165 assert(is_jlong(), "should be");
twisti@2047 166 return llvm_value();
twisti@2047 167 }
twisti@2047 168 Value* SharkNormalValue::jfloat_value() const {
twisti@2047 169 assert(is_jfloat(), "should be");
twisti@2047 170 return llvm_value();
twisti@2047 171 }
twisti@2047 172 Value* SharkNormalValue::jdouble_value() const {
twisti@2047 173 assert(is_jdouble(), "should be");
twisti@2047 174 return llvm_value();
twisti@2047 175 }
twisti@2047 176 Value* SharkNormalValue::jobject_value() const {
twisti@2047 177 assert(is_jobject(), "should be");
twisti@2047 178 return llvm_value();
twisti@2047 179 }
twisti@2047 180 Value* SharkNormalValue::jarray_value() const {
twisti@2047 181 // XXX assert(is_jarray(), "should be");
twisti@2047 182 // XXX http://icedtea.classpath.org/bugzilla/show_bug.cgi?id=324
twisti@2047 183 assert(is_jobject(), "should be");
twisti@2047 184 return llvm_value();
twisti@2047 185 }
twisti@2047 186 int SharkAddressValue::address_value() const {
twisti@2047 187 return _bci;
twisti@2047 188 }
twisti@2047 189
twisti@2047 190 // Type-losing conversions -- use with care!
twisti@2047 191
twisti@2047 192 Value* SharkNormalValue::generic_value() const {
twisti@2047 193 return llvm_value();
twisti@2047 194 }
twisti@2047 195 Value* SharkAddressValue::generic_value() const {
twisti@2047 196 return LLVMValue::intptr_constant(address_value());
twisti@2047 197 }
twisti@2047 198
twisti@2047 199 Value* SharkValue::intptr_value(SharkBuilder* builder) const {
twisti@2047 200 ShouldNotCallThis();
twisti@2047 201 }
twisti@2047 202 Value* SharkNormalValue::intptr_value(SharkBuilder* builder) const {
twisti@2047 203 return builder->CreatePtrToInt(jobject_value(), SharkType::intptr_type());
twisti@2047 204 }
twisti@2047 205
twisti@2047 206 // Phi-style stuff for SharkPHIState::add_incoming
twisti@2047 207
twisti@2047 208 void SharkValue::addIncoming(SharkValue *value, BasicBlock* block) {
twisti@2047 209 ShouldNotCallThis();
twisti@2047 210 }
twisti@2047 211 void SharkPHIValue::addIncoming(SharkValue *value, BasicBlock* block) {
twisti@2047 212 assert(!is_clone(), "shouldn't be");
twisti@2047 213 ((llvm::PHINode *) generic_value())->addIncoming(
twisti@2047 214 value->generic_value(), block);
twisti@2047 215 if (!value->zero_checked())
twisti@2047 216 _all_incomers_zero_checked = false;
twisti@2047 217 }
twisti@2047 218 void SharkAddressValue::addIncoming(SharkValue *value, BasicBlock* block) {
twisti@2047 219 assert(this->equal_to(value), "should be");
twisti@2047 220 }
twisti@2047 221
twisti@2047 222 // Phi-style stuff for SharkState::merge
twisti@2047 223
twisti@2047 224 SharkValue* SharkNormalValue::merge(SharkBuilder* builder,
twisti@2047 225 SharkValue* other,
twisti@2047 226 BasicBlock* other_block,
twisti@2047 227 BasicBlock* this_block,
twisti@2047 228 const char* name) {
twisti@2047 229 assert(type() == other->type(), "should be");
twisti@2047 230 assert(zero_checked() == other->zero_checked(), "should be");
twisti@2047 231
twisti@2047 232 PHINode *phi = builder->CreatePHI(SharkType::to_stackType(type()), name);
twisti@2047 233 phi->addIncoming(this->generic_value(), this_block);
twisti@2047 234 phi->addIncoming(other->generic_value(), other_block);
twisti@2047 235 return SharkValue::create_generic(type(), phi, zero_checked());
twisti@2047 236 }
twisti@2047 237 SharkValue* SharkAddressValue::merge(SharkBuilder* builder,
twisti@2047 238 SharkValue* other,
twisti@2047 239 BasicBlock* other_block,
twisti@2047 240 BasicBlock* this_block,
twisti@2047 241 const char* name) {
twisti@2047 242 assert(this->equal_to(other), "should be");
twisti@2047 243 return this;
twisti@2047 244 }
twisti@2047 245
twisti@2047 246 // Repeated null and divide-by-zero check removal
twisti@2047 247
twisti@2047 248 bool SharkValue::zero_checked() const {
twisti@2047 249 ShouldNotCallThis();
twisti@2047 250 }
twisti@2047 251 void SharkValue::set_zero_checked(bool zero_checked) {
twisti@2047 252 ShouldNotCallThis();
twisti@2047 253 }
twisti@2047 254
twisti@2047 255 bool SharkNormalValue::zero_checked() const {
twisti@2047 256 return _zero_checked;
twisti@2047 257 }
twisti@2047 258 void SharkNormalValue::set_zero_checked(bool zero_checked) {
twisti@2047 259 _zero_checked = zero_checked;
twisti@2047 260 }

mercurial