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#ifndef SHARE_VM_SHARK_SHARKBUILDER_HPP
1879N/A#define SHARE_VM_SHARK_SHARKBUILDER_HPP
1879N/A
1879N/A#include "ci/ciType.hpp"
1879N/A#include "memory/barrierSet.hpp"
1879N/A#include "memory/cardTableModRefBS.hpp"
1879N/A#include "shark/llvmHeaders.hpp"
1879N/A#include "shark/llvmValue.hpp"
1879N/A#include "shark/sharkCodeBuffer.hpp"
1879N/A#include "shark/sharkEntry.hpp"
1879N/A#include "shark/sharkType.hpp"
1879N/A#include "shark/sharkValue.hpp"
1879N/A#include "utilities/debug.hpp"
1879N/A#include "utilities/sizes.hpp"
1879N/A
1612N/Aclass SharkBuilder : public llvm::IRBuilder<> {
1612N/A friend class SharkCompileInvariants;
1612N/A
1612N/A public:
1612N/A SharkBuilder(SharkCodeBuffer* code_buffer);
1612N/A
1612N/A // The code buffer we are building into.
1612N/A private:
1612N/A SharkCodeBuffer* _code_buffer;
1612N/A
1612N/A protected:
1612N/A SharkCodeBuffer* code_buffer() const {
1612N/A return _code_buffer;
1612N/A }
1612N/A
1612N/A // Helpers for accessing structures.
1612N/A public:
1612N/A llvm::Value* CreateAddressOfStructEntry(llvm::Value* base,
1612N/A ByteSize offset,
1612N/A const llvm::Type* type,
1612N/A const char *name = "");
1612N/A llvm::LoadInst* CreateValueOfStructEntry(llvm::Value* base,
1612N/A ByteSize offset,
1612N/A const llvm::Type* type,
1612N/A const char *name = "");
1612N/A
1612N/A // Helpers for accessing arrays.
1612N/A public:
1612N/A llvm::LoadInst* CreateArrayLength(llvm::Value* arrayoop);
1612N/A llvm::Value* CreateArrayAddress(llvm::Value* arrayoop,
1612N/A const llvm::Type* element_type,
1612N/A int element_bytes,
1612N/A ByteSize base_offset,
1612N/A llvm::Value* index,
1612N/A const char* name = "");
1612N/A llvm::Value* CreateArrayAddress(llvm::Value* arrayoop,
1612N/A BasicType basic_type,
1612N/A ByteSize base_offset,
1612N/A llvm::Value* index,
1612N/A const char* name = "");
1612N/A llvm::Value* CreateArrayAddress(llvm::Value* arrayoop,
1612N/A BasicType basic_type,
1612N/A llvm::Value* index,
1612N/A const char* name = "");
1612N/A
1612N/A // Helpers for creating intrinsics and external functions.
1612N/A private:
1612N/A static const llvm::Type* make_type(char type, bool void_ok);
1612N/A static const llvm::FunctionType* make_ftype(const char* params,
1612N/A const char* ret);
1612N/A llvm::Value* make_function(const char* name,
1612N/A const char* params,
1612N/A const char* ret);
1612N/A llvm::Value* make_function(address func,
1612N/A const char* params,
1612N/A const char* ret);
1612N/A
1612N/A // Intrinsics and external functions, part 1: VM calls.
1612N/A // These are functions declared with JRT_ENTRY and JRT_EXIT,
1612N/A // macros which flip the thread from _thread_in_Java to
1612N/A // _thread_in_vm and back. VM calls always safepoint, and can
1612N/A // therefore throw exceptions. VM calls require of setup and
1612N/A // teardown, and must be called with SharkTopLevelBlock::call_vm.
1612N/A public:
1612N/A llvm::Value* find_exception_handler();
1612N/A llvm::Value* monitorenter();
1612N/A llvm::Value* monitorexit();
1612N/A llvm::Value* new_instance();
1612N/A llvm::Value* newarray();
1612N/A llvm::Value* anewarray();
1612N/A llvm::Value* multianewarray();
1612N/A llvm::Value* register_finalizer();
1612N/A llvm::Value* safepoint();
1612N/A llvm::Value* throw_ArithmeticException();
1612N/A llvm::Value* throw_ArrayIndexOutOfBoundsException();
1612N/A llvm::Value* throw_ClassCastException();
1612N/A llvm::Value* throw_NullPointerException();
1612N/A
1612N/A // Intrinsics and external functions, part 2: High-level non-VM calls.
1612N/A // These are called like normal functions. The stack is not set
1612N/A // up for walking so they must not safepoint or throw exceptions,
1612N/A // or call anything that might.
1612N/A public:
1612N/A llvm::Value* f2i();
1612N/A llvm::Value* f2l();
1612N/A llvm::Value* d2i();
1612N/A llvm::Value* d2l();
1612N/A llvm::Value* is_subtype_of();
1612N/A llvm::Value* current_time_millis();
1612N/A llvm::Value* sin();
1612N/A llvm::Value* cos();
1612N/A llvm::Value* tan();
1612N/A llvm::Value* atan2();
1612N/A llvm::Value* sqrt();
1612N/A llvm::Value* log();
1612N/A llvm::Value* log10();
1612N/A llvm::Value* pow();
1612N/A llvm::Value* exp();
1612N/A llvm::Value* fabs();
1612N/A llvm::Value* unsafe_field_offset_to_byte_offset();
1612N/A llvm::Value* osr_migration_end();
1612N/A
1612N/A // Intrinsics and external functions, part 3: semi-VM calls.
1612N/A // These are special cases that do VM call stuff but are invoked
1612N/A // as though they were normal calls. This is acceptable so long
1612N/A // as the method that calls them returns to its immediately that
1612N/A // the semi VM call returns.
1612N/A public:
1612N/A llvm::Value* throw_StackOverflowError();
1612N/A llvm::Value* uncommon_trap();
1612N/A llvm::Value* deoptimized_entry_point();
1612N/A
1612N/A // Intrinsics and external functions, part 4: Native-Java transition.
1612N/A // This is a special case in that it is invoked during a thread
1612N/A // state transition. The stack must be set up for walking, and it
1612N/A // may throw exceptions, but the state is _thread_in_native_trans.
1612N/A public:
1612N/A llvm::Value* check_special_condition_for_native_trans();
1612N/A
1612N/A // Intrinsics and external functions, part 5: Low-level non-VM calls.
1612N/A // These have the same caveats as the high-level non-VM calls
1612N/A // above. They are not accessed directly; rather, you should
1612N/A // access them via the various Create* methods below.
1612N/A private:
1612N/A llvm::Value* cmpxchg_int();
1612N/A llvm::Value* cmpxchg_ptr();
1612N/A llvm::Value* frame_address();
1612N/A llvm::Value* memory_barrier();
1612N/A llvm::Value* memset();
1612N/A llvm::Value* unimplemented();
1612N/A llvm::Value* should_not_reach_here();
1612N/A llvm::Value* dump();
1612N/A
1612N/A // Public interface to low-level non-VM calls.
1612N/A public:
1612N/A llvm::CallInst* CreateCmpxchgInt(llvm::Value* exchange_value,
1612N/A llvm::Value* dst,
1612N/A llvm::Value* compare_value);
1612N/A llvm::CallInst* CreateCmpxchgPtr(llvm::Value* exchange_value,
1612N/A llvm::Value* dst,
1612N/A llvm::Value* compare_value);
1612N/A llvm::CallInst* CreateGetFrameAddress();
1612N/A llvm::CallInst* CreateMemoryBarrier(int flags);
1612N/A llvm::CallInst* CreateMemset(llvm::Value* dst,
1612N/A llvm::Value* value,
1612N/A llvm::Value* len,
1612N/A llvm::Value* align);
1612N/A llvm::CallInst* CreateUnimplemented(const char* file, int line);
1612N/A llvm::CallInst* CreateShouldNotReachHere(const char* file, int line);
1612N/A NOT_PRODUCT(llvm::CallInst* CreateDump(llvm::Value* value));
1612N/A
1612N/A // Flags for CreateMemoryBarrier.
1612N/A public:
1612N/A enum BarrierFlags {
1612N/A BARRIER_LOADLOAD = 1,
1612N/A BARRIER_LOADSTORE = 2,
1612N/A BARRIER_STORELOAD = 4,
1612N/A BARRIER_STORESTORE = 8
1612N/A };
1612N/A
1612N/A // HotSpot memory barriers
1612N/A public:
1612N/A void CreateUpdateBarrierSet(BarrierSet* bs, llvm::Value* field);
1612N/A
1612N/A // Helpers for accessing the code buffer.
1612N/A public:
1612N/A llvm::Value* code_buffer_address(int offset);
1612N/A llvm::Value* CreateInlineOop(jobject object, const char* name = "");
1612N/A llvm::Value* CreateInlineOop(ciObject* object, const char* name = "") {
1612N/A return CreateInlineOop(object->constant_encoding(), name);
1612N/A }
1612N/A llvm::Value* CreateInlineData(void* data,
1612N/A size_t size,
1612N/A const llvm::Type* type,
1612N/A const char* name = "");
1612N/A
1612N/A // Helpers for creating basic blocks.
1612N/A // NB don't use unless SharkFunction::CreateBlock is unavailable.
1612N/A // XXX these are hacky and should be removed.
1612N/A public:
1612N/A llvm::BasicBlock* GetBlockInsertionPoint() const;
1612N/A llvm::BasicBlock* CreateBlock(llvm::BasicBlock* ip,
1612N/A const char* name="") const;
1612N/A};
1879N/A
1879N/A#endif // SHARE_VM_SHARK_SHARKBUILDER_HPP