1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/shark/sharkValue.cpp Wed Aug 11 05:51:21 2010 -0700 1.3 @@ -0,0 +1,260 @@ 1.4 +/* 1.5 + * Copyright (c) 1999, 2007, Oracle and/or its affiliates. All rights reserved. 1.6 + * Copyright 2008, 2009 Red Hat, Inc. 1.7 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.8 + * 1.9 + * This code is free software; you can redistribute it and/or modify it 1.10 + * under the terms of the GNU General Public License version 2 only, as 1.11 + * published by the Free Software Foundation. 1.12 + * 1.13 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.14 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.15 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.16 + * version 2 for more details (a copy is included in the LICENSE file that 1.17 + * accompanied this code). 1.18 + * 1.19 + * You should have received a copy of the GNU General Public License version 1.20 + * 2 along with this work; if not, write to the Free Software Foundation, 1.21 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.22 + * 1.23 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.24 + * or visit www.oracle.com if you need additional information or have any 1.25 + * questions. 1.26 + * 1.27 + */ 1.28 + 1.29 +#include "incls/_precompiled.incl" 1.30 +#include "incls/_sharkValue.cpp.incl" 1.31 + 1.32 +using namespace llvm; 1.33 + 1.34 +// Cloning 1.35 + 1.36 +SharkValue* SharkNormalValue::clone() const { 1.37 + return SharkValue::create_generic(type(), generic_value(), zero_checked()); 1.38 +} 1.39 +SharkValue* SharkPHIValue::clone() const { 1.40 + return SharkValue::create_phi(type(), (PHINode *) generic_value(), this); 1.41 +} 1.42 +SharkValue* SharkAddressValue::clone() const { 1.43 + return SharkValue::address_constant(address_value()); 1.44 +} 1.45 + 1.46 +// Casting 1.47 + 1.48 +bool SharkValue::is_phi() const { 1.49 + return false; 1.50 +} 1.51 +bool SharkPHIValue::is_phi() const { 1.52 + return true; 1.53 +} 1.54 +SharkPHIValue* SharkValue::as_phi() { 1.55 + ShouldNotCallThis(); 1.56 +} 1.57 +SharkPHIValue* SharkPHIValue::as_phi() { 1.58 + return this; 1.59 +} 1.60 + 1.61 +// Comparison 1.62 + 1.63 +bool SharkNormalValue::equal_to(SharkValue *other) const { 1.64 + return (this->type() == other->type() && 1.65 + this->generic_value() == other->generic_value() && 1.66 + this->zero_checked() == other->zero_checked()); 1.67 +} 1.68 +bool SharkAddressValue::equal_to(SharkValue *other) const { 1.69 + return (this->address_value() == other->address_value()); 1.70 +} 1.71 + 1.72 +// Type access 1.73 + 1.74 +ciType* SharkValue::type() const { 1.75 + ShouldNotCallThis(); 1.76 +} 1.77 +ciType* SharkNormalValue::type() const { 1.78 + return _type; 1.79 +} 1.80 + 1.81 +BasicType SharkNormalValue::basic_type() const { 1.82 + return type()->basic_type(); 1.83 +} 1.84 +BasicType SharkAddressValue::basic_type() const { 1.85 + return T_ADDRESS; 1.86 +} 1.87 + 1.88 +int SharkNormalValue::size() const { 1.89 + return type()->size(); 1.90 +} 1.91 +int SharkAddressValue::size() const { 1.92 + return 1; 1.93 +} 1.94 + 1.95 +bool SharkValue::is_jint() const { 1.96 + return false; 1.97 +} 1.98 +bool SharkValue::is_jlong() const { 1.99 + return false; 1.100 +} 1.101 +bool SharkValue::is_jfloat() const { 1.102 + return false; 1.103 +} 1.104 +bool SharkValue::is_jdouble() const { 1.105 + return false; 1.106 +} 1.107 +bool SharkValue::is_jobject() const { 1.108 + return false; 1.109 +} 1.110 +bool SharkValue::is_jarray() const { 1.111 + return false; 1.112 +} 1.113 +bool SharkValue::is_address() const { 1.114 + return false; 1.115 +} 1.116 + 1.117 +bool SharkNormalValue::is_jint() const { 1.118 + return llvm_value()->getType() == SharkType::jint_type(); 1.119 +} 1.120 +bool SharkNormalValue::is_jlong() const { 1.121 + return llvm_value()->getType() == SharkType::jlong_type(); 1.122 +} 1.123 +bool SharkNormalValue::is_jfloat() const { 1.124 + return llvm_value()->getType() == SharkType::jfloat_type(); 1.125 +} 1.126 +bool SharkNormalValue::is_jdouble() const { 1.127 + return llvm_value()->getType() == SharkType::jdouble_type(); 1.128 +} 1.129 +bool SharkNormalValue::is_jobject() const { 1.130 + return llvm_value()->getType() == SharkType::oop_type(); 1.131 +} 1.132 +bool SharkNormalValue::is_jarray() const { 1.133 + return basic_type() == T_ARRAY; 1.134 +} 1.135 +bool SharkAddressValue::is_address() const { 1.136 + return true; 1.137 +} 1.138 + 1.139 +// Typed conversions from SharkValues 1.140 + 1.141 +Value* SharkValue::jint_value() const { 1.142 + ShouldNotCallThis(); 1.143 +} 1.144 +Value* SharkValue::jlong_value() const { 1.145 + ShouldNotCallThis(); 1.146 +} 1.147 +Value* SharkValue::jfloat_value() const { 1.148 + ShouldNotCallThis(); 1.149 +} 1.150 +Value* SharkValue::jdouble_value() const { 1.151 + ShouldNotCallThis(); 1.152 +} 1.153 +Value* SharkValue::jobject_value() const { 1.154 + ShouldNotCallThis(); 1.155 +} 1.156 +Value* SharkValue::jarray_value() const { 1.157 + ShouldNotCallThis(); 1.158 +} 1.159 +int SharkValue::address_value() const { 1.160 + ShouldNotCallThis(); 1.161 +} 1.162 + 1.163 +Value* SharkNormalValue::jint_value() const { 1.164 + assert(is_jint(), "should be"); 1.165 + return llvm_value(); 1.166 +} 1.167 +Value* SharkNormalValue::jlong_value() const { 1.168 + assert(is_jlong(), "should be"); 1.169 + return llvm_value(); 1.170 +} 1.171 +Value* SharkNormalValue::jfloat_value() const { 1.172 + assert(is_jfloat(), "should be"); 1.173 + return llvm_value(); 1.174 +} 1.175 +Value* SharkNormalValue::jdouble_value() const { 1.176 + assert(is_jdouble(), "should be"); 1.177 + return llvm_value(); 1.178 +} 1.179 +Value* SharkNormalValue::jobject_value() const { 1.180 + assert(is_jobject(), "should be"); 1.181 + return llvm_value(); 1.182 +} 1.183 +Value* SharkNormalValue::jarray_value() const { 1.184 + // XXX assert(is_jarray(), "should be"); 1.185 + // XXX http://icedtea.classpath.org/bugzilla/show_bug.cgi?id=324 1.186 + assert(is_jobject(), "should be"); 1.187 + return llvm_value(); 1.188 +} 1.189 +int SharkAddressValue::address_value() const { 1.190 + return _bci; 1.191 +} 1.192 + 1.193 +// Type-losing conversions -- use with care! 1.194 + 1.195 +Value* SharkNormalValue::generic_value() const { 1.196 + return llvm_value(); 1.197 +} 1.198 +Value* SharkAddressValue::generic_value() const { 1.199 + return LLVMValue::intptr_constant(address_value()); 1.200 +} 1.201 + 1.202 +Value* SharkValue::intptr_value(SharkBuilder* builder) const { 1.203 + ShouldNotCallThis(); 1.204 +} 1.205 +Value* SharkNormalValue::intptr_value(SharkBuilder* builder) const { 1.206 + return builder->CreatePtrToInt(jobject_value(), SharkType::intptr_type()); 1.207 +} 1.208 + 1.209 +// Phi-style stuff for SharkPHIState::add_incoming 1.210 + 1.211 +void SharkValue::addIncoming(SharkValue *value, BasicBlock* block) { 1.212 + ShouldNotCallThis(); 1.213 +} 1.214 +void SharkPHIValue::addIncoming(SharkValue *value, BasicBlock* block) { 1.215 + assert(!is_clone(), "shouldn't be"); 1.216 + ((llvm::PHINode *) generic_value())->addIncoming( 1.217 + value->generic_value(), block); 1.218 + if (!value->zero_checked()) 1.219 + _all_incomers_zero_checked = false; 1.220 +} 1.221 +void SharkAddressValue::addIncoming(SharkValue *value, BasicBlock* block) { 1.222 + assert(this->equal_to(value), "should be"); 1.223 +} 1.224 + 1.225 +// Phi-style stuff for SharkState::merge 1.226 + 1.227 +SharkValue* SharkNormalValue::merge(SharkBuilder* builder, 1.228 + SharkValue* other, 1.229 + BasicBlock* other_block, 1.230 + BasicBlock* this_block, 1.231 + const char* name) { 1.232 + assert(type() == other->type(), "should be"); 1.233 + assert(zero_checked() == other->zero_checked(), "should be"); 1.234 + 1.235 + PHINode *phi = builder->CreatePHI(SharkType::to_stackType(type()), name); 1.236 + phi->addIncoming(this->generic_value(), this_block); 1.237 + phi->addIncoming(other->generic_value(), other_block); 1.238 + return SharkValue::create_generic(type(), phi, zero_checked()); 1.239 +} 1.240 +SharkValue* SharkAddressValue::merge(SharkBuilder* builder, 1.241 + SharkValue* other, 1.242 + BasicBlock* other_block, 1.243 + BasicBlock* this_block, 1.244 + const char* name) { 1.245 + assert(this->equal_to(other), "should be"); 1.246 + return this; 1.247 +} 1.248 + 1.249 +// Repeated null and divide-by-zero check removal 1.250 + 1.251 +bool SharkValue::zero_checked() const { 1.252 + ShouldNotCallThis(); 1.253 +} 1.254 +void SharkValue::set_zero_checked(bool zero_checked) { 1.255 + ShouldNotCallThis(); 1.256 +} 1.257 + 1.258 +bool SharkNormalValue::zero_checked() const { 1.259 + return _zero_checked; 1.260 +} 1.261 +void SharkNormalValue::set_zero_checked(bool zero_checked) { 1.262 + _zero_checked = zero_checked; 1.263 +}