1612N/A/*
1879N/A * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
1612N/A * Copyright 2008, 2009, 2010 Red Hat, Inc.
1612N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1612N/A *
1612N/A * This code is free software; you can redistribute it and/or modify it
1612N/A * under the terms of the GNU General Public License version 2 only, as
1612N/A * published by the Free Software Foundation.
1612N/A *
1612N/A * This code is distributed in the hope that it will be useful, but WITHOUT
1612N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1612N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
1612N/A * version 2 for more details (a copy is included in the LICENSE file that
1612N/A * accompanied this code).
1612N/A *
1612N/A * You should have received a copy of the GNU General Public License version
1612N/A * 2 along with this work; if not, write to the Free Software Foundation,
1612N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1612N/A *
1612N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1612N/A * or visit www.oracle.com if you need additional information or have any
1612N/A * questions.
1612N/A *
1612N/A */
1612N/A
1879N/A#include "precompiled.hpp"
1879N/A#include "ci/ciMethod.hpp"
1879N/A#include "memory/resourceArea.hpp"
1879N/A#include "oops/methodOop.hpp"
1879N/A#include "runtime/os.hpp"
1879N/A#include "runtime/synchronizer.hpp"
1879N/A#include "runtime/thread.hpp"
1879N/A#include "shark/llvmHeaders.hpp"
1879N/A#include "shark/llvmValue.hpp"
1879N/A#include "shark/sharkBuilder.hpp"
1879N/A#include "shark/sharkContext.hpp"
1879N/A#include "shark/sharkRuntime.hpp"
1879N/A#include "utilities/debug.hpp"
1612N/A
1612N/Ausing namespace llvm;
1612N/A
1612N/ASharkBuilder::SharkBuilder(SharkCodeBuffer* code_buffer)
1612N/A : IRBuilder<>(SharkContext::current()),
1612N/A _code_buffer(code_buffer) {
1612N/A}
1612N/A
1612N/A// Helpers for accessing structures
1612N/AValue* SharkBuilder::CreateAddressOfStructEntry(Value* base,
1612N/A ByteSize offset,
1612N/A const Type* type,
1612N/A const char* name) {
1612N/A return CreateBitCast(CreateStructGEP(base, in_bytes(offset)), type, name);
1612N/A}
1612N/A
1612N/ALoadInst* SharkBuilder::CreateValueOfStructEntry(Value* base,
1612N/A ByteSize offset,
1612N/A const Type* type,
1612N/A const char* name) {
1612N/A return CreateLoad(
1612N/A CreateAddressOfStructEntry(
1612N/A base, offset, PointerType::getUnqual(type)),
1612N/A name);
1612N/A}
1612N/A
1612N/A// Helpers for accessing arrays
1612N/A
1612N/ALoadInst* SharkBuilder::CreateArrayLength(Value* arrayoop) {
1612N/A return CreateValueOfStructEntry(
1612N/A arrayoop, in_ByteSize(arrayOopDesc::length_offset_in_bytes()),
1612N/A SharkType::jint_type(), "length");
1612N/A}
1612N/A
1612N/AValue* SharkBuilder::CreateArrayAddress(Value* arrayoop,
1612N/A const Type* element_type,
1612N/A int element_bytes,
1612N/A ByteSize base_offset,
1612N/A Value* index,
1612N/A const char* name) {
1612N/A Value* offset = CreateIntCast(index, SharkType::intptr_type(), false);
1612N/A if (element_bytes != 1)
1612N/A offset = CreateShl(
1612N/A offset,
1612N/A LLVMValue::intptr_constant(exact_log2(element_bytes)));
1612N/A offset = CreateAdd(
1612N/A LLVMValue::intptr_constant(in_bytes(base_offset)), offset);
1612N/A
1612N/A return CreateIntToPtr(
1612N/A CreateAdd(CreatePtrToInt(arrayoop, SharkType::intptr_type()), offset),
1612N/A PointerType::getUnqual(element_type),
1612N/A name);
1612N/A}
1612N/A
1612N/AValue* SharkBuilder::CreateArrayAddress(Value* arrayoop,
1612N/A BasicType basic_type,
1612N/A ByteSize base_offset,
1612N/A Value* index,
1612N/A const char* name) {
1612N/A return CreateArrayAddress(
1612N/A arrayoop,
1612N/A SharkType::to_arrayType(basic_type),
1612N/A type2aelembytes(basic_type),
1612N/A base_offset, index, name);
1612N/A}
1612N/A
1612N/AValue* SharkBuilder::CreateArrayAddress(Value* arrayoop,
1612N/A BasicType basic_type,
1612N/A Value* index,
1612N/A const char* name) {
1612N/A return CreateArrayAddress(
1612N/A arrayoop, basic_type,
1612N/A in_ByteSize(arrayOopDesc::base_offset_in_bytes(basic_type)),
1612N/A index, name);
1612N/A}
1612N/A
1612N/A// Helpers for creating intrinsics and external functions.
1612N/A
1612N/Aconst Type* SharkBuilder::make_type(char type, bool void_ok) {
1612N/A switch (type) {
1612N/A // Primitive types
1612N/A case 'c':
1612N/A return SharkType::jbyte_type();
1612N/A case 'i':
1612N/A return SharkType::jint_type();
1612N/A case 'l':
1612N/A return SharkType::jlong_type();
1612N/A case 'x':
1612N/A return SharkType::intptr_type();
1612N/A case 'f':
1612N/A return SharkType::jfloat_type();
1612N/A case 'd':
1612N/A return SharkType::jdouble_type();
1612N/A
1612N/A // Pointers to primitive types
1612N/A case 'C':
1612N/A case 'I':
1612N/A case 'L':
1612N/A case 'X':
1612N/A case 'F':
1612N/A case 'D':
1612N/A return PointerType::getUnqual(make_type(tolower(type), false));
1612N/A
1612N/A // VM objects
1612N/A case 'T':
1612N/A return SharkType::thread_type();
1612N/A case 'M':
1612N/A return PointerType::getUnqual(SharkType::monitor_type());
1612N/A case 'O':
1612N/A return SharkType::oop_type();
1612N/A
1612N/A // Miscellaneous
1612N/A case 'v':
1612N/A assert(void_ok, "should be");
1612N/A return SharkType::void_type();
1612N/A case '1':
1612N/A return SharkType::bit_type();
1612N/A
1612N/A default:
1612N/A ShouldNotReachHere();
1612N/A }
1612N/A}
1612N/A
1612N/Aconst FunctionType* SharkBuilder::make_ftype(const char* params,
1612N/A const char* ret) {
1612N/A std::vector<const Type*> param_types;
1612N/A for (const char* c = params; *c; c++)
1612N/A param_types.push_back(make_type(*c, false));
1612N/A
1612N/A assert(strlen(ret) == 1, "should be");
1612N/A const Type *return_type = make_type(*ret, true);
1612N/A
1612N/A return FunctionType::get(return_type, param_types, false);
1612N/A}
1612N/A
1612N/A// Create an object representing an intrinsic or external function by
1612N/A// referencing the symbol by name. This is the LLVM-style approach,
1612N/A// but it cannot be used on functions within libjvm.so its symbols
1612N/A// are not exported. Note that you cannot make this work simply by
1612N/A// exporting the symbols, as some symbols have the same names as
1612N/A// symbols in the standard libraries (eg, atan2, fabs) and would
1612N/A// obscure them were they visible.
1612N/AValue* SharkBuilder::make_function(const char* name,
1612N/A const char* params,
1612N/A const char* ret) {
1612N/A return SharkContext::current().get_external(name, make_ftype(params, ret));
1612N/A}
1612N/A
1612N/A// Create an object representing an external function by inlining a
1612N/A// function pointer in the code. This is not the LLVM way, but it's
1612N/A// the only way to access functions in libjvm.so and functions like
1612N/A// __kernel_dmb on ARM which is accessed via an absolute address.
1612N/AValue* SharkBuilder::make_function(address func,
1612N/A const char* params,
1612N/A const char* ret) {
1612N/A return CreateIntToPtr(
1612N/A LLVMValue::intptr_constant((intptr_t) func),
1612N/A PointerType::getUnqual(make_ftype(params, ret)));
1612N/A}
1612N/A
1612N/A// VM calls
1612N/A
1612N/AValue* SharkBuilder::find_exception_handler() {
1612N/A return make_function(
1612N/A (address) SharkRuntime::find_exception_handler, "TIi", "i");
1612N/A}
1612N/A
1612N/AValue* SharkBuilder::monitorenter() {
1612N/A return make_function((address) SharkRuntime::monitorenter, "TM", "v");
1612N/A}
1612N/A
1612N/AValue* SharkBuilder::monitorexit() {
1612N/A return make_function((address) SharkRuntime::monitorexit, "TM", "v");
1612N/A}
1612N/A
1612N/AValue* SharkBuilder::new_instance() {
1612N/A return make_function((address) SharkRuntime::new_instance, "Ti", "v");
1612N/A}
1612N/A
1612N/AValue* SharkBuilder::newarray() {
1612N/A return make_function((address) SharkRuntime::newarray, "Tii", "v");
1612N/A}
1612N/A
1612N/AValue* SharkBuilder::anewarray() {
1612N/A return make_function((address) SharkRuntime::anewarray, "Tii", "v");
1612N/A}
1612N/A
1612N/AValue* SharkBuilder::multianewarray() {
1612N/A return make_function((address) SharkRuntime::multianewarray, "TiiI", "v");
1612N/A}
1612N/A
1612N/AValue* SharkBuilder::register_finalizer() {
1612N/A return make_function((address) SharkRuntime::register_finalizer, "TO", "v");
1612N/A}
1612N/A
1612N/AValue* SharkBuilder::safepoint() {
1612N/A return make_function((address) SafepointSynchronize::block, "T", "v");
1612N/A}
1612N/A
1612N/AValue* SharkBuilder::throw_ArithmeticException() {
1612N/A return make_function(
1612N/A (address) SharkRuntime::throw_ArithmeticException, "TCi", "v");
1612N/A}
1612N/A
1612N/AValue* SharkBuilder::throw_ArrayIndexOutOfBoundsException() {
1612N/A return make_function(
1612N/A (address) SharkRuntime::throw_ArrayIndexOutOfBoundsException, "TCii", "v");
1612N/A}
1612N/A
1612N/AValue* SharkBuilder::throw_ClassCastException() {
1612N/A return make_function(
1612N/A (address) SharkRuntime::throw_ClassCastException, "TCi", "v");
1612N/A}
1612N/A
1612N/AValue* SharkBuilder::throw_NullPointerException() {
1612N/A return make_function(
1612N/A (address) SharkRuntime::throw_NullPointerException, "TCi", "v");
1612N/A}
1612N/A
1612N/A// High-level non-VM calls
1612N/A
1612N/AValue* SharkBuilder::f2i() {
1612N/A return make_function((address) SharedRuntime::f2i, "f", "i");
1612N/A}
1612N/A
1612N/AValue* SharkBuilder::f2l() {
1612N/A return make_function((address) SharedRuntime::f2l, "f", "l");
1612N/A}
1612N/A
1612N/AValue* SharkBuilder::d2i() {
1612N/A return make_function((address) SharedRuntime::d2i, "d", "i");
1612N/A}
1612N/A
1612N/AValue* SharkBuilder::d2l() {
1612N/A return make_function((address) SharedRuntime::d2l, "d", "l");
1612N/A}
1612N/A
1612N/AValue* SharkBuilder::is_subtype_of() {
1612N/A return make_function((address) SharkRuntime::is_subtype_of, "OO", "c");
1612N/A}
1612N/A
1612N/AValue* SharkBuilder::current_time_millis() {
1612N/A return make_function((address) os::javaTimeMillis, "", "l");
1612N/A}
1612N/A
1612N/AValue* SharkBuilder::sin() {
1612N/A return make_function("llvm.sin.f64", "d", "d");
1612N/A}
1612N/A
1612N/AValue* SharkBuilder::cos() {
1612N/A return make_function("llvm.cos.f64", "d", "d");
1612N/A}
1612N/A
1612N/AValue* SharkBuilder::tan() {
1612N/A return make_function((address) ::tan, "d", "d");
1612N/A}
1612N/A
1612N/AValue* SharkBuilder::atan2() {
1612N/A return make_function((address) ::atan2, "dd", "d");
1612N/A}
1612N/A
1612N/AValue* SharkBuilder::sqrt() {
1612N/A return make_function("llvm.sqrt.f64", "d", "d");
1612N/A}
1612N/A
1612N/AValue* SharkBuilder::log() {
1612N/A return make_function("llvm.log.f64", "d", "d");
1612N/A}
1612N/A
1612N/AValue* SharkBuilder::log10() {
1612N/A return make_function("llvm.log10.f64", "d", "d");
1612N/A}
1612N/A
1612N/AValue* SharkBuilder::pow() {
1612N/A return make_function("llvm.pow.f64", "dd", "d");
1612N/A}
1612N/A
1612N/AValue* SharkBuilder::exp() {
1612N/A return make_function("llvm.exp.f64", "d", "d");
1612N/A}
1612N/A
1612N/AValue* SharkBuilder::fabs() {
1612N/A return make_function((address) ::fabs, "d", "d");
1612N/A}
1612N/A
1612N/AValue* SharkBuilder::unsafe_field_offset_to_byte_offset() {
1612N/A extern jlong Unsafe_field_offset_to_byte_offset(jlong field_offset);
1612N/A return make_function((address) Unsafe_field_offset_to_byte_offset, "l", "l");
1612N/A}
1612N/A
1612N/AValue* SharkBuilder::osr_migration_end() {
1612N/A return make_function((address) SharedRuntime::OSR_migration_end, "C", "v");
1612N/A}
1612N/A
1612N/A// Semi-VM calls
1612N/A
1612N/AValue* SharkBuilder::throw_StackOverflowError() {
1612N/A return make_function((address) ZeroStack::handle_overflow, "T", "v");
1612N/A}
1612N/A
1612N/AValue* SharkBuilder::uncommon_trap() {
1612N/A return make_function((address) SharkRuntime::uncommon_trap, "Ti", "i");
1612N/A}
1612N/A
1612N/AValue* SharkBuilder::deoptimized_entry_point() {
1612N/A return make_function((address) CppInterpreter::main_loop, "iT", "v");
1612N/A}
1612N/A
1612N/A// Native-Java transition
1612N/A
1612N/AValue* SharkBuilder::check_special_condition_for_native_trans() {
1612N/A return make_function(
1612N/A (address) JavaThread::check_special_condition_for_native_trans,
1612N/A "T", "v");
1612N/A}
1612N/A
1612N/A// Low-level non-VM calls
1612N/A
1612N/A// The ARM-specific code here is to work around unimplemented
1612N/A// atomic exchange and memory barrier intrinsics in LLVM.
1612N/A//
1612N/A// Delegating to external functions for these would normally
1612N/A// incur a speed penalty, but Linux on ARM is a special case
1612N/A// in that atomic operations on that platform are handled by
1612N/A// external functions anyway. It would be *preferable* for
1612N/A// the calls to be hidden away in LLVM, but it's not hurting
1612N/A// performance so having the calls here is acceptable.
1612N/A//
1612N/A// If you are building Shark on a platform without atomic
1612N/A// exchange and/or memory barrier intrinsics then it is only
1612N/A// acceptable to mimic this approach if your platform cannot
1612N/A// perform these operations without delegating to a function.
1612N/A
1612N/A#ifdef ARM
1612N/Astatic jint zero_cmpxchg_int(volatile jint *ptr, jint oldval, jint newval) {
1612N/A return Atomic::cmpxchg(newval, ptr, oldval);
1612N/A}
1612N/A#endif // ARM
1612N/A
1612N/AValue* SharkBuilder::cmpxchg_int() {
1612N/A return make_function(
1612N/A#ifdef ARM
1612N/A (address) zero_cmpxchg_int,
1612N/A#else
1612N/A "llvm.atomic.cmp.swap.i32.p0i32",
1612N/A#endif // ARM
1612N/A "Iii", "i");
1612N/A}
1612N/A
1612N/A#ifdef ARM
1612N/Astatic intptr_t zero_cmpxchg_ptr(volatile intptr_t* ptr,
1612N/A intptr_t oldval,
1612N/A intptr_t newval) {
1612N/A return Atomic::cmpxchg_ptr(newval, ptr, oldval);
1612N/A}
1612N/A#endif // ARM
1612N/A
1612N/AValue* SharkBuilder::cmpxchg_ptr() {
1612N/A return make_function(
1612N/A#ifdef ARM
1612N/A (address) zero_cmpxchg_ptr,
1612N/A#else
1612N/A "llvm.atomic.cmp.swap.i" LP64_ONLY("64") NOT_LP64("32") ".p0i" LP64_ONLY("64") NOT_LP64("32"),
1612N/A#endif // ARM
1612N/A "Xxx", "x");
1612N/A}
1612N/A
1612N/AValue* SharkBuilder::frame_address() {
1612N/A return make_function("llvm.frameaddress", "i", "C");
1612N/A}
1612N/A
1612N/AValue* SharkBuilder::memory_barrier() {
1612N/A return make_function(
1612N/A#ifdef ARM
1612N/A (address) 0xffff0fa0, // __kernel_dmb
1612N/A#else
1612N/A "llvm.memory.barrier",
1612N/A#endif // ARM
1612N/A "11111", "v");
1612N/A}
1612N/A
1612N/AValue* SharkBuilder::memset() {
1612N/A#if SHARK_LLVM_VERSION >= 28
1612N/A // LLVM 2.8 added a fifth isVolatile field for memset
1612N/A // introduced with LLVM r100304
1612N/A return make_function("llvm.memset.i32", "Cciii", "v");
1612N/A#else
1612N/A return make_function("llvm.memset.i32", "Ccii", "v");
1612N/A#endif
1612N/A}
1612N/A
1612N/AValue* SharkBuilder::unimplemented() {
1612N/A return make_function((address) report_unimplemented, "Ci", "v");
1612N/A}
1612N/A
1612N/AValue* SharkBuilder::should_not_reach_here() {
1612N/A return make_function((address) report_should_not_reach_here, "Ci", "v");
1612N/A}
1612N/A
1612N/AValue* SharkBuilder::dump() {
1612N/A return make_function((address) SharkRuntime::dump, "Cx", "v");
1612N/A}
1612N/A
1612N/A// Public interface to low-level non-VM calls
1612N/A
1612N/ACallInst* SharkBuilder::CreateCmpxchgInt(Value* exchange_value,
1612N/A Value* dst,
1612N/A Value* compare_value) {
1612N/A return CreateCall3(cmpxchg_int(), dst, compare_value, exchange_value);
1612N/A}
1612N/A
1612N/ACallInst* SharkBuilder::CreateCmpxchgPtr(Value* exchange_value,
1612N/A Value* dst,
1612N/A Value* compare_value) {
1612N/A return CreateCall3(cmpxchg_ptr(), dst, compare_value, exchange_value);
1612N/A}
1612N/A
1612N/ACallInst* SharkBuilder::CreateGetFrameAddress() {
1612N/A return CreateCall(frame_address(), LLVMValue::jint_constant(0));
1612N/A}
1612N/A
1612N/ACallInst *SharkBuilder::CreateMemoryBarrier(int flags) {
1612N/A Value *args[] = {
1612N/A LLVMValue::bit_constant((flags & BARRIER_LOADLOAD) ? 1 : 0),
1612N/A LLVMValue::bit_constant((flags & BARRIER_LOADSTORE) ? 1 : 0),
1612N/A LLVMValue::bit_constant((flags & BARRIER_STORELOAD) ? 1 : 0),
1612N/A LLVMValue::bit_constant((flags & BARRIER_STORESTORE) ? 1 : 0),
1612N/A LLVMValue::bit_constant(1)};
1612N/A
1612N/A return CreateCall(memory_barrier(), args, args + 5);
1612N/A}
1612N/A
1612N/ACallInst* SharkBuilder::CreateMemset(Value* dst,
1612N/A Value* value,
1612N/A Value* len,
1612N/A Value* align) {
1612N/A#if SHARK_LLVM_VERSION >= 28
1612N/A return CreateCall5(memset(), dst, value, len, align,
1612N/A LLVMValue::jint_constant(0));
1612N/A#else
1612N/A return CreateCall4(memset(), dst, value, len, align);
1612N/A#endif
1612N/A}
1612N/A
1612N/ACallInst* SharkBuilder::CreateUnimplemented(const char* file, int line) {
1612N/A return CreateCall2(
1612N/A unimplemented(),
1612N/A CreateIntToPtr(
1612N/A LLVMValue::intptr_constant((intptr_t) file),
1612N/A PointerType::getUnqual(SharkType::jbyte_type())),
1612N/A LLVMValue::jint_constant(line));
1612N/A}
1612N/A
1612N/ACallInst* SharkBuilder::CreateShouldNotReachHere(const char* file, int line) {
1612N/A return CreateCall2(
1612N/A should_not_reach_here(),
1612N/A CreateIntToPtr(
1612N/A LLVMValue::intptr_constant((intptr_t) file),
1612N/A PointerType::getUnqual(SharkType::jbyte_type())),
1612N/A LLVMValue::jint_constant(line));
1612N/A}
1612N/A
1612N/A#ifndef PRODUCT
1612N/ACallInst* SharkBuilder::CreateDump(Value* value) {
1612N/A const char *name;
1612N/A if (value->hasName())
1612N/A // XXX this leaks, but it's only debug code
1612N/A name = strdup(value->getName().str().c_str());
1612N/A else
1612N/A name = "unnamed_value";
1612N/A
1612N/A if (isa<PointerType>(value->getType()))
1612N/A value = CreatePtrToInt(value, SharkType::intptr_type());
1612N/A else if (value->getType()->
1612N/A#if SHARK_LLVM_VERSION >= 27
1612N/A isIntegerTy()
1612N/A#else
1612N/A isInteger()
1612N/A#endif
1612N/A )
1612N/A value = CreateIntCast(value, SharkType::intptr_type(), false);
1612N/A else
1612N/A Unimplemented();
1612N/A
1612N/A return CreateCall2(
1612N/A dump(),
1612N/A CreateIntToPtr(
1612N/A LLVMValue::intptr_constant((intptr_t) name),
1612N/A PointerType::getUnqual(SharkType::jbyte_type())),
1612N/A value);
1612N/A}
1612N/A#endif // PRODUCT
1612N/A
1612N/A// HotSpot memory barriers
1612N/A
1612N/Avoid SharkBuilder::CreateUpdateBarrierSet(BarrierSet* bs, Value* field) {
1612N/A if (bs->kind() != BarrierSet::CardTableModRef)
1612N/A Unimplemented();
1612N/A
1612N/A CreateStore(
1612N/A LLVMValue::jbyte_constant(CardTableModRefBS::dirty_card),
1612N/A CreateIntToPtr(
1612N/A CreateAdd(
1612N/A LLVMValue::intptr_constant(
1612N/A (intptr_t) ((CardTableModRefBS *) bs)->byte_map_base),
1612N/A CreateLShr(
1612N/A CreatePtrToInt(field, SharkType::intptr_type()),
1612N/A LLVMValue::intptr_constant(CardTableModRefBS::card_shift))),
1612N/A PointerType::getUnqual(SharkType::jbyte_type())));
1612N/A}
1612N/A
1612N/A// Helpers for accessing the code buffer
1612N/A
1612N/AValue* SharkBuilder::code_buffer_address(int offset) {
1612N/A return CreateAdd(
1612N/A code_buffer()->base_pc(),
1612N/A LLVMValue::intptr_constant(offset));
1612N/A}
1612N/A
1612N/AValue* SharkBuilder::CreateInlineOop(jobject object, const char* name) {
1612N/A return CreateLoad(
1612N/A CreateIntToPtr(
1612N/A code_buffer_address(code_buffer()->inline_oop(object)),
1612N/A PointerType::getUnqual(SharkType::oop_type())),
1612N/A name);
1612N/A}
1612N/A
1612N/AValue* SharkBuilder::CreateInlineData(void* data,
1612N/A size_t size,
1612N/A const Type* type,
1612N/A const char* name) {
1612N/A return CreateIntToPtr(
1612N/A code_buffer_address(code_buffer()->inline_data(data, size)),
1612N/A type,
1612N/A name);
1612N/A}
1612N/A
1612N/A// Helpers for creating basic blocks.
1612N/A
1612N/ABasicBlock* SharkBuilder::GetBlockInsertionPoint() const {
1612N/A BasicBlock *cur = GetInsertBlock();
1612N/A
1612N/A // BasicBlock::Create takes an insertBefore argument, so
1612N/A // we need to find the block _after_ the current block
1612N/A Function::iterator iter = cur->getParent()->begin();
1612N/A Function::iterator end = cur->getParent()->end();
1612N/A while (iter != end) {
1612N/A iter++;
1612N/A if (&*iter == cur) {
1612N/A iter++;
1612N/A break;
1612N/A }
1612N/A }
1612N/A
1612N/A if (iter == end)
1612N/A return NULL;
1612N/A else
1612N/A return iter;
1612N/A}
1612N/A
1612N/ABasicBlock* SharkBuilder::CreateBlock(BasicBlock* ip, const char* name) const {
1612N/A return BasicBlock::Create(
1612N/A SharkContext::current(), name, GetInsertBlock()->getParent(), ip);
1612N/A}