view ports/hotspot/src/share/vm/shark/sharkBuilder.cpp @ 1732:5caf65dd9bd3

2009-03-11 Gary Benson <gbenson@redhat.com> * ports/hotspot/src/share/vm/shark/sharkIntrinsics.hpp: New file. * ports/hotspot/src/share/vm/shark/sharkIntrinsics.cpp: Likewise. * ports/hotspot/src/share/vm/shark/shark_globals.hpp (SharkPerformanceWarnings): New flag. * ports/hotspot/src/share/vm/shark/sharkBuilder.hpp (SharkBuilder::_llvm_cmpxchg_int_fn): New field. (SharkBuilder::_llvm_sin_fn): Likewise. (SharkBuilder::_llvm_cos_fn): Likewise. (SharkBuilder::_llvm_sqrt_fn): Likewise. (SharkBuilder::_llvm_log_fn): Likewise. (SharkBuilder::_llvm_log10_fn): Likewise. (SharkBuilder::_llvm_pow_fn): Likewise. (SharkBuilder::_llvm_exp_fn): Likewise. (SharkBuilder::set_llvm_cmpxchg_int_fn): New method. (SharkBuilder::set_llvm_sin_fn): Likewise. (SharkBuilder::set_llvm_cos_fn): Likewise. (SharkBuilder::set_llvm_sqrt_fn): Likewise. (SharkBuilder::set_llvm_log_fn): Likewise. (SharkBuilder::set_llvm_log10_fn): Likewise. (SharkBuilder::set_llvm_pow_fn): Likewise. (SharkBuilder::set_llvm_exp_fn): Likewise. (SharkBuilder::llvm_cmpxchg_int_fn): Likewise. (SharkBuilder::llvm_sin_fn): Likewise. (SharkBuilder::llvm_cos_fn): Likewise. (SharkBuilder::llvm_sqrt_fn): Likewise. (SharkBuilder::llvm_log_fn): Likewise. (SharkBuilder::llvm_log10_fn): Likewise. (SharkBuilder::llvm_pow_fn): Likewise. (SharkBuilder::llvm_exp_fn): Likewise. (SharkBuilder::CreateCmpxchgInt): Likewise. * ports/hotspot/src/share/vm/shark/sharkBuilder.cpp (SharkBuilder::init_external_functions): Initialize new fields. (SharkBuilder::CreateCmpxchgInt): New method. * ports/hotspot/src/share/vm/shark/sharkRuntime.hpp (SharkRuntime::_current_time_millis): New field. (SharkRuntime::_fabs): Likewise. (SharkRuntime::_tan): Likewise. (SharkRuntime::_atan2): Likewise. (SharkRuntime::_unsafe_field_offset_to_byte_offset): Likewise. (SharkRuntime::current_time_millis): New method. (SharkRuntime::fabs): Likewise. (SharkRuntime::tan): Likewise. (SharkRuntime::atan2): Likewise. (SharkRuntime::unsafe_field_offset_to_byte_offset): Likewise. * ports/hotspot/src/share/vm/shark/sharkRuntime.cpp (SharkRuntime::_current_time_millis): New field. (SharkRuntime::_fabs): Likewise. (SharkRuntime::_tan): Likewise. (SharkRuntime::_atan2): Likewise. (SharkRuntime::_unsafe_field_offset_to_byte_offset): Likewise. (SharkRuntime::initialize): Initialize the above. * ports/hotspot/src/share/vm/shark/sharkBlock.hpp (SharkBlock::SharkBlock): New thread argument. (SharkBlock::_thread): New field. (SharkBlock::thread): New method. * ports/hotspot/src/share/vm/shark/sharkTopLevelBlock.hpp (SharkTopLevelBlock::SharkTopLevelBlock): Pass thread to super. (SharkTopLevelBlock::thread): Removed method. * ports/hotspot/src/share/vm/shark/sharkTopLevelBlock.cpp (SharkTopLevelBlock::do_call): Pass thread to inliner. * ports/hotspot/src/share/vm/shark/sharkFunction.cpp (SharkFunction::initialize): Do the arguments before creating blocks. * ports/hotspot/src/share/vm/shark/sharkInliner.hpp (SharkInliner::attempt_inline): New thread argument. * ports/hotspot/src/share/vm/shark/sharkInliner.cpp (SharkInlineBlock::SharkInlineBlock): Pass thread to super. (SharkInlinerHelper::SharkInlinerHelper): New thread argument. (SharkInlinerHelper::_thread): New field. (SharkInlinerHelper::thread): New method. (SharkInlinerHelper::do_inline): Pass thread to block constructor. (SharkInliner::attempt_inline): Attempt to inline intrinsics. * ports/hotspot/src/share/vm/includeDB_shark: Updated. (transplanted from 1eeb14582f5a679354df249e23e10b2f61b423e8)
author Gary Benson <gbenson@redhat.com>
date Wed, 11 Mar 2009 09:03:27 -0400
parents f7efa3c95c17
children
line wrap: on
line source

/*
 * Copyright 1999-2007 Sun Microsystems, Inc.  All Rights Reserved.
 * Copyright 2008, 2009 Red Hat, Inc.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
 * CA 95054 USA or visit www.sun.com if you need additional information or
 * have any questions.
 *
 */

#include "incls/_precompiled.incl"
#include "incls/_sharkBuilder.cpp.incl"

using namespace llvm;

SharkBuilder::SharkBuilder(SharkCompiler* compiler)
  : IRBuilder<>(),
    _compiler(compiler)
{
  init_external_functions();
}

Constant* SharkBuilder::make_function(intptr_t            addr,
                                      const FunctionType* sig,
                                      const char*         name)
{
  Constant *func = make_pointer(addr, sig);

#ifndef PRODUCT
  ResourceMark rm;

  // Use a trampoline to make dumped code more readable
  Function *trampoline = (Function *) module()->getOrInsertFunction(name, sig);
  SetInsertPoint(BasicBlock::Create("", trampoline));

  Value **args = NEW_RESOURCE_ARRAY(Value*, trampoline->arg_size());
  Function::arg_iterator ai = trampoline->arg_begin();
  for (unsigned i = 0; i < trampoline->arg_size(); i++)
    args[i] = ai++;

  Value *result = CreateCall(func, args, args + trampoline->arg_size());
  if (sig->getReturnType() == Type::VoidTy)
    CreateRetVoid();
  else
    CreateRet(result);

  func = trampoline;
#endif // !PRODUCT

  return func;
}

void SharkBuilder::init_external_functions()
{
  std::vector<const Type*> params;
  params.push_back(PointerType::getUnqual(SharkType::jbyte_type()));
  params.push_back(SharkType::jbyte_type());
  params.push_back(SharkType::jint_type());
  params.push_back(SharkType::jint_type());
  FunctionType *type = FunctionType::get(Type::VoidTy, params, false);
  set_llvm_memset_fn(module()->getOrInsertFunction("llvm.memset.i32", type));

  params.clear();
  params.push_back(PointerType::getUnqual(SharkType::jint_type()));
  params.push_back(SharkType::jint_type());
  params.push_back(SharkType::jint_type());
  type = FunctionType::get(SharkType::jint_type(), params, false);
  set_llvm_cmpxchg_int_fn(
    module()->getOrInsertFunction("llvm.atomic.cmp.swap.i32", type));

  params.clear();
  params.push_back(PointerType::getUnqual(SharkType::intptr_type()));
  params.push_back(SharkType::intptr_type());
  params.push_back(SharkType::intptr_type());
  type = FunctionType::get(SharkType::intptr_type(), params, false);
  set_llvm_cmpxchg_ptr_fn(
    module()->getOrInsertFunction(
      "llvm.atomic.cmp.swap.i" LP64_ONLY("64") NOT_LP64("32"), type));

  params.clear();
  for (int i = 0; i < 5; i++)
    params.push_back(Type::Int1Ty);
  type = FunctionType::get(Type::VoidTy, params, false);
  set_llvm_memory_barrier_fn(
    module()->getOrInsertFunction("llvm.memory.barrier", type));

  params.clear();
  params.push_back(SharkType::jdouble_type());
  type = FunctionType::get(SharkType::jdouble_type(), params, false);
  set_llvm_sin_fn  (module()->getOrInsertFunction("llvm.sin.f64",   type));
  set_llvm_cos_fn  (module()->getOrInsertFunction("llvm.cos.f64",   type));
  set_llvm_sqrt_fn (module()->getOrInsertFunction("llvm.sqrt.f64",  type));
  set_llvm_log_fn  (module()->getOrInsertFunction("llvm.log.f64",   type));
  set_llvm_log10_fn(module()->getOrInsertFunction("llvm.log10.f64", type));
  set_llvm_exp_fn  (module()->getOrInsertFunction("llvm.exp.f64",   type));  

  params.clear();
  params.push_back(SharkType::jdouble_type());
  params.push_back(SharkType::jdouble_type());
  type = FunctionType::get(SharkType::jdouble_type(), params, false);
  set_llvm_pow_fn(module()->getOrInsertFunction("llvm.pow.f64", type));  
}

Function *SharkBuilder::CreateFunction(const char *name)
{
  Function *function = Function::Create(
      SharkType::entry_point_type(),
      GlobalVariable::InternalLinkage,
      name);
  module()->getFunctionList().push_back(function);
  return function;
}

CallInst* SharkBuilder::CreateDump(llvm::Value* value)
{
  Constant *const_name;
  if (value->hasName())
    const_name = ConstantArray::get(value->getName());
  else
    const_name = ConstantArray::get("unnamed_value");

  Value *name = CreatePtrToInt(
    CreateStructGEP(
      new GlobalVariable(
        const_name->getType(),
        true, GlobalValue::InternalLinkage,
        const_name, "dump", module()),
      0),
    SharkType::intptr_type());

  if (isa<PointerType>(value->getType()))
    value = CreatePtrToInt(value, SharkType::intptr_type());
  else if (value->getType()->isInteger())
    value = CreateIntCast(value, SharkType::intptr_type(), false);
  else
    Unimplemented();

  Value *args[] = {name, value};
  return CreateCall2(SharkRuntime::dump(), name, value);
}

CallInst* SharkBuilder::CreateCmpxchgInt(Value* exchange_value,
                                         Value* dst,
                                         Value* compare_value)
{
  return CreateCall3(
    llvm_cmpxchg_int_fn(), dst, compare_value, exchange_value);
}

CallInst* SharkBuilder::CreateCmpxchgPtr(Value* exchange_value,
                                         Value* dst,
                                         Value* compare_value)
{
  return CreateCall3(
    llvm_cmpxchg_ptr_fn(), dst, compare_value, exchange_value);
}

CallInst* SharkBuilder::CreateMemset(Value* dst,
                                     Value* value,
                                     Value* len,
                                     Value* align)
{
  return CreateCall4(llvm_memset_fn(), dst, value, len, align);
}

CallInst* SharkBuilder::CreateUnimplemented(const char* file, int line)
{
  return CreateCall2(
    SharkRuntime::unimplemented(),
    pointer_constant(file),
    LLVMValue::jint_constant(line));
}

CallInst* SharkBuilder::CreateShouldNotReachHere(const char* file, int line)
{
  return CreateCall2(
    SharkRuntime::should_not_reach_here(),
    pointer_constant(file),
    LLVMValue::jint_constant(line));
}

CallInst *SharkBuilder::CreateMemoryBarrier(BarrierFlags flags)
{
  Value *args[] = {
    ConstantInt::get(Type::Int1Ty, (flags & BARRIER_LOADLOAD) ? 1 : 0),
    ConstantInt::get(Type::Int1Ty, (flags & BARRIER_LOADSTORE) ? 1 : 0),
    ConstantInt::get(Type::Int1Ty, (flags & BARRIER_STORELOAD) ? 1 : 0),
    ConstantInt::get(Type::Int1Ty, (flags & BARRIER_STORESTORE) ? 1 : 0),
    ConstantInt::get(Type::Int1Ty, 0)};
  return CreateCall(llvm_memory_barrier_fn(), args, args + 5);
}