src/share/vm/shark/sharkValue.cpp

Wed, 27 Apr 2016 01:25:04 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:25:04 +0800
changeset 0
f90c822e73f8
child 6876
710a3c8b516e
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/hotspot/
changeset: 6782:28b50d07f6f8
tag: jdk8u25-b17

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

mercurial