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

mercurial