Tue, 27 Nov 2012 12:48:52 -0800
8003868: fix shark for latest HotSpot and LLVM
Reviewed-by: twisti
Contributed-by: Roman Kennke <rkennke@redhat.com>
twisti@2047 | 1 | /* |
stefank@2314 | 2 | * Copyright (c) 1999, 2010, 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 | |
stefank@2314 | 26 | #include "precompiled.hpp" |
stefank@2314 | 27 | #include "ci/ciType.hpp" |
stefank@2314 | 28 | #include "shark/llvmHeaders.hpp" |
stefank@2314 | 29 | #include "shark/llvmValue.hpp" |
stefank@2314 | 30 | #include "shark/sharkBuilder.hpp" |
stefank@2314 | 31 | #include "shark/sharkValue.hpp" |
twisti@2047 | 32 | |
twisti@2047 | 33 | using namespace llvm; |
twisti@2047 | 34 | |
twisti@2047 | 35 | // Cloning |
twisti@2047 | 36 | |
twisti@2047 | 37 | SharkValue* SharkNormalValue::clone() const { |
twisti@2047 | 38 | return SharkValue::create_generic(type(), generic_value(), zero_checked()); |
twisti@2047 | 39 | } |
twisti@2047 | 40 | SharkValue* SharkPHIValue::clone() const { |
twisti@2047 | 41 | return SharkValue::create_phi(type(), (PHINode *) generic_value(), this); |
twisti@2047 | 42 | } |
twisti@2047 | 43 | SharkValue* SharkAddressValue::clone() const { |
twisti@2047 | 44 | return SharkValue::address_constant(address_value()); |
twisti@2047 | 45 | } |
twisti@2047 | 46 | |
twisti@2047 | 47 | // Casting |
twisti@2047 | 48 | |
twisti@2047 | 49 | bool SharkValue::is_phi() const { |
twisti@2047 | 50 | return false; |
twisti@2047 | 51 | } |
twisti@2047 | 52 | bool SharkPHIValue::is_phi() const { |
twisti@2047 | 53 | return true; |
twisti@2047 | 54 | } |
twisti@2047 | 55 | SharkPHIValue* SharkValue::as_phi() { |
twisti@2047 | 56 | ShouldNotCallThis(); |
twisti@2047 | 57 | } |
twisti@2047 | 58 | SharkPHIValue* SharkPHIValue::as_phi() { |
twisti@2047 | 59 | return this; |
twisti@2047 | 60 | } |
twisti@2047 | 61 | |
twisti@2047 | 62 | // Comparison |
twisti@2047 | 63 | |
twisti@2047 | 64 | bool SharkNormalValue::equal_to(SharkValue *other) const { |
twisti@2047 | 65 | return (this->type() == other->type() && |
twisti@2047 | 66 | this->generic_value() == other->generic_value() && |
twisti@2047 | 67 | this->zero_checked() == other->zero_checked()); |
twisti@2047 | 68 | } |
twisti@2047 | 69 | bool SharkAddressValue::equal_to(SharkValue *other) const { |
twisti@2047 | 70 | return (this->address_value() == other->address_value()); |
twisti@2047 | 71 | } |
twisti@2047 | 72 | |
twisti@2047 | 73 | // Type access |
twisti@2047 | 74 | |
twisti@2047 | 75 | ciType* SharkValue::type() const { |
twisti@2047 | 76 | ShouldNotCallThis(); |
twisti@2047 | 77 | } |
twisti@2047 | 78 | ciType* SharkNormalValue::type() const { |
twisti@2047 | 79 | return _type; |
twisti@2047 | 80 | } |
twisti@2047 | 81 | |
twisti@2047 | 82 | BasicType SharkNormalValue::basic_type() const { |
twisti@2047 | 83 | return type()->basic_type(); |
twisti@2047 | 84 | } |
twisti@2047 | 85 | BasicType SharkAddressValue::basic_type() const { |
twisti@2047 | 86 | return T_ADDRESS; |
twisti@2047 | 87 | } |
twisti@2047 | 88 | |
twisti@2047 | 89 | int SharkNormalValue::size() const { |
twisti@2047 | 90 | return type()->size(); |
twisti@2047 | 91 | } |
twisti@2047 | 92 | int SharkAddressValue::size() const { |
twisti@2047 | 93 | return 1; |
twisti@2047 | 94 | } |
twisti@2047 | 95 | |
twisti@2047 | 96 | bool SharkValue::is_jint() const { |
twisti@2047 | 97 | return false; |
twisti@2047 | 98 | } |
twisti@2047 | 99 | bool SharkValue::is_jlong() const { |
twisti@2047 | 100 | return false; |
twisti@2047 | 101 | } |
twisti@2047 | 102 | bool SharkValue::is_jfloat() const { |
twisti@2047 | 103 | return false; |
twisti@2047 | 104 | } |
twisti@2047 | 105 | bool SharkValue::is_jdouble() const { |
twisti@2047 | 106 | return false; |
twisti@2047 | 107 | } |
twisti@2047 | 108 | bool SharkValue::is_jobject() const { |
twisti@2047 | 109 | return false; |
twisti@2047 | 110 | } |
twisti@2047 | 111 | bool SharkValue::is_jarray() const { |
twisti@2047 | 112 | return false; |
twisti@2047 | 113 | } |
twisti@2047 | 114 | bool SharkValue::is_address() const { |
twisti@2047 | 115 | return false; |
twisti@2047 | 116 | } |
twisti@2047 | 117 | |
twisti@2047 | 118 | bool SharkNormalValue::is_jint() const { |
twisti@2047 | 119 | return llvm_value()->getType() == SharkType::jint_type(); |
twisti@2047 | 120 | } |
twisti@2047 | 121 | bool SharkNormalValue::is_jlong() const { |
twisti@2047 | 122 | return llvm_value()->getType() == SharkType::jlong_type(); |
twisti@2047 | 123 | } |
twisti@2047 | 124 | bool SharkNormalValue::is_jfloat() const { |
twisti@2047 | 125 | return llvm_value()->getType() == SharkType::jfloat_type(); |
twisti@2047 | 126 | } |
twisti@2047 | 127 | bool SharkNormalValue::is_jdouble() const { |
twisti@2047 | 128 | return llvm_value()->getType() == SharkType::jdouble_type(); |
twisti@2047 | 129 | } |
twisti@2047 | 130 | bool SharkNormalValue::is_jobject() const { |
twisti@2047 | 131 | return llvm_value()->getType() == SharkType::oop_type(); |
twisti@2047 | 132 | } |
twisti@2047 | 133 | bool SharkNormalValue::is_jarray() const { |
twisti@2047 | 134 | return basic_type() == T_ARRAY; |
twisti@2047 | 135 | } |
twisti@2047 | 136 | bool SharkAddressValue::is_address() const { |
twisti@2047 | 137 | return true; |
twisti@2047 | 138 | } |
twisti@2047 | 139 | |
twisti@2047 | 140 | // Typed conversions from SharkValues |
twisti@2047 | 141 | |
twisti@2047 | 142 | Value* SharkValue::jint_value() const { |
twisti@2047 | 143 | ShouldNotCallThis(); |
twisti@2047 | 144 | } |
twisti@2047 | 145 | Value* SharkValue::jlong_value() const { |
twisti@2047 | 146 | ShouldNotCallThis(); |
twisti@2047 | 147 | } |
twisti@2047 | 148 | Value* SharkValue::jfloat_value() const { |
twisti@2047 | 149 | ShouldNotCallThis(); |
twisti@2047 | 150 | } |
twisti@2047 | 151 | Value* SharkValue::jdouble_value() const { |
twisti@2047 | 152 | ShouldNotCallThis(); |
twisti@2047 | 153 | } |
twisti@2047 | 154 | Value* SharkValue::jobject_value() const { |
twisti@2047 | 155 | ShouldNotCallThis(); |
twisti@2047 | 156 | } |
twisti@2047 | 157 | Value* SharkValue::jarray_value() const { |
twisti@2047 | 158 | ShouldNotCallThis(); |
twisti@2047 | 159 | } |
twisti@2047 | 160 | int SharkValue::address_value() const { |
twisti@2047 | 161 | ShouldNotCallThis(); |
twisti@2047 | 162 | } |
twisti@2047 | 163 | |
twisti@2047 | 164 | Value* SharkNormalValue::jint_value() const { |
twisti@2047 | 165 | assert(is_jint(), "should be"); |
twisti@2047 | 166 | return llvm_value(); |
twisti@2047 | 167 | } |
twisti@2047 | 168 | Value* SharkNormalValue::jlong_value() const { |
twisti@2047 | 169 | assert(is_jlong(), "should be"); |
twisti@2047 | 170 | return llvm_value(); |
twisti@2047 | 171 | } |
twisti@2047 | 172 | Value* SharkNormalValue::jfloat_value() const { |
twisti@2047 | 173 | assert(is_jfloat(), "should be"); |
twisti@2047 | 174 | return llvm_value(); |
twisti@2047 | 175 | } |
twisti@2047 | 176 | Value* SharkNormalValue::jdouble_value() const { |
twisti@2047 | 177 | assert(is_jdouble(), "should be"); |
twisti@2047 | 178 | return llvm_value(); |
twisti@2047 | 179 | } |
twisti@2047 | 180 | Value* SharkNormalValue::jobject_value() const { |
twisti@2047 | 181 | assert(is_jobject(), "should be"); |
twisti@2047 | 182 | return llvm_value(); |
twisti@2047 | 183 | } |
twisti@2047 | 184 | Value* SharkNormalValue::jarray_value() const { |
twisti@2047 | 185 | // XXX assert(is_jarray(), "should be"); |
twisti@2047 | 186 | // XXX http://icedtea.classpath.org/bugzilla/show_bug.cgi?id=324 |
twisti@2047 | 187 | assert(is_jobject(), "should be"); |
twisti@2047 | 188 | return llvm_value(); |
twisti@2047 | 189 | } |
twisti@2047 | 190 | int SharkAddressValue::address_value() const { |
twisti@2047 | 191 | return _bci; |
twisti@2047 | 192 | } |
twisti@2047 | 193 | |
twisti@2047 | 194 | // Type-losing conversions -- use with care! |
twisti@2047 | 195 | |
twisti@2047 | 196 | Value* SharkNormalValue::generic_value() const { |
twisti@2047 | 197 | return llvm_value(); |
twisti@2047 | 198 | } |
twisti@2047 | 199 | Value* SharkAddressValue::generic_value() const { |
twisti@2047 | 200 | return LLVMValue::intptr_constant(address_value()); |
twisti@2047 | 201 | } |
twisti@2047 | 202 | |
twisti@2047 | 203 | Value* SharkValue::intptr_value(SharkBuilder* builder) const { |
twisti@2047 | 204 | ShouldNotCallThis(); |
twisti@2047 | 205 | } |
twisti@2047 | 206 | Value* SharkNormalValue::intptr_value(SharkBuilder* builder) const { |
twisti@2047 | 207 | return builder->CreatePtrToInt(jobject_value(), SharkType::intptr_type()); |
twisti@2047 | 208 | } |
twisti@2047 | 209 | |
twisti@2047 | 210 | // Phi-style stuff for SharkPHIState::add_incoming |
twisti@2047 | 211 | |
twisti@2047 | 212 | void SharkValue::addIncoming(SharkValue *value, BasicBlock* block) { |
twisti@2047 | 213 | ShouldNotCallThis(); |
twisti@2047 | 214 | } |
twisti@2047 | 215 | void SharkPHIValue::addIncoming(SharkValue *value, BasicBlock* block) { |
twisti@2047 | 216 | assert(!is_clone(), "shouldn't be"); |
twisti@2047 | 217 | ((llvm::PHINode *) generic_value())->addIncoming( |
twisti@2047 | 218 | value->generic_value(), block); |
twisti@2047 | 219 | if (!value->zero_checked()) |
twisti@2047 | 220 | _all_incomers_zero_checked = false; |
twisti@2047 | 221 | } |
twisti@2047 | 222 | void SharkAddressValue::addIncoming(SharkValue *value, BasicBlock* block) { |
twisti@2047 | 223 | assert(this->equal_to(value), "should be"); |
twisti@2047 | 224 | } |
twisti@2047 | 225 | |
twisti@2047 | 226 | // Phi-style stuff for SharkState::merge |
twisti@2047 | 227 | |
twisti@2047 | 228 | SharkValue* SharkNormalValue::merge(SharkBuilder* builder, |
twisti@2047 | 229 | SharkValue* other, |
twisti@2047 | 230 | BasicBlock* other_block, |
twisti@2047 | 231 | BasicBlock* this_block, |
twisti@2047 | 232 | const char* name) { |
twisti@2047 | 233 | assert(type() == other->type(), "should be"); |
twisti@2047 | 234 | assert(zero_checked() == other->zero_checked(), "should be"); |
twisti@2047 | 235 | |
twisti@4314 | 236 | PHINode *phi = builder->CreatePHI(SharkType::to_stackType(type()), 0, name); |
twisti@2047 | 237 | phi->addIncoming(this->generic_value(), this_block); |
twisti@2047 | 238 | phi->addIncoming(other->generic_value(), other_block); |
twisti@2047 | 239 | return SharkValue::create_generic(type(), phi, zero_checked()); |
twisti@2047 | 240 | } |
twisti@2047 | 241 | SharkValue* SharkAddressValue::merge(SharkBuilder* builder, |
twisti@2047 | 242 | SharkValue* other, |
twisti@2047 | 243 | BasicBlock* other_block, |
twisti@2047 | 244 | BasicBlock* this_block, |
twisti@2047 | 245 | const char* name) { |
twisti@2047 | 246 | assert(this->equal_to(other), "should be"); |
twisti@2047 | 247 | return this; |
twisti@2047 | 248 | } |
twisti@2047 | 249 | |
twisti@2047 | 250 | // Repeated null and divide-by-zero check removal |
twisti@2047 | 251 | |
twisti@2047 | 252 | bool SharkValue::zero_checked() const { |
twisti@2047 | 253 | ShouldNotCallThis(); |
twisti@2047 | 254 | } |
twisti@2047 | 255 | void SharkValue::set_zero_checked(bool zero_checked) { |
twisti@2047 | 256 | ShouldNotCallThis(); |
twisti@2047 | 257 | } |
twisti@2047 | 258 | |
twisti@2047 | 259 | bool SharkNormalValue::zero_checked() const { |
twisti@2047 | 260 | return _zero_checked; |
twisti@2047 | 261 | } |
twisti@2047 | 262 | void SharkNormalValue::set_zero_checked(bool zero_checked) { |
twisti@2047 | 263 | _zero_checked = zero_checked; |
twisti@2047 | 264 | } |