src/share/vm/shark/sharkBuilder.cpp

Wed, 27 Apr 2016 01:25:04 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:25:04 +0800
changeset 0
f90c822e73f8
child 6876
710a3c8b516e
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/hotspot/
changeset: 6782:28b50d07f6f8
tag: jdk8u25-b17

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * Copyright 2008, 2009, 2010 Red Hat, Inc.
aoqi@0 4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 5 *
aoqi@0 6 * This code is free software; you can redistribute it and/or modify it
aoqi@0 7 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 8 * published by the Free Software Foundation.
aoqi@0 9 *
aoqi@0 10 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 13 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 14 * accompanied this code).
aoqi@0 15 *
aoqi@0 16 * You should have received a copy of the GNU General Public License version
aoqi@0 17 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 19 *
aoqi@0 20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 21 * or visit www.oracle.com if you need additional information or have any
aoqi@0 22 * questions.
aoqi@0 23 *
aoqi@0 24 */
aoqi@0 25
aoqi@0 26 #include "precompiled.hpp"
aoqi@0 27 #include "ci/ciMethod.hpp"
aoqi@0 28 #include "memory/resourceArea.hpp"
aoqi@0 29 #include "oops/method.hpp"
aoqi@0 30 #include "runtime/os.hpp"
aoqi@0 31 #include "runtime/synchronizer.hpp"
aoqi@0 32 #include "runtime/thread.hpp"
aoqi@0 33 #include "shark/llvmHeaders.hpp"
aoqi@0 34 #include "shark/llvmValue.hpp"
aoqi@0 35 #include "shark/sharkBuilder.hpp"
aoqi@0 36 #include "shark/sharkContext.hpp"
aoqi@0 37 #include "shark/sharkRuntime.hpp"
aoqi@0 38 #include "utilities/debug.hpp"
aoqi@0 39
aoqi@0 40 using namespace llvm;
aoqi@0 41
aoqi@0 42 SharkBuilder::SharkBuilder(SharkCodeBuffer* code_buffer)
aoqi@0 43 : IRBuilder<>(SharkContext::current()),
aoqi@0 44 _code_buffer(code_buffer) {
aoqi@0 45 }
aoqi@0 46
aoqi@0 47 // Helpers for accessing structures
aoqi@0 48 Value* SharkBuilder::CreateAddressOfStructEntry(Value* base,
aoqi@0 49 ByteSize offset,
aoqi@0 50 Type* type,
aoqi@0 51 const char* name) {
aoqi@0 52 return CreateBitCast(CreateStructGEP(base, in_bytes(offset)), type, name);
aoqi@0 53 }
aoqi@0 54
aoqi@0 55 LoadInst* SharkBuilder::CreateValueOfStructEntry(Value* base,
aoqi@0 56 ByteSize offset,
aoqi@0 57 Type* type,
aoqi@0 58 const char* name) {
aoqi@0 59 return CreateLoad(
aoqi@0 60 CreateAddressOfStructEntry(
aoqi@0 61 base, offset, PointerType::getUnqual(type)),
aoqi@0 62 name);
aoqi@0 63 }
aoqi@0 64
aoqi@0 65 // Helpers for accessing arrays
aoqi@0 66
aoqi@0 67 LoadInst* SharkBuilder::CreateArrayLength(Value* arrayoop) {
aoqi@0 68 return CreateValueOfStructEntry(
aoqi@0 69 arrayoop, in_ByteSize(arrayOopDesc::length_offset_in_bytes()),
aoqi@0 70 SharkType::jint_type(), "length");
aoqi@0 71 }
aoqi@0 72
aoqi@0 73 Value* SharkBuilder::CreateArrayAddress(Value* arrayoop,
aoqi@0 74 Type* element_type,
aoqi@0 75 int element_bytes,
aoqi@0 76 ByteSize base_offset,
aoqi@0 77 Value* index,
aoqi@0 78 const char* name) {
aoqi@0 79 Value* offset = CreateIntCast(index, SharkType::intptr_type(), false);
aoqi@0 80 if (element_bytes != 1)
aoqi@0 81 offset = CreateShl(
aoqi@0 82 offset,
aoqi@0 83 LLVMValue::intptr_constant(exact_log2(element_bytes)));
aoqi@0 84 offset = CreateAdd(
aoqi@0 85 LLVMValue::intptr_constant(in_bytes(base_offset)), offset);
aoqi@0 86
aoqi@0 87 return CreateIntToPtr(
aoqi@0 88 CreateAdd(CreatePtrToInt(arrayoop, SharkType::intptr_type()), offset),
aoqi@0 89 PointerType::getUnqual(element_type),
aoqi@0 90 name);
aoqi@0 91 }
aoqi@0 92
aoqi@0 93 Value* SharkBuilder::CreateArrayAddress(Value* arrayoop,
aoqi@0 94 BasicType basic_type,
aoqi@0 95 ByteSize base_offset,
aoqi@0 96 Value* index,
aoqi@0 97 const char* name) {
aoqi@0 98 return CreateArrayAddress(
aoqi@0 99 arrayoop,
aoqi@0 100 SharkType::to_arrayType(basic_type),
aoqi@0 101 type2aelembytes(basic_type),
aoqi@0 102 base_offset, index, name);
aoqi@0 103 }
aoqi@0 104
aoqi@0 105 Value* SharkBuilder::CreateArrayAddress(Value* arrayoop,
aoqi@0 106 BasicType basic_type,
aoqi@0 107 Value* index,
aoqi@0 108 const char* name) {
aoqi@0 109 return CreateArrayAddress(
aoqi@0 110 arrayoop, basic_type,
aoqi@0 111 in_ByteSize(arrayOopDesc::base_offset_in_bytes(basic_type)),
aoqi@0 112 index, name);
aoqi@0 113 }
aoqi@0 114
aoqi@0 115 // Helpers for creating intrinsics and external functions.
aoqi@0 116
aoqi@0 117 Type* SharkBuilder::make_type(char type, bool void_ok) {
aoqi@0 118 switch (type) {
aoqi@0 119 // Primitive types
aoqi@0 120 case 'c':
aoqi@0 121 return SharkType::jbyte_type();
aoqi@0 122 case 'i':
aoqi@0 123 return SharkType::jint_type();
aoqi@0 124 case 'l':
aoqi@0 125 return SharkType::jlong_type();
aoqi@0 126 case 'x':
aoqi@0 127 return SharkType::intptr_type();
aoqi@0 128 case 'f':
aoqi@0 129 return SharkType::jfloat_type();
aoqi@0 130 case 'd':
aoqi@0 131 return SharkType::jdouble_type();
aoqi@0 132
aoqi@0 133 // Pointers to primitive types
aoqi@0 134 case 'C':
aoqi@0 135 case 'I':
aoqi@0 136 case 'L':
aoqi@0 137 case 'X':
aoqi@0 138 case 'F':
aoqi@0 139 case 'D':
aoqi@0 140 return PointerType::getUnqual(make_type(tolower(type), false));
aoqi@0 141
aoqi@0 142 // VM objects
aoqi@0 143 case 'T':
aoqi@0 144 return SharkType::thread_type();
aoqi@0 145 case 'M':
aoqi@0 146 return PointerType::getUnqual(SharkType::monitor_type());
aoqi@0 147 case 'O':
aoqi@0 148 return SharkType::oop_type();
aoqi@0 149 case 'K':
aoqi@0 150 return SharkType::klass_type();
aoqi@0 151
aoqi@0 152 // Miscellaneous
aoqi@0 153 case 'v':
aoqi@0 154 assert(void_ok, "should be");
aoqi@0 155 return SharkType::void_type();
aoqi@0 156 case '1':
aoqi@0 157 return SharkType::bit_type();
aoqi@0 158
aoqi@0 159 default:
aoqi@0 160 ShouldNotReachHere();
aoqi@0 161 }
aoqi@0 162 }
aoqi@0 163
aoqi@0 164 FunctionType* SharkBuilder::make_ftype(const char* params,
aoqi@0 165 const char* ret) {
aoqi@0 166 std::vector<Type*> param_types;
aoqi@0 167 for (const char* c = params; *c; c++)
aoqi@0 168 param_types.push_back(make_type(*c, false));
aoqi@0 169
aoqi@0 170 assert(strlen(ret) == 1, "should be");
aoqi@0 171 Type *return_type = make_type(*ret, true);
aoqi@0 172
aoqi@0 173 return FunctionType::get(return_type, param_types, false);
aoqi@0 174 }
aoqi@0 175
aoqi@0 176 // Create an object representing an intrinsic or external function by
aoqi@0 177 // referencing the symbol by name. This is the LLVM-style approach,
aoqi@0 178 // but it cannot be used on functions within libjvm.so its symbols
aoqi@0 179 // are not exported. Note that you cannot make this work simply by
aoqi@0 180 // exporting the symbols, as some symbols have the same names as
aoqi@0 181 // symbols in the standard libraries (eg, atan2, fabs) and would
aoqi@0 182 // obscure them were they visible.
aoqi@0 183 Value* SharkBuilder::make_function(const char* name,
aoqi@0 184 const char* params,
aoqi@0 185 const char* ret) {
aoqi@0 186 return SharkContext::current().get_external(name, make_ftype(params, ret));
aoqi@0 187 }
aoqi@0 188
aoqi@0 189 // Create an object representing an external function by inlining a
aoqi@0 190 // function pointer in the code. This is not the LLVM way, but it's
aoqi@0 191 // the only way to access functions in libjvm.so and functions like
aoqi@0 192 // __kernel_dmb on ARM which is accessed via an absolute address.
aoqi@0 193 Value* SharkBuilder::make_function(address func,
aoqi@0 194 const char* params,
aoqi@0 195 const char* ret) {
aoqi@0 196 return CreateIntToPtr(
aoqi@0 197 LLVMValue::intptr_constant((intptr_t) func),
aoqi@0 198 PointerType::getUnqual(make_ftype(params, ret)));
aoqi@0 199 }
aoqi@0 200
aoqi@0 201 // VM calls
aoqi@0 202
aoqi@0 203 Value* SharkBuilder::find_exception_handler() {
aoqi@0 204 return make_function(
aoqi@0 205 (address) SharkRuntime::find_exception_handler, "TIi", "i");
aoqi@0 206 }
aoqi@0 207
aoqi@0 208 Value* SharkBuilder::monitorenter() {
aoqi@0 209 return make_function((address) SharkRuntime::monitorenter, "TM", "v");
aoqi@0 210 }
aoqi@0 211
aoqi@0 212 Value* SharkBuilder::monitorexit() {
aoqi@0 213 return make_function((address) SharkRuntime::monitorexit, "TM", "v");
aoqi@0 214 }
aoqi@0 215
aoqi@0 216 Value* SharkBuilder::new_instance() {
aoqi@0 217 return make_function((address) SharkRuntime::new_instance, "Ti", "v");
aoqi@0 218 }
aoqi@0 219
aoqi@0 220 Value* SharkBuilder::newarray() {
aoqi@0 221 return make_function((address) SharkRuntime::newarray, "Tii", "v");
aoqi@0 222 }
aoqi@0 223
aoqi@0 224 Value* SharkBuilder::anewarray() {
aoqi@0 225 return make_function((address) SharkRuntime::anewarray, "Tii", "v");
aoqi@0 226 }
aoqi@0 227
aoqi@0 228 Value* SharkBuilder::multianewarray() {
aoqi@0 229 return make_function((address) SharkRuntime::multianewarray, "TiiI", "v");
aoqi@0 230 }
aoqi@0 231
aoqi@0 232 Value* SharkBuilder::register_finalizer() {
aoqi@0 233 return make_function((address) SharkRuntime::register_finalizer, "TO", "v");
aoqi@0 234 }
aoqi@0 235
aoqi@0 236 Value* SharkBuilder::safepoint() {
aoqi@0 237 return make_function((address) SafepointSynchronize::block, "T", "v");
aoqi@0 238 }
aoqi@0 239
aoqi@0 240 Value* SharkBuilder::throw_ArithmeticException() {
aoqi@0 241 return make_function(
aoqi@0 242 (address) SharkRuntime::throw_ArithmeticException, "TCi", "v");
aoqi@0 243 }
aoqi@0 244
aoqi@0 245 Value* SharkBuilder::throw_ArrayIndexOutOfBoundsException() {
aoqi@0 246 return make_function(
aoqi@0 247 (address) SharkRuntime::throw_ArrayIndexOutOfBoundsException, "TCii", "v");
aoqi@0 248 }
aoqi@0 249
aoqi@0 250 Value* SharkBuilder::throw_ClassCastException() {
aoqi@0 251 return make_function(
aoqi@0 252 (address) SharkRuntime::throw_ClassCastException, "TCi", "v");
aoqi@0 253 }
aoqi@0 254
aoqi@0 255 Value* SharkBuilder::throw_NullPointerException() {
aoqi@0 256 return make_function(
aoqi@0 257 (address) SharkRuntime::throw_NullPointerException, "TCi", "v");
aoqi@0 258 }
aoqi@0 259
aoqi@0 260 // High-level non-VM calls
aoqi@0 261
aoqi@0 262 Value* SharkBuilder::f2i() {
aoqi@0 263 return make_function((address) SharedRuntime::f2i, "f", "i");
aoqi@0 264 }
aoqi@0 265
aoqi@0 266 Value* SharkBuilder::f2l() {
aoqi@0 267 return make_function((address) SharedRuntime::f2l, "f", "l");
aoqi@0 268 }
aoqi@0 269
aoqi@0 270 Value* SharkBuilder::d2i() {
aoqi@0 271 return make_function((address) SharedRuntime::d2i, "d", "i");
aoqi@0 272 }
aoqi@0 273
aoqi@0 274 Value* SharkBuilder::d2l() {
aoqi@0 275 return make_function((address) SharedRuntime::d2l, "d", "l");
aoqi@0 276 }
aoqi@0 277
aoqi@0 278 Value* SharkBuilder::is_subtype_of() {
aoqi@0 279 return make_function((address) SharkRuntime::is_subtype_of, "KK", "c");
aoqi@0 280 }
aoqi@0 281
aoqi@0 282 Value* SharkBuilder::current_time_millis() {
aoqi@0 283 return make_function((address) os::javaTimeMillis, "", "l");
aoqi@0 284 }
aoqi@0 285
aoqi@0 286 Value* SharkBuilder::sin() {
aoqi@0 287 return make_function("llvm.sin.f64", "d", "d");
aoqi@0 288 }
aoqi@0 289
aoqi@0 290 Value* SharkBuilder::cos() {
aoqi@0 291 return make_function("llvm.cos.f64", "d", "d");
aoqi@0 292 }
aoqi@0 293
aoqi@0 294 Value* SharkBuilder::tan() {
aoqi@0 295 return make_function((address) ::tan, "d", "d");
aoqi@0 296 }
aoqi@0 297
aoqi@0 298 Value* SharkBuilder::atan2() {
aoqi@0 299 return make_function((address) ::atan2, "dd", "d");
aoqi@0 300 }
aoqi@0 301
aoqi@0 302 Value* SharkBuilder::sqrt() {
aoqi@0 303 return make_function("llvm.sqrt.f64", "d", "d");
aoqi@0 304 }
aoqi@0 305
aoqi@0 306 Value* SharkBuilder::log() {
aoqi@0 307 return make_function("llvm.log.f64", "d", "d");
aoqi@0 308 }
aoqi@0 309
aoqi@0 310 Value* SharkBuilder::log10() {
aoqi@0 311 return make_function("llvm.log10.f64", "d", "d");
aoqi@0 312 }
aoqi@0 313
aoqi@0 314 Value* SharkBuilder::pow() {
aoqi@0 315 return make_function("llvm.pow.f64", "dd", "d");
aoqi@0 316 }
aoqi@0 317
aoqi@0 318 Value* SharkBuilder::exp() {
aoqi@0 319 return make_function("llvm.exp.f64", "d", "d");
aoqi@0 320 }
aoqi@0 321
aoqi@0 322 Value* SharkBuilder::fabs() {
aoqi@0 323 return make_function((address) ::fabs, "d", "d");
aoqi@0 324 }
aoqi@0 325
aoqi@0 326 Value* SharkBuilder::unsafe_field_offset_to_byte_offset() {
aoqi@0 327 extern jlong Unsafe_field_offset_to_byte_offset(jlong field_offset);
aoqi@0 328 return make_function((address) Unsafe_field_offset_to_byte_offset, "l", "l");
aoqi@0 329 }
aoqi@0 330
aoqi@0 331 Value* SharkBuilder::osr_migration_end() {
aoqi@0 332 return make_function((address) SharedRuntime::OSR_migration_end, "C", "v");
aoqi@0 333 }
aoqi@0 334
aoqi@0 335 // Semi-VM calls
aoqi@0 336
aoqi@0 337 Value* SharkBuilder::throw_StackOverflowError() {
aoqi@0 338 return make_function((address) ZeroStack::handle_overflow, "T", "v");
aoqi@0 339 }
aoqi@0 340
aoqi@0 341 Value* SharkBuilder::uncommon_trap() {
aoqi@0 342 return make_function((address) SharkRuntime::uncommon_trap, "Ti", "i");
aoqi@0 343 }
aoqi@0 344
aoqi@0 345 Value* SharkBuilder::deoptimized_entry_point() {
aoqi@0 346 return make_function((address) CppInterpreter::main_loop, "iT", "v");
aoqi@0 347 }
aoqi@0 348
aoqi@0 349 // Native-Java transition
aoqi@0 350
aoqi@0 351 Value* SharkBuilder::check_special_condition_for_native_trans() {
aoqi@0 352 return make_function(
aoqi@0 353 (address) JavaThread::check_special_condition_for_native_trans,
aoqi@0 354 "T", "v");
aoqi@0 355 }
aoqi@0 356
aoqi@0 357 Value* SharkBuilder::frame_address() {
aoqi@0 358 return make_function("llvm.frameaddress", "i", "C");
aoqi@0 359 }
aoqi@0 360
aoqi@0 361 Value* SharkBuilder::memset() {
aoqi@0 362 // LLVM 2.8 added a fifth isVolatile field for memset
aoqi@0 363 // introduced with LLVM r100304
aoqi@0 364 return make_function("llvm.memset.p0i8.i32", "Cciii", "v");
aoqi@0 365 }
aoqi@0 366
aoqi@0 367 Value* SharkBuilder::unimplemented() {
aoqi@0 368 return make_function((address) report_unimplemented, "Ci", "v");
aoqi@0 369 }
aoqi@0 370
aoqi@0 371 Value* SharkBuilder::should_not_reach_here() {
aoqi@0 372 return make_function((address) report_should_not_reach_here, "Ci", "v");
aoqi@0 373 }
aoqi@0 374
aoqi@0 375 Value* SharkBuilder::dump() {
aoqi@0 376 return make_function((address) SharkRuntime::dump, "Cx", "v");
aoqi@0 377 }
aoqi@0 378
aoqi@0 379 // Public interface to low-level non-VM calls
aoqi@0 380
aoqi@0 381 CallInst* SharkBuilder::CreateGetFrameAddress() {
aoqi@0 382 return CreateCall(frame_address(), LLVMValue::jint_constant(0));
aoqi@0 383 }
aoqi@0 384
aoqi@0 385 CallInst* SharkBuilder::CreateMemset(Value* dst,
aoqi@0 386 Value* value,
aoqi@0 387 Value* len,
aoqi@0 388 Value* align) {
aoqi@0 389 return CreateCall5(memset(), dst, value, len, align,
aoqi@0 390 LLVMValue::jint_constant(0));
aoqi@0 391 }
aoqi@0 392
aoqi@0 393 CallInst* SharkBuilder::CreateUnimplemented(const char* file, int line) {
aoqi@0 394 return CreateCall2(
aoqi@0 395 unimplemented(),
aoqi@0 396 CreateIntToPtr(
aoqi@0 397 LLVMValue::intptr_constant((intptr_t) file),
aoqi@0 398 PointerType::getUnqual(SharkType::jbyte_type())),
aoqi@0 399 LLVMValue::jint_constant(line));
aoqi@0 400 }
aoqi@0 401
aoqi@0 402 CallInst* SharkBuilder::CreateShouldNotReachHere(const char* file, int line) {
aoqi@0 403 return CreateCall2(
aoqi@0 404 should_not_reach_here(),
aoqi@0 405 CreateIntToPtr(
aoqi@0 406 LLVMValue::intptr_constant((intptr_t) file),
aoqi@0 407 PointerType::getUnqual(SharkType::jbyte_type())),
aoqi@0 408 LLVMValue::jint_constant(line));
aoqi@0 409 }
aoqi@0 410
aoqi@0 411 #ifndef PRODUCT
aoqi@0 412 CallInst* SharkBuilder::CreateDump(Value* value) {
aoqi@0 413 const char *name;
aoqi@0 414 if (value->hasName())
aoqi@0 415 // XXX this leaks, but it's only debug code
aoqi@0 416 name = strdup(value->getName().str().c_str());
aoqi@0 417 else
aoqi@0 418 name = "unnamed_value";
aoqi@0 419
aoqi@0 420 if (isa<PointerType>(value->getType()))
aoqi@0 421 value = CreatePtrToInt(value, SharkType::intptr_type());
aoqi@0 422 else if (value->getType()->
aoqi@0 423 isIntegerTy()
aoqi@0 424 )
aoqi@0 425 value = CreateIntCast(value, SharkType::intptr_type(), false);
aoqi@0 426 else
aoqi@0 427 Unimplemented();
aoqi@0 428
aoqi@0 429 return CreateCall2(
aoqi@0 430 dump(),
aoqi@0 431 CreateIntToPtr(
aoqi@0 432 LLVMValue::intptr_constant((intptr_t) name),
aoqi@0 433 PointerType::getUnqual(SharkType::jbyte_type())),
aoqi@0 434 value);
aoqi@0 435 }
aoqi@0 436 #endif // PRODUCT
aoqi@0 437
aoqi@0 438 // HotSpot memory barriers
aoqi@0 439
aoqi@0 440 void SharkBuilder::CreateUpdateBarrierSet(BarrierSet* bs, Value* field) {
aoqi@0 441 if (bs->kind() != BarrierSet::CardTableModRef)
aoqi@0 442 Unimplemented();
aoqi@0 443
aoqi@0 444 CreateStore(
aoqi@0 445 LLVMValue::jbyte_constant(CardTableModRefBS::dirty_card),
aoqi@0 446 CreateIntToPtr(
aoqi@0 447 CreateAdd(
aoqi@0 448 LLVMValue::intptr_constant(
aoqi@0 449 (intptr_t) ((CardTableModRefBS *) bs)->byte_map_base),
aoqi@0 450 CreateLShr(
aoqi@0 451 CreatePtrToInt(field, SharkType::intptr_type()),
aoqi@0 452 LLVMValue::intptr_constant(CardTableModRefBS::card_shift))),
aoqi@0 453 PointerType::getUnqual(SharkType::jbyte_type())));
aoqi@0 454 }
aoqi@0 455
aoqi@0 456 // Helpers for accessing the code buffer
aoqi@0 457
aoqi@0 458 Value* SharkBuilder::code_buffer_address(int offset) {
aoqi@0 459 return CreateAdd(
aoqi@0 460 code_buffer()->base_pc(),
aoqi@0 461 LLVMValue::intptr_constant(offset));
aoqi@0 462 }
aoqi@0 463
aoqi@0 464 Value* SharkBuilder::CreateInlineOop(jobject object, const char* name) {
aoqi@0 465 return CreateLoad(
aoqi@0 466 CreateIntToPtr(
aoqi@0 467 code_buffer_address(code_buffer()->inline_oop(object)),
aoqi@0 468 PointerType::getUnqual(SharkType::oop_type())),
aoqi@0 469 name);
aoqi@0 470 }
aoqi@0 471
aoqi@0 472 Value* SharkBuilder::CreateInlineMetadata(Metadata* metadata, llvm::PointerType* type, const char* name) {
aoqi@0 473 assert(metadata != NULL, "inlined metadata must not be NULL");
aoqi@0 474 assert(metadata->is_metaspace_object(), "sanity check");
aoqi@0 475 return CreateLoad(
aoqi@0 476 CreateIntToPtr(
aoqi@0 477 code_buffer_address(code_buffer()->inline_Metadata(metadata)),
aoqi@0 478 PointerType::getUnqual(type)),
aoqi@0 479 name);
aoqi@0 480 }
aoqi@0 481
aoqi@0 482 Value* SharkBuilder::CreateInlineData(void* data,
aoqi@0 483 size_t size,
aoqi@0 484 Type* type,
aoqi@0 485 const char* name) {
aoqi@0 486 return CreateIntToPtr(
aoqi@0 487 code_buffer_address(code_buffer()->inline_data(data, size)),
aoqi@0 488 type,
aoqi@0 489 name);
aoqi@0 490 }
aoqi@0 491
aoqi@0 492 // Helpers for creating basic blocks.
aoqi@0 493
aoqi@0 494 BasicBlock* SharkBuilder::GetBlockInsertionPoint() const {
aoqi@0 495 BasicBlock *cur = GetInsertBlock();
aoqi@0 496
aoqi@0 497 // BasicBlock::Create takes an insertBefore argument, so
aoqi@0 498 // we need to find the block _after_ the current block
aoqi@0 499 Function::iterator iter = cur->getParent()->begin();
aoqi@0 500 Function::iterator end = cur->getParent()->end();
aoqi@0 501 while (iter != end) {
aoqi@0 502 iter++;
aoqi@0 503 if (&*iter == cur) {
aoqi@0 504 iter++;
aoqi@0 505 break;
aoqi@0 506 }
aoqi@0 507 }
aoqi@0 508
aoqi@0 509 if (iter == end)
aoqi@0 510 return NULL;
aoqi@0 511 else
aoqi@0 512 return iter;
aoqi@0 513 }
aoqi@0 514
aoqi@0 515 BasicBlock* SharkBuilder::CreateBlock(BasicBlock* ip, const char* name) const {
aoqi@0 516 return BasicBlock::Create(
aoqi@0 517 SharkContext::current(), name, GetInsertBlock()->getParent(), ip);
aoqi@0 518 }
aoqi@0 519
aoqi@0 520 LoadInst* SharkBuilder::CreateAtomicLoad(Value* ptr, unsigned align, AtomicOrdering ordering, SynchronizationScope synchScope, bool isVolatile, const char* name) {
aoqi@0 521 return Insert(new LoadInst(ptr, name, isVolatile, align, ordering, synchScope), name);
aoqi@0 522 }
aoqi@0 523
aoqi@0 524 StoreInst* SharkBuilder::CreateAtomicStore(Value* val, Value* ptr, unsigned align, AtomicOrdering ordering, SynchronizationScope synchScope, bool isVolatile, const char* name) {
aoqi@0 525 return Insert(new StoreInst(val, ptr, isVolatile, align, ordering, synchScope), name);
aoqi@0 526 }

mercurial