twisti@2047: /* stefank@2314: * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. twisti@2047: * Copyright 2008, 2009, 2010 Red Hat, Inc. twisti@2047: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. twisti@2047: * twisti@2047: * This code is free software; you can redistribute it and/or modify it twisti@2047: * under the terms of the GNU General Public License version 2 only, as twisti@2047: * published by the Free Software Foundation. twisti@2047: * twisti@2047: * This code is distributed in the hope that it will be useful, but WITHOUT twisti@2047: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or twisti@2047: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License twisti@2047: * version 2 for more details (a copy is included in the LICENSE file that twisti@2047: * accompanied this code). twisti@2047: * twisti@2047: * You should have received a copy of the GNU General Public License version twisti@2047: * 2 along with this work; if not, write to the Free Software Foundation, twisti@2047: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. twisti@2047: * twisti@2047: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA twisti@2047: * or visit www.oracle.com if you need additional information or have any twisti@2047: * questions. twisti@2047: * twisti@2047: */ twisti@2047: stefank@2314: #ifndef SHARE_VM_SHARK_SHARKBUILDER_HPP stefank@2314: #define SHARE_VM_SHARK_SHARKBUILDER_HPP stefank@2314: stefank@2314: #include "ci/ciType.hpp" stefank@2314: #include "memory/barrierSet.hpp" stefank@2314: #include "memory/cardTableModRefBS.hpp" stefank@2314: #include "shark/llvmHeaders.hpp" stefank@2314: #include "shark/llvmValue.hpp" stefank@2314: #include "shark/sharkCodeBuffer.hpp" stefank@2314: #include "shark/sharkEntry.hpp" stefank@2314: #include "shark/sharkType.hpp" stefank@2314: #include "shark/sharkValue.hpp" stefank@2314: #include "utilities/debug.hpp" stefank@2314: #include "utilities/sizes.hpp" stefank@2314: twisti@2047: class SharkBuilder : public llvm::IRBuilder<> { twisti@2047: friend class SharkCompileInvariants; twisti@2047: twisti@2047: public: twisti@2047: SharkBuilder(SharkCodeBuffer* code_buffer); twisti@2047: twisti@2047: // The code buffer we are building into. twisti@2047: private: twisti@2047: SharkCodeBuffer* _code_buffer; twisti@2047: twisti@2047: protected: twisti@2047: SharkCodeBuffer* code_buffer() const { twisti@2047: return _code_buffer; twisti@2047: } twisti@2047: twisti@4314: public: twisti@4314: llvm::LoadInst* CreateAtomicLoad(llvm::Value* ptr, twisti@4314: unsigned align = HeapWordSize, twisti@4314: llvm::AtomicOrdering ordering = llvm::SequentiallyConsistent, twisti@4314: llvm::SynchronizationScope synchScope = llvm::CrossThread, twisti@4314: bool isVolatile = true, twisti@4314: const char *name = ""); twisti@4314: llvm::StoreInst* CreateAtomicStore(llvm::Value *val, twisti@4314: llvm::Value *ptr, twisti@4314: unsigned align = HeapWordSize, twisti@4314: llvm::AtomicOrdering ordering = llvm::SequentiallyConsistent, twisti@4314: llvm::SynchronizationScope SynchScope = llvm::CrossThread, twisti@4314: bool isVolatile = true, twisti@4314: const char *name = ""); twisti@4314: twisti@2047: // Helpers for accessing structures. twisti@2047: public: twisti@2047: llvm::Value* CreateAddressOfStructEntry(llvm::Value* base, twisti@2047: ByteSize offset, twisti@4314: llvm::Type* type, twisti@2047: const char *name = ""); twisti@2047: llvm::LoadInst* CreateValueOfStructEntry(llvm::Value* base, twisti@2047: ByteSize offset, twisti@4314: llvm::Type* type, twisti@2047: const char *name = ""); twisti@2047: twisti@2047: // Helpers for accessing arrays. twisti@2047: public: twisti@2047: llvm::LoadInst* CreateArrayLength(llvm::Value* arrayoop); twisti@2047: llvm::Value* CreateArrayAddress(llvm::Value* arrayoop, twisti@4314: llvm::Type* element_type, twisti@2047: int element_bytes, twisti@2047: ByteSize base_offset, twisti@2047: llvm::Value* index, twisti@2047: const char* name = ""); twisti@2047: llvm::Value* CreateArrayAddress(llvm::Value* arrayoop, twisti@2047: BasicType basic_type, twisti@2047: ByteSize base_offset, twisti@2047: llvm::Value* index, twisti@2047: const char* name = ""); twisti@2047: llvm::Value* CreateArrayAddress(llvm::Value* arrayoop, twisti@2047: BasicType basic_type, twisti@2047: llvm::Value* index, twisti@2047: const char* name = ""); twisti@2047: twisti@2047: // Helpers for creating intrinsics and external functions. twisti@2047: private: twisti@4314: static llvm::Type* make_type(char type, bool void_ok); twisti@4314: static llvm::FunctionType* make_ftype(const char* params, twisti@2047: const char* ret); twisti@2047: llvm::Value* make_function(const char* name, twisti@2047: const char* params, twisti@2047: const char* ret); twisti@2047: llvm::Value* make_function(address func, twisti@2047: const char* params, twisti@2047: const char* ret); twisti@2047: twisti@2047: // Intrinsics and external functions, part 1: VM calls. twisti@2047: // These are functions declared with JRT_ENTRY and JRT_EXIT, twisti@2047: // macros which flip the thread from _thread_in_Java to twisti@2047: // _thread_in_vm and back. VM calls always safepoint, and can twisti@2047: // therefore throw exceptions. VM calls require of setup and twisti@2047: // teardown, and must be called with SharkTopLevelBlock::call_vm. twisti@2047: public: twisti@2047: llvm::Value* find_exception_handler(); twisti@2047: llvm::Value* monitorenter(); twisti@2047: llvm::Value* monitorexit(); twisti@2047: llvm::Value* new_instance(); twisti@2047: llvm::Value* newarray(); twisti@2047: llvm::Value* anewarray(); twisti@2047: llvm::Value* multianewarray(); twisti@2047: llvm::Value* register_finalizer(); twisti@2047: llvm::Value* safepoint(); twisti@2047: llvm::Value* throw_ArithmeticException(); twisti@2047: llvm::Value* throw_ArrayIndexOutOfBoundsException(); twisti@2047: llvm::Value* throw_ClassCastException(); twisti@2047: llvm::Value* throw_NullPointerException(); twisti@2047: twisti@2047: // Intrinsics and external functions, part 2: High-level non-VM calls. twisti@2047: // These are called like normal functions. The stack is not set twisti@2047: // up for walking so they must not safepoint or throw exceptions, twisti@2047: // or call anything that might. twisti@2047: public: twisti@2047: llvm::Value* f2i(); twisti@2047: llvm::Value* f2l(); twisti@2047: llvm::Value* d2i(); twisti@2047: llvm::Value* d2l(); twisti@2047: llvm::Value* is_subtype_of(); twisti@2047: llvm::Value* current_time_millis(); twisti@2047: llvm::Value* sin(); twisti@2047: llvm::Value* cos(); twisti@2047: llvm::Value* tan(); twisti@2047: llvm::Value* atan2(); twisti@2047: llvm::Value* sqrt(); twisti@2047: llvm::Value* log(); twisti@2047: llvm::Value* log10(); twisti@2047: llvm::Value* pow(); twisti@2047: llvm::Value* exp(); twisti@2047: llvm::Value* fabs(); twisti@2047: llvm::Value* unsafe_field_offset_to_byte_offset(); twisti@2047: llvm::Value* osr_migration_end(); twisti@2047: twisti@2047: // Intrinsics and external functions, part 3: semi-VM calls. twisti@2047: // These are special cases that do VM call stuff but are invoked twisti@2047: // as though they were normal calls. This is acceptable so long twisti@2047: // as the method that calls them returns to its immediately that twisti@2047: // the semi VM call returns. twisti@2047: public: twisti@2047: llvm::Value* throw_StackOverflowError(); twisti@2047: llvm::Value* uncommon_trap(); twisti@2047: llvm::Value* deoptimized_entry_point(); twisti@2047: twisti@2047: // Intrinsics and external functions, part 4: Native-Java transition. twisti@2047: // This is a special case in that it is invoked during a thread twisti@2047: // state transition. The stack must be set up for walking, and it twisti@2047: // may throw exceptions, but the state is _thread_in_native_trans. twisti@2047: public: twisti@2047: llvm::Value* check_special_condition_for_native_trans(); twisti@2047: twisti@2047: // Intrinsics and external functions, part 5: Low-level non-VM calls. twisti@2047: // These have the same caveats as the high-level non-VM calls twisti@2047: // above. They are not accessed directly; rather, you should twisti@2047: // access them via the various Create* methods below. twisti@2047: private: twisti@2047: llvm::Value* cmpxchg_int(); twisti@2047: llvm::Value* cmpxchg_ptr(); twisti@2047: llvm::Value* frame_address(); twisti@2047: llvm::Value* memset(); twisti@2047: llvm::Value* unimplemented(); twisti@2047: llvm::Value* should_not_reach_here(); twisti@2047: llvm::Value* dump(); twisti@2047: twisti@2047: // Public interface to low-level non-VM calls. twisti@2047: public: twisti@2047: llvm::CallInst* CreateGetFrameAddress(); twisti@2047: llvm::CallInst* CreateMemset(llvm::Value* dst, twisti@2047: llvm::Value* value, twisti@2047: llvm::Value* len, twisti@2047: llvm::Value* align); twisti@2047: llvm::CallInst* CreateUnimplemented(const char* file, int line); twisti@2047: llvm::CallInst* CreateShouldNotReachHere(const char* file, int line); twisti@2047: NOT_PRODUCT(llvm::CallInst* CreateDump(llvm::Value* value)); twisti@2047: twisti@2047: // HotSpot memory barriers twisti@2047: public: twisti@2047: void CreateUpdateBarrierSet(BarrierSet* bs, llvm::Value* field); twisti@2047: twisti@2047: // Helpers for accessing the code buffer. twisti@2047: public: twisti@2047: llvm::Value* code_buffer_address(int offset); twisti@2047: llvm::Value* CreateInlineOop(jobject object, const char* name = ""); twisti@2047: llvm::Value* CreateInlineOop(ciObject* object, const char* name = "") { twisti@2047: return CreateInlineOop(object->constant_encoding(), name); twisti@2047: } twisti@4314: twisti@4314: llvm::Value* CreateInlineMetadata(Metadata* metadata, llvm::PointerType* type, const char* name = ""); twisti@4314: llvm::Value* CreateInlineMetadata(ciMetadata* metadata, llvm::PointerType* type, const char* name = "") { twisti@4314: return CreateInlineMetadata(metadata->constant_encoding(), type, name); twisti@4314: } twisti@2047: llvm::Value* CreateInlineData(void* data, twisti@2047: size_t size, twisti@4314: llvm::Type* type, twisti@2047: const char* name = ""); twisti@2047: twisti@2047: // Helpers for creating basic blocks. twisti@2047: // NB don't use unless SharkFunction::CreateBlock is unavailable. twisti@2047: // XXX these are hacky and should be removed. twisti@2047: public: twisti@2047: llvm::BasicBlock* GetBlockInsertionPoint() const; twisti@2047: llvm::BasicBlock* CreateBlock(llvm::BasicBlock* ip, twisti@2047: const char* name="") const; twisti@2047: }; twisti@4314: #endif // SHARE_VM_SHARK_SHARKBUILDER_HPP