src/share/vm/shark/sharkBuilder.cpp

Mon, 04 Apr 2011 03:02:00 -0700

author
twisti
date
Mon, 04 Apr 2011 03:02:00 -0700
changeset 2729
e863062e521d
parent 2314
f95d63e2154a
child 4037
da91efe96a93
permissions
-rw-r--r--

7032458: Zero and Shark fixes
Reviewed-by: twisti
Contributed-by: Gary Benson <gbenson@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, 2010 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/ciMethod.hpp"
stefank@2314 28 #include "memory/resourceArea.hpp"
stefank@2314 29 #include "oops/methodOop.hpp"
stefank@2314 30 #include "runtime/os.hpp"
stefank@2314 31 #include "runtime/synchronizer.hpp"
stefank@2314 32 #include "runtime/thread.hpp"
stefank@2314 33 #include "shark/llvmHeaders.hpp"
stefank@2314 34 #include "shark/llvmValue.hpp"
stefank@2314 35 #include "shark/sharkBuilder.hpp"
stefank@2314 36 #include "shark/sharkContext.hpp"
stefank@2314 37 #include "shark/sharkRuntime.hpp"
stefank@2314 38 #include "utilities/debug.hpp"
twisti@2047 39
twisti@2047 40 using namespace llvm;
twisti@2047 41
twisti@2047 42 SharkBuilder::SharkBuilder(SharkCodeBuffer* code_buffer)
twisti@2047 43 : IRBuilder<>(SharkContext::current()),
twisti@2047 44 _code_buffer(code_buffer) {
twisti@2047 45 }
twisti@2047 46
twisti@2047 47 // Helpers for accessing structures
twisti@2047 48 Value* SharkBuilder::CreateAddressOfStructEntry(Value* base,
twisti@2047 49 ByteSize offset,
twisti@2047 50 const Type* type,
twisti@2047 51 const char* name) {
twisti@2047 52 return CreateBitCast(CreateStructGEP(base, in_bytes(offset)), type, name);
twisti@2047 53 }
twisti@2047 54
twisti@2047 55 LoadInst* SharkBuilder::CreateValueOfStructEntry(Value* base,
twisti@2047 56 ByteSize offset,
twisti@2047 57 const Type* type,
twisti@2047 58 const char* name) {
twisti@2047 59 return CreateLoad(
twisti@2047 60 CreateAddressOfStructEntry(
twisti@2047 61 base, offset, PointerType::getUnqual(type)),
twisti@2047 62 name);
twisti@2047 63 }
twisti@2047 64
twisti@2047 65 // Helpers for accessing arrays
twisti@2047 66
twisti@2047 67 LoadInst* SharkBuilder::CreateArrayLength(Value* arrayoop) {
twisti@2047 68 return CreateValueOfStructEntry(
twisti@2047 69 arrayoop, in_ByteSize(arrayOopDesc::length_offset_in_bytes()),
twisti@2047 70 SharkType::jint_type(), "length");
twisti@2047 71 }
twisti@2047 72
twisti@2047 73 Value* SharkBuilder::CreateArrayAddress(Value* arrayoop,
twisti@2047 74 const Type* element_type,
twisti@2047 75 int element_bytes,
twisti@2047 76 ByteSize base_offset,
twisti@2047 77 Value* index,
twisti@2047 78 const char* name) {
twisti@2047 79 Value* offset = CreateIntCast(index, SharkType::intptr_type(), false);
twisti@2047 80 if (element_bytes != 1)
twisti@2047 81 offset = CreateShl(
twisti@2047 82 offset,
twisti@2047 83 LLVMValue::intptr_constant(exact_log2(element_bytes)));
twisti@2047 84 offset = CreateAdd(
twisti@2047 85 LLVMValue::intptr_constant(in_bytes(base_offset)), offset);
twisti@2047 86
twisti@2047 87 return CreateIntToPtr(
twisti@2047 88 CreateAdd(CreatePtrToInt(arrayoop, SharkType::intptr_type()), offset),
twisti@2047 89 PointerType::getUnqual(element_type),
twisti@2047 90 name);
twisti@2047 91 }
twisti@2047 92
twisti@2047 93 Value* SharkBuilder::CreateArrayAddress(Value* arrayoop,
twisti@2047 94 BasicType basic_type,
twisti@2047 95 ByteSize base_offset,
twisti@2047 96 Value* index,
twisti@2047 97 const char* name) {
twisti@2047 98 return CreateArrayAddress(
twisti@2047 99 arrayoop,
twisti@2047 100 SharkType::to_arrayType(basic_type),
twisti@2047 101 type2aelembytes(basic_type),
twisti@2047 102 base_offset, index, name);
twisti@2047 103 }
twisti@2047 104
twisti@2047 105 Value* SharkBuilder::CreateArrayAddress(Value* arrayoop,
twisti@2047 106 BasicType basic_type,
twisti@2047 107 Value* index,
twisti@2047 108 const char* name) {
twisti@2047 109 return CreateArrayAddress(
twisti@2047 110 arrayoop, basic_type,
twisti@2047 111 in_ByteSize(arrayOopDesc::base_offset_in_bytes(basic_type)),
twisti@2047 112 index, name);
twisti@2047 113 }
twisti@2047 114
twisti@2047 115 // Helpers for creating intrinsics and external functions.
twisti@2047 116
twisti@2047 117 const Type* SharkBuilder::make_type(char type, bool void_ok) {
twisti@2047 118 switch (type) {
twisti@2047 119 // Primitive types
twisti@2047 120 case 'c':
twisti@2047 121 return SharkType::jbyte_type();
twisti@2047 122 case 'i':
twisti@2047 123 return SharkType::jint_type();
twisti@2047 124 case 'l':
twisti@2047 125 return SharkType::jlong_type();
twisti@2047 126 case 'x':
twisti@2047 127 return SharkType::intptr_type();
twisti@2047 128 case 'f':
twisti@2047 129 return SharkType::jfloat_type();
twisti@2047 130 case 'd':
twisti@2047 131 return SharkType::jdouble_type();
twisti@2047 132
twisti@2047 133 // Pointers to primitive types
twisti@2047 134 case 'C':
twisti@2047 135 case 'I':
twisti@2047 136 case 'L':
twisti@2047 137 case 'X':
twisti@2047 138 case 'F':
twisti@2047 139 case 'D':
twisti@2047 140 return PointerType::getUnqual(make_type(tolower(type), false));
twisti@2047 141
twisti@2047 142 // VM objects
twisti@2047 143 case 'T':
twisti@2047 144 return SharkType::thread_type();
twisti@2047 145 case 'M':
twisti@2047 146 return PointerType::getUnqual(SharkType::monitor_type());
twisti@2047 147 case 'O':
twisti@2047 148 return SharkType::oop_type();
twisti@2047 149
twisti@2047 150 // Miscellaneous
twisti@2047 151 case 'v':
twisti@2047 152 assert(void_ok, "should be");
twisti@2047 153 return SharkType::void_type();
twisti@2047 154 case '1':
twisti@2047 155 return SharkType::bit_type();
twisti@2047 156
twisti@2047 157 default:
twisti@2047 158 ShouldNotReachHere();
twisti@2047 159 }
twisti@2047 160 }
twisti@2047 161
twisti@2047 162 const FunctionType* SharkBuilder::make_ftype(const char* params,
twisti@2047 163 const char* ret) {
twisti@2047 164 std::vector<const Type*> param_types;
twisti@2047 165 for (const char* c = params; *c; c++)
twisti@2047 166 param_types.push_back(make_type(*c, false));
twisti@2047 167
twisti@2047 168 assert(strlen(ret) == 1, "should be");
twisti@2047 169 const Type *return_type = make_type(*ret, true);
twisti@2047 170
twisti@2047 171 return FunctionType::get(return_type, param_types, false);
twisti@2047 172 }
twisti@2047 173
twisti@2047 174 // Create an object representing an intrinsic or external function by
twisti@2047 175 // referencing the symbol by name. This is the LLVM-style approach,
twisti@2047 176 // but it cannot be used on functions within libjvm.so its symbols
twisti@2047 177 // are not exported. Note that you cannot make this work simply by
twisti@2047 178 // exporting the symbols, as some symbols have the same names as
twisti@2047 179 // symbols in the standard libraries (eg, atan2, fabs) and would
twisti@2047 180 // obscure them were they visible.
twisti@2047 181 Value* SharkBuilder::make_function(const char* name,
twisti@2047 182 const char* params,
twisti@2047 183 const char* ret) {
twisti@2047 184 return SharkContext::current().get_external(name, make_ftype(params, ret));
twisti@2047 185 }
twisti@2047 186
twisti@2047 187 // Create an object representing an external function by inlining a
twisti@2047 188 // function pointer in the code. This is not the LLVM way, but it's
twisti@2047 189 // the only way to access functions in libjvm.so and functions like
twisti@2047 190 // __kernel_dmb on ARM which is accessed via an absolute address.
twisti@2047 191 Value* SharkBuilder::make_function(address func,
twisti@2047 192 const char* params,
twisti@2047 193 const char* ret) {
twisti@2047 194 return CreateIntToPtr(
twisti@2047 195 LLVMValue::intptr_constant((intptr_t) func),
twisti@2047 196 PointerType::getUnqual(make_ftype(params, ret)));
twisti@2047 197 }
twisti@2047 198
twisti@2047 199 // VM calls
twisti@2047 200
twisti@2047 201 Value* SharkBuilder::find_exception_handler() {
twisti@2047 202 return make_function(
twisti@2047 203 (address) SharkRuntime::find_exception_handler, "TIi", "i");
twisti@2047 204 }
twisti@2047 205
twisti@2047 206 Value* SharkBuilder::monitorenter() {
twisti@2047 207 return make_function((address) SharkRuntime::monitorenter, "TM", "v");
twisti@2047 208 }
twisti@2047 209
twisti@2047 210 Value* SharkBuilder::monitorexit() {
twisti@2047 211 return make_function((address) SharkRuntime::monitorexit, "TM", "v");
twisti@2047 212 }
twisti@2047 213
twisti@2047 214 Value* SharkBuilder::new_instance() {
twisti@2047 215 return make_function((address) SharkRuntime::new_instance, "Ti", "v");
twisti@2047 216 }
twisti@2047 217
twisti@2047 218 Value* SharkBuilder::newarray() {
twisti@2047 219 return make_function((address) SharkRuntime::newarray, "Tii", "v");
twisti@2047 220 }
twisti@2047 221
twisti@2047 222 Value* SharkBuilder::anewarray() {
twisti@2047 223 return make_function((address) SharkRuntime::anewarray, "Tii", "v");
twisti@2047 224 }
twisti@2047 225
twisti@2047 226 Value* SharkBuilder::multianewarray() {
twisti@2047 227 return make_function((address) SharkRuntime::multianewarray, "TiiI", "v");
twisti@2047 228 }
twisti@2047 229
twisti@2047 230 Value* SharkBuilder::register_finalizer() {
twisti@2047 231 return make_function((address) SharkRuntime::register_finalizer, "TO", "v");
twisti@2047 232 }
twisti@2047 233
twisti@2047 234 Value* SharkBuilder::safepoint() {
twisti@2047 235 return make_function((address) SafepointSynchronize::block, "T", "v");
twisti@2047 236 }
twisti@2047 237
twisti@2047 238 Value* SharkBuilder::throw_ArithmeticException() {
twisti@2047 239 return make_function(
twisti@2047 240 (address) SharkRuntime::throw_ArithmeticException, "TCi", "v");
twisti@2047 241 }
twisti@2047 242
twisti@2047 243 Value* SharkBuilder::throw_ArrayIndexOutOfBoundsException() {
twisti@2047 244 return make_function(
twisti@2047 245 (address) SharkRuntime::throw_ArrayIndexOutOfBoundsException, "TCii", "v");
twisti@2047 246 }
twisti@2047 247
twisti@2047 248 Value* SharkBuilder::throw_ClassCastException() {
twisti@2047 249 return make_function(
twisti@2047 250 (address) SharkRuntime::throw_ClassCastException, "TCi", "v");
twisti@2047 251 }
twisti@2047 252
twisti@2047 253 Value* SharkBuilder::throw_NullPointerException() {
twisti@2047 254 return make_function(
twisti@2047 255 (address) SharkRuntime::throw_NullPointerException, "TCi", "v");
twisti@2047 256 }
twisti@2047 257
twisti@2047 258 // High-level non-VM calls
twisti@2047 259
twisti@2047 260 Value* SharkBuilder::f2i() {
twisti@2047 261 return make_function((address) SharedRuntime::f2i, "f", "i");
twisti@2047 262 }
twisti@2047 263
twisti@2047 264 Value* SharkBuilder::f2l() {
twisti@2047 265 return make_function((address) SharedRuntime::f2l, "f", "l");
twisti@2047 266 }
twisti@2047 267
twisti@2047 268 Value* SharkBuilder::d2i() {
twisti@2047 269 return make_function((address) SharedRuntime::d2i, "d", "i");
twisti@2047 270 }
twisti@2047 271
twisti@2047 272 Value* SharkBuilder::d2l() {
twisti@2047 273 return make_function((address) SharedRuntime::d2l, "d", "l");
twisti@2047 274 }
twisti@2047 275
twisti@2047 276 Value* SharkBuilder::is_subtype_of() {
twisti@2047 277 return make_function((address) SharkRuntime::is_subtype_of, "OO", "c");
twisti@2047 278 }
twisti@2047 279
twisti@2047 280 Value* SharkBuilder::current_time_millis() {
twisti@2047 281 return make_function((address) os::javaTimeMillis, "", "l");
twisti@2047 282 }
twisti@2047 283
twisti@2047 284 Value* SharkBuilder::sin() {
twisti@2047 285 return make_function("llvm.sin.f64", "d", "d");
twisti@2047 286 }
twisti@2047 287
twisti@2047 288 Value* SharkBuilder::cos() {
twisti@2047 289 return make_function("llvm.cos.f64", "d", "d");
twisti@2047 290 }
twisti@2047 291
twisti@2047 292 Value* SharkBuilder::tan() {
twisti@2047 293 return make_function((address) ::tan, "d", "d");
twisti@2047 294 }
twisti@2047 295
twisti@2047 296 Value* SharkBuilder::atan2() {
twisti@2047 297 return make_function((address) ::atan2, "dd", "d");
twisti@2047 298 }
twisti@2047 299
twisti@2047 300 Value* SharkBuilder::sqrt() {
twisti@2047 301 return make_function("llvm.sqrt.f64", "d", "d");
twisti@2047 302 }
twisti@2047 303
twisti@2047 304 Value* SharkBuilder::log() {
twisti@2047 305 return make_function("llvm.log.f64", "d", "d");
twisti@2047 306 }
twisti@2047 307
twisti@2047 308 Value* SharkBuilder::log10() {
twisti@2047 309 return make_function("llvm.log10.f64", "d", "d");
twisti@2047 310 }
twisti@2047 311
twisti@2047 312 Value* SharkBuilder::pow() {
twisti@2047 313 return make_function("llvm.pow.f64", "dd", "d");
twisti@2047 314 }
twisti@2047 315
twisti@2047 316 Value* SharkBuilder::exp() {
twisti@2047 317 return make_function("llvm.exp.f64", "d", "d");
twisti@2047 318 }
twisti@2047 319
twisti@2047 320 Value* SharkBuilder::fabs() {
twisti@2047 321 return make_function((address) ::fabs, "d", "d");
twisti@2047 322 }
twisti@2047 323
twisti@2047 324 Value* SharkBuilder::unsafe_field_offset_to_byte_offset() {
twisti@2047 325 extern jlong Unsafe_field_offset_to_byte_offset(jlong field_offset);
twisti@2047 326 return make_function((address) Unsafe_field_offset_to_byte_offset, "l", "l");
twisti@2047 327 }
twisti@2047 328
twisti@2047 329 Value* SharkBuilder::osr_migration_end() {
twisti@2047 330 return make_function((address) SharedRuntime::OSR_migration_end, "C", "v");
twisti@2047 331 }
twisti@2047 332
twisti@2047 333 // Semi-VM calls
twisti@2047 334
twisti@2047 335 Value* SharkBuilder::throw_StackOverflowError() {
twisti@2047 336 return make_function((address) ZeroStack::handle_overflow, "T", "v");
twisti@2047 337 }
twisti@2047 338
twisti@2047 339 Value* SharkBuilder::uncommon_trap() {
twisti@2047 340 return make_function((address) SharkRuntime::uncommon_trap, "Ti", "i");
twisti@2047 341 }
twisti@2047 342
twisti@2047 343 Value* SharkBuilder::deoptimized_entry_point() {
twisti@2047 344 return make_function((address) CppInterpreter::main_loop, "iT", "v");
twisti@2047 345 }
twisti@2047 346
twisti@2047 347 // Native-Java transition
twisti@2047 348
twisti@2047 349 Value* SharkBuilder::check_special_condition_for_native_trans() {
twisti@2047 350 return make_function(
twisti@2047 351 (address) JavaThread::check_special_condition_for_native_trans,
twisti@2047 352 "T", "v");
twisti@2047 353 }
twisti@2047 354
twisti@2047 355 // Low-level non-VM calls
twisti@2047 356
twisti@2047 357 // The ARM-specific code here is to work around unimplemented
twisti@2047 358 // atomic exchange and memory barrier intrinsics in LLVM.
twisti@2047 359 //
twisti@2047 360 // Delegating to external functions for these would normally
twisti@2047 361 // incur a speed penalty, but Linux on ARM is a special case
twisti@2047 362 // in that atomic operations on that platform are handled by
twisti@2047 363 // external functions anyway. It would be *preferable* for
twisti@2047 364 // the calls to be hidden away in LLVM, but it's not hurting
twisti@2047 365 // performance so having the calls here is acceptable.
twisti@2047 366 //
twisti@2047 367 // If you are building Shark on a platform without atomic
twisti@2047 368 // exchange and/or memory barrier intrinsics then it is only
twisti@2047 369 // acceptable to mimic this approach if your platform cannot
twisti@2047 370 // perform these operations without delegating to a function.
twisti@2047 371
twisti@2047 372 #ifdef ARM
twisti@2047 373 static jint zero_cmpxchg_int(volatile jint *ptr, jint oldval, jint newval) {
twisti@2047 374 return Atomic::cmpxchg(newval, ptr, oldval);
twisti@2047 375 }
twisti@2047 376 #endif // ARM
twisti@2047 377
twisti@2047 378 Value* SharkBuilder::cmpxchg_int() {
twisti@2047 379 return make_function(
twisti@2047 380 #ifdef ARM
twisti@2047 381 (address) zero_cmpxchg_int,
twisti@2047 382 #else
twisti@2047 383 "llvm.atomic.cmp.swap.i32.p0i32",
twisti@2047 384 #endif // ARM
twisti@2047 385 "Iii", "i");
twisti@2047 386 }
twisti@2047 387
twisti@2047 388 #ifdef ARM
twisti@2047 389 static intptr_t zero_cmpxchg_ptr(volatile intptr_t* ptr,
twisti@2047 390 intptr_t oldval,
twisti@2047 391 intptr_t newval) {
twisti@2047 392 return Atomic::cmpxchg_ptr(newval, ptr, oldval);
twisti@2047 393 }
twisti@2047 394 #endif // ARM
twisti@2047 395
twisti@2047 396 Value* SharkBuilder::cmpxchg_ptr() {
twisti@2047 397 return make_function(
twisti@2047 398 #ifdef ARM
twisti@2047 399 (address) zero_cmpxchg_ptr,
twisti@2047 400 #else
twisti@2047 401 "llvm.atomic.cmp.swap.i" LP64_ONLY("64") NOT_LP64("32") ".p0i" LP64_ONLY("64") NOT_LP64("32"),
twisti@2047 402 #endif // ARM
twisti@2047 403 "Xxx", "x");
twisti@2047 404 }
twisti@2047 405
twisti@2047 406 Value* SharkBuilder::frame_address() {
twisti@2047 407 return make_function("llvm.frameaddress", "i", "C");
twisti@2047 408 }
twisti@2047 409
twisti@2047 410 Value* SharkBuilder::memory_barrier() {
twisti@2047 411 return make_function(
twisti@2047 412 #ifdef ARM
twisti@2047 413 (address) 0xffff0fa0, // __kernel_dmb
twisti@2047 414 #else
twisti@2047 415 "llvm.memory.barrier",
twisti@2047 416 #endif // ARM
twisti@2047 417 "11111", "v");
twisti@2047 418 }
twisti@2047 419
twisti@2047 420 Value* SharkBuilder::memset() {
twisti@2047 421 #if SHARK_LLVM_VERSION >= 28
twisti@2047 422 // LLVM 2.8 added a fifth isVolatile field for memset
twisti@2047 423 // introduced with LLVM r100304
twisti@2047 424 return make_function("llvm.memset.i32", "Cciii", "v");
twisti@2047 425 #else
twisti@2047 426 return make_function("llvm.memset.i32", "Ccii", "v");
twisti@2047 427 #endif
twisti@2047 428 }
twisti@2047 429
twisti@2047 430 Value* SharkBuilder::unimplemented() {
twisti@2047 431 return make_function((address) report_unimplemented, "Ci", "v");
twisti@2047 432 }
twisti@2047 433
twisti@2047 434 Value* SharkBuilder::should_not_reach_here() {
twisti@2047 435 return make_function((address) report_should_not_reach_here, "Ci", "v");
twisti@2047 436 }
twisti@2047 437
twisti@2047 438 Value* SharkBuilder::dump() {
twisti@2047 439 return make_function((address) SharkRuntime::dump, "Cx", "v");
twisti@2047 440 }
twisti@2047 441
twisti@2047 442 // Public interface to low-level non-VM calls
twisti@2047 443
twisti@2047 444 CallInst* SharkBuilder::CreateCmpxchgInt(Value* exchange_value,
twisti@2047 445 Value* dst,
twisti@2047 446 Value* compare_value) {
twisti@2047 447 return CreateCall3(cmpxchg_int(), dst, compare_value, exchange_value);
twisti@2047 448 }
twisti@2047 449
twisti@2047 450 CallInst* SharkBuilder::CreateCmpxchgPtr(Value* exchange_value,
twisti@2047 451 Value* dst,
twisti@2047 452 Value* compare_value) {
twisti@2047 453 return CreateCall3(cmpxchg_ptr(), dst, compare_value, exchange_value);
twisti@2047 454 }
twisti@2047 455
twisti@2047 456 CallInst* SharkBuilder::CreateGetFrameAddress() {
twisti@2047 457 return CreateCall(frame_address(), LLVMValue::jint_constant(0));
twisti@2047 458 }
twisti@2047 459
twisti@2047 460 CallInst *SharkBuilder::CreateMemoryBarrier(int flags) {
twisti@2047 461 Value *args[] = {
twisti@2047 462 LLVMValue::bit_constant((flags & BARRIER_LOADLOAD) ? 1 : 0),
twisti@2047 463 LLVMValue::bit_constant((flags & BARRIER_LOADSTORE) ? 1 : 0),
twisti@2047 464 LLVMValue::bit_constant((flags & BARRIER_STORELOAD) ? 1 : 0),
twisti@2047 465 LLVMValue::bit_constant((flags & BARRIER_STORESTORE) ? 1 : 0),
twisti@2047 466 LLVMValue::bit_constant(1)};
twisti@2047 467
twisti@2047 468 return CreateCall(memory_barrier(), args, args + 5);
twisti@2047 469 }
twisti@2047 470
twisti@2047 471 CallInst* SharkBuilder::CreateMemset(Value* dst,
twisti@2047 472 Value* value,
twisti@2047 473 Value* len,
twisti@2047 474 Value* align) {
twisti@2047 475 #if SHARK_LLVM_VERSION >= 28
twisti@2047 476 return CreateCall5(memset(), dst, value, len, align,
twisti@2047 477 LLVMValue::jint_constant(0));
twisti@2047 478 #else
twisti@2047 479 return CreateCall4(memset(), dst, value, len, align);
twisti@2047 480 #endif
twisti@2047 481 }
twisti@2047 482
twisti@2047 483 CallInst* SharkBuilder::CreateUnimplemented(const char* file, int line) {
twisti@2047 484 return CreateCall2(
twisti@2047 485 unimplemented(),
twisti@2047 486 CreateIntToPtr(
twisti@2047 487 LLVMValue::intptr_constant((intptr_t) file),
twisti@2047 488 PointerType::getUnqual(SharkType::jbyte_type())),
twisti@2047 489 LLVMValue::jint_constant(line));
twisti@2047 490 }
twisti@2047 491
twisti@2047 492 CallInst* SharkBuilder::CreateShouldNotReachHere(const char* file, int line) {
twisti@2047 493 return CreateCall2(
twisti@2047 494 should_not_reach_here(),
twisti@2047 495 CreateIntToPtr(
twisti@2047 496 LLVMValue::intptr_constant((intptr_t) file),
twisti@2047 497 PointerType::getUnqual(SharkType::jbyte_type())),
twisti@2047 498 LLVMValue::jint_constant(line));
twisti@2047 499 }
twisti@2047 500
twisti@2047 501 #ifndef PRODUCT
twisti@2047 502 CallInst* SharkBuilder::CreateDump(Value* value) {
twisti@2047 503 const char *name;
twisti@2047 504 if (value->hasName())
twisti@2047 505 // XXX this leaks, but it's only debug code
twisti@2047 506 name = strdup(value->getName().str().c_str());
twisti@2047 507 else
twisti@2047 508 name = "unnamed_value";
twisti@2047 509
twisti@2047 510 if (isa<PointerType>(value->getType()))
twisti@2047 511 value = CreatePtrToInt(value, SharkType::intptr_type());
twisti@2047 512 else if (value->getType()->
twisti@2047 513 #if SHARK_LLVM_VERSION >= 27
twisti@2047 514 isIntegerTy()
twisti@2047 515 #else
twisti@2047 516 isInteger()
twisti@2047 517 #endif
twisti@2047 518 )
twisti@2047 519 value = CreateIntCast(value, SharkType::intptr_type(), false);
twisti@2047 520 else
twisti@2047 521 Unimplemented();
twisti@2047 522
twisti@2047 523 return CreateCall2(
twisti@2047 524 dump(),
twisti@2047 525 CreateIntToPtr(
twisti@2047 526 LLVMValue::intptr_constant((intptr_t) name),
twisti@2047 527 PointerType::getUnqual(SharkType::jbyte_type())),
twisti@2047 528 value);
twisti@2047 529 }
twisti@2047 530 #endif // PRODUCT
twisti@2047 531
twisti@2047 532 // HotSpot memory barriers
twisti@2047 533
twisti@2047 534 void SharkBuilder::CreateUpdateBarrierSet(BarrierSet* bs, Value* field) {
twisti@2047 535 if (bs->kind() != BarrierSet::CardTableModRef)
twisti@2047 536 Unimplemented();
twisti@2047 537
twisti@2047 538 CreateStore(
twisti@2047 539 LLVMValue::jbyte_constant(CardTableModRefBS::dirty_card),
twisti@2047 540 CreateIntToPtr(
twisti@2047 541 CreateAdd(
twisti@2047 542 LLVMValue::intptr_constant(
twisti@2047 543 (intptr_t) ((CardTableModRefBS *) bs)->byte_map_base),
twisti@2047 544 CreateLShr(
twisti@2047 545 CreatePtrToInt(field, SharkType::intptr_type()),
twisti@2047 546 LLVMValue::intptr_constant(CardTableModRefBS::card_shift))),
twisti@2047 547 PointerType::getUnqual(SharkType::jbyte_type())));
twisti@2047 548 }
twisti@2047 549
twisti@2047 550 // Helpers for accessing the code buffer
twisti@2047 551
twisti@2047 552 Value* SharkBuilder::code_buffer_address(int offset) {
twisti@2047 553 return CreateAdd(
twisti@2047 554 code_buffer()->base_pc(),
twisti@2047 555 LLVMValue::intptr_constant(offset));
twisti@2047 556 }
twisti@2047 557
twisti@2047 558 Value* SharkBuilder::CreateInlineOop(jobject object, const char* name) {
twisti@2047 559 return CreateLoad(
twisti@2047 560 CreateIntToPtr(
twisti@2047 561 code_buffer_address(code_buffer()->inline_oop(object)),
twisti@2047 562 PointerType::getUnqual(SharkType::oop_type())),
twisti@2047 563 name);
twisti@2047 564 }
twisti@2047 565
twisti@2047 566 Value* SharkBuilder::CreateInlineData(void* data,
twisti@2047 567 size_t size,
twisti@2047 568 const Type* type,
twisti@2047 569 const char* name) {
twisti@2047 570 return CreateIntToPtr(
twisti@2047 571 code_buffer_address(code_buffer()->inline_data(data, size)),
twisti@2047 572 type,
twisti@2047 573 name);
twisti@2047 574 }
twisti@2047 575
twisti@2047 576 // Helpers for creating basic blocks.
twisti@2047 577
twisti@2047 578 BasicBlock* SharkBuilder::GetBlockInsertionPoint() const {
twisti@2047 579 BasicBlock *cur = GetInsertBlock();
twisti@2047 580
twisti@2047 581 // BasicBlock::Create takes an insertBefore argument, so
twisti@2047 582 // we need to find the block _after_ the current block
twisti@2047 583 Function::iterator iter = cur->getParent()->begin();
twisti@2047 584 Function::iterator end = cur->getParent()->end();
twisti@2047 585 while (iter != end) {
twisti@2047 586 iter++;
twisti@2047 587 if (&*iter == cur) {
twisti@2047 588 iter++;
twisti@2047 589 break;
twisti@2047 590 }
twisti@2047 591 }
twisti@2047 592
twisti@2047 593 if (iter == end)
twisti@2047 594 return NULL;
twisti@2047 595 else
twisti@2047 596 return iter;
twisti@2047 597 }
twisti@2047 598
twisti@2047 599 BasicBlock* SharkBuilder::CreateBlock(BasicBlock* ip, const char* name) const {
twisti@2047 600 return BasicBlock::Create(
twisti@2047 601 SharkContext::current(), name, GetInsertBlock()->getParent(), ip);
twisti@2047 602 }

mercurial