src/share/vm/shark/sharkBuilder.cpp

changeset 2047
d2ede61b7a12
child 2314
f95d63e2154a
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/vm/shark/sharkBuilder.cpp	Wed Aug 11 05:51:21 2010 -0700
     1.3 @@ -0,0 +1,591 @@
     1.4 +/*
     1.5 + * Copyright (c) 1999, 2007, Oracle and/or its affiliates. All rights reserved.
     1.6 + * Copyright 2008, 2009, 2010 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/_sharkBuilder.cpp.incl"
    1.31 +
    1.32 +using namespace llvm;
    1.33 +
    1.34 +SharkBuilder::SharkBuilder(SharkCodeBuffer* code_buffer)
    1.35 +  : IRBuilder<>(SharkContext::current()),
    1.36 +    _code_buffer(code_buffer) {
    1.37 +}
    1.38 +
    1.39 +// Helpers for accessing structures
    1.40 +Value* SharkBuilder::CreateAddressOfStructEntry(Value*      base,
    1.41 +                                                ByteSize    offset,
    1.42 +                                                const Type* type,
    1.43 +                                                const char* name) {
    1.44 +  return CreateBitCast(CreateStructGEP(base, in_bytes(offset)), type, name);
    1.45 +}
    1.46 +
    1.47 +LoadInst* SharkBuilder::CreateValueOfStructEntry(Value*      base,
    1.48 +                                                 ByteSize    offset,
    1.49 +                                                 const Type* type,
    1.50 +                                                 const char* name) {
    1.51 +  return CreateLoad(
    1.52 +    CreateAddressOfStructEntry(
    1.53 +      base, offset, PointerType::getUnqual(type)),
    1.54 +    name);
    1.55 +}
    1.56 +
    1.57 +// Helpers for accessing arrays
    1.58 +
    1.59 +LoadInst* SharkBuilder::CreateArrayLength(Value* arrayoop) {
    1.60 +  return CreateValueOfStructEntry(
    1.61 +    arrayoop, in_ByteSize(arrayOopDesc::length_offset_in_bytes()),
    1.62 +    SharkType::jint_type(), "length");
    1.63 +}
    1.64 +
    1.65 +Value* SharkBuilder::CreateArrayAddress(Value*      arrayoop,
    1.66 +                                        const Type* element_type,
    1.67 +                                        int         element_bytes,
    1.68 +                                        ByteSize    base_offset,
    1.69 +                                        Value*      index,
    1.70 +                                        const char* name) {
    1.71 +  Value* offset = CreateIntCast(index, SharkType::intptr_type(), false);
    1.72 +  if (element_bytes != 1)
    1.73 +    offset = CreateShl(
    1.74 +      offset,
    1.75 +      LLVMValue::intptr_constant(exact_log2(element_bytes)));
    1.76 +  offset = CreateAdd(
    1.77 +    LLVMValue::intptr_constant(in_bytes(base_offset)), offset);
    1.78 +
    1.79 +  return CreateIntToPtr(
    1.80 +    CreateAdd(CreatePtrToInt(arrayoop, SharkType::intptr_type()), offset),
    1.81 +    PointerType::getUnqual(element_type),
    1.82 +    name);
    1.83 +}
    1.84 +
    1.85 +Value* SharkBuilder::CreateArrayAddress(Value*      arrayoop,
    1.86 +                                        BasicType   basic_type,
    1.87 +                                        ByteSize    base_offset,
    1.88 +                                        Value*      index,
    1.89 +                                        const char* name) {
    1.90 +  return CreateArrayAddress(
    1.91 +    arrayoop,
    1.92 +    SharkType::to_arrayType(basic_type),
    1.93 +    type2aelembytes(basic_type),
    1.94 +    base_offset, index, name);
    1.95 +}
    1.96 +
    1.97 +Value* SharkBuilder::CreateArrayAddress(Value*      arrayoop,
    1.98 +                                        BasicType   basic_type,
    1.99 +                                        Value*      index,
   1.100 +                                        const char* name) {
   1.101 +  return CreateArrayAddress(
   1.102 +    arrayoop, basic_type,
   1.103 +    in_ByteSize(arrayOopDesc::base_offset_in_bytes(basic_type)),
   1.104 +    index, name);
   1.105 +}
   1.106 +
   1.107 +// Helpers for creating intrinsics and external functions.
   1.108 +
   1.109 +const Type* SharkBuilder::make_type(char type, bool void_ok) {
   1.110 +  switch (type) {
   1.111 +    // Primitive types
   1.112 +  case 'c':
   1.113 +    return SharkType::jbyte_type();
   1.114 +  case 'i':
   1.115 +    return SharkType::jint_type();
   1.116 +  case 'l':
   1.117 +    return SharkType::jlong_type();
   1.118 +  case 'x':
   1.119 +    return SharkType::intptr_type();
   1.120 +  case 'f':
   1.121 +    return SharkType::jfloat_type();
   1.122 +  case 'd':
   1.123 +    return SharkType::jdouble_type();
   1.124 +
   1.125 +    // Pointers to primitive types
   1.126 +  case 'C':
   1.127 +  case 'I':
   1.128 +  case 'L':
   1.129 +  case 'X':
   1.130 +  case 'F':
   1.131 +  case 'D':
   1.132 +    return PointerType::getUnqual(make_type(tolower(type), false));
   1.133 +
   1.134 +    // VM objects
   1.135 +  case 'T':
   1.136 +    return SharkType::thread_type();
   1.137 +  case 'M':
   1.138 +    return PointerType::getUnqual(SharkType::monitor_type());
   1.139 +  case 'O':
   1.140 +    return SharkType::oop_type();
   1.141 +
   1.142 +    // Miscellaneous
   1.143 +  case 'v':
   1.144 +    assert(void_ok, "should be");
   1.145 +    return SharkType::void_type();
   1.146 +  case '1':
   1.147 +    return SharkType::bit_type();
   1.148 +
   1.149 +  default:
   1.150 +    ShouldNotReachHere();
   1.151 +  }
   1.152 +}
   1.153 +
   1.154 +const FunctionType* SharkBuilder::make_ftype(const char* params,
   1.155 +                                             const char* ret) {
   1.156 +  std::vector<const Type*> param_types;
   1.157 +  for (const char* c = params; *c; c++)
   1.158 +    param_types.push_back(make_type(*c, false));
   1.159 +
   1.160 +  assert(strlen(ret) == 1, "should be");
   1.161 +  const Type *return_type = make_type(*ret, true);
   1.162 +
   1.163 +  return FunctionType::get(return_type, param_types, false);
   1.164 +}
   1.165 +
   1.166 +// Create an object representing an intrinsic or external function by
   1.167 +// referencing the symbol by name.  This is the LLVM-style approach,
   1.168 +// but it cannot be used on functions within libjvm.so its symbols
   1.169 +// are not exported.  Note that you cannot make this work simply by
   1.170 +// exporting the symbols, as some symbols have the same names as
   1.171 +// symbols in the standard libraries (eg, atan2, fabs) and would
   1.172 +// obscure them were they visible.
   1.173 +Value* SharkBuilder::make_function(const char* name,
   1.174 +                                   const char* params,
   1.175 +                                   const char* ret) {
   1.176 +  return SharkContext::current().get_external(name, make_ftype(params, ret));
   1.177 +}
   1.178 +
   1.179 +// Create an object representing an external function by inlining a
   1.180 +// function pointer in the code.  This is not the LLVM way, but it's
   1.181 +// the only way to access functions in libjvm.so and functions like
   1.182 +// __kernel_dmb on ARM which is accessed via an absolute address.
   1.183 +Value* SharkBuilder::make_function(address     func,
   1.184 +                                   const char* params,
   1.185 +                                   const char* ret) {
   1.186 +  return CreateIntToPtr(
   1.187 +    LLVMValue::intptr_constant((intptr_t) func),
   1.188 +    PointerType::getUnqual(make_ftype(params, ret)));
   1.189 +}
   1.190 +
   1.191 +// VM calls
   1.192 +
   1.193 +Value* SharkBuilder::find_exception_handler() {
   1.194 +  return make_function(
   1.195 +    (address) SharkRuntime::find_exception_handler, "TIi", "i");
   1.196 +}
   1.197 +
   1.198 +Value* SharkBuilder::monitorenter() {
   1.199 +  return make_function((address) SharkRuntime::monitorenter, "TM", "v");
   1.200 +}
   1.201 +
   1.202 +Value* SharkBuilder::monitorexit() {
   1.203 +  return make_function((address) SharkRuntime::monitorexit, "TM", "v");
   1.204 +}
   1.205 +
   1.206 +Value* SharkBuilder::new_instance() {
   1.207 +  return make_function((address) SharkRuntime::new_instance, "Ti", "v");
   1.208 +}
   1.209 +
   1.210 +Value* SharkBuilder::newarray() {
   1.211 +  return make_function((address) SharkRuntime::newarray, "Tii", "v");
   1.212 +}
   1.213 +
   1.214 +Value* SharkBuilder::anewarray() {
   1.215 +  return make_function((address) SharkRuntime::anewarray, "Tii", "v");
   1.216 +}
   1.217 +
   1.218 +Value* SharkBuilder::multianewarray() {
   1.219 +  return make_function((address) SharkRuntime::multianewarray, "TiiI", "v");
   1.220 +}
   1.221 +
   1.222 +Value* SharkBuilder::register_finalizer() {
   1.223 +  return make_function((address) SharkRuntime::register_finalizer, "TO", "v");
   1.224 +}
   1.225 +
   1.226 +Value* SharkBuilder::safepoint() {
   1.227 +  return make_function((address) SafepointSynchronize::block, "T", "v");
   1.228 +}
   1.229 +
   1.230 +Value* SharkBuilder::throw_ArithmeticException() {
   1.231 +  return make_function(
   1.232 +    (address) SharkRuntime::throw_ArithmeticException, "TCi", "v");
   1.233 +}
   1.234 +
   1.235 +Value* SharkBuilder::throw_ArrayIndexOutOfBoundsException() {
   1.236 +  return make_function(
   1.237 +    (address) SharkRuntime::throw_ArrayIndexOutOfBoundsException, "TCii", "v");
   1.238 +}
   1.239 +
   1.240 +Value* SharkBuilder::throw_ClassCastException() {
   1.241 +  return make_function(
   1.242 +    (address) SharkRuntime::throw_ClassCastException, "TCi", "v");
   1.243 +}
   1.244 +
   1.245 +Value* SharkBuilder::throw_NullPointerException() {
   1.246 +  return make_function(
   1.247 +    (address) SharkRuntime::throw_NullPointerException, "TCi", "v");
   1.248 +}
   1.249 +
   1.250 +// High-level non-VM calls
   1.251 +
   1.252 +Value* SharkBuilder::f2i() {
   1.253 +  return make_function((address) SharedRuntime::f2i, "f", "i");
   1.254 +}
   1.255 +
   1.256 +Value* SharkBuilder::f2l() {
   1.257 +  return make_function((address) SharedRuntime::f2l, "f", "l");
   1.258 +}
   1.259 +
   1.260 +Value* SharkBuilder::d2i() {
   1.261 +  return make_function((address) SharedRuntime::d2i, "d", "i");
   1.262 +}
   1.263 +
   1.264 +Value* SharkBuilder::d2l() {
   1.265 +  return make_function((address) SharedRuntime::d2l, "d", "l");
   1.266 +}
   1.267 +
   1.268 +Value* SharkBuilder::is_subtype_of() {
   1.269 +  return make_function((address) SharkRuntime::is_subtype_of, "OO", "c");
   1.270 +}
   1.271 +
   1.272 +Value* SharkBuilder::current_time_millis() {
   1.273 +  return make_function((address) os::javaTimeMillis, "", "l");
   1.274 +}
   1.275 +
   1.276 +Value* SharkBuilder::sin() {
   1.277 +  return make_function("llvm.sin.f64", "d", "d");
   1.278 +}
   1.279 +
   1.280 +Value* SharkBuilder::cos() {
   1.281 +  return make_function("llvm.cos.f64", "d", "d");
   1.282 +}
   1.283 +
   1.284 +Value* SharkBuilder::tan() {
   1.285 +  return make_function((address) ::tan, "d", "d");
   1.286 +}
   1.287 +
   1.288 +Value* SharkBuilder::atan2() {
   1.289 +  return make_function((address) ::atan2, "dd", "d");
   1.290 +}
   1.291 +
   1.292 +Value* SharkBuilder::sqrt() {
   1.293 +  return make_function("llvm.sqrt.f64", "d", "d");
   1.294 +}
   1.295 +
   1.296 +Value* SharkBuilder::log() {
   1.297 +  return make_function("llvm.log.f64", "d", "d");
   1.298 +}
   1.299 +
   1.300 +Value* SharkBuilder::log10() {
   1.301 +  return make_function("llvm.log10.f64", "d", "d");
   1.302 +}
   1.303 +
   1.304 +Value* SharkBuilder::pow() {
   1.305 +  return make_function("llvm.pow.f64", "dd", "d");
   1.306 +}
   1.307 +
   1.308 +Value* SharkBuilder::exp() {
   1.309 +  return make_function("llvm.exp.f64", "d", "d");
   1.310 +}
   1.311 +
   1.312 +Value* SharkBuilder::fabs() {
   1.313 +  return make_function((address) ::fabs, "d", "d");
   1.314 +}
   1.315 +
   1.316 +Value* SharkBuilder::unsafe_field_offset_to_byte_offset() {
   1.317 +  extern jlong Unsafe_field_offset_to_byte_offset(jlong field_offset);
   1.318 +  return make_function((address) Unsafe_field_offset_to_byte_offset, "l", "l");
   1.319 +}
   1.320 +
   1.321 +Value* SharkBuilder::osr_migration_end() {
   1.322 +  return make_function((address) SharedRuntime::OSR_migration_end, "C", "v");
   1.323 +}
   1.324 +
   1.325 +// Semi-VM calls
   1.326 +
   1.327 +Value* SharkBuilder::throw_StackOverflowError() {
   1.328 +  return make_function((address) ZeroStack::handle_overflow, "T", "v");
   1.329 +}
   1.330 +
   1.331 +Value* SharkBuilder::uncommon_trap() {
   1.332 +  return make_function((address) SharkRuntime::uncommon_trap, "Ti", "i");
   1.333 +}
   1.334 +
   1.335 +Value* SharkBuilder::deoptimized_entry_point() {
   1.336 +  return make_function((address) CppInterpreter::main_loop, "iT", "v");
   1.337 +}
   1.338 +
   1.339 +// Native-Java transition
   1.340 +
   1.341 +Value* SharkBuilder::check_special_condition_for_native_trans() {
   1.342 +  return make_function(
   1.343 +    (address) JavaThread::check_special_condition_for_native_trans,
   1.344 +    "T", "v");
   1.345 +}
   1.346 +
   1.347 +// Low-level non-VM calls
   1.348 +
   1.349 +// The ARM-specific code here is to work around unimplemented
   1.350 +// atomic exchange and memory barrier intrinsics in LLVM.
   1.351 +//
   1.352 +// Delegating to external functions for these would normally
   1.353 +// incur a speed penalty, but Linux on ARM is a special case
   1.354 +// in that atomic operations on that platform are handled by
   1.355 +// external functions anyway.  It would be *preferable* for
   1.356 +// the calls to be hidden away in LLVM, but it's not hurting
   1.357 +// performance so having the calls here is acceptable.
   1.358 +//
   1.359 +// If you are building Shark on a platform without atomic
   1.360 +// exchange and/or memory barrier intrinsics then it is only
   1.361 +// acceptable to mimic this approach if your platform cannot
   1.362 +// perform these operations without delegating to a function.
   1.363 +
   1.364 +#ifdef ARM
   1.365 +static jint zero_cmpxchg_int(volatile jint *ptr, jint oldval, jint newval) {
   1.366 +  return Atomic::cmpxchg(newval, ptr, oldval);
   1.367 +}
   1.368 +#endif // ARM
   1.369 +
   1.370 +Value* SharkBuilder::cmpxchg_int() {
   1.371 +  return make_function(
   1.372 +#ifdef ARM
   1.373 +    (address) zero_cmpxchg_int,
   1.374 +#else
   1.375 +    "llvm.atomic.cmp.swap.i32.p0i32",
   1.376 +#endif // ARM
   1.377 +    "Iii", "i");
   1.378 +}
   1.379 +
   1.380 +#ifdef ARM
   1.381 +static intptr_t zero_cmpxchg_ptr(volatile intptr_t* ptr,
   1.382 +                                 intptr_t           oldval,
   1.383 +                                 intptr_t           newval) {
   1.384 +  return Atomic::cmpxchg_ptr(newval, ptr, oldval);
   1.385 +}
   1.386 +#endif // ARM
   1.387 +
   1.388 +Value* SharkBuilder::cmpxchg_ptr() {
   1.389 +  return make_function(
   1.390 +#ifdef ARM
   1.391 +    (address) zero_cmpxchg_ptr,
   1.392 +#else
   1.393 +    "llvm.atomic.cmp.swap.i" LP64_ONLY("64") NOT_LP64("32") ".p0i" LP64_ONLY("64") NOT_LP64("32"),
   1.394 +#endif // ARM
   1.395 +    "Xxx", "x");
   1.396 +}
   1.397 +
   1.398 +Value* SharkBuilder::frame_address() {
   1.399 +  return make_function("llvm.frameaddress", "i", "C");
   1.400 +}
   1.401 +
   1.402 +Value* SharkBuilder::memory_barrier() {
   1.403 +  return make_function(
   1.404 +#ifdef ARM
   1.405 +    (address) 0xffff0fa0, // __kernel_dmb
   1.406 +#else
   1.407 +    "llvm.memory.barrier",
   1.408 +#endif // ARM
   1.409 +    "11111", "v");
   1.410 +}
   1.411 +
   1.412 +Value* SharkBuilder::memset() {
   1.413 +#if SHARK_LLVM_VERSION >= 28
   1.414 +  // LLVM 2.8 added a fifth isVolatile field for memset
   1.415 +  // introduced with LLVM r100304
   1.416 +  return make_function("llvm.memset.i32", "Cciii", "v");
   1.417 +#else
   1.418 +  return make_function("llvm.memset.i32", "Ccii", "v");
   1.419 +#endif
   1.420 +}
   1.421 +
   1.422 +Value* SharkBuilder::unimplemented() {
   1.423 +  return make_function((address) report_unimplemented, "Ci", "v");
   1.424 +}
   1.425 +
   1.426 +Value* SharkBuilder::should_not_reach_here() {
   1.427 +  return make_function((address) report_should_not_reach_here, "Ci", "v");
   1.428 +}
   1.429 +
   1.430 +Value* SharkBuilder::dump() {
   1.431 +  return make_function((address) SharkRuntime::dump, "Cx", "v");
   1.432 +}
   1.433 +
   1.434 +// Public interface to low-level non-VM calls
   1.435 +
   1.436 +CallInst* SharkBuilder::CreateCmpxchgInt(Value* exchange_value,
   1.437 +                                         Value* dst,
   1.438 +                                         Value* compare_value) {
   1.439 +  return CreateCall3(cmpxchg_int(), dst, compare_value, exchange_value);
   1.440 +}
   1.441 +
   1.442 +CallInst* SharkBuilder::CreateCmpxchgPtr(Value* exchange_value,
   1.443 +                                         Value* dst,
   1.444 +                                         Value* compare_value) {
   1.445 +  return CreateCall3(cmpxchg_ptr(), dst, compare_value, exchange_value);
   1.446 +}
   1.447 +
   1.448 +CallInst* SharkBuilder::CreateGetFrameAddress() {
   1.449 +  return CreateCall(frame_address(), LLVMValue::jint_constant(0));
   1.450 +}
   1.451 +
   1.452 +CallInst *SharkBuilder::CreateMemoryBarrier(int flags) {
   1.453 +  Value *args[] = {
   1.454 +    LLVMValue::bit_constant((flags & BARRIER_LOADLOAD) ? 1 : 0),
   1.455 +    LLVMValue::bit_constant((flags & BARRIER_LOADSTORE) ? 1 : 0),
   1.456 +    LLVMValue::bit_constant((flags & BARRIER_STORELOAD) ? 1 : 0),
   1.457 +    LLVMValue::bit_constant((flags & BARRIER_STORESTORE) ? 1 : 0),
   1.458 +    LLVMValue::bit_constant(1)};
   1.459 +
   1.460 +  return CreateCall(memory_barrier(), args, args + 5);
   1.461 +}
   1.462 +
   1.463 +CallInst* SharkBuilder::CreateMemset(Value* dst,
   1.464 +                                     Value* value,
   1.465 +                                     Value* len,
   1.466 +                                     Value* align) {
   1.467 +#if SHARK_LLVM_VERSION >= 28
   1.468 +  return CreateCall5(memset(), dst, value, len, align,
   1.469 +                     LLVMValue::jint_constant(0));
   1.470 +#else
   1.471 +  return CreateCall4(memset(), dst, value, len, align);
   1.472 +#endif
   1.473 +}
   1.474 +
   1.475 +CallInst* SharkBuilder::CreateUnimplemented(const char* file, int line) {
   1.476 +  return CreateCall2(
   1.477 +    unimplemented(),
   1.478 +    CreateIntToPtr(
   1.479 +      LLVMValue::intptr_constant((intptr_t) file),
   1.480 +      PointerType::getUnqual(SharkType::jbyte_type())),
   1.481 +    LLVMValue::jint_constant(line));
   1.482 +}
   1.483 +
   1.484 +CallInst* SharkBuilder::CreateShouldNotReachHere(const char* file, int line) {
   1.485 +  return CreateCall2(
   1.486 +    should_not_reach_here(),
   1.487 +    CreateIntToPtr(
   1.488 +      LLVMValue::intptr_constant((intptr_t) file),
   1.489 +      PointerType::getUnqual(SharkType::jbyte_type())),
   1.490 +    LLVMValue::jint_constant(line));
   1.491 +}
   1.492 +
   1.493 +#ifndef PRODUCT
   1.494 +CallInst* SharkBuilder::CreateDump(Value* value) {
   1.495 +  const char *name;
   1.496 +  if (value->hasName())
   1.497 +    // XXX this leaks, but it's only debug code
   1.498 +    name = strdup(value->getName().str().c_str());
   1.499 +  else
   1.500 +    name = "unnamed_value";
   1.501 +
   1.502 +  if (isa<PointerType>(value->getType()))
   1.503 +    value = CreatePtrToInt(value, SharkType::intptr_type());
   1.504 +  else if (value->getType()->
   1.505 +#if SHARK_LLVM_VERSION >= 27
   1.506 +           isIntegerTy()
   1.507 +#else
   1.508 +           isInteger()
   1.509 +#endif
   1.510 +           )
   1.511 +    value = CreateIntCast(value, SharkType::intptr_type(), false);
   1.512 +  else
   1.513 +    Unimplemented();
   1.514 +
   1.515 +  return CreateCall2(
   1.516 +    dump(),
   1.517 +    CreateIntToPtr(
   1.518 +      LLVMValue::intptr_constant((intptr_t) name),
   1.519 +      PointerType::getUnqual(SharkType::jbyte_type())),
   1.520 +    value);
   1.521 +}
   1.522 +#endif // PRODUCT
   1.523 +
   1.524 +// HotSpot memory barriers
   1.525 +
   1.526 +void SharkBuilder::CreateUpdateBarrierSet(BarrierSet* bs, Value* field) {
   1.527 +  if (bs->kind() != BarrierSet::CardTableModRef)
   1.528 +    Unimplemented();
   1.529 +
   1.530 +  CreateStore(
   1.531 +    LLVMValue::jbyte_constant(CardTableModRefBS::dirty_card),
   1.532 +    CreateIntToPtr(
   1.533 +      CreateAdd(
   1.534 +        LLVMValue::intptr_constant(
   1.535 +          (intptr_t) ((CardTableModRefBS *) bs)->byte_map_base),
   1.536 +        CreateLShr(
   1.537 +          CreatePtrToInt(field, SharkType::intptr_type()),
   1.538 +          LLVMValue::intptr_constant(CardTableModRefBS::card_shift))),
   1.539 +      PointerType::getUnqual(SharkType::jbyte_type())));
   1.540 +}
   1.541 +
   1.542 +// Helpers for accessing the code buffer
   1.543 +
   1.544 +Value* SharkBuilder::code_buffer_address(int offset) {
   1.545 +  return CreateAdd(
   1.546 +    code_buffer()->base_pc(),
   1.547 +    LLVMValue::intptr_constant(offset));
   1.548 +}
   1.549 +
   1.550 +Value* SharkBuilder::CreateInlineOop(jobject object, const char* name) {
   1.551 +  return CreateLoad(
   1.552 +    CreateIntToPtr(
   1.553 +      code_buffer_address(code_buffer()->inline_oop(object)),
   1.554 +      PointerType::getUnqual(SharkType::oop_type())),
   1.555 +    name);
   1.556 +}
   1.557 +
   1.558 +Value* SharkBuilder::CreateInlineData(void*       data,
   1.559 +                                      size_t      size,
   1.560 +                                      const Type* type,
   1.561 +                                      const char* name) {
   1.562 +  return CreateIntToPtr(
   1.563 +    code_buffer_address(code_buffer()->inline_data(data, size)),
   1.564 +    type,
   1.565 +    name);
   1.566 +}
   1.567 +
   1.568 +// Helpers for creating basic blocks.
   1.569 +
   1.570 +BasicBlock* SharkBuilder::GetBlockInsertionPoint() const {
   1.571 +  BasicBlock *cur = GetInsertBlock();
   1.572 +
   1.573 +  // BasicBlock::Create takes an insertBefore argument, so
   1.574 +  // we need to find the block _after_ the current block
   1.575 +  Function::iterator iter = cur->getParent()->begin();
   1.576 +  Function::iterator end  = cur->getParent()->end();
   1.577 +  while (iter != end) {
   1.578 +    iter++;
   1.579 +    if (&*iter == cur) {
   1.580 +      iter++;
   1.581 +      break;
   1.582 +    }
   1.583 +  }
   1.584 +
   1.585 +  if (iter == end)
   1.586 +    return NULL;
   1.587 +  else
   1.588 +    return iter;
   1.589 +}
   1.590 +
   1.591 +BasicBlock* SharkBuilder::CreateBlock(BasicBlock* ip, const char* name) const {
   1.592 +  return BasicBlock::Create(
   1.593 +    SharkContext::current(), name, GetInsertBlock()->getParent(), ip);
   1.594 +}

mercurial